From 46a9a86085761354c94a434b1f98ef3f25caf303 Mon Sep 17 00:00:00 2001 From: AndrewBC Date: Sun, 12 Jun 2011 13:58:57 -0500 Subject: [PATCH] Fixed some old PyInt usage, drastically reduced compile-time warnings --- llvm/_core.c | 19 ++++++++++--------- llvm/extra.cpp | 5 ----- llvm/extra.h | 5 ----- llvm/wrap.c | 2 +- llvm/wrap.h | 30 +++++++++++++++--------------- test/testall.py | 2 +- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/llvm/_core.c b/llvm/_core.c index b9ce878..2b6d6f0 100644 --- a/llvm/_core.c +++ b/llvm/_core.c @@ -32,10 +32,7 @@ #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" @@ -55,6 +52,10 @@ typedef int Py_ssize_t; #endif +/* Project-wide setting */ +#if (PY_MAJOR_VERSION >= 3) +#define LLVM_PY_USE_PYCAPSULE +#endif /*===----------------------------------------------------------------------===*/ /* Modules */ @@ -66,7 +67,7 @@ _wLLVMModuleCreateWithName(PyObject *self, PyObject *args) const char *s; LLVMModuleRef module; - if (!PyArg_ParseTuple(args, "y#", &s)) + if (!PyArg_ParseTuple(args, "s", &s)) return NULL; module = LLVMModuleCreateWithName(s); @@ -430,7 +431,7 @@ _wLLVMConstString(PyObject *self, PyObject *args) int dont_null_terminate; LLVMValueRef val; - if (!PyArg_ParseTuple(args, "y#i", &s, &dont_null_terminate)) + if (!PyArg_ParseTuple(args, "si", &s, &dont_null_terminate)) return NULL; val = LLVMConstString(s, strlen(s), dont_null_terminate); @@ -647,7 +648,7 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args) LLVMBasicBlockRef then_blk, catch_blk; LLVMValueRef inst; - if (!PyArg_ParseTuple(args, "OOOOOy#", &obj1, &obj2, &obj3, &obj4, &obj5, &name)) + if (!PyArg_ParseTuple(args, "OOOOOs", &obj1, &obj2, &obj3, &obj4, &obj5, &name)) return NULL; #ifdef LLVM_PY_USE_PYCAPSULE @@ -763,7 +764,7 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args) char *outmsg; PyObject *ret; - if (!PyArg_ParseTuple(args, "y#", &path)) + if (!PyArg_ParseTuple(args, "s", &path)) return NULL; if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) { @@ -1221,7 +1222,7 @@ _wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args) char *outmsg; PyObject *ret; - if (!PyArg_ParseTuple(args, "y#", &filename)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } diff --git a/llvm/extra.cpp b/llvm/extra.cpp index bd1f5ab..57ce418 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -28,11 +28,6 @@ * 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 4aaf407..fb80233 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -37,11 +37,6 @@ #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 c57952b..4e02516 100644 --- a/llvm/wrap.c +++ b/llvm/wrap.c @@ -79,7 +79,7 @@ _define_std_ctor(LLVMGenericValueRef) PyObject *ctor_int(int i) { - return PyInt_FromLong(i); + return PyLong_FromLong((long)i); } PyObject *ctor_llvmwrap_ull(llvmwrap_ull ull) diff --git a/llvm/wrap.h b/llvm/wrap.h index cfd294f..191566d 100644 --- a/llvm/wrap.h +++ b/llvm/wrap.h @@ -35,10 +35,6 @@ #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 @@ -50,6 +46,11 @@ #include "llvm-c/ExecutionEngine.h" #include "llvm-c/Target.h" +/* Project-wide setting */ +#if PY_MAJOR_VERSION >= 3 +#define LLVM_PY_USE_PYCAPSULE +#endif + /*===----------------------------------------------------------------------===*/ /* Typedefs */ /*===----------------------------------------------------------------------===*/ @@ -135,7 +136,6 @@ 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, "y#", &arg1)) \ + if (!PyArg_ParseTuple(args, "s", &arg1)) \ return NULL; \ \ return ctor_ ## outtype ( func (arg1)); \ @@ -395,7 +395,7 @@ _w ## func (PyObject *self, PyObject *args) \ const char *arg2; \ intype1 arg1; \ \ - if (!PyArg_ParseTuple(args, "Oy#", &obj1, &arg2)) \ + if (!PyArg_ParseTuple(args, "Os", &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, "Oy#", &obj1, &arg2)) \ + if (!PyArg_ParseTuple(args, "Os", &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, "OOy#", &obj1, &obj2, &arg3)) \ + if (!PyArg_ParseTuple(args, "OOs", &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, "Oy#O", &obj1, &arg2, &obj3)) \ + if (!PyArg_ParseTuple(args, "OsO", &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, "OOiy#", &obj1, &obj2, &arg3, &arg4)) \ + if (!PyArg_ParseTuple(args, "OOis", &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, "OOOy#", &obj1, &obj2, &obj3, &arg4)) \ + if (!PyArg_ParseTuple(args, "OOOs", &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, "OOOOy#", &obj1, &obj2, &obj3, &obj4, &arg5)) \ + if (!PyArg_ParseTuple(args, "OOOOs", &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, "OiOOy#", &obj1, &arg2, &obj3, &obj4, &arg5)) \ + if (!PyArg_ParseTuple(args, "OiOOs", &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, "OOOy#", &obj1, &obj2, &obj3, &arg4))\ + if (!PyArg_ParseTuple(args, "OOOs", &obj1, &obj2, &obj3, &arg4))\ return NULL; \ \ arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ diff --git a/test/testall.py b/test/testall.py index 5f2dced..8bd57de 100755 --- a/test/testall.py +++ b/test/testall.py @@ -13,7 +13,6 @@ from llvm.passes import * ti = Type.int() - def do_llvmexception(): print(" Testing class LLVMException") e = LLVMException() @@ -36,6 +35,7 @@ def do_misc(): except LLVMException: pass try: + print(" ... second one now") load_library_permanently("no*such*so") except LLVMException: pass