int initRun(struct Runobj *runobj, PyObject *args)
{
    PyObject *config, *args_obj, *trace_obj, *time_obj, *memory_obj;
    PyObject *calls_obj, *runner_obj, *fd_obj;
    
    if (!PyArg_ParseTuple(args, "O", &config))
        RAISE1("initRun parseTuple failure");
    if(!PyDict_Check(config)) RAISE1("argument must be a dict");
    
    if((args_obj = PyDict_GetItemString(config,"args")) == NULL)
        RAISE1("must supply args");
    
    if((runobj->args = genRunArgs(args_obj)) == NULL) return -1;
    
    if((fd_obj = PyDict_GetItemString(config, "fd_in")) == NULL)
        runobj->fd_in = -1;
    else runobj->fd_in = PyLong_AsLong(fd_obj);
    if((fd_obj = PyDict_GetItemString(config, "fd_out")) == NULL)
        runobj->fd_out = -1;
    else runobj->fd_out = PyLong_AsLong(fd_obj);
    if((fd_obj = PyDict_GetItemString(config, "fd_err")) == NULL)
        runobj->fd_err = -1;
    else runobj->fd_err = PyLong_AsLong(fd_obj);
      
    if((time_obj = PyDict_GetItemString(config,"timelimit")) == NULL)
        RAISE1("must supply timelimit");
    runobj->time_limit = PyLong_AsLong(time_obj);
    
    if((memory_obj = PyDict_GetItemString(config,"memorylimit")) == NULL)
        RAISE1("must supply memorylimit");
    runobj->memory_limit = PyLong_AsLong(memory_obj);
    
    if((runner_obj = PyDict_GetItemString(config,"runner")) == NULL)
        runobj->runner = -1;
    else
        runobj->runner = PyLong_AsLong(runner_obj);
    
    if((trace_obj = PyDict_GetItemString(config,"trace")) != NULL){
        if(trace_obj == Py_True){
            runobj->trace = 1;
            //trace mode: supply calls and files to access.
            if((calls_obj = PyDict_GetItemString(config,"calls")) == NULL)
                RAISE1("trace == True, so you must specify calls.");
            if(!PyList_Check(calls_obj))
                RAISE1("calls must be a list.");
            if(initCalls(calls_obj, runobj->inttable)) return -1;
            
            if((runobj->files = PyDict_GetItemString(config,"files")) == NULL)
                RAISE1("trace == True, so you must specify files.");
            if(!PyDict_Check(runobj->files))
                RAISE1("files must be a dcit.");
        } else runobj->trace = 0;
    } else runobj->trace = 0;
    
    return 0;
}
Ejemplo n.º 2
0
Archivo: prim.c Proyecto: l0stman/loot
/* Check if the primitive has the right number of arguments */
static inline void
chkargs(char *name, exp_t *args, int num)
{
        exp_t *ep;
        int n;

        for (ep = args, n = num; n-- && !isnull(ep); ep = cdr(ep))
                ;
        if (n != -1 || !isnull(ep))
                RAISE1(eval_error, "%s: expects %d arguments, given %s",
                       name, num, tostr(args));
}
Ejemplo n.º 3
0
int initCalls(PyObject *li, u_char calls[]) {
    PyObject *t;
    Py_ssize_t len, i;

    memset(calls, 0, sizeof(u_char) * CALLS_MAX);

    len = PyList_Size(li);
    for (i = 0; i < len; i++) {
        t = PyList_GetItem(li, i);
        if (t == NULL) {return -1;}

        #ifdef IS_PY3
        if (!PyLong_Check(t))
            RAISE1("calls must be a list of numbers.");
        calls[PyLong_AsLong(t)] = 1;
        #else
        if (!PyInt_Check(t) && !PyLong_Check(t))
            RAISE1("calls must be a list of numbers.");
        calls[PyInt_AsLong(t)] = 1;
        #endif
    }

    return 0;
}