A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2002-April/022327.html below:

[Python-Dev] Problem with the memory docs

[Python-Dev] Problem with the memory docs [Python-Dev] Problem with the memory docsFredrik Lundh fredrik@pythonware.com
Thu, 4 Apr 2002 19:19:46 +0200
tim wrote:

>
>     Requesting zero bytes returns a non-NULL pointer.
> 
> I can't guarantee this without insane effort, and our code has never
> guaranteed this.

umm.  I have to admit that it's rather ugly, but I'm pretty sure the
following guarantees that requesting zero bytes will never return a
NULL pointer:

static char nullbyte = MAGIC;

void* malloc(int bytes)
{
    if (bytes == 0) {
#if DEBUG_MODE
        if (*nullbyte != MAGIC)
            uh-oh
#endif
        return &nullbyte;
    }
    ...

void free(void* ptr)
{
    if (ptr == &nullbyte) {
#if DEBUG_MODE
        if (*nullbyte != MAGIC)
            uh-oh
#endif
        return; /* nothing to do */
    }
    ...

</F>





RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4