gobject-introspection r732 - in trunk: giscanner tests/scanner
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r732 - in trunk: giscanner tests/scanner
- Date: Thu, 16 Oct 2008 19:34:39 +0000 (UTC)
Author: walters
Date: Thu Oct 16 19:34:39 2008
New Revision: 732
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=732&view=rev
Log:
Default GObject transfer to full
Modified:
trunk/giscanner/glibtransformer.py
trunk/giscanner/transformer.py
trunk/tests/scanner/annotation-1.0-expected.gir
trunk/tests/scanner/annotation.c
trunk/tests/scanner/annotation.h
Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py (original)
+++ trunk/giscanner/glibtransformer.py Thu Oct 16 19:34:39 2008
@@ -27,7 +27,7 @@
from .ast import (Callback, Constant, Enum, Function, Member, Namespace,
Parameter, Property, Return, Struct, Type, Alias, Array,
Union, type_name_from_ctype,
- default_array_types, TYPE_UINT8)
+ default_array_types, TYPE_UINT8, PARAM_DIRECTION_IN)
from .transformer import Names
from .glibast import (GLibBoxed, GLibEnum, GLibEnumMember, GLibFlags,
GLibInterface, GLibObject, GLibSignal, GLibBoxedStruct,
@@ -659,6 +659,7 @@
def _resolve_param_type_validate(self, ptype):
ptype = self._resolve_param_type(ptype)
+
if self._validating and not self._validate_type(ptype):
raise UnknownTypeError("Unknown type %r" % (ptype, ))
return ptype
@@ -669,7 +670,6 @@
self._names)
except KeyError, e:
return self._transformer.resolve_param_type(ptype)
- return ptype
def _resolve_node(self, node):
if isinstance(node, Function):
@@ -782,13 +782,30 @@
def _resolve_property(self, prop):
prop.type = self._resolve_param_type(prop.type)
+ def _adjust_transfer(self, param):
+ # Do GLib/GObject-specific type transformations here
+
+ # Default to full transfer for GObjects
+ if isinstance(param, Parameter):
+ is_out = (param.direction != PARAM_DIRECTION_IN)
+ else:
+ is_out = True
+ if (is_out and
+ param.transfer is None and
+ (param.type.name == 'GObject.Object' or
+ (self._namespace_name == 'GObject'
+ and param.type.name == 'Object'))):
+ param.transfer = 'full'
+
def _resolve_function(self, func):
self._resolve_parameters(func.parameters)
func.retval.type = self._resolve_param_type(func.retval.type)
+ self._adjust_transfer(func.retval)
def _resolve_parameters(self, parameters):
for parameter in parameters:
parameter.type = self._resolve_param_type(parameter.type)
+ self._adjust_transfer(parameter)
def _resolve_field(self, field):
if isinstance(field, Callback):
Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py (original)
+++ trunk/giscanner/transformer.py Thu Oct 16 19:34:39 2008
@@ -342,9 +342,8 @@
return node
def _parse_ctype(self, ctype):
- canonical = type_name_from_ctype(ctype)
- derefed = canonical.replace('*', '')
- return derefed
+ derefed = ctype.replace('*', '')
+ return type_name_from_ctype(derefed)
def _create_type(self, source_type, options):
ctype = self._create_source_type(source_type)
@@ -354,6 +353,8 @@
# properly instead
elif ctype == 'FILE*':
raise SkipError
+
+ # Now check for a list/map/array type
if ctype in self._list_ctypes:
param = options.get('element-type')
if param:
@@ -363,7 +364,7 @@
return List(ctype.replace('*', ''),
ctype,
contained_type)
- if ctype in self._map_ctypes:
+ elif ctype in self._map_ctypes:
param = options.get('element-type')
if param:
key_type = self._parse_ctype(param[0])
@@ -374,7 +375,7 @@
return Map(ctype.replace('*', ''),
ctype,
key_type, value_type)
- if (ctype in default_array_types) or ('array' in options):
+ elif (ctype in default_array_types) or ('array' in options):
derefed = ctype[:-1] # strip the *
result = Array(ctype,
self._parse_ctype(derefed))
@@ -383,25 +384,28 @@
(_, len_name) = array_opts[0].split('=')
result.length_param_name = len_name
return result
- resolved_type_name = self._parse_ctype(ctype)
- # string memory management
+ # string memory management - we just look at 'const'
if type_name_from_ctype(ctype) == TYPE_STRING:
if source_type.base_type.type_qualifier & TYPE_QUALIFIER_CONST:
options['transfer'] = ['none']
else:
options['transfer'] = ['full']
+ derefed_name = self._parse_ctype(ctype)
+
# deduce direction for some types passed by reference
if (not ('out' in options or
'in' in options or
'inout' in options or
'in-out' in options) and
source_type.type == CTYPE_POINTER and
- type_name_from_ctype(resolved_type_name) in default_out_types):
+ derefed_name in default_out_types):
options['out'] = []
- return Type(resolved_type_name, ctype)
+ resolved_name = self.resolve_type_name(derefed_name, ctype)
+
+ return Type(derefed_name, ctype)
def _handle_generic_param_options(self, param, options):
for option, data in options.iteritems():
Modified: trunk/tests/scanner/annotation-1.0-expected.gir
==============================================================================
--- trunk/tests/scanner/annotation-1.0-expected.gir (original)
+++ trunk/tests/scanner/annotation-1.0-expected.gir Thu Oct 16 19:34:39 2008
@@ -34,7 +34,7 @@
</return-value>
</method>
<method name="allow_none" c:identifier="annotation_object_allow_none">
- <return-value>
+ <return-value transfer-ownership="full">
<type name="GObject.Object" c:type="GObject*"/>
</return-value>
<parameters>
@@ -43,6 +43,11 @@
</parameter>
</parameters>
</method>
+ <method name="notrans" c:identifier="annotation_object_notrans">
+ <return-value transfer-ownership="none">
+ <type name="GObject.Object" c:type="GObject*"/>
+ </return-value>
+ </method>
<method name="inout" c:identifier="annotation_object_inout">
<return-value>
<type name="int" c:type="gint"/>
@@ -101,7 +106,7 @@
<parameter name="toown1" direction="out" transfer-ownership="full">
<type name="GObject.Object" c:type="GObject**"/>
</parameter>
- <parameter name="toown2" direction="out" transfer-ownership="full">
+ <parameter name="toown2" direction="out" transfer-ownership="none">
<type name="GObject.Object" c:type="GObject**"/>
</parameter>
</parameters>
@@ -164,7 +169,7 @@
c:identifier="annotation_object_do_not_use"
deprecated="Use annotation_object_create_object() instead."
deprecated-version="0.12">
- <return-value>
+ <return-value transfer-ownership="full">
<type name="GObject.Object" c:type="GObject*"/>
</return-value>
</method>
Modified: trunk/tests/scanner/annotation.c
==============================================================================
--- trunk/tests/scanner/annotation.c (original)
+++ trunk/tests/scanner/annotation.c Thu Oct 16 19:34:39 2008
@@ -112,9 +112,9 @@
* annotation_object_calleeowns:
* @object: a #GObject
*
- * This is a test for out arguments
+ * This is a test for out arguments; GObject defaults to transfer
*
- * @toown: (out) (transfer): a #GObject
+ * @toown: (out): a #GObject
* Return value: an int
*/
gint
@@ -128,10 +128,10 @@
* annotation_object_calleesowns:
* @object: a #GObject
*
- * This is a test for out arguments
+ * This is a test for out arguments, one transferred, other not
*
* @toown1: (out) (transfer): a #GObject
- * @toown2: (out) (transfer): a #GObject
+ * @toown2: (out) (transfer none): a #GObject
* Return value: an int
*/
gint
@@ -249,6 +249,20 @@
GObject*
annotation_object_allow_none (AnnotationObject *object, gchar *somearg)
{
+ return NULL;
+}
+
+/**
+ * annotation_object_notrans:
+ * @object: a #GObject
+ *
+ * Returns: (transfer none): An object, not referenced
+ **/
+
+GObject*
+annotation_object_notrans (AnnotationObject *object)
+{
+ return NULL;
}
/**
Modified: trunk/tests/scanner/annotation.h
==============================================================================
--- trunk/tests/scanner/annotation.h (original)
+++ trunk/tests/scanner/annotation.h Thu Oct 16 19:34:39 2008
@@ -24,6 +24,7 @@
GObject* annotation_object_create_object(AnnotationObject *object);
GObject* annotation_object_allow_none (AnnotationObject *object,
gchar *somearg);
+GObject* annotation_object_notrans (AnnotationObject *object);
gint annotation_object_inout (AnnotationObject *object,
int *inoutarg);
gint annotation_object_inout2 (AnnotationObject *object,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]