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
|
|
@ -163,7 +163,11 @@ _wLLVMGetModuleFromAssembly(PyObject *self, PyObject *args)
|
|||
{
|
||||
LLVMPY_TRY
|
||||
const char * str;
|
||||
#if (PY_MAJOR_VERSION >= 3)
|
||||
if ( !PyArg_ParseTuple(args, "y", &str) ){
|
||||
#else
|
||||
if ( !PyArg_ParseTuple(args, "s", &str) ){
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,3 +101,8 @@ def _isstring_choose():
|
|||
|
||||
isstring = _isstring_choose()
|
||||
|
||||
try:
|
||||
unicode_type = unicode
|
||||
except NameError: # Py3
|
||||
unicode_type = str
|
||||
|
||||
|
|
|
|||
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