Skip to content

Commit 779749b

Browse files
committed
Add state variable to posixmodule_exec()
1 parent f4a6471 commit 779749b

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

Modules/posixmodule.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14802,12 +14802,10 @@ static const char * const have_functions[] = {
1480214802
static int
1480314803
posixmodule_exec(PyObject *m)
1480414804
{
14805-
PyObject *v;
14806-
PyObject *list;
14807-
const char * const *trace;
14805+
_posixstate *state = get_posix_state(m);
1480814806

1480914807
/* Initialize environ dictionary */
14810-
v = convertenviron();
14808+
PyObject *v = convertenviron();
1481114809
Py_XINCREF(v);
1481214810
if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
1481314811
return -1;
@@ -14830,7 +14828,7 @@ posixmodule_exec(PyObject *m)
1483014828
}
1483114829
Py_INCREF(WaitidResultType);
1483214830
PyModule_AddObject(m, "waitid_result", WaitidResultType);
14833-
get_posix_state(m)->WaitidResultType = WaitidResultType;
14831+
state->WaitidResultType = WaitidResultType;
1483414832
#endif
1483514833

1483614834
stat_result_desc.name = "os.stat_result"; /* see issue #19209 */
@@ -14843,7 +14841,7 @@ posixmodule_exec(PyObject *m)
1484314841
}
1484414842
Py_INCREF(StatResultType);
1484514843
PyModule_AddObject(m, "stat_result", StatResultType);
14846-
get_posix_state(m)->StatResultType = StatResultType;
14844+
state->StatResultType = StatResultType;
1484714845
structseq_new = ((PyTypeObject *)StatResultType)->tp_new;
1484814846
((PyTypeObject *)StatResultType)->tp_new = statresult_new;
1484914847

@@ -14854,7 +14852,7 @@ posixmodule_exec(PyObject *m)
1485414852
}
1485514853
Py_INCREF(StatVFSResultType);
1485614854
PyModule_AddObject(m, "statvfs_result", StatVFSResultType);
14857-
get_posix_state(m)->StatVFSResultType = StatVFSResultType;
14855+
state->StatVFSResultType = StatVFSResultType;
1485814856
#ifdef NEED_TICKS_PER_SECOND
1485914857
# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
1486014858
ticks_per_second = sysconf(_SC_CLK_TCK);
@@ -14873,7 +14871,7 @@ posixmodule_exec(PyObject *m)
1487314871
}
1487414872
Py_INCREF(SchedParamType);
1487514873
PyModule_AddObject(m, "sched_param", SchedParamType);
14876-
get_posix_state(m)->SchedParamType = SchedParamType;
14874+
state->SchedParamType = SchedParamType;
1487714875
((PyTypeObject *)SchedParamType)->tp_new = os_sched_param;
1487814876
#endif
1487914877

@@ -14884,22 +14882,22 @@ posixmodule_exec(PyObject *m)
1488414882
}
1488514883
Py_INCREF(TerminalSizeType);
1488614884
PyModule_AddObject(m, "terminal_size", TerminalSizeType);
14887-
get_posix_state(m)->TerminalSizeType = TerminalSizeType;
14885+
state->TerminalSizeType = TerminalSizeType;
1488814886

1488914887
/* initialize scandir types */
1489014888
PyObject *ScandirIteratorType = PyType_FromModuleAndSpec(m, &ScandirIteratorType_spec, NULL);
1489114889
if (ScandirIteratorType == NULL) {
1489214890
return -1;
1489314891
}
14894-
get_posix_state(m)->ScandirIteratorType = ScandirIteratorType;
14892+
state->ScandirIteratorType = ScandirIteratorType;
1489514893

1489614894
PyObject *DirEntryType = PyType_FromModuleAndSpec(m, &DirEntryType_spec, NULL);
1489714895
if (DirEntryType == NULL) {
1489814896
return -1;
1489914897
}
1490014898
Py_INCREF(DirEntryType);
1490114899
PyModule_AddObject(m, "DirEntry", DirEntryType);
14902-
get_posix_state(m)->DirEntryType = DirEntryType;
14900+
state->DirEntryType = DirEntryType;
1490314901

1490414902
times_result_desc.name = MODNAME ".times_result";
1490514903
PyObject *TimesResultType = (PyObject *)PyStructSequence_NewType(&times_result_desc);
@@ -14908,15 +14906,15 @@ posixmodule_exec(PyObject *m)
1490814906
}
1490914907
Py_INCREF(TimesResultType);
1491014908
PyModule_AddObject(m, "times_result", TimesResultType);
14911-
get_posix_state(m)->TimesResultType = TimesResultType;
14909+
state->TimesResultType = TimesResultType;
1491214910

1491314911
PyTypeObject *UnameResultType = PyStructSequence_NewType(&uname_result_desc);
1491414912
if (UnameResultType == NULL) {
1491514913
return -1;
1491614914
}
1491714915
Py_INCREF(UnameResultType);
1491814916
PyModule_AddObject(m, "uname_result", (PyObject *)UnameResultType);
14919-
get_posix_state(m)->UnameResultType = (PyObject *)UnameResultType;
14917+
state->UnameResultType = (PyObject *)UnameResultType;
1492014918

1492114919
#ifdef __APPLE__
1492214920
/*
@@ -14956,15 +14954,15 @@ posixmodule_exec(PyObject *m)
1495614954

1495714955
#endif /* __APPLE__ */
1495814956

14959-
if ((get_posix_state(m)->billion = PyLong_FromLong(1000000000)) == NULL)
14957+
if ((state->billion = PyLong_FromLong(1000000000)) == NULL)
1496014958
return -1;
1496114959
#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
14962-
get_posix_state(m)->struct_rusage = PyUnicode_InternFromString("struct_rusage");
14963-
if (get_posix_state(m)->struct_rusage == NULL)
14960+
state->struct_rusage = PyUnicode_InternFromString("struct_rusage");
14961+
if (state->struct_rusage == NULL)
1496414962
return -1;
1496514963
#endif
14966-
get_posix_state(m)->st_mode = PyUnicode_InternFromString("st_mode");
14967-
if (get_posix_state(m)->st_mode == NULL)
14964+
state->st_mode = PyUnicode_InternFromString("st_mode");
14965+
if (state->st_mode == NULL)
1496814966
return -1;
1496914967

1497014968
/* suppress "function not used" warnings */
@@ -14981,10 +14979,11 @@ posixmodule_exec(PyObject *m)
1498114979
* provide list of locally available functions
1498214980
* so os.py can populate support_* lists
1498314981
*/
14984-
list = PyList_New(0);
14985-
if (!list)
14982+
PyObject *list = PyList_New(0);
14983+
if (!list) {
1498614984
return -1;
14987-
for (trace = have_functions; *trace; trace++) {
14985+
}
14986+
for (const char * const *trace = have_functions; *trace; trace++) {
1498814987
PyObject *unicode = PyUnicode_DecodeASCII(*trace, strlen(*trace), NULL);
1498914988
if (!unicode)
1499014989
return -1;

0 commit comments

Comments
 (0)