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

Avoid using Py_OptimizeFlag in the Limited API. #5606

Merged
merged 2 commits into from
Aug 11, 2023

Conversation

scoder
Copy link
Contributor

@scoder scoder commented Aug 9, 2023

Closes #5605

@scoder
Copy link
Contributor Author

scoder commented Aug 9, 2023

I actually wonder if it's worth using the (not so public) _PyConfig_… C-API for the "normal" CPython case. It's a one time price to pay at import time, so it might simply be enough to do the same dance also in CPython 3.12 and later (without Limited API).

@da-woods
Copy link
Contributor

da-woods commented Aug 9, 2023

I wonder if you could pass the module in as an argument - I think the function might be defined too early to have access to the module object.

Apart from that, it looks simpler (and better) than what I was planning.

@da-woods
Copy link
Contributor

I wonder if you could pass the module in as an argument

This doesn't work, but:

if self.init:
writer = output['init_globals']
writer.putln("/* %s.init */" % self.name)
if isinstance(self.init, basestring):
writer.put(self.format_code(self.init))
else:
self.init(writer, output.module_pos)
writer.putln(writer.error_goto_if_PyErr(output.module_pos))
writer.putln()

It looks like it checks for PyErr_Occurred after each of these init segments, so there's no need to write unraisable.

I actually wonder if it's worth using the (not so public) PyConfig… C-API for the "normal" CPython case. It's a one time price to pay at import time, so it might simply be enough to do the same dance also in CPython 3.12 and later (without Limited API).

Inclined to agree with this.

…d otherwise end up using private C-API calls for an unimportant one-time check at import time.

Also, do not call PyErr_WriteUnraisable() and instead propagate exceptions that occur at init time.
@scoder scoder merged commit db995de into cython:master Aug 11, 2023
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Py_Optimize flag doesn't exist in the limited APi
2 participants