summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bindings/bindings.py80
-rw-r--r--bindings/java/lang.py13
-rw-r--r--bindings/php5/wrapper_source.py1
-rw-r--r--bindings/utils.py3
4 files changed, 54 insertions, 43 deletions
diff --git a/bindings/bindings.py b/bindings/bindings.py
index d168e50f..91140ac3 100644
--- a/bindings/bindings.py
+++ b/bindings/bindings.py
@@ -276,34 +276,7 @@ class DocString:
break
else:
raise Exception('should not happen ' + param_name + ' ' + lines[0] + repr(function))
- if 'allow-none' in param_options:
- arg[2]['optional'] = True
- if re.search('\(\s*out\s*\)', param_options):
- arg[2]['out'] = True
- if arg[2].get('optional'):
- m = re.search('\(\s*default\s*(.*)\s*\)', param_options)
- if m:
- prefix = ''
- if is_boolean(arg):
- prefix = 'b:'
- elif is_int(arg):
- prefix = 'c:'
- else:
- raise Exception('should not happen: could not found type for default: ' + param_options)
- arg[2]['default'] = prefix + m.group(1)
- m = re.search('\(\s*element-type\s+(\w+)(?:\s+(\w+))?', param_options)
- if m:
- if len(m.groups()) > 2:
- arg[2]['key-type'] = \
- convert_type_from_gobject_annotation(m.group(1))
- arg[2]['value-type'] = \
- convert_type_from_gobject_annotation(m.group(2))
- else:
- arg[2]['element-type'] = \
- convert_type_from_gobject_annotation(m.group(1))
- m = re.search('\(\s*transfer\s+(\w+)', param_options)
- if m:
- arg[2]['transfer'] = m.group(1)
+ self.annotation2arg(arg, param_options)
else:
param_desc = splits[1]
self.parameters.append([param_name, param_desc])
@@ -326,17 +299,52 @@ class DocString:
self.description = self.description.strip()
# return value
- if lines[0].startswith('Return value'):
+ if lines[0].startswith('Return value') or lines[0].startswith('Returns'):
lines[0] = lines[0].split(':', 1)[1]
- self.return_value = ''
+ accu = ''
while lines[0].strip():
- self.return_value = self.return_value + ' ' + lines[0].strip()
+ accu = accu + ' ' + lines[0].strip()
if len(lines) == 1:
break
lines = lines[1:]
- self.return_value = self.return_value[1:] # remove leading space
-
-
+ # find GObject-introspection annotations
+ if re.match(r'\s*\(', accu):
+ annotation, accu = accu.split(':', 1)
+ self.annotation2arg(function.return_arg, annotation)
+ self.return_value = accu.strip() # remove leading space
+ def annotation2arg(self, arg, annotation):
+ '''Convert GObject-introspection annotations to arg options'''
+
+ if 'allow-none' in annotation:
+ arg[2]['optional'] = True
+ if re.search('\(\s*out\s*\)', annotation):
+ arg[2]['out'] = True
+ if re.search('\(\s*in\s*\)', annotation):
+ arg[2]['in'] = True
+ if arg[2].get('optional'):
+ m = re.search('\(\s*default\s*(.*)\s*\)', annotation)
+ if m:
+ prefix = ''
+ if is_boolean(arg):
+ prefix = 'b:'
+ elif is_int(arg):
+ prefix = 'c:'
+ else:
+ raise Exception('should not happen: could not found type for default: ' + annotation)
+ arg[2]['default'] = prefix + m.group(1)
+ m = re.search('\(\s*element-type\s+(\w+)(?:\s+(\w+))?', annotation)
+ if m:
+ if len(m.groups()) > 2:
+ arg[2]['key-type'] = \
+ convert_type_from_gobject_annotation(m.group(1))
+ arg[2]['value-type'] = \
+ convert_type_from_gobject_annotation(m.group(2))
+ else:
+ arg[2]['element-type'] = \
+ convert_type_from_gobject_annotation(m.group(1))
+ m = re.search('\(\s*transfer\s+(\w+)', annotation)
+ if m:
+ arg[2]['transfer'] = m.group(1)
def normalise_var(type, name):
if name[0] == '*':
@@ -443,7 +451,8 @@ def parse_header(header_file):
i += 1
line = line[:-1] + lines[i].lstrip()
- m = re.match(r'LASSO_EXPORT(.*(?:\s|\*))(\w+)\s*\((.*?)\)', line)
+ # parse the type, then the name, then argument list
+ 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()
@@ -458,6 +467,7 @@ def parse_header(header_file):
return_type = clean_type(return_type)
if return_type != 'void':
f.return_type = return_type
+ f.return_arg = (return_type, None, {})
if function_name.endswith('_destroy'):
# skip the _destroy functions, they are just wrapper over
# g_object_unref
diff --git a/bindings/java/lang.py b/bindings/java/lang.py
index 21fb5bd5..ed6688f1 100644
--- a/bindings/java/lang.py
+++ b/bindings/java/lang.py
@@ -110,9 +110,6 @@ def is_collection(type):
def is_string_type(type):
return type in ['char*', 'const char*', 'gchar*', 'const gchar*']
-def is_const_type(type):
- return type in ['const char*', 'const gchar*']
-
class Binding:
def __init__(self, binding_data):
self.binding_data = binding_data
@@ -526,8 +523,12 @@ protected static native void destroy(long cptr);
print >> fd, 'return_value = ',
if 'new' in m.name:
print >>fd, '(%s)' % m.return_type,
-
- print >> fd, '%s(%s);' % (m.name, ', '.join([x[1] for x in m.args]))
+ def arg2ref(x):
+ if is_const(x):
+ return '(%s) %s' % (x[0],x[1])
+ else:
+ return x[1]
+ print >> fd, '%s(%s);' % (m.name, ', '.join([arg2ref(x) for x in m.args]))
# Free const char * args
idx=0
for arg in m.args:
@@ -554,7 +555,7 @@ protected static native void destroy(long cptr);
if m.return_owner:
if m.return_type == 'GList*' or m.return_type == 'const GList*':
print >> fd, ' free_glist(&return_value, NULL);'
- elif is_string_type(m.return_type) and not is_const_type(m.return_type):
+ elif is_string_type(m.return_type) and not is_const(m.return_arg):
print >> fd, ' if (return_value)'
print >> fd, ' g_free(return_value);'
print >> fd, ' return ret;'
diff --git a/bindings/php5/wrapper_source.py b/bindings/php5/wrapper_source.py
index 5775b7be..0045cf6e 100644
--- a/bindings/php5/wrapper_source.py
+++ b/bindings/php5/wrapper_source.py
@@ -343,7 +343,6 @@ PHP_MSHUTDOWN_FUNCTION(lasso)
if is_out(arg):
# export the returned variable
free = is_transfer_full(unref_type(arg))
- print m
self.set_zval('php_out_%s' % argname, argname, unref_type(arg), free = free)
pass
elif argtype == 'xmlNode*':
diff --git a/bindings/utils.py b/bindings/utils.py
index e1248d92..68ce2392 100644
--- a/bindings/utils.py
+++ b/bindings/utils.py
@@ -128,7 +128,8 @@ def value_type(arg):
return arg[2].get('value-type')
def is_out(arg):
- return _test_arg(arg, 'out') or arg_type(arg).endswith('**')
+ return _test_arg(arg, 'out') or (arg_type(arg).endswith('**') and not _test_arg(arg, 'in'))
+
def is_glist(arg):
return re.match('GList\>', var_type(arg))