diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2022-08-11 21:25:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 21:25:49 (GMT) |
commit | 6f6a4e6cc5cd76af4a53ffbb62b686142646ac9a (patch) | |
tree | aeb6de5e55af7bb77acaeccf6d672f725c81aeed /Modules/clinic/pyexpat.c.h | |
parent | bdb2cf8e913c041f26e8976abe58414819b3e8ff (diff) | |
download | cpython-6f6a4e6cc5cd76af4a53ffbb62b686142646ac9a.zip cpython-6f6a4e6cc5cd76af4a53ffbb62b686142646ac9a.tar.gz cpython-6f6a4e6cc5cd76af4a53ffbb62b686142646ac9a.tar.bz2 |
gh-90928: Statically Initialize the Keywords Tuple in Clinic-Generated Code (gh-95860)
We only statically initialize for core code and builtin modules. Extension modules still create
the tuple at runtime. We'll solve that part of interpreter isolation separately.
This change includes generated code. The non-generated changes are in:
* Tools/clinic/clinic.py
* Python/getargs.c
* Include/cpython/modsupport.h
* Makefile.pre.in (re-generate global strings after running clinic)
* very minor tweaks to Modules/_codecsmodule.c and Python/Python-tokenize.c
All other changes are generated code (clinic, global strings).
Diffstat (limited to 'Modules/clinic/pyexpat.c.h')
-rw-r--r-- | Modules/clinic/pyexpat.c.h | 183 |
1 files changed, 177 insertions, 6 deletions
diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h index b264832..e8947aa 100644 --- a/Modules/clinic/pyexpat.c.h +++ b/Modules/clinic/pyexpat.c.h @@ -2,6 +2,12 @@ preserve [clinic start generated code]*/ +#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) +# include "pycore_gc.h" // PyGC_Head +# include "pycore_runtime.h" // _Py_ID() +#endif + + PyDoc_STRVAR(pyexpat_xmlparser_Parse__doc__, "Parse($self, data, isfinal=False, /)\n" "--\n" @@ -21,8 +27,41 @@ static PyObject * pyexpat_xmlparser_Parse(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #define NUM_KEYWORDS 0 + #if NUM_KEYWORDS == 0 + + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + # else + # define KWTUPLE NULL + # endif + + #else // NUM_KEYWORDS != 0 + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { }, + }; + # define KWTUPLE (&_kwtuple.ob_base.ob_base) + + # else // !Py_BUILD_CORE + # define KWTUPLE NULL + # endif // !Py_BUILD_CORE + #endif // NUM_KEYWORDS != 0 + #undef NUM_KEYWORDS + static const char * const _keywords[] = {"", "", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "Parse", 0}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "Parse", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE PyObject *argsbuf[2]; PyObject *data; int isfinal = 0; @@ -63,8 +102,41 @@ static PyObject * pyexpat_xmlparser_ParseFile(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #define NUM_KEYWORDS 0 + #if NUM_KEYWORDS == 0 + + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + # else + # define KWTUPLE NULL + # endif + + #else // NUM_KEYWORDS != 0 + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { }, + }; + # define KWTUPLE (&_kwtuple.ob_base.ob_base) + + # else // !Py_BUILD_CORE + # define KWTUPLE NULL + # endif // !Py_BUILD_CORE + #endif // NUM_KEYWORDS != 0 + #undef NUM_KEYWORDS + static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "ParseFile", 0}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "ParseFile", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE PyObject *argsbuf[1]; PyObject *file; @@ -175,8 +247,41 @@ static PyObject * pyexpat_xmlparser_ExternalEntityParserCreate(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #define NUM_KEYWORDS 0 + #if NUM_KEYWORDS == 0 + + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + # else + # define KWTUPLE NULL + # endif + + #else // NUM_KEYWORDS != 0 + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { }, + }; + # define KWTUPLE (&_kwtuple.ob_base.ob_base) + + # else // !Py_BUILD_CORE + # define KWTUPLE NULL + # endif // !Py_BUILD_CORE + #endif // NUM_KEYWORDS != 0 + #undef NUM_KEYWORDS + static const char * const _keywords[] = {"", "", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "ExternalEntityParserCreate", 0}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "ExternalEntityParserCreate", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE PyObject *argsbuf[2]; const char *context; const char *encoding = NULL; @@ -282,8 +387,41 @@ static PyObject * pyexpat_xmlparser_UseForeignDTD(xmlparseobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #define NUM_KEYWORDS 0 + #if NUM_KEYWORDS == 0 + + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + # else + # define KWTUPLE NULL + # endif + + #else // NUM_KEYWORDS != 0 + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { }, + }; + # define KWTUPLE (&_kwtuple.ob_base.ob_base) + + # else // !Py_BUILD_CORE + # define KWTUPLE NULL + # endif // !Py_BUILD_CORE + #endif // NUM_KEYWORDS != 0 + #undef NUM_KEYWORDS + static const char * const _keywords[] = {"", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "UseForeignDTD", 0}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "UseForeignDTD", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE PyObject *argsbuf[1]; int flag = 1; @@ -325,8 +463,41 @@ static PyObject * pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; + #define NUM_KEYWORDS 3 + #if NUM_KEYWORDS == 0 + + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) + # else + # define KWTUPLE NULL + # endif + + #else // NUM_KEYWORDS != 0 + # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) + + static struct { + PyGC_Head _this_is_not_used; + PyObject_VAR_HEAD + PyObject *ob_item[NUM_KEYWORDS]; + } _kwtuple = { + .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) + .ob_item = { &_Py_ID(encoding), &_Py_ID(namespace_separator), &_Py_ID(intern), }, + }; + # define KWTUPLE (&_kwtuple.ob_base.ob_base) + + # else // !Py_BUILD_CORE + # define KWTUPLE NULL + # endif // !Py_BUILD_CORE + #endif // NUM_KEYWORDS != 0 + #undef NUM_KEYWORDS + static const char * const _keywords[] = {"encoding", "namespace_separator", "intern", NULL}; - static _PyArg_Parser _parser = {NULL, _keywords, "ParserCreate", 0}; + static _PyArg_Parser _parser = { + .keywords = _keywords, + .fname = "ParserCreate", + .kwtuple = KWTUPLE, + }; + #undef KWTUPLE PyObject *argsbuf[3]; Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; const char *encoding = NULL; @@ -425,4 +596,4 @@ exit: #ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF #endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */ -/*[clinic end generated code: output=3e333b89da3aa58c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=94c16fdc27f36fae input=a9049054013a1b77]*/ |