Skip to content
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

Closed
petere mannequin opened this issue Jan 29, 2011 · 6 comments
Closed

Py_LIMITED_API breaks most PySomething_Check() functions #55276

petere mannequin opened this issue Jan 29, 2011 · 6 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error

Comments

@petere
Copy link
Mannequin

petere mannequin commented Jan 29, 2011

BPO 11067
Nosy @loewis, @birkenfeld, @pitrou, @asvetlov, @petere
Files
  • unisub.diff
  • tp_flags.diff
  • 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:

    assignee = None
    closed_at = <Date 2011-02-05.20:36:14.380>
    created_at = <Date 2011-01-29.21:34:46.259>
    labels = ['interpreter-core', 'type-bug', 'release-blocker']
    title = 'Py_LIMITED_API breaks most PySomething_Check() functions'
    updated_at = <Date 2011-02-05.20:36:14.379>
    user = 'https://github.com/petere'

    bugs.python.org fields:

    activity = <Date 2011-02-05.20:36:14.379>
    actor = 'loewis'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-02-05.20:36:14.380>
    closer = 'loewis'
    components = ['Interpreter Core']
    creation = <Date 2011-01-29.21:34:46.259>
    creator = 'petere'
    dependencies = []
    files = ['20646', '20678']
    hgrepos = []
    issue_num = 11067
    keywords = ['patch']
    message_count = 6.0
    messages = ['127488', '127727', '127729', '127924', '127939', '128023']
    nosy_count = 5.0
    nosy_names = ['loewis', 'georg.brandl', 'pitrou', 'asvetlov', 'petere']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'accepted'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue11067'
    versions = ['Python 3.2']

    @petere
    Copy link
    Mannequin Author

    petere mannequin commented Jan 29, 2011

    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;
    PyUnicode_Check(o); 
    

    }

    test.c: In function ‘foo’:
    test.c:9: error: dereferencing pointer to incomplete type

    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.

    @pitrou pitrou added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 29, 2011
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Feb 2, 2011

    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.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Feb 2, 2011

    Reconsidering: it's better to use PyType_IsSubtype, as this matches better the fast check.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Feb 4, 2011

    Here is the patch I'd like to add to 3.2: this adds PyType_GetFlags, so that the fast checks remain available.

    @loewis loewis mannequin added the release-blocker label Feb 4, 2011
    @pitrou
    Copy link
    Member

    pitrou commented Feb 4, 2011

    The doc needs a versionadded attribute. Otherwise, looks good to me.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Feb 5, 2011

    Thanks for the review. Committed as r88351.

    @loewis loewis mannequin closed this as completed Feb 5, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant