]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112136: Restore removed _PyArg_Parser (#121262)
authorVictor Stinner <vstinner@python.org>
Wed, 3 Jul 2024 16:36:57 +0000 (18:36 +0200)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2024 16:36:57 +0000 (18:36 +0200)
Restore the private _PyArg_Parser structure and the private
_PyArg_ParseTupleAndKeywordsFast() function, previously removed
in Python 3.13 alpha 1.

Recreate Include/cpython/modsupport.h header file.

Include/cpython/modsupport.h [new file with mode: 0644]
Include/internal/pycore_lock.h
Include/internal/pycore_modsupport.h
Include/modsupport.h
Makefile.pre.in
Misc/NEWS.d/next/C API/2024-07-02-11-03-40.gh-issue-112136.f3fiY8.rst [new file with mode: 0644]
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters

diff --git a/Include/cpython/modsupport.h b/Include/cpython/modsupport.h
new file mode 100644 (file)
index 0000000..d3b88f5
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef Py_CPYTHON_MODSUPPORT_H
+#  error "this header file must not be included directly"
+#endif
+
+// A data structure that can be used to run initialization code once in a
+// thread-safe manner. The C++11 equivalent is std::call_once.
+typedef struct {
+    uint8_t v;
+} _PyOnceFlag;
+
+typedef struct _PyArg_Parser {
+    const char *format;
+    const char * const *keywords;
+    const char *fname;
+    const char *custom_msg;
+    _PyOnceFlag once;       /* atomic one-time initialization flag */
+    int is_kwtuple_owned;   /* does this parser own the kwtuple object? */
+    int pos;                /* number of positional-only arguments */
+    int min;                /* minimal number of arguments */
+    int max;                /* maximal number of positional arguments */
+    PyObject *kwtuple;      /* tuple of keyword parameter names */
+    struct _PyArg_Parser *next;
+} _PyArg_Parser;
+
+PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
+                                                 struct _PyArg_Parser *, ...);
index 8aa73946e2c6451aa162dcfb39a054e0c1c9a1c6..3824434f3f375d300761ba9d60a7ef404c7b4735 100644 (file)
@@ -128,12 +128,6 @@ _PyRawMutex_Unlock(_PyRawMutex *m)
     _PyRawMutex_UnlockSlow(m);
 }
 
-// A data structure that can be used to run initialization code once in a
-// thread-safe manner. The C++11 equivalent is std::call_once.
-typedef struct {
-    uint8_t v;
-} _PyOnceFlag;
-
 // Type signature for one-time initialization functions. The function should
 // return 0 on success and -1 on failure.
 typedef int _Py_once_fn_t(void *arg);
index 3d3cd6722528e93070782af07e1f7e0776bacbba..11fde814875938f23768d517a5434032502b9298 100644 (file)
@@ -67,24 +67,6 @@ PyAPI_FUNC(void) _PyArg_BadArgument(
 
 // --- _PyArg_Parser API ---------------------------------------------------
 
-typedef struct _PyArg_Parser {
-    const char *format;
-    const char * const *keywords;
-    const char *fname;
-    const char *custom_msg;
-    _PyOnceFlag once;       /* atomic one-time initialization flag */
-    int is_kwtuple_owned;   /* does this parser own the kwtuple object? */
-    int pos;                /* number of positional-only arguments */
-    int min;                /* minimal number of arguments */
-    int max;                /* maximal number of positional arguments */
-    PyObject *kwtuple;      /* tuple of keyword parameter names */
-    struct _PyArg_Parser *next;
-} _PyArg_Parser;
-
-// Export for '_testclinic' shared extension
-PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
-                                                 struct _PyArg_Parser *, ...);
-
 // Export for '_dbm' shared extension
 PyAPI_FUNC(int) _PyArg_ParseStackAndKeywords(
     PyObject *const *args,
index ea4c0fce9f4562c0bc046ecc2c3396fb34b13b51..af995f567b004c9a288f57118e16dab74be47878 100644 (file)
@@ -134,6 +134,12 @@ PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
 
 #endif /* New in 3.5 */
 
+#ifndef Py_LIMITED_API
+#  define Py_CPYTHON_MODSUPPORT_H
+#  include "cpython/modsupport.h"
+#  undef Py_CPYTHON_MODSUPPORT_H
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index e1c793ce629b02c53519a0909c75ef6f69d54991..94cfb74138a3d9906de424de5c7a6fbc840490b3 100644 (file)
@@ -1115,6 +1115,7 @@ PYTHON_HEADERS= \
                $(srcdir)/Include/cpython/longobject.h \
                $(srcdir)/Include/cpython/memoryobject.h \
                $(srcdir)/Include/cpython/methodobject.h \
+               $(srcdir)/Include/cpython/modsupport.h \
                $(srcdir)/Include/cpython/monitoring.h \
                $(srcdir)/Include/cpython/object.h \
                $(srcdir)/Include/cpython/objimpl.h \
diff --git a/Misc/NEWS.d/next/C API/2024-07-02-11-03-40.gh-issue-112136.f3fiY8.rst b/Misc/NEWS.d/next/C API/2024-07-02-11-03-40.gh-issue-112136.f3fiY8.rst
new file mode 100644 (file)
index 0000000..a240b4e
--- /dev/null
@@ -0,0 +1,3 @@
+Restore the private ``_PyArg_Parser`` structure and the private
+``_PyArg_ParseTupleAndKeywordsFast()`` function, previously removed in Python
+3.13 alpha 1. Patch by Victor Stinner.
index 3378ed54203f1886450275dbc8203b3fbe72f905..f36fcb8caece330e7ce0ac80778b10d46e7f3d5f 100644 (file)
     <ClInclude Include="..\Include\cpython\longobject.h" />
     <ClInclude Include="..\Include\cpython\memoryobject.h" />
     <ClInclude Include="..\Include\cpython\methodobject.h" />
+    <ClInclude Include="..\Include\cpython\modsupport.h" />
     <ClInclude Include="..\Include\cpython\object.h" />
     <ClInclude Include="..\Include\cpython\objimpl.h" />
     <ClInclude Include="..\Include\cpython\odictobject.h" />
index 742d88d9e1fa7a518ee8139a6774a17418dc33e4..a1b43addf9e36a6b00ffb401c2f5a720147ccd05 100644 (file)
     <ClInclude Include="..\Include\cpython\methodobject.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>
+    <ClInclude Include="..\Include\cpython\modsupport.h">
+      <Filter>Include\cpython</Filter>
+    </ClInclude>
     <ClInclude Include="..\Include\cpython\objimpl.h">
       <Filter>Include\cpython</Filter>
     </ClInclude>