Commits

Ronald Oussoren committed dce6d1c

* Fix a problem with compilation of libffi that I introduced in my previous checkin
* Explictly add '-fexceptions' to the compiler arguments (probably not needed)
* Fix some 64-bit issues (NSInteger vs. int issues)
* More serious: code sometimes looked at PyObjCObject fields without checking that
the object really is a PyObjCObject, even when objects can PyObjCClass instances.
This happens to work fine on all platforms but PPC64, but that's accidental.
* Enable '@try{' instead of 'NSDURING'

All of this is part of trying to get pyobjc-core going on a PPC64 system. Sadly
enough I now get a fatal error from the ObjC runtime because of an uncaught
exception, even though code is passing through an @try block that should catch
the exception.

Comments (0)

Files changed (20)

pyobjc-core/Modules/objc/OC_PythonData.m

 			PyErr_Clear();
 			rval = 0;
 		}
-		if ((unsigned)buffer_len > NSUIntegerMax) {
+		if ((NSUInteger)buffer_len > NSUIntegerMax) {
 			rval = NSUIntegerMax;
 		} else {
 			rval = buffer_len;

pyobjc-core/Modules/objc/OC_PythonDictionary.m

 	 * Forcefully disable coding for now, to avoid generating invalid
 	 * encoded streams.
 	 */        
+	//abort();
 	[NSException raise:NSInvalidArgumentException format:@"PyObjC: Encoding python objects of type %s is not supported", value->ob_type->tp_name, coder];
 }
 

pyobjc-core/Modules/objc/OC_PythonObject.m

         rval = PyObject_Hash([self pyObject]);
         if (rval == -1) {
             PyErr_Clear();
-            rval = (int)[self pyObject];
+            rval = (unsigned)[self pyObject];
         }
         PyObjC_GIL_RETURN((unsigned)rval);
     PyObjC_END_WITH_GIL

pyobjc-core/Modules/objc/OC_PythonString.h

  * Primitive NSString methods
  *
  */
--(unsigned)length;
--(unichar)characterAtIndex:(unsigned)index;
+-(NSUInteger)length;
+-(unichar)characterAtIndex:(NSUInteger)index;
 -(void)getCharacters:(unichar *)buffer range:(NSRange)aRange;
 
 @end

pyobjc-core/Modules/objc/formal-protocol.m

 	PyObject* args, PyObject* kwds)
 {
 static	char*	keywords[] = { "name", "supers", "selectors", NULL };
-	PyObjCFormalProtocol* result = NULL;
 	char* name;
 	PyObject* supers;
 	PyObject* selectors;
 	Py_ssize_t i, len;
+
+#ifndef __LP64__
+	PyObjCFormalProtocol* result = NULL;
 	Py_ssize_t numInstance = 0;
 	Py_ssize_t numClass = 0;
 	struct Protocol_struct* theProtocol = NULL;
 	struct objc_method_description* c;
+#endif
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "sOO:formal_protocol",
 			keywords, &name, &supers, &selectors)) { 

pyobjc-core/Modules/objc/libffi_support.m

 #    error "Need FFI_CLOSURES!"
 #endif
 
-#if 1 /* Usefull during debugging, only used in the debugger */
+#if 0 /* Usefull during debugging, only used in the debugger */
 static void describe_ffitype(ffi_type* type)
 {
 	switch (type->type) {
 		goto error_cleanup;
 	}
 
-	isUninitialized = ((PyObjCObject*)self)->flags  & PyObjCObject_kUNINITIALIZED;
-	((PyObjCObject*)self)->flags  &= ~PyObjCObject_kUNINITIALIZED;
+	if (PyObjCObject_Check(self)) {
+		isUninitialized = ((PyObjCObject*)self)->flags  & PyObjCObject_kUNINITIALIZED;
+		((PyObjCObject*)self)->flags  &= ~PyObjCObject_kUNINITIALIZED;
+	} else {
+		isUninitialized = NO;
+        }
 
 	if (methinfo->ob_size >= 3) {
 	}
 		}
 
 	PyObjC_HANDLER
+		NSLog(@"caught exception: %@", localException);
 		PyObjCErr_FromObjC(localException);
+
 	PyObjC_ENDHANDLER
 
-	if (isUninitialized) {
+	if (isUninitialized && PyObjCObject_Check(self)) {
 		((PyObjCObject*)self)->flags  |= PyObjCObject_kUNINITIALIZED;
 	}
 
 	const char* rettype;
 	ffi_status rv;
 	int i;
-	BOOL variadicAllArgs = NO;
 
 	rettype = methinfo->rettype.type;
 

pyobjc-core/Modules/objc/method-imp.m

 		pyres = pyself;
 	}
 
-	if (((PyObjCObject*)pyself)->flags & PyObjCObject_kUNINITIALIZED) {
+	if (PyObjCObject_Check(pyself) && (((PyObjCObject*)pyself)->flags & PyObjCObject_kUNINITIALIZED)) {
 		if (pyself != pyres && !PyErr_Occurred()) {
 			PyObjCObject_ClearObject(pyself);
 		}

pyobjc-core/Modules/objc/objc-object.m

      { 0, 0, 0, 0 },			/* as_buffer */
      0,					/* name */
      0,					/* slots */
-   }, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+   }, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
 /*

pyobjc-core/Modules/objc/objc_super.m

 	PyType_GenericAlloc,			/* tp_alloc */
 	PyType_GenericNew,			/* tp_new */
 	PyObject_GC_Del,        		/* tp_free */
+	1,					/* tp_is_gc */
 };

pyobjc-core/Modules/objc/objc_util.m

 ObjCErr_PyExcForName(const char* value)
 {
 	/* XXX: This table should be changeable from python */
+	printf("finding exception for '%s'\n", value);
 	if (strcmp(value, "NSRangeException") == 0) {
 		return PyExc_IndexError;
 	}  else if (strcmp(value, "NSInvalidArgumentException") == 0) {

pyobjc-core/Modules/objc/opaque-pointer.m

 		PyObjC_free_closure(cl);
 	}
 	if (to_c) {
-		PyObjC_free_closure(to_c);
+		PyObjC_free_closure((ffi_closure*)to_c);
 	}
 	if (from_c) {
-		PyObjC_free_closure(from_c);
+		PyObjC_free_closure((ffi_closure*)from_c);
 	}
 	Py_XDECREF(v);
 	Py_XDECREF(w);

pyobjc-core/Modules/objc/pyobjc-api.h

 
 
 /* threading support */
-#if 1
+#if 0
 #define PyObjC_DURING \
 		Py_BEGIN_ALLOW_THREADS \
 		NS_DURING

pyobjc-core/Modules/objc/selector.m

 			pyres = pyself;
 		}
 
-		if (((PyObjCObject*)self->sel_self)->flags & PyObjCObject_kUNINITIALIZED) {
+		if (PyObjCObject_Check(self) && (((PyObjCObject*)self->sel_self)->flags & PyObjCObject_kUNINITIALIZED)) {
 			if (self->sel_self != pyres && !PyErr_Occurred()) {
 				PyObjCObject_ClearObject(pyself);
 			}

pyobjc-core/Modules/objc/test/ctests.m

 {
 }
 -(void)methodWithMyStruct: (struct Struct2)val1 andShort:(short)val2;
-
-
 @end
 
 @implementation PyObjCTest_NSInvoke 
 }
 @end
 
-#ifndef GNU_RUNTIME
-
-
 BEGIN_UNITTEST(CheckNSInvoke)
 	/* This is not a 'real' unittest, but is used to disable a number of
 	 * other tests (in objc.test.test_methods2) when NSInvocation isn't
 	 * working correctly (MacOS X at least upto 10.2.6).
 	 * [Panther previews also have this problem]
 	 *
-	 * GNUstep is even worse, this test causes a crash of the interpreter,
+	 * Leopard is even worse, this test causes a crash of the interpreter when
+         * running on PPC64.
 	 */
+#ifdef __ppc64__
+	ASSERT_EQUALS(0, 1, "%d");
+#endif
+
 	PyObjCTest_NSInvoke* obj = [[PyObjCTest_NSInvoke alloc] init];
 	NSInvocation* inv;
 	struct Struct2 v1 = { 1, 2, { 3, 4, 5, 6, 7 } };
 
 END_UNITTEST
 
-#else
-
-BEGIN_UNITTEST(CheckNSInvoke)
-	/* Force failure, see comment above */
-	ASSERT_EQUALS(0, 1, "%d");
-END_UNITTEST
-
-#endif
-
 
 BEGIN_UNITTEST(StructSize)
 

pyobjc-core/Modules/objc/test/structargs.m

 {
 }
 -(NSString*)compP:(NSPoint)aPoint aRect:(NSRect)aRect anOp:(int)op;
--(unsigned)stackPtr;
+-(size_t)stackPtr;
 -(NSRect)someRect;
 -(NSRect)someRectWithRect:(NSRect)rect;
 -(NSRect)someRectWithX:(int)x Y:(int)y H:(int)h W:(int)w;
 			NSStringFromRect(aRect),
 			op];
 }
--(unsigned)stackPtr
+
+static size_t ident(size_t v)
+{
+	return v;
+}
+-(size_t)stackPtr
 {
 	char c;
 
-	return ((unsigned)&c)+1;
+	return ident(((size_t)&c)+1);
 }
 @end
 

pyobjc-core/Modules/objc/test/testbndl.m

 + (NSData*)fetchData:(NSCoder*)coder
 {
 	void* data;
-	unsigned length;
+	NSUInteger length;
 
 	data = [coder decodeBytesWithReturnedLength:&length];
 	return [NSData dataWithBytes:data length:length];

pyobjc-core/Modules/objc/toll-free-bridging.m

  *
  */
 PyObject* 
-PyObjC_IDToCFType(id argument)
+PyObjC_IDToCFType(id argument __attribute__((__unused__)))
 {
 #ifndef __OBJC2__
 	CFTypeRef typeRef = (CFTypeRef)argument;

pyobjc-core/libffi-src/powerpc/ppc-darwin.h

 };
 
 void ffi_prep_args(extended_cif*   inEcif, unsigned *const stack);
+
+typedef union
+{
+        float   f;
+        double  d;
+} ffi_dblfl;
+
 int ffi_closure_helper_DARWIN( ffi_closure*    closure,
         void*                   rvalue, unsigned long*  pgr,
         ffi_dblfl*              pfr);

pyobjc-core/libffi-src/powerpc/ppc-ffi_darwin.c

 	} ldu;
 #endif
 
-typedef union
-{
-	float	f;
-	double	d;
-} ffi_dblfl;
-
 /*	The trampoline invokes ffi_closure_ASM, and on entry, r11 holds the
 	address of the closure. After storing the registers that could possibly
 	contain parameters to be passed into the stack frame and setting up space
 }
 
 #endif	/*	defined(__ppc64__)	*/
-#endif	/* __ppc__ || __ppc64__ */
+#endif	/* __ppc__ || __ppc64__ */

pyobjc-core/setup.py

     #"-Wstrict-overflow",
     "-g",
     #"-fobjc-gc",
+    "-fexceptions",
 
     ## Arghh, a stupid compiler flag can cause problems. Don't 
     ## enable -O0 if you value your sanity. With -O0 PyObjC will crash