Replace StringIO with BytesIO
This commit is contained in:
parent
c3a08a446f
commit
740d2595ee
3 changed files with 17 additions and 28 deletions
21
llvm/core.py
21
llvm/core.py
|
|
@ -28,10 +28,7 @@
|
|||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
from io import BytesIO
|
||||
import contextlib, weakref
|
||||
|
||||
import llvm
|
||||
|
|
@ -337,7 +334,7 @@ class Module(llvm.Wrapper):
|
|||
bc = fileobj_or_str
|
||||
else:
|
||||
bc = fileobj_or_str.read()
|
||||
errbuf = StringIO()
|
||||
errbuf = BytesIO()
|
||||
context = api.llvm.getGlobalContext()
|
||||
m = api.llvm.ParseBitCodeFile(bc, context, errbuf)
|
||||
if not m:
|
||||
|
|
@ -359,7 +356,7 @@ class Module(llvm.Wrapper):
|
|||
ir = fileobj_or_str
|
||||
else:
|
||||
ir = fileobj_or_str.read()
|
||||
errbuf = StringIO()
|
||||
errbuf = BytesIO()
|
||||
context = api.llvm.getGlobalContext()
|
||||
m = api.llvm.ParseAssemblyString(ir, None, api.llvm.SMDiagnostic.new(),
|
||||
context)
|
||||
|
|
@ -432,7 +429,7 @@ class Module(llvm.Wrapper):
|
|||
enum_mode = api.llvm.Linker.LinkerMode
|
||||
mode = enum_mode.PreserveSource if preserve else enum_mode.DestroySource
|
||||
|
||||
with contextlib.closing(StringIO()) as errmsg:
|
||||
with contextlib.closing(BytesIO()) as errmsg:
|
||||
failed = api.llvm.Linker.LinkModules(self._ptr,
|
||||
other._ptr,
|
||||
mode,
|
||||
|
|
@ -512,7 +509,7 @@ class Module(llvm.Wrapper):
|
|||
Checks module for errors. Raises `llvm.LLVMException' on any
|
||||
error."""
|
||||
action = api.llvm.VerifierFailureAction.ReturnStatusAction
|
||||
errio = StringIO()
|
||||
errio = BytesIO()
|
||||
broken = api.llvm.verifyModule(self._ptr, action, errio)
|
||||
if broken:
|
||||
raise llvm.LLVMException(errio.getvalue())
|
||||
|
|
@ -530,7 +527,7 @@ class Module(llvm.Wrapper):
|
|||
ret = False
|
||||
if fileobj is None:
|
||||
ret = True
|
||||
fileobj = StringIO
|
||||
fileobj = BytesIO
|
||||
api.llvm.WriteBitcodeToFile(self._ptr, fileobj)
|
||||
if ret:
|
||||
return fileobj.getvalue()
|
||||
|
|
@ -571,7 +568,7 @@ class Module(llvm.Wrapper):
|
|||
ret = False
|
||||
if fileobj is None:
|
||||
ret = True
|
||||
fileobj = StringIO()
|
||||
fileobj = BytesIO()
|
||||
from llvm.ee import TargetMachine
|
||||
tm = TargetMachine.new()
|
||||
fileobj.write(tm.emit_object(self))
|
||||
|
|
@ -588,7 +585,7 @@ class Module(llvm.Wrapper):
|
|||
ret = False
|
||||
if fileobj is None:
|
||||
ret = True
|
||||
fileobj = StringIO()
|
||||
fileobj = BytesIO()
|
||||
from llvm.ee import TargetMachine
|
||||
tm = TargetMachine.new()
|
||||
fileobj.write(tm.emit_assembly(self))
|
||||
|
|
@ -2269,7 +2266,7 @@ def load_library_permanently(filename):
|
|||
Load the given shared library (filename argument specifies the full
|
||||
path of the .so file) using LLVM. Symbols from these are available
|
||||
from the execution engine thereafter."""
|
||||
with contextlib.closing(StringIO()) as errmsg:
|
||||
with contextlib.closing(BytesIO()) as errmsg:
|
||||
failed = api.llvm.sys.DynamicLibrary.LoadPermanentLibrary(filename,
|
||||
errmsg)
|
||||
if failed:
|
||||
|
|
|
|||
|
|
@ -30,10 +30,7 @@
|
|||
|
||||
"Execution Engine and related classes."
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
from io import BytesIO
|
||||
import contextlib
|
||||
|
||||
import llvm
|
||||
|
|
@ -244,7 +241,7 @@ class TargetMachine(llvm.Wrapper):
|
|||
triple = get_default_triple()
|
||||
if not cpu:
|
||||
cpu = get_host_cpu_name()
|
||||
with contextlib.closing(StringIO()) as error:
|
||||
with contextlib.closing(BytesIO()) as error:
|
||||
target = api.llvm.TargetRegistry.lookupTarget(triple, error)
|
||||
if not target:
|
||||
raise llvm.LLVMException(error)
|
||||
|
|
@ -273,7 +270,7 @@ class TargetMachine(llvm.Wrapper):
|
|||
use: `llvm-as < /dev/null | llc -march=xyz -mattr=help`
|
||||
'''
|
||||
triple = api.llvm.Triple.new()
|
||||
with contextlib.closing(StringIO()) as error:
|
||||
with contextlib.closing(BytesIO()) as error:
|
||||
target = api.llvm.TargetRegistry.lookupTarget(arch, triple, error)
|
||||
if not target:
|
||||
raise llvm.LLVMException(error)
|
||||
|
|
|
|||
|
|
@ -10,13 +10,8 @@ import subprocess
|
|||
import tempfile
|
||||
import contextlib
|
||||
|
||||
is_py3k = bool(sys.version_info[0] == 3)
|
||||
BITS = tuple.__itemsize__ * 8
|
||||
|
||||
if is_py3k:
|
||||
from io import StringIO
|
||||
else:
|
||||
from cStringIO import StringIO
|
||||
from io import BytesIO
|
||||
|
||||
|
||||
import llvm
|
||||
|
|
@ -123,7 +118,7 @@ class TestAttr(TestCase):
|
|||
ret void
|
||||
}
|
||||
"""
|
||||
return Module.from_assembly(StringIO(test_module))
|
||||
return Module.from_assembly(BytesIO(test_module))
|
||||
|
||||
def test_align(self):
|
||||
m = self.make_module()
|
||||
|
|
@ -255,7 +250,7 @@ entry:
|
|||
}
|
||||
"""
|
||||
def test_operands(self):
|
||||
m = Module.from_assembly(StringIO(self.test_module))
|
||||
m = Module.from_assembly(BytesIO(self.test_module))
|
||||
|
||||
test_func = m.get_function_named("test_func")
|
||||
prod = m.get_function_named("prod")
|
||||
|
|
@ -317,7 +312,7 @@ entry:
|
|||
}
|
||||
"""
|
||||
def test_passes(self):
|
||||
m = Module.from_assembly(StringIO(self.asm))
|
||||
m = Module.from_assembly(BytesIO(self.asm))
|
||||
|
||||
fn_test1 = m.get_function_named('test1')
|
||||
fn_test2 = m.get_function_named('test2')
|
||||
|
|
@ -365,7 +360,7 @@ entry:
|
|||
self.assertNotEqual(str(fn_test1).strip(), original_test1.strip())
|
||||
|
||||
def test_passes_with_pmb(self):
|
||||
m = Module.from_assembly(StringIO(self.asm))
|
||||
m = Module.from_assembly(BytesIO(self.asm))
|
||||
|
||||
fn_test1 = m.get_function_named('test1')
|
||||
fn_test2 = m.get_function_named('test2')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue