Exemple #1
0
static PyObject *pyAssertEvents(PyObject *self, PyObject *args) {
    void *handle;
    char *events;
    if (!PyArg_ParseTuple(args, "ls", &handle, &events)) {
        PyErr_SetString(RulesError, "pyAssertEvents Invalid argument");
        return NULL;
    }

    unsigned int *results = NULL;
    unsigned int resultsLength;
    unsigned int result = assertEvents(handle, events, &resultsLength, &results);
    if (result == RULES_OK) {
        if (results) {
            free(results);
        }
        return Py_BuildValue("i", resultsLength);
    } else {
        if (result == ERR_OUT_OF_MEMORY) {
            PyErr_NoMemory();
        } else { 
            if (results) {
                free(results);
            }
            char *message;
            if (asprintf(&message, "Could not assert events, error code: %d", result)) {
                PyErr_NoMemory();
            } else {
                PyErr_SetString(RulesError, message);
                free(message);
            }
        }
        return NULL;
    }
}
Exemple #2
0
static VALUE rbAssertEvents(VALUE self, VALUE handle, VALUE events) {
    Check_Type(handle, T_FIXNUM);
    Check_Type(events, T_STRING);

    unsigned int *results = NULL;
    unsigned int resultsLength = 0;
    unsigned int result = assertEvents((void *)FIX2LONG(handle), RSTRING_PTR(events), &resultsLength, &results);
    if (result == RULES_OK) {
        if (results) {
            free(results);
        }
        return INT2FIX(resultsLength);   
    } else {
        if (result == ERR_OUT_OF_MEMORY) {
            rb_raise(rb_eNoMemError, "Out of memory");
        } else { 
            if (results) {
                free(results);
            }
            rb_raise(rb_eException, "Could not assert events, error code: %d", result);
        }
    }

    return Qnil;
}