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
Py_LIMITED_API breaks most PySomething_Check() functions #55276
Comments
When setting Py_LIMITED_API, functions such as PyUnicode_Check() can no longer be used. Example: #define Py_LIMITED_API
#include <Python.h>
void foo()
{
PyObject *o;
} test.c: In function ‘foo’: PEP-384 contains some nested language that suggests that the _Check macros should be available under the limited API. And it seems to me that they easily could be, if Py_TYPE were implemented as a function instead of a macro. |
The fast subtype checks cannot be supported in the limited API, as the layout of type objects is intentionally not exposed. It would be possible to expose a getter for the type flags; the individual flag values *are* part of the ABI. I propose the attached patch, which replaces the fast subtype check with a slow one in the limited API. The patch would need to be extended to all subtype checks. It's not strictly necessary to include this patch into the 3.2 release; users could also explicitly call PyObject_IsSubclass as a work-around. The patch could then be added for 3.2.1. As another work-around, users can also use PyUnicode_CheckExact, which is even faster and might be correct in many cases as well. |
Reconsidering: it's better to use PyType_IsSubtype, as this matches better the fast check. |
Here is the patch I'd like to add to 3.2: this adds PyType_GetFlags, so that the fast checks remain available. |
The doc needs a versionadded attribute. Otherwise, looks good to me. |
Thanks for the review. Committed as r88351. |
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: