Commits

Ronald Oussoren committed 5ba20e6

- Add more news
- Make sure the return value is not deallocated before the caller can get its
hands on it. Perform '[[value retain] autorelease]' iff the Python version of
value has a refcnt of 1 (meaning it will get deallocated after at the end
of the conversion).
- Actually convert the return value for calls to python of methods with
pass-by-reference output arguments. (E.g. unittests are not complete)
- Fix for WebServicesTool, seems to work just fine on my system.

BTW. While working on de WebServicesTool I noticed that I cannot edit python
files in PB, double-clicking starts PythonLauncher!

  • Participants
  • Parent commits 11def37

Comments (0)

Files changed (6)

pyobjc/Examples/WebServicesTool/WSTConnectionWindowControllerClass.py

     generically useful toolbar management untility.
     """
     toolbarItem = NSToolbarItem.alloc().initWithItemIdentifier_(anIdentifier)
-    toolbarItem.autorelease()
     
     toolbarItem.setLabel_(aLabel)
     toolbarItem.setPaletteLabel_(aPaletteLabel)
         toolbarItem.setMaxSize_( maxSize )
         
     if aMenu:
-        menuItem = NSMenuItem.alloc().init().autorelease()
+        menuItem = NSMenuItem.alloc().init()
         menuItem.setSubmenu_(aMenu)
         menuItem.setTitle_( aMenu.title() )
         toolbarItem.setMenuFormRepresentation_(menuItem)
         """
         Create and return a default connection window instance.
         """
-        return WSTConnectionWindowController.alloc().init().autorelease()
+        return WSTConnectionWindowController.alloc().init()
            
     def init(self):
         """
         """
         Creates and configures the toolbar to be used by the window.
         """
-        toolbar = NSToolbar.alloc().initWithIdentifier_("WST Connection Window").autorelease()
+        toolbar = NSToolbar.alloc().initWithIdentifier_("WST Connection Window")
         toolbar.setDelegate_(self)
         toolbar.setAllowsUserCustomization_(YES)
         toolbar.setAutosavesConfiguration_(YES)
         newItem = NSToolbarItem.alloc().initWithItemIdentifier_(itemIdentifier)
         item = self._toolbarItems.objectForKey_(itemIdentifier)
         
-        newItem.autorelease()
-        
         newItem.setLabel_( item.label() )
         newItem.setPaletteLabel_( item.paletteLabel() )
         if item.view():
             return aMethod
 
     ### adjust method decls to be in line with ObjC requirements
-    connectionWindowController = selector(connectionWindowController, class_method=1)
+    connectionWindowController = selector(connectionWindowController, isClassMethod=1)
     """
     Declares that the method connectionWindowController is actually a
     class method.  This is the one piece of non-automatic glue

pyobjc/Lib/PyObjCTools/test/test_collections.py

         self.assertSameArrayContents(d1.keys(), d2.keys())
 
         for k in d1:
+            self.assert_(d1.has_key(k), "Missing key %s in %s"%(`k`, `d1`))
+            self.assert_(d2.has_key(k), "Missing key %s in %s"%(`k`, `d2`))
             self.assertEqual(d1[k], d2[k],
                              "assertSameDictionary() failed for key '%s'. [%s != %s]" % (k, d1[k], d2[k]))
         for k in d2:
+            self.assert_(d1.has_key(k), "Missing key %s in %s"%(`k`, `d1`))
+            self.assert_(d2.has_key(k), "Missing key %s in %s"%(`k`, `d2`))
             self.assertEqual(d1[k], d2[k],
                              "assertSameDictionary() failed for key '%s'. [%s != %s]" % (k, d1[k], d2[k]))
                              

pyobjc/Modules/objc/libffi_support.m

 		if (*rettype != _C_VOID) {
 			const char* rettype = [methinfo methodReturnType];
 			err = depythonify_c_return_value(rettype, res, resp);
+
+			if (*rettype == _C_ID && res->ob_refcnt == 1) {
+				/* make sure return value doesn't die before
+				 * the caller can get its hands on it.
+				 */
+				[[(*(id*)resp) retain] autorelease];
+			}
 			Py_DECREF(res);
 			if (err == -1) {
 				ObjCErr_ToObjC();
 			ObjCErr_Set(PyExc_TypeError,
 				"%s: Need tuple of %d arguments as result",
 				SELNAME(*(SEL*)args[1]), have_output+1);
+			Py_DECREF(res);
 			ObjCErr_ToObjC();
 		}
 
 
 			v = PyTuple_GET_ITEM(res, idx++);
 			err = depythonify_c_value(argtype, v, args[i]);
-			Py_DECREF(res);
 			if (err == -1) {
 				ObjCErr_ToObjC();
 			}
 		}
 
+		if (*rettype != _C_VOID) {
+			const char* rettype = [methinfo methodReturnType];
+			int err = depythonify_c_return_value(rettype, real_res, resp);
+
+			if (*rettype == _C_ID && real_res->ob_refcnt == 1) {
+				/* make sure return value doesn't die before
+				 * the caller can get its hands on it.
+				 */
+				[[(*(id*)resp) retain] autorelease];
+			}
+			if (err == -1) {
+				Py_DECREF(res);
+				ObjCErr_ToObjC();
+			}
+		}
+
+		Py_DECREF(res);
+
 	}
 }
 

pyobjc/Modules/objc/method-accessor.m

 	if (strcmp(name, "__class__") == 0) {
 		/* Someone does 'type(object.pybojc_instanceMethods)' */
 		Py_INCREF(self->ob_type);
-		return self->ob_type;
+		return (PyObject*)self->ob_type;
 	}
 
 	if (name[0] == '_' && name[1] == '_') {

pyobjc/Modules/objc/selector.m

 /* Ronald: This is probably a bit too much documentation... */
 PyDoc_STRVAR(base_selector_type_doc,
 "selector(function, [, signature] [, selector] [, isClassMethod=0]\n"
-"    [, returnType] [, argumentTypes] [, required=True]) -> selector\n"
+"    [, returnType] [, argumentTypes] [, isRequired=True]) -> selector\n"
 "\n"
 "Return an Objective-C method from a function. The other arguments \n"
 "specify attributes of the Objective-C method.\n"
 - The InterfaceBuilder, PreferencePanes and ScreenSaver frameworks have been
   wrapped.
 
+- Management of reference counts is now completely automatic, it is no longer
+  necessary to manually compensate for the higher reference count of objects 
+  returned by the alloc, copy and copyWithZone: class methods.
+
+- Various function and keyword arguments have been renamed for a better 
+  integration with Cocoa. A partial list is of the changed names is:
+  	objc.lookup_class -> objc.lookUpClass
+	objc.selector arguments/attributes:
+		is_initializer -> isInitializer
+		is_allocator -> isAlloc
+		donates_ref -> doesDonateReference
+		is_required -> isRequired
+		class_method -> isClassMethod
+		defining_class -> definingClass
+		returns_self -> returnsSelf
+		argument_types -> argumentTypes
+		return_type -> returnType
+	objc.get_class_list -> objc.getClassList
+
+- On Python 2.2, objc.YES and objc.NO are instances of a private boolean type,
+  on Python 2.3 these are instances of the builtin type bool.
+
+
 Version 0.8 (Dec-10-2002):
 
 - GNUStep support has been removed for lack of support.  Volunteers