Commit d9932c3e authored by Ghislain MARY's avatar Ghislain MARY

Support build of Python module for Python 3.

parent 74a32770
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
import argparse import argparse
import os import os
import six
import string import string
import sys import sys
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
...@@ -399,7 +400,7 @@ class Project: ...@@ -399,7 +400,7 @@ class Project:
def __parseCStructMember(self, node, structname): def __parseCStructMember(self, node, structname):
name = node.find('./name').text name = node.find('./name').text
definition = node.find('./definition').text definition = node.find('./definition').text
t = definition[0:string.find(definition, structname + "::" + name)] t = definition[0:definition.find(structname + "::" + name)]
sm = CStructMember(name, t) sm = CStructMember(name, t)
deprecatedNode = node.find(".//xrefsect[xreftitle='Deprecated']") deprecatedNode = node.find(".//xrefsect[xreftitle='Deprecated']")
if deprecatedNode is not None: if deprecatedNode is not None:
...@@ -433,7 +434,7 @@ class Project: ...@@ -433,7 +434,7 @@ class Project:
if definition.startswith('typedef '): if definition.startswith('typedef '):
definition = definition[8 :] definition = definition[8 :]
if name.endswith('Cb'): if name.endswith('Cb'):
pos = string.find(definition, "(*") pos = definition.find("(*")
if pos == -1: if pos == -1:
return None return None
returntype = definition[0:pos].strip() returntype = definition[0:pos].strip()
...@@ -448,13 +449,13 @@ class Project: ...@@ -448,13 +449,13 @@ class Project:
elif returnarg.completeType != 'void': elif returnarg.completeType != 'void':
missingDocWarning += "\tReturn value is not documented\n" missingDocWarning += "\tReturn value is not documented\n"
definition = definition[pos + 2 :] definition = definition[pos + 2 :]
pos = string.find(definition, "(") pos = definition.find("(")
definition = definition[pos + 1 : -1] definition = definition[pos + 1 : -1]
argslist = CArgumentsList() argslist = CArgumentsList()
for argdef in definition.split(', '): for argdef in definition.split(', '):
argType = '' argType = ''
starPos = string.rfind(argdef, '*') starPos = argdef.rfind('*')
spacePos = string.rfind(argdef, ' ') spacePos = argdef.rfind(' ')
if starPos != -1: if starPos != -1:
argType = argdef[0 : starPos + 1] argType = argdef[0 : starPos + 1]
argName = argdef[starPos + 1 :] argName = argdef[starPos + 1 :]
...@@ -483,7 +484,7 @@ class Project: ...@@ -483,7 +484,7 @@ class Project:
f.detailedDescription = self.__cleanDescription(node.find('./detaileddescription')) f.detailedDescription = self.__cleanDescription(node.find('./detaileddescription'))
return f return f
else: else:
pos = string.rfind(definition, " " + name) pos = definition.rfind(" " + name)
if pos != -1: if pos != -1:
definition = definition[0 : pos] definition = definition[0 : pos]
td = CTypedef(name, definition) td = CTypedef(name, definition)
...@@ -595,7 +596,7 @@ class Project: ...@@ -595,7 +596,7 @@ class Project:
def check(self): def check(self):
for c in self.classes: for c in self.classes:
for name, p in c.properties.iteritems(): for name, p in six.iteritems(c.properties):
if p.getter is None and p.setter is not None: if p.getter is None and p.setter is not None:
print("Property '" + name + "' of class '" + c.name + "' has a setter but no getter") print("Property '" + name + "' of class '" + c.name + "' has a setter but no getter")
...@@ -734,7 +735,7 @@ class Generator: ...@@ -734,7 +735,7 @@ class Generator:
project.classes.sort(key = lambda c: c.name) project.classes.sort(key = lambda c: c.name)
for cclass in project.classes: for cclass in project.classes:
self.__generateClass(cclass, classesNode) self.__generateClass(cclass, classesNode)
s = '<?xml version="1.0" encoding="UTF-8" ?>\n' s = '<?xml version="1.0" encoding="UTF-8" ?>\n'.encode('utf-8')
s += ET.tostring(apiNode, 'utf-8') s += ET.tostring(apiNode, 'utf-8')
if project.prettyPrint: if project.prettyPrint:
s = minidom.parseString(s).toprettyxml(indent='\t') s = minidom.parseString(s).toprettyxml(indent='\t')
......
...@@ -25,6 +25,7 @@ typedef struct { ...@@ -25,6 +25,7 @@ typedef struct {
LCSipTransports lcst; LCSipTransports lcst;
} pylinphone_SipTransportsObject; } pylinphone_SipTransportsObject;
static bctbx_list_t * pylinphone_bctbx_list_free(bctbx_list_t * elem);
PyObject * PyList_FromBctbxListOfString(const bctbx_list_t *msl); PyObject * PyList_FromBctbxListOfString(const bctbx_list_t *msl);
bctbx_list_t * PyList_AsBctbxListOfString(PyObject *pyl); bctbx_list_t * PyList_AsBctbxListOfString(PyObject *pyl);
......
static bctbx_list_t * pylinphone_bctbx_list_free(bctbx_list_t * elem) {
return bctbx_list_free_with_data(elem, bctbx_free);
}
PyObject * PyList_FromBctbxListOfString(const bctbx_list_t *msl) { PyObject * PyList_FromBctbxListOfString(const bctbx_list_t *msl) {
PyObject *pyl = PyList_New(0); PyObject *pyl = PyList_New(0);
while (msl != NULL) { while (msl != NULL) {
...@@ -15,6 +19,7 @@ bctbx_list_t * PyList_AsBctbxListOfString(PyObject *pyl) { ...@@ -15,6 +19,7 @@ bctbx_list_t * PyList_AsBctbxListOfString(PyObject *pyl) {
for (idx = 0; idx < size; idx++) { for (idx = 0; idx < size; idx++) {
PyObject *item = PyList_GetItem(pyl, idx); PyObject *item = PyList_GetItem(pyl, idx);
char *citem = (char *)PyString_AsString(item); char *citem = (char *)PyString_AsString(item);
if (citem != NULL) citem = bctbx_strdup_printf(citem);
msl = bctbx_list_append(msl, citem); msl = bctbx_list_append(msl, citem);
} }
return msl; return msl;
...@@ -562,8 +567,7 @@ static PyMemberDef pylinphone_VideoSize_members[] = { ...@@ -562,8 +567,7 @@ static PyMemberDef pylinphone_VideoSize_members[] = {
}; };
static PyTypeObject pylinphone_VideoSizeType = { static PyTypeObject pylinphone_VideoSizeType = {
PyObject_HEAD_INIT(NULL) PyVarObject_HEAD_INIT(NULL, 0)
0, /* ob_size */
"linphone.VideoSize", /* tp_name */ "linphone.VideoSize", /* tp_name */
sizeof(pylinphone_VideoSizeObject), /* tp_basicsize */ sizeof(pylinphone_VideoSizeObject), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
...@@ -680,8 +684,7 @@ static PyMemberDef pylinphone_SipTransports_members[] = { ...@@ -680,8 +684,7 @@ static PyMemberDef pylinphone_SipTransports_members[] = {
}; };
static PyTypeObject pylinphone_SipTransportsType = { static PyTypeObject pylinphone_SipTransportsType = {
PyObject_HEAD_INIT(NULL) PyVarObject_HEAD_INIT(NULL, 0)
0, /* ob_size */
"linphone.SipTransports", /* tp_name */ "linphone.SipTransports", /* tp_name */
sizeof(pylinphone_SipTransportsObject), /* tp_basicsize */ sizeof(pylinphone_SipTransportsObject), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import re import re
from sets import Set import six
import sys import sys
...@@ -35,7 +35,9 @@ def remove_useless_enum_prefix(senum, svalue): ...@@ -35,7 +35,9 @@ def remove_useless_enum_prefix(senum, svalue):
i = 0 i = 0
while i < len(lenum) and lenum[i] == lvalue[i]: while i < len(lenum) and lenum[i] == lvalue[i]:
i += 1 i += 1
return ''.join(lvalue[i:]) svalue = ''.join(lvalue[i:])
if svalue == "None":
return "_None"
return svalue return svalue
def is_callback(s): def is_callback(s):
...@@ -238,7 +240,7 @@ class ArgumentType: ...@@ -238,7 +240,7 @@ class ArgumentType:
self.convert_code = "{result_name}{result_suffix} = {cast}PyList_AsBctbxListOf" + self.contained_type + "({arg_name});\n" self.convert_code = "{result_name}{result_suffix} = {cast}PyList_AsBctbxListOf" + self.contained_type + "({arg_name});\n"
self.convert_from_func = 'PyList_FromBctbxListOf' + self.contained_type self.convert_from_func = 'PyList_FromBctbxListOf' + self.contained_type
if not is_const_from_complete_type(self.complete_type): if not is_const_from_complete_type(self.complete_type):
self.free_convert_result_func = "bctbx_list_free" self.free_convert_result_func = "pylinphone_bctbx_list_free"
self.check_condition = "!PyList_Check({arg_name})" self.check_condition = "!PyList_Check({arg_name})"
self.fmt_str = 'O' self.fmt_str = 'O'
self.cfmt_str = '%p' self.cfmt_str = '%p'
...@@ -1043,7 +1045,7 @@ class LinphoneModule(object): ...@@ -1043,7 +1045,7 @@ class LinphoneModule(object):
self.known_types = ['char', 'int', 'int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'bool_t', 'float', 'double', 'size_t', 'time_t', 'MSList', 'bctbx_list_t', 'MSVideoSize', 'LCSipTransports', 'PayloadType'] self.known_types = ['char', 'int', 'int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'bool_t', 'float', 'double', 'size_t', 'time_t', 'MSList', 'bctbx_list_t', 'MSVideoSize', 'LCSipTransports', 'PayloadType']
self.internal_instance_method_names = ['destroy', 'ref', 'unref'] self.internal_instance_method_names = ['destroy', 'ref', 'unref']
self.internal_property_names = ['user_data'] self.internal_property_names = ['user_data']
self.bctbxlist_types = Set([]) self.bctbxlist_types = set([])
self.enums = [] self.enums = []
self.enum_names = [] self.enum_names = []
self.cfunction2methodmap = {} self.cfunction2methodmap = {}
...@@ -1084,6 +1086,7 @@ class LinphoneModule(object): ...@@ -1084,6 +1086,7 @@ class LinphoneModule(object):
v['enum_value_doc'] = self.__format_doc(xml_enum_value.find('briefdescription'), xml_enum_value.find('detaileddescription')) v['enum_value_doc'] = self.__format_doc(xml_enum_value.find('briefdescription'), xml_enum_value.find('detaileddescription'))
e['enum_deprecated_values'].append(v) e['enum_deprecated_values'].append(v)
e['enum_doc'] = self.__replace_doc_special_chars(e['enum_doc']) e['enum_doc'] = self.__replace_doc_special_chars(e['enum_doc'])
e['enum_doc'] = e['enum_doc'].encode('unicode_escape')
self.enums.append(e) self.enums.append(e)
self.enum_names.append(e['enum_name']) self.enum_names.append(e['enum_name'])
self.known_types.append(e['enum_cname']) self.known_types.append(e['enum_cname'])
...@@ -1099,6 +1102,7 @@ class LinphoneModule(object): ...@@ -1099,6 +1102,7 @@ class LinphoneModule(object):
c['class_name'] = strip_leading_linphone(c['class_cname']) c['class_name'] = strip_leading_linphone(c['class_cname'])
c['class_c_function_prefix'] = xml_class.get('cfunctionprefix') c['class_c_function_prefix'] = xml_class.get('cfunctionprefix')
c['class_doc'] = self.__format_doc(xml_class.find('briefdescription'), xml_class.find('detaileddescription')) c['class_doc'] = self.__format_doc(xml_class.find('briefdescription'), xml_class.find('detaileddescription'))
c['class_doc'] = c['class_doc'].encode('unicode_escape')
c['class_refcountable'] = (xml_class.get('refcountable') == 'true') c['class_refcountable'] = (xml_class.get('refcountable') == 'true')
c['class_destroyable'] = (xml_class.get('destroyable') == 'true') c['class_destroyable'] = (xml_class.get('destroyable') == 'true')
c['class_has_user_data'] = False c['class_has_user_data'] = False
...@@ -1119,6 +1123,7 @@ class LinphoneModule(object): ...@@ -1119,6 +1123,7 @@ class LinphoneModule(object):
ev['event_cname'] = xml_event.get('name') ev['event_cname'] = xml_event.get('name')
ev['event_name'] = compute_event_name(ev['event_cname'], c['class_name']) ev['event_name'] = compute_event_name(ev['event_cname'], c['class_name'])
ev['event_doc'] = self.__format_doc(xml_event.find('briefdescription'), xml_event.find('detaileddescription')) ev['event_doc'] = self.__format_doc(xml_event.find('briefdescription'), xml_event.find('detaileddescription'))
ev['event_doc'] = ev['event_doc'].encode('unicode_escape')
c['class_events'].append(ev) c['class_events'].append(ev)
self.known_types.append(ev['event_cname']) self.known_types.append(ev['event_cname'])
c['class_object_members'].append(ev['event_name']) c['class_object_members'].append(ev['event_name'])
...@@ -1129,11 +1134,13 @@ class LinphoneModule(object): ...@@ -1129,11 +1134,13 @@ class LinphoneModule(object):
m = {} m = {}
m['method_name'] = hand_written_code.name m['method_name'] = hand_written_code.name
m['method_doc'] = self.__replace_doc_special_chars(hand_written_code.doc) m['method_doc'] = self.__replace_doc_special_chars(hand_written_code.doc)
m['method_doc'] = m['method_doc'].encode('unicode_escape')
c['class_type_hand_written_methods'].append(m) c['class_type_hand_written_methods'].append(m)
elif isinstance(hand_written_code, HandWrittenInstanceMethod): elif isinstance(hand_written_code, HandWrittenInstanceMethod):
m = {} m = {}
m['method_name'] = hand_written_code.name m['method_name'] = hand_written_code.name
m['method_doc'] = self.__replace_doc_special_chars(hand_written_code.doc) m['method_doc'] = self.__replace_doc_special_chars(hand_written_code.doc)
m['method_doc'] = m['method_doc'].encode('unicode_escape')
c['class_instance_hand_written_methods'].append(m) c['class_instance_hand_written_methods'].append(m)
elif isinstance(hand_written_code, HandWrittenDeallocMethod): elif isinstance(hand_written_code, HandWrittenDeallocMethod):
c['class_has_hand_written_dealloc'] = True c['class_has_hand_written_dealloc'] = True
...@@ -1149,6 +1156,7 @@ class LinphoneModule(object): ...@@ -1149,6 +1156,7 @@ class LinphoneModule(object):
else: else:
p['setter_reference'] = '(setter)pylinphone_' + c['class_name'] + '_set_' + p['property_name'] p['setter_reference'] = '(setter)pylinphone_' + c['class_name'] + '_set_' + p['property_name']
p['property_doc'] = self.__replace_doc_special_chars(hand_written_code.doc) p['property_doc'] = self.__replace_doc_special_chars(hand_written_code.doc)
p['property_doc'] = p['property_doc'].encode('unicode_escape')
c['class_hand_written_properties'].append(p) c['class_hand_written_properties'].append(p)
xml_type_methods = xml_class.findall("./classmethods/classmethod") xml_type_methods = xml_class.findall("./classmethods/classmethod")
for xml_type_method in xml_type_methods: for xml_type_method in xml_type_methods:
...@@ -1225,71 +1233,74 @@ class LinphoneModule(object): ...@@ -1225,71 +1233,74 @@ class LinphoneModule(object):
xml_new_method = c['class_xml_node'].find("./classmethods/classmethod[@name='" + c['class_c_function_prefix'] + "new']") xml_new_method = c['class_xml_node'].find("./classmethods/classmethod[@name='" + c['class_c_function_prefix'] + "new']")
try: try:
c['new_body'] = NewMethodDefinition(self, c, xml_new_method).format() c['new_body'] = NewMethodDefinition(self, c, xml_new_method).format()
except UnknownTypeException, e: except (UnknownTypeException) as e:
print(e) print(e)
c['blacklisted'] = True c['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], 'new_body') e.args += (c['class_name'], 'new_body')
raise raise
try: try:
c['init_body'] = InitMethodDefinition(self, c, xml_new_method).format() c['init_body'] = InitMethodDefinition(self, c, xml_new_method).format()
except UnknownTypeException, e: except (UnknownTypeException) as e:
print(e) print(e)
c['blacklisted'] = True c['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], 'init_body') e.args += (c['class_name'], 'init_body')
raise raise
try: try:
c['from_native_pointer_body'] = FromNativePointerMethodDefinition(self, c).format() c['from_native_pointer_body'] = FromNativePointerMethodDefinition(self, c).format()
except UnknownTypeException, e: except (UnknownTypeException) as e:
print(e) print(e)
c['blacklisted'] = True c['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], 'from_native_pointer_body') e.args += (c['class_name'], 'from_native_pointer_body')
raise raise
for m in c['class_type_methods']: for m in c['class_type_methods']:
try: try:
m['method_body'] = MethodDefinition(self, c, m['method_name'], m['method_xml_node']).format() m['method_body'] = MethodDefinition(self, c, m['method_name'], m['method_xml_node']).format()
m['method_doc'] = self.__format_method_doc(m['method_xml_node']) m['method_doc'] = self.__format_method_doc(m['method_xml_node'])
except UnknownTypeException, e: m['method_doc'] = m['method_doc'].encode('unicode_escape')
except (UnknownTypeException) as e:
print(e) print(e)
m['blacklisted'] = True m['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], m['method_name']) e.args += (c['class_name'], m['method_name'])
raise raise
for m in c['class_instance_methods']: for m in c['class_instance_methods']:
try: try:
m['method_body'] = MethodDefinition(self, c, m['method_name'], m['method_xml_node']).format() m['method_body'] = MethodDefinition(self, c, m['method_name'], m['method_xml_node']).format()
m['method_doc'] = self.__format_method_doc(m['method_xml_node']) m['method_doc'] = self.__format_method_doc(m['method_xml_node'])
except UnknownTypeException, e: m['method_doc'] = m['method_doc'].encode('unicode_escape')
except (UnknownTypeException) as e:
print(e) print(e)
m['blacklisted'] = True m['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], m['method_name']) e.args += (c['class_name'], m['method_name'])
raise raise
for p in c['class_properties']: for p in c['class_properties']:
p['property_doc'] = '' p['property_doc'] = ''
if p.has_key('setter_xml_node'): if 'setter_xml_node' in p:
try: try:
p['setter_body'] = SetterMethodDefinition(self, c, p['property_name'], p['setter_xml_node']).format() p['setter_body'] = SetterMethodDefinition(self, c, p['property_name'], p['setter_xml_node']).format()
p['property_doc'] = self.__format_setter_doc(p['setter_xml_node']) p['property_doc'] = self.__format_setter_doc(p['setter_xml_node'])
except UnknownTypeException, e: except (UnknownTypeException) as e:
print(e) print(e)
p['blacklisted'] = True p['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], p['property_name']) e.args += (c['class_name'], p['property_name'])
raise raise
if p.has_key('getter_xml_node'): if 'getter_xml_node' in p:
try: try:
p['getter_body'] = GetterMethodDefinition(self, c, p['property_name'], p['getter_xml_node']).format() p['getter_body'] = GetterMethodDefinition(self, c, p['property_name'], p['getter_xml_node']).format()
if p['property_doc'] == '': if p['property_doc'] == '':
p['property_doc'] = self.__format_getter_doc(p['getter_xml_node']) p['property_doc'] = self.__format_getter_doc(p['getter_xml_node'])
except UnknownTypeException, e: except (UnknownTypeException) as e:
print(e) print(e)
p['blacklisted'] = True p['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], p['property_name']) e.args += (c['class_name'], p['property_name'])
raise raise
p['property_doc'] = p['property_doc'].encode('unicode_escape')
if not 'class_has_hand_written_dealloc' in c: if not 'class_has_hand_written_dealloc' in c:
try: try:
if c['class_refcountable']: if c['class_refcountable']:
...@@ -1300,18 +1311,18 @@ class LinphoneModule(object): ...@@ -1300,18 +1311,18 @@ class LinphoneModule(object):
c['dealloc_definition'] = DeallocMethodDefinition(self, c, xml_instance_method).format() c['dealloc_definition'] = DeallocMethodDefinition(self, c, xml_instance_method).format()
else: else:
c['dealloc_definition'] = DeallocMethodDefinition(self, c).format() c['dealloc_definition'] = DeallocMethodDefinition(self, c).format()
except UnknownTypeException, e: except (UnknownTypeException) as e:
print(e) print(e)
c['blacklisted'] = True c['blacklisted'] = True
except Exception, e: except (Exception) as e:
e.args += (c['class_name'], 'dealloc_body') e.args += (c['class_name'], 'dealloc_body')
raise raise
# Remove blacklisted classes and methods # Remove blacklisted classes and methods
self.classes = [c for c in self.classes if not c.has_key('blacklisted')] self.classes = [c for c in self.classes if not 'blacklisted' in c]
for c in self.classes: for c in self.classes:
c['class_type_methods'] = [m for m in c['class_type_methods'] if not m.has_key('blacklisted')] c['class_type_methods'] = [m for m in c['class_type_methods'] if not 'blacklisted' in m]
c['class_instance_methods'] = [m for m in c['class_instance_methods'] if not m.has_key('blacklisted')] c['class_instance_methods'] = [m for m in c['class_instance_methods'] if not 'blacklisted' in m]
c['class_properties'] = [m for m in c['class_properties'] if not m.has_key('blacklisted')] c['class_properties'] = [m for m in c['class_properties'] if not 'blacklisted' in m]
# Convert bctbxlist_types to a list of dictionaries for the template # Convert bctbxlist_types to a list of dictionaries for the template
d = [] d = []
for bctbxlist_type in self.bctbxlist_types: for bctbxlist_type in self.bctbxlist_types:
...@@ -1365,12 +1376,12 @@ class LinphoneModule(object): ...@@ -1365,12 +1376,12 @@ class LinphoneModule(object):
return doc return doc
def __replace_doc_special_chars(self, doc): def __replace_doc_special_chars(self, doc):
return doc.replace('"', '').encode('string-escape') return doc.replace('"', '') #.encode('utf-8') #.encode('unicode_escape')
def __replace_doc_cfunction_by_method(self, doc): def __replace_doc_cfunction_by_method(self, doc):
for cfunction, method in self.cfunction2methodmap.iteritems(): for cfunction, method in six.iteritems(self.cfunction2methodmap):
doc = doc.replace(cfunction + '()', method) doc = doc.replace(cfunction + '()', method)
for cfunction, method in self.cfunction2methodmap.iteritems(): for cfunction, method in six.iteritems(self.cfunction2methodmap):
doc = doc.replace(cfunction, method) doc = doc.replace(cfunction, method)
return doc return doc
......
...@@ -38,6 +38,57 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ...@@ -38,6 +38,57 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define PYLINPHONE_INLINE inline #define PYLINPHONE_INLINE inline
#endif #endif
/**
* Definitions for Python 2 and 3 support.
*/
#ifndef PyVarObject_HEAD_INIT
#define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
#endif
#ifndef PyInt_Check
#define PyInt_Check(p) PyLong_Check(p)
#endif
#ifndef PyInt_AsLong
#define PyInt_AsLong(io) PyLong_AsLong(io)
#endif
#ifndef PyInt_AS_LONG
static int pylinphone_aslongoverflow;
#define PyInt_AS_LONG(io) PyLong_AsLongAndOverflow(io, &pylinphone_aslongoverflow)
#endif
#ifndef PyInt_AsSsize_t
#define PyInt_AsSsize_t(io) PyLong_AsSsize_t(io)
#endif
#ifndef PyInt_AsUnsignedLongMask
#define PyInt_AsUnsignedLongMask(io) PyLong_AsUnsignedLongMask(io)
#endif
#ifndef PyString_Check
#define PyString_Check(io) PyUnicode_Check(io)
#endif
#ifndef PyString_FromString
#define PyString_FromString(v) PyUnicode_FromString(v)
#endif
#if PY_MAJOR_VERSION >= 3
#define PyString_AsString(s) PyUnicode_AsUTF8(s)
#endif
#if PY_MAJOR_VERSION >= 3
#define MOD_DEF(ob, name, methods, doc) \
static struct PyModuleDef moduledef_##ob = { \
PyModuleDef_HEAD_INIT, name, doc, -1, methods, }; \
ob = PyModule_Create(&moduledef_##ob);
#else
#define MOD_DEF(ob, name, methods, doc) \
ob = Py_InitModule3(name, methods, doc);
#endif
static void pylinphone_dispatch_messages(void); static void pylinphone_dispatch_messages(void);
static PYLINPHONE_INLINE void pylinphone_trace(int indent, const char *fmt, ...); static PYLINPHONE_INLINE void pylinphone_trace(int indent, const char *fmt, ...);
...@@ -193,8 +244,7 @@ static PyGetSetDef pylinphone_{{class_name}}_getseters[] = { ...@@ -193,8 +244,7 @@ static PyGetSetDef pylinphone_{{class_name}}_getseters[] = {
}; };
static PyTypeObject pylinphone_{{class_name}}Type = { static PyTypeObject pylinphone_{{class_name}}Type = {
PyObject_HEAD_INIT(NULL) PyVarObject_HEAD_INIT(NULL, 0)
0, /* ob_size */
"linphone.{{class_name}}", /* tp_name */ "linphone.{{class_name}}", /* tp_name */
sizeof(pylinphone_{{class_name}}Object), /* tp_basicsize */ sizeof(pylinphone_{{class_name}}Object), /* tp_basicsize */
0, /* tp_itemsize */ 0, /* tp_itemsize */
...@@ -280,54 +330,57 @@ static PyMethodDef pylinphone_{{enum_name}}_ModuleMethods[] = { ...@@ -280,54 +330,57 @@ static PyMethodDef pylinphone_{{enum_name}}_ModuleMethods[] = {
{{> linphone_testing_module}} {{> linphone_testing_module}}
PyMODINIT_FUNC initlinphone(void) { static PyObject * pylinphone_moduleinit(void) {
PyObject *m; PyObject *m;
PyObject *menum; PyObject *menum_PayloadType;
PyDateTime_IMPORT; PyDateTime_IMPORT;
PyEval_InitThreads(); PyEval_InitThreads();
pylinphone_init_logging(); pylinphone_init_logging();
{{#classes}} {{#classes}}
if (PyType_Ready(&pylinphone_{{class_name}}Type) < 0) return; if (PyType_Ready(&pylinphone_{{class_name}}Type) < 0) return NULL;