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

[mypyc] Getting capsule pointer from module instead of PyCapsule_Import. #18286

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

advait-dixit
Copy link
Contributor

@advait-dixit advait-dixit commented Dec 12, 2024

Fixes mypyc/mypyc#999.

PyCapsule_Import was failing in sub-packages. Since the capsule is an attribute of the module, we can access the capsule from the module instead of importing it.

@advait-dixit
Copy link
Contributor Author

@hauntsaninja , @JukkaL : Can you please take a look at this pull request? I think it fixes an import bug that has been reported by many users.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the issue! Looks good overall, just one error check seems to be missing.

@@ -5,8 +5,10 @@ PyInit_{modname}(void)
{{
PyObject *tmp;
if (!(tmp = PyImport_ImportModule("{libname}"))) return NULL;
PyObject *capsule = PyObject_GetAttrString(tmp, "init_{full_modname}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for null return. Otherwise we may decref a null pointer below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it. Thanks.

@JukkaL JukkaL merged commit f445369 into python:master Dec 19, 2024
13 checks passed
@advait-dixit advait-dixit deleted the fix_circ_imp branch December 19, 2024 18:56
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.

mayhem with nested packages and relative import
2 participants