Skip to content

refactor: Use functions from limited API #542

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
wants to merge 1 commit into from

Conversation

tiran
Copy link
Member

@tiran tiran commented Oct 30, 2023

Replace unsafe macros and direct struct access with functions from the subset of limited API functions.

  • PySequence_Fast_GET_ITEM -> PySequence_GetItem
  • PyTuple_SET_ITEM -> PyTuple_SetItem
  • PyList_SET_ITEM -> PyList_SetItem
  • PyUnicode_AsUTF8AndSize -> PyUnicode_AsUTF8String + PyBytes_AsStringAndSize. The function PyUnicode_AsUTF8AndSize is not in limited API before Python 3.10.
  • const char *tp_name -> Py_TYPE() string representation

See: #540

@mistotebe
Copy link
Contributor

Shouldn't this also enable the limited API so the changes are exercised immediately?

@tiran
Copy link
Member Author

tiran commented Oct 30, 2023

This PR only replaces a few functions that are outside the limited API set. I have split my original work into smaller chunks, that are easier to understand and review. There is a bunch of more work to do before I can enable the limited API, e.g. port LDAP_Type to heap type.

@mistotebe
Copy link
Contributor

This PR only replaces a few functions that are outside the limited API set. I have split my original work into smaller chunks, that are easier to understand and review. There is a bunch of more work to do before I can enable the limited API, e.g. port LDAP_Type to heap type.

Right I assumed it was considered ready for review, not a draft?

@tiran
Copy link
Member Author

tiran commented Oct 30, 2023

Right I assumed it was considered ready for review, not a draft?

I don't follow. This PR is not a draft and is ready for review.

I'm sorry if I wasn't clear. I want to split the work on #540 into small, digestible chunks. Each PR will improve and change one aspect of the code base. Every PR will also leave the code base in working conditions with all tests passing.

This approach makes it easier for you and @droideck to review and verify the changes. Some changes are not obvious unless you are familiar with stable ABI and module states. I estimate that #540 is going to take around 6 to 7 PRs in total.

@mistotebe
Copy link
Contributor

Hmm, sure, but at this point how do I tell whether the PR is useful? It gives no clear way to see if something has been missed for one.

I can see #540 is large and you want to split it into different parts (and get your point there) but I'd still expect each PR to be a patchset with a clear intent along the path that gets realised (somewhat) by the end of it, not necessarily one patch per PR if that makes sense? This PR as it stands looks like one commit that can't be reviewed alone, which might change if more commits were added to it (e.g. being able to limit ourselves to the stable ABI for 3.x+ and enforcing that).

You are welcome to disagree but then I'll have to recuse myself from reviewing this.

@tiran tiran force-pushed the issue540-limited-api branch from bad8aef to b45e0c3 Compare November 1, 2023 06:10
@tiran
Copy link
Member Author

tiran commented Nov 1, 2023

But this PR has a clear intent; it replaces several macros, one function, and one case of direct struct access with features from the limited API. To review the PR, you look up the documentation of each replaced function / macro, check that the old code is not marked for Part of the Stable ABI, and the new code is in the stable ABI for 3.6+.

You could argue that my patch may be missing some function replacements. That's not a problem, we can address that in another commit. The important bit is that this PR does not introduce a regression.

@tiran tiran force-pushed the issue540-limited-api branch from b45e0c3 to c37d196 Compare November 3, 2023 10:03
Replace unsafe macros and direct struct access with functions from
the subset of limited API functions.

* `PySequence_Fast_GET_ITEM` -> `PySequence_GetItem`
* `PyTuple_SET_ITEM` -> `PyTuple_SetItem`
* `PyList_SET_ITEM` -> `PyList_SetItem`
* `PyUnicode_AsUTF8AndSize` -> `PyUnicode_AsUTF8String` +
  `PyBytes_AsStringAndSize`. The function `PyUnicode_AsUTF8AndSize` is
  not in limited API before Python 3.10.
* `const char *tp_name` -> `Py_TYPE()` string representation

See: python-ldap#540
Signed-off-by: Christian Heimes <cheimes@redhat.com>
@tiran tiran force-pushed the issue540-limited-api branch from c37d196 to 5d49f27 Compare November 3, 2023 10:08
@tiran tiran closed this Feb 12, 2024
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

Successfully merging this pull request may close these issues.

3 participants