|
| 1 | +#define PY_SSIZE_T_CLEAN |
| 2 | +#include <Python.h> |
| 3 | + |
| 4 | +#include "hopper/hopper.h" |
| 5 | + |
| 6 | +// clang-format off |
| 7 | +struct _hopper_pipe { |
| 8 | + PyObject_HEAD |
| 9 | + PyObject *name; |
| 10 | + PyObject *endpoint; |
| 11 | + PyObject *hopper; |
| 12 | + int fd; |
| 13 | + int flags; |
| 14 | +}; |
| 15 | + |
| 16 | +static PyTypeObject _py_hopper_pipe = { |
| 17 | + .ob_base = PyVarObject_HEAD_INIT(NULL, 0) |
| 18 | + .tp_name = "hopper.HopperPipe", |
| 19 | + .tp_doc = PyDoc_STR("A object representing a Hopper pipe"), |
| 20 | + .tp_basicsize = sizeof(struct _hopper_pipe), |
| 21 | + .tp_itemsize = 0, |
| 22 | + .tp_flags = Py_TPFLAGS_DEFAULT, |
| 23 | + .tp_new = PyType_GenericNew, |
| 24 | +}; |
| 25 | +// clang-format on |
| 26 | + |
| 27 | +static PyObject *hopper_open_pipe(PyObject *self, PyObject *args) {} |
| 28 | +static PyObject *hopper_close_pipe(PyObject *self, PyObject *args) {} |
| 29 | +static PyObject *hopper_read_pipe(PyObject *self, PyObject *args) {} |
| 30 | +static PyObject *hopper_write_pipe(PyObject *self, PyObject *args) {} |
| 31 | + |
| 32 | +static int hopper_module_exec(PyObject *m) { |
| 33 | + if (PyType_Ready(&_py_hopper_pipe) < 0) |
| 34 | + return -1; |
| 35 | + |
| 36 | + if (PyModule_AddObjectRef(m, "HopperPipe", (PyObject *)&_py_hopper_pipe) < |
| 37 | + 0) |
| 38 | + return -1; |
| 39 | + |
| 40 | + return 0; |
| 41 | +} |
| 42 | + |
| 43 | +static PyMethodDef hopper_methods[] = { |
| 44 | + {"open", hopper_open_pipe, METH_VARARGS, ""}, |
| 45 | + {"close", hopper_close_pipe, METH_VARARGS, ""}, |
| 46 | + {"read", hopper_read_pipe, METH_VARARGS, ""}, |
| 47 | + {"write", hopper_write_pipe, METH_VARARGS, ""}, |
| 48 | + {NULL, NULL, 0, NULL}, |
| 49 | +}; |
| 50 | + |
| 51 | +static PyModuleDef_Slot hopper_slots[] = { |
| 52 | + {Py_mod_exec, (void *)hopper_module_exec}, |
| 53 | + {Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED}, |
| 54 | + {0, NULL}, |
| 55 | +}; |
| 56 | + |
| 57 | +static struct PyModuleDef hoppermodule = { |
| 58 | + .m_base = PyModuleDef_HEAD_INIT, |
| 59 | + .m_name = "hopper", |
| 60 | + .m_doc = NULL, |
| 61 | + .m_methods = hopper_methods, |
| 62 | + .m_slots = hopper_slots, |
| 63 | +}; |
| 64 | + |
| 65 | +PyMODINIT_FUNC PyInit_hopper(void) { return PyModuleDef_Init(&hoppermodule); } |
| 66 | + |
0 commit comments