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

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Mon May  5 11:14:13 2008
New Revision: 2000

Log:
Adds OC_PythonSet, a subclass of NSMutableSet that is used to wrap
set() and frozenset().  Includes full unittests.

Also fixes a number of bugs in OC_PythonEnumerator.


Added:
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_set_proxy.py   (contents, props changed)
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonSet.h   (contents, props changed)
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonSet.m
   trunk/pyobjc/pyobjc-core/Modules/objc/test/pythonset.m
Modified:
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonEnumerator.m
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.h
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.h
   trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.m
   trunk/pyobjc/pyobjc-core/Modules/objc/pyobjc.h
   trunk/pyobjc/pyobjc-core/NEWS.txt

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonEnumerator.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonEnumerator.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonEnumerator.m	Mon May  5 11:14:13 2008
@@ -28,25 +28,31 @@
 
 -nextObject
 {
-	if (!valid) return nil;
+	if (!valid) {
+		return nil;
+	}
 
 	NSObject* result = nil;
 
 	PyObjC_BEGIN_WITH_GIL
 		PyObject* object = PyIter_Next(value);
 		if (object == NULL) {
-			if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
+			if (!PyErr_Occurred()) {
 				valid = NO;
 				PyErr_Clear();
 				PyObjC_GIL_RETURN(nil);
+			} else {
+				PyObjC_GIL_FORWARD_EXC();
 			}
 
-			PyObjC_GIL_FORWARD_EXC();
-
 		}
 		result = PyObjC_PythonToId(object);
 		if (result == nil) {
-			PyObjC_GIL_FORWARD_EXC();
+			if (PyErr_Occurred()) {
+				PyObjC_GIL_FORWARD_EXC();
+			} else {
+				PyObjC_GIL_RETURN([NSNull null]);
+			}
 		}
 
 	PyObjC_END_WITH_GIL

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.h	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonNumber.h	Mon May  5 11:14:13 2008
@@ -3,13 +3,6 @@
 @interface OC_PythonNumber : NSNumber
 {
 	PyObject* value;
-#if 0
-	union {
-		long long 		as_longlong;
-		unsigned long long 	as_ulonglong;
-		double    		as_double;
-	}	c_value;
-#endif
 }
 
 + newWithPythonObject:(PyObject*)value;

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.h	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/OC_PythonObject.h	Mon May  5 11:14:13 2008
@@ -30,6 +30,7 @@
 
 extern PyObject* PyObjC_Encoder;
 extern PyObject* PyObjC_Decoder;
+extern PyObject* PyObjC_CopyFunc;
 
 extern void PyObjC_encodeWithCoder(PyObject* pyObject, NSCoder* coder);
 

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	Mon May  5 11:14:13 2008
@@ -167,6 +167,16 @@
 		} else {
 			r = -1;
 		}
+
+	} else if (PyAnySet_Check(argument)) {
+		rval = [OC_PythonSet newWithPythonObject:argument];
+		if (rval) {
+			PyObjC_RegisterObjCProxy(argument, rval);
+			r = 0;
+		} else {
+			r = -1;
+		}
+
 	} else if ((rval = PyObjC_CFTypeToID(argument))) {
 		// unwrapped cf
 		r = 0;
@@ -267,6 +277,16 @@
 			PyObjC_GIL_FORWARD_EXC();
 		}
 		
+		/* Check if the object is "set-like" */
+		instance = [OC_PythonSet depythonifyObject:obj];
+		if (instance != nil) {
+			PyObjC_RegisterObjCProxy(obj, instance);
+			PyObjC_GIL_RETURN(instance);
+		} 
+		if (PyErr_Occurred()) {
+			PyObjC_GIL_FORWARD_EXC();
+		}
+
 		/* Check if the object is "datetime-like" */
 		instance = [OC_PythonDate depythonifyObject:obj];
 		if (instance != nil) {

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	Mon May  5 11:14:13 2008
@@ -38,6 +38,7 @@
 #include "OC_PythonEnumerator.h"
 #include "OC_PythonDate.h"
 #include "OC_PythonNumber.h"
+#include "OC_PythonSet.h"
 #include "method-signature.h"
 #include "objc_util.h"
 #include "objc-class.h"

Modified: trunk/pyobjc/pyobjc-core/NEWS.txt
==============================================================================
--- trunk/pyobjc/pyobjc-core/NEWS.txt	(original)
+++ trunk/pyobjc/pyobjc-core/NEWS.txt	Mon May  5 11:14:13 2008
@@ -30,7 +30,6 @@
   instances before using them from Objective-C (such as using an 
   ``NSDateFormatter``)
 
-- There is experimental support for archiving Python objects 
   using an ``NSKeyedArchiver``. 
 
 - Objective-C classes that support the ``NSCopying`` protocol can now be
@@ -93,7 +92,9 @@
     This is used instead of ``NSNumber`` because we might loose information
     otherwise (such as when using custom subclasses of ``int``).
 
-  * ``OC_PythonSet``: wraps a python set
+  * ``OC_PythonSet``: wraps a python set and is a subclass of ``NSMutableSet``
+
+- BUGFIX: ``OC_PythonEnumerator`` now actually works.
 
 - BUGFIX: using the ``@throw`` syntax one can raise arbitrary objects as
   exceptions (not just instances of NSException) in Objective-C. All 

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
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.