Skip to content

Commit 74319ae

Browse files
committed
Use Py_ssize_t type for number of arguments
Issue python#27848: use Py_ssize_t rather than C int for the number of function positional and keyword arguments.
1 parent c532b3c commit 74319ae

7 files changed

Lines changed: 128 additions & 90 deletions

File tree

Include/abstract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
280280
Return the result on success. Raise an exception on return NULL on
281281
error. */
282282
PyAPI_FUNC(PyObject *) _PyObject_FastCallDict(PyObject *func,
283-
PyObject **args, int nargs,
283+
PyObject **args, Py_ssize_t nargs,
284284
PyObject *kwargs);
285285

286286
#define _PyObject_FastCall(func, args, nargs) \

Include/funcobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ PyAPI_FUNC(int) PyFunction_SetAnnotations(PyObject *, PyObject *);
6161
#ifndef Py_LIMITED_API
6262
PyAPI_FUNC(PyObject *) _PyFunction_FastCallDict(
6363
PyObject *func,
64-
PyObject **args, int nargs,
64+
PyObject **args,
65+
Py_ssize_t nargs,
6566
PyObject *kwargs);
6667
#endif
6768

Include/methodobject.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *);
3939

4040
#ifndef Py_LIMITED_API
4141
PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func,
42-
PyObject **args, int nargs,
42+
PyObject **args,
43+
Py_ssize_t nargs,
4344
PyObject *kwargs);
4445
#endif
4546

Objects/abstract.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ _PyStack_AsTuple(PyObject **stack, Py_ssize_t nargs)
22552255
}
22562256

22572257
PyObject *
2258-
_PyObject_FastCallDict(PyObject *func, PyObject **args, int nargs,
2258+
_PyObject_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
22592259
PyObject *kwargs)
22602260
{
22612261
ternaryfunc call;

Objects/methodobject.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,20 @@ PyCFunction_Call(PyObject *func, PyObject *args, PyObject *kwds)
146146
}
147147

148148
PyObject *
149-
_PyCFunction_FastCallDict(PyObject *func_obj, PyObject **args, int nargs,
149+
_PyCFunction_FastCallDict(PyObject *func_obj, PyObject **args, Py_ssize_t nargs,
150150
PyObject *kwargs)
151151
{
152-
PyCFunctionObject* func = (PyCFunctionObject*)func_obj;
152+
PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
153153
PyCFunction meth = PyCFunction_GET_FUNCTION(func);
154154
PyObject *self = PyCFunction_GET_SELF(func);
155155
PyObject *result;
156156
int flags;
157157

158+
assert(func != NULL);
159+
assert(nargs >= 0);
160+
assert(nargs == 0 || args != NULL);
161+
assert(kwargs == NULL || PyDict_Check(kwargs));
162+
158163
/* _PyCFunction_FastCallDict() must not be called with an exception set,
159164
because it may clear it (directly or indirectly) and so the
160165
caller loses its exception */

Python/bltinmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
20952095
PyObject *callable;
20962096
static char *kwlist[] = {"iterable", "key", "reverse", 0};
20972097
int reverse;
2098-
int nargs;
2098+
Py_ssize_t nargs;
20992099

21002100
/* args 1-3 should match listsort in Objects/listobject.c */
21012101
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",

0 commit comments

Comments
 (0)