Generate new method body by code instead of a simple template in the Python wrapper.

This commit is contained in:
Ghislain MARY 2014-07-16 14:51:05 +02:00
parent c3024aa772
commit 2b1f7c50aa
2 changed files with 18 additions and 4 deletions

View file

@ -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

View file

@ -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) {