From 0cccb3dec9e1a70107a09a43398caea87a2f01de Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Wed, 27 Feb 2013 19:03:44 -0600 Subject: [PATCH] Attempt to fix object code printing problem due to unicode --- llvm/ee.py | 8 +++++++- llvm/test_llvmpy.py | 6 +----- llvmpy/include/llvm_binding/conversion.h | 6 ++++++ llvmpy/src/Support/raw_ostream.py | 2 ++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/llvm/ee.py b/llvm/ee.py index 672a0b6..18cef78 100644 --- a/llvm/ee.py +++ b/llvm/ee.py @@ -291,7 +291,13 @@ class TargetMachine(llvm.Wrapper): pm.add(api.llvm.DataLayout.new(str(self.target_data))) failed = self._ptr.addPassesToEmitFile(pm, os, cgft) pm.run(module) - return os.str() + + + CGFT = api.llvm.TargetMachine.CodeGenFileType + if cgft == CGFT.CGFT_ObjectFile: + return os.bytes() + else: + return os.str() def emit_assembly(self, module): '''returns byte string of the module as assembly code of the target machine diff --git a/llvm/test_llvmpy.py b/llvm/test_llvmpy.py index 02bb386..c96f471 100644 --- a/llvm/test_llvmpy.py +++ b/llvm/test_llvmpy.py @@ -729,11 +729,7 @@ class TestNative(TestCase): src = os.path.join(self.tmpdir, 'llvmobj.o') with open(src, 'wb') as fout: - if is_py3k: - fout.write(output.encode('utf-8')) - else: - fout.write(output) - + fout.write(output) self._compile(src) diff --git a/llvmpy/include/llvm_binding/conversion.h b/llvmpy/include/llvm_binding/conversion.h index 5395a3f..cdc0350 100644 --- a/llvmpy/include/llvm_binding/conversion.h +++ b/llvmpy/include/llvm_binding/conversion.h @@ -209,6 +209,12 @@ static PyObject* py_str_from(const std::string &str){ return PyString_FromStringAndSize(str.c_str(), str.size()); } + + +static +PyObject* py_bytes_from(const std::string &str){ + return PyBytes_FromStringAndSize(str.c_str(), str.size()); +} // //static //PyObject* py_str_from(const llvm::StringRef *str){ diff --git a/llvmpy/src/Support/raw_ostream.py b/llvmpy/src/Support/raw_ostream.py index dcce73f..02765aa 100644 --- a/llvmpy/src/Support/raw_ostream.py +++ b/llvmpy/src/Support/raw_ostream.py @@ -15,4 +15,6 @@ class raw_svector_ostream: _base_ = raw_ostream str = Method(cast(str, StringRef)) + bytes = Method(cast(bytes, StringRef)) + bytes.realname = 'str'