[PyObjC-svn] r2122 - in trunk/pyobjc/pyobjc-core: . Lib/PyObjCTools Lib/objc/test Modules/objc

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Fri Mar 27 11:41:00 2009
New Revision: 2122

Log:
Fix small annoyance with implementing -copyWithZone:


Modified:
   trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_copying.py
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_splitsig.py
   trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
   trunk/pyobjc/pyobjc-core/Modules/objc/selector.m
   trunk/pyobjc/pyobjc-core/setup.py

Modified: trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py	Fri Mar 27 11:41:00 2009
@@ -137,6 +137,15 @@
         if value is None:
             sel.fail(message, "%r is not %r"%(value, test))
 
+    def failUnlessArgIsNullTerminated(self, method, argno, message = None):
+        if isinstance(method, objc.selector):
+            offset = 2
+        else:
+            offset = 0
+        info = method.__metadata__()
+        if not info['arguments'][argno+offset].get('c_array_delimited_by_null'):
+            self.fail(message or "argument %d of %r is not a nul-terminated array"%(argno, method))
+
     def failUnlessArgIsPrintf(self, method, argno, message = None):
         if isinstance(method, objc.selector):
             offset = 2
@@ -205,6 +214,36 @@
             self.fail(message or "arg %d of %s is not of type %r, but %r"%(
                 argno, method, tp, type))
 
+    def failUnlessArgIsFunction(self, method, argno, sel_type, retained, message=None):
+        if isinstance(method, objc.selector):
+            offset = 2
+        else:
+            offset = 0
+        info = method.__metadata__()
+        type = info['arguments'][argno+offset]['type']
+        if type != '^?':
+            self.fail(message or "arg %d of %s is not of type function_pointer"%(
+                argno, method))
+
+        st = info['arguments'][argno+offset].get('callable')
+        if st is None:
+            self.fail(message or "arg %d of %s is not of type function_pointer"%(
+                argno, method))
+
+        iface = st['retval']['type']
+        for a in st['arguments']:
+            iface += a['type']
+
+        if iface != sel_type:
+            self.fail(message or "arg %d of %s is not a function_pointer with type %r, but %r"%(argno, method, sel_type, iface))
+
+
+        st = info['arguments'][argno+offset]['callable_retained']
+        if bool(st) != bool(retained):
+            self.fail(message or "arg %d of %s; retained: %r, expected: %r"%(
+                argno, method, st, retained))
+
+
     def failUnlessArgIsSEL(self, method, argno, sel_type, message=None):
         if isinstance(method, objc.selector):
             offset = 2
@@ -216,10 +255,10 @@
             self.fail(message or "arg %d of %s is not of type SEL"%(
                 argno, method))
 
-        st = info['arguments'][argno+offset]['sel_of_type']
+        st = info['arguments'][argno+offset].get('sel_of_type')
         if st != sel_type:
             self.fail(message or "arg %d of %s doesn't have sel_type %r but %r"%(
-                argno, method, sel_type, info['arguments'][argno+offset]['sel_of_type']))
+                argno, method, sel_type, st))
 
     def failUnlessResultIsBOOL(self, method, message=None):
         info = method.__metadata__()
@@ -239,6 +278,29 @@
             self.fail(message or "arg %d of %s is not of type BOOL"%(
                 argno, method))
 
+    def failUnlessArgIsFixedSize(self, method, argno, count, message=None):
+        if isinstance(method, objc.selector):
+            offset = 2
+        else:
+            offset = 0
+        info = method.__metadata__()
+        cnt = info['arguments'][argno+offset]['c_array_of_fixed_length']
+        if cnt != count:
+            self.fail(message or "arg %d of %s is not a C-array of length %d"%(
+                argno, method, count))
+
+    def failUnlessArgSizeInArg(self, method, argno, count, message=None):
+        if isinstance(method, objc.selector):
+            offset = 2
+        else:
+            offset = 0
+        info = method.__metadata__()
+        cnt = info['arguments'][argno+offset]['c_array_length_in_arg']
+        if cnt != count + offset:
+            self.fail(message or "arg %d of %s is not a C-array of with length in arg %d"%(
+                argno, method, count))
+
+
     def failUnlessArgIsOut(self, method, argno, message=None):
         if isinstance(method, objc.selector):
             offset = 2

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_copying.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_copying.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_copying.py	Fri Mar 27 11:41:00 2009
@@ -88,7 +88,16 @@
         other.z = "hello"
         return other
 
+class TestNSCopyingHelper (NSObject):
+    def copyWithZone_(self, zone):
+        return 42
+
 class TestNSCopying (TestCase):
+    def testCopyingRegr20090327(self):
+        o = TestNSCopyingHelper.alloc().init()
+        v = o.copyWithZone_(None)
+        self.failUnlessEqual(v, 42)
+
     def testCopyingWithoutSuperFromObjC(self):
         v = OC_TestCopy1.alloc().init()
         self.assert_(not v.copyWithZone_.isClassMethod)

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_splitsig.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_splitsig.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_splitsig.py	Fri Mar 27 11:41:00 2009
@@ -81,6 +81,7 @@
             "methodWithArg_",
             "myMethod",
             "twoargs",
+            "set_helper",
 
             # dictionary methods
             'get',

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m	Fri Mar 27 11:41:00 2009
@@ -1165,7 +1165,7 @@
 			if (sel->sel_class == NULL) {
 				sel->sel_class = new_class;
 			}
-		} /* XXX: else if (PyObjCIMP_Check(value)) { */
+		} /* XXX: else if (PyObjCIMP_Check(value)) */
 	}
 	Py_DECREF(key_list);
 	key_list = NULL;

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/selector.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/selector.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/selector.m	Fri Mar 27 11:41:00 2009
@@ -1887,7 +1887,13 @@
 		meth = class_getClassMethod(oc_class, selector);
 	} else {
 		meth = class_getInstanceMethod(oc_class, selector);
-		if (!meth) {
+		
+		if (!meth && !sel_isEqual(selector, @selector(copyWithZone:))) {
+		        /* Look for a classmethod, but don't do that for copyWithZone:
+			 * because that method is commonly defined in Python, and
+			 * overriding "NSObject +copyWithZone:" is almost certainly
+			 * not the intended behaviour.
+			 */
 			meth = class_getClassMethod(oc_class, selector);
 			if (meth) {
 				is_class_method = 1;

Modified: trunk/pyobjc/pyobjc-core/setup.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/setup.py	(original)
+++ trunk/pyobjc/pyobjc-core/setup.py	Fri Mar 27 11:41:00 2009
@@ -83,6 +83,10 @@
 # Enable 'PyObjC_STRICT_DEBUGGING' to enable some costly internal 
 # assertions. 
 CFLAGS=[
+    "-nostdinc",
+    "-isystem/usr/include",
+    "-isystem/usr/lib/gcc/i686-apple-darwin9/4.0.1/include",
+    "-iframework/System/Library/Frameworks",
     "-DPyObjC_STRICT_DEBUGGING",
     "-DMACOSX",
     "-no-cpp-precomp",

------------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.