Skip to content

PyMemoryView_FromMemory is part of stable ABI but the flag constants (PyBUF_READ, etc.) are not #98680

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

Closed
asottile opened this issue Oct 25, 2022 · 5 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@asottile
Copy link
Contributor

asottile commented Oct 25, 2022

Feature or enhancement

I'd rather not write:

#ifndef PyBUF_READ
#define PyBUF_READ 0x100
#endif

and instead be able to rely on these even in stable abi mode

relevant error message:

whatever.c:1:30: error: ‘PyBUF_READ’ undeclared (first use in this function)

Linked PRs

@asottile asottile added the type-feature A feature request or enhancement label Oct 25, 2022
@sobolevn sobolevn added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 26, 2022
encukou added a commit to encukou/cpython that referenced this issue Dec 5, 2022
These were available in 3.11.0 with Py_LIMITED_API defined for 3.11,
and are necessary to use the API.

They should be considered part of the 3.11 Limited API.
@encukou
Copy link
Member

encukou commented Dec 5, 2022

whatever.c:1:30: error: ‘PyBUF_READ’ undeclared (first use in this function)

How did you get this error? The flags should be available with #define Py_LIMITED_API 0x030b0000 (3.11).

It's true that they weren't added to the manifest, though. Thanks for catching that!

encukou added a commit to encukou/cpython that referenced this issue Dec 5, 2022
These were available in 3.11.0 with Py_LIMITED_API defined for 3.11,
and are necessary to use the API.

They should be considered part of the 3.11 Limited API.
@asottile
Copy link
Contributor Author

asottile commented Dec 5, 2022

anything older than 3.11 has:

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size,
                                               int flags);
#endif

@encukou
Copy link
Member

encukou commented Dec 5, 2022

Ah! Of course. 3.11 added the whole buffer API and I somehow assumed PyMemoryView_FromMemory was part of that.

If we add the constants retroactively, code that compiles fine on newer Python versions might fail to compile on older ones, even with the same Py_LIMITED_API setting. I'd rather avoid that.
The #ifndef/#define you posted is a good workaround. (Pedantically, it is relying on non-limited API until 3.11, but earlier releases won't change any more so it's fine.)

@asottile
Copy link
Contributor Author

asottile commented Dec 5, 2022

yeah I totally understand -- my bad for not checking 3.11 otherwise this would have been more accurately just a documentation issue /o\

encukou added a commit that referenced this issue Dec 5, 2022
``PyBUF_*`` constants are marked as part of Limited API of Python 3.11+.
These were available in 3.11.0 with `Py_LIMITED_API` defined for 3.11,
and are necessary to use the buffer API. Omitting them in `stable_abi.toml`
was a mistake.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 5, 2022
…honGH-100018)

``PyBUF_*`` constants are marked as part of Limited API of Python 3.11+.
These were available in 3.11.0 with `Py_LIMITED_API` defined for 3.11,
and are necessary to use the buffer API. Omitting them in `stable_abi.toml`
was a mistake.
(cherry picked from commit f247387)

Co-authored-by: Petr Viktorin <[email protected]>
miss-islington added a commit that referenced this issue Dec 5, 2022
``PyBUF_*`` constants are marked as part of Limited API of Python 3.11+.
These were available in 3.11.0 with `Py_LIMITED_API` defined for 3.11,
and are necessary to use the buffer API. Omitting them in `stable_abi.toml`
was a mistake.
(cherry picked from commit f247387)

Co-authored-by: Petr Viktorin <[email protected]>
@encukou
Copy link
Member

encukou commented Dec 6, 2022

Don't feel bad at all -- an issue that's not fully triaged is better than no issue :)
Thanks for reaching out!

@encukou encukou closed this as completed Dec 6, 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) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants