mirror of https://github.com/python/cpython
Initialize structseq types only once.
This commit is contained in:
parent
d18d5a3153
commit
19ab6c98cf
|
@ -12,6 +12,10 @@ What's New in Python 2.5 alpha 2?
|
||||||
Core and builtins
|
Core and builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- All uses of PyStructSequence_InitType have been changed to initialize
|
||||||
|
the type objects only once, even if the interpreter is initialized
|
||||||
|
multiple times.
|
||||||
|
|
||||||
- Bug #1454485, array.array('u') could crash the interpreter. This was
|
- Bug #1454485, array.array('u') could crash the interpreter. This was
|
||||||
due to PyArgs_ParseTuple(args, 'u#', ...) trying to convert buffers (strings)
|
due to PyArgs_ParseTuple(args, 'u#', ...) trying to convert buffers (strings)
|
||||||
to unicode when it didn't make sense. 'u#' now requires a unicode string.
|
to unicode when it didn't make sense. 'u#' now requires a unicode string.
|
||||||
|
|
|
@ -515,6 +515,7 @@ static PyStructSequence_Desc profiler_subentry_desc = {
|
||||||
5
|
5
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static PyTypeObject StatsEntryType;
|
static PyTypeObject StatsEntryType;
|
||||||
static PyTypeObject StatsSubEntryType;
|
static PyTypeObject StatsSubEntryType;
|
||||||
|
|
||||||
|
@ -857,8 +858,12 @@ init_lsprof(void)
|
||||||
return;
|
return;
|
||||||
PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type);
|
PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type);
|
||||||
|
|
||||||
PyStructSequence_InitType(&StatsEntryType, &profiler_entry_desc);
|
if (!initialized) {
|
||||||
PyStructSequence_InitType(&StatsSubEntryType, &profiler_subentry_desc);
|
PyStructSequence_InitType(&StatsEntryType,
|
||||||
|
&profiler_entry_desc);
|
||||||
|
PyStructSequence_InitType(&StatsSubEntryType,
|
||||||
|
&profiler_subentry_desc);
|
||||||
|
}
|
||||||
Py_INCREF((PyObject*) &StatsEntryType);
|
Py_INCREF((PyObject*) &StatsEntryType);
|
||||||
Py_INCREF((PyObject*) &StatsSubEntryType);
|
Py_INCREF((PyObject*) &StatsSubEntryType);
|
||||||
PyModule_AddObject(module, "profiler_entry",
|
PyModule_AddObject(module, "profiler_entry",
|
||||||
|
@ -866,4 +871,5 @@ init_lsprof(void)
|
||||||
PyModule_AddObject(module, "profiler_subentry",
|
PyModule_AddObject(module, "profiler_subentry",
|
||||||
(PyObject*) &StatsSubEntryType);
|
(PyObject*) &StatsSubEntryType);
|
||||||
empty_tuple = PyTuple_New(0);
|
empty_tuple = PyTuple_New(0);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ static PyStructSequence_Desc struct_group_type_desc = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static PyTypeObject StructGrpType;
|
static PyTypeObject StructGrpType;
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -174,6 +175,8 @@ initgrp(void)
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return;
|
return;
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
PyStructSequence_InitType(&StructGrpType, &struct_group_type_desc);
|
if (!initialized)
|
||||||
|
PyStructSequence_InitType(&StructGrpType, &struct_group_type_desc);
|
||||||
PyDict_SetItemString(d, "struct_group", (PyObject *) &StructGrpType);
|
PyDict_SetItemString(d, "struct_group", (PyObject *) &StructGrpType);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -981,6 +981,7 @@ static PyStructSequence_Desc statvfs_result_desc = {
|
||||||
10
|
10
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static PyTypeObject StatResultType;
|
static PyTypeObject StatResultType;
|
||||||
static PyTypeObject StatVFSResultType;
|
static PyTypeObject StatVFSResultType;
|
||||||
static newfunc structseq_new;
|
static newfunc structseq_new;
|
||||||
|
@ -8241,21 +8242,24 @@ INITFUNC(void)
|
||||||
posix_putenv_garbage = PyDict_New();
|
posix_putenv_garbage = PyDict_New();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
stat_result_desc.name = MODNAME ".stat_result";
|
if (!initialized) {
|
||||||
stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
|
stat_result_desc.name = MODNAME ".stat_result";
|
||||||
stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
|
stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
|
||||||
stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
|
stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
|
||||||
PyStructSequence_InitType(&StatResultType, &stat_result_desc);
|
stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
|
||||||
structseq_new = StatResultType.tp_new;
|
PyStructSequence_InitType(&StatResultType, &stat_result_desc);
|
||||||
StatResultType.tp_new = statresult_new;
|
structseq_new = StatResultType.tp_new;
|
||||||
|
StatResultType.tp_new = statresult_new;
|
||||||
|
|
||||||
|
statvfs_result_desc.name = MODNAME ".statvfs_result";
|
||||||
|
PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
|
||||||
|
}
|
||||||
Py_INCREF((PyObject*) &StatResultType);
|
Py_INCREF((PyObject*) &StatResultType);
|
||||||
PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
|
PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
|
||||||
|
|
||||||
statvfs_result_desc.name = MODNAME ".statvfs_result";
|
|
||||||
PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
|
|
||||||
Py_INCREF((PyObject*) &StatVFSResultType);
|
Py_INCREF((PyObject*) &StatVFSResultType);
|
||||||
PyModule_AddObject(m, "statvfs_result",
|
PyModule_AddObject(m, "statvfs_result",
|
||||||
(PyObject*) &StatVFSResultType);
|
(PyObject*) &StatVFSResultType);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -42,6 +42,7 @@ The uid and gid items are integers, all others are strings. An\n\
|
||||||
exception is raised if the entry asked for cannot be found.");
|
exception is raised if the entry asked for cannot be found.");
|
||||||
|
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static PyTypeObject StructPwdType;
|
static PyTypeObject StructPwdType;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -186,9 +187,12 @@ initpwd(void)
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PyStructSequence_InitType(&StructPwdType, &struct_pwd_type_desc);
|
if (!initialized)
|
||||||
|
PyStructSequence_InitType(&StructPwdType,
|
||||||
|
&struct_pwd_type_desc);
|
||||||
Py_INCREF((PyObject *) &StructPwdType);
|
Py_INCREF((PyObject *) &StructPwdType);
|
||||||
PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
|
PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
|
||||||
/* And for b/w compatibility (this was defined by mistake): */
|
/* And for b/w compatibility (this was defined by mistake): */
|
||||||
PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType);
|
PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ static PyStructSequence_Desc struct_rusage_desc = {
|
||||||
16 /* n_in_sequence */
|
16 /* n_in_sequence */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static PyTypeObject StructRUsageType;
|
static PyTypeObject StructRUsageType;
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -244,7 +245,10 @@ initresource(void)
|
||||||
}
|
}
|
||||||
Py_INCREF(ResourceError);
|
Py_INCREF(ResourceError);
|
||||||
PyModule_AddObject(m, "error", ResourceError);
|
PyModule_AddObject(m, "error", ResourceError);
|
||||||
PyStructSequence_InitType(&StructRUsageType, &struct_rusage_desc);
|
if (!initialized)
|
||||||
|
PyStructSequence_InitType(&StructRUsageType,
|
||||||
|
&struct_rusage_desc);
|
||||||
|
Py_INCREF(&StructRUsageType);
|
||||||
PyModule_AddObject(m, "struct_rusage",
|
PyModule_AddObject(m, "struct_rusage",
|
||||||
(PyObject*) &StructRUsageType);
|
(PyObject*) &StructRUsageType);
|
||||||
|
|
||||||
|
@ -320,4 +324,5 @@ initresource(void)
|
||||||
if (v) {
|
if (v) {
|
||||||
PyModule_AddObject(m, "RLIM_INFINITY", v);
|
PyModule_AddObject(m, "RLIM_INFINITY", v);
|
||||||
}
|
}
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ static PyStructSequence_Desc struct_spwd_type_desc = {
|
||||||
9,
|
9,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static PyTypeObject StructSpwdType;
|
static PyTypeObject StructSpwdType;
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,7 +174,10 @@ initspwd(void)
|
||||||
m=Py_InitModule3("spwd", spwd_methods, spwd__doc__);
|
m=Py_InitModule3("spwd", spwd_methods, spwd__doc__);
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return;
|
return;
|
||||||
PyStructSequence_InitType(&StructSpwdType, &struct_spwd_type_desc);
|
if (!initialized)
|
||||||
|
PyStructSequence_InitType(&StructSpwdType,
|
||||||
|
&struct_spwd_type_desc);
|
||||||
Py_INCREF((PyObject *) &StructSpwdType);
|
Py_INCREF((PyObject *) &StructSpwdType);
|
||||||
PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType);
|
PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,7 @@ static PyStructSequence_Desc struct_time_type_desc = {
|
||||||
9,
|
9,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int initialized;
|
||||||
static PyTypeObject StructTimeType;
|
static PyTypeObject StructTimeType;
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -807,9 +808,13 @@ inittime(void)
|
||||||
hInterruptEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
hInterruptEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||||
SetConsoleCtrlHandler( PyCtrlHandler, TRUE);
|
SetConsoleCtrlHandler( PyCtrlHandler, TRUE);
|
||||||
#endif /* MS_WINDOWS */
|
#endif /* MS_WINDOWS */
|
||||||
PyStructSequence_InitType(&StructTimeType, &struct_time_type_desc);
|
if (!initialized) {
|
||||||
|
PyStructSequence_InitType(&StructTimeType,
|
||||||
|
&struct_time_type_desc);
|
||||||
|
}
|
||||||
Py_INCREF(&StructTimeType);
|
Py_INCREF(&StructTimeType);
|
||||||
PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType);
|
PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType);
|
||||||
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue