[PyObjC-svn] r2060 - in trunk/pyobjc/pyobjc-core: Lib/objc/test Modules/objc

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Fri Feb 27 00:36:22 2009
New Revision: 2060

Log:
* Fix a number of small issues, all unittests now pass
* Remove picklercoder code, that was a very incomplete attempt
  at pickling objc objects. 
  
  Code dropped because it is unused, incomplete and
  I ran into serious incompatibilities between the way
  NSCoder and pickle work conceptually that will make
  it almost(?) impossible to complete the implementation
* Ensure that Modules/objc/*.m compiles without warnings 
  on Leopard


Removed:
   trunk/pyobjc/pyobjc-core/Modules/objc/picklecoder.h
   trunk/pyobjc/pyobjc-core/Modules/objc/picklecoder.m
Modified:
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.m
   trunk/pyobjc/pyobjc-core/Modules/objc/function.m
   trunk/pyobjc/pyobjc-core/Modules/objc/instance-var.m
   trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
   trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m
   trunk/pyobjc/pyobjc-core/Modules/objc/objc_inject.m
   trunk/pyobjc/pyobjc-core/Modules/objc/objc_super.m
   trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h
   trunk/pyobjc/pyobjc-core/Modules/objc/unicode-object.m

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_number_proxy.py	Fri Feb 27 00:36:22 2009
@@ -195,9 +195,18 @@
 
     def testClasses(self):
         # Ensure that python numbers are proxied using the right proxy type
-        for v in (True, False, 0, 1, 2**32+1, 2**64+1, 42.5):
+        for v in (0, 1, 2**32+1, 2**64+1, 42.5):
             self.assert_(OC_TestNumber.numberClass_(v) is OC_PythonNumber)
 
+        # The booleans True and False must be proxied as the corresponding
+        # NSNumber constants, otherwise lowlevel Cocoa/CoreFoundation code
+        # get's upset.
+        boolClass = objc.lookUpClass('NSCFBoolean')
+        for v in (True, False):
+            self.assert_(OC_TestNumber.numberClass_(v) is boolClass)
+            self.assert_(objc.repythonify(v) is v)
+
+
     def testPythonIntConversions(self):
         # Conversions to other values. Note that values are converted
         # using C casts, without any exceptions when converting a
@@ -420,11 +429,11 @@
 
         v = OC_TestNumber.numberDescription_(False)
         self.assert_(isinstance(v, unicode))
-        self.assertEquals(v, u"False")
+        self.assertEquals(v, u"0")
 
         v = OC_TestNumber.numberDescription_(True)
         self.assert_(isinstance(v, unicode))
-        self.assertEquals(v, u"True")
+        self.assertEquals(v, u"1")
 
 class TestInteractions (TestCase):
     # Test interactions between Python and NSNumber numbers

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py	Fri Feb 27 00:36:22 2009
@@ -243,8 +243,5 @@
             # cause a warning when called.
             self.assertEquals(1, 0)
 
-        def test_Missing(self):
-            self.fail("Implement test for class that doesn't implement a formal protocl, seems to be missing")
-
 if __name__ == '__main__':
     main()

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.m	Fri Feb 27 00:36:22 2009
@@ -111,12 +111,15 @@
 			r = -1;
 		}
 	} else if (PyBool_Check(argument)) {
+		/* This is needed because some low-level API's behaves
+		 * differently with [NSNumber numberWithBool:] than 
+		 * [NSNumber numberWithInt:]
+		 */
 		if (argument == Py_True) {
 			rval = [NSNumber numberWithBool:1];
 		} else  {
 			rval = [NSNumber numberWithBool:0];
 		}
-		//rval = [OC_PythonNumber newWithPythonObject:argument]; 
 		PyObjC_RegisterObjCProxy(argument, rval);
 		r = 0;
 

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/function.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/function.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/function.m	Fri Feb 27 00:36:22 2009
@@ -151,7 +151,7 @@
 		return NULL;
 	}
 
-	variadicAllArgs = self->methinfo->variadic && (self->methinfo->null_terminated_array || self->methinfo->arrayArg != -1);
+	variadicAllArgs |= self->methinfo->variadic && (self->methinfo->null_terminated_array || self->methinfo->arrayArg != -1);
 
 	if (variadicAllArgs) {
 		if (byref_in_count != 0 || byref_out_count != 0) {

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/instance-var.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/instance-var.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/instance-var.m	Fri Feb 27 00:36:22 2009
@@ -166,7 +166,8 @@
 	}
 	
 	NSString* ocName = [NSString stringWithUTF8String:self->name];
-	[objc willChangeValueForKey:ocName];
+
+	// [objc willChangeValueForKey:ocName];
 
 	if (self->isSlot) {
 		PyObject** slotval = (PyObject**)(
@@ -175,7 +176,7 @@
 		Py_XDECREF(*slotval);
 		*slotval = value;
 
-		[objc didChangeValueForKey:ocName];
+		// [objc didChangeValueForKey:ocName];
 		return 0;
 	}
 
@@ -185,7 +186,7 @@
 
 		res = depythonify_c_value(@encode(id), value, &new_value);
 		if (res == -1) {
-			[objc didChangeValueForKey:ocName];
+			// [objc didChangeValueForKey:ocName];
 			return -1;
 		}
 
@@ -200,24 +201,24 @@
 		}
 
 		object_setIvar(objc, var, new_value);
-		[objc didChangeValueForKey:ocName];
+		// [objc didChangeValueForKey:ocName];
 
 		return 0;
 	}
 
 	size = PyObjCRT_SizeOfType(ivar_getTypeEncoding(var));
 	if (size == -1) {
-		[objc didChangeValueForKey:ocName];
+		// [objc didChangeValueForKey:ocName];
 		return -1;
 	}
 	res = depythonify_c_value(ivar_getTypeEncoding(var), value, 
 		(void*)(((char*)objc)+ivar_getOffset(var)));
 	if (res == -1) {
-		[objc didChangeValueForKey:ocName];
+		// [objc didChangeValueForKey:ocName];
 		return -1;
 	}
 
-	[objc didChangeValueForKey:ocName];
+	// [objc didChangeValueForKey:ocName];
 	return 0;
 }
 

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m	Fri Feb 27 00:36:22 2009
@@ -910,7 +910,7 @@
 	PyObjCMethodSignature* methinfo,
 	PyObject* argtuple, Py_ssize_t argoffset,
 	void** byref,
-	ffi_type** arglist, void** values, int count)
+	ffi_type** arglist, void** values, Py_ssize_t count)
 {
 	Py_ssize_t curarg = methinfo->ob_size-1;
 	Py_ssize_t maxarg = PyTuple_Size(argtuple);
@@ -918,7 +918,7 @@
 
 	if (count != -1) {
 		if (maxarg - curarg != count) {
-			PyErr_Format(PyExc_ValueError, "Wrong number of variadic arguments, need %d, got %d",
+			PyErr_Format(PyExc_ValueError, "Wrong number of variadic arguments, need %" PY_FORMAT_SIZE_T "d, got %" PY_FORMAT_SIZE_T "d",
 					count, (maxarg - curarg));
 			return -1;
 		}

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc-object.m	Fri Feb 27 00:36:22 2009
@@ -19,7 +19,7 @@
  * XXX: for reasons beyond my current comprehension the "legacy" block must be active, otherwise we
  * get a fatal python error.
  */
-#if 1 || !defined(MAC_OS_X_VERSION_MIN_REQUIRED) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3
+#if !defined(MAC_OS_X_VERSION_MIN_REQUIRED) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3
 
 /* Deal with platforms that don't support KVO */
 
@@ -61,9 +61,9 @@
 _UseKVO(NSObject *self, NSString *key, BOOL willChange)
 {           
     PyObjC_DURING
-        if ([key characterAtIndex:0] == (unichar)'_') return;
-
-        if (willChange) {
+        if ([key characterAtIndex:0] == (unichar)'_') {
+	    /* pass */
+	} else if (willChange) {
             [self willChangeValueForKey:key];
         } else {
             [self didChangeValueForKey:key];

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc_inject.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc_inject.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc_inject.m	Fri Feb 27 00:36:22 2009
@@ -244,13 +244,16 @@
 INJECT_test_func(void) {
 }
 
+#if defined (__i386__)
+extern void __pthread_set_self(char*);
+#endif
+
 static void
 INJECT_ENTRY(ptrdiff_t codeOffset, objc_inject_param *param, size_t paramSize __attribute__((__unused__)), char *dummy_pthread_struct __attribute__((__unused__))) {
 #if defined (__i386__)
 	// On intel, per-pthread data is a zone of data that must be allocated.
 	// if not, all function trying to access per-pthread data (all mig functions for instance)
 	// will crash. 
-	extern void __pthread_set_self(char*);
 	__pthread_set_self(dummy_pthread_struct);
 #endif
 	func_wrappers *f = &param->f;

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc_super.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc_super.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc_super.m	Fri Feb 27 00:36:22 2009
@@ -148,4 +148,11 @@
 	PyType_GenericAlloc,			/* tp_alloc */
 	PyType_GenericNew,			/* tp_new */
 	PyObject_GC_Del,        		/* tp_free */
+	0,					/* tp_is_gc */
+	0,					/* tp_bases */
+	0,					/* tp_mro */
+	0,					/* tp_cache */
+	0,					/* tp_mro */
+	0,					/* tp_weaklist */
+	0,					/* tp_del */
 };

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h	Fri Feb 27 00:36:22 2009
@@ -62,7 +62,6 @@
 #include "varlist.h"
 #include "parsexml.h"
 #include "objc_super.h"
-#include "picklecoder.h"
 
 
 /*

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/unicode-object.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/unicode-object.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/unicode-object.m	Fri Feb 27 00:36:22 2009
@@ -226,7 +226,7 @@
 	PyObjCUnicodeObject* result;
 // XXX - I don't know how to get gcc to let me use sizeof(unichar)
 #ifdef PyObjC_UNICODE_FAST_PATH
-	int length = [value length];
+	Py_ssize_t length = [value length];
 	result = PyObject_New(PyObjCUnicodeObject, &PyObjCUnicode_Type);
 	PyUnicode_AS_UNICODE(result) = PyMem_NEW(Py_UNICODE, length);
 	if (PyUnicode_AS_UNICODE(result) == NULL) {

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
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.