Moar py3k updates... Still segfaulting, in PyArg_ParseTuple of _wLLVMLoadLibraryPermanently for some reason. :|

This commit is contained in:
AndrewBC 2011-06-12 05:54:08 -05:00
commit 2c42b82799
3 changed files with 54 additions and 37 deletions

View file

@ -66,7 +66,7 @@ _wLLVMModuleCreateWithName(PyObject *self, PyObject *args)
const char *s;
LLVMModuleRef module;
if (!PyArg_ParseTuple(args, "s", &s))
if (!PyArg_ParseTuple(args, "y#", &s))
return NULL;
module = LLVMModuleCreateWithName(s);
@ -101,10 +101,10 @@ _wLLVMVerifyModule(PyObject *self, PyObject *args)
(void) LLVMVerifyModule(m, LLVMReturnStatusAction, &outmsg);
if (outmsg) {
ret = PyString_FromString(outmsg);
ret = PyBytes_FromString(outmsg);
LLVMDisposeMessage(outmsg);
} else {
ret = PyString_FromString("");
ret = PyBytes_FromString("");
}
return ret;
@ -124,14 +124,14 @@ _get_asm_or_bc(asm_or_bc_fn_t fn, PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O", &obj))
return NULL;
start = PyString_AsString(obj);
len = PyString_Size(obj);
start = PyBytes_AsString(obj);
len = PyBytes_Size(obj);
outmsg = 0;
m = fn(start, len, &outmsg);
if (!m) {
if (outmsg) {
ret = PyString_FromString(outmsg);
ret = PyBytes_FromString(outmsg);
LLVMDisposeMessage(outmsg);
return ret;
} else {
@ -168,7 +168,7 @@ _wLLVMGetBitcodeFromModule(PyObject *self, PyObject *args)
if (!(bytes = LLVMGetBitcodeFromModule(m, &len)))
Py_RETURN_NONE;
ret = PyString_FromStringAndSize((char *)bytes, (Py_ssize_t)len);
ret = PyBytes_FromStringAndSize((char *)bytes, (Py_ssize_t)len);
LLVMDisposeMessage((char *)bytes);
return ret;
}
@ -193,10 +193,10 @@ _wLLVMLinkModules(PyObject *self, PyObject *args)
if (!LLVMLinkModules(dest, src, &errmsg)) {
if (errmsg) {
ret = PyString_FromString(errmsg);
ret = PyBytes_FromString(errmsg);
LLVMDisposeMessage(errmsg);
} else {
ret = PyString_FromString("Link error");
ret = PyBytes_FromString("Link error");
}
return ret;
}
@ -430,7 +430,7 @@ _wLLVMConstString(PyObject *self, PyObject *args)
int dont_null_terminate;
LLVMValueRef val;
if (!PyArg_ParseTuple(args, "si", &s, &dont_null_terminate))
if (!PyArg_ParseTuple(args, "y#i", &s, &dont_null_terminate))
return NULL;
val = LLVMConstString(s, strlen(s), dont_null_terminate);
@ -647,7 +647,7 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args)
LLVMBasicBlockRef then_blk, catch_blk;
LLVMValueRef inst;
if (!PyArg_ParseTuple(args, "OOOOOs", &obj1, &obj2, &obj3, &obj4, &obj5, &name))
if (!PyArg_ParseTuple(args, "OOOOOy#", &obj1, &obj2, &obj3, &obj4, &obj5, &name))
return NULL;
#ifdef LLVM_PY_USE_PYCAPSULE
@ -763,13 +763,13 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args)
char *outmsg;
PyObject *ret;
if (!PyArg_ParseTuple(args, "s", &path))
if (!PyArg_ParseTuple(args, "y#", &path))
return NULL;
if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) {
ret = ctor_LLVMMemoryBufferRef(ref);
} else {
ret = PyString_FromString(outmsg);
ret = PyBytes_FromString(outmsg);
LLVMDisposeMessage(outmsg);
}
@ -786,7 +786,7 @@ _wLLVMCreateMemoryBufferWithSTDIN(PyObject *self, PyObject *args)
if (!LLVMCreateMemoryBufferWithSTDIN(&ref, &outmsg)) {
ret = ctor_LLVMMemoryBufferRef(ref);
} else {
ret = PyString_FromString(outmsg);
ret = PyBytes_FromString(outmsg);
LLVMDisposeMessage(outmsg);
}
@ -921,7 +921,7 @@ _wLLVMTargetDataAsString(PyObject *self, PyObject *args)
return NULL;
tdrep = LLVMCopyStringRepOfTargetData(td);
ret = PyString_FromString(tdrep);
ret = PyBytes_FromString(tdrep);
LLVMDisposeMessage(tdrep);
return ret;
}
@ -979,7 +979,7 @@ _wLLVMCreateExecutionEngine(PyObject *self, PyObject *args)
error = LLVMCreateJITCompilerForModule(&ee, mod, 1 /*fast*/, &outmsg);
if (error) {
ret = PyString_FromString(outmsg);
ret = PyBytes_FromString(outmsg);
LLVMDisposeMessage(outmsg);
} else {
ret = ctor_LLVMExecutionEngineRef(ee);
@ -1043,10 +1043,10 @@ _wLLVMRemoveModule2(PyObject *self, PyObject *args)
ret = ctor_LLVMModuleRef(mod_new);
} else {
if (outmsg) {
ret = PyString_FromString(outmsg);
ret = PyBytes_FromString(outmsg);
LLVMDisposeMessage(outmsg);
} else {
ret = PyString_FromString("error");
ret = PyBytes_FromString("error");
}
}
@ -1216,17 +1216,19 @@ _wrap_objintlist2obj(LLVMGetIntrinsic, LLVMModuleRef, LLVMTypeRef,
static PyObject *
_wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
{
// XXX TODO: Figure out why this is segfaulting
const char *filename;
char *outmsg;
PyObject *ret;
if (!PyArg_ParseTuple(args, "s", &filename))
if (!PyArg_ParseTuple(args, "y#", &filename)) {
return NULL;
}
outmsg = 0;
if (!LLVMLoadLibraryPermanently(filename, &outmsg)) {
if (outmsg) {
ret = PyString_FromString(outmsg);
ret = PyBytes_FromString(outmsg);
LLVMDisposeMessage(outmsg);
return ret;
}
@ -1256,9 +1258,18 @@ _wPyCObjectVoidPtrToPyLong(PyObject *self, PyObject *args)
/* Python member method table */
/*===----------------------------------------------------------------------===*/
#ifdef LLVM_PY_USE_PYCAPSULE
#define _method( func ) { # func , ( PyCFunction )_w ## func , METH_VARARGS , NULL },
#define _pass( P ) _method( LLVMAdd ## P ## Pass )
#else
#define _method( func ) { # func , _w ## func , METH_VARARGS },
#define _pass( P ) _method( LLVMAdd ## P ## Pass )
#endif
static PyMethodDef core_methods[] = {
/* Modules */

View file

@ -433,16 +433,22 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, unsigned *lenp)
/* Return 0 on failure (with errmsg filled in), 1 on success. */
unsigned LLVMLoadLibraryPermanently(const char* filename, char **errmsg)
{
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@1");
assert(filename);
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2");
assert(errmsg);
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@3");
/* Note: the LLVM API returns true on failure. Don't ask why. */
std::string msg;
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4");
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(filename, &msg)) {
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@5");
*errmsg = strdup(msg.c_str());
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@6");
return 0;
}
printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@7");
return 1;
}

View file

@ -36,7 +36,7 @@
#define LLVM_PY_WRAP_H
/* Project-wide setting */
#if (PY_MAJOR_VERSION >= 3)
#if PY_MAJOR_VERSION >= 3
#define LLVM_PY_USE_PYCAPSULE
#endif
@ -135,7 +135,7 @@ PyObject *make_list_from_LLVMValueRef_array(LLVMValueRef *p, unsigned n);
*** PyCapsule Calls
******************************************************************************
*****************************************************************************/
#error "Capsule @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
/**
* Wrap LLVM functions of the type
@ -330,7 +330,7 @@ _w ## func (PyObject *self, PyObject *args) \
{ \
const char *arg1; \
\
if (!PyArg_ParseTuple(args, "s", &arg1)) \
if (!PyArg_ParseTuple(args, "y#", &arg1)) \
return NULL; \
\
return ctor_ ## outtype ( func (arg1)); \
@ -363,7 +363,7 @@ _w ## func (PyObject *self, PyObject *args) \
if (!(arg1 = ( intype1 )get_object_arg(args))) \
return NULL; \
\
return PyString_FromString( func (arg1)); \
return PyBytes_FromString( func (arg1)); \
}
/**
@ -395,7 +395,7 @@ _w ## func (PyObject *self, PyObject *args) \
const char *arg2; \
intype1 arg1; \
\
if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \
if (!PyArg_ParseTuple(args, "Oy#", &obj1, &arg2)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -416,7 +416,7 @@ _w ## func (PyObject *self, PyObject *args) \
const char *arg2; \
intype1 arg1; \
\
if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \
if (!PyArg_ParseTuple(args, "Oy#", &obj1, &arg2)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -479,7 +479,7 @@ _w ## func (PyObject *self, PyObject *args) \
intype2 arg2; \
const char *arg3; \
\
if (!PyArg_ParseTuple(args, "OOs", &obj1, &obj2, &arg3)) \
if (!PyArg_ParseTuple(args, "OOy#", &obj1, &obj2, &arg3)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -588,7 +588,7 @@ _w ## func (PyObject *self, PyObject *args) \
const char *arg2; \
intype3 arg3; \
\
if (!PyArg_ParseTuple(args, "OsO", &obj1, &arg2, &obj3)) \
if (!PyArg_ParseTuple(args, "Oy#O", &obj1, &arg2, &obj3)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -612,7 +612,7 @@ _w ## func (PyObject *self, PyObject *args) \
int arg3; \
const char *arg4; \
\
if (!PyArg_ParseTuple(args, "OOis", &obj1, &obj2, &arg3, &arg4)) \
if (!PyArg_ParseTuple(args, "OOiy#", &obj1, &obj2, &arg3, &arg4)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -635,7 +635,7 @@ _w ## func (PyObject *self, PyObject *args) \
intype3 arg3; \
const char *arg4; \
\
if (!PyArg_ParseTuple(args, "OOOs", &obj1, &obj2, &obj3, &arg4)) \
if (!PyArg_ParseTuple(args, "OOOy#", &obj1, &obj2, &obj3, &arg4)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -709,7 +709,7 @@ _w ## func (PyObject *self, PyObject *args) \
intype4 arg4; \
const char *arg5; \
\
if (!PyArg_ParseTuple(args, "OOOOs", &obj1, &obj2, &obj3, &obj4, &arg5)) \
if (!PyArg_ParseTuple(args, "OOOOy#", &obj1, &obj2, &obj3, &obj4, &arg5)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -735,7 +735,7 @@ _w ## func (PyObject *self, PyObject *args) \
intype4 arg4; \
const char *arg5; \
\
if (!PyArg_ParseTuple(args, "OiOOs", &obj1, &arg2, &obj3, &obj4, &arg5)) \
if (!PyArg_ParseTuple(args, "OiOOy#", &obj1, &arg2, &obj3, &obj4, &arg5)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -931,7 +931,7 @@ _w ## func (PyObject *self, PyObject *args) \
unsigned arg3n; \
outtype ret; \
\
if (!PyArg_ParseTuple(args, "OOOs", &obj1, &obj2, &obj3, &arg4))\
if (!PyArg_ParseTuple(args, "OOOy#", &obj1, &obj2, &obj3, &arg4))\
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
@ -963,7 +963,7 @@ _w ## func (PyObject *self, PyObject *args) \
return NULL; \
\
val = func (arg1); \
ret = PyString_FromString(val); \
ret = PyBytes_FromString(val); \
LLVMDisposeMessage(val); \
return ret; \
}
@ -1201,7 +1201,7 @@ _w ## func (PyObject *self, PyObject *args) \
if (!(arg1 = ( intype1 )get_object_arg(args))) \
return NULL; \
\
return PyString_FromString( func (arg1)); \
return PyBytes_FromString( func (arg1)); \
}
/**
@ -1800,7 +1800,7 @@ _w ## func (PyObject *self, PyObject *args) \
return NULL; \
\
val = func (arg1); \
ret = PyString_FromString(val); \
ret = PyBytes_FromString(val); \
LLVMDisposeMessage(val); \
return ret; \
}