Skip to content

Commit 3d4e533

Browse files
[3.13] gh-112136: Restore removed _PyArg_Parser (GH-121262) (#121344)
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 f8373db) Co-authored-by: Victor Stinner <[email protected]>
1 parent 8799f05 commit 3d4e533

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed

Include/cpython/modsupport.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef Py_CPYTHON_MODSUPPORT_H
2+
# error "this header file must not be included directly"
3+
#endif
4+
5+
// A data structure that can be used to run initialization code once in a
6+
// thread-safe manner. The C++11 equivalent is std::call_once.
7+
typedef struct {
8+
uint8_t v;
9+
} _PyOnceFlag;
10+
11+
typedef struct _PyArg_Parser {
12+
const char *format;
13+
const char * const *keywords;
14+
const char *fname;
15+
const char *custom_msg;
16+
_PyOnceFlag once; /* atomic one-time initialization flag */
17+
int is_kwtuple_owned; /* does this parser own the kwtuple object? */
18+
int pos; /* number of positional-only arguments */
19+
int min; /* minimal number of arguments */
20+
int max; /* maximal number of positional arguments */
21+
PyObject *kwtuple; /* tuple of keyword parameter names */
22+
struct _PyArg_Parser *next;
23+
} _PyArg_Parser;
24+
25+
PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
26+
struct _PyArg_Parser *, ...);

Include/internal/pycore_lock.h

-6
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ _PyRawMutex_Unlock(_PyRawMutex *m)
128128
_PyRawMutex_UnlockSlow(m);
129129
}
130130

131-
// A data structure that can be used to run initialization code once in a
132-
// thread-safe manner. The C++11 equivalent is std::call_once.
133-
typedef struct {
134-
uint8_t v;
135-
} _PyOnceFlag;
136-
137131
// Type signature for one-time initialization functions. The function should
138132
// return 0 on success and -1 on failure.
139133
typedef int _Py_once_fn_t(void *arg);

Include/internal/pycore_modsupport.h

-18
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,6 @@ PyAPI_FUNC(void) _PyArg_BadArgument(
6767

6868
// --- _PyArg_Parser API ---------------------------------------------------
6969

70-
typedef struct _PyArg_Parser {
71-
const char *format;
72-
const char * const *keywords;
73-
const char *fname;
74-
const char *custom_msg;
75-
_PyOnceFlag once; /* atomic one-time initialization flag */
76-
int is_kwtuple_owned; /* does this parser own the kwtuple object? */
77-
int pos; /* number of positional-only arguments */
78-
int min; /* minimal number of arguments */
79-
int max; /* maximal number of positional arguments */
80-
PyObject *kwtuple; /* tuple of keyword parameter names */
81-
struct _PyArg_Parser *next;
82-
} _PyArg_Parser;
83-
84-
// Export for '_testclinic' shared extension
85-
PyAPI_FUNC(int) _PyArg_ParseTupleAndKeywordsFast(PyObject *, PyObject *,
86-
struct _PyArg_Parser *, ...);
87-
8870
// Export for '_dbm' shared extension
8971
PyAPI_FUNC(int) _PyArg_ParseStackAndKeywords(
9072
PyObject *const *args,

Include/modsupport.h

+6
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ PyAPI_FUNC(PyObject *) PyModule_FromDefAndSpec2(PyModuleDef *def,
134134

135135
#endif /* New in 3.5 */
136136

137+
#ifndef Py_LIMITED_API
138+
# define Py_CPYTHON_MODSUPPORT_H
139+
# include "cpython/modsupport.h"
140+
# undef Py_CPYTHON_MODSUPPORT_H
141+
#endif
142+
137143
#ifdef __cplusplus
138144
}
139145
#endif

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ PYTHON_HEADERS= \
11141114
$(srcdir)/Include/cpython/longobject.h \
11151115
$(srcdir)/Include/cpython/memoryobject.h \
11161116
$(srcdir)/Include/cpython/methodobject.h \
1117+
$(srcdir)/Include/cpython/modsupport.h \
11171118
$(srcdir)/Include/cpython/monitoring.h \
11181119
$(srcdir)/Include/cpython/object.h \
11191120
$(srcdir)/Include/cpython/objimpl.h \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Restore the private ``_PyArg_Parser`` structure and the private
2+
``_PyArg_ParseTupleAndKeywordsFast()`` function, previously removed in Python
3+
3.13 alpha 1. Patch by Victor Stinner.

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<ClInclude Include="..\Include\cpython\longobject.h" />
164164
<ClInclude Include="..\Include\cpython\memoryobject.h" />
165165
<ClInclude Include="..\Include\cpython\methodobject.h" />
166+
<ClInclude Include="..\Include\cpython\modsupport.h" />
166167
<ClInclude Include="..\Include\cpython\object.h" />
167168
<ClInclude Include="..\Include\cpython\objimpl.h" />
168169
<ClInclude Include="..\Include\cpython\odictobject.h" />

PCbuild/pythoncore.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@
429429
<ClInclude Include="..\Include\cpython\methodobject.h">
430430
<Filter>Include\cpython</Filter>
431431
</ClInclude>
432+
<ClInclude Include="..\Include\cpython\modsupport.h">
433+
<Filter>Include\cpython</Filter>
434+
</ClInclude>
432435
<ClInclude Include="..\Include\cpython\objimpl.h">
433436
<Filter>Include\cpython</Filter>
434437
</ClInclude>

0 commit comments

Comments
 (0)