diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-12-27 12:46:59 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-12-27 12:46:59 -0500 |
commit | a78f0158a28734f965218b834ea8c0b166b7353f (patch) | |
tree | dca70268e2a41d49658e7eed783c6fc243d119cd /Modules/symtablemodule.c | |
parent | ec8e6895a3ce9cd69b6ceb75a15fcc74d4a522dc (diff) | |
parent | bf64d9064ab641b1ef9a0c4bda097ebf1204faf4 (diff) | |
download | cpython-git-revert-23107-revert-13893-fix-issue-37193.tar.gz |
Merge branch 'master' into revert-23107-revert-13893-fix-issue-37193revert-23107-revert-13893-fix-issue-37193
Diffstat (limited to 'Modules/symtablemodule.c')
-rw-r--r-- | Modules/symtablemodule.c | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c index 9180f185e1..f6c378fdae 100644 --- a/Modules/symtablemodule.c +++ b/Modules/symtablemodule.c @@ -71,56 +71,60 @@ static PyMethodDef symtable_methods[] = { {NULL, NULL} /* sentinel */ }; +static int +symtable_init_stentry_type(PyObject *m) +{ + return PyType_Ready(&PySTEntry_Type); +} + +static int +symtable_init_constants(PyObject *m) +{ + if (PyModule_AddIntMacro(m, USE) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_GLOBAL) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_NONLOCAL) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_LOCAL) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_PARAM) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_FREE) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_FREE_CLASS) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_IMPORT) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_BOUND) < 0) return -1; + if (PyModule_AddIntMacro(m, DEF_ANNOT) < 0) return -1; + + if (PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock) < 0) + return -1; + if (PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock) < 0) return -1; + if (PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock) < 0) + return -1; + + if (PyModule_AddIntMacro(m, LOCAL) < 0) return -1; + if (PyModule_AddIntMacro(m, GLOBAL_EXPLICIT) < 0) return -1; + if (PyModule_AddIntMacro(m, GLOBAL_IMPLICIT) < 0) return -1; + if (PyModule_AddIntMacro(m, FREE) < 0) return -1; + if (PyModule_AddIntMacro(m, CELL) < 0) return -1; + + if (PyModule_AddIntConstant(m, "SCOPE_OFF", SCOPE_OFFSET) < 0) return -1; + if (PyModule_AddIntMacro(m, SCOPE_MASK) < 0) return -1; + + return 0; +} + +static PyModuleDef_Slot symtable_slots[] = { + {Py_mod_exec, symtable_init_stentry_type}, + {Py_mod_exec, symtable_init_constants}, + {0, NULL} +}; + static struct PyModuleDef symtablemodule = { PyModuleDef_HEAD_INIT, - "_symtable", - NULL, - -1, - symtable_methods, - NULL, - NULL, - NULL, - NULL + .m_name = "_symtable", + .m_size = 0, + .m_methods = symtable_methods, + .m_slots = symtable_slots, }; PyMODINIT_FUNC PyInit__symtable(void) { - PyObject *m; - - if (PyType_Ready(&PySTEntry_Type) < 0) - return NULL; - - m = PyModule_Create(&symtablemodule); - if (m == NULL) - return NULL; - PyModule_AddIntMacro(m, USE); - PyModule_AddIntMacro(m, DEF_GLOBAL); - PyModule_AddIntMacro(m, DEF_NONLOCAL); - PyModule_AddIntMacro(m, DEF_LOCAL); - PyModule_AddIntMacro(m, DEF_PARAM); - PyModule_AddIntMacro(m, DEF_FREE); - PyModule_AddIntMacro(m, DEF_FREE_CLASS); - PyModule_AddIntMacro(m, DEF_IMPORT); - PyModule_AddIntMacro(m, DEF_BOUND); - PyModule_AddIntMacro(m, DEF_ANNOT); - - PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock); - PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock); - PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock); - - PyModule_AddIntMacro(m, LOCAL); - PyModule_AddIntMacro(m, GLOBAL_EXPLICIT); - PyModule_AddIntMacro(m, GLOBAL_IMPLICIT); - PyModule_AddIntMacro(m, FREE); - PyModule_AddIntMacro(m, CELL); - - PyModule_AddIntConstant(m, "SCOPE_OFF", SCOPE_OFFSET); - PyModule_AddIntMacro(m, SCOPE_MASK); - - if (PyErr_Occurred()) { - Py_DECREF(m); - m = 0; - } - return m; + return PyModuleDef_Init(&symtablemodule); } |