| 
4 | 4 | #include <cstring>  | 
5 | 5 | #include <ostream>  | 
6 | 6 | #include <sstream>  | 
 | 7 | +#include <ff/ff.hpp>  | 
7 | 8 | #include "py_ff_a2a.hpp"  | 
8 | 9 | #include "py_ff_pipeline.hpp"  | 
9 | 10 | #include "py_ff_farm.hpp"  | 
 | 11 | +#include "py_ff_callback.hpp"  | 
 | 12 | +#include "process/ff_monode_process.hpp"  | 
 | 13 | +#include "process/ff_node_process.hpp"  | 
 | 14 | +#include "py_ff_constant.hpp"  | 
10 | 15 | 
 
  | 
11 |  | -// A struct contains the definition of a module  | 
12 |  | -PyModuleDef moduledef = {  | 
13 |  | - PyModuleDef_HEAD_INIT,  | 
14 |  | - "fastflow_module", // Module name  | 
15 |  | - "This is FastFlow's docstring",  | 
16 |  | - -1, // Optional size of the module state memory  | 
17 |  | - NULL, // Optional module methods  | 
18 |  | - NULL, // Optional slot definitions  | 
19 |  | - NULL, // Optional traversal function  | 
20 |  | - NULL, // Optional clear function  | 
21 |  | - NULL // Optional module deallocation function  | 
22 |  | -};  | 
 | 16 | +PyDoc_STRVAR(ff_send_out_to_doc, "Send out to a node");  | 
23 | 17 | 
 
  | 
24 |  | -PyMODINIT_FUNC  | 
25 |  | -PyInit_fastflow_module(void) {  | 
26 |  | - PyObject* module = PyModule_Create(&moduledef);  | 
27 |  | - if (module == NULL)  | 
28 |  | - return NULL;  | 
 | 18 | +PyObject* empty_ff_send_out_to(PyObject *self, PyObject *args) {  | 
 | 19 | + assert(self);  | 
29 | 20 | 
 
  | 
 | 21 | + PyErr_SetString(PyExc_Exception, "Operation not available. This is not a multi output node");  | 
 | 22 | + return NULL;  | 
 | 23 | +}  | 
 | 24 | + | 
 | 25 | +/* initialization function */  | 
 | 26 | +static int  | 
 | 27 | +fastflow_module_exec(PyObject *module)   | 
 | 28 | +{   | 
30 | 29 |  // add FFPipeline  | 
31 | 30 |  if (PyType_Ready(&py_ff_pipeline_type) < 0)  | 
32 |  | - return NULL;  | 
 | 31 | + return -1;  | 
33 | 32 | 
 
  | 
34 | 33 |  if (PyModule_AddObject(module, "FFPipeline", (PyObject *) &py_ff_pipeline_type) < 0) {  | 
35 |  | - Py_DECREF(module);  | 
36 |  | - return NULL;  | 
 | 34 | + return -1;  | 
37 | 35 |  }  | 
38 | 36 | 
 
  | 
39 | 37 |  // add FFFarm  | 
40 | 38 |  PyObject *py_ff_farm = PyType_FromSpec(&spec_py_ff_farm);  | 
41 | 39 |  if (py_ff_farm == NULL){  | 
42 |  | - return NULL;  | 
 | 40 | + return -1;  | 
43 | 41 |  }  | 
44 | 42 |  Py_INCREF(py_ff_farm);  | 
45 | 43 | 
 
  | 
46 |  | - if (PyModule_AddObject(module, "FFFarm", py_ff_farm) < 0){  | 
 | 44 | + if (PyModule_AddObject(module, "FFFarm", py_ff_farm) < 0) {  | 
47 | 45 |  Py_DECREF(py_ff_farm);  | 
48 |  | - Py_DECREF(module);  | 
49 |  | - return NULL;  | 
 | 46 | + return -1;  | 
50 | 47 |  }  | 
51 | 48 | 
 
  | 
52 | 49 |  // add FFAllToAll  | 
53 | 50 |  if (PyType_Ready(&py_ff_a2a_type) < 0)  | 
54 |  | - return NULL;  | 
 | 51 | + return -1;  | 
55 | 52 | 
 
  | 
56 | 53 |  if (PyModule_AddObject(module, "FFAllToAll", (PyObject *) &py_ff_a2a_type) < 0) {  | 
57 |  | - Py_DECREF(module);  | 
58 |  | - return NULL;  | 
 | 54 | + return -1;  | 
 | 55 | + }  | 
 | 56 | + | 
 | 57 | + // add the callback object. Do not AddObject,   | 
 | 58 | + // to avoid the user instantiating it  | 
 | 59 | + if (PyType_Ready(&py_ff_callback_type) < 0) {  | 
 | 60 | + return -1;  | 
 | 61 | + }  | 
 | 62 | + | 
 | 63 | + // add fastflow's constant type. Do not AddObject,   | 
 | 64 | + // to avoid the user instantiating it  | 
 | 65 | + if (PyType_Ready(&py_ff_constant_type) < 0) {  | 
 | 66 | + return -1;  | 
 | 67 | + }  | 
 | 68 | + | 
 | 69 | + if (PyModule_AddObject(module, GO_ON_CONSTANT_NAME, build_py_ff_constant(ff::FF_GO_ON)) < 0) {  | 
 | 70 | + return -1;  | 
59 | 71 |  }  | 
60 |  | - return module;  | 
 | 72 | + | 
 | 73 | + return 0;  | 
 | 74 | +}  | 
 | 75 | + | 
 | 76 | +static PyMethodDef module_methods[] = {  | 
 | 77 | + { "ff_send_out_to", (PyCFunction) empty_ff_send_out_to, METH_VARARGS, ff_send_out_to_doc },  | 
 | 78 | + {NULL, NULL} /* Sentinel */  | 
 | 79 | +};  | 
 | 80 | + | 
 | 81 | +static PyModuleDef_Slot module_slots[] = {  | 
 | 82 | + {Py_mod_exec, (void*) fastflow_module_exec},  | 
 | 83 | +#if PY_MINOR_VERSION >= 12  | 
 | 84 | + {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},  | 
 | 85 | +#endif  | 
 | 86 | + {0, NULL},  | 
 | 87 | +};  | 
 | 88 | + | 
 | 89 | +static struct PyModuleDef moduledef = {  | 
 | 90 | + .m_base = PyModuleDef_HEAD_INIT,  | 
 | 91 | + .m_name = "fastflow_module",  | 
 | 92 | + .m_doc = "This is FastFlow's docstring",  | 
 | 93 | + .m_size = 0,  | 
 | 94 | + .m_methods = module_methods,  | 
 | 95 | + .m_slots = module_slots,  | 
 | 96 | +};  | 
 | 97 | + | 
 | 98 | +PyMODINIT_FUNC  | 
 | 99 | +PyInit_fastflow_module(void) {  | 
 | 100 | + return PyModuleDef_Init(&moduledef);  | 
61 | 101 | }  | 
62 | 102 | 
 
  | 
63 | 103 | // Useful reading  | 
 | 
0 commit comments