diff --git a/llvm/_core.cpp b/llvm/_core.cpp index 9aa779a..7b56369 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -650,11 +650,11 @@ _wLLVMGetNamedMetadataOperands(PyObject *self, PyObject *args) LLVMModuleRef module = (LLVMModuleRef)PyCapsule_GetPointer(obj_module, NULL); unsigned num_operands = LLVMGetNamedMetadataNumOperands(module, name); - LLVMValueRef *operands = (LLVMValueRef*)malloc(sizeof(LLVMValueRef)*num_operands); + LLVMValueRef *operands = new LLVMValueRef[num_operands]; LLVMGetNamedMetadataOperands(module, name, operands); PyObject *list = make_list_from_LLVMValueRef_array(operands, num_operands); - free(operands); + delete [] operands; return list; _CATCH_ALL @@ -741,8 +741,6 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args) size_t fnarg_count = PyList_Size(obj3); LLVMValueRef *fnargs = make_array_from_list(obj3, fnarg_count); - if (!fnargs) - return PyErr_NoMemory(); const LLVMBasicBlockRef then_blk = pycap_get ( obj4 ) ; const LLVMBasicBlockRef catch_blk = pycap_get ( obj5 ) ; diff --git a/llvm/extra.cpp b/llvm/extra.cpp index 3cf0fb4..3ba62f2 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -875,7 +875,7 @@ unsigned LLVMValueGetUses(LLVMValueRef value, LLVMValueRef **refs) return 0; assert(refs); - LLVMValueRef *out = (LLVMValueRef *)malloc(sizeof(LLVMValueRef) * n); + LLVMValueRef *out = new LLVMValueRef[n]; if (!out) return 0; *refs = out; @@ -893,7 +893,7 @@ unsigned LLVMValueGetUses(LLVMValueRef value, LLVMValueRef **refs) void LLVMDisposeValueRefArray(LLVMValueRef *refs) { assert(refs); - free(refs); + delete [] refs; } unsigned LLVMUserGetNumOperands(LLVMValueRef user) @@ -1018,11 +1018,9 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, size_t *lenp) llvm::WriteBitcodeToFile(modulep, buf); const std::string& bc = buf.str(); - /* and then into a malloc()-ed block */ + /* and then into a new()-ed block */ size_t bclen = bc.size(); - unsigned char *bytes = (unsigned char *)malloc(bclen); - if (!bytes) - return NULL; + unsigned char *bytes = new unsigned char[bclen]; memcpy(bytes, bc.data(), bclen); /* return */ diff --git a/llvm/wrap.cpp b/llvm/wrap.cpp index 80ddeef..cf7a8da 100644 --- a/llvm/wrap.cpp +++ b/llvm/wrap.cpp @@ -97,10 +97,6 @@ void *get_object_arg(PyObject *args) void **make_array_from_list(PyObject *list, int n) { void **arr = new void*[n] ; - if (!arr){ - PyErr_NoMemory(); - return NULL; - } int i; for (i=0; i (obj1); \ const size_t arg2n = PyList_Size(obj2); \ - intype2 *arg2v; \ - if (!(arg2v = make_array_from_list< intype2 *>(obj2, arg2n))) \ - return PyErr_NoMemory(); \ + intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \ \ outtype ret = func (arg1, arg2v, arg2n); \ delete [] arg2v ; \ @@ -1176,9 +1174,7 @@ _w ## func (PyObject *self, PyObject *args) \ return NULL; \ \ const size_t arg1n = PyList_Size(obj1); \ - intype1 *arg1v; \ - if (!(arg1v = make_array_from_list< intype1 *>(obj1, arg1n)))\ - return PyErr_NoMemory(); \ + intype1 *arg1v = make_array_from_list< intype1 *>(obj1, arg1n); \ \ outtype ret = func (arg1v, arg1n, arg2); \ delete [] arg1v; \ @@ -1202,9 +1198,7 @@ _w ## func (PyObject *self, PyObject *args) \ return NULL; \ \ const size_t arg1n = PyList_Size(obj1); \ - intype1 *arg1v; \ - if (!(arg1v = make_array_from_list< intype1 *>(obj1, arg1n)))\ - return PyErr_NoMemory(); \ + intype1 *arg1v = make_array_from_list< intype1 *>(obj1, arg1n); \ \ outtype ret = func (arg1v, arg1n); \ delete [] arg1v; \ @@ -1231,9 +1225,7 @@ _w ## func (PyObject *self, PyObject *args) \ intype1 arg1 = pycap_get< intype1 > (obj1); \ _CHECK_PYCAP(arg1); \ const size_t arg2n = PyList_Size(obj2); \ - intype2 *arg2v = NULL; \ - if (arg2n && !(arg2v = make_array_from_list< intype2 *>(obj2, arg2n)))\ - return PyErr_NoMemory(); \ + intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \ \ outtype ret = func (arg1, arg2v, arg2n, arg3); \ delete [] arg2v ; \ @@ -1261,9 +1253,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ _CHECK_PYCAP(arg1); \ const size_t arg2n = PyList_Size(obj2); \ - intype2 *arg2v; \ - if (!(arg2v = make_array_from_list< intype2 *>(obj2, arg2n)))\ - return PyErr_NoMemory(); \ + intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \ \ func (arg1, arg2v, arg2n, arg3); \ delete [] arg2v ; \ @@ -1290,9 +1280,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype1 arg1 = pycap_get< intype1 > (obj1); \ _CHECK_PYCAP(arg1); \ const size_t arg3n = PyList_Size(obj3); \ - intype3 *arg3v; \ - if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \ - return PyErr_NoMemory(); \ + intype3 *arg3v = make_array_from_list< intype3 *>(obj3, arg3n); \ \ outtype ret = func (arg1, arg2, arg3v, arg3n); \ delete [] arg3v ; \ @@ -1320,9 +1308,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ _CHECK_PYCAP(arg2); \ const size_t arg3n = PyList_Size(obj3); \ - intype3 *arg3v; \ - if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \ - return PyErr_NoMemory(); \ + intype3 *arg3v = make_array_from_list< intype3 *>(obj3, arg3n); \ \ outtype ret = func (arg1, arg2, arg3v, arg3n); \ delete [] arg3v ; \ @@ -1351,9 +1337,7 @@ _w ## func (PyObject *self, PyObject *args) \ const intype2 arg2 = pycap_get< intype2 > (obj2); \ _CHECK_PYCAP(arg2); \ const size_t arg3n = PyList_Size(obj3); \ - intype3 *arg3v; \ - if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \ - return PyErr_NoMemory(); \ + intype3 *arg3v = make_array_from_list< intype3 *>(obj3, arg3n); \ \ outtype ret = func (arg1, arg2, arg3v, arg3n, arg4); \ delete [] arg3v ; \