diff --git a/llvm/_core.cpp b/llvm/_core.cpp index e5502ed..77a1d4c 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -56,6 +56,48 @@ typedef int Py_ssize_t; #endif + +// explicit specializations +template <> PyObject* pycap_new(int i) +{ + return PyLong_FromLong(static_cast(i)); +} + +template <> PyObject* pycap_new(size_t i) +{ + return PyLong_FromLong(static_cast(i)); +} + +template <> PyObject* pycap_new(LLVMTypeKind i) +{ + return PyLong_FromLong(static_cast(i)); +} + +template <> PyObject* pycap_new(LLVMLinkage i) +{ + return PyLong_FromLong(static_cast(i)); +} + +template <> PyObject* pycap_new(LLVMVisibility i) +{ + return PyLong_FromLong(static_cast(i)); +} + +template <> PyObject* pycap_new(LLVMByteOrdering i) +{ + return PyLong_FromLong(static_cast(i)); +} + +template <> PyObject* pycap_new(unsigned long long ull) +{ + return PyLong_FromUnsignedLongLong(ull); +} + +template <> PyObject* pycap_new(long long ll) +{ + return PyLong_FromLongLong(ll); +} + /*===----------------------------------------------------------------------===*/ /* Modules */ /*===----------------------------------------------------------------------===*/ @@ -71,7 +113,7 @@ _wLLVMModuleCreateWithName(PyObject *self, PyObject *args) } const LLVMModuleRef module = LLVMModuleCreateWithName(s); - return ctor_LLVMModuleRef(module); + return pycap_new(module); _CATCH_ALL } @@ -86,7 +128,7 @@ _wrap_objstr2obj(LLVMGetTypeByName, LLVMModuleRef, LLVMTypeRef) _wrap_obj2none(LLVMDumpModule, LLVMModuleRef) _wrap_obj2none(LLVMDisposeModule, LLVMModuleRef) _wrap_dumper(LLVMDumpModuleToString, LLVMModuleRef) -_wrap_obj2obj(LLVMModuleGetPointerSize, LLVMModuleRef, int) + _wrap_obj2obj( LLVMModuleGetPointerSize, LLVMModuleRef, int) _wrap_objstrobj2obj(LLVMModuleGetOrInsertFunction, LLVMModuleRef, LLVMTypeRef, LLVMValueRef) @@ -138,7 +180,7 @@ _wLLVMGetModuleFromAssembly(PyObject *self, PyObject *args) } } - return ctor_LLVMModuleRef(mod); + return pycap_new(mod); _CATCH_ALL } @@ -168,7 +210,7 @@ _wLLVMGetModuleFromBitcode(PyObject *self, PyObject *args) } } - return ctor_LLVMModuleRef(m); + return pycap_new(m); _CATCH_ALL } @@ -309,8 +351,7 @@ obj2arr(PyObject *self, PyObject *args, arrcnt_fn_t cntfunc, obj2arr_fn_t arrfun arrfunc(type, param_types); /* create a list from the array */ - PyObject *list - = make_list_from_LLVMTypeRef_array(param_types, param_count); + PyObject *list = make_list(param_types, param_count); /* free temp storage */ delete [] param_types ; @@ -403,7 +444,7 @@ _wLLVMValueGetUses(PyObject *self, PyObject *args) LLVMValueRef *uses = 0; size_t n = LLVMValueGetUses(value, &uses); - PyObject *list = make_list_from_LLVMValueRef_array(uses, n); + PyObject *list = make_list(uses, n); if (n > 0) LLVMDisposeValueRefArray(uses); @@ -444,7 +485,7 @@ _wLLVMConstInt(PyObject *self, PyObject *args) const LLVMValueRef val = LLVMConstInt(ty, n, sign_extend); - return ctor_LLVMValueRef(val); + return pycap_new(val); _CATCH_ALL } @@ -461,7 +502,7 @@ _wLLVMConstReal(PyObject *self, PyObject *args) const LLVMTypeRef ty = pycap_get( obj ) ; const LLVMValueRef val = LLVMConstReal(ty, d); - return ctor_LLVMValueRef(val); + return pycap_new(val); _CATCH_ALL } @@ -483,7 +524,7 @@ _wLLVMConstString(PyObject *self, PyObject *args) } LLVMValueRef val = LLVMConstString(s, strlen(s), dont_null_terminate); - return ctor_LLVMValueRef(val); + return pycap_new(val); _CATCH_ALL } @@ -600,7 +641,7 @@ _wLLVMVerifyFunction(PyObject *self, PyObject *args) const LLVMValueRef fn = get_object_arg(args); if (!fn) return NULL; - return ctor_int(LLVMVerifyFunction(fn, LLVMReturnStatusAction)); + return pycap_new(LLVMVerifyFunction(fn, LLVMReturnStatusAction)); _CATCH_ALL } @@ -651,7 +692,7 @@ _wLLVMGetNamedMetadataOperands(PyObject *self, PyObject *args) LLVMValueRef *operands = new LLVMValueRef[num_operands]; LLVMGetNamedMetadataOperands(module, name, operands); - PyObject *list = make_list_from_LLVMValueRef_array(operands, num_operands); + PyObject *list = make_list(operands, num_operands); delete [] operands; return list; @@ -749,7 +790,7 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args) delete [] fnargs; - return ctor_LLVMValueRef(inst); + return pycap_new(inst); _CATCH_ALL } @@ -855,7 +896,7 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args) char *outmsg; if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) { - ret = ctor_LLVMMemoryBufferRef(ref); + ret = pycap_new(ref); } else { ret = PyUnicode_FromString(outmsg); LLVMDisposeMessage(outmsg); @@ -873,7 +914,7 @@ _wLLVMCreateMemoryBufferWithSTDIN(PyObject *self, PyObject *args) LLVMMemoryBufferRef ref; char *outmsg; if (!LLVMCreateMemoryBufferWithSTDIN(&ref, &outmsg)) { - ret = ctor_LLVMMemoryBufferRef(ref); + ret = pycap_new(ref); } else { ret = PyUnicode_FromString(outmsg); LLVMDisposeMessage(outmsg); @@ -1087,7 +1128,7 @@ _wLLVMTargetMachineLookup(PyObject * self, PyObject * args) PyErr_SetString(PyExc_RuntimeError, error.c_str()); return NULL; } - return ctor_LLVMTargetMachineRef(tm); + return pycap_new(tm); _CATCH_ALL } @@ -1200,7 +1241,7 @@ _wLLVMEngineBuilderCreate(PyObject *self, PyObject *args) if( !ee ){ // check if error message is set. ret = PyUnicode_FromString(outmsg.c_str()); }else{ - ret = ctor_LLVMExecutionEngineRef(ee); + ret = pycap_new(ee); } return ret; @@ -1236,7 +1277,7 @@ _wLLVMCreateExecutionEngine(PyObject *self, PyObject *args) ret = PyUnicode_FromString(outmsg); LLVMDisposeMessage(outmsg); } else { - ret = ctor_LLVMExecutionEngineRef(ee); + ret = pycap_new(ee); } return ret; @@ -1284,7 +1325,7 @@ _wLLVMRemoveModule2(PyObject *self, PyObject *args) LLVMRemoveModule(ee, mod, &mod_new, &outmsg); PyObject *ret; if (mod_new) { - ret = ctor_LLVMModuleRef(mod_new); + ret = pycap_new(mod_new); } else { if (outmsg) { ret = PyUnicode_FromString(outmsg); @@ -1330,7 +1371,7 @@ _wLLVMCreateGenericValueOfInt(PyObject *self, PyObject *args) const LLVMTypeRef ty = pycap_get( obj1 ) ; gv = LLVMCreateGenericValueOfInt(ty, n, is_signed); - return ctor_LLVMGenericValueRef(gv); + return pycap_new(gv); _CATCH_ALL } @@ -1348,7 +1389,7 @@ _wLLVMCreateGenericValueOfFloat(PyObject *self, PyObject *args) const LLVMTypeRef ty = pycap_get( obj1 ) ; gv = LLVMCreateGenericValueOfFloat(ty, d); - return ctor_LLVMGenericValueRef(gv); + return pycap_new(gv); _CATCH_ALL } @@ -1367,7 +1408,7 @@ _wLLVMCreateGenericValueOfPointer(PyObject *self, PyObject *args) n=n_; const LLVMGenericValueRef gv = LLVMCreateGenericValueOfPointer((void*)n); - return ctor_LLVMGenericValueRef(gv); + return pycap_new(gv); _CATCH_ALL } diff --git a/llvm/wrap.cpp b/llvm/wrap.cpp index e19b12c..47cbdc9 100644 --- a/llvm/wrap.cpp +++ b/llvm/wrap.cpp @@ -30,52 +30,10 @@ #include "wrap.h" -/*===----------------------------------------------------------------------===*/ -/* Helper functions/macros */ -/*===----------------------------------------------------------------------===*/ - -#define _define_std_ctor(typ) \ -PyObject * ctor_ ## typ ( typ p) \ -{ \ - if (p){ \ - return PyCapsule_New(p, NULL, NULL); \ - } \ - Py_RETURN_NONE; \ -} - /*===----------------------------------------------------------------------===*/ /* Type ctor/dtor */ /*===----------------------------------------------------------------------===*/ -_define_std_ctor(LLVMModuleRef) -_define_std_ctor(LLVMTypeRef) -_define_std_ctor(LLVMValueRef) -_define_std_ctor(LLVMBasicBlockRef) -_define_std_ctor(LLVMBuilderRef) -_define_std_ctor(LLVMMemoryBufferRef) -_define_std_ctor(LLVMPassManagerRef) -_define_std_ctor(LLVMExecutionEngineRef) -_define_std_ctor(LLVMTargetDataRef) -_define_std_ctor(LLVMGenericValueRef) - -_define_std_ctor(LLVMPassManagerBuilderRef) -_define_std_ctor(LLVMEngineBuilderRef) -_define_std_ctor(LLVMTargetMachineRef) - -PyObject *ctor_int(int i) -{ - return PyLong_FromLong((long)i); -} - -PyObject *ctor_llvmwrap_ull(llvmwrap_ull ull) -{ - return PyLong_FromUnsignedLongLong(ull); -} - -PyObject *ctor_llvmwrap_ll(llvmwrap_ll ll) -{ - return PyLong_FromLongLong(ll); -} /*===----------------------------------------------------------------------===*/ /* Helper functions */ @@ -108,24 +66,3 @@ void **make_array_from_list(PyObject *list, int n) return arr; } - -#define LIST_FROM_ARRAY_IMPL(TYPE) \ -PyObject *make_list_from_ ## TYPE ## _array( TYPE *p, size_t n) \ -{ \ - size_t i; \ - PyObject *list = PyList_New(n); \ - \ - if (!list) \ - throw py_exception(); \ - \ - for (i=0; i - * for various types. - */ - -#define _declare_std_ctor(typ) \ -PyObject * ctor_ ## typ ( typ p); - -_declare_std_ctor(LLVMModuleRef) -_declare_std_ctor(LLVMTypeRef) -_declare_std_ctor(LLVMValueRef) -_declare_std_ctor(LLVMBasicBlockRef) -_declare_std_ctor(LLVMBuilderRef) -_declare_std_ctor(LLVMMemoryBufferRef) -_declare_std_ctor(LLVMPassManagerRef) -_declare_std_ctor(LLVMExecutionEngineRef) -_declare_std_ctor(LLVMTargetDataRef) -_declare_std_ctor(LLVMGenericValueRef) - -// extra LLVM classes -_declare_std_ctor(LLVMPassManagerBuilderRef) -_declare_std_ctor(LLVMEngineBuilderRef) -_declare_std_ctor(LLVMTargetMachineRef) - -/* standard types */ -_declare_std_ctor(int) -_declare_std_ctor(llvmwrap_ull) -_declare_std_ctor(llvmwrap_ll) +// Cast python object to aTYPE +template +aTYPE pycap_get( PyObject* obj ) +{ + return static_cast ( PyCapsule_GetPointer(obj, NULL) ); +} +// Contruct python object to hold aTYPE pointer +template +PyObject* pycap_new( aTYPE p ) +{ + if (p){ + return PyCapsule_New(p, NULL, NULL); + } + Py_RETURN_NONE; +} /*===----------------------------------------------------------------------===*/ /* Helper methods */ @@ -133,6 +118,12 @@ _declare_std_ctor(llvmwrap_ll) */ void *get_object_arg(PyObject *args); +template +aTYPE get_object_arg( PyObject* obj ) +{ + return static_cast ( get_object_arg(obj) ); +} + /** * Given a PyList object (list) having n (= PyList_Size(list)) elements, * each list object being a PyCObject, return a new()-ed array of @@ -142,38 +133,29 @@ void *get_object_arg(PyObject *args); */ void **make_array_from_list(PyObject *list, int n); -/** - * Given an array of LLVMTypeRef's, create a PyList object. - */ -PyObject *make_list_from_LLVMTypeRef_array(LLVMTypeRef *p, size_t n); - -/** - * Given an array of LLVMValueRef's, create a PyList object. - */ -PyObject *make_list_from_LLVMValueRef_array(LLVMValueRef *p, size_t n); - -/*===----------------------------------------------------------------------===*/ -/* Template functions */ - -// wrap the cast template -LLTYPE pycap_get( PyObject* obj ) +LLTYPE make_array_from_list(PyObject *list, int n) { - LLTYPE p = static_cast ( PyCapsule_GetPointer(obj, NULL) ); + LLTYPE p = reinterpret_cast(make_array_from_list(list, n)) ; if ( !p ) throw py_exception(); return p; } -template -LLTYPE get_object_arg( PyObject* obj ) +template +PyObject* make_list( aTYPE p[], size_t n ) { - return static_cast ( get_object_arg(obj) ); -} + PyObject *list = PyList_New(n); -template -LLTYPE make_array_from_list(PyObject *list, int n) -{ - return reinterpret_cast(make_array_from_list(list, n)) ; + if (!list) + return NULL; + + size_t i; + for (i=0; i( p[i] ); + PyList_SetItem(list, i, elem); + } + + return list; } /*===----------------------------------------------------------------------===*/ @@ -195,14 +177,14 @@ LLTYPE make_array_from_list(PyObject *list, int n) #define _wrap_none2none(func) \ static PyObject * \ -_w ## func(PyObject * self, PyObject * args) \ +_w ## func(PyObject * self, PyObject * args) \ { \ _TRY \ if (!PyArg_ParseTuple(args, "")) \ return NULL; \ func(); \ Py_RETURN_NONE; \ - _CATCH_ALL \ + _CATCH_ALL \ } /** @@ -216,8 +198,8 @@ _w ## func (PyObject *self, PyObject *args) \ _TRY \ intype1 arg1 = get_object_arg(args); \ \ - return ctor_ ## outtype ( func (arg1)); \ - _CATCH_ALL \ + return pycap_new( func( arg1 ) ); \ + _CATCH_ALL \ } /** @@ -234,7 +216,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "i", &arg1)) \ return NULL; \ \ - return ctor_ ## outtype ( func (arg1)); \ + return pycap_new( func( arg1 ) ); \ _CATCH_ALL \ } @@ -255,7 +237,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2)); \ + return pycap_new( func( arg1, arg2 ) ); \ _CATCH_ALL \ } @@ -298,7 +280,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ - return ctor_ ## outtype ( func (arg1, arg2)); \ + return pycap_new( func( arg1, arg2 ) ); \ _CATCH_ALL \ } @@ -320,7 +302,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ + return pycap_new( func( arg1, arg2, arg3 ) ); \ _CATCH_ALL \ } @@ -365,7 +347,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ + return pycap_new( func( arg1, arg2, arg3 ) ); \ _CATCH_ALL \ } @@ -387,7 +369,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ + return pycap_new( func( arg1, arg2, arg3 ) ); \ _CATCH_ALL \ } @@ -405,7 +387,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "s", &arg1)) \ return NULL; \ \ - return ctor_ ## outtype ( func (arg1)); \ + return pycap_new( func( arg1 ) ); \ _CATCH_ALL \ } @@ -421,7 +403,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "")) \ return NULL; \ \ - return ctor_ ## outtype ( func ()); \ + return pycap_new( func() ); \ _CATCH_ALL \ } @@ -451,8 +433,7 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ _TRY \ - intype1 arg1 = get_object_arg(args); \ - \ + const intype1 arg1 = get_object_arg(args) ; \ return PyUnicode_FromString( func (arg1)); \ _CATCH_ALL \ } @@ -466,8 +447,7 @@ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ _TRY \ - intype1 arg1 = get_object_arg(args); \ - \ + const intype1 arg1 = get_object_arg(args) ; \ func (arg1); \ Py_RETURN_NONE; \ _CATCH_ALL \ @@ -488,7 +468,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Os", &obj1, &arg2)) \ return NULL; \ \ - const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype1 arg1 = pycap_get< intype1 >( obj1 ); \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -512,7 +492,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ - return ctor_ ## outtype ( func (arg1, arg2)); \ + return pycap_new( func( arg1, arg2 ) ); \ _CATCH_ALL \ } @@ -553,7 +533,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Oi", &obj1, &arg2)) \ return NULL; \ \ - const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype1 arg1 = pycap_get< intype1 >( obj1 ); \ \ func (arg1, arg2); \ Py_RETURN_NONE; \ @@ -578,7 +558,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ + return pycap_new ( func (arg1, arg2, arg3)); \ _CATCH_ALL \ } @@ -600,7 +580,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)) ; \ + return pycap_new( func( arg1, arg2, arg3 ) ) ; \ _CATCH_ALL \ } @@ -622,7 +602,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)) ; \ + return pycap_new( func( arg1, arg2, arg3 ) ) ; \ _CATCH_ALL \ } @@ -664,7 +644,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "Oii", &obj1, &arg2, &arg3)) \ return NULL; \ \ - const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype1 arg1 = pycap_get< intype1 >( obj1 ); \ \ func (arg1, arg2, arg3); \ Py_RETURN_NONE; \ @@ -689,7 +669,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ + return pycap_new( func( arg1, arg2, arg3 ) ); \ _CATCH_ALL \ } @@ -697,7 +677,7 @@ _w ## func (PyObject *self, PyObject *args) \ * Wrap LLVM functions of the type * void func(intype1 arg1, const char *arg2, intype3 arg3) */ -#define _wrap_objstrobj2none(func, intype1, intype3) \ +#define _wrap_objstrobj2none(func, intype1, intype3) \ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ @@ -737,7 +717,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)) ; \ + return pycap_new( func( arg1, arg2, arg3, arg4 ) ) ; \ _CATCH_ALL \ } @@ -762,7 +742,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)) ; \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5 ) ) ; \ _CATCH_ALL \ } @@ -785,7 +765,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ + return pycap_new( func( arg1, arg2, arg3, arg4 ) ); \ _CATCH_ALL \ } @@ -808,7 +788,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ + return pycap_new( func( arg1, arg2, arg3, arg4 ) ); \ _CATCH_ALL \ } @@ -834,7 +814,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5 ) ); \ _CATCH_ALL \ } @@ -856,7 +836,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3)); \ + return pycap_new( func( arg1, arg2, arg3 ) ); \ _CATCH_ALL \ } @@ -881,7 +861,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5 ) ); \ _CATCH_ALL \ } @@ -909,7 +889,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5, arg6)); \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5, arg6 ) );\ _CATCH_ALL \ } @@ -934,7 +914,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5, arg6)); \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5, arg6 ) ); \ _CATCH_ALL \ } @@ -960,7 +940,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5, arg6)); \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5, arg6 ) ); \ _CATCH_ALL \ } @@ -983,7 +963,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ const intype3 arg3 = pycap_get< intype3 > (obj3); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)); \ + return pycap_new( func( arg1, arg2, arg3, arg4 ) ); \ _CATCH_ALL \ } @@ -1005,7 +985,7 @@ _w ## func (PyObject *self, PyObject *args) 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)); \ + return pycap_new( func( arg1, arg2, arg3, arg4 ) ); \ _CATCH_ALL \ } @@ -1029,7 +1009,7 @@ _w ## func (PyObject *self, PyObject *args) const intype3 arg3 = pycap_get< intype3 > (obj3); \ const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5 ) ); \ _CATCH_ALL \ } @@ -1053,7 +1033,7 @@ _w ## func (PyObject *self, PyObject *args) const intype3 arg3 = pycap_get< intype3 > (obj3); \ const intype4 arg4 = pycap_get< intype4 > (obj4); \ \ - return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)); \ + return pycap_new( func( arg1, arg2, arg3, arg4, arg5 ) ); \ _CATCH_ALL \ } @@ -1072,13 +1052,13 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2)) \ return NULL; \ \ - const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype1 arg1 = pycap_get< intype1 >( obj1 ); \ const size_t arg2n = PyList_Size(obj2); \ intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \ \ outtype ret = func (arg1, arg2v, arg2n); \ delete [] arg2v ; \ - return ctor_ ## outtype (ret); \ + return pycap_new( ret ); \ _CATCH_ALL \ } @@ -1103,7 +1083,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ outtype ret = func (arg1v, arg1n, arg2); \ delete [] arg1v; \ - return ctor_ ## outtype (ret); \ + return pycap_new( ret ); \ _CATCH_ALL \ } @@ -1127,7 +1107,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ outtype ret = func (arg1v, arg1n); \ delete [] arg1v; \ - return ctor_ ## outtype (ret); \ + return pycap_new( ret ); \ _CATCH_ALL \ } @@ -1147,13 +1127,13 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ return NULL; \ \ - intype1 arg1 = pycap_get< intype1 > (obj1); \ + intype1 arg1 = pycap_get< intype1 >( obj1 ); \ const size_t arg2n = PyList_Size(obj2); \ intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \ \ outtype ret = func (arg1, arg2v, arg2n, arg3); \ delete [] arg2v ; \ - return ctor_ ## outtype (ret); \ + return pycap_new( ret ); \ _CATCH_ALL \ } @@ -1163,7 +1143,7 @@ _w ## func (PyObject *self, PyObject *args) \ * void func(intype1 arg1, intype2 *arg2v, unsigned arg2n, int arg3) * where arg2v is an array of intype2 elements, arg2n in length. */ -#define _wrap_objlistint2none(func, intype1, intype2) \ +#define _wrap_objlistint2none(func, intype1, intype2) \ static PyObject * \ _w ## func (PyObject *self, PyObject *args) \ { \ @@ -1174,7 +1154,7 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \ return NULL; \ \ - const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype1 arg1 = pycap_get< intype1 >( obj1 ); \ const size_t arg2n = PyList_Size(obj2); \ intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \ \ @@ -1200,13 +1180,13 @@ _w ## func (PyObject *self, PyObject *args) \ if (!PyArg_ParseTuple(args, "OiO", &obj1, &arg2, &obj3)) \ return NULL; \ \ - const intype1 arg1 = pycap_get< intype1 > (obj1); \ + const intype1 arg1 = pycap_get< intype1 >( obj1 ); \ const size_t arg3n = PyList_Size(obj3); \ intype3 *arg3v = make_array_from_list< intype3 *>(obj3, arg3n); \ \ outtype ret = func (arg1, arg2, arg3v, arg3n); \ delete [] arg3v ; \ - return ctor_ ## outtype (ret); \ + return pycap_new( ret ); \ _CATCH_ALL \ } @@ -1232,7 +1212,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ outtype ret = func (arg1, arg2, arg3v, arg3n); \ delete [] arg3v ; \ - return ctor_ ## outtype (ret); \ + return pycap_new( ret ); \ _CATCH_ALL \ } @@ -1259,7 +1239,7 @@ _w ## func (PyObject *self, PyObject *args) \ \ outtype ret = func (arg1, arg2, arg3v, arg3n, arg4); \ delete [] arg3v ; \ - return ctor_ ## outtype (ret); \ + return pycap_new( ret ); \ _CATCH_ALL \ }