def generate(functions): f = open(paths.OUTPUT_CALLBACK_C_BINDINGS, "w") c = CCodeWriter(f) # write out the header first c.write(""" // DO NOT EDIT, AUTOGENERATED FILE #include <Python.h> #include "ts3_module.h" void callEventHandler(const char * methodName, PyObject *kwargs){ PyObject * clientEventHandlerIterator = getClientEventHandlerIterator(); if(!PyIter_Check(clientEventHandlerIterator)){ printf("clientEventHandlerIterator is not iterable\\n"); return; } PyObject * item; while ((item = PyIter_Next(clientEventHandlerIterator)) != NULL) { PyObject * method = PyObject_GetAttrString(item, methodName); if(!PyCallable_Check(method)){ printf("ClientEventHandler's method %s is not callable\\n", methodName); } else { PyObject * tuple = PyTuple_New(0); PyObject * value = PyObject_Call(method, tuple, kwargs); if(!value){ printf("Method call failed in %s\\n", methodName); if(PyErr_Occurred()){ PyErr_Print(); } } Py_XDECREF(value); Py_XDECREF(tuple); } Py_XDECREF(method); Py_XDECREF(item); } Py_XDECREF(clientEventHandlerIterator); } """) for function in functions: generator = CCallbackBindingsGenerator(function) generator.get_definition(c) f.close();
def generate(functions): f = open(paths.OUTPUT_TS3_FUNCTIONS, "w") w = CCodeWriter(f) w.write(""" // DO NOT EDIT, AUTO GENERATED FILE #include "ts3_functions_interface.h" #include "public_errors.h" #include "python_setup.h" #define TS3_STRING_BUFFER_LEN 256 """) for function in functions: gen = TS3FunctionGenerator(function) if gen.should_ignore(): continue gen.print_function(w) w.write(""" static PyMethodDef TS3FunctionsMethods[] = {""") for function in functions: gen = TS3FunctionGenerator(function) if gen.should_ignore(): continue gen.get_module_definition(w) w.write(""" {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC init_ts3functions(){ PyObject *m; m = Py_InitModule("TS3Functions", TS3FunctionsMethods); if (m == NULL){ printf("Failed to initialize TS3Functions\\n"); return; } } """) f.close()