#include "../bouncer_headers.h" #include "headers/LinearSketch.h" #include "headers/hashing_alg.h" #include "headers/countmin.h" #include "LinearSketch.c" #include "hashing_alg.c" #include "countmin.c" PyMODINIT_FUNC PyInit_sketches(void); static PyModuleDef sketches_module = { PyModuleDef_HEAD_INIT, .m_name = "sketches", .m_doc = "Non-deterministic approximate counting algorithms for turnstile input streams.", .m_size = -1, }; PyMODINIT_FUNC PyInit_sketches(void) { PyObject *m; if (PyType_Ready(&LinearSketch_type) < 0){ return NULL; } if (PyType_Ready(&CountMin_type) < 0){ return NULL; } m = PyModule_Create(&sketches_module); if (m == NULL){ return NULL; } Py_INCREF(&LinearSketch_type); if (PyModule_AddObject(m, "LinearSketch", (PyObject *) &LinearSketch_type) < 0) { Py_DECREF(&LinearSketch_type); Py_DECREF(m); return NULL; } // Adding two custom errors to class HyperParameterError = PyErr_NewException("HyperParameterError.error", NULL, NULL); Py_XINCREF(HyperParameterError); if (PyModule_AddObject(m, "error", HyperParameterError) < 0) { Py_XDECREF(HyperParameterError); Py_CLEAR(HyperParameterError); Py_DECREF(&LinearSketch_type); Py_DECREF(m); return NULL; } VersionError = PyErr_NewException("VersionError.error", NULL, NULL); Py_XINCREF(VersionError); if (PyModule_AddObject(m, "error", VersionError) < 0) { Py_XDECREF(VersionError); Py_CLEAR(VersionError); Py_DECREF(&LinearSketch_type); Py_DECREF(m); return NULL; } MemoryError = PyErr_NewException("MemoryError.error", NULL, NULL); Py_XINCREF(MemoryError); if (PyModule_AddObject(m, "error", MemoryError) < 0) { Py_XDECREF(MemoryError); Py_CLEAR(MemoryError); Py_DECREF(&LinearSketch_type); Py_DECREF(m); return NULL; } TokenError = PyErr_NewException("TokenError.error", NULL, NULL); Py_XINCREF(TokenError); if (PyModule_AddObject(m, "error", TokenError) < 0) { Py_XDECREF(TokenError); Py_CLEAR(TokenError); Py_DECREF(&LinearSketch_type); Py_DECREF(m); return NULL; } // add on the sub class after adding all dependencies to super class Py_INCREF(&CountMin_type); if (PyModule_AddObject(m, "CountMin", (PyObject *) &CountMin_type) < 0) { Py_DECREF(&CountMin_type); Py_DECREF(m); return NULL; } return m; }