8000 WIP: BUG: Prevent running initialize_numeric_types more than once by mattip · Pull Request #11377 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

WIP: BUG: Prevent running initialize_numeric_types more than once #11377

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

mattip
Copy link
Member
@mattip mattip commented Jun 19, 2018

This code

import sys, numpy
sys.modules['np'] = sys.modules['numpy']
__import__('np.core.multiarray')

will segfault on CPython3. The code calls PyInit_multiarray a second time, which gets to initialize_numeric_types, which tries to reinitialize all the Py*ArrType_Types. Normally PyType_Ready will check the tp_flags for initialized type objects, but initialize_numeric_types resets the flags and many more pointers. The easiest fix is to check if one of the types has already been initialized.

@eric-wieser
Copy link
Member
eric-wieser commented Jun 19, 2018

Not sure this is the right fix. It seems like duplicating sys.modules like that isn't something python likes doing, especially if we only duplicate some of them. See my suggestion on the referenced issue.

@eric-wieser
Copy link
Member

If we're going to have an exit-early shortcut, shouldn't it be at the start of PyInit_multiarray?

@mattip mattip changed the title BUG: Prevent running initialize_numeric_types more than once WIP: BUG: Prevent running initialize_numeric_types more than once Sep 27, 2018
@mattip
Copy link
Member Author
mattip commented Sep 27, 2018

Thanks for the comment. Label changed to WIP, I should revisit this and make it work. It seems something is still wrong as other imports are failing after this test runs.

@mattip
Copy link
Member Author
mattip commented Jan 14, 2019

Closing, it seems like the wrong approach

@mattip mattip closed this Jan 14, 2019
@mattip mattip deleted the allow-PyInit_multiarray-twice branch March 4, 2019 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0