#include "../bouncer_headers.h" #include "headers/morris_counter.h" #include "morris_counter.c" PyMODINIT_FUNC PyInit_counters(void); static PyModuleDef counters_module = { PyModuleDef_HEAD_INIT, .m_name = "counters", .m_doc = "Non-deterministic approximate counting algorithms for vanilla input streams.", .m_size = -1, }; PyMODINIT_FUNC PyInit_counters(void) { PyObject *m; if (PyType_Ready(&Morris_type) < 0){ return NULL; } m = PyModule_Create(&counters_module); if (m == NULL){ return NULL; } Py_INCREF(&Morris_type); if (PyModule_AddObject(m, "Morris", (PyObject *) &Morris_type) < 0) { Py_DECREF(&Morris_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(&Morris_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(&Morris_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(&Morris_type); Py_DECREF(m); return NULL; } return m; }