mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 20:49:01 -04:00
Merge branch 'master' into 3.0.0-releng
This commit is contained in:
commit
348138e747
@ -21,7 +21,7 @@
|
||||
#define daemon portability_is_king
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/un.h>
|
||||
|
@ -39,6 +39,7 @@ static PyObject *python_kore_bind(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_timer(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_fatal(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_queue(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_tracer(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_gather(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_fatalx(PyObject *, PyObject *);
|
||||
static PyObject *python_kore_suspend(PyObject *, PyObject *);
|
||||
@ -66,6 +67,7 @@ static struct PyMethodDef pykore_methods[] = {
|
||||
METHOD("bind", python_kore_bind, METH_VARARGS),
|
||||
METHOD("timer", python_kore_timer, METH_VARARGS),
|
||||
METHOD("queue", python_kore_queue, METH_VARARGS),
|
||||
METHOD("tracer", python_kore_tracer, METH_VARARGS),
|
||||
METHOD("gather", python_kore_gather, METH_VARARGS),
|
||||
METHOD("fatal", python_kore_fatal, METH_VARARGS),
|
||||
METHOD("fatalx", python_kore_fatalx, METH_VARARGS),
|
||||
|
36
src/python.c
36
src/python.c
@ -15,6 +15,7 @@
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
@ -170,6 +171,7 @@ extern const char *__progname;
|
||||
|
||||
/* XXX */
|
||||
static struct python_coro *coro_running = NULL;
|
||||
static PyObject *python_tracer = NULL;
|
||||
|
||||
void
|
||||
kore_python_init(void)
|
||||
@ -286,7 +288,7 @@ void
|
||||
kore_python_log_error(const char *function)
|
||||
{
|
||||
const char *sval;
|
||||
PyObject *repr, *type, *value, *traceback;
|
||||
PyObject *ret, *repr, *type, *value, *traceback;
|
||||
|
||||
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_StopIteration))
|
||||
return;
|
||||
@ -309,6 +311,13 @@ kore_python_log_error(const char *function)
|
||||
*/
|
||||
if (coro_running != NULL && coro_running->gatherop != NULL) {
|
||||
PyErr_SetObject(PyExc_StopIteration, value);
|
||||
} else if (python_tracer != NULL) {
|
||||
/*
|
||||
* Call the user-supplied tracer callback.
|
||||
*/
|
||||
ret = PyObject_CallFunctionObjArgs(python_tracer,
|
||||
type, value, traceback, NULL);
|
||||
Py_XDECREF(ret);
|
||||
} else {
|
||||
if ((repr = PyObject_Repr(value)) == NULL)
|
||||
sval = "unknown";
|
||||
@ -1026,6 +1035,31 @@ python_kore_queue(PyObject *self, PyObject *args)
|
||||
return ((PyObject *)queue);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_kore_tracer(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *obj;
|
||||
|
||||
if (python_tracer != NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "tracer already set");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O", &obj))
|
||||
return (NULL);
|
||||
|
||||
if (!PyCallable_Check(obj)) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "object not callable");
|
||||
Py_DECREF(obj);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
Py_INCREF(obj);
|
||||
python_tracer = obj;
|
||||
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
python_kore_gather(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user