diff options
author | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-10-03 04:01:07 +0000 |
---|---|---|
committer | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-10-03 04:01:07 +0000 |
commit | 5750453020926ce270aee38bd5eb7f0ff3467237 (patch) | |
tree | 5e00ea3b2f67bdd77c02d67e409ed27e72fb52d9 /lldb/scripts/Python | |
parent | f13b8d4fe962216cd0e1a7dc318709caa1c5b59a (diff) | |
download | bcm5719-llvm-5750453020926ce270aee38bd5eb7f0ff3467237.tar.gz bcm5719-llvm-5750453020926ce270aee38bd5eb7f0ff3467237.zip |
new api class: SBFile
Summary:
SBFile is a scripting API wrapper for lldb_private::File
This is the first step in a project to enable arbitrary python
io.IOBase file objects -- including those that override the read()
and write() methods -- to be used as the main debugger IOStreams.
Currently this is impossible because python file objects must first
be converted into FILE* streams by SWIG in order to be passed into
the debugger.
full prototype: https://github.com/smoofra/llvm-project/tree/files
Reviewers: JDevlieghere, jasonmolenda, zturner, jingham, labath
Reviewed By: labath
Subscribers: labath, mgorny, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D67793
llvm-svn: 373562
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r-- | lldb/scripts/Python/python-typemaps.swig | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig index fe6a1798c53..9c43ef18ac1 100644 --- a/lldb/scripts/Python/python-typemaps.swig +++ b/lldb/scripts/Python/python-typemaps.swig @@ -224,7 +224,7 @@ namespace { template <class T> T PyLongAsT(PyObject *obj) { - static_assert(true, "unsupported type"); + static_assert(true, "unsupported type"); } template <> uint64_t PyLongAsT<uint64_t>(PyObject *obj) { @@ -461,3 +461,44 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) { return NULL; } } + +// These two pybuffer macros are copied out of swig/Lib/python/pybuffer.i, +// and fixed so they will not crash if PyObject_GetBuffer fails. +// https://github.com/swig/swig/issues/1640 + +%define %pybuffer_mutable_binary(TYPEMAP, SIZE) +%typemap(in) (TYPEMAP, SIZE) { + int res; Py_ssize_t size = 0; void *buf = 0; + Py_buffer view; + res = PyObject_GetBuffer($input, &view, PyBUF_WRITABLE); + if (res < 0) { + PyErr_Clear(); + %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum); + } + size = view.len; + buf = view.buf; + PyBuffer_Release(&view); + $1 = ($1_ltype) buf; + $2 = ($2_ltype) (size/sizeof($*1_type)); +} +%enddef + +%define %pybuffer_binary(TYPEMAP, SIZE) +%typemap(in) (TYPEMAP, SIZE) { + int res; Py_ssize_t size = 0; const void *buf = 0; + Py_buffer view; + res = PyObject_GetBuffer($input, &view, PyBUF_CONTIG_RO); + if (res < 0) { + PyErr_Clear(); + %argument_fail(res, "(TYPEMAP, SIZE)", $symname, $argnum); + } + size = view.len; + buf = view.buf; + PyBuffer_Release(&view); + $1 = ($1_ltype) buf; + $2 = ($2_ltype) (size / sizeof($*1_type)); +} +%enddef + +%pybuffer_binary(const uint8_t *buf, size_t num_bytes); +%pybuffer_mutable_binary(uint8_t *buf, size_t num_bytes); |