[issue11286] Some "trivial" python 2.x pickles fails to load in Python 3.2
Antoine Pitrou
report at bugs.python.org
Tue Feb 22 16:21:00 CET 2011
Antoine Pitrou <pitrou at free.fr> added the comment:
This is because of the buffer pointer passed to the codecs machinery being NULL when the empty string is being decoded.
Quick patch follows (needs a test). Also, it is not clear whether it is allowed to store a NULL pointer in the "buf" member of a Py_buffer when the length is 0. Nick, Mark?
Index: Objects/unicodeobject.c
===================================================================
--- Objects/unicodeobject.c (révision 88500)
+++ Objects/unicodeobject.c (copie de travail)
@@ -1460,6 +1460,7 @@
PyObject *buffer = NULL, *unicode;
Py_buffer info;
char lower[11]; /* Enough for any encoding shortcut */
+ static const char empty[] = "";
if (encoding == NULL)
encoding = PyUnicode_GetDefaultEncoding();
@@ -1485,6 +1486,8 @@
/* Decode via the codec registry */
buffer = NULL;
+ if (s == NULL)
+ s = empty;
if (PyBuffer_FillInfo(&info, NULL, (void *)s, size, 1, PyBUF_FULL_RO) < 0)
goto onError;
buffer = PyMemoryView_FromBuffer(&info);
----------
nosy: +mark.dickinson, ncoghlan
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11286>
_______________________________________
More information about the Python-bugs-list
mailing list