]> granicus.if.org Git - python/commitdiff
Initialize structseq types only once.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 16 Apr 2006 18:55:50 +0000 (18:55 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 16 Apr 2006 18:55:50 +0000 (18:55 +0000)
Misc/NEWS
Modules/_lsprof.c
Modules/grpmodule.c
Modules/posixmodule.c
Modules/pwdmodule.c
Modules/resource.c
Modules/spwdmodule.c
Modules/timemodule.c

index 02dcd0ab548a1543b03d5fae4c38ea429306d605..0f703788c71cf80a93e827c5285ebdd567806a2d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,10 @@ What's New in Python 2.5 alpha 2?
 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
   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.
index dddab8ea1a92e566922bc4a6783a69bd503702a5..d35c894c5aae69cb59db0fdc15c5c20d42888c71 100644 (file)
@@ -515,6 +515,7 @@ static PyStructSequence_Desc profiler_subentry_desc = {
        5
 };
 
+static int initialized;
 static PyTypeObject StatsEntryType;
 static PyTypeObject StatsSubEntryType;
 
@@ -857,8 +858,12 @@ init_lsprof(void)
                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 @@ init_lsprof(void)
        PyModule_AddObject(module, "profiler_subentry",
                           (PyObject*) &StatsSubEntryType);
        empty_tuple = PyTuple_New(0);
+       initialized = 1;
 }
index de849c98bd5a2506f52876c1fc237be438cb11b7..12d33dd2a4112ded98ba73f741555bedb2ecb950 100644 (file)
@@ -29,6 +29,7 @@ static PyStructSequence_Desc struct_group_type_desc = {
 };
 
 
+static int initialized;
 static PyTypeObject StructGrpType;
 
 static PyObject *
@@ -174,6 +175,8 @@ initgrp(void)
     if (m == NULL)
         return;
     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);
+    initialized = 1;
 }
index e07021a8f3d91e3830ed58aecff9ea2108d9393a..53f35da4272ea530684d2c2e1111320d53454157 100644 (file)
@@ -981,6 +981,7 @@ static PyStructSequence_Desc statvfs_result_desc = {
        10
 };
 
+static int initialized;
 static PyTypeObject StatResultType;
 static PyTypeObject StatVFSResultType;
 static newfunc structseq_new;
@@ -8241,21 +8242,24 @@ INITFUNC(void)
                posix_putenv_garbage = PyDict_New();
 #endif
 
-       stat_result_desc.name = MODNAME ".stat_result";
-       stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
-       stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
-       stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
-       PyStructSequence_InitType(&StatResultType, &stat_result_desc);
-       structseq_new = StatResultType.tp_new;
-       StatResultType.tp_new = statresult_new;
+       if (!initialized) {
+               stat_result_desc.name = MODNAME ".stat_result";
+               stat_result_desc.fields[7].name = PyStructSequence_UnnamedField;
+               stat_result_desc.fields[8].name = PyStructSequence_UnnamedField;
+               stat_result_desc.fields[9].name = PyStructSequence_UnnamedField;
+               PyStructSequence_InitType(&StatResultType, &stat_result_desc);
+               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);
        PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType);
-
-       statvfs_result_desc.name = MODNAME ".statvfs_result";
-       PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
        Py_INCREF((PyObject*) &StatVFSResultType);
        PyModule_AddObject(m, "statvfs_result",
                           (PyObject*) &StatVFSResultType);
+       initialized = 1;
 }
 
 #ifdef __cplusplus
index 9e7b864b75a045cbccc69ed76160cb04dac9882c..9e01f4875768fd957e7045a8d2c895875b1d8c76 100644 (file)
@@ -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.");
 
       
+static int initialized;
 static PyTypeObject StructPwdType;
 
 static void
@@ -186,9 +187,12 @@ initpwd(void)
        if (m == NULL)
                return;
 
-       PyStructSequence_InitType(&StructPwdType, &struct_pwd_type_desc);
+       if (!initialized)
+               PyStructSequence_InitType(&StructPwdType, 
+                                         &struct_pwd_type_desc);
        Py_INCREF((PyObject *) &StructPwdType);
        PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType);
        /* And for b/w compatibility (this was defined by mistake): */
        PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType);
+       initialized = 1;
 }
index 7cbd2c94b490c50561fc9db2d18986c2225115a8..e73c8781581ec6ba63cbbd22a66c133d8d06dccd 100644 (file)
@@ -55,6 +55,7 @@ static PyStructSequence_Desc struct_rusage_desc = {
        16      /* n_in_sequence */
 };
 
+static int initialized;
 static PyTypeObject StructRUsageType;
 
 static PyObject *
@@ -244,7 +245,10 @@ initresource(void)
        }
        Py_INCREF(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", 
                           (PyObject*) &StructRUsageType);
 
@@ -320,4 +324,5 @@ initresource(void)
        if (v) {
                PyModule_AddObject(m, "RLIM_INFINITY", v);
        }
+       initialized = 1;
 }
index 7c618e77615bab45b01462bfa7dd7ed9b50fa89c..b7bf20e6d8a4a157d7850df5dc0b3e1a75bdb680 100644 (file)
@@ -52,6 +52,7 @@ static PyStructSequence_Desc struct_spwd_type_desc = {
        9,
 };
 
+static int initialized;
 static PyTypeObject StructSpwdType;
 
 
@@ -173,7 +174,10 @@ initspwd(void)
        m=Py_InitModule3("spwd", spwd_methods, spwd__doc__);
        if (m == NULL)
                return;
-       PyStructSequence_InitType(&StructSpwdType, &struct_spwd_type_desc);
+       if (!initialized)
+               PyStructSequence_InitType(&StructSpwdType, 
+                                         &struct_spwd_type_desc);
        Py_INCREF((PyObject *) &StructSpwdType);
        PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType);
+       initialized = 1;
 }
index 7f762f31a1f915af673b6b04582b2cc80e9bcbe3..08d28a103c3a30bd6e2c302a48e41771b05d9468 100644 (file)
@@ -228,6 +228,7 @@ static PyStructSequence_Desc struct_time_type_desc = {
        9,
 };
 
+static int initialized;
 static PyTypeObject StructTimeType;
 
 static PyObject *
@@ -807,9 +808,13 @@ inittime(void)
        hInterruptEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
        SetConsoleCtrlHandler( PyCtrlHandler, TRUE);
 #endif /* MS_WINDOWS */
-        PyStructSequence_InitType(&StructTimeType, &struct_time_type_desc);
+       if (!initialized) {
+               PyStructSequence_InitType(&StructTimeType, 
+                                         &struct_time_type_desc);
+       }
        Py_INCREF(&StructTimeType);
        PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType);
+       initialized = 1;
 }