[/F] > 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 */ > } > ... Don't forget realloc too, and that malloc hasn't taken an int argument since before 1989 <wink>. Sorry, but this is nuts, and Martin is right that I don't want Python to offer a "malloc wrapper" that doesn't meet the standard rules for malloc. Instead I intend to change the docs to say that Py_Malloc(0) acts like platform malloc(1), and leave it at that. I expect the _PyMem_EXTRA hack to go away too.
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