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 segfault when raising Python errors that didn't set an exception. #1410

Merged
merged 1 commit into from
Jul 9, 2023

Conversation

dfalbel
Copy link
Member

@dfalbel dfalbel commented Jul 9, 2023

This fixes #1404 in the sense that we no longer segfault when calling import_builtins()$globals().

The segfault happens because the call to globals() fails but never sets an exceptionType in Python side, which is expected by the py_fetch_error().

The reason why this call fails is still unkown to me (no backtrace makes it harder to figure it out), but it it seems that, the Python interpreter used by reticulate has no default module imported, causing the globals dictionary to not exist.

I think we might be missing somehting like:

reticulate/src/python.cpp

Lines 2967 to 2968 in 9a712cb

PyObject* main = PyImport_AddModule("__main__");
PyObject* globals = PyModule_GetDict(main);

during the initialization of reticulate's interpreter.

Previous reticulate versions raise:

> reticulate::import_builtins()$globals()
Error: <unknown error>

@t-kalinowski t-kalinowski merged commit f59e178 into rstudio:main Jul 9, 2023
12 checks passed
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.

Segfault with when calling globals
2 participants