diff options
author | Pavel Labath <pavel@labath.sk> | 2021-11-22 16:32:44 +0100 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2021-11-30 11:06:09 +0100 |
commit | 9a14adeae00015798843ff5cad987e5fdbdddb34 (patch) | |
tree | ea8895cb9a5261cf5362b2cbaad1a876824c4815 /lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp | |
parent | bc5dbb0baee357649c3132254ca6766b5cd6f15b (diff) | |
download | llvm-9a14adeae00015798843ff5cad987e5fdbdddb34.zip llvm-9a14adeae00015798843ff5cad987e5fdbdddb34.tar.gz llvm-9a14adeae00015798843ff5cad987e5fdbdddb34.tar.bz2 |
[lldb] Remove 'extern "C"' from the lldb-swig-python interface
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.
Differential Revision: https://reviews.llvm.org/D114369
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp')
-rw-r--r-- | lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp | 174 |
1 files changed, 74 insertions, 100 deletions
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp index 230fcf7..1295ab2 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp @@ -8,10 +8,10 @@ #include "gtest/gtest.h" -#include "Plugins/ScriptInterpreter/Python/lldb-python.h" - +#include "Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h" #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h" +#include "Plugins/ScriptInterpreter/Python/lldb-python.h" #include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" @@ -55,24 +55,11 @@ void PythonTestSuite::TearDown() { #if PY_MAJOR_VERSION >= 3 extern "C" PyObject *PyInit__lldb(void) { return nullptr; } -#define LLDBSwigPyInit PyInit__lldb #else extern "C" void init_lldb(void) {} -#define LLDBSwigPyInit init_lldb -#endif - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wreturn-type-c-linkage" - -// Disable warning C4190: 'LLDBSwigPythonBreakpointCallbackFunction' has -// C-linkage specified, but returns UDT 'llvm::Expected<bool>' which is -// incompatible with C -#if _MSC_VER -#pragma warning (push) -#pragma warning (disable : 4190) #endif -extern "C" llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction( +llvm::Expected<bool> lldb_private::LLDBSwigPythonBreakpointCallbackFunction( const char *python_function_name, const char *session_dictionary_name, const lldb::StackFrameSP &sb_frame, const lldb::BreakpointLocationSP &sb_bp_loc, @@ -80,218 +67,205 @@ extern "C" llvm::Expected<bool> LLDBSwigPythonBreakpointCallbackFunction( return false; } -#if _MSC_VER -#pragma warning (pop) -#endif - -#pragma clang diagnostic pop - -extern "C" bool LLDBSwigPythonWatchpointCallbackFunction( +bool lldb_private::LLDBSwigPythonWatchpointCallbackFunction( const char *python_function_name, const char *session_dictionary_name, const lldb::StackFrameSP &sb_frame, const lldb::WatchpointSP &sb_wp) { return false; } -extern "C" bool LLDBSwigPythonCallTypeScript( - const char *python_function_name, void *session_dictionary, +bool lldb_private::LLDBSwigPythonCallTypeScript( + const char *python_function_name, const void *session_dictionary, const lldb::ValueObjectSP &valobj_sp, void **pyfunct_wrapper, const lldb::TypeSummaryOptionsSP &options_sp, std::string &retval) { return false; } -extern "C" void * -LLDBSwigPythonCreateSyntheticProvider(const char *python_class_name, - const char *session_dictionary_name, - const lldb::ValueObjectSP &valobj_sp) { +void *lldb_private::LLDBSwigPythonCreateSyntheticProvider( + const char *python_class_name, const char *session_dictionary_name, + const lldb::ValueObjectSP &valobj_sp) { return nullptr; } -extern "C" void * -LLDBSwigPythonCreateCommandObject(const char *python_class_name, - const char *session_dictionary_name, - const lldb::DebuggerSP debugger_sp) { +void *lldb_private::LLDBSwigPythonCreateCommandObject( + const char *python_class_name, const char *session_dictionary_name, + const lldb::DebuggerSP debugger_sp) { return nullptr; } -extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan( +void *lldb_private::LLDBSwigPythonCreateScriptedThreadPlan( const char *python_class_name, const char *session_dictionary_name, - StructuredDataImpl *args_data, - std::string &error_string, + StructuredDataImpl *args_data, std::string &error_string, const lldb::ThreadPlanSP &thread_plan_sp) { return nullptr; } -extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor, - const char *method_name, - Event *event_sp, bool &got_error) { +bool lldb_private::LLDBSWIGPythonCallThreadPlan(void *implementor, + const char *method_name, + Event *event_sp, + bool &got_error) { return false; } -extern "C" void *LLDBSwigPythonCreateScriptedBreakpointResolver( +void *lldb_private::LLDBSwigPythonCreateScriptedBreakpointResolver( const char *python_class_name, const char *session_dictionary_name, lldb_private::StructuredDataImpl *args, const lldb::BreakpointSP &bkpt_sp) { return nullptr; } -extern "C" unsigned int -LLDBSwigPythonCallBreakpointResolver(void *implementor, const char *method_name, - lldb_private::SymbolContext *sym_ctx) { +unsigned int lldb_private::LLDBSwigPythonCallBreakpointResolver( + void *implementor, const char *method_name, + lldb_private::SymbolContext *sym_ctx) { return 0; } -extern "C" size_t LLDBSwigPython_CalculateNumChildren(void *implementor, - uint32_t max) { +size_t lldb_private::LLDBSwigPython_CalculateNumChildren(PyObject *implementor, + uint32_t max) { return 0; } -extern "C" void *LLDBSwigPython_GetChildAtIndex(void *implementor, - uint32_t idx) { +PyObject *lldb_private::LLDBSwigPython_GetChildAtIndex(PyObject *implementor, + uint32_t idx) { return nullptr; } -extern "C" int LLDBSwigPython_GetIndexOfChildWithName(void *implementor, - const char *child_name) { +int lldb_private::LLDBSwigPython_GetIndexOfChildWithName( + PyObject *implementor, const char *child_name) { return 0; } -extern "C" void *LLDBSWIGPython_CastPyObjectToSBData(void *data) { +void *lldb_private::LLDBSWIGPython_CastPyObjectToSBData(PyObject *data) { return nullptr; } -extern "C" void *LLDBSWIGPython_CastPyObjectToSBError(void *data) { +void *lldb_private::LLDBSWIGPython_CastPyObjectToSBError(PyObject *data) { return nullptr; } -extern "C" void *LLDBSWIGPython_CastPyObjectToSBValue(void *data) { +void *lldb_private::LLDBSWIGPython_CastPyObjectToSBValue(PyObject *data) { return nullptr; } -extern "C" void *LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(void *data) { +void * +lldb_private::LLDBSWIGPython_CastPyObjectToSBMemoryRegionInfo(PyObject *data) { return nullptr; } -extern lldb::ValueObjectSP -LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) { +lldb::ValueObjectSP +lldb_private::LLDBSWIGPython_GetValueObjectSPFromSBValue(void *data) { return nullptr; } -extern "C" bool LLDBSwigPython_UpdateSynthProviderInstance(void *implementor) { +bool lldb_private::LLDBSwigPython_UpdateSynthProviderInstance( + PyObject *implementor) { return false; } -extern "C" bool -LLDBSwigPython_MightHaveChildrenSynthProviderInstance(void *implementor) { +bool lldb_private::LLDBSwigPython_MightHaveChildrenSynthProviderInstance( + PyObject *implementor) { return false; } -extern "C" void * -LLDBSwigPython_GetValueSynthProviderInstance(void *implementor) { +PyObject *lldb_private::LLDBSwigPython_GetValueSynthProviderInstance( + PyObject *implementor) { return nullptr; } -extern "C" bool -LLDBSwigPythonCallCommand(const char *python_function_name, - const char *session_dictionary_name, - lldb::DebuggerSP &debugger, const char *args, - lldb_private::CommandReturnObject &cmd_retobj, - lldb::ExecutionContextRefSP exe_ctx_ref_sp) { +bool lldb_private::LLDBSwigPythonCallCommand( + const char *python_function_name, const char *session_dictionary_name, + lldb::DebuggerSP &debugger, const char *args, + lldb_private::CommandReturnObject &cmd_retobj, + lldb::ExecutionContextRefSP exe_ctx_ref_sp) { return false; } -extern "C" bool -LLDBSwigPythonCallCommandObject(void *implementor, lldb::DebuggerSP &debugger, - const char *args, - lldb_private::CommandReturnObject &cmd_retobj, - lldb::ExecutionContextRefSP exe_ctx_ref_sp) { +bool lldb_private::LLDBSwigPythonCallCommandObject( + PyObject *implementor, lldb::DebuggerSP &debugger, const char *args, + lldb_private::CommandReturnObject &cmd_retobj, + lldb::ExecutionContextRefSP exe_ctx_ref_sp) { return false; } -extern "C" bool -LLDBSwigPythonCallModuleInit(const char *python_module_name, - const char *session_dictionary_name, - lldb::DebuggerSP &debugger) { +bool lldb_private::LLDBSwigPythonCallModuleInit( + const char *python_module_name, const char *session_dictionary_name, + lldb::DebuggerSP &debugger) { return false; } -extern "C" void * -LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, - const char *session_dictionary_name, - const lldb::ProcessSP &process_sp) { +void * +lldb_private::LLDBSWIGPythonCreateOSPlugin(const char *python_class_name, + const char *session_dictionary_name, + const lldb::ProcessSP &process_sp) { return nullptr; } -extern "C" void *LLDBSwigPythonCreateScriptedProcess( +void *lldb_private::LLDBSwigPythonCreateScriptedProcess( const char *python_class_name, const char *session_dictionary_name, const lldb::TargetSP &target_sp, StructuredDataImpl *args_impl, std::string &error_string) { return nullptr; } -extern "C" void *LLDBSwigPythonCreateScriptedThread( +void *lldb_private::LLDBSwigPythonCreateScriptedThread( const char *python_class_name, const char *session_dictionary_name, const lldb::ProcessSP &process_sp, StructuredDataImpl *args_impl, std::string &error_string) { return nullptr; } -extern "C" void * -LLDBSWIGPython_CreateFrameRecognizer(const char *python_class_name, - const char *session_dictionary_name) { +void *lldb_private::LLDBSWIGPython_CreateFrameRecognizer( + const char *python_class_name, const char *session_dictionary_name) { return nullptr; } -extern "C" void * -LLDBSwigPython_GetRecognizedArguments(void *implementor, - const lldb::StackFrameSP &frame_sp) { +PyObject *lldb_private::LLDBSwigPython_GetRecognizedArguments( + PyObject *implementor, const lldb::StackFrameSP &frame_sp) { return nullptr; } -extern "C" bool LLDBSWIGPythonRunScriptKeywordProcess( +bool lldb_private::LLDBSWIGPythonRunScriptKeywordProcess( const char *python_function_name, const char *session_dictionary_name, const lldb::ProcessSP &process, std::string &output) { return false; } -extern "C" bool LLDBSWIGPythonRunScriptKeywordThread( +bool lldb_private::LLDBSWIGPythonRunScriptKeywordThread( const char *python_function_name, const char *session_dictionary_name, lldb::ThreadSP &thread, std::string &output) { return false; } -extern "C" bool LLDBSWIGPythonRunScriptKeywordTarget( +bool lldb_private::LLDBSWIGPythonRunScriptKeywordTarget( const char *python_function_name, const char *session_dictionary_name, const lldb::TargetSP &target, std::string &output) { return false; } -extern "C" bool LLDBSWIGPythonRunScriptKeywordFrame( +bool lldb_private::LLDBSWIGPythonRunScriptKeywordFrame( const char *python_function_name, const char *session_dictionary_name, lldb::StackFrameSP &frame, std::string &output) { return false; } -extern "C" bool LLDBSWIGPythonRunScriptKeywordValue( +bool lldb_private::LLDBSWIGPythonRunScriptKeywordValue( const char *python_function_name, const char *session_dictionary_name, const lldb::ValueObjectSP &value, std::string &output) { return false; } -extern "C" void * -LLDBSWIGPython_GetDynamicSetting(void *module, const char *setting, - const lldb::TargetSP &target_sp) { +void *lldb_private::LLDBSWIGPython_GetDynamicSetting( + void *module, const char *setting, const lldb::TargetSP &target_sp) { return nullptr; } -extern "C" void *LLDBSwigPythonCreateScriptedStopHook( +void *lldb_private::LLDBSwigPythonCreateScriptedStopHook( lldb::TargetSP target_sp, const char *python_class_name, const char *session_dictionary_name, lldb_private::StructuredDataImpl *args_impl, Status &error) { return nullptr; } -extern "C" bool -LLDBSwigPythonStopHookCallHandleStop(void *implementor, - lldb::ExecutionContextRefSP exc_ctx_sp, - lldb::StreamSP stream) { +bool lldb_private::LLDBSwigPythonStopHookCallHandleStop( + void *implementor, lldb::ExecutionContextRefSP exc_ctx_sp, + lldb::StreamSP stream) { return false; } |