Skip to content

Commit

Permalink
Improved error handling using SWIG_fail.
Browse files Browse the repository at this point in the history
The SWIG_fail expands to `goto fail`, which is a code section that
returns `NULL` and frees the memory if applicable.
  • Loading branch information
matejak committed Oct 9, 2018
1 parent 9895db2 commit 971b8b9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions swig/src/openscap.i
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
$1 = (time_t) PyFloat_AsDouble($input);
else {
PyErr_SetString(PyExc_TypeError,"Expected a large number");
return NULL;
SWIG_fail;
}
}

Expand Down Expand Up @@ -88,7 +88,7 @@
$1[i] = 0;
} else {
PyErr_SetString(PyExc_TypeError,"not a list");
return NULL;
SWIG_fail;
}
}

Expand All @@ -105,11 +105,11 @@

if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence");
return NULL;
SWIG_fail;
}
if (a_size <= 0) {
PyErr_SetString(PyExc_ValueError,"Expected not empty sequence");
return NULL;
SWIG_fail;
}

$1 = (struct cpe_name **) malloc(a_size*sizeof(struct cpe_name *));
Expand All @@ -118,12 +118,12 @@
PyObject *obj = PySequence_GetItem($input,i);
if (obj == NULL) {
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "cpe_name" "' substitution '" "', can't access sequence");
return NULL; /*5956*/
SWIG_fail; /*5956*/
}
res_o = SWIG_ConvertPtr(obj, &arg, SWIGTYPE_p_cpe_name, 0 );
if (!SWIG_IsOK(res_o)) {
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "cpe_name" "' substitution invalid types");
return NULL;
SWIG_fail;
}
$1[i] = (struct cpe_name *) arg;
}
Expand All @@ -137,11 +137,11 @@

if (!PySequence_Check($input)) {
PyErr_SetString(PyExc_ValueError,"Expected a sequence");
return NULL;
SWIG_fail;
}
if (a_size <= 0) {
PyErr_SetString(PyExc_ValueError,"Expected not empty sequence");
return NULL;
SWIG_fail;
}

$1 = (struct oval_syschar_model **) malloc(a_size*sizeof(struct oval_syschar_model *));
Expand All @@ -150,12 +150,12 @@
PyObject *obj = PySequence_GetItem($input,i);
if (obj == NULL) {
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "oval_syschar_model" "' substitution '" "', can't access sequence");
return NULL;
SWIG_fail;
}
res_o = SWIG_ConvertPtr(obj, &arg, SWIGTYPE_p_oval_syschar_model, 0 );
if (!SWIG_IsOK(res_o)) {
SWIG_exception_fail(SWIG_ArgError(res_o), "in argument '" "oval_syschar_model" "' substitution invalid types");
return NULL;
SWIG_fail;
}
$1[i] = (struct oval_syschar_model *) arg;
}
Expand Down

0 comments on commit 971b8b9

Please sign in to comment.