mirror of https://git.kore.io/kore.git
allow use udata in kore.timer() via the data kwarg.
This commit is contained in:
parent
2d380cac3f
commit
d86a10afa1
|
@ -38,7 +38,6 @@ static PyObject *python_kore_log(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_time(PyObject *, PyObject *);
|
static PyObject *python_kore_time(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_lock(PyObject *, PyObject *);
|
static PyObject *python_kore_lock(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_proc(PyObject *, PyObject *);
|
static PyObject *python_kore_proc(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_timer(PyObject *, PyObject *);
|
|
||||||
static PyObject *python_kore_fatal(PyObject *, PyObject *);
|
static PyObject *python_kore_fatal(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_queue(PyObject *, PyObject *);
|
static PyObject *python_kore_queue(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_worker(PyObject *, PyObject *);
|
static PyObject *python_kore_worker(PyObject *, PyObject *);
|
||||||
|
@ -53,6 +52,7 @@ static PyObject *python_kore_task_kill(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_prerequest(PyObject *, PyObject *);
|
static PyObject *python_kore_prerequest(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_task_create(PyObject *, PyObject *);
|
static PyObject *python_kore_task_create(PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_socket_wrap(PyObject *, PyObject *);
|
static PyObject *python_kore_socket_wrap(PyObject *, PyObject *);
|
||||||
|
static PyObject *python_kore_timer(PyObject *, PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_domain(PyObject *, PyObject *, PyObject *);
|
static PyObject *python_kore_domain(PyObject *, PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_gather(PyObject *, PyObject *, PyObject *);
|
static PyObject *python_kore_gather(PyObject *, PyObject *, PyObject *);
|
||||||
static PyObject *python_kore_sendobj(PyObject *, PyObject *,
|
static PyObject *python_kore_sendobj(PyObject *, PyObject *,
|
||||||
|
@ -84,7 +84,6 @@ static struct PyMethodDef pykore_methods[] = {
|
||||||
METHOD("time", python_kore_time, METH_NOARGS),
|
METHOD("time", python_kore_time, METH_NOARGS),
|
||||||
METHOD("lock", python_kore_lock, METH_NOARGS),
|
METHOD("lock", python_kore_lock, METH_NOARGS),
|
||||||
METHOD("proc", python_kore_proc, METH_VARARGS),
|
METHOD("proc", python_kore_proc, METH_VARARGS),
|
||||||
METHOD("timer", python_kore_timer, METH_VARARGS),
|
|
||||||
METHOD("queue", python_kore_queue, METH_VARARGS),
|
METHOD("queue", python_kore_queue, METH_VARARGS),
|
||||||
METHOD("worker", python_kore_worker, METH_VARARGS),
|
METHOD("worker", python_kore_worker, METH_VARARGS),
|
||||||
METHOD("tracer", python_kore_tracer, METH_VARARGS),
|
METHOD("tracer", python_kore_tracer, METH_VARARGS),
|
||||||
|
@ -99,6 +98,7 @@ static struct PyMethodDef pykore_methods[] = {
|
||||||
METHOD("prerequest", python_kore_prerequest, METH_VARARGS),
|
METHOD("prerequest", python_kore_prerequest, METH_VARARGS),
|
||||||
METHOD("task_create", python_kore_task_create, METH_VARARGS),
|
METHOD("task_create", python_kore_task_create, METH_VARARGS),
|
||||||
METHOD("socket_wrap", python_kore_socket_wrap, METH_VARARGS),
|
METHOD("socket_wrap", python_kore_socket_wrap, METH_VARARGS),
|
||||||
|
METHOD("timer", python_kore_timer, METH_VARARGS | METH_KEYWORDS),
|
||||||
METHOD("server", python_kore_server, METH_VARARGS | METH_KEYWORDS),
|
METHOD("server", python_kore_server, METH_VARARGS | METH_KEYWORDS),
|
||||||
METHOD("gather", python_kore_gather, METH_VARARGS | METH_KEYWORDS),
|
METHOD("gather", python_kore_gather, METH_VARARGS | METH_KEYWORDS),
|
||||||
METHOD("domain", python_kore_domain, METH_VARARGS | METH_KEYWORDS),
|
METHOD("domain", python_kore_domain, METH_VARARGS | METH_KEYWORDS),
|
||||||
|
@ -256,6 +256,7 @@ struct pytimer {
|
||||||
int flags;
|
int flags;
|
||||||
struct kore_timer *run;
|
struct kore_timer *run;
|
||||||
PyObject *callable;
|
PyObject *callable;
|
||||||
|
PyObject *udata;
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyObject *pytimer_close(struct pytimer *, PyObject *);
|
static PyObject *pytimer_close(struct pytimer *, PyObject *);
|
||||||
|
|
19
src/python.c
19
src/python.c
|
@ -2273,7 +2273,7 @@ python_kore_corotrace(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
python_kore_timer(PyObject *self, PyObject *args)
|
python_kore_timer(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
u_int64_t ms;
|
u_int64_t ms;
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
|
@ -2291,6 +2291,7 @@ python_kore_timer(PyObject *self, PyObject *args)
|
||||||
if ((timer = PyObject_New(struct pytimer, &pytimer_type)) == NULL)
|
if ((timer = PyObject_New(struct pytimer, &pytimer_type)) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
|
timer->udata = NULL;
|
||||||
timer->flags = flags;
|
timer->flags = flags;
|
||||||
timer->callable = obj;
|
timer->callable = obj;
|
||||||
timer->run = kore_timer_add(pytimer_run, ms, timer, flags);
|
timer->run = kore_timer_add(pytimer_run, ms, timer, flags);
|
||||||
|
@ -2298,6 +2299,13 @@ python_kore_timer(PyObject *self, PyObject *args)
|
||||||
Py_INCREF((PyObject *)timer);
|
Py_INCREF((PyObject *)timer);
|
||||||
Py_INCREF(timer->callable);
|
Py_INCREF(timer->callable);
|
||||||
|
|
||||||
|
if (kwargs != NULL) {
|
||||||
|
if ((obj = PyDict_GetItemString(kwargs, "data")) != NULL) {
|
||||||
|
Py_INCREF(obj);
|
||||||
|
timer->udata = obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ((PyObject *)timer);
|
return ((PyObject *)timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2581,9 +2589,11 @@ pytimer_run(void *arg, u_int64_t now)
|
||||||
struct pytimer *timer = arg;
|
struct pytimer *timer = arg;
|
||||||
|
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
ret = PyObject_CallObject(timer->callable, NULL);
|
ret = PyObject_CallFunctionObjArgs(timer->callable, timer->udata, NULL);
|
||||||
Py_XDECREF(ret);
|
Py_XDECREF(ret);
|
||||||
|
Py_XDECREF(timer->udata);
|
||||||
|
|
||||||
|
timer->udata = NULL;
|
||||||
kore_python_log_error("pytimer_run");
|
kore_python_log_error("pytimer_run");
|
||||||
|
|
||||||
if (timer->flags & KORE_TIMER_ONESHOT) {
|
if (timer->flags & KORE_TIMER_ONESHOT) {
|
||||||
|
@ -2621,6 +2631,11 @@ pytimer_close(struct pytimer *timer, PyObject *args)
|
||||||
timer->callable = NULL;
|
timer->callable = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timer->udata != NULL) {
|
||||||
|
Py_DECREF(timer->udata);
|
||||||
|
timer->udata = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
Py_INCREF((PyObject *)timer);
|
Py_INCREF((PyObject *)timer);
|
||||||
Py_RETURN_TRUE;
|
Py_RETURN_TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue