From 4407396fb94dc3a1da5b51f9512381f9bb46ca64 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 25 Jan 2016 23:21:18 +0000 Subject: Fix some issues with bytes and strings in Python 3. SBProcess::ReadMemory and other related functions such as WriteMemory are returning Python string() objects. This means that in Python 3 that are returning Unicode objects. In reality they should be returning bytes objects which is the same as a string in Python 2, but different in Python 3. This patch updates the generated SWIG code to return Python bytes objects for all memory related functions. One quirk of this patch is that the C++ signature of ReadCStringFromMemory has it writing c-string data into a void*. This confuses our swig typemaps which expect that a void* means byte data. So I hacked up a custom typemap which maps this specific function to treat the void* as string data instead of byte data. llvm-svn: 258743 --- lldb/scripts/Python/python-typemaps.swig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lldb/scripts/Python') diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig index 659199f1fd0..82e33e1bc60 100644 --- a/lldb/scripts/Python/python-typemaps.swig +++ b/lldb/scripts/Python/python-typemaps.swig @@ -93,6 +93,9 @@ } $1 = (char *) malloc($2); } +// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated +// as char data instead of byte data. +%typemap(in) (void *char_buf, size_t size) = (char *dst, size_t dst_len); // Return the char buffer. Discarding any previous return result // See also SBThread::GetStopDescription. @@ -108,6 +111,9 @@ } free($1); } +// SBProcess::ReadCStringFromMemory() uses a void*, but needs to be treated +// as char data instead of byte data. +%typemap(argout) (void *char_buf, size_t size) = (char *dst, size_t dst_len); // typemap for an outgoing buffer @@ -231,9 +237,8 @@ $result = Py_None; Py_INCREF($result); } else { - llvm::StringRef ref(static_cast($1), result); - lldb_private::PythonString string(ref); - $result = string.release(); + lldb_private::PythonBytes bytes(static_cast($1), result); + $result = bytes.release(); } free($1); } -- cgit v1.2.3