New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyVectorcall_NARGS(): change return type to Py_ssize_t #83792
Comments
I propose to change PyVectorcall_NARGS() return type from unsigned size_t to signed Py_ssize_t. Currently, the function is defined as: static inline Py_ssize_t
PyVectorcall_NARGS(size_t n)
{
return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET;
} But in CPython code base, the result is always stored in a *signed* Py_ssize_t: Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); Sometimes, this nargs is passed to _PyObject_MakeTpCall() which expects nargs to be Py_ssize_t, so it's consistent. In general in CPython, a size uses type Py_ssize_t, not size_t. Example: PyVarObject.ob_size type is Py_ssize_t. |
The current return type already is Py_ssize_t, exactly for the reason you mention – compatibility with all other "argument count" values in Python. (It would be more correct to use unsigned, but that ship has sailed.) The *argument* type is unsigned size_t, though: unsigned is the correct type for for bit fields. Also, the "nargsf" value should never be directly used as argument count; making it a different type tends to trigger nice compiler warnings. |
Closing; please reopen if we're somehow misunderstanding each other :) |
Alright, I was confused by how PyVectorcall_NARGS() is supposed to be used. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: