From: Guido van Rossum Date: Wed, 9 May 2007 23:36:14 +0000 (+0000) Subject: The NULL pointer for empty strings turns out to be a pain. X-Git-Tag: v3.0a1~980 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=63eac1592700e550d7a8e9b5ef1f77cadac9a020;p=python The NULL pointer for empty strings turns out to be a pain. At least for the buffer API, return "" in that case. --- diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index a07f9e709b..2cdaf37768 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -950,7 +950,10 @@ bytes_getbuffer(PyBytesObject *self, Py_ssize_t index, const void **ptr) "accessing non-existent bytes segment"); return -1; } - *ptr = (void *)self->ob_bytes; + if (self->ob_bytes == NULL) + *ptr = ""; + else + *ptr = self->ob_bytes; return self->ob_size; }