]> granicus.if.org Git - python/commitdiff
Partial fix for bug #1306
authorChristian Heimes <christian@cheimes.de>
Fri, 30 Nov 2007 10:18:26 +0000 (10:18 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 30 Nov 2007 10:18:26 +0000 (10:18 +0000)
Multiple reinitializations of Python 3.0 failed on a system without a hardcoded default fs encoding. The patch makes sure that the default fs encoding is freed and reset to NULL on e.g. Linux.
I've also taken the liberty to increase the debugging in Objects/object.c:_Py_ForgetReference(). The method is used to validate the reference chain.
Reinitialization still fails in the 3rd round of my test suite:
* ob
object  : <refcnt 0 at 0x821c840>
type    : str
refcount: 0
address : 0x821c840
* op->_ob_prev->_ob_next
object  : <refcnt 0 at 0x821c840>
type    : str
refcount: 0
address : 0x821c840
* op->_ob_next->_ob_prev
object  : bytearray(b'')
type    : bytearray
refcount: 1
address : 0x826b838
Fatal Python error: UNREF invalid object

Include/fileobject.h
Objects/object.c
Python/bltinmodule.c
Python/pythonrun.c

index 40d871aea5df62b1b578e62d47b2c72fe91b6a6d..0f40089ef19624d0ee8be84fc010d4a48ee012be 100644 (file)
@@ -20,6 +20,7 @@ PyAPI_FUNC(char *) Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
    If non-NULL, this is different than the default encoding for strings
 */
 PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
+PyAPI_DATA(const int) Py_HasFileSystemDefaultEncoding;
 
 /* Internal API
 
index df93a192d6078ee39e7558a2d2ed38e87d6c72d8..64146736404006ec372bfa2985343fad700137c6 100644 (file)
@@ -1532,8 +1532,15 @@ _Py_ForgetReference(register PyObject *op)
        if (op->ob_refcnt < 0)
                Py_FatalError("UNREF negative refcnt");
        if (op == &refchain ||
-           op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op)
+           op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) {
+               fprintf(stderr, "* ob\n");
+               _PyObject_Dump(op);
+               fprintf(stderr, "* op->_ob_prev->_ob_next\n");
+               _PyObject_Dump(op->_ob_prev->_ob_next);
+               fprintf(stderr, "* op->_ob_next->_ob_prev\n");
+               _PyObject_Dump(op->_ob_next->_ob_prev);
                Py_FatalError("UNREF invalid object");
+       }
 #ifdef SLOW_UNREF_CHECK
        for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
                if (p == op)
index b109ba7c3b81eedcf4b0ac2f25ff10b47909346c..fb7e223367ee2fce8214844fedbe4286ca84c6bf 100644 (file)
 */
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
 const char *Py_FileSystemDefaultEncoding = "mbcs";
+const int Py_HasFileSystemDefaultEncoding = 1;
 #elif defined(__APPLE__)
 const char *Py_FileSystemDefaultEncoding = "utf-8";
+const int Py_HasFileSystemDefaultEncoding = 1;
 #else
 const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
+const int Py_HasFileSystemDefaultEncoding = 0;
 #endif
 
 static PyObject *
index 0ba8646ab5d2fcbff62f91d513922ecff96fa8c0..5766b2385e533f94f71c206e4a77d1c6044d47c6 100644 (file)
@@ -502,6 +502,12 @@ Py_Finalize(void)
        /* Cleanup Unicode implementation */
        _PyUnicode_Fini();
 
+       /* reset file system default encoding */
+       if (!Py_HasFileSystemDefaultEncoding) {
+               free((char*)Py_FileSystemDefaultEncoding);
+               Py_FileSystemDefaultEncoding = NULL;
+       }
+
        /* XXX Still allocated:
           - various static ad-hoc pointers to interned strings
           - int and float free list blocks