[Lldb-commits] [PATCH] D114369: [lldb] Remove 'extern "C"' from the lldb-swig-python interface

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 22 07:45:53 PST 2021


labath created this revision.
labath added reviewers: JDevlieghere, jingham.
labath requested review of this revision.
Herald added a project: LLDB.

The LLDBSWIGPython functions had (at least) two problems:

- There wasn't a single source of truth (a header file) for the prototypes of these functions. This meant that subtle differences in copies of function declarations could go by undetected. And not-so-subtle differences would result in strange runtime failures.
- All of the declarations had to have an extern "C" interface, because the function definitions were being placed inside and extert "C" block generated by swig.

This patch fixes both problems by moving the function definitions to the
%header block of the swig files. This block is not surrounded by extern
"C", and seems more appropriate anyway, as swig docs say it is meant for
"user-defined support code" (whereas the previous %wrapper code was for
automatically-generated wrappers).

It also puts the declarations into the SWIGPythonBridge header file
(which seems to have been created for this purpose), and ensures it is
included by all code wishing to define or use these functions. This
means that any differences in the declaration become a compiler error
instead of a runtime failure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114369

Files:
  lldb/bindings/python/python-wrapper.swig
  lldb/bindings/python/python.swig
  lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
  lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
  lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114369.388918.patch
Type: text/x-patch
Size: 44331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211122/d409a2b2/attachment-0001.bin>


More information about the lldb-commits mailing list