[Python-bugs-list] [ python-Bugs-543344 ] Interpreter crashes when recoding
SourceForge.net
noreply@sourceforge.net
Tue, 04 Feb 2003 11:03:14 -0800
Bugs item #543344, was opened at 2002-04-13 08:12
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=543344&group_id=5470
Category: Unicode
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Martin v. Löwis (loewis)
Assigned to: M.-A. Lemburg (lemburg)
Summary: Interpreter crashes when recoding
Initial Comment:
Python crashes when executing
import codecs
f = open("syllables", "w+")
f2 = codecs.EncodedFile(f, "unicode_internal", "utf-8")
f2.write(u"a")
f2.close()
----------------------------------------------------------------------
Comment By: Michael Stone (mbrierst)
Date: 2003-02-04 19:03
Message:
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));
+ }
else {
if (PyObject_AsReadBuffer(obj, (const void **)&data, &size))
return NULL;
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2002-04-13 08:36
Message:
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
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=543344&group_id=5470