Add try-catch to all exposed functions
This commit is contained in:
parent
d77c3a61e1
commit
f17d4f7d62
2 changed files with 183 additions and 5 deletions
|
|
@ -63,6 +63,7 @@ typedef int Py_ssize_t;
|
|||
static PyObject *
|
||||
_wLLVMModuleCreateWithName(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const char *s;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:LLVMModuleCreateWithName", &s)) {
|
||||
|
|
@ -71,6 +72,7 @@ _wLLVMModuleCreateWithName(PyObject *self, PyObject *args)
|
|||
|
||||
const LLVMModuleRef module = LLVMModuleCreateWithName(s);
|
||||
return ctor_LLVMModuleRef(module);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_obj2str(LLVMGetDataLayout, LLVMModuleRef)
|
||||
|
|
@ -91,6 +93,7 @@ _wrap_objstrobj2obj(LLVMModuleGetOrInsertFunction, LLVMModuleRef,
|
|||
static PyObject *
|
||||
_wLLVMVerifyModule(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const LLVMModuleRef m = get_object_arg<LLVMModuleRef>(args) ;
|
||||
if (!m) return NULL;
|
||||
|
||||
|
|
@ -106,6 +109,7 @@ _wLLVMVerifyModule(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
///// unused
|
||||
|
|
@ -115,6 +119,7 @@ _wLLVMVerifyModule(PyObject *self, PyObject *args)
|
|||
static PyObject*
|
||||
_wLLVMGetModuleFromAssembly(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const char * str;
|
||||
if ( !PyArg_ParseTuple(args, "s", &str) ){
|
||||
return NULL;
|
||||
|
|
@ -134,11 +139,13 @@ _wLLVMGetModuleFromAssembly(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ctor_LLVMModuleRef(mod);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMGetModuleFromBitcode(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj ;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "S", &obj))
|
||||
|
|
@ -162,12 +169,13 @@ _wLLVMGetModuleFromBitcode(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ctor_LLVMModuleRef(m);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMGetBitcodeFromModule(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
||||
_TRY
|
||||
const LLVMModuleRef m = get_object_arg<LLVMModuleRef>(args) ;
|
||||
if (!m ) return NULL;
|
||||
|
||||
|
|
@ -179,12 +187,13 @@ _wLLVMGetBitcodeFromModule(PyObject *self, PyObject *args)
|
|||
PyObject *ret = PyBytes_FromStringAndSize(chars, len);
|
||||
LLVMDisposeMessage(const_cast<char*>(chars));
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMGetNativeCodeFromModule(PyObject * self, PyObject * args)
|
||||
{
|
||||
|
||||
_TRY
|
||||
PyObject * arg_m;
|
||||
int arg_use_asm;
|
||||
|
||||
|
|
@ -207,11 +216,13 @@ _wLLVMGetNativeCodeFromModule(PyObject * self, PyObject * args)
|
|||
LLVMDisposeMessage(const_cast<char*>(chars));
|
||||
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMLinkModules(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
size_t mode = 0;
|
||||
|
||||
PyObject *dest_obj, *src_obj ;
|
||||
|
|
@ -235,6 +246,7 @@ _wLLVMLinkModules(PyObject *self, PyObject *args)
|
|||
|
||||
/* note: success => None, failure => string with error message */
|
||||
Py_RETURN_NONE;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
|
|
@ -310,7 +322,9 @@ obj2arr(PyObject *self, PyObject *args, arrcnt_fn_t cntfunc, obj2arr_fn_t arrfun
|
|||
static PyObject *
|
||||
_wLLVMGetFunctionTypeParams(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
return obj2arr(self, args, LLVMCountParamTypes, LLVMGetParamTypes);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
/*===-- Struct types -----------------------------------------------------===*/
|
||||
|
|
@ -326,8 +340,10 @@ _wrap_objstr2none(LLVMSetStructName, LLVMTypeRef)
|
|||
static PyObject *
|
||||
_wLLVMGetStructElementTypes(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
return obj2arr(self, args, LLVMCountStructElementTypes,
|
||||
LLVMGetStructElementTypes);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -382,6 +398,7 @@ _wrap_obj2obj(LLVMValueGetNumUses, LLVMValueRef, int)
|
|||
static PyObject *
|
||||
_wLLVMValueGetUses(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const LLVMValueRef value = get_object_arg<LLVMValueRef>(args) ;
|
||||
if (!value) return NULL;
|
||||
|
||||
|
|
@ -393,6 +410,7 @@ _wLLVMValueGetUses(PyObject *self, PyObject *args)
|
|||
LLVMDisposeValueRefArray(uses);
|
||||
|
||||
return list;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
/*===-- Users ------------------------------------------------------------===*/
|
||||
|
|
@ -416,6 +434,7 @@ _wrap_obj2obj(LLVMIsUndef, LLVMValueRef, int)
|
|||
static PyObject *
|
||||
_wLLVMConstInt(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj;
|
||||
unsigned long long n;
|
||||
int sign_extend;
|
||||
|
|
@ -428,11 +447,13 @@ _wLLVMConstInt(PyObject *self, PyObject *args)
|
|||
const LLVMValueRef val = LLVMConstInt(ty, n, sign_extend);
|
||||
|
||||
return ctor_LLVMValueRef(val);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMConstReal(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj;
|
||||
double d;
|
||||
|
||||
|
|
@ -443,6 +464,7 @@ _wLLVMConstReal(PyObject *self, PyObject *args)
|
|||
|
||||
const LLVMValueRef val = LLVMConstReal(ty, d);
|
||||
return ctor_LLVMValueRef(val);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_objstr2obj(LLVMConstRealOfString, LLVMTypeRef, LLVMValueRef)
|
||||
|
|
@ -454,6 +476,7 @@ _wrap_obj2obj(LLVMConstIntGetSExtValue, LLVMValueRef, llvmwrap_ll)
|
|||
static PyObject *
|
||||
_wLLVMConstString(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const char *s;
|
||||
int dont_null_terminate;
|
||||
|
||||
|
|
@ -463,6 +486,7 @@ _wLLVMConstString(PyObject *self, PyObject *args)
|
|||
|
||||
LLVMValueRef val = LLVMConstString(s, strlen(s), dont_null_terminate);
|
||||
return ctor_LLVMValueRef(val);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_objlist2obj(LLVMConstArray, LLVMTypeRef, LLVMValueRef, LLVMValueRef)
|
||||
|
|
@ -574,10 +598,12 @@ _wrap_objenum2none(LLVMRemoveFunctionAttr, LLVMValueRef, LLVMAttribute)
|
|||
static PyObject *
|
||||
_wLLVMVerifyFunction(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const LLVMValueRef fn = get_object_arg<LLVMValueRef>(args);
|
||||
if (!fn) return NULL;
|
||||
|
||||
return ctor_int(LLVMVerifyFunction(fn, LLVMReturnStatusAction));
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -615,6 +641,7 @@ _wrap_objstr2obj(LLVMMetaDataStringGet, LLVMModuleRef, LLVMValueRef)
|
|||
static PyObject *
|
||||
_wLLVMGetNamedMetadataOperands(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj_module;
|
||||
const char *name;
|
||||
|
||||
|
|
@ -630,6 +657,7 @@ _wLLVMGetNamedMetadataOperands(PyObject *self, PyObject *args)
|
|||
free(operands);
|
||||
|
||||
return list;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
/*===-- Instructions -----------------------------------------------------===*/
|
||||
|
|
@ -699,6 +727,7 @@ _wrap_objobjobjint2obj(LLVMBuildSwitch, LLVMBuilderRef, LLVMValueRef, LLVMBasicB
|
|||
static PyObject *
|
||||
_wLLVMBuildInvoke(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj1, *obj2, *obj3, *obj4, *obj5;
|
||||
const char *name;
|
||||
|
||||
|
|
@ -725,6 +754,7 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args)
|
|||
delete [] fnargs;
|
||||
|
||||
return ctor_LLVMValueRef(inst);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_obj2obj(LLVMBuildUnreachable, LLVMBuilderRef, LLVMValueRef)
|
||||
|
|
@ -818,6 +848,7 @@ _wrap_objobjobjobjstr2obj(LLVMBuildShuffleVector, LLVMBuilderRef, LLVMValueRef,
|
|||
static PyObject *
|
||||
_wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const char *path;
|
||||
LLVMMemoryBufferRef ref;
|
||||
PyObject *ret;
|
||||
|
|
@ -835,11 +866,13 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMCreateMemoryBufferWithSTDIN(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *ret;
|
||||
LLVMMemoryBufferRef ref;
|
||||
char *outmsg;
|
||||
|
|
@ -851,6 +884,7 @@ _wLLVMCreateMemoryBufferWithSTDIN(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_obj2none(LLVMDisposeMemoryBuffer, LLVMMemoryBufferRef)
|
||||
|
|
@ -1041,6 +1075,7 @@ _wrap_obj2none(LLVMDisposeTargetMachine, LLVMTargetMachineRef)
|
|||
static PyObject *
|
||||
_wLLVMTargetMachineLookup(PyObject * self, PyObject * args)
|
||||
{
|
||||
_TRY
|
||||
const char *arch;
|
||||
const char *cpu;
|
||||
const char *features;
|
||||
|
|
@ -1057,12 +1092,13 @@ _wLLVMTargetMachineLookup(PyObject * self, PyObject * args)
|
|||
return NULL;
|
||||
}
|
||||
return ctor_LLVMTargetMachineRef(tm);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMTargetMachineEmitFile(PyObject * self, PyObject * args)
|
||||
{
|
||||
|
||||
_TRY
|
||||
PyObject *arg_tm, *arg_m;
|
||||
int arg_use_asm;
|
||||
|
||||
|
|
@ -1086,6 +1122,7 @@ _wLLVMTargetMachineEmitFile(PyObject * self, PyObject * args)
|
|||
PyObject * ret = PyBytes_FromStringAndSize(chars, len);
|
||||
delete [] ubytes;
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_obj2obj(LLVMTargetMachineGetTargetData, LLVMTargetMachineRef,
|
||||
|
|
@ -1108,6 +1145,7 @@ _wrap_obj2none(LLVMDisposeTargetData, LLVMTargetDataRef)
|
|||
static PyObject *
|
||||
_wLLVMTargetDataAsString(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const LLVMTargetDataRef td = get_object_arg<LLVMTargetDataRef>(args);
|
||||
if (!td) return NULL;
|
||||
|
||||
|
|
@ -1115,6 +1153,7 @@ _wLLVMTargetDataAsString(PyObject *self, PyObject *args)
|
|||
PyObject *ret = PyUnicode_FromString(tdrep);
|
||||
LLVMDisposeMessage(tdrep);
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_objobj2none(LLVMAddTargetData, LLVMTargetDataRef, LLVMPassManagerRef)
|
||||
|
|
@ -1155,6 +1194,7 @@ _wrap_objstr2none(LLVMEngineBuilderSetMAttrs, LLVMEngineBuilderRef)
|
|||
static PyObject *
|
||||
_wLLVMEngineBuilderCreate(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const LLVMEngineBuilderRef obj
|
||||
= get_object_arg<LLVMEngineBuilderRef>(args) ;
|
||||
if (!obj)
|
||||
|
|
@ -1171,6 +1211,7 @@ _wLLVMEngineBuilderCreate(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
|
|
@ -1180,6 +1221,7 @@ _wLLVMEngineBuilderCreate(PyObject *self, PyObject *args)
|
|||
static PyObject *
|
||||
_wLLVMCreateExecutionEngine(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj;
|
||||
int force_interpreter;
|
||||
char *outmsg = 0;
|
||||
|
|
@ -1205,11 +1247,13 @@ _wLLVMCreateExecutionEngine(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMGetPointerToFunction(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj_ee;
|
||||
PyObject *obj_fn;
|
||||
|
||||
|
|
@ -1220,6 +1264,7 @@ _wLLVMGetPointerToFunction(PyObject *self, PyObject *args)
|
|||
const LLVMValueRef fn = pycap_get<LLVMValueRef>( obj_fn ) ;
|
||||
|
||||
return PyLong_FromVoidPtr(LLVMGetPointerToFunction(ee,fn));
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
/* the args should have been ptr, num */
|
||||
|
|
@ -1232,8 +1277,8 @@ LLVMGenericValueRef LLVMRunFunction2(LLVMExecutionEngineRef EE,
|
|||
static PyObject *
|
||||
_wLLVMRemoveModule2(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj_ee;
|
||||
|
||||
PyObject *obj_mod;
|
||||
if (!PyArg_ParseTuple(args, "OO", &obj_ee, &obj_mod))
|
||||
return NULL;
|
||||
|
|
@ -1257,6 +1302,7 @@ _wLLVMRemoveModule2(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
return ret;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_obj2none(LLVMDisposeExecutionEngine, LLVMExecutionEngineRef)
|
||||
|
|
@ -1279,6 +1325,7 @@ _wrap_objobj2none(LLVMAddModule, LLVMExecutionEngineRef,
|
|||
static PyObject *
|
||||
_wLLVMCreateGenericValueOfInt(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj1;
|
||||
unsigned long long n;
|
||||
int is_signed;
|
||||
|
|
@ -1291,11 +1338,13 @@ _wLLVMCreateGenericValueOfInt(PyObject *self, PyObject *args)
|
|||
|
||||
gv = LLVMCreateGenericValueOfInt(ty, n, is_signed);
|
||||
return ctor_LLVMGenericValueRef(gv);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMCreateGenericValueOfFloat(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj1;
|
||||
double d;
|
||||
LLVMGenericValueRef gv;
|
||||
|
|
@ -1307,11 +1356,13 @@ _wLLVMCreateGenericValueOfFloat(PyObject *self, PyObject *args)
|
|||
|
||||
gv = LLVMCreateGenericValueOfFloat(ty, d);
|
||||
return ctor_LLVMGenericValueRef(gv);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMCreateGenericValueOfPointer(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
// PyObject *obj1;
|
||||
// LLVMTypeRef ty; //unused?
|
||||
unsigned long long n_;
|
||||
|
|
@ -1324,11 +1375,13 @@ _wLLVMCreateGenericValueOfPointer(PyObject *self, PyObject *args)
|
|||
|
||||
const LLVMGenericValueRef gv = LLVMCreateGenericValueOfPointer((void*)n);
|
||||
return ctor_LLVMGenericValueRef(gv);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMGenericValueToInt(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj1;
|
||||
int is_signed;
|
||||
unsigned long long val;
|
||||
|
|
@ -1342,11 +1395,13 @@ _wLLVMGenericValueToInt(PyObject *self, PyObject *args)
|
|||
return is_signed ?
|
||||
PyLong_FromLongLong((long long)val) :
|
||||
PyLong_FromUnsignedLongLong(val);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMGenericValueToFloat(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj1, *obj2;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OO", &obj1, &obj2))
|
||||
|
|
@ -1357,11 +1412,13 @@ _wLLVMGenericValueToFloat(PyObject *self, PyObject *args)
|
|||
|
||||
double val = LLVMGenericValueToFloat(ty, gv);
|
||||
return PyFloat_FromDouble(val);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMGenericValueToPointer(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
PyObject *obj1;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &obj1))
|
||||
|
|
@ -1371,6 +1428,7 @@ _wLLVMGenericValueToPointer(PyObject *self, PyObject *args)
|
|||
|
||||
void * val = LLVMGenericValueToPointer(gv);
|
||||
return PyLong_FromVoidPtr(val);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_obj2none(LLVMDisposeGenericValue, LLVMGenericValueRef)
|
||||
|
|
@ -1386,6 +1444,7 @@ _wrap_objintlist2obj(LLVMGetIntrinsic, LLVMModuleRef, LLVMTypeRef,
|
|||
static PyObject *
|
||||
_wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const char *filename;
|
||||
PyObject *ret;
|
||||
|
||||
|
|
@ -1404,11 +1463,13 @@ _wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
|
|||
|
||||
/* note: success => None, failure => string with error message */
|
||||
Py_RETURN_NONE;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
_wLLVMParseEnvOpts(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
const char * progname;
|
||||
const char * envname;
|
||||
if(!PyArg_ParseTuple(args, "ss", &progname, &envname)) {
|
||||
|
|
@ -1418,6 +1479,7 @@ _wLLVMParseEnvOpts(PyObject *self, PyObject *args)
|
|||
llvm::cl::ParseEnvironmentOptions(progname, envname);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
_wrap_obj2obj(LLVMInlineFunction, LLVMValueRef, int)
|
||||
|
|
@ -1427,12 +1489,14 @@ _wrap_obj2obj(LLVMInlineFunction, LLVMValueRef, int)
|
|||
static PyObject *
|
||||
_wPyCObjectVoidPtrToPyLong(PyObject *self, PyObject *args)
|
||||
{
|
||||
_TRY
|
||||
void *p;
|
||||
|
||||
if (!(p = get_object_arg(args)))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromVoidPtr(p);
|
||||
_CATCH_ALL
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue