It compiles! It also segfaults when tested! :D

This commit is contained in:
AndrewBC 2011-06-12 03:41:03 -05:00
commit 13815fd2f3
6 changed files with 923 additions and 159 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -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 */

File diff suppressed because it is too large Load diff

View file

@ -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',