Skip to content

Commit

Permalink
pythongh-112136: Restore removed _PyArg_Parser
Browse files Browse the repository at this point in the history
Restore removed private _PyArg_Parser structure and private
_PyArg_ParseTupleAndKeywordsFast() function.

Recreate Include/cpython/modsupport.h header file.
  • Loading branch information
vstinner committed Jul 2, 2024
1 parent b505334 commit c6703e5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
20 changes: 20 additions & 0 deletions Include/cpython/modsupport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef Py_CPYTHON_MODSUPPORT_H
# error "this header file must not be included directly"
#endif

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 *, ...);
18 changes: 0 additions & 18 deletions Include/internal/pycore_modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions Include/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Restore removed private ``_PyArg_Parser`` structure and private
``_PyArg_ParseTupleAndKeywordsFast()`` function. Patch by Victor Stinner.
1 change: 1 addition & 0 deletions PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<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" />
Expand Down
3 changes: 3 additions & 0 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@
<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>
Expand Down

0 comments on commit c6703e5

Please sign in to comment.