Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/ChangeLog,v
retrieving revision 1.690
diff -u -p -r1.690 ChangeLog
--- ChangeLog	19 Dec 2003 08:07:55 -0000	1.690
+++ ChangeLog	20 Dec 2003 13:01:06 -0000
@@ -1,3 +1,16 @@
+2003-12-20  Gustavo J. A. M. Carneiro  <gustavo@users.sourceforge.net>
+
+	* codegen/codegen.py (Wrapper.get_initial_constructor_substdict):
+	now receives the constructor FunctionDef as argument.
+	(Wrapper.write_constructor): Pass the constructor
+	get_initial_constructor_substdict.
+	(GObjectWrapper.get_initial_constructor_substdict): Receive/pass
+	constructor argument. If constructor's caller_owns_return flag is
+	set to #f, add an extra g_object_ref(self->obj).
+	(GBoxedWrapper.get_initial_constructor_sub): Receive/pass extra
+	constructor argument.
+	(GPointerWrapper.get_initial_constructor_substdict): idem.
+
 2003-12-17  James Henstridge  <james@daa.com.au>
 
 	* gtk/gtk-types.defs (TextSearchFlags): GtkTextSearchFlags is a
Index: codegen/codegen.py
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/codegen/codegen.py,v
retrieving revision 1.62
diff -u -p -r1.62 codegen.py
--- codegen/codegen.py	19 Dec 2003 08:07:56 -0000	1.62
+++ codegen/codegen.py	20 Dec 2003 13:01:07 -0000
@@ -159,7 +159,7 @@ class Wrapper:
 
     def get_initial_class_substdict(self): return {}
 
-    def get_initial_constructor_substdict(self):
+    def get_initial_constructor_substdict(self, constructor):
         return { 'name': '%s.__init__' % self.objinfo.c_name,
                  'errorreturn': '-1' }
     def get_initial_method_substdict(self, method):
@@ -286,7 +286,7 @@ class Wrapper:
                     code = self.write_function_wrapper(constructor,
                         self.constructor_tmpl,
                         handle_return=0, is_method=0, kwargs_needed=1,
-                        substdict=self.get_initial_constructor_substdict())[0]
+                        substdict=self.get_initial_constructor_substdict(constructor))[0]
                     self.fp.write(code)
                 initfunc = '_wrap_' + constructor.c_name
             except:
@@ -483,14 +483,17 @@ class GObjectWrapper(Wrapper):
         castmacro = string.replace(self.objinfo.typecode, '_TYPE_', '_', 1)
         return '%s(pygobject_get(self))->%s' % (castmacro, fieldname)
 
-    def get_initial_constructor_substdict(self):
-        substdict = Wrapper.get_initial_constructor_substdict(self)
+    def get_initial_constructor_substdict(self, constructor):
+        substdict = Wrapper.get_initial_constructor_substdict(self, constructor)
         if argtypes.matcher.object_is_a(self.objinfo.c_name, 'GtkWindow'):
             substdict['aftercreate'] = "    g_object_ref(self->obj); /* we don't own the first reference of windows */\n"
         elif argtypes.matcher.object_is_a(self.objinfo.c_name, 'GtkInvisible'):
             substdict['aftercreate'] = "    g_object_ref(self->obj); /* we don't own the first reference of invisibles */\n"
-        else:
-            substdict['aftercreate'] = ''
+	else:
+	    if not constructor.caller_owns_return:
+		substdict['aftercreate'] = "    g_object_ref(self->obj);\n"
+	    else:
+		substdict['aftercreate'] = ''
         return substdict
 
     def get_initial_method_substdict(self, method):
@@ -550,8 +553,8 @@ class GBoxedWrapper(Wrapper):
     def get_field_accessor(self, fieldname):
         return 'pyg_boxed_get(self, %s)->%s' % (self.objinfo.c_name, fieldname)
 
-    def get_initial_constructor_substdict(self):
-        substdict = Wrapper.get_initial_constructor_substdict(self)
+    def get_initial_constructor_substdict(self, constructor):
+        substdict = Wrapper.get_initial_constructor_substdict(self, constructor)
         substdict['typecode'] = self.objinfo.typecode
         return substdict
 
@@ -592,8 +595,8 @@ class GPointerWrapper(GBoxedWrapper):
     def get_field_accessor(self, fieldname):
         return 'pyg_pointer_get(self, %s)->%s' % (self.objinfo.c_name, fieldname)
 
-    def get_initial_constructor_substdict(self):
-        substdict = Wrapper.get_initial_constructor_substdict(self)
+    def get_initial_constructor_substdict(self, constructor):
+        substdict = Wrapper.get_initial_constructor_substdict(self, constructor)
         substdict['typecode'] = self.objinfo.typecode
         return substdict
 
