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:
@@ -224,6 +224,20 @@ TEST_F(PythonDataObjectsTest, TestPythonBytes)
|
||||
EXPECT_EQ(0, ::memcmp(bytes.data(), test_bytes, bytes.size()));
|
||||
}
|
||||
|
||||
TEST_F(PythonDataObjectsTest, TestPythonByteArray)
|
||||
{
|
||||
static const char *test_bytes = "PythonDataObjectsTest::TestPythonByteArray";
|
||||
llvm::StringRef orig_bytes(test_bytes);
|
||||
PyObject *py_bytes = PyByteArray_FromStringAndSize(test_bytes, orig_bytes.size());
|
||||
EXPECT_TRUE(PythonByteArray::Check(py_bytes));
|
||||
PythonByteArray python_bytes(PyRefType::Owned, py_bytes);
|
||||
EXPECT_EQ(PyObjectType::ByteArray, python_bytes.GetObjectType());
|
||||
|
||||
llvm::ArrayRef<uint8_t> after_bytes = python_bytes.GetBytes();
|
||||
EXPECT_EQ(after_bytes.size(), orig_bytes.size());
|
||||
EXPECT_EQ(0, ::memcmp(orig_bytes.data(), test_bytes, orig_bytes.size()));
|
||||
}
|
||||
|
||||
TEST_F(PythonDataObjectsTest, TestPythonString)
|
||||
{
|
||||
// Test that strings behave correctly when wrapped by a PythonString.
|
||||
|
||||
Reference in New Issue
Block a user