From 796fc3158572c9a20f64f6b1c54e278639e6f032 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 30 Jan 2008 18:58:29 +0000 Subject: [PATCH] The previous change was causing a segfault after multiple calls to Py_Initialize() and Py_Finalize(). --- Objects/floatobject.c | 14 +++++--------- Python/sysmodule.c | 6 +++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 689edcdb5ad..63512787a6b 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -66,7 +66,7 @@ PyFloat_GetMin(void) return DBL_MIN; } -static PyTypeObject FloatInfoType = {0}; +static PyTypeObject FloatInfoType = {0, 0, 0, 0, 0, 0}; PyDoc_STRVAR(floatinfo__doc__, "sys.floatinfo\n\ @@ -105,15 +105,9 @@ static PyStructSequence_Desc floatinfo_desc = { PyObject * PyFloat_GetInfo(void) { - static PyObject* floatinfo; + PyObject* floatinfo; int pos = 0; - if (floatinfo != NULL) { - Py_INCREF(floatinfo); - return floatinfo; - } - PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc); - floatinfo = PyStructSequence_New(&FloatInfoType); if (floatinfo == NULL) { return NULL; @@ -142,7 +136,6 @@ PyFloat_GetInfo(void) Py_CLEAR(floatinfo); return NULL; } - return floatinfo; } @@ -1669,6 +1662,9 @@ _PyFloat_Init(void) /* Initialize floating point repr */ _PyFloat_DigitsInit(); #endif + /* Init float info */ + if (FloatInfoType.tp_name == 0) + PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc); } void diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 80d24d1911a..41830b9e4c8 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1107,7 +1107,7 @@ PyDoc_STRVAR(flags__doc__, \n\ Flags provided through command line arguments or environment vars."); -static PyTypeObject FlagsType; +static PyTypeObject FlagsType = {0, 0, 0, 0, 0, 0}; static PyStructSequence_Field flags_fields[] = { {"debug", "-d"}, @@ -1180,7 +1180,6 @@ make_flags(void) if (PyErr_Occurred()) { return NULL; } - return seq; } @@ -1346,7 +1345,8 @@ _PySys_Init(void) PyDict_SetItemString(sysdict, "warnoptions", warnoptions); } - PyStructSequence_InitType(&FlagsType, &flags_desc); + if (FlagsType.tp_name == 0) + PyStructSequence_InitType(&FlagsType, &flags_desc); SET_SYS_FROM_STRING("flags", make_flags()); /* prevent user from creating new instances */ FlagsType.tp_init = NULL;