PEP 590: Use size_t for "number of arguments + flag" (GH-1066)

Bitwise operations are not well defined on signed values in C.
This commit is contained in:
Petr Viktorin 2019-05-28 11:34:02 +02:00 committed by GitHub
parent 8363d1f06c
commit 2d9833abd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -65,11 +65,11 @@ Calls are made through a function pointer taking the following parameters:
* ``PyObject *callable``: The called object
* ``PyObject *const *args``: A vector of arguments
* ``Py_ssize_t nargs``: The number of arguments plus the optional flag ``PY_VECTORCALL_ARGUMENTS_OFFSET`` (see below)
* ``size_t nargs``: The number of arguments plus the optional flag ``PY_VECTORCALL_ARGUMENTS_OFFSET`` (see below)
* ``PyObject *kwnames``: Either ``NULL`` or a tuple with the names of the keyword arguments
This is implemented by the function pointer type:
``typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames);``
``typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args, size_t nargs, PyObject *kwnames);``
Changes to the ``PyTypeObject`` struct
--------------------------------------
@ -138,7 +138,7 @@ New C API and changes to CPython
The following functions or macros are added to the C API:
- ``PyObject *_PyObject_Vectorcall(PyObject *obj, PyObject *const *args, Py_ssize_t nargs, PyObject *keywords)``:
- ``PyObject *_PyObject_Vectorcall(PyObject *obj, PyObject *const *args, size_t nargs, PyObject *keywords)``:
Calls ``obj`` with the given arguments.
Note that ``nargs`` may include the flag ``PY_VECTORCALL_ARGUMENTS_OFFSET``.
The actual number of positional arguments is given by ``PyVectorcall_NARGS(nargs)``.
@ -152,7 +152,7 @@ The following functions or macros are added to the C API:
``*args`` and ``**kwargs`` calling convention.
This is mostly meant to put in the ``tp_call`` slot.
- ``Py_ssize_t PyVectorcall_NARGS(Py_ssize nargs)``: Given a vectorcall ``nargs`` argument,
- ``Py_ssize_t PyVectorcall_NARGS(size_t nargs)``: Given a vectorcall ``nargs`` argument,
return the actual number of arguments.
Currently equivalent to ``nargs & ~PY_VECTORCALL_ARGUMENTS_OFFSET``.