mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 15:14:31 +00:00
Fix swig typemap for SBEvent.
This needs to be able to handle bytes, strings, and bytearray objects. In Python 2 this was easy because bytes and strings are the same thing, but in Python 3 the 2 cases need to be handled separately. So as not to mix raw Python C API code with PythonDataObjects code, I've also introduced a PythonByteArray class to PythonDataObjects to make the paradigm used here consistent. llvm-svn: 258741
This commit is contained in:
1 parent
10a50b188e
commit
f9d6d204e8
4 files changed
+147
-6
No files matched your search
@@ -75,6 +75,7 @@ enum class PyObjectType
|
||||
List,
|
||||
String,
|
||||
Bytes,
|
||||
ByteArray,
|
||||
Module,
|
||||
Callable,
|
||||
Tuple,
|
||||
@@ -293,6 +294,39 @@ public:
|
||||
CreateStructuredString() const;
|
||||
};
|
||||
|
||||
class PythonByteArray : public PythonObject
|
||||
{
|
||||
public:
|
||||
PythonByteArray();
|
||||
explicit PythonByteArray(llvm::ArrayRef<uint8_t> bytes);
|
||||
PythonByteArray(const uint8_t *bytes, size_t length);
|
||||
PythonByteArray(PyRefType type, PyObject *o);
|
||||
PythonByteArray(const PythonBytes &object);
|
||||
|
||||
~PythonByteArray() override;
|
||||
|
||||
static bool
|
||||
Check(PyObject *py_obj);
|
||||
|
||||
// Bring in the no-argument base class version
|
||||
using PythonObject::Reset;
|
||||
|
||||
void
|
||||
Reset(PyRefType type, PyObject *py_obj) override;
|
||||
|
||||
llvm::ArrayRef<uint8_t>
|
||||
GetBytes() const;
|
||||
|
||||
size_t
|
||||
GetSize() const;
|
||||
|
||||
void
|
||||
SetBytes(llvm::ArrayRef<uint8_t> stringbytes);
|
||||
|
||||
StructuredData::StringSP
|
||||
CreateStructuredString() const;
|
||||
};
|
||||
|
||||
class PythonString : public PythonObject
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in new issue
Block a user