add use_sandbox parameter

This commit is contained in:
virusdefender 2016-01-22 10:01:08 +08:00
parent 11ace673e2
commit da1a446946
2 changed files with 15 additions and 5 deletions

View File

@ -7,15 +7,16 @@ static PyObject *error;
static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
struct config config;
struct result result = {0, 0, 0, 0, 0};
PyObject *args_list = NULL, *env_list = NULL, *next = NULL, *args_iter = NULL, *env_iter = NULL;
struct result result = {0, 0, 0, 0, 0, 1};
PyObject *args_list = NULL, *env_list = NULL, *use_sandbox, *next = NULL, *args_iter = NULL, *env_iter = NULL;
int count = 0;
static char *kwargs_list[] = {"path", "in_file", "out_file", "max_cpu_time", "max_memory", "args", "env", NULL};
static char *kwargs_list[] = {"path", "in_file", "out_file", "max_cpu_time",
"max_memory", "args", "env", "use_sandbox", NULL};
config.path = config.in_file = config.out_file = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sssii|OO", kwargs_list, &(config.path), &(config.in_file),
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sssii|OOO", kwargs_list, &(config.path), &(config.in_file),
&(config.out_file), &(config.max_cpu_time), &(config.max_memory),
&args_list, &env_list)) {
&args_list, &env_list, &use_sandbox)) {
PyErr_SetString(error, "Invalid args and kwargs");
return NULL;
}
@ -79,6 +80,14 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
}
config.env[count] = NULL;
if (use_sandbox != NULL) {
if (!PyBool_Check(use_sandbox)) {
PyErr_SetString(error, "use sandbox must ba a bool");
return NULL;
}
config.use_sandbox = PyObject_IsTrue(use_sandbox);
}
run(&config, &result);
return Py_BuildValue("{s:i, s:l, s:i, s:i, s:i, s:i}",
"cpu_time", result.cpu_time, "memory", result.memory, "real_time", result.real_time, "signal",

View File

@ -49,6 +49,7 @@ struct config {
char *out_file;
char *args[100];
char *env[100];
int use_sandbox;
};