Commits

Ronald Oussoren committed 7d94096

- Clarification of some comments
- Fix bug where takeing the repr of an unbound method would cause a core-dump
- Add testcase for the above bug

Comments (0)

Files changed (7)

pyobjc/Lib/objc/__init__.py

 """
 
 ##
-## Disable gc -- blows up w/Python 2.2
+## Disable gc -- blows up w/Python 2.2.0
 ##
+## XXX Fix me: This is probably a bug in PyObjC, need to check why this
+## fails on Python 2.2.0 and not on Python 2.2.2. Copying gcmodule.c from
+## Python 2.2.2 to 2.2.0 causes the crash to go away...
 import sys
 if sys.version_info[:3] == (2,2,0):
     import gc
 
 from _objc import *
 from _objc import __version__
+import _FoundationSignatures
 
 # Import values used to define signatures
 import _objc
 # methods in the Foundation framework. Doing it here
 # is ugly, but it is also something that would be very
 # hard to avoid...
-try:
-    import _FoundationSignatures
-    del _FoundationSignatures
-except ImportError:
-    pass
 
 try:
     import _FoundationMapping
 except ImportError:
     pass
 
-# This is a hack, should probably patch python:
-# - We want the resources directory to be on the python search-path
-# - It must be at the start of the path
-# - The CWD must not be on the path
-if 1 :
-    b = lookUpClass('NSBundle').mainBundle()
-    if b:
-        sys.path.insert(0, '%s/Contents/Resources'%str(b.bundlePath()))
-    del b
 del sys, __builtin__

pyobjc/Lib/objc/test/test_subclass.py

         except objc.error, msg:
             self.assertEquals(str(msg), "Class already exists in Objective-C runtime")
 
+class TestSelectors(unittest.TestCase):
+    def testSelectorRepr(self):
+        class SelectorRepr(NSObject):
+            def foo(self):
+                pass
+
+        self.assert_(repr(SelectorRepr.foo) == '<unbound selector foo of SelectorRepr>')
+
+
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(TestSubclassing))
+    suite.addTest(unittest.makeSuite(TestSelectors))
     return suite
 
 if __name__ == '__main__':

pyobjc/Modules/objc/OC_PythonDictionary.m

 		return nil;
 	}
 
-	/* PyMapping_GetItemString exists, but no PyMapping_GetItem */
+	/* XXX: PyMapping_GetItemString exists, but no PyMapping_GetItem */
 #if 0
 	v = PyMapping_GetItem([self pyObject], k);
 #else
 		return;
 	}
 
-	/* PyMapping_SetItemString exists, but no PyMapping_SetItem */
+	/* XXX: PyMapping_SetItemString exists, but no PyMapping_SetItem */
 	if (PyDict_SetItem([self pyObject], k, v) < 0) {
 		Py_DECREF(v);
 		Py_DECREF(k);
 
 -keyEnumerator
 {
+	/* XXX: Should replace this by a custom enumerator, the current 
+	 *      version is leaking memory!
+	 */
+
 	PyObject* keys = PyMapping_Keys([self pyObject]);
 	id result = [OC_PythonArray newWithPythonObject:keys];
 	Py_DECREF(keys);
-	[result retain]; /* XXX leaking!!! */
+
+	[result retain]; 
 
 	return [result objectEnumerator];
 }

pyobjc/Modules/objc/class-builder.m

 
 			}
 
+			if (sel->sel_class == NULL) {
+				sel->sel_class = &new_class->class;
+			}
+
 			if (meth->method_imp == NULL) {
 				goto error_cleanup;
 			}

pyobjc/Modules/objc/objc-class.m

 		return NULL;
 	}
 	Py_DECREF(item); 
-	/* Py_INCREF(class); XXX Needed? */
+	// Py_INCREF(class); // XXX Needed?
 	return info;
 }
 

pyobjc/Modules/objc/objc-object.m

 {
 	PyObject* result;
 
-	ObjCClass_CheckMethodList(obj->ob_type);
+	ObjCClass_CheckMethodList((PyObject*)obj->ob_type);
 
 	result = PyObject_GenericGetAttr(obj, name);
 	if (result) return result;

pyobjc/Modules/objc/selector.m

 		cur = PyCObject_AsVoidPtr(
 			PyList_GetItem(replacement_signatures, i));
 
-	
 		if (cur->selector != selector) {
 			continue;
 		}
 		Py_DECREF(arglist);
 	}
 
+#if 0
+	/* There are some issues with this code, Bill doesn't like it while
+	 * Ronald does.
+	 */
 	if (res && ObjCObject_Check(res) && 
 			(self->sel_flags & ObjCSelector_kDONATE_REF)) {
 		/* Ownership transfered to us, but 'execute' method has
 		 * increased retainCount, the retainCount is now one too high
 		 */
 		id obj = ObjCObject_GetObject(res);
-    		/*[ObjCObject_GetObject(res) release]; XXX */
+    		[ObjCObject_GetObject(res) release];
 	}
+#endif
 	return res;
 }
 
 		}
 	}
 	result->sel_self = NULL;
+	result->sel_class = NULL;
 	result->sel_flags = 0;
 	result->callable = callable;
 	if (class_method) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.