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

Remove broken PySequence_Fast() function from the limited C API #55

Closed
5 of 6 tasks
vstinner opened this issue Jan 29, 2025 · 4 comments
Closed
5 of 6 tasks

Remove broken PySequence_Fast() function from the limited C API #55

vstinner opened this issue Jan 29, 2025 · 4 comments

Comments

@vstinner
Copy link

vstinner commented Jan 29, 2025

The limited C API has the function PySequence_Fast() which should be used with these macros:

  • PySequence_Fast_GET_SIZE()
  • PySequence_Fast_GET_ITEM()
  • PySequence_Fast_ITEMS()

Problem: none of these 3 macros work with the limited C API. The whole PySequence_Fast() API is broken in the limited C API.

Example:

#define PySequence_Fast_GET_ITEM(o, i)\
     (PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i)))

PyList_GET_ITEM() and PyTuple_GET_ITEM() are not part of the limited C API, so PySequence_Fast_GET_ITEM() cannot be used in the limited C API.

I propose to remove PySequence_Fast() and these 3 macros from the limited C API, since they are incompatible and never worked with the limited C API.

Vote:

@serhiy-storchaka
Copy link

I support this. It is clear to me that they were not excluded from the limited C API due to oversight.

PySequence_ITEM also slipped in the limited C API. It was excluded in issue python/cpython#77919 (PR python/cpython#7477).

@encukou
Copy link
Collaborator

encukou commented Jan 30, 2025

+1 for removing the macros; yes, they never worked in limited API (and since PEP 652 they were never “officially” part of limited API); moving them to Include/cpython is the right thing to do.

The PySequence_Fast function itself works. Third-party code can, theoretically, require a result of PySequence_Fast as input.
If y'all think it should go I won't block the removal, but I think it's unnecessary. As minor, benign mistake of the past, it doesn't need fixing.

@vstinner
Copy link
Author

Ping @erlend-aasland.

@vstinner
Copy link
Author

vstinner commented Feb 2, 2025

Thanks for voting. I close the issue.

@encukou:

Third-party code can, theoretically, require a result of PySequence_Fast as input.
If y'all think it should go I won't block the removal, but I think it's unnecessary.

At least, the function remains available in the stable ABI.

@vstinner vstinner closed this as completed Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants