Fix writing to file-like obj in python3.3
This commit is contained in:
parent
45e70333fd
commit
d270f47328
2 changed files with 8 additions and 5 deletions
|
|
@ -9,7 +9,7 @@ int py_bytes_to(PyObject *bytesobj, llvm::StringRef &strref){
|
||||||
// type check
|
// type check
|
||||||
if (!PyBytes_Check(bytesobj)) {
|
if (!PyBytes_Check(bytesobj)) {
|
||||||
// raises TypeError
|
// raises TypeError
|
||||||
PyErr_SetString(PyExc_TypeError, "Expecting a str");
|
PyErr_SetString(PyExc_TypeError, "Expecting a bytes");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// get len and buffer
|
// get len and buffer
|
||||||
|
|
|
||||||
|
|
@ -477,9 +477,13 @@ PyObject* llvm_ParseBitCodeFile(llvm::StringRef Buf, llvm::LLVMContext& Ctx,
|
||||||
if (FObj) {
|
if (FObj) {
|
||||||
std::string ErrStr;
|
std::string ErrStr;
|
||||||
M = ParseBitcodeFile(MB, Ctx, &ErrStr);
|
M = ParseBitcodeFile(MB, Ctx, &ErrStr);
|
||||||
if (-1 == PyFile_WriteString(ErrStr.c_str(), FObj)) {
|
auto_pyobject buf = PyBytes_FromString(ErrStr.c_str());
|
||||||
|
if (NULL == PyObject_CallMethod(FObj, "write", "O", *buf)){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
// if (-1 == PyFile_WriteString(ErrStr.c_str(), FObj)) {
|
||||||
|
// return NULL;
|
||||||
|
// }
|
||||||
} else {
|
} else {
|
||||||
M = ParseBitcodeFile(MB, Ctx);
|
M = ParseBitcodeFile(MB, Ctx);
|
||||||
}
|
}
|
||||||
|
|
@ -497,9 +501,8 @@ PyObject* llvm_WriteBitcodeToFile(const llvm::Module *M, PyObject* FObj)
|
||||||
llvm::WriteBitcodeToFile(M, rso);
|
llvm::WriteBitcodeToFile(M, rso);
|
||||||
rso.flush();
|
rso.flush();
|
||||||
StringRef ref = rso.str();
|
StringRef ref = rso.str();
|
||||||
PyObject* buf = PyBytes_FromStringAndSize(ref.data(), ref.size());
|
auto_pyobject buf = PyBytes_FromStringAndSize(ref.data(), ref.size());
|
||||||
puts(PyString_AsString(PyObject_Str(PyObject_Type(buf))));
|
return PyObject_CallMethod(FObj, "write", "O", *buf);
|
||||||
return PyObject_CallMethod(FObj, "write", "O", buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue