This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Remove 'extern "C"' from the lldb-swig-python interface
ClosedPublic

Authored by labath on Nov 22 2021, 7:45 AM.

Details

Summary

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.

Diff Detail

Event Timeline

labath requested review of this revision.Nov 22 2021, 7:45 AM
labath created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptNov 22 2021, 7:45 AM
labath updated this revision to Diff 388935.Nov 22 2021, 8:55 AM

Revert the PyInit_lldb changes. They fail on windows due to declspec(dllexport)
mistmatches, and this function is kinda special anyway.

JDevlieghere accepted this revision.Nov 29 2021, 9:20 AM

Makes sense. LGTM.

This revision is now accepted and ready to land.Nov 29 2021, 9:20 AM