Skip to content

bpo-40549: posixmodule.c uses defining_class #20075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add state variable to posixmodule_exec()
  • Loading branch information
vstinner committed May 14, 2020
commit 779749bf71a2a2fa6fdad3386454b17553e8c000
41 changes: 20 additions & 21 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -14802,12 +14802,10 @@ static const char * const have_functions[] = {
static int
posixmodule_exec(PyObject *m)
{
PyObject *v;
PyObject *list;
const char * const *trace;
_posixstate *state = get_posix_state(m);

/* Initialize environ dictionary */
v = convertenviron();
PyObject *v = convertenviron();
Py_XINCREF(v);
if (v == NULL || PyModule_AddObject(m, "environ", v) != 0)
return -1;
Expand All @@ -14830,7 +14828,7 @@ posixmodule_exec(PyObject *m)
}
Py_INCREF(WaitidResultType);
PyModule_AddObject(m, "waitid_result", WaitidResultType);
get_posix_state(m)->WaitidResultType = WaitidResultType;
state->WaitidResultType = WaitidResultType;
#endif

stat_result_desc.name = "os.stat_result"; /* see issue #19209 */
Expand All @@ -14843,7 +14841,7 @@ posixmodule_exec(PyObject *m)
}
Py_INCREF(StatResultType);
PyModule_AddObject(m, "stat_result", StatResultType);
get_posix_state(m)->StatResultType = StatResultType;
state->StatResultType = StatResultType;
structseq_new = ((PyTypeObject *)StatResultType)->tp_new;
((PyTypeObject *)StatResultType)->tp_new = statresult_new;

Expand All @@ -14854,7 +14852,7 @@ posixmodule_exec(PyObject *m)
}
Py_INCREF(StatVFSResultType);
PyModule_AddObject(m, "statvfs_result", StatVFSResultType);
get_posix_state(m)->StatVFSResultType = StatVFSResultType;
state->StatVFSResultType = StatVFSResultType;
#ifdef NEED_TICKS_PER_SECOND
# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
ticks_per_second = sysconf(_SC_CLK_TCK);
Expand All @@ -14873,7 +14871,7 @@ posixmodule_exec(PyObject *m)
}
Py_INCREF(SchedParamType);
PyModule_AddObject(m, "sched_param", SchedParamType);
get_posix_state(m)->SchedParamType = SchedParamType;
state->SchedParamType = SchedParamType;
((PyTypeObject *)SchedParamType)->tp_new = os_sched_param;
#endif

Expand All @@ -14884,22 +14882,22 @@ posixmodule_exec(PyObject *m)
}
Py_INCREF(TerminalSizeType);
PyModule_AddObject(m, "terminal_size", TerminalSizeType);
get_posix_state(m)->TerminalSizeType = TerminalSizeType;
state->TerminalSizeType = TerminalSizeType;

/* initialize scandir types */
PyObject *ScandirIteratorType = PyType_FromModuleAndSpec(m, &ScandirIteratorType_spec, NULL);
if (ScandirIteratorType == NULL) {
return -1;
}
get_posix_state(m)->ScandirIteratorType = ScandirIteratorType;
state->ScandirIteratorType = ScandirIteratorType;

PyObject *DirEntryType = PyType_FromModuleAndSpec(m, &DirEntryType_spec, NULL);
if (DirEntryType == NULL) {
return -1;
}
Py_INCREF(DirEntryType);
PyModule_AddObject(m, "DirEntry", DirEntryType);
get_posix_state(m)->DirEntryType = DirEntryType;
state->DirEntryType = DirEntryType;

times_result_desc.name = MODNAME ".times_result";
PyObject *TimesResultType = (PyObject *)PyStructSequence_NewType(&times_result_desc);
Expand All @@ -14908,15 +14906,15 @@ posixmodule_exec(PyObject *m)
}
Py_INCREF(TimesResultType);
PyModule_AddObject(m, "times_result", TimesResultType);
get_posix_state(m)->TimesResultType = TimesResultType;
state->TimesResultType = TimesResultType;

PyTypeObject *UnameResultType = PyStructSequence_NewType(&uname_result_desc);
if (UnameResultType == NULL) {
return -1;
}
Py_INCREF(UnameResultType);
PyModule_AddObject(m, "uname_result", (PyObject *)UnameResultType);
get_posix_state(m)->UnameResultType = (PyObject *)UnameResultType;
state->UnameResultType = (PyObject *)UnameResultType;

#ifdef __APPLE__
/*
Expand Down Expand Up @@ -14956,15 +14954,15 @@ posixmodule_exec(PyObject *m)

#endif /* __APPLE__ */

if ((get_posix_state(m)->billion = PyLong_FromLong(1000000000)) == NULL)
if ((state->billion = PyLong_FromLong(1000000000)) == NULL)
return -1;
#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
get_posix_state(m)->struct_rusage = PyUnicode_InternFromString("struct_rusage");
if (get_posix_state(m)->struct_rusage == NULL)
state->struct_rusage = PyUnicode_InternFromString("struct_rusage");
if (state->struct_rusage == NULL)
return -1;
#endif
get_posix_state(m)->st_mode = PyUnicode_InternFromString("st_mode");
if (get_posix_state(m)->st_mode == NULL)
state->st_mode = PyUnicode_InternFromString("st_mode");
if (state->st_mode == NULL)
return -1;

/* suppress "function not used" warnings */
Expand All @@ -14981,10 +14979,11 @@ posixmodule_exec(PyObject *m)
* provide list of locally available functions
* so os.py can populate support_* lists
*/
list = PyList_New(0);
if (!list)
PyObject *list = PyList_New(0);
if (!list) {
return -1;
for (trace = have_functions; *trace; trace++) {
}
for (const char * const *trace = have_functions; *trace; trace++) {
PyObject *unicode = PyUnicode_DecodeASCII(*trace, strlen(*trace), NULL);
if (!unicode)
return -1;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy