Page MenuHomePhabricator

Hold GIL while allocating memory for PythonString.
ClosedPublic

Authored by tatyana-krasnukha on Sep 1 2018, 1:07 AM.

Details

Summary

Swig wraps C++ code into SWIG_PYTHON_THREAD_BEGIN_ALLOW; ... SWIG_PYTHON_THREAD_END_ALLOW;
Thus, lldb crashs with "Fatal Python error: Python memory allocator called without holding the GIL" when calls lldb_SB***___str__ function.

Diff Detail

Repository
rLLDB LLDB

Event Timeline

%feature("nothreadallow") looks more appropriate in this case. GetDescription method is quite cheap, no need to handle the GIL.

granata.enrico resigned from this revision.Sep 2 2018, 7:26 PM

I don't work on LLDB anymore. I am sure Greg will do a fine job reviewing!

Not sure about this one. IIUC we now wouldn't take the GIL for these functions now and hope that the str() function doesn't do something that would require thread safety?

Yes, and %feature("nothreadallow") doesn't allow to release GIL before calling these functions - it prevents Swig from wrapping them into SWIG_PYTHON_THREAD_BEGIN_ALLOW .. SWIG_PYTHON_THREAD_END_ALLOW block.

What kind of scenario causes this crash to happen? Seems like a hack?

I have a third party module which implements a custom command for LLDB. The command calls str(target), str(process), etc. for logging.

Anyway, every call to these functions will cause this crash to happen, because PythonString is allocated after releasing the lock.

Use more readable aliases to set end clear the feature.

clayborg accepted this revision.Sep 5 2018, 9:46 AM
This revision is now accepted and ready to land.Sep 5 2018, 9:46 AM
This revision was automatically updated to reflect the committed changes.