Skip to content

Commit 3e7d77c

Browse files
author
christian.heimes
committed
The previous change was causing a segfault after multiple calls to Py_Initialize() and Py_Finalize().
git-svn-id: http://svn.python.org/projects/python/trunk@60450 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 4acc1d1 commit 3e7d77c

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

Objects/floatobject.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ PyFloat_GetMin(void)
6666
return DBL_MIN;
6767
}
6868

69-
static PyTypeObject FloatInfoType = {0};
69+
static PyTypeObject FloatInfoType = {0, 0, 0, 0, 0, 0};
7070

7171
PyDoc_STRVAR(floatinfo__doc__,
7272
"sys.floatinfo\n\
@@ -105,15 +105,9 @@ static PyStructSequence_Desc floatinfo_desc = {
105105
PyObject *
106106
PyFloat_GetInfo(void)
107107
{
108-
static PyObject* floatinfo;
108+
PyObject* floatinfo;
109109
int pos = 0;
110110

111-
if (floatinfo != NULL) {
112-
Py_INCREF(floatinfo);
113-
return floatinfo;
114-
}
115-
PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc);
116-
117111
floatinfo = PyStructSequence_New(&FloatInfoType);
118112
if (floatinfo == NULL) {
119113
return NULL;
@@ -142,7 +136,6 @@ PyFloat_GetInfo(void)
142136
Py_CLEAR(floatinfo);
143137
return NULL;
144138
}
145-
146139
return floatinfo;
147140
}
148141

@@ -1669,6 +1662,9 @@ _PyFloat_Init(void)
16691662
/* Initialize floating point repr */
16701663
_PyFloat_DigitsInit();
16711664
#endif
1665+
/* Init float info */
1666+
if (FloatInfoType.tp_name == 0)
1667+
PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc);
16721668
}
16731669

16741670
void

Python/sysmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ PyDoc_STRVAR(flags__doc__,
11071107
\n\
11081108
Flags provided through command line arguments or environment vars.");
11091109

1110-
static PyTypeObject FlagsType;
1110+
static PyTypeObject FlagsType = {0, 0, 0, 0, 0, 0};
11111111

11121112
static PyStructSequence_Field flags_fields[] = {
11131113
{"debug", "-d"},
@@ -1180,7 +1180,6 @@ make_flags(void)
11801180
if (PyErr_Occurred()) {
11811181
return NULL;
11821182
}
1183-
11841183
return seq;
11851184
}
11861185

@@ -1346,7 +1345,8 @@ _PySys_Init(void)
13461345
PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
13471346
}
13481347

1349-
PyStructSequence_InitType(&FlagsType, &flags_desc);
1348+
if (FlagsType.tp_name == 0)
1349+
PyStructSequence_InitType(&FlagsType, &flags_desc);
13501350
SET_SYS_FROM_STRING("flags", make_flags());
13511351
/* prevent user from creating new instances */
13521352
FlagsType.tp_init = NULL;

0 commit comments

Comments
 (0)