Initialize structseq types only once.
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index dddab8e..d35c894 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -515,6 +515,7 @@
5
};
+static int initialized;
static PyTypeObject StatsEntryType;
static PyTypeObject StatsSubEntryType;
@@ -857,8 +858,12 @@
return;
PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type);
- PyStructSequence_InitType(&StatsEntryType, &profiler_entry_desc);
- PyStructSequence_InitType(&StatsSubEntryType, &profiler_subentry_desc);
+ if (!initialized) {
+ PyStructSequence_InitType(&StatsEntryType,
+ &profiler_entry_desc);
+ PyStructSequence_InitType(&StatsSubEntryType,
+ &profiler_subentry_desc);
+ }
Py_INCREF((PyObject*) &StatsEntryType);
Py_INCREF((PyObject*) &StatsSubEntryType);
PyModule_AddObject(module, "profiler_entry",
@@ -866,4 +871,5 @@
PyModule_AddObject(module, "profiler_subentry",
(PyObject*) &StatsSubEntryType);
empty_tuple = PyTuple_New(0);
+ initialized = 1;
}