summaryrefslogtreecommitdiffstats
path: root/lldb/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/scripts')
-rw-r--r--lldb/scripts/Python/python-typemaps.swig43
-rw-r--r--lldb/scripts/interface/SBFile.i38
-rw-r--r--lldb/scripts/lldb.swig2
3 files changed, 82 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);
diff --git a/lldb/scripts/interface/SBFile.i b/lldb/scripts/interface/SBFile.i
new file mode 100644
index 00000000000..6cdb192f26e
--- /dev/null
+++ b/lldb/scripts/interface/SBFile.i
@@ -0,0 +1,38 @@
+//===-- SWIG Interface for SBFile -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+namespace lldb {
+
+%feature("docstring",
+"Represents a file."
+) SBFile;
+
+class SBFile
+{
+public:
+ SBFile();
+ SBFile(int fd, const char *mode, bool transfer_ownership);
+
+ ~SBFile ();
+
+ %feature("autodoc", "Read(buffer) -> SBError, bytes_read") Read;
+ SBError Read(uint8_t *buf, size_t num_bytes, size_t *OUTPUT);
+
+ %feature("autodoc", "Write(buffer) -> SBError, written_read") Write;
+ SBError Write(const uint8_t *buf, size_t num_bytes, size_t *OUTPUT);
+
+ void Flush();
+
+ bool IsValid() const;
+
+ operator bool() const;
+
+ SBError Close();
+};
+
+} // namespace lldb
diff --git a/lldb/scripts/lldb.swig b/lldb/scripts/lldb.swig
index ec39ad1b335..1634e1884af 100644
--- a/lldb/scripts/lldb.swig
+++ b/lldb/scripts/lldb.swig
@@ -123,6 +123,7 @@ def lldb_iter(obj, getsize, getelem):
#include "lldb/API/SBExecutionContext.h"
#include "lldb/API/SBExpressionOptions.h"
#include "lldb/API/SBFileSpec.h"
+#include "lldb/API/SBFile.h"
#include "lldb/API/SBFileSpecList.h"
#include "lldb/API/SBFrame.h"
#include "lldb/API/SBFunction.h"
@@ -210,6 +211,7 @@ def lldb_iter(obj, getsize, getelem):
%include "./interface/SBExecutionContext.i"
%include "./interface/SBExpressionOptions.i"
%include "./interface/SBFileSpec.i"
+%include "./interface/SBFile.i"
%include "./interface/SBFileSpecList.i"
%include "./interface/SBFrame.i"
%include "./interface/SBFunction.i"
OpenPOWER on IntegriCloud