This is an archive of the discontinued LLVM Phabricator instance.

Port native Python API to support 3.x
ClosedPublic

Authored by zturner on Oct 7 2015, 3:14 PM.

Details

Summary

With this change, liblldb is 95% of the way towards being able
to work under both Python 2.x and Python 3.x. This should
introduce no functional change for Python 2.x, but for Python
3.x there are some important changes. Primarily, these are:

  1. PyString doesn't exist in Python 3. Everything is a PyUnicode. To account for this, PythonString now stores a PyBytes instead of a PyString.
  2. PyInt doesn't exist in Python 3. Everything is a PyLong. To account for this, PythonInteger stores a PyLong instead of a PyInt. In Python 2.x, this requires doing a conversion to PyLong when creating a PythonInteger from a PyInt. In 3.x, there is no PyInt anyway, so we can assume everything is a PyLong.
  3. PyFile_FromFile doesn't exist in Python 3. Instead there is a PyFile_FromFd. This is not addressed in this patch because it will require quite a large change to plumb fd's all the way through the system into the ScriptInterpreter. This is the only remaining piece of the puzzle to get LLDB supporting Python 3.x.

Being able to run the test suite is not addressed in this patch.
After the extension module can compile and you can enter an embedded
3.x interpreter, the test suite will be addressed in a followup.

Diff Detail

Event Timeline

zturner updated this revision to Diff 36804.Oct 7 2015, 3:14 PM
zturner retitled this revision from to Port native Python API to support 3.x.
zturner updated this object.
zturner added reviewers: clayborg, granata.enrico.
zturner added a subscriber: lldb-commits.
clayborg requested changes to this revision.Oct 7 2015, 3:26 PM
clayborg edited edge metadata.

Few minor changes.

source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
1183

"value_str.data()" might not be NULL terminate. Either use value_str.str().c_str() or use "%*s":

error.SetErrorStringWithFormat("%*s\n%s", (int)value_str.size(), value_str.data(), bt.c_str());
unittests/ScriptInterpreter/CMakeLists.txt
4

add newline

unittests/ScriptInterpreter/Python/CMakeLists.txt
7

add newline

This revision now requires changes to proceed.Oct 7 2015, 3:26 PM
zturner updated this revision to Diff 36806.Oct 7 2015, 3:49 PM
zturner edited edge metadata.

Do you mind giving this a run on MacOSX and verifying it still compiles and test suite passes?

zturner added inline comments.Oct 7 2015, 3:50 PM
unittests/ScriptInterpreter/CMakeLists.txt
4

Missed this one in my updated patch, but I fixed it locally. Don't want to update a 3rd revision just for a newline though.

zturner added a subscriber: zturner.Oct 9 2015, 9:24 AM

Ping. Does this look ok?

clayborg accepted this revision.Oct 9 2015, 10:27 AM
clayborg edited edge metadata.

Looks good.

This revision is now accepted and ready to land.Oct 9 2015, 10:27 AM
zturner closed this revision.Oct 15 2015, 1:52 PM