Issue 543344: Interpreter crashes when recoding (original) (raw)

Logged In: YES user_id=31435

Here's a clue from a debug-mode build:

import codecs [9477 refs] f = open("syllables", "w+") [9483 refs] f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8") [9830 refs] f2.write(u"a") C:\Code\python\Objects\tupleobject.c:147 negative ref count -1

Logged In: YES user_id=670441

This was a problem in Modules/_codecsmodule.c Throughout most of the module, objects retrieved through PyArg_ParseTuple are converted to new types, but in this one line the object is used directly. In that case we must INCREF it as PyArg_ParseTuple will not.

Patch below:

Index: dist/src/Modules/_codecsmodule.c

RCS file: /cvsroot/python/python/dist/src/Modules/_codecsmodule.c,v retrieving revision 2.16 diff -c -r2.16 _codecsmodule.c *** dist/src/Modules/_codecsmodule.c 31 Oct 2002 13:36:29 -0000 2.16 --- dist/src/Modules/_codecsmodule.c 4 Feb 2003 18:53:50 -0000


*** 167,174 **** &obj, &errors)) return NULL;

! if (PyUnicode_Check(obj)) return codec_tuple(obj, PyUnicode_GET_SIZE(obj)); else { if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) return NULL; --- 167,176 ---- &obj, &errors)) return NULL;

! if (PyUnicode_Check(obj)) { ! Py_INCREF(obj); return codec_tuple(obj, PyUnicode_GET_SIZE(obj));