diff options
author | Enrico Granata <granata.enrico@gmail.com> | 2012-02-23 18:39:44 +0000 |
---|---|---|
committer | Enrico Granata <granata.enrico@gmail.com> | 2012-02-23 18:39:44 +0000 |
commit | 10afbe022dfc5d4487f317623bdff9e7041dc05a (patch) | |
tree | 834b77ef6136ff463202d61cf95b3240000ed029 /lldb/scripts/Python | |
parent | c232b775566bb4cbc5fb85c8c9f92d96a579dc15 (diff) | |
download | bcm5719-llvm-10afbe022dfc5d4487f317623bdff9e7041dc05a.tar.gz bcm5719-llvm-10afbe022dfc5d4487f317623bdff9e7041dc05a.zip |
typemaps to allow Python to invoke the new SBModule::GetVersion() API. Memory management is taken care of automatically so that Python users can simply say my_list = my_module.GetVersion() and receive a new list with the version numbers, if any, inside.
llvm-svn: 151271
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r-- | lldb/scripts/Python/python-typemaps.swig | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig index 539e55a01a7..0eca5ea3778 100644 --- a/lldb/scripts/Python/python-typemaps.swig +++ b/lldb/scripts/Python/python-typemaps.swig @@ -288,3 +288,45 @@ %typemap(freearg) (double* array, size_t array_len) { free($1); } + +// these typemaps wrap SBModule::GetVersion() from requiring a memory buffer +// to the more Pythonic style where a list is returned and no previous allocation +// is necessary - this will break if more than 50 versions are ever returned +%typemap(typecheck) (uint32_t *versions, uint32_t num_versions) { + $1 = ($input == Py_None ? 1 : 0); +} + +%typemap(in, numinputs=0) (uint32_t *versions) { + $1 = (uint32_t*)malloc(sizeof(uint32_t) * 50); +} + +%typemap(in, numinputs=0) (uint32_t num_versions) { + $1 = 50; +} + +%typemap(argout) (uint32_t *versions, uint32_t num_versions) { + uint32_t count = result; + if (count >= $2) + count = $2; + PyObject* list = PyList_New(count); + for (int j = 0; j < count; j++) + { + if ($1[j] < UINT32_MAX) + { + PyObject* item = PyInt_FromLong($1[j]); + int ok = PyList_SetItem(list,j,item); + if (ok != 0) + { + $result = Py_None; + break; + } + } + else + break; + } + $result = list; +} + +%typemap(freearg) (uint32_t *versions) { + free($1); +}
\ No newline at end of file |