Cleanup all memory allocations and their exception handling
This commit is contained in:
parent
f17d4f7d62
commit
0079b1de07
4 changed files with 15 additions and 39 deletions
|
|
@ -650,11 +650,11 @@ _wLLVMGetNamedMetadataOperands(PyObject *self, PyObject *args)
|
||||||
|
|
||||||
LLVMModuleRef module = (LLVMModuleRef)PyCapsule_GetPointer(obj_module, NULL);
|
LLVMModuleRef module = (LLVMModuleRef)PyCapsule_GetPointer(obj_module, NULL);
|
||||||
unsigned num_operands = LLVMGetNamedMetadataNumOperands(module, name);
|
unsigned num_operands = LLVMGetNamedMetadataNumOperands(module, name);
|
||||||
LLVMValueRef *operands = (LLVMValueRef*)malloc(sizeof(LLVMValueRef)*num_operands);
|
LLVMValueRef *operands = new LLVMValueRef[num_operands];
|
||||||
LLVMGetNamedMetadataOperands(module, name, operands);
|
LLVMGetNamedMetadataOperands(module, name, operands);
|
||||||
|
|
||||||
PyObject *list = make_list_from_LLVMValueRef_array(operands, num_operands);
|
PyObject *list = make_list_from_LLVMValueRef_array(operands, num_operands);
|
||||||
free(operands);
|
delete [] operands;
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
_CATCH_ALL
|
_CATCH_ALL
|
||||||
|
|
@ -741,8 +741,6 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args)
|
||||||
size_t fnarg_count = PyList_Size(obj3);
|
size_t fnarg_count = PyList_Size(obj3);
|
||||||
LLVMValueRef *fnargs
|
LLVMValueRef *fnargs
|
||||||
= make_array_from_list<LLVMValueRef *>(obj3, fnarg_count);
|
= make_array_from_list<LLVMValueRef *>(obj3, fnarg_count);
|
||||||
if (!fnargs)
|
|
||||||
return PyErr_NoMemory();
|
|
||||||
|
|
||||||
const LLVMBasicBlockRef then_blk = pycap_get<LLVMBasicBlockRef> ( obj4 ) ;
|
const LLVMBasicBlockRef then_blk = pycap_get<LLVMBasicBlockRef> ( obj4 ) ;
|
||||||
const LLVMBasicBlockRef catch_blk = pycap_get<LLVMBasicBlockRef> ( obj5 ) ;
|
const LLVMBasicBlockRef catch_blk = pycap_get<LLVMBasicBlockRef> ( obj5 ) ;
|
||||||
|
|
|
||||||
|
|
@ -875,7 +875,7 @@ unsigned LLVMValueGetUses(LLVMValueRef value, LLVMValueRef **refs)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert(refs);
|
assert(refs);
|
||||||
LLVMValueRef *out = (LLVMValueRef *)malloc(sizeof(LLVMValueRef) * n);
|
LLVMValueRef *out = new LLVMValueRef[n];
|
||||||
if (!out)
|
if (!out)
|
||||||
return 0;
|
return 0;
|
||||||
*refs = out;
|
*refs = out;
|
||||||
|
|
@ -893,7 +893,7 @@ unsigned LLVMValueGetUses(LLVMValueRef value, LLVMValueRef **refs)
|
||||||
void LLVMDisposeValueRefArray(LLVMValueRef *refs)
|
void LLVMDisposeValueRefArray(LLVMValueRef *refs)
|
||||||
{
|
{
|
||||||
assert(refs);
|
assert(refs);
|
||||||
free(refs);
|
delete [] refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned LLVMUserGetNumOperands(LLVMValueRef user)
|
unsigned LLVMUserGetNumOperands(LLVMValueRef user)
|
||||||
|
|
@ -1018,11 +1018,9 @@ unsigned char *LLVMGetBitcodeFromModule(LLVMModuleRef module, size_t *lenp)
|
||||||
llvm::WriteBitcodeToFile(modulep, buf);
|
llvm::WriteBitcodeToFile(modulep, buf);
|
||||||
const std::string& bc = buf.str();
|
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();
|
size_t bclen = bc.size();
|
||||||
unsigned char *bytes = (unsigned char *)malloc(bclen);
|
unsigned char *bytes = new unsigned char[bclen];
|
||||||
if (!bytes)
|
|
||||||
return NULL;
|
|
||||||
memcpy(bytes, bc.data(), bclen);
|
memcpy(bytes, bc.data(), bclen);
|
||||||
|
|
||||||
/* return */
|
/* return */
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,6 @@ void *get_object_arg(PyObject *args)
|
||||||
void **make_array_from_list(PyObject *list, int n)
|
void **make_array_from_list(PyObject *list, int n)
|
||||||
{
|
{
|
||||||
void **arr = new void*[n] ;
|
void **arr = new void*[n] ;
|
||||||
if (!arr){
|
|
||||||
PyErr_NoMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i=0; i<n; i++) {
|
for (i=0; i<n; i++) {
|
||||||
|
|
|
||||||
34
llvm/wrap.h
34
llvm/wrap.h
|
|
@ -132,7 +132,7 @@ void *get_object_arg(PyObject *args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a PyList object (list) having n (= PyList_Size(list)) elements,
|
* Given a PyList object (list) having n (= PyList_Size(list)) elements,
|
||||||
* each list object being a PyCObject, return a malloc()-ed array of
|
* each list object being a PyCObject, return a new()-ed array of
|
||||||
* opaque pointers from the PyCObjects. The 'n' is passed explicitly
|
* opaque pointers from the PyCObjects. The 'n' is passed explicitly
|
||||||
* since the caller will have to query it once anyway, and we can avoid
|
* since the caller will have to query it once anyway, and we can avoid
|
||||||
* a second call internally.
|
* a second call internally.
|
||||||
|
|
@ -1149,9 +1149,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
\
|
\
|
||||||
const intype1 arg1 = pycap_get< intype1 > (obj1); \
|
const intype1 arg1 = pycap_get< intype1 > (obj1); \
|
||||||
const size_t arg2n = PyList_Size(obj2); \
|
const size_t arg2n = PyList_Size(obj2); \
|
||||||
intype2 *arg2v; \
|
intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \
|
||||||
if (!(arg2v = make_array_from_list< intype2 *>(obj2, arg2n))) \
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
outtype ret = func (arg1, arg2v, arg2n); \
|
outtype ret = func (arg1, arg2v, arg2n); \
|
||||||
delete [] arg2v ; \
|
delete [] arg2v ; \
|
||||||
|
|
@ -1176,9 +1174,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
\
|
\
|
||||||
const size_t arg1n = PyList_Size(obj1); \
|
const size_t arg1n = PyList_Size(obj1); \
|
||||||
intype1 *arg1v; \
|
intype1 *arg1v = make_array_from_list< intype1 *>(obj1, arg1n); \
|
||||||
if (!(arg1v = make_array_from_list< intype1 *>(obj1, arg1n)))\
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
outtype ret = func (arg1v, arg1n, arg2); \
|
outtype ret = func (arg1v, arg1n, arg2); \
|
||||||
delete [] arg1v; \
|
delete [] arg1v; \
|
||||||
|
|
@ -1202,9 +1198,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
\
|
\
|
||||||
const size_t arg1n = PyList_Size(obj1); \
|
const size_t arg1n = PyList_Size(obj1); \
|
||||||
intype1 *arg1v; \
|
intype1 *arg1v = make_array_from_list< intype1 *>(obj1, arg1n); \
|
||||||
if (!(arg1v = make_array_from_list< intype1 *>(obj1, arg1n)))\
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
outtype ret = func (arg1v, arg1n); \
|
outtype ret = func (arg1v, arg1n); \
|
||||||
delete [] arg1v; \
|
delete [] arg1v; \
|
||||||
|
|
@ -1231,9 +1225,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
intype1 arg1 = pycap_get< intype1 > (obj1); \
|
intype1 arg1 = pycap_get< intype1 > (obj1); \
|
||||||
_CHECK_PYCAP(arg1); \
|
_CHECK_PYCAP(arg1); \
|
||||||
const size_t arg2n = PyList_Size(obj2); \
|
const size_t arg2n = PyList_Size(obj2); \
|
||||||
intype2 *arg2v = NULL; \
|
intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \
|
||||||
if (arg2n && !(arg2v = make_array_from_list< intype2 *>(obj2, arg2n)))\
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
outtype ret = func (arg1, arg2v, arg2n, arg3); \
|
outtype ret = func (arg1, arg2v, arg2n, arg3); \
|
||||||
delete [] arg2v ; \
|
delete [] arg2v ; \
|
||||||
|
|
@ -1261,9 +1253,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
const intype1 arg1 = pycap_get< intype1 > (obj1); \
|
const intype1 arg1 = pycap_get< intype1 > (obj1); \
|
||||||
_CHECK_PYCAP(arg1); \
|
_CHECK_PYCAP(arg1); \
|
||||||
const size_t arg2n = PyList_Size(obj2); \
|
const size_t arg2n = PyList_Size(obj2); \
|
||||||
intype2 *arg2v; \
|
intype2 *arg2v = make_array_from_list< intype2 *>(obj2, arg2n); \
|
||||||
if (!(arg2v = make_array_from_list< intype2 *>(obj2, arg2n)))\
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
func (arg1, arg2v, arg2n, arg3); \
|
func (arg1, arg2v, arg2n, arg3); \
|
||||||
delete [] arg2v ; \
|
delete [] arg2v ; \
|
||||||
|
|
@ -1290,9 +1280,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
const intype1 arg1 = pycap_get< intype1 > (obj1); \
|
const intype1 arg1 = pycap_get< intype1 > (obj1); \
|
||||||
_CHECK_PYCAP(arg1); \
|
_CHECK_PYCAP(arg1); \
|
||||||
const size_t arg3n = PyList_Size(obj3); \
|
const size_t arg3n = PyList_Size(obj3); \
|
||||||
intype3 *arg3v; \
|
intype3 *arg3v = make_array_from_list< intype3 *>(obj3, arg3n); \
|
||||||
if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
outtype ret = func (arg1, arg2, arg3v, arg3n); \
|
outtype ret = func (arg1, arg2, arg3v, arg3n); \
|
||||||
delete [] arg3v ; \
|
delete [] arg3v ; \
|
||||||
|
|
@ -1320,9 +1308,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
const intype2 arg2 = pycap_get< intype2 > (obj2); \
|
const intype2 arg2 = pycap_get< intype2 > (obj2); \
|
||||||
_CHECK_PYCAP(arg2); \
|
_CHECK_PYCAP(arg2); \
|
||||||
const size_t arg3n = PyList_Size(obj3); \
|
const size_t arg3n = PyList_Size(obj3); \
|
||||||
intype3 *arg3v; \
|
intype3 *arg3v = make_array_from_list< intype3 *>(obj3, arg3n); \
|
||||||
if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
outtype ret = func (arg1, arg2, arg3v, arg3n); \
|
outtype ret = func (arg1, arg2, arg3v, arg3n); \
|
||||||
delete [] arg3v ; \
|
delete [] arg3v ; \
|
||||||
|
|
@ -1351,9 +1337,7 @@ _w ## func (PyObject *self, PyObject *args) \
|
||||||
const intype2 arg2 = pycap_get< intype2 > (obj2); \
|
const intype2 arg2 = pycap_get< intype2 > (obj2); \
|
||||||
_CHECK_PYCAP(arg2); \
|
_CHECK_PYCAP(arg2); \
|
||||||
const size_t arg3n = PyList_Size(obj3); \
|
const size_t arg3n = PyList_Size(obj3); \
|
||||||
intype3 *arg3v; \
|
intype3 *arg3v = make_array_from_list< intype3 *>(obj3, arg3n); \
|
||||||
if (!(arg3v = make_array_from_list< intype3 *>(obj3, arg3n))) \
|
|
||||||
return PyErr_NoMemory(); \
|
|
||||||
\
|
\
|
||||||
outtype ret = func (arg1, arg2, arg3v, arg3n, arg4); \
|
outtype ret = func (arg1, arg2, arg3v, arg3n, arg4); \
|
||||||
delete [] arg3v ; \
|
delete [] arg3v ; \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue