Partial fix for bug #1306
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
This commit is contained in:
parent
a22e8bdfd9
commit
c896700235
|
@ -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
|
If non-NULL, this is different than the default encoding for strings
|
||||||
*/
|
*/
|
||||||
PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
|
PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
|
||||||
|
PyAPI_DATA(const int) Py_HasFileSystemDefaultEncoding;
|
||||||
|
|
||||||
/* Internal API
|
/* Internal API
|
||||||
|
|
||||||
|
|
|
@ -1532,8 +1532,15 @@ _Py_ForgetReference(register PyObject *op)
|
||||||
if (op->ob_refcnt < 0)
|
if (op->ob_refcnt < 0)
|
||||||
Py_FatalError("UNREF negative refcnt");
|
Py_FatalError("UNREF negative refcnt");
|
||||||
if (op == &refchain ||
|
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");
|
Py_FatalError("UNREF invalid object");
|
||||||
|
}
|
||||||
#ifdef SLOW_UNREF_CHECK
|
#ifdef SLOW_UNREF_CHECK
|
||||||
for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
|
for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
|
||||||
if (p == op)
|
if (p == op)
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
*/
|
*/
|
||||||
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
|
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
|
||||||
const char *Py_FileSystemDefaultEncoding = "mbcs";
|
const char *Py_FileSystemDefaultEncoding = "mbcs";
|
||||||
|
const int Py_HasFileSystemDefaultEncoding = 1;
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
const char *Py_FileSystemDefaultEncoding = "utf-8";
|
const char *Py_FileSystemDefaultEncoding = "utf-8";
|
||||||
|
const int Py_HasFileSystemDefaultEncoding = 1;
|
||||||
#else
|
#else
|
||||||
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
|
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
|
||||||
|
const int Py_HasFileSystemDefaultEncoding = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
|
@ -502,6 +502,12 @@ Py_Finalize(void)
|
||||||
/* Cleanup Unicode implementation */
|
/* Cleanup Unicode implementation */
|
||||||
_PyUnicode_Fini();
|
_PyUnicode_Fini();
|
||||||
|
|
||||||
|
/* reset file system default encoding */
|
||||||
|
if (!Py_HasFileSystemDefaultEncoding) {
|
||||||
|
free((char*)Py_FileSystemDefaultEncoding);
|
||||||
|
Py_FileSystemDefaultEncoding = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX Still allocated:
|
/* XXX Still allocated:
|
||||||
- various static ad-hoc pointers to interned strings
|
- various static ad-hoc pointers to interned strings
|
||||||
- int and float free list blocks
|
- int and float free list blocks
|
||||||
|
|
Loading…
Reference in New Issue