diff --git a/builder.py b/builder.py index 8e48151..6158a50 100644 --- a/builder.py +++ b/builder.py @@ -13,6 +13,7 @@ #include #include #include + #include #include """, include_dirs=incdirs, @@ -158,6 +159,11 @@ """ ) +# Noop API +ffibuilder.cdef(""" + int vaccel_noop(struct vaccel_session *sess); + """ +) if __name__ == "__main__": ffibuilder.compile(verbose=True) diff --git a/vaccel/_vaccel.c b/vaccel/_vaccel.c index facbae7..8ebb4dc 100644 --- a/vaccel/_vaccel.c +++ b/vaccel/_vaccel.c @@ -570,6 +570,7 @@ static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *); #include #include #include + #include #include @@ -983,6 +984,44 @@ _cffi_f_unregister_plugin(PyObject *self, PyObject *arg0) # define _cffi_f_unregister_plugin _cffi_d_unregister_plugin #endif +static int _cffi_d_vaccel_noop(struct vaccel_session * x0) +{ + return vaccel_noop(x0); +} +#ifndef PYPY_VERSION +static PyObject * +_cffi_f_vaccel_noop(PyObject *self, PyObject *arg0) +{ + struct vaccel_session * x0; + Py_ssize_t datasize; + struct _cffi_freeme_s *large_args_free = NULL; + int result; + PyObject *pyresult; + + datasize = _cffi_prepare_pointer_call_argument( + _cffi_type(11), arg0, (char **)&x0); + if (datasize != 0) { + x0 = ((size_t)datasize) <= 640 ? (struct vaccel_session *)alloca((size_t)datasize) : NULL; + if (_cffi_convert_array_argument(_cffi_type(11), arg0, (char **)&x0, + datasize, &large_args_free) < 0) + return NULL; + } + + Py_BEGIN_ALLOW_THREADS + _cffi_restore_errno(); + { result = vaccel_noop(x0); } + _cffi_save_errno(); + Py_END_ALLOW_THREADS + + (void)self; /* unused */ + pyresult = _cffi_from_c_int(result, int); + if (large_args_free != NULL) _cffi_free_array_arguments(large_args_free); + return pyresult; +} +#else +# define _cffi_f_vaccel_noop _cffi_d_vaccel_noop +#endif + static int _cffi_d_vaccel_sess_free(struct vaccel_session * x0) { return vaccel_sess_free(x0); @@ -1717,6 +1756,7 @@ static const struct _cffi_global_s _cffi_globals[] = { { "register_plugin_function", (void *)_cffi_f_register_plugin_function, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 0), (void *)_cffi_d_register_plugin_function }, { "register_plugin_functions", (void *)_cffi_f_register_plugin_functions, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 3), (void *)_cffi_d_register_plugin_functions }, { "unregister_plugin", (void *)_cffi_f_unregister_plugin, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 7), (void *)_cffi_d_unregister_plugin }, + { "vaccel_noop", (void *)_cffi_f_vaccel_noop, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 10), (void *)_cffi_d_vaccel_noop }, { "vaccel_sess_free", (void *)_cffi_f_vaccel_sess_free, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 10), (void *)_cffi_d_vaccel_sess_free }, { "vaccel_sess_has_resource", (void *)_cffi_f_vaccel_sess_has_resource, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 13), (void *)_cffi_d_vaccel_sess_has_resource }, { "vaccel_sess_init", (void *)_cffi_f_vaccel_sess_init, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 34), (void *)_cffi_d_vaccel_sess_init }, @@ -1811,7 +1851,7 @@ static const struct _cffi_type_context_s _cffi_type_context = { _cffi_struct_unions, _cffi_enums, _cffi_typenames, - 39, /* num_globals */ + 40, /* num_globals */ 10, /* num_struct_unions */ 1, /* num_enums */ 1, /* num_typenames */ diff --git a/vaccel/noop.py b/vaccel/noop.py new file mode 100644 index 0000000..07f9b7c --- /dev/null +++ b/vaccel/noop.py @@ -0,0 +1,19 @@ +from vaccel._vaccel import lib, ffi +from vaccel.error import VaccelError + +from vaccel.session import Session + +class Noop: + def __init__(self): + """exec vAccel Noop""" + printf("test init") + + def __del__(self): + printf("test del") + + @classmethod + def noop(self, session): + """exec the operation""" + csession = session._to_inner() + return lib.vaccel_noop(csession) + diff --git a/vaccel/test.py b/vaccel/test.py index f30fae4..0daeade 100644 --- a/vaccel/test.py +++ b/vaccel/test.py @@ -1 +1,11 @@ import vaccel + +from vaccel.session import Session +from vaccel.noop import Noop + +a = Session(flags=0) +b = Session(flags=1) + +print(a.id(), b.id()) + +c = Noop.noop(a)