mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Fixed new seemingly random segfaults, by moving the initialization of
delstr from initgc() into collect(). initgc() isn't called unless the user explicitly imports gc, so can be used only for initialization of user-visible module features; delstr needs to be initialized for proper internal operation, whether or not gc is explicitly imported. Bugfix candidate? I don't know whether the new bug was backported to 2.2 already.
This commit is contained in:
parent
c377cbfdaf
commit
93ad66dea9
1 changed files with 11 additions and 8 deletions
|
|
@ -59,8 +59,8 @@ static PyObject *garbage;
|
||||||
/* Python string to use if unhandled exception occurs */
|
/* Python string to use if unhandled exception occurs */
|
||||||
static PyObject *gc_str;
|
static PyObject *gc_str;
|
||||||
|
|
||||||
/* Python string used to looked for __del__ attribute. */
|
/* Python string used to look for __del__ attribute. */
|
||||||
static PyObject *delstr;
|
static PyObject *delstr = NULL;
|
||||||
|
|
||||||
/* set for debugging information */
|
/* set for debugging information */
|
||||||
#define DEBUG_STATS (1<<0) /* print collection statistics */
|
#define DEBUG_STATS (1<<0) /* print collection statistics */
|
||||||
|
|
@ -525,6 +525,12 @@ collect(int generation)
|
||||||
PyGC_Head finalizers;
|
PyGC_Head finalizers;
|
||||||
PyGC_Head *gc;
|
PyGC_Head *gc;
|
||||||
|
|
||||||
|
if (delstr == NULL) {
|
||||||
|
delstr = PyString_InternFromString("__del__");
|
||||||
|
if (delstr == NULL)
|
||||||
|
Py_FatalError("gc couldn't allocate \"__del__\"");
|
||||||
|
}
|
||||||
|
|
||||||
if (debug & DEBUG_STATS) {
|
if (debug & DEBUG_STATS) {
|
||||||
PySys_WriteStderr("gc: collecting generation %d...\n",
|
PySys_WriteStderr("gc: collecting generation %d...\n",
|
||||||
generation);
|
generation);
|
||||||
|
|
@ -969,9 +975,6 @@ initgc(void)
|
||||||
PyObject *m;
|
PyObject *m;
|
||||||
PyObject *d;
|
PyObject *d;
|
||||||
|
|
||||||
delstr = PyString_InternFromString("__del__");
|
|
||||||
if (!delstr)
|
|
||||||
return;
|
|
||||||
m = Py_InitModule4("gc",
|
m = Py_InitModule4("gc",
|
||||||
GcMethods,
|
GcMethods,
|
||||||
gc__doc__,
|
gc__doc__,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue