Improve bytes/unicode distinction for reading modules from bitcode & assembly
This commit is contained in:
parent
1c15a9784b
commit
aba3e208d2
3 changed files with 17 additions and 2 deletions
10
llvm/core.py
10
llvm/core.py
|
|
@ -351,7 +351,9 @@ class Module(llvm.Ownable, llvm.Cacheable):
|
|||
a module represented in bitcode.
|
||||
"""
|
||||
|
||||
if _util.isstring(fileobj_or_str):
|
||||
if isinstance(fileobj_or_str, _util.unicode_type):
|
||||
data = fileobj_or_str.encode('utf-8')
|
||||
elif isinstance(fileobj_or_str, bytes):
|
||||
data = fileobj_or_str
|
||||
else:
|
||||
data = fileobj_or_str.read()
|
||||
|
|
@ -373,10 +375,14 @@ class Module(llvm.Ownable, llvm.Cacheable):
|
|||
a module represented in llvm-ir assembly.
|
||||
"""
|
||||
|
||||
if _util.isstring(fileobj_or_str):
|
||||
if isinstance(fileobj_or_str, _util.unicode_type):
|
||||
data = fileobj_or_str.encode('utf-8')
|
||||
elif isinstance(fileobj_or_str, bytes):
|
||||
data = fileobj_or_str
|
||||
else:
|
||||
data = fileobj_or_str.read()
|
||||
if isinstance(data, _util.unicode_type):
|
||||
data = data.encode()
|
||||
ret = _core.LLVMGetModuleFromAssembly(data)
|
||||
if not ret:
|
||||
raise llvm.LLVMException("Unable to create module from assembly")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue