From 13815fd2f3ab527ec093fd49cca4391628ef3cd3 Mon Sep 17 00:00:00 2001 From: AndrewBC Date: Sun, 12 Jun 2011 03:41:03 -0500 Subject: [PATCH] It compiles! It also segfaults when tested! :D --- llvm/_core.c | 37 +- llvm/extra.cpp | 5 + llvm/extra.h | 5 + llvm/wrap.c | 22 +- llvm/wrap.h | 1008 +++++++++++++++++++++++++++++++++++++++++------- setup.py | 5 +- 6 files changed, 923 insertions(+), 159 deletions(-) diff --git a/llvm/_core.c b/llvm/_core.c index f48975c..b844561 100644 --- a/llvm/_core.c +++ b/llvm/_core.c @@ -32,6 +32,11 @@ #include "wrap.h" #include "extra.h" +/* Project-wide setting */ +#if (PY_MAJOR_VERSION >= 3) +#define LLVM_PY_USE_PYCAPSULE +#endif + // Python include #include "Python.h" @@ -1027,12 +1032,10 @@ _wLLVMRemoveModule2(PyObject *self, PyObject *args) #ifdef LLVM_PY_USE_PYCAPSULE ee = (LLVMExecutionEngineRef) PyCapsule_GetPointer(obj_ee, NULL); - fn = (LLVMValueRef) PyCapsule_GetPointer(obj_fn, NULL); -#error "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Using capsule" + mod = (LLVMValueRef) PyCapsule_GetPointer(obj_mod, NULL); #else ee = (LLVMExecutionEngineRef) PyCObject_AsVoidPtr(obj_ee); mod = (LLVMModuleRef) PyCObject_AsVoidPtr(obj_mod); -#error "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Using pycobject" #endif LLVMRemoveModule(ee, mod, &mod_new, &outmsg); @@ -1749,11 +1752,37 @@ static PyMethodDef core_methods[] = { { NULL } }; +// Module main function, hairy because of py3k port + +#if (PY_MAJOR_VERSION >= 3) +struct PyModuleDef module_def = { + PyModuleDef_HEAD_INIT, + "_core", + NULL, + -1, + core_methods, + NULL, NULL, NULL, NULL +}; +#define INITERROR return NULL +PyObject * +PyInit__core(void) +#else +#define INITERROR return PyMODINIT_FUNC init_core(void) +#endif { LLVMLinkInJIT(); LLVMLinkInInterpreter(); LLVMInitializeNativeTarget(); - Py_InitModule("_core", core_methods); +#if PY_MAJOR_VERSION >= 3 + PyObject *module = PyModule_Create( &module_def ); +#else + PyObject *module = Py_InitModule("_core", core_methods); +#endif + if (module == NULL) + INITERROR; +#if PY_MAJOR_VERSION >= 3 + return module; +#endif } diff --git a/llvm/extra.cpp b/llvm/extra.cpp index bf5eb93..8b990f9 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -28,6 +28,11 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* Project-wide setting */ +#if (PY_MAJOR_VERSION >= 3) +#define LLVM_PY_USE_PYCAPSULE +#endif + /** * These are some "extra" functions not available in the standard LLVM-C * bindings, but are required / good-to-have inorder to implement the diff --git a/llvm/extra.h b/llvm/extra.h index fb80233..4aaf407 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -37,6 +37,11 @@ #ifndef LLVM_PY_EXTRA_H #define LLVM_PY_EXTRA_H +/* Project-wide setting */ +#if (PY_MAJOR_VERSION >= 3) +#define LLVM_PY_USE_PYCAPSULE +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/llvm/wrap.c b/llvm/wrap.c index 09a2ad8..c57952b 100644 --- a/llvm/wrap.c +++ b/llvm/wrap.c @@ -30,22 +30,36 @@ #include "wrap.h" +/* Project-wide setting */ +#if (PY_MAJOR_VERSION >= 3) +#define LLVM_PY_USE_PYCAPSULE +#endif + /*===----------------------------------------------------------------------===*/ /* Helper functions/macros */ /*===----------------------------------------------------------------------===*/ +#ifdef LLVM_PY_USE_PYCAPSULE + #define _define_std_ctor(typ) \ PyObject * ctor_ ## typ ( typ p) \ { \ if (p) \ -#ifdef LLVM_PY_USE_PYCAPSULE \ return PyCapsule_New(p, NULL, NULL); \ -#else \ - return PyCObject_FromVoidPtr(p, NULL); \ -#endif \ Py_RETURN_NONE; \ } +#else + +#define _define_std_ctor(typ) \ +PyObject * ctor_ ## typ ( typ p) \ +{ \ + if (p) \ + return PyCObject_FromVoidPtr(p, NULL); \ + Py_RETURN_NONE; \ +} + +#endif /*===----------------------------------------------------------------------===*/ /* Type ctor/dtor */ diff --git a/llvm/wrap.h b/llvm/wrap.h index 3686386..aee1c49 100644 --- a/llvm/wrap.h +++ b/llvm/wrap.h @@ -27,11 +27,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -/* Project-wide setting */ -#if (PY_MAJOR_VERSION >= 3) -#define LLVM_PY_USE_PYCAPSULE -#endif /** * Functions and macros to aid in wrapping. @@ -40,6 +35,10 @@ #ifndef LLVM_PY_WRAP_H #define LLVM_PY_WRAP_H +/* Project-wide setting */ +#if (PY_MAJOR_VERSION >= 3) +#define LLVM_PY_USE_PYCAPSULE +#endif /* python includes */ #include @@ -128,6 +127,16 @@ PyObject *make_list_from_LLVMValueRef_array(LLVMValueRef *p, unsigned n); * conventions. */ + + +#ifdef LLVM_PY_USE_PYCAPSULE +/****************************************************************************** + ****************************************************************************** + *** PyCapsule Calls + ****************************************************************************** + *****************************************************************************/ + + /** * Wrap LLVM functions of the type * outtype func(intype1 arg1) @@ -174,13 +183,8 @@ _w ## func (PyObject *self, PyObject *args) \ \ if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) \ return NULL; \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ + arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ \ return ctor_ ## outtype ( func (arg1, arg2)); \ } @@ -199,13 +203,8 @@ _w ## func (PyObject *self, PyObject *args) \ \ if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) \ return NULL; \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ + arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -225,11 +224,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ if (!PyArg_ParseTuple(args, "OI", &obj1, &arg2)) \ return NULL; \ -#ifdef LLVM_PY_USE_PYCAPSULE \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ + arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ \ return ctor_ ## outtype ( func (arg1, arg2)); \ } @@ -250,15 +245,9 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOO", &obj1, &obj2, &obj3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -279,15 +268,9 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOO", &obj1, &obj2, &obj3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ -#endif \ \ func (arg1, arg2, arg3); \ Py_RETURN_NONE; \ @@ -309,13 +292,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "IOO", &arg1, &obj2, &obj3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ -#else \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -336,13 +314,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "IOO", &arg1, &obj2, &obj3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ -#else \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -425,11 +398,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -450,11 +419,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2)); \ } @@ -474,11 +439,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -499,11 +460,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -525,13 +482,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOs", &obj1, &obj2, &arg3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)) ;\ } @@ -552,13 +504,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)) ;\ } @@ -579,13 +526,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOK", &obj1, &obj2, &arg3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)) ;\ } @@ -605,11 +547,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Oii", &obj1, &arg2, &arg3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ \ func (arg1, arg2, arg3); \ Py_RETURN_NONE; \ @@ -631,11 +569,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Oii", &obj1, &arg2, &arg3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ \ func (arg1, arg2, arg3); \ Py_RETURN_NONE; \ @@ -657,13 +591,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OsO", &obj1, &arg2, &obj3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -686,13 +615,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOis", &obj1, &obj2, &arg3, &arg4)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)) ;\ } @@ -714,15 +638,9 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOOs", &obj1, &obj2, &obj3, &arg4)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ } @@ -744,15 +662,9 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOOi", &obj1, &obj2, &obj3, &arg4)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ } @@ -774,17 +686,10 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOOO", &obj1, &obj2, &obj3, &obj4)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ - arg4 = ( intype4 ) PyCObject_AsVoidPtr(obj4); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ } @@ -807,17 +712,10 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOOOs", &obj1, &obj2, &obj3, &obj4, &arg5)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ - arg4 = ( intype4 ) PyCObject_AsVoidPtr(obj4); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ } @@ -840,15 +738,9 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OiOOs", &obj1, &arg2, &obj3, &obj4, &arg5)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ - arg4 = ( intype4 ) PyCObject_AsVoidPtr(obj4); \ -#endif \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ } @@ -871,11 +763,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ + arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2n = (unsigned) PyList_Size(obj2); \ if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n))) \ return PyErr_NoMemory(); \ @@ -957,11 +845,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ + arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2n = (unsigned) PyList_Size(obj2); \ if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n))) \ return PyErr_NoMemory(); \ @@ -990,11 +874,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OiO", &obj1, &arg2, &obj3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ -#endif \ + arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg3n = (unsigned) PyList_Size(obj3); \ if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ return PyErr_NoMemory(); \ @@ -1023,13 +903,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOO", &obj1, &obj2, &obj3)) \ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ arg3n = (unsigned) PyList_Size(obj3); \ if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ return PyErr_NoMemory(); \ @@ -1059,13 +934,8 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOOs", &obj1, &obj2, &obj3, &arg4))\ return NULL; \ \ -#ifdef LLVM_PY_USE_PYCAPSULE \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ -#else \ - arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ - arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ -#endif \ arg3n = ( unsigned ) PyList_Size(obj3); \ if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ return PyErr_NoMemory(); \ @@ -1098,5 +968,843 @@ _w ## func (PyObject *self, PyObject *args) \ return ret; \ } +#else +/****************************************************************************** + ****************************************************************************** + *** PyCObject calls + ****************************************************************************** + *****************************************************************************/ + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1) + */ +#define _wrap_obj2obj(func, intype1, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + intype1 arg1; \ + \ + if (!(arg1 = ( intype1 )get_object_arg(args))) \ + return NULL; \ + \ + return ctor_ ## outtype ( func (arg1)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(int arg1) + */ +#define _wrap_int2obj(func, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + int arg1; \ + \ + if (!PyArg_ParseTuple(args, "i", &arg1)) \ + return NULL; \ + \ + return ctor_ ## outtype ( func (arg1)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2) + */ +#define _wrap_objobj2obj(func, intype1, intype2, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 arg2; \ + \ + if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) \ + return NULL; \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + \ + return ctor_ ## outtype ( func (arg1, arg2)); \ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1, intype2 arg2) + */ +#define _wrap_objobj2none(func, intype1, intype2) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 arg2; \ + \ + if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) \ + return NULL; \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + \ + func (arg1, arg2); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, arg2) + */ +#define _wrap_objint2obj(func, intype1, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + intype1 arg1; \ + unsigned int arg2; \ + \ + if (!PyArg_ParseTuple(args, "OI", &obj1, &arg2)) \ + return NULL; \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + \ + return ctor_ ## outtype ( func (arg1, arg2)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3 arg3) + */ +#define _wrap_objobjobj2obj(func, intype1, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + \ + if (!PyArg_ParseTuple(args, "OOO", &obj1, &obj2, &obj3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1, intype2 arg2, intype3 arg3) + */ +#define _wrap_objobjobj2none(func, intype1, intype2, intype3) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + \ + if (!PyArg_ParseTuple(args, "OOO", &obj1, &obj2, &obj3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + \ + func (arg1, arg2, arg3); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * outtype func( arg1, intype2 arg2, intype3 arg3) + */ +#define _wrap_intobjobj2obj(func, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + unsigned int arg1; \ + PyObject *obj2, *obj3; \ + intype2 arg2; \ + intype3 arg3; \ + \ + if (!PyArg_ParseTuple(args, "IOO", &arg1, &obj2, &obj3)) \ + return NULL; \ + \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(enum_intype1 arg1, intype2 arg2, intype3 arg3) + */ +#define _wrap_enumobjobj2obj(func, intype1, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + intype1 arg1; \ + PyObject *obj2, *obj3; \ + intype2 arg2; \ + intype3 arg3; \ + \ + if (!PyArg_ParseTuple(args, "IOO", &arg1, &obj2, &obj3)) \ + return NULL; \ + \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(const char *s) + */ +#define _wrap_str2obj(func, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + const char *arg1; \ + \ + if (!PyArg_ParseTuple(args, "s", &arg1)) \ + return NULL; \ + \ + return ctor_ ## outtype ( func (arg1)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func() + */ +#define _wrap_none2obj(func, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + if (!PyArg_ParseTuple(args, "")) \ + return NULL; \ + \ + return ctor_ ## outtype ( func ()); \ +} + +/** + * Wrap LLVM functions of the type + * const char *func(intype1 arg1) + */ +#define _wrap_obj2str(func, intype1) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + intype1 arg1; \ + \ + if (!(arg1 = ( intype1 )get_object_arg(args))) \ + return NULL; \ + \ + return PyString_FromString( func (arg1)); \ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1) + */ +#define _wrap_obj2none(func, intype1) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + intype1 arg1; \ + \ + if (!(arg1 = ( intype1 )get_object_arg(args))) \ + return NULL; \ + \ + func (arg1); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1, const char *arg2) + */ +#define _wrap_objstr2none(func, intype1) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + const char *arg2; \ + intype1 arg1; \ + \ + if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + \ + func (arg1, arg2); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, const char *arg2) + */ +#define _wrap_objstr2obj(func, intype1, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + const char *arg2; \ + intype1 arg1; \ + \ + if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + \ + return ctor_ ## outtype ( func (arg1, arg2)); \ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1, arg2) + */ +#define _wrap_objint2none(func, intype1) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + int arg2; \ + intype1 arg1; \ + \ + if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + \ + func (arg1, arg2); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1, enum_intype2 arg2) + */ +#define _wrap_objenum2none(func, intype1, intype2) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + intype1 arg1; \ + intype2 arg2; \ + \ + if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + \ + func (arg1, arg2); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, const char *arg3) + */ +#define _wrap_objobjstr2obj(func, intype1, intype2, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 arg2; \ + const char *arg3; \ + \ + if (!PyArg_ParseTuple(args, "OOs", &obj1, &obj2, &arg3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3)) ;\ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, int arg3) + */ +#define _wrap_objobjint2obj(func, intype1, intype2, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 arg2; \ + int arg3; \ + \ + if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3)) ;\ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, unsigned long long arg3) + */ +#define _wrap_objobjull2obj(func, intype1, intype2, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 arg2; \ + unsigned long long arg3; \ + \ + if (!PyArg_ParseTuple(args, "OOK", &obj1, &obj2, &arg3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3)) ;\ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1, arg2, arg3) + */ +#define _wrap_objintint2none(func, intype1) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + intype1 arg1; \ + int arg2, arg3; \ + \ + if (!PyArg_ParseTuple(args, "Oii", &obj1, &arg2, &arg3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + \ + func (arg1, arg2, arg3); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * void func(intype1 arg1, arg2, enum_intype3 arg3) + */ +#define _wrap_objintenum2none(func, intype1, intype3) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + intype1 arg1; \ + int arg2; \ + intype3 arg3; \ + \ + if (!PyArg_ParseTuple(args, "Oii", &obj1, &arg2, &arg3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + \ + func (arg1, arg2, arg3); \ + Py_RETURN_NONE; \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, const char *arg2, intype3 arg3) + */ +#define _wrap_objstrobj2obj(func, intype1, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj3; \ + intype1 arg1; \ + const char *arg2; \ + intype3 arg3; \ + \ + if (!PyArg_ParseTuple(args, "OsO", &obj1, &arg2, &obj3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ +} + + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, int arg3, const char *arg4) + */ +#define _wrap_objobjintstr2obj(func, intype1, intype2, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 arg2; \ + int arg3; \ + const char *arg4; \ + \ + if (!PyArg_ParseTuple(args, "OOis", &obj1, &obj2, &arg3, &arg4)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)) ;\ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4) + */ +#define _wrap_objobjobjstr2obj(func, intype1, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + const char *arg4; \ + \ + if (!PyArg_ParseTuple(args, "OOOs", &obj1, &obj2, &obj3, &arg4)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, arg4) + */ +#define _wrap_objobjobjint2obj(func, intype1, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + int arg4; \ + \ + if (!PyArg_ParseTuple(args, "OOOi", &obj1, &obj2, &obj3, &arg4)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4) + */ +#define _wrap_objobjobjobj2obj(func, intype1, intype2, intype3, intype4, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3, *obj4; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + intype4 arg4; \ + \ + if (!PyArg_ParseTuple(args, "OOOO", &obj1, &obj2, &obj3, &obj4)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + arg4 = ( intype4 ) PyCObject_AsVoidPtr(obj4); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4, const char *arg5) + */ +#define _wrap_objobjobjobjstr2obj(func, intype1, intype2, intype3, intype4, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3, *obj4; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + intype4 arg4; \ + const char *arg5; \ + \ + if (!PyArg_ParseTuple(args, "OOOOs", &obj1, &obj2, &obj3, &obj4, &arg5)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + arg4 = ( intype4 ) PyCObject_AsVoidPtr(obj4); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, enum_intype2 arg2, intype3 arg3, intype4 arg4, const char *arg5) + */ +#define _wrap_objenumobjobjstr2obj(func, intype1, intype2, intype3, intype4, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj3, *obj4; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + intype4 arg4; \ + const char *arg5; \ + \ + if (!PyArg_ParseTuple(args, "OiOOs", &obj1, &arg2, &obj3, &obj4, &arg5)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg3 = ( intype3 ) PyCObject_AsVoidPtr(obj3); \ + arg4 = ( intype4 ) PyCObject_AsVoidPtr(obj4); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 *arg2v, unsigned arg2n) + * where arg2v is an array of intype2 elements, arg2n in length. + */ +#define _wrap_objlist2obj(func, intype1, intype2, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 *arg2v; \ + unsigned arg2n; \ + outtype ret; \ + \ + if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) \ + return NULL; \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2n = (unsigned) PyList_Size(obj2); \ + if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n))) \ + return PyErr_NoMemory(); \ + \ + ret = func (arg1, arg2v, arg2n); \ + free(arg2v); \ + return ctor_ ## outtype (ret); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 *arg1v, unsigned arg1n, int arg2) + * where arg1v is an array of intype1 elements, arg1n in length. + */ +#define _wrap_listint2obj(func, intype1, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + int arg2; \ + intype1 *arg1v; \ + unsigned arg1n; \ + outtype ret; \ + \ + if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ + return NULL; \ + \ + arg1n = (unsigned) PyList_Size(obj1); \ + if (!(arg1v = ( intype1 *)make_array_from_list(obj1, arg1n))) \ + return PyErr_NoMemory(); \ + \ + ret = func (arg1v, arg1n, arg2); \ + free(arg1v); \ + return ctor_ ## outtype (ret); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 *arg1v, unsigned arg1n) + * where arg1v is an array of intype1 elements, arg1n in length. + */ +#define _wrap_list2obj(func, intype1, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1; \ + intype1 *arg1v; \ + unsigned arg1n; \ + outtype ret; \ + \ + if (!PyArg_ParseTuple(args, "O", &obj1)) \ + return NULL; \ + \ + arg1n = (unsigned) PyList_Size(obj1); \ + if (!(arg1v = ( intype1 *)make_array_from_list(obj1, arg1n))) \ + return PyErr_NoMemory(); \ + \ + ret = func (arg1v, arg1n); \ + free(arg1v); \ + return ctor_ ## outtype (ret); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 *arg2v, unsigned arg2n, int arg3) + * where arg2v is an array of intype2 elements, arg2n in length. + */ +#define _wrap_objlistint2obj(func, intype1, intype2, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2; \ + intype1 arg1; \ + intype2 *arg2v; \ + unsigned arg2n; \ + int arg3; \ + outtype ret; \ + \ + if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2n = (unsigned) PyList_Size(obj2); \ + if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n))) \ + return PyErr_NoMemory(); \ + \ + ret = func (arg1, arg2v, arg2n, arg3); \ + free(arg2v); \ + return ctor_ ## outtype (ret); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, int arg2, intype3 *arg3v, unsigned arg3n) + * where arg3v is an array of intype3 elements, arg3n in length. + */ +#define _wrap_objintlist2obj(func, intype1, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj3; \ + intype1 arg1; \ + int arg2; \ + intype3 *arg3v; \ + unsigned arg3n; \ + outtype ret; \ + \ + if (!PyArg_ParseTuple(args, "OiO", &obj1, &arg2, &obj3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg3n = (unsigned) PyList_Size(obj3); \ + if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ + return PyErr_NoMemory(); \ + \ + ret = func (arg1, arg2, arg3v, arg3n); \ + free(arg3v); \ + return ctor_ ## outtype (ret); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3 *arg3v, unsigned arg3n) + * where arg3v is an array of intype3 elements, arg3n in length. + */ +#define _wrap_objobjlist2obj(func, intype1, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 *arg3v; \ + unsigned arg3n; \ + outtype ret; \ + \ + if (!PyArg_ParseTuple(args, "OOO", &obj1, &obj2, &obj3)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3n = (unsigned) PyList_Size(obj3); \ + if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ + return PyErr_NoMemory(); \ + \ + ret = func (arg1, arg2, arg3v, arg3n); \ + free(arg3v); \ + return ctor_ ## outtype (ret); \ +} + +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3 *arg3v, unsigned arg3n, const char *arg4) + * where arg3v is an array of intype3 elements, arg3n in length. + */ +#define _wrap_objobjliststr2obj(func, intype1, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3; \ + const char *arg4; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 *arg3v; \ + unsigned arg3n; \ + outtype ret; \ + \ + if (!PyArg_ParseTuple(args, "OOOs", &obj1, &obj2, &obj3, &arg4))\ + return NULL; \ + \ + arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \ + arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \ + arg3n = ( unsigned ) PyList_Size(obj3); \ + if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ + return PyErr_NoMemory(); \ + \ + ret = func (arg1, arg2, arg3v, arg3n, arg4); \ + free(arg3v); \ + return ctor_ ## outtype (ret); \ +} + +/** + * Wrap LLVM dump-to-string functions of the type + * char *func(intype1) + * where the return value has to be disposed after use by calling + * LLVMDisposeMessage. + */ +#define _wrap_dumper(func, intype1) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + intype1 arg1; \ + char *val; \ + PyObject *ret; \ + \ + if (!(arg1= ( intype1 ) get_object_arg(args))) \ + return NULL; \ + \ + val = func (arg1); \ + ret = PyString_FromString(val); \ + LLVMDisposeMessage(val); \ + return ret; \ +} + +#endif /* LLVM_PY_USE_PYCAPSULE */ #endif /* LLVM_PY_WRAP_H */ diff --git a/setup.py b/setup.py index 1780f73..4bb94ae 100755 --- a/setup.py +++ b/setup.py @@ -85,10 +85,13 @@ def call_setup(llvm_config): 'asmparser', 'linker', 'support']) std_libs = [ 'pthread', 'm', 'stdc++' ] + extra_link_args = ["-fPIC"] if not ("openbsd" in sys.platform or "freebsd" in sys.platform): std_libs.append("dl") if "darwin" in sys.platform: std_libs.append("ffi") + extra_link_args += ['-framework', 'Python'] + ext_core = Extension( 'llvm._core', @@ -101,7 +104,7 @@ def call_setup(llvm_config): library_dirs = [libdir], libraries = std_libs + libs_core, extra_objects = objs_core, - extra_link_args = ["-fPIC"]) + extra_link_args = extra_link_args) setup( name='llvm-py',