From 2b1f7c50aa946e10053836c0e41657342b401d24 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Wed, 16 Jul 2014 14:51:05 +0200 Subject: [PATCH] Generate new method body by code instead of a simple template in the Python wrapper. --- tools/python/apixml2python/linphone.py | 17 +++++++++++++++++ .../apixml2python/linphone_module.mustache | 5 +---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/python/apixml2python/linphone.py b/tools/python/apixml2python/linphone.py index 904fd820a..8704c0671 100644 --- a/tools/python/apixml2python/linphone.py +++ b/tools/python/apixml2python/linphone.py @@ -211,6 +211,16 @@ class MethodDefinition: self.body += \ """ Py_RETURN_NONE;""" + def format_new_body(self): + self.body += \ +""" pylinphone_{class_name}Object *self = (pylinphone_{class_name}Object *)type->tp_alloc(type, 0); +""".format(class_name=self.class_['class_name']) + self.format_tracing() + self.body += \ +""" self->native_ptr = NULL; + return (PyObject *)self; +""" + def format_new_from_native_pointer_body(self): self.body += \ """ pylinphone_{class_name}Object *self; @@ -430,6 +440,8 @@ class LinphoneModule(object): self.classes.append(c) # Format methods' bodies for c in self.classes: + xml_new_method = c['class_xml_node'].find("./classmethods/classmethod[@name='" + c['class_c_function_prefix'] + "new']") + c['new_body'] = self.__format_new_body(xml_new_method, c) for m in c['class_type_methods']: m['method_body'] = self.__format_method_body(m['method_xml_node'], c) for m in c['class_instance_methods']: @@ -477,6 +489,11 @@ class LinphoneModule(object): method.format_setter_value_checking_and_c_function_call() return method.body + def __format_new_body(self, method_node, class_): + method = MethodDefinition(method_node, class_, self) + method.format_new_body() + return method.body + def __format_new_from_native_pointer_body(self, method_node, class_): method = MethodDefinition(method_node, class_, self) # Force return value type of dealloc function to prevent declaring useless local variables diff --git a/tools/python/apixml2python/linphone_module.mustache b/tools/python/apixml2python/linphone_module.mustache index 9400dab74..85889b4ae 100644 --- a/tools/python/apixml2python/linphone_module.mustache +++ b/tools/python/apixml2python/linphone_module.mustache @@ -110,10 +110,7 @@ static PyObject * pylinphone_{{class_name}}_new_from_native_ptr(PyTypeObject *ty } static PyObject * pylinphone_{{class_name}}_new(PyTypeObject *type, PyObject *args, PyObject *kw) { - pylinphone_{{class_name}}Object *self = (pylinphone_{{class_name}}Object *)type->tp_alloc(type, 0); - pylinphone_debug("[PYLINPHONE] %s", __FUNCTION__); - self->native_ptr = NULL; - return (PyObject *)self; +{{{new_body}}} } static void pylinphone_{{class_name}}_dealloc(PyObject *self) {