-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb] Deobfuscate python-swigsafecast.swig
This file was way more complicated than it needed to be. This patch removes the automagic reference-to-pointer delegation and replaces the template specializations with regular free functions (taking reference arguments). The reason I chose references is twofold: - there are more arguments being passed by reference than by pointer - the reference arguments make it more obvious that there is a lot of leaking going on in there. Currently, the code was assuming that the pointer arguments have some kind of a special meaning and that pointer functions take ownership of their arguments, which isn't true (it's possible it was true at some point in the past, I haven't done the archeology). This makes it easier to implement proper lifetime management in follow-up patches. Differential Revision: https://reviews.llvm.org/D114150
- Loading branch information
Showing
2 changed files
with
72 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,161 +1,72 @@ | ||
// leaving this undefined ensures we will get a linker error if we try to use SBTypeToSWIGWrapper() | ||
// for a type for which we did not specialze this function | ||
template <typename SBClass> | ||
PyObject* | ||
SBTypeToSWIGWrapper (SBClass* sb_object); | ||
|
||
template <typename SBClass> | ||
PyObject* | ||
SBTypeToSWIGWrapper (SBClass& sb_object) | ||
{ | ||
return SBTypeToSWIGWrapper(&sb_object); | ||
} | ||
|
||
template <typename SBClass> | ||
PyObject* | ||
SBTypeToSWIGWrapper (const SBClass& sb_object) | ||
{ | ||
return SBTypeToSWIGWrapper(&sb_object); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (PyObject* py_object) | ||
{ | ||
return py_object; | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (unsigned int* c_int) | ||
{ | ||
if (!c_int) | ||
return NULL; | ||
return PyInt_FromLong(*c_int); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBEvent* event_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) event_sb, SWIGTYPE_p_lldb__SBEvent, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBProcess* process_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) process_sb, SWIGTYPE_p_lldb__SBProcess, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBEvent &event_sb) { | ||
return SWIG_NewPointerObj(&event_sb, SWIGTYPE_p_lldb__SBEvent, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBThread* thread_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) thread_sb, SWIGTYPE_p_lldb__SBThread, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBProcess &process_sb) { | ||
return SWIG_NewPointerObj(&process_sb, SWIGTYPE_p_lldb__SBProcess, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBThreadPlan* thread_plan_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) thread_plan_sb, SWIGTYPE_p_lldb__SBThreadPlan, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBThread &thread_sb) { | ||
return SWIG_NewPointerObj(&thread_sb, SWIGTYPE_p_lldb__SBThread, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBTarget* target_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) target_sb, SWIGTYPE_p_lldb__SBTarget, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBThreadPlan &thread_plan_sb) { | ||
return SWIG_NewPointerObj(&thread_plan_sb, SWIGTYPE_p_lldb__SBThreadPlan, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBFrame* frame_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) frame_sb, SWIGTYPE_p_lldb__SBFrame, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBTarget &target_sb) { | ||
return SWIG_NewPointerObj(&target_sb, SWIGTYPE_p_lldb__SBTarget, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBDebugger* debugger_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) debugger_sb, SWIGTYPE_p_lldb__SBDebugger, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBFrame &frame_sb) { | ||
return SWIG_NewPointerObj(&frame_sb, SWIGTYPE_p_lldb__SBFrame, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBBreakpoint* breakpoint_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) breakpoint_sb, SWIGTYPE_p_lldb__SBBreakpoint, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBDebugger &debugger_sb) { | ||
return SWIG_NewPointerObj(&debugger_sb, SWIGTYPE_p_lldb__SBDebugger, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBWatchpoint* watchpoint_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) watchpoint_sb, SWIGTYPE_p_lldb__SBWatchpoint, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBBreakpoint &breakpoint_sb) { | ||
return SWIG_NewPointerObj(&breakpoint_sb, SWIGTYPE_p_lldb__SBBreakpoint, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBBreakpointLocation* breakpoint_location_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) breakpoint_location_sb, SWIGTYPE_p_lldb__SBBreakpointLocation, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBWatchpoint &watchpoint_sb) { | ||
return SWIG_NewPointerObj(&watchpoint_sb, SWIGTYPE_p_lldb__SBWatchpoint, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBBreakpointName* breakpoint_name_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) breakpoint_name_sb, SWIGTYPE_p_lldb__SBBreakpointName, 0); | ||
PyObject * | ||
SBTypeToSWIGWrapper(lldb::SBBreakpointLocation &breakpoint_location_sb) { | ||
return SWIG_NewPointerObj(&breakpoint_location_sb, | ||
SWIGTYPE_p_lldb__SBBreakpointLocation, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBValue* value_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) value_sb, SWIGTYPE_p_lldb__SBValue, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBValue &value_sb) { | ||
return SWIG_NewPointerObj(&value_sb, SWIGTYPE_p_lldb__SBValue, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBCommandReturnObject* cmd_ret_obj_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) cmd_ret_obj_sb, SWIGTYPE_p_lldb__SBCommandReturnObject, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBCommandReturnObject &cmd_ret_obj_sb) { | ||
return SWIG_NewPointerObj(&cmd_ret_obj_sb, | ||
SWIGTYPE_p_lldb__SBCommandReturnObject, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBExecutionContext* ctx_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) ctx_sb, SWIGTYPE_p_lldb__SBExecutionContext, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBExecutionContext &ctx_sb) { | ||
return SWIG_NewPointerObj(&ctx_sb, SWIGTYPE_p_lldb__SBExecutionContext, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBTypeSummaryOptions* summary_options_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) summary_options_sb, SWIGTYPE_p_lldb__SBTypeSummaryOptions, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBTypeSummaryOptions &summary_options_sb) { | ||
return SWIG_NewPointerObj(&summary_options_sb, | ||
SWIGTYPE_p_lldb__SBTypeSummaryOptions, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBStructuredData* structured_data_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) structured_data_sb, SWIGTYPE_p_lldb__SBStructuredData, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBStructuredData &structured_data_sb) { | ||
return SWIG_NewPointerObj(&structured_data_sb, | ||
SWIGTYPE_p_lldb__SBStructuredData, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBSymbolContext* sym_ctx_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) sym_ctx_sb, SWIGTYPE_p_lldb__SBSymbolContext, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBSymbolContext &sym_ctx_sb) { | ||
return SWIG_NewPointerObj(&sym_ctx_sb, SWIGTYPE_p_lldb__SBSymbolContext, 0); | ||
} | ||
|
||
template <> | ||
PyObject* | ||
SBTypeToSWIGWrapper (lldb::SBStream* stream_sb) | ||
{ | ||
return SWIG_NewPointerObj((void *) stream_sb, SWIGTYPE_p_lldb__SBStream, 0); | ||
PyObject *SBTypeToSWIGWrapper(lldb::SBStream &stream_sb) { | ||
return SWIG_NewPointerObj(&stream_sb, SWIGTYPE_p_lldb__SBStream, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters