diff --git a/llvm/_core.cpp b/llvm/_core.cpp index ef1a68d..99642e8 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -51,9 +51,6 @@ typedef unsigned int LLVMLinkerMode; #endif -/* libc includes */ -#include /* for malloc(), free() */ - /* Compatibility with Python 2.4: Py_ssize_t is not available. */ #ifndef PY_SSIZE_T_MAX typedef int Py_ssize_t; @@ -67,13 +64,12 @@ static PyObject * _wLLVMModuleCreateWithName(PyObject *self, PyObject *args) { const char *s; - LLVMModuleRef module; if (!PyArg_ParseTuple(args, "s:LLVMModuleCreateWithName", &s)) { return NULL; } - module = LLVMModuleCreateWithName(s); + const LLVMModuleRef module = LLVMModuleCreateWithName(s); return ctor_LLVMModuleRef(module); } @@ -95,16 +91,13 @@ _wrap_objstrobj2obj(LLVMModuleGetOrInsertFunction, LLVMModuleRef, static PyObject * _wLLVMVerifyModule(PyObject *self, PyObject *args) { - char *outmsg; - PyObject *ret; - LLVMModuleRef m; + const LLVMModuleRef m = get_object_arg(args) ; + if (!m) return NULL; - if (!(m = (LLVMModuleRef)get_object_arg(args))) - return NULL; - - outmsg = 0; + char *outmsg = 0; (void) LLVMVerifyModule(m, LLVMReturnStatusAction, &outmsg); + PyObject *ret; if (outmsg) { ret = PyUnicode_FromString(outmsg); LLVMDisposeMessage(outmsg); @@ -122,13 +115,13 @@ _wLLVMVerifyModule(PyObject *self, PyObject *args) static PyObject* _wLLVMGetModuleFromAssembly(PyObject *self, PyObject *args) { - char * str; + const char * str; if ( !PyArg_ParseTuple(args, "s", &str) ){ return NULL; } char * outmsg = 0; - LLVMModuleRef mod = LLVMGetModuleFromAssembly(str, &outmsg); + const LLVMModuleRef mod = LLVMGetModuleFromAssembly(str, &outmsg); if ( !mod ){ if ( outmsg ){ @@ -146,19 +139,18 @@ _wLLVMGetModuleFromAssembly(PyObject *self, PyObject *args) static PyObject * _wLLVMGetModuleFromBitcode(PyObject *self, PyObject *args) { - PyObject *obj, *ret; - Py_ssize_t len; - char *start, *outmsg; - LLVMModuleRef m; + PyObject *obj ; if (!PyArg_ParseTuple(args, "S", &obj)) return NULL; - start = PyBytes_AsString(obj); - len = PyBytes_Size(obj); + const char *start = PyBytes_AsString(obj); + const Py_ssize_t len = PyBytes_Size(obj); - outmsg = 0; - m = LLVMGetModuleFromBitcode(start, len, &outmsg); + char *outmsg = 0; + LLVMModuleRef m = LLVMGetModuleFromBitcode(start, len, &outmsg); + + PyObject *ret; if (!m) { if (outmsg) { ret = PyUnicode_FromString(outmsg); @@ -175,29 +167,23 @@ _wLLVMGetModuleFromBitcode(PyObject *self, PyObject *args) static PyObject * _wLLVMGetBitcodeFromModule(PyObject *self, PyObject *args) { - PyObject *ret; - unsigned len; - unsigned char *bytes; - LLVMModuleRef m; - if (!(m = (LLVMModuleRef)get_object_arg(args))) - return NULL; + const LLVMModuleRef m = get_object_arg(args) ; + if (!m ) return NULL; - if (!(bytes = LLVMGetBitcodeFromModule(m, &len))) - Py_RETURN_NONE; + size_t len; + unsigned const char *ubytes = LLVMGetBitcodeFromModule(m, &len) ; + if ( !ubytes ) Py_RETURN_NONE; - ret = PyBytes_FromStringAndSize((char *)bytes, (Py_ssize_t)len); - LLVMDisposeMessage((char *)bytes); + const char *chars = reinterpret_cast(ubytes) ; + PyObject *ret = PyBytes_FromStringAndSize(chars, len); + LLVMDisposeMessage(const_cast(chars)); return ret; } static PyObject * _wLLVMGetNativeCodeFromModule(PyObject * self, PyObject * args) { - PyObject * ret; - unsigned len; - unsigned char * bytes; - LLVMModuleRef m; PyObject * arg_m; int arg_use_asm; @@ -205,33 +191,38 @@ _wLLVMGetNativeCodeFromModule(PyObject * self, PyObject * args) if (!PyArg_ParseTuple(args, "Oi", &arg_m, &arg_use_asm)) return NULL; - m = (LLVMModuleRef) PyCapsule_GetPointer(arg_m, NULL); + const LLVMModuleRef m = pycap_get( arg_m ) ; std::string error; - bytes = LLVMGetNativeCodeFromModule(m, arg_use_asm, &len, error); + size_t len; + unsigned const char * ubytes + = LLVMGetNativeCodeFromModule(m, arg_use_asm, &len, error); if ( !error.empty() ){ PyErr_SetString(PyExc_RuntimeError, error.c_str()); } - ret = PyBytes_FromStringAndSize((char *)bytes, (Py_ssize_t)len); - delete [] bytes; + const char *chars = reinterpret_cast(ubytes) ; + PyObject * ret = PyBytes_FromStringAndSize(chars, len); + + LLVMDisposeMessage(const_cast(chars)); + return ret; } static PyObject * _wLLVMLinkModules(PyObject *self, PyObject *args) { - PyObject *dest_obj, *src_obj, *ret; - LLVMModuleRef dest, src; - char *errmsg; - unsigned int mode = 0; + size_t mode = 0; + PyObject *dest_obj, *src_obj ; if (!PyArg_ParseTuple(args, "OO|I", &dest_obj, &src_obj, &mode)) return NULL; - dest = (LLVMModuleRef) PyCapsule_GetPointer(dest_obj, NULL); - src = (LLVMModuleRef) PyCapsule_GetPointer(src_obj, NULL); + const LLVMModuleRef dest = pycap_get(dest_obj ) ; + const LLVMModuleRef src = pycap_get(src_obj) ; + PyObject *ret; + char *errmsg; if (!LLVMLinkModules(dest, src, (LLVMLinkerMode)mode, &errmsg)) { if (errmsg) { ret = PyUnicode_FromString(errmsg); @@ -291,29 +282,27 @@ typedef unsigned (*arrcnt_fn_t)(LLVMTypeRef ty); static PyObject * obj2arr(PyObject *self, PyObject *args, arrcnt_fn_t cntfunc, obj2arr_fn_t arrfunc) { - LLVMTypeRef type, *param_types; - unsigned param_count; - PyObject *list; + size_t param_count; /* get the function object ptr */ - if (!(type = (LLVMTypeRef)get_object_arg(args))) - return NULL; + const LLVMTypeRef type = get_object_arg(args) ; + if (!type) return NULL; /* get param count */ param_count = cntfunc(type); /* alloc enough space for all of them */ - if (!(param_types = (LLVMTypeRef *)malloc(sizeof(LLVMTypeRef) * param_count))) - return PyErr_NoMemory(); + LLVMTypeRef* param_types = new LLVMTypeRef[param_count] ; /* call LLVM func */ arrfunc(type, param_types); /* create a list from the array */ - list = make_list_from_LLVMTypeRef_array(param_types, param_count); + PyObject *list + = make_list_from_LLVMTypeRef_array(param_types, param_count); /* free temp storage */ - free(param_types); + delete [] param_types ; return list; } @@ -337,7 +326,8 @@ _wrap_objstr2none(LLVMSetStructName, LLVMTypeRef) static PyObject * _wLLVMGetStructElementTypes(PyObject *self, PyObject *args) { - return obj2arr(self, args, LLVMCountStructElementTypes, LLVMGetStructElementTypes); + return obj2arr(self, args, LLVMCountStructElementTypes, + LLVMGetStructElementTypes); } @@ -392,13 +382,11 @@ _wrap_obj2obj(LLVMValueGetNumUses, LLVMValueRef, int) static PyObject * _wLLVMValueGetUses(PyObject *self, PyObject *args) { - LLVMValueRef value; - - if (!(value = (LLVMValueRef)get_object_arg(args))) - return NULL; + const LLVMValueRef value = get_object_arg(args) ; + if (!value) return NULL; LLVMValueRef *uses = 0; - unsigned n = LLVMValueGetUses(value, &uses); + size_t n = LLVMValueGetUses(value, &uses); PyObject *list = make_list_from_LLVMValueRef_array(uses, n); if (n > 0) @@ -431,15 +419,14 @@ _wLLVMConstInt(PyObject *self, PyObject *args) PyObject *obj; unsigned long long n; int sign_extend; - LLVMTypeRef ty; - LLVMValueRef val; if (!PyArg_ParseTuple(args, "OKi", &obj, &n, &sign_extend)) return NULL; - ty = (LLVMTypeRef) PyCapsule_GetPointer(obj, NULL); + const LLVMTypeRef ty = pycap_get( obj ) ; + + const LLVMValueRef val = LLVMConstInt(ty, n, sign_extend); - val = LLVMConstInt(ty, n, sign_extend); return ctor_LLVMValueRef(val); } @@ -448,15 +435,13 @@ _wLLVMConstReal(PyObject *self, PyObject *args) { PyObject *obj; double d; - LLVMTypeRef ty; - LLVMValueRef val; if (!PyArg_ParseTuple(args, "Od", &obj, &d)) return NULL; - ty = (LLVMTypeRef) PyCapsule_GetPointer(obj, NULL); + const LLVMTypeRef ty = pycap_get( obj ) ; - val = LLVMConstReal(ty, d); + const LLVMValueRef val = LLVMConstReal(ty, d); return ctor_LLVMValueRef(val); } @@ -471,13 +456,12 @@ _wLLVMConstString(PyObject *self, PyObject *args) { const char *s; int dont_null_terminate; - LLVMValueRef val; if (!PyArg_ParseTuple(args, "si:LLVMConstString", &s, &dont_null_terminate)) { return NULL; } - val = LLVMConstString(s, strlen(s), dont_null_terminate); + LLVMValueRef val = LLVMConstString(s, strlen(s), dont_null_terminate); return ctor_LLVMValueRef(val); } @@ -590,10 +574,8 @@ _wrap_objenum2none(LLVMRemoveFunctionAttr, LLVMValueRef, LLVMAttribute) static PyObject * _wLLVMVerifyFunction(PyObject *self, PyObject *args) { - LLVMValueRef fn; - - if (!(fn = (LLVMValueRef)get_object_arg(args))) - return NULL; + const LLVMValueRef fn = get_object_arg(args); + if (!fn) return NULL; return ctor_int(LLVMVerifyFunction(fn, LLVMReturnStatusAction)); } @@ -695,33 +677,28 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args) { PyObject *obj1, *obj2, *obj3, *obj4, *obj5; const char *name; - LLVMBuilderRef builder; - LLVMValueRef func; - LLVMValueRef *fnargs; - unsigned fnarg_count; - LLVMBasicBlockRef then_blk, catch_blk; - LLVMValueRef inst; if (!PyArg_ParseTuple(args, "OOOOOs:LLVMBuildInvoke", &obj1, &obj2, &obj3, &obj4, &obj5, &name)) { return NULL; } - builder = (LLVMBuilderRef) PyCapsule_GetPointer(obj1, NULL); - func = (LLVMValueRef) PyCapsule_GetPointer(obj2, NULL); + const LLVMBuilderRef builder = pycap_get( obj1); + const LLVMValueRef func = pycap_get( obj2 ) ; - - fnarg_count = (unsigned) PyList_Size(obj3); - fnargs = (LLVMValueRef *)make_array_from_list(obj3, fnarg_count); + size_t fnarg_count = PyList_Size(obj3); + LLVMValueRef *fnargs + = make_array_from_list(obj3, fnarg_count); if (!fnargs) return PyErr_NoMemory(); - then_blk = (LLVMBasicBlockRef) PyCapsule_GetPointer(obj4, NULL); - catch_blk = (LLVMBasicBlockRef) PyCapsule_GetPointer(obj5, NULL); + const LLVMBasicBlockRef then_blk = pycap_get ( obj4 ) ; + const LLVMBasicBlockRef catch_blk = pycap_get ( obj5 ) ; + const LLVMValueRef inst + = LLVMBuildInvoke(builder, func, fnargs, fnarg_count, then_blk, + catch_blk, name); - inst = LLVMBuildInvoke(builder, func, fnargs, fnarg_count, then_blk, catch_blk, name); - - free(fnargs); + delete [] fnargs; return ctor_LLVMValueRef(inst); } @@ -819,13 +796,13 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args) { const char *path; LLVMMemoryBufferRef ref; - char *outmsg; PyObject *ret; if (!PyArg_ParseTuple(args, "s:LLVMCreateMemoryBufferWithContentsOfFile", &path)) { return NULL; } + char *outmsg; if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) { ret = ctor_LLVMMemoryBufferRef(ref); } else { @@ -839,10 +816,9 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args) static PyObject * _wLLVMCreateMemoryBufferWithSTDIN(PyObject *self, PyObject *args) { + PyObject *ret; LLVMMemoryBufferRef ref; char *outmsg; - PyObject *ret; - if (!LLVMCreateMemoryBufferWithSTDIN(&ref, &outmsg)) { ret = ctor_LLVMMemoryBufferRef(ref); } else { @@ -1062,11 +1038,6 @@ _wLLVMTargetMachineLookup(PyObject * self, PyObject * args) static PyObject * _wLLVMTargetMachineEmitFile(PyObject * self, PyObject * args) { - PyObject * ret; - unsigned len; - unsigned char * bytes; - LLVMTargetMachineRef tm; - LLVMModuleRef m; PyObject *arg_tm, *arg_m; int arg_use_asm; @@ -1074,18 +1045,22 @@ _wLLVMTargetMachineEmitFile(PyObject * self, PyObject * args) if (!PyArg_ParseTuple(args, "OOi", &arg_tm, &arg_m, &arg_use_asm)) return NULL; - tm = (LLVMTargetMachineRef) PyCapsule_GetPointer(arg_tm, NULL); - m = (LLVMModuleRef) PyCapsule_GetPointer(arg_m, NULL); + const LLVMTargetMachineRef tm + = pycap_get( arg_tm ) ; + const LLVMModuleRef m = pycap_get( arg_m ) ; std::string error; - bytes = LLVMTargetMachineEmitFile(tm, m, arg_use_asm, &len, error); + size_t len; + unsigned const char * ubytes + = LLVMTargetMachineEmitFile(tm, m, arg_use_asm, &len, error); if ( !error.empty() ){ PyErr_SetString(PyExc_RuntimeError, error.c_str()); return NULL; } - ret = PyBytes_FromStringAndSize((char *)bytes, (Py_ssize_t)len); - delete [] bytes; + const char *chars = reinterpret_cast(ubytes) ; + PyObject * ret = PyBytes_FromStringAndSize(chars, len); + delete [] ubytes; return ret; } @@ -1109,15 +1084,11 @@ _wrap_obj2none(LLVMDisposeTargetData, LLVMTargetDataRef) static PyObject * _wLLVMTargetDataAsString(PyObject *self, PyObject *args) { - LLVMTargetDataRef td; - char *tdrep = 0; - PyObject *ret; + const LLVMTargetDataRef td = get_object_arg(args); + if (!td) return NULL; - if (!(td = (LLVMTargetDataRef)get_object_arg(args))) - return NULL; - - tdrep = LLVMCopyStringRepOfTargetData(td); - ret = PyUnicode_FromString(tdrep); + char *tdrep = LLVMCopyStringRepOfTargetData(td); + PyObject *ret = PyUnicode_FromString(tdrep); LLVMDisposeMessage(tdrep); return ret; } @@ -1160,13 +1131,13 @@ _wrap_objstr2none(LLVMEngineBuilderSetMAttrs, LLVMEngineBuilderRef) static PyObject * _wLLVMEngineBuilderCreate(PyObject *self, PyObject *args) { - LLVMEngineBuilderRef obj; - if (!(obj = (LLVMEngineBuilderRef)get_object_arg(args))) + const LLVMEngineBuilderRef obj + = get_object_arg(args) ; + if (!obj) return NULL; std::string outmsg; - - LLVMExecutionEngineRef ee = LLVMEngineBuilderCreate(obj, outmsg); + const LLVMExecutionEngineRef ee = LLVMEngineBuilderCreate(obj, outmsg); PyObject * ret; if( !ee ){ // check if error message is set. @@ -1185,24 +1156,23 @@ _wLLVMEngineBuilderCreate(PyObject *self, PyObject *args) static PyObject * _wLLVMCreateExecutionEngine(PyObject *self, PyObject *args) { - LLVMModuleRef mod; PyObject *obj; int force_interpreter; - LLVMExecutionEngineRef ee; char *outmsg = 0; - PyObject *ret; int error; if (!PyArg_ParseTuple(args, "Oi", &obj, &force_interpreter)) return NULL; - mod = (LLVMModuleRef) PyCapsule_GetPointer(obj, NULL); + const LLVMModuleRef mod = pycap_get( obj ) ; + LLVMExecutionEngineRef ee; if (force_interpreter) error = LLVMCreateInterpreterForModule(&ee, mod, &outmsg); else error = LLVMCreateJITCompilerForModule(&ee, mod, 1 /*fast*/, &outmsg); + PyObject *ret; if (error) { ret = PyUnicode_FromString(outmsg); LLVMDisposeMessage(outmsg); @@ -1218,14 +1188,12 @@ _wLLVMGetPointerToFunction(PyObject *self, PyObject *args) { PyObject *obj_ee; PyObject *obj_fn; - LLVMExecutionEngineRef ee; - LLVMValueRef fn; if (!PyArg_ParseTuple(args, "OO", &obj_ee, &obj_fn)) return NULL; - ee = (LLVMExecutionEngineRef) PyCapsule_GetPointer(obj_ee, NULL); - fn = (LLVMValueRef) PyCapsule_GetPointer(obj_fn, NULL); + const LLVMExecutionEngineRef ee = pycap_get(obj_ee ) ; + const LLVMValueRef fn = pycap_get( obj_fn ) ; return PyLong_FromVoidPtr(LLVMGetPointerToFunction(ee,fn)); } @@ -1241,19 +1209,18 @@ static PyObject * _wLLVMRemoveModule2(PyObject *self, PyObject *args) { PyObject *obj_ee; - PyObject *obj_mod; - LLVMExecutionEngineRef ee; - LLVMModuleRef mod, mod_new = 0; - char *outmsg = 0; - PyObject *ret; + PyObject *obj_mod; if (!PyArg_ParseTuple(args, "OO", &obj_ee, &obj_mod)) return NULL; - ee = (LLVMExecutionEngineRef) PyCapsule_GetPointer(obj_ee, NULL); - mod = (LLVMModuleRef) PyCapsule_GetPointer(obj_mod, NULL); + const LLVMExecutionEngineRef ee = pycap_get( obj_ee ) ; + const LLVMModuleRef mod = pycap_get(obj_mod) ; + char *outmsg = 0; + LLVMModuleRef mod_new = 0; LLVMRemoveModule(ee, mod, &mod_new, &outmsg); + PyObject *ret; if (mod_new) { ret = ctor_LLVMModuleRef(mod_new); } else { @@ -1289,7 +1256,6 @@ static PyObject * _wLLVMCreateGenericValueOfInt(PyObject *self, PyObject *args) { PyObject *obj1; - LLVMTypeRef ty; unsigned long long n; int is_signed; LLVMGenericValueRef gv; @@ -1297,7 +1263,7 @@ _wLLVMCreateGenericValueOfInt(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "OLi", &obj1, &n, &is_signed)) return NULL; - ty = (LLVMTypeRef) PyCapsule_GetPointer(obj1, NULL); + const LLVMTypeRef ty = pycap_get( obj1 ) ; gv = LLVMCreateGenericValueOfInt(ty, n, is_signed); return ctor_LLVMGenericValueRef(gv); @@ -1307,14 +1273,13 @@ static PyObject * _wLLVMCreateGenericValueOfFloat(PyObject *self, PyObject *args) { PyObject *obj1; - LLVMTypeRef ty; double d; LLVMGenericValueRef gv; if (!PyArg_ParseTuple(args, "Od", &obj1, &d)) return NULL; - ty = (LLVMTypeRef) PyCapsule_GetPointer(obj1, NULL); + const LLVMTypeRef ty = pycap_get( obj1 ) ; gv = LLVMCreateGenericValueOfFloat(ty, d); return ctor_LLVMGenericValueRef(gv); @@ -1327,16 +1292,13 @@ _wLLVMCreateGenericValueOfPointer(PyObject *self, PyObject *args) // LLVMTypeRef ty; //unused? unsigned long long n_; size_t n; - LLVMGenericValueRef gv; if (!PyArg_ParseTuple(args, "L", &n_)) return NULL; n=n_; -// ty = (LLVMTypeRef) PyCapsule_GetPointer(obj1, NULL); - - gv = LLVMCreateGenericValueOfPointer((void*)n); + const LLVMGenericValueRef gv = LLVMCreateGenericValueOfPointer((void*)n); return ctor_LLVMGenericValueRef(gv); } @@ -1345,13 +1307,12 @@ _wLLVMGenericValueToInt(PyObject *self, PyObject *args) { PyObject *obj1; int is_signed; - LLVMGenericValueRef gv; unsigned long long val; if (!PyArg_ParseTuple(args, "Oi", &obj1, &is_signed)) return NULL; - gv = (LLVMGenericValueRef) PyCapsule_GetPointer(obj1, NULL); + LLVMGenericValueRef gv = pycap_get(obj1); val = LLVMGenericValueToInt(gv, is_signed); return is_signed ? @@ -1363,17 +1324,14 @@ static PyObject * _wLLVMGenericValueToFloat(PyObject *self, PyObject *args) { PyObject *obj1, *obj2; - LLVMTypeRef ty; - LLVMGenericValueRef gv; - double val; if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) return NULL; - ty = (LLVMTypeRef) PyCapsule_GetPointer(obj1, NULL); - gv = (LLVMGenericValueRef) PyCapsule_GetPointer(obj2, NULL); + const LLVMTypeRef ty = pycap_get( obj1 ) ; + const LLVMGenericValueRef gv = pycap_get( obj2 ) ; - val = LLVMGenericValueToFloat(ty, gv); + double val = LLVMGenericValueToFloat(ty, gv); return PyFloat_FromDouble(val); } @@ -1381,15 +1339,13 @@ static PyObject * _wLLVMGenericValueToPointer(PyObject *self, PyObject *args) { PyObject *obj1; - LLVMGenericValueRef gv; - void * val; if (!PyArg_ParseTuple(args, "O", &obj1)) return NULL; - gv = (LLVMGenericValueRef) PyCapsule_GetPointer(obj1, NULL); + const LLVMGenericValueRef gv = pycap_get( obj1 ) ; - val = LLVMGenericValueToPointer(gv); + void * val = LLVMGenericValueToPointer(gv); return PyLong_FromVoidPtr(val); } @@ -1407,14 +1363,13 @@ static PyObject * _wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args) { const char *filename; - char *outmsg; PyObject *ret; if (!PyArg_ParseTuple(args, "s:LLVMLoadLibraryPermanently", &filename)) { return NULL; } - outmsg = 0; + char *outmsg = 0; if (!LLVMLoadLibraryPermanently(filename, &outmsg)) { if (outmsg) { ret = PyUnicode_FromString(outmsg); diff --git a/llvm/wrap.cpp b/llvm/wrap.cpp index 97b4f5e..6e2024e 100644 --- a/llvm/wrap.cpp +++ b/llvm/wrap.cpp @@ -91,15 +91,14 @@ void *get_object_arg(PyObject *args) return PyCapsule_GetPointer(o, NULL); } +// must delete [] returned array void **make_array_from_list(PyObject *list, int n) { - int i; - void **arr; - - arr = (void **)malloc(sizeof(void *) * n); + void **arr = new void*[n] ; if (!arr) return NULL; + int i; for (i=0; i +LLTYPE pycap_get( PyObject* obj ) +{ + return static_cast ( PyCapsule_GetPointer(obj, NULL) ); +} + +template +LLTYPE get_object_arg( PyObject* obj ) +{ + return static_cast ( get_object_arg(obj) ); +} + +template +LLTYPE make_array_from_list(PyObject *list, int n) +{ + return reinterpret_cast(make_array_from_list(list, n)) ; +} /*===----------------------------------------------------------------------===*/ /* Wrapper macros */ @@ -169,7 +190,7 @@ _w ## func (PyObject *self, PyObject *args) \ { \ intype1 arg1; \ \ - if (!(arg1 = ( intype1 )get_object_arg(args))) \ + if (!(arg1 = get_object_arg(args))) \ return NULL; \ \ return ctor_ ## outtype ( func (arg1)); \ @@ -200,14 +221,12 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ return ctor_ ## outtype ( func (arg1, arg2)); \ } @@ -221,14 +240,12 @@ 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 ) PyCapsule_GetPointer(obj1, NULL);\ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL);\ + intype1 arg1 = pycap_get< intype1 > (obj1); \ + intype2 arg2 = pycap_get< intype2 > (obj2); \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -243,13 +260,12 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1; \ - intype1 arg1; \ - unsigned int arg2; \ + size_t arg2; \ \ if (!PyArg_ParseTuple(args, "OI", &obj1, &arg2)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL);\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ return ctor_ ## outtype ( func (arg1, arg2)); \ } @@ -263,16 +279,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -286,16 +299,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ func (arg1, arg2, arg3); \ Py_RETURN_NONE; \ @@ -309,16 +319,14 @@ _w ## func (PyObject *self, PyObject *args) \ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ - unsigned int arg1; \ + size_t arg1; \ PyObject *obj2, *obj3; \ - intype2 arg2; \ - intype3 arg3; \ \ if (!PyArg_ParseTuple(args, "IOO", &arg1, &obj2, &obj3)) \ return NULL; \ \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -333,14 +341,12 @@ _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 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -400,7 +406,7 @@ _w ## func (PyObject *self, PyObject *args) \ { \ intype1 arg1; \ \ - if (!(arg1 = ( intype1 )get_object_arg(args))) \ + if (!(arg1 = get_object_arg(args))) \ return NULL; \ \ return PyUnicode_FromString( func (arg1)); \ @@ -416,7 +422,7 @@ _w ## func (PyObject *self, PyObject *args) \ { \ intype1 arg1; \ \ - if (!(arg1 = ( intype1 )get_object_arg(args))) \ + if (!(arg1 = get_object_arg(args))) \ return NULL; \ \ func (arg1); \ @@ -433,12 +439,11 @@ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1; \ const char *arg2; \ - intype1 arg1; \ \ if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL);\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -454,12 +459,11 @@ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1; \ const char *arg2; \ - intype1 arg1; \ \ if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL);\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ return ctor_ ## outtype ( func (arg1, arg2)); \ } @@ -474,12 +478,11 @@ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1; \ int arg2; \ - intype1 arg1; \ \ if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL);\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -493,14 +496,13 @@ _w ## func (PyObject *self, PyObject *args) \ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ - PyObject *obj1; \ - intype1 arg1; \ intype2 arg2; \ + PyObject *obj1; \ \ if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL);\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -515,15 +517,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -537,15 +537,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)) ; \ } @@ -559,15 +557,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)) ; \ } @@ -581,13 +577,12 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ func (arg1, arg2, arg3); \ Py_RETURN_NONE; \ @@ -602,14 +597,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ func (arg1, arg2, arg3); \ Py_RETURN_NONE; \ @@ -624,15 +618,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -646,15 +638,13 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ func(arg1, arg2, arg3); \ \ @@ -671,16 +661,14 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)) ; \ } @@ -694,9 +682,6 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2, *obj3; \ - intype1 arg1; \ - intype2 arg2; \ - intype3 arg3; \ int arg4; \ const char *arg5; \ \ @@ -704,9 +689,9 @@ _w ## func (PyObject *self, PyObject *args) \ &arg5)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)) ; \ } @@ -720,17 +705,14 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ } @@ -744,16 +726,14 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2; \ - intype1 arg1; \ - intype2 arg2; \ const char *arg3; \ int arg4; \ \ if (!PyArg_ParseTuple(args, "OOsi", &obj1, &obj2, &arg3, &arg4)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ } @@ -769,8 +749,6 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2; \ - intype1 arg1; \ - intype2 arg2; \ int arg3; \ const char *arg4; \ int arg5; \ @@ -778,10 +756,10 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOisi", &obj1, &obj2, &arg3, &arg4, &arg5)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ } /** @@ -793,14 +771,13 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1; \ - intype1 arg1; \ const char *arg2; \ int arg3; \ \ - if (!PyArg_ParseTuple(args, "Osi", &obj1, &arg2, &arg3)) \ + if (!PyArg_ParseTuple(args, "Osi", &obj1, &arg2, &arg3)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ } @@ -815,18 +792,15 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2, *obj3; \ - intype1 arg1; \ - intype2 arg2; \ - intype3 arg3; \ const char *arg4; \ int arg5; \ \ if (!PyArg_ParseTuple(args, "OOOsi", &obj1, &obj2, &obj3, &arg4, &arg5)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ } @@ -843,9 +817,6 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2, *obj3; \ - intype1 arg1; \ - intype2 arg2; \ - intype3 arg3; \ int arg4; \ const char *arg5; \ int arg6; \ @@ -853,9 +824,9 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOOisi", &obj1, &obj2, &obj3, &arg4, &arg5, &arg6)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5, arg6)); \ } @@ -869,20 +840,16 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2, *obj3, *obj4; \ - intype1 arg1; \ - intype2 arg2; \ - intype3 arg3; \ - intype4 arg4; \ const char *arg5; \ int arg6; \ \ if (!PyArg_ParseTuple(args, "OOOOsi", &obj1, &obj2, &obj3, &obj4, &arg5, &arg6)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ - arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ + const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5, arg6)); \ } @@ -897,19 +864,16 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj3, *obj4; \ - intype1 arg1; \ const char *arg2; \ - intype3 arg3; \ - intype4 arg4; \ const char *arg5; \ int arg6; \ \ if (!PyArg_ParseTuple(args, "OsOOsi", &obj1, &arg2, &obj3, &obj4, &arg5, &arg6)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ - arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ + const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5, arg6)); \ } @@ -923,17 +887,14 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ } @@ -947,19 +908,14 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ - arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ - \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ + const intype4 arg4 = pycap_get< intype4 > (obj4); \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ } @@ -972,19 +928,15 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ - arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ + const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ } @@ -998,18 +950,15 @@ static PyObject * _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj3, *obj4; \ - intype1 arg1; \ - intype2 arg2; \ - intype3 arg3; \ - intype4 arg4; \ + intype2 arg2 ; \ const char *arg5; \ \ if (!PyArg_ParseTuple(args, "OiOOs", &obj1, &arg2, &obj3, &obj4, &arg5)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ - arg4 = ( intype4 ) PyCapsule_GetPointer(obj4, NULL); \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype3 arg3 = pycap_get< intype3 > (obj3); \ + const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ } @@ -1024,21 +973,18 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2n = (unsigned) PyList_Size(obj2); \ - if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n)))\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const size_t arg2n = PyList_Size(obj2); \ + intype2 *arg2v; \ + if (!(arg2v = make_array_from_list< intype2 *>(obj2, arg2n))) \ return PyErr_NoMemory(); \ \ - ret = func (arg1, arg2v, arg2n); \ - free(arg2v); \ + outtype ret = func (arg1, arg2v, arg2n); \ + delete [] arg2v ; \ return ctor_ ## outtype (ret); \ } @@ -1053,19 +999,17 @@ _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)))\ + const size_t arg1n = PyList_Size(obj1); \ + intype1 *arg1v; \ + if (!(arg1v = make_array_from_list< intype1 *>(obj1, arg1n)))\ return PyErr_NoMemory(); \ \ - ret = func (arg1v, arg1n, arg2); \ - free(arg1v); \ + outtype ret = func (arg1v, arg1n, arg2); \ + delete [] arg1v; \ return ctor_ ## outtype (ret); \ } @@ -1079,19 +1023,17 @@ 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)))\ + const size_t arg1n = PyList_Size(obj1); \ + intype1 *arg1v; \ + if (!(arg1v = make_array_from_list< intype1 *>(obj1, arg1n)))\ return PyErr_NoMemory(); \ \ - ret = func (arg1v, arg1n); \ - free(arg1v); \ + outtype ret = func (arg1v, arg1n); \ + delete [] arg1v; \ return ctor_ ## outtype (ret); \ } @@ -1105,22 +1047,19 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2; \ - intype1 arg1; \ - intype2 *arg2v = NULL; \ - unsigned arg2n; \ int arg3; \ - outtype ret; \ \ if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2n = (unsigned) PyList_Size(obj2); \ - if (arg2n && !(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n)))\ + intype1 arg1 = pycap_get< intype1 > (obj1); \ + const size_t arg2n = PyList_Size(obj2); \ + intype2 *arg2v = NULL; \ + if (arg2n && !(arg2v = make_array_from_list< intype2 *>(obj2, arg2n)))\ return PyErr_NoMemory(); \ \ - ret = func (arg1, arg2v, arg2n, arg3); \ - free(arg2v); \ + outtype ret = func (arg1, arg2v, arg2n, arg3); \ + delete [] arg2v ; \ return ctor_ ## outtype (ret); \ } @@ -1135,21 +1074,19 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ PyObject *obj1, *obj2; \ - intype1 arg1; \ - intype2 *arg2v; \ - unsigned arg2n; \ int arg3; \ \ if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ return NULL; \ \ - arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2n = (unsigned) PyList_Size(obj2); \ - if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n)))\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const size_t arg2n = PyList_Size(obj2); \ + intype2 *arg2v; \ + if (!(arg2v = make_array_from_list< intype2 *>(obj2, arg2n)))\ return PyErr_NoMemory(); \ \ func (arg1, arg2v, arg2n, arg3); \ - free(arg2v); \ + delete [] arg2v ; \ Py_RETURN_NONE; \ } @@ -1163,22 +1100,19 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg3n = (unsigned) PyList_Size(obj3); \ - if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n)))\ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const size_t arg3n = PyList_Size(obj3); \ + intype3 *arg3v; \ + if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \ return PyErr_NoMemory(); \ \ - ret = func (arg1, arg2, arg3v, arg3n); \ - free(arg3v); \ + outtype ret = func (arg1, arg2, arg3v, arg3n); \ + delete [] arg3v ; \ return ctor_ ## outtype (ret); \ } @@ -1192,23 +1126,19 @@ 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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3n = (unsigned) PyList_Size(obj3); \ - if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const size_t arg3n = PyList_Size(obj3); \ + intype3 *arg3v; \ + if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \ return PyErr_NoMemory(); \ \ - ret = func (arg1, arg2, arg3v, arg3n); \ - free(arg3v); \ + outtype ret = func (arg1, arg2, arg3v, arg3n); \ + delete [] arg3v ; \ return ctor_ ## outtype (ret); \ } @@ -1223,23 +1153,19 @@ _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 ) PyCapsule_GetPointer(obj1, NULL); \ - arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ - arg3n = ( unsigned ) PyList_Size(obj3); \ - if (!(arg3v = ( intype3 *)make_array_from_list(obj3, arg3n))) \ + const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype2 arg2 = pycap_get< intype2 > (obj2); \ + const size_t arg3n = PyList_Size(obj3); \ + intype3 *arg3v; \ + if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \ return PyErr_NoMemory(); \ \ - ret = func (arg1, arg2, arg3v, arg3n, arg4); \ - free(arg3v); \ + outtype ret = func (arg1, arg2, arg3v, arg3n, arg4); \ + delete [] arg3v ; \ return ctor_ ## outtype (ret); \ } @@ -1254,18 +1180,15 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ intype1 arg1; \ - char *val; \ - PyObject *ret; \ \ - if (!(arg1= ( intype1 ) get_object_arg(args))) \ + if (!(arg1 = get_object_arg(args))) \ return NULL; \ \ - val = func (arg1); \ - ret = PyUnicode_FromString(val); \ - LLVMDisposeMessage(val); \ + const char *val = func (arg1); \ + PyObject *ret = PyUnicode_FromString(val); \ + LLVMDisposeMessage(const_cast(val)); \ return ret; \ } #endif /* LLVM_PY_WRAP_H */ -