classification
Title: Py_LIMITED_API breaks most PySomething_Check() functions
Type: behavior Stage: commit review
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, georg.brandl, loewis, petere, pitrou
Priority: release blocker Keywords: patch

Created on 2011-01-29 21:34 by petere, last changed 2011-02-05 20:36 by loewis. This issue is now closed.

Files
File name Uploaded Description Edit
unisub.diff loewis, 2011-02-02 09:31
tp_flags.diff loewis, 2011-02-04 19:30
Messages (6)
msg127488 - (view) Author: Peter Eisentraut (petere) * Date: 2011-01-29 21:34
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.
msg127727 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-02 08:58
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.
msg127729 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-02 09:31
Reconsidering: it's better to use PyType_IsSubtype, as this matches better the fast check.
msg127924 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-04 19:30
Here is the patch I'd like to add to 3.2: this adds PyType_GetFlags, so that the fast checks remain available.
msg127939 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-02-04 20:35
The doc needs a versionadded attribute. Otherwise, looks good to me.
msg128023 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-02-05 20:36
Thanks for the review. Committed as r88351.
History
Date User Action Args
2011-02-05 20:36:14loewissetstatus: open -> closed
nosy: loewis, georg.brandl, pitrou, asvetlov, petere
messages: + msg128023
2011-02-04 20:35:10pitrousetnosy: + pitrou
messages: + msg127939

resolution: accepted
stage: commit review
2011-02-04 19:30:10loewissetfiles: + tp_flags.diff
priority: normal -> release blocker

nosy: + georg.brandl
messages: + msg127924
2011-02-04 08:31:49asvetlovsetnosy: + asvetlov
2011-02-02 09:31:01loewissetfiles: + unisub.diff

messages: + msg127729
2011-02-02 09:30:04loewissetfiles: - unisub.diff
2011-02-02 09:22:05loewissetfiles: + unisub.diff
2011-02-02 09:21:54loewissetfiles: - unisub.diff
2011-02-02 08:58:48loewissetfiles: + unisub.diff

messages: + msg127727
keywords: + patch
2011-01-29 21:39:40pitrousetnosy: + loewis
type: behavior
components: + Interpreter Core, - None
2011-01-29 21:34:46peterecreate