diff options
author | Enrico Granata <egranata@apple.com> | 2013-06-21 23:27:16 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2013-06-21 23:27:16 +0000 |
commit | c20eed4280fdb0b3ede42171e6015eadb5d96ca8 (patch) | |
tree | 9de458d8b36c65d76f8c2e8c192b6f62ee6fdca3 /lldb/scripts/Python/python-swigsafecast.swig | |
parent | e5c41896b3068e8601db2688cf618c5d16064973 (diff) | |
download | bcm5719-llvm-c20eed4280fdb0b3ede42171e6015eadb5d96ca8.tar.gz bcm5719-llvm-c20eed4280fdb0b3ede42171e6015eadb5d96ca8.zip |
Lots of cleanup on the SWIG wrapping layer
Now, the way SWIG wrappers call into Python is through a utility PyCallable object, which overloads operator () to look like a normal function call
Plus, using the SBTypeToSWIGWrapper() family of functions, we can call python functions transparently as if they were plain C functions
Using this new technique should make adding new Python call points easier and quicker
The PyCallable is a generally useful facility, and we might want to consider moving it to a separate layer where other parts of LLDB can use it
llvm-svn: 184608
Diffstat (limited to 'lldb/scripts/Python/python-swigsafecast.swig')
-rw-r--r-- | lldb/scripts/Python/python-swigsafecast.swig | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/lldb/scripts/Python/python-swigsafecast.swig b/lldb/scripts/Python/python-swigsafecast.swig index 7ee658fb458..da7444c9b96 100644 --- a/lldb/scripts/Python/python-swigsafecast.swig +++ b/lldb/scripts/Python/python-swigsafecast.swig @@ -1,7 +1,3 @@ -#ifndef __cplusplus -#error needs C++ to build these -#endif - // 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> @@ -15,6 +11,38 @@ 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 (const char* c_str) +{ + if (c_str) + return PyString_FromString(c_str); + return NULL; +} + +template <> +PyObject* +SBTypeToSWIGWrapper (unsigned int* c_int) +{ + if (!c_int) + return NULL; + return PyInt_FromLong(*c_int); +} + template <> PyObject* SBTypeToSWIGWrapper (lldb::SBProcess* process_sb) |