]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-112136: Restore removed _PyArg_Parser (GH-121262) (#121344)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 3 Jul 2024 18:29:00 +0000 (20:29 +0200)
committerGitHub <noreply@github.com>
Wed, 3 Jul 2024 18:29:00 +0000 (18:29 +0000)
gh-112136: Restore removed _PyArg_Parser (GH-121262)

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.
(cherry picked from commit f8373db153920b890c2e2dd8def249e8df63bcc6)

Co-authored-by: Victor Stinner <vstinner@python.org>
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 80d609897b4f0c94deeab50bc4b7c9ec2e223854..e6930cc8eecb36414c57056bef6d233b5a61f87e 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 9900560d31255ac2b67e6fee4fe08da24fa40df2..0009374a84f07a2cf2ac7f5cdc64e3ab2523ce10 100644 (file)
@@ -1114,6 +1114,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 33ab50fb8c4b6cd14c0147c70761c6fdecdde010..70212903c83781c1b498c5794f3a529c23ffc267 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 828f14db34e4a82145b7fce44ef10e0f33d0b372..3eed5a9465bca4e4f86cea5ccfad5b4d163b9323 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>