Fixing segfault with PyArg_ParseTuple for strings
This commit is contained in:
parent
7035735ea4
commit
cb9fcd70cb
2 changed files with 498 additions and 439 deletions
50
llvm/_core.c
50
llvm/_core.c
|
|
@ -67,9 +67,18 @@ _wLLVMModuleCreateWithName(PyObject *self, PyObject *args)
|
||||||
const char *s;
|
const char *s;
|
||||||
LLVMModuleRef module;
|
LLVMModuleRef module;
|
||||||
|
|
||||||
|
#ifdef LLVM_PY_USE_PYCAPSULE
|
||||||
|
PyObject *s_;
|
||||||
|
if (!PyArg_ParseTuple(args, "U:LLVMModuleCreateWithName", &s_)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = PyUnicode_AS_DATA(s_);
|
||||||
|
#else
|
||||||
if (!PyArg_ParseTuple(args, "s", &s))
|
if (!PyArg_ParseTuple(args, "s", &s))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
module = LLVMModuleCreateWithName(s);
|
module = LLVMModuleCreateWithName(s);
|
||||||
return ctor_LLVMModuleRef(module);
|
return ctor_LLVMModuleRef(module);
|
||||||
}
|
}
|
||||||
|
|
@ -430,9 +439,18 @@ _wLLVMConstString(PyObject *self, PyObject *args)
|
||||||
const char *s;
|
const char *s;
|
||||||
int dont_null_terminate;
|
int dont_null_terminate;
|
||||||
LLVMValueRef val;
|
LLVMValueRef val;
|
||||||
|
|
||||||
|
#ifdef LLVM_PY_USE_PYCAPSULE
|
||||||
|
PyObject *s_;
|
||||||
|
if (!PyArg_ParseTuple(args, "Ui:LLVMConstString", &s_, &dont_null_terminate)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = PyUnicode_AS_DATA(s_);
|
||||||
|
#else
|
||||||
if (!PyArg_ParseTuple(args, "si", &s, &dont_null_terminate))
|
if (!PyArg_ParseTuple(args, "si", &s, &dont_null_terminate))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
val = LLVMConstString(s, strlen(s), dont_null_terminate);
|
val = LLVMConstString(s, strlen(s), dont_null_terminate);
|
||||||
return ctor_LLVMValueRef(val);
|
return ctor_LLVMValueRef(val);
|
||||||
|
|
@ -648,8 +666,17 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args)
|
||||||
LLVMBasicBlockRef then_blk, catch_blk;
|
LLVMBasicBlockRef then_blk, catch_blk;
|
||||||
LLVMValueRef inst;
|
LLVMValueRef inst;
|
||||||
|
|
||||||
|
#ifdef LLVM_PY_USE_PYCAPSULE
|
||||||
|
PyObject *name_;
|
||||||
|
if (!PyArg_ParseTuple(args, "OOOOOU:LLVMBuildInvoke", &obj1, &obj2, &obj3, &obj4, &obj5, &name_)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = PyUnicode_AS_DATA(name_);
|
||||||
|
#else
|
||||||
if (!PyArg_ParseTuple(args, "OOOOOs", &obj1, &obj2, &obj3, &obj4, &obj5, &name))
|
if (!PyArg_ParseTuple(args, "OOOOOs", &obj1, &obj2, &obj3, &obj4, &obj5, &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef LLVM_PY_USE_PYCAPSULE
|
#ifdef LLVM_PY_USE_PYCAPSULE
|
||||||
builder = (LLVMBuilderRef) PyCapsule_GetPointer(obj1, NULL);
|
builder = (LLVMBuilderRef) PyCapsule_GetPointer(obj1, NULL);
|
||||||
|
|
@ -764,9 +791,18 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args)
|
||||||
char *outmsg;
|
char *outmsg;
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
|
|
||||||
|
#ifdef LLVM_PY_USE_PYCAPSULE
|
||||||
|
PyObject *path_;
|
||||||
|
if (!PyArg_ParseTuple(args, "U:LLVMCreateMemoryBufferWithContentsOfFile", &path_)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
path = PyUnicode_AS_DATA(path_);
|
||||||
|
#else
|
||||||
if (!PyArg_ParseTuple(args, "s", &path))
|
if (!PyArg_ParseTuple(args, "s", &path))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) {
|
if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) {
|
||||||
ret = ctor_LLVMMemoryBufferRef(ref);
|
ret = ctor_LLVMMemoryBufferRef(ref);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1217,14 +1253,22 @@ _wrap_objintlist2obj(LLVMGetIntrinsic, LLVMModuleRef, LLVMTypeRef,
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
|
_wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
// XXX TODO: Figure out why this is segfaulting
|
|
||||||
const char *filename;
|
const char *filename;
|
||||||
char *outmsg;
|
char *outmsg;
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
|
|
||||||
|
#ifdef LLVM_PY_USE_PYCAPSULE
|
||||||
|
PyObject *filename_;
|
||||||
|
if (!PyArg_ParseTuple(args, "U:LLVMLoadLibraryPermanently", &filename_)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
filename = PyUnicode_AS_DATA(filename_);
|
||||||
|
#else
|
||||||
if (!PyArg_ParseTuple(args, "s", &filename)) {
|
if (!PyArg_ParseTuple(args, "s", &filename)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
outmsg = 0;
|
outmsg = 0;
|
||||||
if (!LLVMLoadLibraryPermanently(filename, &outmsg)) {
|
if (!LLVMLoadLibraryPermanently(filename, &outmsg)) {
|
||||||
|
|
|
||||||
887
llvm/wrap.h
887
llvm/wrap.h
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue