mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-110964: Remove private _PyArg functions (#110966)
Move the following private functions and structures to pycore_modsupport.h internal C API: * _PyArg_BadArgument() * _PyArg_CheckPositional() * _PyArg_NoKeywords() * _PyArg_NoPositional() * _PyArg_ParseStack() * _PyArg_ParseStackAndKeywords() * _PyArg_Parser structure * _PyArg_UnpackKeywords() * _PyArg_UnpackKeywordsWithVararg() * _PyArg_UnpackStack() * _Py_ANY_VARARGS() Changes: * Python/getargs.h now includes pycore_modsupport.h to export functions. * clinic.py now adds pycore_modsupport.h when one of these functions is used. * Add pycore_modsupport.h includes when a C extension uses one of these functions. * Define Py_BUILD_CORE_MODULE in C extensions which now include directly or indirectly (via code generated by Argument Clinic) pycore_modsupport.h: * _csv * _curses_panel * _dbm * _gdbm * _multiprocessing.posixshmem * _sqlite.row * _statistics * grp * resource * syslog * _testcapi: bad_get() no longer uses METH_FASTCALL calling convention but METH_VARARGS. Replace _PyArg_UnpackStack() with PyArg_ParseTuple(). * _testcapi: add PYTESTCAPI_NEED_INTERNAL_API macro which is defined by _testcapi sub-modules which need the internal C API (pycore_modsupport.h): exceptions.c, float.c, vectorcall.c, watchers.c. * Remove Include/cpython/modsupport.h header file. Include/modsupport.h no longer includes the removed header file. * Fix mypy clinic.py
This commit is contained in:
parent
054f496bd4
commit
be5e8a0103
166 changed files with 511 additions and 229 deletions
|
@ -13,6 +13,24 @@ extern int _PyArg_NoKwnames(const char *funcname, PyObject *kwnames);
|
|||
#define _PyArg_NoKwnames(funcname, kwnames) \
|
||||
((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames)))
|
||||
|
||||
// Export for '_bz2' shared extension
|
||||
PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
|
||||
#define _PyArg_NoPositional(funcname, args) \
|
||||
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
|
||||
|
||||
// Export for '_asyncio' shared extension
|
||||
PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
|
||||
#define _PyArg_NoKeywords(funcname, kwargs) \
|
||||
((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
|
||||
|
||||
// Export for 'zlib' shared extension
|
||||
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
|
||||
Py_ssize_t, Py_ssize_t);
|
||||
#define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX)
|
||||
#define _PyArg_CheckPositional(funcname, nargs, min, max) \
|
||||
((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
|
||||
|| _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
|
||||
|
||||
extern PyObject ** _Py_VaBuildStack(
|
||||
PyObject **small_stack,
|
||||
Py_ssize_t small_stack_len,
|
||||
|
@ -22,6 +40,80 @@ extern PyObject ** _Py_VaBuildStack(
|
|||
|
||||
extern PyObject* _PyModule_CreateInitialized(PyModuleDef*, int apiver);
|
||||
|
||||
// Export for '_curses' shared extension
|
||||
PyAPI_FUNC(int) _PyArg_ParseStack(
|
||||
PyObject *const *args,
|
||||
Py_ssize_t nargs,
|
||||
const char *format,
|
||||
...);
|
||||
|
||||
extern int _PyArg_UnpackStack(
|
||||
PyObject *const *args,
|
||||
Py_ssize_t nargs,
|
||||
const char *name,
|
||||
Py_ssize_t min,
|
||||
Py_ssize_t max,
|
||||
...);
|
||||
|
||||
// Export for '_heapq' shared extension
|
||||
PyAPI_FUNC(void) _PyArg_BadArgument(
|
||||
const char *fname,
|
||||
const char *displayname,
|
||||
const char *expected,
|
||||
PyObject *arg);
|
||||
|
||||
// --- _PyArg_Parser API ---------------------------------------------------
|
||||
|
||||
typedef struct _PyArg_Parser {
|
||||
int initialized;
|
||||
const char *format;
|
||||
const char * const *keywords;
|
||||
const char *fname;
|
||||
const char *custom_msg;
|
||||
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,
|
||||
Py_ssize_t nargs,
|
||||
PyObject *kwnames,
|
||||
struct _PyArg_Parser *,
|
||||
...);
|
||||
|
||||
// Export for 'math' shared extension
|
||||
PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywords(
|
||||
PyObject *const *args,
|
||||
Py_ssize_t nargs,
|
||||
PyObject *kwargs,
|
||||
PyObject *kwnames,
|
||||
struct _PyArg_Parser *parser,
|
||||
int minpos,
|
||||
int maxpos,
|
||||
int minkw,
|
||||
PyObject **buf);
|
||||
#define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
|
||||
(((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
|
||||
(minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? (args) : \
|
||||
_PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
|
||||
(minpos), (maxpos), (minkw), (buf)))
|
||||
|
||||
// Export for '_testclinic' shared extension
|
||||
PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(
|
||||
PyObject *const *args, Py_ssize_t nargs,
|
||||
PyObject *kwargs, PyObject *kwnames,
|
||||
struct _PyArg_Parser *parser,
|
||||
int minpos, int maxpos, int minkw,
|
||||
int vararg, PyObject **buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue