py/rna: BPy_reports_to_error() now takes the exception type as an argument and returns -1 as an error value

This commit is contained in:
Campbell Barton 2011-03-12 15:18:08 +00:00
parent a5e59ede6e
commit 90d42e114c
5 changed files with 12 additions and 13 deletions

@ -198,8 +198,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
if(BPy_reports_to_error(reports, FALSE))
error_val = -1;
error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE);
/* operator output is nice to have in the terminal/console too */
if(reports->list.first) {

@ -4223,10 +4223,10 @@ static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
BKE_reports_init(&reports, RPT_STORE);
RNA_function_call(C, &reports, self_ptr, self_func, &parms);
err= (BPy_reports_to_error(&reports, TRUE))? -1: 0;
err= (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE));
/* return value */
if(err==0) {
if(err != -1) {
if (ret_len > 0) {
if (ret_len > 1) {
ret= PyTuple_New(ret_len);
@ -6127,7 +6127,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
srna_new= reg(C, &reports, py_class, identifier, bpy_class_validate, bpy_class_call, bpy_class_free);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
/* python errors validating are not converted into reports so the check above will fail.

@ -183,7 +183,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
result= insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
MEM_freeN((void *)path_full);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
return PyBool_FromLong(result);
@ -228,7 +228,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
result= delete_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
MEM_freeN((void *)path_full);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
return PyBool_FromLong(result);
@ -270,7 +270,7 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
result= ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0, DRIVER_TYPE_PYTHON);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
if(result) {
@ -345,7 +345,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
MEM_freeN((void *)path_full);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
return PyBool_FromLong(result);

@ -57,7 +57,7 @@ char *BPy_enum_as_string(EnumPropertyItem *item)
return cstring;
}
short BPy_reports_to_error(ReportList *reports, const short clear)
short BPy_reports_to_error(ReportList *reports, PyObject *exception, const short clear)
{
char *report_str;
@ -68,11 +68,11 @@ short BPy_reports_to_error(ReportList *reports, const short clear)
}
if(report_str) {
PyErr_SetString(PyExc_RuntimeError, report_str);
PyErr_SetString(exception, report_str);
MEM_freeN(report_str);
}
return (report_str != NULL);
return (report_str == NULL) ? 0 : -1;
}

@ -44,7 +44,7 @@ char *BPy_enum_as_string(struct EnumPropertyItem *item);
#define BLANK_PYTHON_TYPE {PyVarObject_HEAD_INIT(NULL, 0) NULL}
/* error reporting */
short BPy_reports_to_error(struct ReportList *reports, const short clear);
short BPy_reports_to_error(struct ReportList *reports, PyObject *exception, const short clear);
short BPy_errors_to_report(struct ReportList *reports);
/* TODO - find a better solution! */