summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-01-04 09:16:00 +0000
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2010-01-04 09:16:00 +0000
commitfcd8739f49ce231f002604d31068087daa6e2fb7 (patch)
treeb5503fe3e7ebe5e336be5553b187e4bceade2902 /bindings
parent914a176d99e7686cb3d0207a4d1429bf6c944cc5 (diff)
downloadlasso-fcd8739f49ce231f002604d31068087daa6e2fb7.tar.gz
lasso-fcd8739f49ce231f002604d31068087daa6e2fb7.tar.xz
lasso-fcd8739f49ce231f002604d31068087daa6e2fb7.zip
Bindings: simplify GList handling
Diffstat (limited to 'bindings')
-rw-r--r--bindings/bindings.py18
-rw-r--r--bindings/java/lang.py58
-rw-r--r--bindings/php5/php_code.py4
-rw-r--r--bindings/php5/wrapper_source.py42
-rw-r--r--bindings/python/lang.py92
-rw-r--r--bindings/utils.py2
6 files changed, 120 insertions, 96 deletions
diff --git a/bindings/bindings.py b/bindings/bindings.py
index 91140ac3..2fedbc36 100644
--- a/bindings/bindings.py
+++ b/bindings/bindings.py
@@ -146,7 +146,7 @@ class BindingData:
func = getfunc(function_name)
if not func:
continue
- func.docstring = DocString(func, docstring)
+ func.docstring = DocString(func, docstring, self)
if exception_doc:
lines = os.popen('perl ../utility-scripts/error-analyzer.pl %s' % srcdir, 'r').readlines()
for line in lines:
@@ -211,7 +211,7 @@ class Function:
if param.attrib.get('type'):
arg[0] = param.attrib.get('type')
if param.attrib.get('elem_type'):
- arg[2]['elem_type'] = param.attrib.get('elem_type')
+ arg[2]['element-type'] = param.attrib.get('elem_type')
if func.attrib.get('rename'):
self.rename = func.attrib.get('rename')
if func.attrib.get('return_owner'):
@@ -236,6 +236,7 @@ class Function:
if arg_name and arg_sub:
args = [ x for x in self.args if x[1] == arg_name]
for arg in args:
+ arg[2]['original-name'] = arg[1]
arg[1] = arg_sub
@@ -245,7 +246,8 @@ class DocString:
return_value = None
description = None
- def __init__(self, function, docstring):
+ def __init__(self, function, docstring, binding_data):
+ self.binding_data = binding_data
self.orig_docstring = docstring
self.parameters = []
self.params = {}
@@ -271,7 +273,7 @@ class DocString:
self.parameters.append([param_name, param_desc, param_options])
self.params[param_name] = { 'desc': param_desc, 'options': param_options }
for a in function.args:
- if a[1] == param_name:
+ if a[1] == param_name or a[2].get('original-name') == param_name:
arg = a
break
else:
@@ -327,7 +329,7 @@ class DocString:
prefix = ''
if is_boolean(arg):
prefix = 'b:'
- elif is_int(arg):
+ elif is_int(arg, self.binding_data):
prefix = 'c:'
else:
raise Exception('should not happen: could not found type for default: ' + annotation)
@@ -445,14 +447,14 @@ def parse_header(header_file):
of_type = line[line.index('/* of')+6:].split()[0]
if of_type == 'strings':
of_type = 'char*'
- options['elem_type'] = of_type
+ options['element-type'] = of_type
elif line.startswith('LASSO_EXPORT '):
while not line.strip().endswith(';'):
i += 1
- line = line[:-1] + lines[i].lstrip()
+ line = line[:-1] + ' ' + lines[i].lstrip()
# parse the type, then the name, then argument list
- m = re.match(r'LASSO_EXPORT\s+(.*(?:\s|\*))(\w+)\s*\(\s*(.*?)\s*\)\s*;', line)
+ m = re.match(r'LASSO_EXPORT\s+([^(]*(?:\s|\*))(\w+)\s*\(\s*(.*?)\s*\)\s*;', line)
if m and not m.group(2).endswith('_get_type'):
return_type, function_name, args = m.groups()
return_type = return_type.strip()
diff --git a/bindings/java/lang.py b/bindings/java/lang.py
index ed6688f1..6b470699 100644
--- a/bindings/java/lang.py
+++ b/bindings/java/lang.py
@@ -265,7 +265,7 @@ protected static native void destroy(long cptr);
def JNI_member_type(self,member):
type, name, options = member
if type in ('const GList*','GList*','GHashTable*'):
- return self.JNI_arg_type(options.get('elem_type'))
+ return self.JNI_arg_type(options.get('element-type'))
else:
return self.JNI_arg_type(type)
@@ -302,7 +302,7 @@ protected static native void destroy(long cptr);
print >> fd, ' public static native void %s(GObject obj, %s[] value);' % (name,jtype)
name = '%s_add' % prefix
print >> fd, ' public static native void %s(GObject obj, %s value);' % (name,jtype)
- if not m[2].get('elem_type') in ('xmlNode*',):
+ if not m[2].get('element-type') in ('xmlNode*',):
name = '%s_remove' % prefix
print >> fd, ' public static native void %s(GObject obj, %s value);' % (name,jtype)
elif mtype == 'GHashTable*':
@@ -409,16 +409,16 @@ protected static native void destroy(long cptr);
elif is_string_type(type):
return 'string_to_jstring(env, %s, &%s)' % (right, left)
elif type in ('const GList*','GList*',):
- elem_type = options.get('elem_type')
- if elem_type == 'char*':
+ element_type = options.get('element-type')
+ if element_type == 'char*':
return 'get_list_of_strings(env, %s, &%s)' % (right, left)
- elif elem_type == 'xmlNode*':
+ elif element_type == 'xmlNode*':
return 'get_list_of_xml_nodes(env, %s, &%s)' % (right, left)
else:
return 'get_list_of_objects(env, %s, &%s)' % (right, left)
elif type in ('GHashTable*',):
- elem_type = options.get('elem_type')
- if elem_type == 'char*':
+ element_type = options.get('element-type')
+ if element_type == 'char*':
return 'get_hash_of_strings(env, %s, &%s)' % (right, left)
else:
return 'get_hash_of_objects(env, %s, &%s)' % (right, left)
@@ -436,16 +436,16 @@ protected static native void destroy(long cptr);
elif is_string_type(type):
return 'jstring_to_string(env, %s, (char**)&%s);' % (right,left)
elif type in ('const GList*','GList*',):
- elem_type = options.get('elem_type')
- if elem_type == 'char*':
+ element_type = options.get('element-type')
+ if element_type == 'char*':
return 'set_list_of_strings(env, &%s,%s);' % (left,right)
- elif elem_type == 'xmlNode*':
+ elif element_type == 'xmlNode*':
return 'set_list_of_xml_nodes(env, &%s, %s);' % (left, right)
else:
return 'set_list_of_objects(env, &%s, %s);' % (left, right)
elif type in ('GHashTable*',):
- elem_type = options.get('elem_type')
- if elem_type == 'char*':
+ element_type = options.get('element-type')
+ if element_type == 'char*':
return 'set_hash_of_strings(env, %s, %s);' % (left,right)
else:
return 'set_hash_of_objects(env, %s, %s);' % (left,right)
@@ -538,10 +538,12 @@ protected static native void destroy(long cptr);
print >> fd, ' if (%s)' % arg_name
print >> fd, ' g_free(%s);' % arg_name
elif arg_type == 'GList*' or arg_type == 'const GList*':
- if arg_options.get('elem_type') == 'char*':
+ if arg_options.get('element-type') == 'char*':
print >> fd, ' free_glist(&%s, (GFunc)free);' % arg_name
+ elif is_object(element_type(arg)):
+ print >> fd, ' free_glist(&%s, (GFunc)g_object_unref);' % arg_name
else:
- raise Exception('Freeing args of type list of \'%s\' not supported.' % arg_options.get('elem_type'))
+ raise Exception('Freeing args of type list of \'%s\' not supported.' % arg_options.get('element-type'))
# Return
if m.return_type:
@@ -612,26 +614,26 @@ protected static native void destroy(long cptr);
if mtype in ('const GList*','GList*', ):
# add
print >> fd,'/* Adder for %s %s.%s */' % (mtype,klassname,m[1])
- elem_type = m[2].get('elem_type')
+ element_type = m[2].get('element-type')
wrapper_decl("%s_add" % prefix, 'void', fd)
- print >> fd, ', jobject jobj, %s value)\n {' % jni_elem_type(elem_type)
+ print >> fd, ', jobject jobj, %s value)\n {' % jni_elem_type(element_type)
print >> fd, ' %s *gobj;' % klassname
print >> fd, ' jobject_to_gobject(env, jobj, (GObject**)&gobj);'
- if is_string_type(elem_type):
+ if is_string_type(element_type):
print >> fd, ' add_to_list_of_strings(env, &gobj->%s,value);' % m[1]
- elif elem_type in ('xmlNode*',):
+ elif element_type in ('xmlNode*',):
print >> fd, ' add_to_list_of_xml_nodes(env, &gobj->%s,value);' % m[1]
else:
print >> fd, ' add_to_list_of_objects(env, &gobj->%s,value);' % m[1]
print >> fd, '}'
# remove
- if elem_type not in ('xmlNode*',):
+ if element_type not in ('xmlNode*',):
print >> fd,'/* Remover for %s %s.%s */' % (mtype,klassname,m[1])
wrapper_decl("%s_remove" % prefix, 'void', fd)
- print >> fd, ', jobject jobj, %s value)\n {' % jni_elem_type(elem_type)
+ print >> fd, ', jobject jobj, %s value)\n {' % jni_elem_type(element_type)
print >> fd, ' %s *gobj;' % klassname
print >> fd, ' jobject_to_gobject(env, jobj, (GObject**)&gobj);'
- if elem_type in ('char*','gchar*'):
+ if element_type in ('char*','gchar*'):
print >> fd, ' remove_from_list_of_strings(env, &gobj->%s,value);' % m[1]
else:
print >> fd, ' remove_from_list_of_objects(env, &gobj->%s,value);' % m[1]
@@ -640,12 +642,12 @@ protected static native void destroy(long cptr);
if mtype in ('GHashTable*',):
# add
print >> fd,'/* Adder for %s %s.%s */' % (mtype,klassname,m[1])
- elem_type = m[2].get('elem_type')
+ element_type = m[2].get('element-type')
wrapper_decl("%s_add" % prefix, 'void', fd)
- print >> fd, ', jobject jobj, jstring key, %s value)\n {' % jni_elem_type(elem_type)
+ print >> fd, ', jobject jobj, jstring key, %s value)\n {' % jni_elem_type(element_type)
print >> fd, ' %s *gobj;' % klassname
print >> fd, ' jobject_to_gobject(env, jobj, (GObject**)&gobj);'
- if elem_type in ('char*','gchar*'):
+ if element_type in ('char*','gchar*'):
print >> fd, ' add_to_hash_of_strings(env, gobj->%s,value,key);' % m[1]
else:
print >> fd, ' add_to_hash_of_objects(env, gobj->%s,value,key);' % m[1]
@@ -656,18 +658,18 @@ protected static native void destroy(long cptr);
# print >> fd, ', jobject jobj, jstring key)\n {'
# print >> fd, ' %s *gobj;' % klassname
# print >> fd, ' jobject_to_gobject(env, jobj, (GObject**)&gobj);'
-# if elem_type in ('char*','gchar*'):
+# if element_type in ('char*','gchar*'):
# print >> fd, ' remove_from_hash_of_strings(env, gobj->%s,key);' % m[1]
# else:
# print >> fd, ' remove_from_hash_of_objects(env, gobj->%s,key);' % m[1]
# print >> fd, '}'
# # get by name
# print >> fd,'/* Get by name for %s %s.%s */' % (mtype,klassname,m[1])
-# wrapper_decl("%s_get_by_name" % prefix, jni_elem_type(elem_type) , fd)
+# wrapper_decl("%s_get_by_name" % prefix, jni_elem_type(element_type) , fd)
# print >> fd, ', jobject jobj, jstring key)\n {'
# print >> fd, ' %s *gobj;' % klassname
# print >> fd, ' jobject_to_gobject(env, jobj, (GObject**)&gobj);'
-# if elem_type in ('char*','gchar*'):
+# if element_type in ('char*','gchar*'):
# print >> fd, ' return get_hash_of_strings_by_name(env, gobj->%s,key);' % m[1]
# else:
# print >> fd, ' return get_hash_of_objects_by_name(env, gobj->%s,key);' % m[1]
@@ -808,7 +810,7 @@ protected static native void destroy(long cptr);
print >> fd, ' public void addTo%s(%s value) {' % (jname,jtype)
print >> fd, ' LassoJNI.%s_add(this, value);' % prefix
print >> fd, ' }'
- if m[2].get('elem_type') not in ('xmlNode*',):
+ if m[2].get('element-type') not in ('xmlNode*',):
print >> fd, ' public void removeFrom%s(%s value) {' % (jname,jtype)
print >> fd, ' LassoJNI.%s_remove(this, value);' % prefix
print >> fd, ' }'
diff --git a/bindings/php5/php_code.py b/bindings/php5/php_code.py
index 64439778..3530acf8 100644
--- a/bindings/php5/php_code.py
+++ b/bindings/php5/php_code.py
@@ -196,7 +196,7 @@ function lassoRegisterIdWsf2DstService($prefix, $href) {
klass.name, mname)
elif mtype in ('GList*', 'GHashTable*'):
print >> self.fd, ' $array = %s_%s_get($this->_cptr);' % (klass.name, mname)
- if self.is_object(options.get('elem_type')):
+ if self.is_object(options.get('element-type')):
print >> self.fd, ' $obj_array = array();'
if mtype == 'GList*':
print >> self.fd, ' foreach ($array as $item) {'
@@ -215,7 +215,7 @@ function lassoRegisterIdWsf2DstService($prefix, $href) {
print >> self.fd, ' protected function set_%s($value) {' % mname
if self.is_object(mtype):
print >> self.fd, ' %s_%s_set($this->_cptr, $value->_cptr);' % (klass.name, mname)
- elif mtype in ('GList*', 'GHashTable*') and self.is_object(options.get('elem_type')):
+ elif mtype in ('GList*', 'GHashTable*') and self.is_object(options.get('element-type')):
print >> self.fd, ' $array = array();'
# FIXME: setting an array to NULL should really set it to NULL and not to an empty array
print >> self.fd, ' if (!is_null($value)) {'
diff --git a/bindings/php5/wrapper_source.py b/bindings/php5/wrapper_source.py
index 0045cf6e..0f0b7bcd 100644
--- a/bindings/php5/wrapper_source.py
+++ b/bindings/php5/wrapper_source.py
@@ -134,7 +134,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
elif arg_type(type) == 'GList*':
elem_type = make_arg(element_type(type))
if not arg_type(elem_type):
- raise Exception('unknown elem_type: ' + repr(type))
+ raise Exception('unknown element-type: ' + repr(type))
if is_cstring(elem_type):
function = 'set_array_from_list_of_strings'
free_function = 'free_glist(%(c_variable)s, (GFunc)free);'
@@ -145,7 +145,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
function = 'set_array_from_list_of_objects'
free_function = 'g_list_free(%(c_variable)s);'
else:
- raise Exception('unknown elem_type: ' + repr(type))
+ raise Exception('unknown element-type: ' + repr(type))
print >> self.fd, ' %s(%s, &%s);' % (function, c_variable, zval_name)
if free:
print >> self.fd, ' ', free_function % q
@@ -205,13 +205,13 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
}
'''
elif vtype == 'GList*':
- if options.get('elem_type') == 'char*':
+ if options.get('element-type') == 'char*':
print >> self.fd, '''\
set_array_from_list_of_strings(return_c_value, &return_value);
'''
if free:
print >> self.fd, ' free_glist(&return_c_value, (GFunc)free);'
- elif options.get('elem_type') == 'xmlNode*':
+ elif options.get('element-type') == 'xmlNode*':
print >> self.fd, '''\
set_array_from_list_of_xmlnodes(return_c_value, &return_value);
'''
@@ -224,7 +224,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
if free:
print >> self.fd, ' free_glist(&return_c_value, NULL);'
elif vtype == 'GHashTable*':
- if options.get('elem_type') not in ('char*', 'xmlNode*'):
+ if options.get('element-type') not in ('char*', 'xmlNode*'):
print >> self.fd, '''\
set_array_from_hashtable_of_objects(return_c_value, &return_value);
'''
@@ -267,7 +267,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
print >> self.fd, ' %s %s = NULL;' % ('char*', arg_name)
print >> self.fd, ' %s %s_str = NULL;' % ('char*', arg_name)
print >> self.fd, ' %s %s_len = 0;' % ('int', arg_name)
- elif arg_type in ['int', 'gint', 'gboolean', 'const gboolean'] + self.binding_data.enums:
+ elif arg_type in ['int', 'gint', 'GType', 'gboolean', 'const gboolean'] + self.binding_data.enums:
parse_tuple_format.append('l')
parse_tuple_args.append('&%s' % arg_name)
print >> self.fd, ' %s %s;' % ('long', arg_name)
@@ -318,11 +318,11 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
print >> self.fd, ' ZEND_FETCH_RESOURCE(cvt_%s, PhpGObjectPtr *, &zval_%s, -1, PHP_LASSO_SERVER_RES_NAME, le_lasso_server);' % (arg[1], arg[1])
print >> self.fd, ' %s = (%s)cvt_%s->obj;' % (arg[1], arg[0], arg[1])
elif f.startswith('a'):
- elem_type = arg[2].get('elem_type')
- if elem_type == 'char*':
+ element_type = arg[2].get('element-type')
+ if element_type == 'char*':
print >> self.fd, ' %(name)s = get_list_from_array_of_strings(zval_%(name)s);' % {'name': arg[1]}
else:
- print >> sys.stderr, 'E: In %(function)s arg %(name)s is of type GList<%(elem)s>' % { 'function': m.name, 'name': arg[1], 'elem': elem_type }
+ print >> sys.stderr, 'E: In %(function)s arg %(name)s is of type GList<%(elem)s>' % { 'function': m.name, 'name': arg[1], 'elem': element_type }
elif f == 'l':
pass
else:
@@ -348,8 +348,8 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
elif argtype == 'xmlNode*':
print >> self.fd, ' xmlFree(%s);' % argname
elif f.startswith('a'):
- elem_type = arg[2].get('elem_type')
- if elem_type == 'char*':
+ element_type = arg[2].get('element-type')
+ if element_type == 'char*':
print >> self.fd, ' if (%(name)s) {' % { 'name': arg[1] }
print >> self.fd, ' free_glist(&%(name)s,(GFunc)free);' % { 'name': arg[1] }
print >> self.fd, ' }'
@@ -365,9 +365,9 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
self.generate_setter(c.name, m_type, m_name, m_options)
def generate_getter(self, klassname, m_type, m_name, m_options):
- if m_type == 'GList*' and m_options.get('elem_type') not in ('char*', 'xmlNode*') \
- and not self.is_object(m_options.get('elem_type')):
- print >> sys.stderr, 'E: GList argument : %s of %s, with type : %s' % (m_name, klassname, m_options.get('elem_type'))
+ if m_type == 'GList*' and m_options.get('element-type') not in ('char*', 'xmlNode*') \
+ and not self.is_object(m_options.get('element-type')):
+ print >> sys.stderr, 'E: GList argument : %s of %s, with type : %s' % (m_name, klassname, m_options.get('element-type'))
return
function_name = '%s_%s_get' % (klassname, format_as_camelcase(m_name))
@@ -409,9 +409,9 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
def generate_setter(self, klassname, m_type, m_name, m_options):
- if m_type == 'GList*' and m_options.get('elem_type') not in ('char*', 'xmlNode*') \
- and not self.is_object(m_options.get('elem_type')):
- print >> sys.stderr, 'E: GList argument : %s of %s, with type : %s' % (m_name, klassname, m_options.get('elem_type'))
+ if m_type == 'GList*' and m_options.get('element-type') not in ('char*', 'xmlNode*') \
+ and not self.is_object(m_options.get('element-type')):
+ print >> sys.stderr, 'E: GList argument : %s of %s, with type : %s' % (m_name, klassname, m_options.get('element-type'))
return
function_name = '%s_%s_set' % (klassname, format_as_camelcase(m_name))
@@ -435,7 +435,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
parse_tuple_args.append('&%s_str, &%s_len' % (arg_name, arg_name))
print >> self.fd, ' %s %s_str = NULL;' % ('char*', arg_name)
print >> self.fd, ' %s %s_len = 0;' % ('int', arg_name)
- elif arg_type in ['int', 'gint', 'gboolean', 'const gboolean'] + self.binding_data.enums:
+ elif arg_type in ['int', 'gint', 'GType', 'gboolean', 'const gboolean'] + self.binding_data.enums:
parse_tuple_format += 'l'
parse_tuple_args.append('&%s' % arg_name)
print >> self.fd, ' %s %s;' % ('long', arg_name)
@@ -486,7 +486,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
print >> self.fd, ' this->%s = NULL;' % m_name
print >> self.fd, ' }'
elif arg_type == 'GList*':
- if m_options.get('elem_type') == 'char*':
+ if m_options.get('element-type') == 'char*':
print >> self.fd, '''
if (this->%(name)s) {
/* free existing list */
@@ -495,7 +495,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
}
this->%(name)s = get_list_from_array_of_strings(zval_%(name)s);
''' % { 'name': m_name }
- elif m_options.get('elem_type') == 'xmlNode*':
+ elif m_options.get('element-type') == 'xmlNode*':
print >> self.fd, '''
if (this->%(name)s) {
/* free existing list */
@@ -509,7 +509,7 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
free_glist(&this->%(name)s, (GFunc)g_object_unref);
this->%(name)s = get_list_from_array_of_objects(zval_%(name)s);
''' % { 'name': m_name }
- elif arg_type == 'GHashTable*' and arg_options.get('elem_type') != 'char*':
+ elif arg_type == 'GHashTable*' and arg_options.get('element-type') != 'char*':
print >> self.fd, '''\
{
GHashTable *oldhash = this->%(name)s;
diff --git a/bindings/python/lang.py b/bindings/python/lang.py
index ff06b746..8b1f18b4 100644
--- a/bindings/python/lang.py
+++ b/bindings/python/lang.py
@@ -275,7 +275,7 @@ if WSF_SUPPORT:
py_args.append(get_python_arg_decl(o))
if self.is_pygobject(arg_type):
- c_args.append('%s._cptr' % arg_name)
+ c_args.append('%s and %s._cptr' % (arg_name, arg_name))
else:
c_args.append(arg_name)
@@ -300,7 +300,7 @@ if WSF_SUPPORT:
py_args.append(get_python_arg_decl(o))
if self.is_pygobject(arg_type):
- c_args.append('%s._cptr' % arg_name)
+ c_args.append('%s and %s._cptr' % (arg_name, arg_name))
else:
c_args.append(arg_name)
c_args = ', '.join(c_args)
@@ -323,7 +323,7 @@ if WSF_SUPPORT:
print >> fd, ' t = _lasso.%s_%s_get(self._cptr)' % (
klassname, mname)
print >> fd, ' return cptrToPy(t)'
- elif m[0] == 'GList*' and options.get('elem_type') not in ('char*', 'xmlNode*'):
+ elif m[0] == 'GList*' and options.get('element-type') not in ('char*', 'xmlNode*'):
print >> fd, ' l = _lasso.%s_%s_get(self._cptr)' % (
klassname, mname)
print >> fd, ' if not l: return l'
@@ -332,7 +332,7 @@ if WSF_SUPPORT:
print >> fd, ' d = _lasso.%s_%s_get(self._cptr)' % (
klassname, mname)
print >> fd, ' if not d: return d'
- if options.get('elem_type') != 'char*':
+ if options.get('element-type') != 'char*':
print >> fd, ' d2 = {}'
print >> fd, ' for k, v in d.items():'
print >> fd, ' d2[k] = cptrToPy(v)'
@@ -345,8 +345,8 @@ if WSF_SUPPORT:
print >> fd, ' def set_%s(self, value):' % mname
if self.is_pygobject(m[0]):
print >> fd, ' if value is not None:'
- print >> fd, ' value = value._cptr'
- elif m[0] == 'GList*' and options.get('elem_type') not in ('char*', 'xmlNode*'):
+ print >> fd, ' value = value and value._cptr'
+ elif m[0] == 'GList*' and options.get('element-type') not in ('char*', 'xmlNode*'):
print >> fd, ' if value is not None:'
print >> fd, ' value = tuple([x._cptr for x in value])'
print >> fd, ' _lasso.%s_%s_set(self._cptr, value)' % (
@@ -376,7 +376,10 @@ if WSF_SUPPORT:
function_name = function_name[6:]
else:
mname = m.name
- mname = re.match(r'lasso_.*_get_(\w+)', mname).group(1)
+ try:
+ mname = re.match(r'lasso_.*_get_(\w+)', mname).group(1)
+ except:
+ raise
mname = format_underscore_as_camelcase(mname)
print >> fd, ' def get_%s(self):' % mname
function_name = m.name[6:]
@@ -430,12 +433,17 @@ if WSF_SUPPORT:
if is_out(o):
c_args.append(outvar)
- elif arg_type in ('char*', 'const char*', 'guchar*', 'const guchar*', 'gchar*', 'const gchar*', 'xmlNode*') or \
- arg_type in ['int', 'gint', 'gboolean', 'const gboolean'] or \
- arg_type in self.binding_data.enums or is_time_t_pointer(o):
+ elif not self.is_pygobject(arg_type):
c_args.append(arg_name)
else:
- c_args.append('%s._cptr' % arg_name)
+ c_args.append('%s and %s._cptr' % (arg_name, arg_name))
+ # check py_args
+ opt = False
+ for x in py_args:
+ if '=' in x:
+ opt = True
+ elif opt:
+ print 'W: non-optional follow optional,', m
if py_args:
py_args = ', ' + ', '.join(py_args)
@@ -567,7 +575,8 @@ if WSF_SUPPORT:
s.append('\n')
- s[-1] = s[-1].rstrip() # remove trailing newline from last line
+ if s:
+ s[-1] = s[-1].rstrip() # remove trailing newline from last line
return '\n'.join([(indent*' ')+x for x in ''.join(s).splitlines()])
@@ -704,10 +713,10 @@ register_constants(PyObject *d)
print >> fd, ' if (this->%s) g_free(this->%s);' % (m[1], m[1])
print >> fd, ' this->%s = g_strdup(value);' % m[1]
elif parse_format == 'O' and arg_type == 'GList*':
- elem_type = m[2].get('elem_type')
- if elem_type == 'char*':
+ element_type = m[2].get('element-type')
+ if element_type == 'char*':
print >> fd, ' set_list_of_strings(&this->%s, cvt_value);' % m[1]
- elif elem_type == 'xmlNode*':
+ elif element_type == 'xmlNode*':
print >> fd, ' set_list_of_xml_nodes(&this->%s, cvt_value);' % m[1]
else:
print >> fd, ' set_list_of_pygobject(&this->%s, cvt_value);' % m[1]
@@ -748,18 +757,18 @@ register_constants(PyObject *d)
print >> fd, ' %s = noneRef();' % return_pyvar_name
print >> fd, ' }'
elif vtype in ('const GList*', 'GList*',):
- elem_type = options.get('elem_type')
- if not elem_type or self.is_pygobject(elem_type):
+ element_type = options.get('element-type')
+ if not element_type or self.is_pygobject(element_type):
print >> fd, ' %s = get_list_of_pygobject(%s);' % (return_pyvar_name, return_var_name)
- elif elem_type == 'char*':
+ elif element_type == 'char*':
print >> fd, ' %s = get_list_of_strings(%s);' % (return_pyvar_name, return_var_name)
- elif elem_type.startswith('xmlNode'):
+ elif element_type.startswith('xmlNode'):
print >> fd, ' %s = get_list_of_xml_nodes(%s);' % (return_pyvar_name, return_var_name)
else:
raise Exception('Should not happen: %s %s ' % (repr(options), vtype))
elif vtype in ('GHashTable*',):
- elem_type = options.get('elem_type')
- if elem_type == 'char*':
+ element_type = options.get('element-type')
+ if element_type == 'char*':
print >> fd, ' %s = get_dict_from_hashtable_of_strings(%s);' % (return_pyvar_name, return_var_name)
else:
print >> fd, ' %s = get_dict_from_hashtable_of_objects(%s);' % (return_pyvar_name, return_var_name)
@@ -798,20 +807,18 @@ register_constants(PyObject *d)
arg_def = None
python_cvt_def = None
defval = None
+ if arg_options.get('optional'):
+ if not '|' in parse_tuple_format:
+ parse_tuple_format.append('|')
if arg_type in ('char*', 'const char*', 'gchar*', 'const gchar*'):
arg_type = arg_type.replace('const ', '')
if arg_options.get('optional'):
- if not '|' in parse_tuple_format:
- parse_tuple_format.append('|')
parse_tuple_format.append('z')
else:
parse_tuple_format.append('s')
parse_tuple_args.append('&%s' % arg_name)
arg_def = ' %s %s = NULL;' % (arg[0], arg[1])
- elif arg_type in ['int', 'gint', 'gboolean', 'const gboolean'] + self.binding_data.enums:
- if arg_options.get('optional'):
- if not '|' in parse_tuple_format:
- parse_tuple_format.append('|')
+ elif arg_type in ['GType', 'int', 'gint', 'gboolean', 'const gboolean'] + self.binding_data.enums:
parse_tuple_format.append('i')
parse_tuple_args.append('&%s' % arg_name)
if arg_options.get('default'):
@@ -857,25 +864,38 @@ register_constants(PyObject *d)
print >> fd, ' if (! PyArg_ParseTuple(args, "%s"%s)) return NULL;' % (
''.join(parse_tuple_format), parse_tuple_args)
- for f, arg in zip(parse_tuple_format, m.args):
+ for f, arg in zip([ x for x in parse_tuple_format if x != '|'], m.args):
if is_out(arg):
continue
if is_list(arg):
- qualifier = arg[2].get('elem_type')
- if qualifier == 'char*':
+ qualifier = element_type(arg)
+ if qualifier == 'char*' or qualifier == 'utf8':
print >> fd, ' set_list_of_strings(&%s, cvt_%s);' % (arg[1], arg[1])
elif qualifier == 'xmlNode*':
print >> fd, ' set_list_of_xml_nodes(&%s, cvt_%s);' % (arg[1], arg[1])
- elif qualifier == 'LassoNode':
+ elif isinstance(qualifier, basestring) and qualifier.startswith('Lasso'):
print >> fd, ' set_list_of_pygobject(&%s, cvt_%s);' % (arg[1], arg[1])
else:
- print >> sys.stderr, 'E: unqualified GList argument in', name
+ print >> sys.stderr, 'E: unqualified GList argument in', name, qualifier, arg
elif is_xml_node(arg):
print >> fd, ' %s = get_xml_node_from_pystring(cvt_%s);' % (arg[1], arg[1])
elif is_time_t_pointer(arg):
print >> fd, ' %s = get_time_t(cvt_%s);' % (arg[1], arg[1])
elif f == 'O':
- print >> fd, ' %s = (%s)cvt_%s->obj;' % (arg[1], arg[0], arg[1])
+ if is_optional(arg):
+ print >> fd, ' if (PyObject_TypeCheck((PyObject*)cvt_%s, &PyGObjectPtrType)) {' % arg[1]
+ print >> fd, ' %s = (%s)cvt_%s->obj;' % (arg[1], arg[0], arg[1])
+ print >> fd, ' } else {'
+ print >> fd, ' %s = NULL;' % arg[1]
+ print >> fd, ' }'
+ else:
+ print >> fd, ' if (PyObject_TypeCheck((PyObject*)cvt_%s, &PyGObjectPtrType)) {' % arg[1]
+ print >> fd, ' %s = (%s)cvt_%s->obj;' % (arg[1], arg[0], arg[1])
+ print >> fd, ' } else {'
+ print >> fd, ' PyErr_SetString(PyExc_TypeError, "value should be a PyGObject");'
+ print >> fd, ' return NULL;'
+ print >> fd, ' }'
+
if m.return_type:
print >> fd, ' return_value =',
@@ -887,10 +907,10 @@ register_constants(PyObject *d)
for f, arg in zip(parse_tuple_format, m.args):
if is_out(arg):
- self.return_value(fd, var_type(arg), {'elem_type': element_type(arg)}, return_var_name = arg[1], return_pyvar_name = 'out_pyvalue')
+ self.return_value(fd, var_type(arg), {'element-type': element_type(arg)}, return_var_name = arg[1], return_pyvar_name = 'out_pyvalue')
print >> fd, ' PyList_SetItem(cvt_%s_out, 0, out_pyvalue);' % arg[1]
elif arg[0] == 'GList*':
- qualifier = arg[2].get('elem_type')
+ qualifier = arg[2].get('element-type')
if qualifier == 'char*':
print >> fd, ' free_list(&%s, (GFunc)g_free);' % arg[1]
elif qualifier == 'xmlNode*':
@@ -905,7 +925,7 @@ register_constants(PyObject *d)
else:
# Constructor so decrease refcount (it was incremented by PyGObjectPtr_New called
# in self.return_value
- self.return_value(fd, m.return_type, {'elem_type': m.return_type_qualifier})
+ self.return_value(fd, m.return_type, {'element-type': m.return_type_qualifier})
if m.return_owner and self.is_pygobject(m.return_type):
print >> fd, ' if (return_value) g_object_unref(return_value);'
print >> fd, ' return return_pyvalue;'
diff --git a/bindings/utils.py b/bindings/utils.py
index 68ce2392..86594cd3 100644
--- a/bindings/utils.py
+++ b/bindings/utils.py
@@ -23,7 +23,7 @@ import re
import string
_mapping_convert_type_from_gobject_annotation = {
- 'utf8': 'char8'
+ 'utf8': 'char*'
}
def convert_type_from_gobject_annotation(type):