Move null-checks into converter
@@ -70,6 +70,10 @@ static int gpi_sim_hdl_converter(PyObject *o, gpi_sim_hdl *data)
if ((p == NULL) && PyErr_Occurred()) {
return 0;
}
+ if (p == NULL) {
+ PyErr_SetString(PyExc_ValueError, "handle cannot be 0");
+ return 0;
+ }
*data = (gpi_sim_hdl)p;
return 1;
}
@@ -81,6 +85,10 @@ static int gpi_iterator_hdl_converter(PyObject *o, gpi_iterator_hdl *data)
if ((p == NULL) && PyErr_Occurred()) {
return 0;
}
+ if (p == NULL) {
+ PyErr_SetString(PyExc_ValueError, "handle cannot be 0");
+ return 0;
+ }
*data = (gpi_iterator_hdl)p;
return 1;
}
@@ -443,10 +451,6 @@ static PyObject *register_value_change_callback(PyObject *self, PyObject *args)
if (!gpi_sim_hdl_converter(pSihHdl, &sig_hdl)) {
return NULL;
}
- if (sig_hdl == NULL) {
- PyErr_SetString(PyExc_ValueError, "handle cannot be 0");
- return NULL;
- }
// Extract the callback function
function = PyTuple_GetItem(args, 1);
@@ -896,10 +900,6 @@ static PyObject *deregister_callback(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O&", gpi_sim_hdl_converter, &hdl)) {
return NULL;
}
- if (hdl == NULL) {
- PyErr_SetString(PyExc_ValueError, "handle cannot be 0");
- return NULL;
- }
gpi_deregister_callback(hdl);
