static PyObject *pyAssertTimers(PyObject *self, PyObject *args) { void *handle; if (!PyArg_ParseTuple(args, "l", &handle)) { PyErr_SetString(RulesError, "pyAssertTimers Invalid argument"); return NULL; } unsigned int result = assertTimers(handle); if (result == RULES_OK) { return Py_BuildValue("i", 1); } else if (result == ERR_NO_TIMERS_AVAILABLE) { return Py_BuildValue("i", 0); } else { if (result == ERR_OUT_OF_MEMORY) { PyErr_NoMemory(); } else { char *message; if (asprintf(&message, "Could not assert timers, error code: %d", result)) { PyErr_NoMemory(); } else { PyErr_SetString(RulesError, message); free(message); } } return NULL; } }
static VALUE rbAssertTimers(VALUE self, VALUE handle) { Check_Type(handle, T_FIXNUM); unsigned int result = assertTimers((void *)FIX2LONG(handle)); if (result == RULES_OK) { return INT2FIX(1); } else if (result == ERR_NO_TIMERS_AVAILABLE) { return INT2FIX(0); } else { if (result == ERR_OUT_OF_MEMORY) { rb_raise(rb_eNoMemError, "Out of memory"); } else { rb_raise(rb_eException, "Could not assert timers, error code: %d", result); } } return Qnil; }