Ronald Oussoren avatar Ronald Oussoren committed 78d3151

Some bugfixes for problems reported in private mail

Comments (0)

Files changed (6)

pyobjc-core/Modules/objc/libffi_support.m

 
 #   define SMALL_STRUCT_LIMIT	8
 
-#elif defined(__i386__) 
+#elif defined(__i386__)
 
 #   define SMALL_STRUCT_LIMIT 	8
 
-#elif defined(__x86_64__) 
+#elif defined(__x86_64__)
 
 #   define SMALL_STRUCT_LIMIT	16
 
 	       break;
 
 	default:
-	       // Don't abort, this is called from the debugger 
+	       // Don't abort, this is called from the debugger
 	       printf("?(%d)", type->type);
 	}
 }
 	if (*argtype != _C_STRUCT_B) return -1;
 	while (*argtype != _C_STRUCT_E && *argtype != '=') argtype++;
 	if (*argtype == _C_STRUCT_E) return 0;
-	
+
 	argtype++;
 	while (*argtype != _C_STRUCT_E) {
 		if (*argtype == '"') {
 }
 #endif
 
-static ffi_type* 
+static ffi_type*
 array_to_ffi_type(const char* argtype)
 {
 static  PyObject* array_types = NULL; /* XXX: Use NSMap  */
 		return (ffi_type*)PyCapsule_GetPointer(v, "objc.__ffi_type__");
 	}
 
-	/* We don't have a type description yet, dynamicly 
+	/* We don't have a type description yet, dynamicly
 	 * create it.
 	 */
 	field_count = atoi(argtype+1);
-			
+
 	type = PyMem_Malloc(sizeof(*type));
 	if (type == NULL) {
 		PyErr_NoMemory();
 	type->size = PyObjCRT_SizeOfType(argtype);
 	type->alignment = PyObjCRT_AlignOfType(argtype);
 
-	/* Libffi doesn't really know about arrays as part of larger 
+	/* Libffi doesn't really know about arrays as part of larger
 	 * data-structures (e.g. struct foo { int field[3]; };). We fake it
-	 * by treating the nested array as a struct. These seems to work 
+	 * by treating the nested array as a struct. These seems to work
 	 * fine on MacOS X.
 	 */
 	type->type = FFI_TYPE_STRUCT;
 		PyErr_NoMemory();
 		return NULL;
 	}
-	
+
 	while (isdigit(*++argtype));
 	type->elements[0] = signature_to_ffi_type(argtype);
 	for (i = 1; i < field_count; i++) {
 	return type;
 }
 
-static ffi_type* 
+static ffi_type*
 struct_to_ffi_type(const char* argtype)
 {
 	static  PyObject* struct_types = NULL; /* XXX: Use NSMap  */
 		return (ffi_type*)PyCapsule_GetPointer(v, "objc.__ffi_type__");
 	}
 
-	/* We don't have a type description yet, dynamicly 
+	/* We don't have a type description yet, dynamicly
 	 * create it.
 	 */
 	field_count = num_struct_fields(argtype);
 			"Cannot determine layout of %s", argtype);
 		return NULL;
 	}
-			
+
 	type = PyMem_Malloc(sizeof(*type));
 	if (type == NULL) {
 		PyErr_NoMemory();
 		PyErr_NoMemory();
 		return NULL;
 	}
-	
+
 	field_count = 0;
 	curtype = argtype+1;
 	while (*curtype != _C_STRUCT_E && *curtype != '=') curtype++;
 				curtype++;
 				while (*curtype++ != '"') {}
 			}
-			type->elements[field_count] = 
+			type->elements[field_count] =
 				signature_to_ffi_type(curtype);
 			if (type->elements[field_count] == NULL) {
 				PyMem_Free(type->elements);
 	switch (*argtype) {
 	case _C_CHR: case _C_SHT: case _C_UNICHAR:
 		return signature_to_ffi_type(long_type);
-	case _C_UCHR: case _C_USHT: 
+	case _C_UCHR: case _C_USHT:
 		return signature_to_ffi_type(ulong_type);
 #ifdef _C_BOOL
 	case _C_BOOL: return signature_to_ffi_type(long_type);
-#endif	
-	case _C_NSBOOL: 
+#endif
+	case _C_NSBOOL:
 		      return signature_to_ffi_type(long_type);
 	default:
 		return signature_to_ffi_type(argtype);
 	case _C_CHAR_AS_INT: return &ffi_type_schar;
 	case _C_CHAR_AS_TEXT: return &ffi_type_schar;
 #ifdef _C_BOOL
-	case _C_BOOL: 
+	case _C_BOOL:
 	     /* sizeof(bool) == 4 on PPC32, and 1 on all others */
 #if defined(__ppc__) && !defined(__LP__)
 	     return &ffi_type_sint;
 	     return &ffi_type_schar;
 #endif
 
-#endif	
+#endif
 	case _C_NSBOOL: return &ffi_type_schar;
 	case _C_UCHR: return &ffi_type_uchar;
 	case _C_SHT: return &ffi_type_sshort;
 	case _C_UINT: return &ffi_type_uint;
 
 	 /* The next to defintions are incorrect, but the correct definitions
-	  * don't work (e.g. give testsuite failures). 
+	  * don't work (e.g. give testsuite failures).
 	  */
 #ifdef __LP64__
 	case _C_LNG: return &ffi_type_sint64;  /* ffi_type_slong */
 	case _C_DBL: return &ffi_type_double;
 	case _C_CHARPTR: return &ffi_type_pointer;
 	case _C_PTR: return &ffi_type_pointer;
-	case _C_ARY_B: 
+	case _C_ARY_B:
 		return array_to_ffi_type(argtype);
-	case _C_IN: case _C_OUT: case _C_INOUT: case _C_CONST: 
+	case _C_IN: case _C_OUT: case _C_INOUT: case _C_CONST:
 #if 0	/* 'O' is used by remote objects ??? */
 	  case 'O':
 #endif
 		return signature_to_ffi_type(argtype+1);
-	case _C_STRUCT_B: 
+	case _C_STRUCT_B:
 		return struct_to_ffi_type(argtype);
 	case _C_UNDEF:
 		return &ffi_type_pointer;
 		return ((CFRange*)pvalue)->length;
 	}
 
-	if (strncmp(type, @encode(CFArrayRef), sizeof(@encode(CFArrayRef))-1) == 0 || 
+	if (strncmp(type, @encode(CFArrayRef), sizeof(@encode(CFArrayRef))-1) == 0 ||
 		strncmp(type, @encode(CFMutableArrayRef), sizeof(@encode(CFMutableArrayRef))-1) == 0) {
-	
+
 		return CFArrayGetCount(*(CFArrayRef*)pvalue);
 	}
-	PyErr_Format(PyExc_TypeError, 
+	PyErr_Format(PyExc_TypeError,
 			"Don't know how to convert to extract count: %s", type);
 	return -1;
 }
 		char typecode;
 
 		/* Skip '%' */
-		format ++; 
+		format ++;
 
 		/* Check for '%%' escape */
 		if (*format == '%') {
 			if (depythonify_c_value(@encode(int), PyTuple_GET_ITEM(argtuple, argoffset), byref[curarg]) < 0) {
 				Py_DECREF(encoded);
 				return -1;
-			}	
+			}
 			values[curarg] = byref[curarg];
 			arglist[curarg] = signature_to_ffi_type(@encode(int));
 
 			argoffset++;
 			curarg++;
-			
+
 		} else {
 			while (isdigit(*format)) format++;
 		}
 				if (depythonify_c_value(@encode(int), PyTuple_GET_ITEM(argtuple, argoffset), byref[curarg]) < 0) {
 					Py_DECREF(encoded);
 					return -1;
-				}	
+				}
 				values[curarg] = byref[curarg];
 				arglist[curarg] = signature_to_ffi_type(@encode(int));
 				argoffset++;
 					return -1;
 				}
 				*(int*)byref[curarg] = (wchar_t)*PyString_AsString(v);
-			} else 
+			} else
 #endif
 			if (PyUnicode_Check(v)) {
-				
+
 				if (PyUnicode_GetSize(v) != 1) {
 					PyErr_SetString(PyExc_ValueError, "Expecting string of length 1");
 					Py_DECREF(encoded);
 			/* INT */
 			if (*format == 'D') {
 				typecode = _C_LNG;
-			} 
+			}
 
 			if (typecode == _C_LNG_LNG) {
 				byref[curarg] = PyMem_Malloc(sizeof(long long));
-			
+
 			} else if (typecode == _C_LNG) {
 				byref[curarg] = PyMem_Malloc(sizeof(long));
 
 			if (depythonify_c_value(&typecode, PyTuple_GET_ITEM(argtuple, argoffset), byref[curarg]) < 0) {
 				Py_DECREF(encoded);
 				return -1;
-			}	
+			}
 			values[curarg] = byref[curarg];
 			arglist[curarg] = signature_to_ffi_type(&typecode);
 
 			if (typecode == _C_LNG_LNG) {
 				byref[curarg] = PyMem_Malloc(sizeof(long long));
 				typecode = _C_ULNG_LNG;
-			
+
 			} else if (typecode == _C_LNG) {
 				byref[curarg] = PyMem_Malloc(sizeof(long));
 				typecode = _C_ULNG;
 			if (depythonify_c_value(&typecode, PyTuple_GET_ITEM(argtuple, argoffset), byref[curarg]) < 0) {
 				Py_DECREF(encoded);
 				return -1;
-			}	
+			}
 			values[curarg] = byref[curarg];
 			arglist[curarg] = signature_to_ffi_type(&typecode);
 
 			if (depythonify_c_value(&typecode, PyTuple_GET_ITEM(argtuple, argoffset), byref[curarg]) < 0) {
 				Py_DECREF(encoded);
 				return -1;
-			}	
+			}
 			values[curarg] = byref[curarg];
-#if defined(__ppc__) 
+#if defined(__ppc__)
 			/* Passing floats to variadic functions on darwin/ppc
 			 * is slightly convoluted. Lying to libffi about the
 			 * type of the argument seems to trick it into doing
 				if (depythonify_c_value(&typecode, PyTuple_GET_ITEM(argtuple, argoffset), byref[curarg]) < 0) {
 					Py_DECREF(encoded);
 					return -1;
-				}	
+				}
 				arglist[curarg] = signature_to_ffi_type(&typecode);
 				values[curarg] = byref[curarg];
 			}
 			if (depythonify_c_value(&typecode, PyTuple_GET_ITEM(argtuple, argoffset), byref[curarg]) < 0) {
 				Py_DECREF(encoded);
 				return -1;
-			}	
+			}
 			values[curarg] = byref[curarg];
 			arglist[curarg] = signature_to_ffi_type(&typecode);
 
 		if (byref[curarg] == NULL) {
 			return -1;
 		}
-		if (depythonify_c_value(argType->type, 
-			PyTuple_GET_ITEM(argtuple, argoffset), 
+		if (depythonify_c_value(argType->type,
+			PyTuple_GET_ITEM(argtuple, argoffset),
 			byref[curarg]) < 0) {
 
 			return -1;
 	enum closureType	  closureType;
 } _method_stub_userdata;
 
-static void 
+static void
 method_stub(ffi_cif* cif __attribute__((__unused__)), void* resp, void** args, void* _userdata)
 {
 	int err;
 		startArg = 0;
 		pyself = NULL;
 	}
-	
+
 	for (i = startArg; i < Py_SIZE(methinfo); i++) {
 
 		const char* argtype = methinfo->argtype[i].type;
 #endif
 
 		switch (*argtype) {
-		case _C_INOUT: 
+		case _C_INOUT:
 			if (argtype[1] == _C_PTR) {
 				have_output ++;
 			}
 			break;
 
 		case _C_ARY_B:
-			/* An array is actually a pointer to the first 
+			/* An array is actually a pointer to the first
 			 * element of the array. Libffi passes a pointer to
-			 * that pointer, we need to strip one level of 
+			 * that pointer, we need to strip one level of
 			 * indirection to ensure that pythonify_c_value works
 			 * correctly.
 			 */
 			v = pythonify_c_value(argtype, *(void**)args[i]);
 			break;
 
+                case _C_ID:
+			v = pythonify_c_value(argtype, args[i]);
+                        if (v != NULL && PyObjCObject_IsBlock(v) && PyObjCObject_GetBlock(v) == NULL) {
+                            /* Argument is a block */
+                            if (methinfo->argtype[i].callable != NULL) {
+                                    PyObjCObject_SET_BLOCK(v, methinfo->argtype[i].callable);
+                                    Py_INCREF(methinfo->argtype[i].callable);
+                            }
+                        }
+                        break;
+
 		default:
 			v = pythonify_c_value(argtype, args[i]);
 		}
 			Py_DECREF(arglist);
 			goto error;
 		}
-		Py_DECREF(v); 
+		Py_DECREF(v);
 	}
 
 	v = PyList_AsTuple(arglist);
 
 	if (!callable) {
 		abort();
-	} 
+	}
 
 	/* Avoid calling a PyObjCPythonSelector directory, it does
 	 * additional work that we don't need.
 					case PyObjC_kPointerPlain:
 						err = depythonify_c_return_value(unqualified_type, res, resp);
 						if (err == -1) {
-							Py_DECREF(res); 
+							Py_DECREF(res);
 							goto error;
 						}
 						break;
 					case PyObjC_kArrayCountInArg:
 						/* We don't have output arguments, thus can calculate the response immediately */
 						count = extract_count(
-							methinfo->argtype[methinfo->rettype.arrayArg].type, 
-							args[methinfo->rettype.arrayArg]); 
+							methinfo->argtype[methinfo->rettype.arrayArg].type,
+							args[methinfo->rettype.arrayArg]);
 						if (count == -1 && PyErr_Occurred()) {
 							goto error;
 						}
 				}
 
 			} else {
-				err = depythonify_c_return_value(rettype, 
+				err = depythonify_c_return_value(rettype,
 					res, resp);
 
 				if (methinfo->rettype.alreadyRetained) {
-				   /* Must return a 'new' instead of a borrowed 
+				   /* Must return a 'new' instead of a borrowed
 				    * reference.
 				    */
 				   [(*(id*)resp) retain];
 
 				} else if (methinfo->rettype.alreadyCFRetained) {
-				   /* Must return a 'new' instead of a borrowed 
+				   /* Must return a 'new' instead of a borrowed
 				    * reference.
 				    */
 				   CFRetain((*(id*)resp));
 						}
 
 					}
-					Py_DECREF(res); 
+					Py_DECREF(res);
 					goto error;
 				}
 			}
 					break;
 
 				case PyObjC_kNullTerminatedArray:
-					count = c_array_nullterminated_size(res, &seq);            
+					count = c_array_nullterminated_size(res, &seq);
 					if (count == -1) {
 						goto error;
 					}
 
 				case PyObjC_kArrayCountInArg:
 					count = extract_count(
-							methinfo->argtype[methinfo->argtype[i].arrayArg].type, 
-							args[methinfo->argtype[i].arrayArg]); 
+							methinfo->argtype[methinfo->argtype[i].arrayArg].type,
+							args[methinfo->argtype[i].arrayArg]);
 					if (count == -1 && PyErr_Occurred()) {
 						goto error;
 					}
 						err = depythonify_c_return_value(unqualified_type,
 							real_res, resp);
 						if (err == -1) {
-							Py_DECREF(res); 
+							Py_DECREF(res);
 							goto error;
 						}
 						break;
 					case PyObjC_kArrayCountInArg:
 						if (*PyObjCRT_SkipTypeQualifiers(methinfo->argtype[methinfo->rettype.arrayArg].type) != _C_PTR) {
 							count = extract_count(
-								methinfo->argtype[methinfo->rettype.arrayArg].type, 
-								args[methinfo->rettype.arrayArg]); 
+								methinfo->argtype[methinfo->rettype.arrayArg].type,
+								args[methinfo->rettype.arrayArg]);
 							if (count == -1 && PyErr_Occurred()) {
 								goto error;
 							}
 							*(void**)resp = NULL;
 							break;
 						}
-					
+
 					}
 				}
 
 			} else {
-				err = depythonify_c_return_value(rettype, 
+				err = depythonify_c_return_value(rettype,
 					real_res, resp);
 
 				if (methinfo->rettype.alreadyRetained) {
-				   /* Must return a 'new' instead of a borrowed 
+				   /* Must return a 'new' instead of a borrowed
 				    * reference.
 				    */
 				   [(*(id*)resp) retain];
 						   "a value",
 						   sel_getName(*(SEL*)args[1]));
 					}
-					Py_DECREF(res); 
+					Py_DECREF(res);
 					goto error;
 				}
 			}
 				break;
 
 			case PyObjC_kNullTerminatedArray:
-				count = c_array_nullterminated_size(PyTuple_GET_ITEM(res, idx++), &seq);            
+				count = c_array_nullterminated_size(PyTuple_GET_ITEM(res, idx++), &seq);
 				if (count == -1) {
 					goto error;
 				}
 
 				case PyObjC_kArrayCountInArg:
 					count = extract_count(
-							methinfo->argtype[methinfo->argtype[i].arrayArg].type, 
-							args[methinfo->argtype[i].arrayArg]); 
+							methinfo->argtype[methinfo->argtype[i].arrayArg].type,
+							args[methinfo->argtype[i].arrayArg]);
 					if (count == -1 && PyErr_Occurred()) {
 						goto error;
 					}
 					}
 
 					count = extract_count(
-						methinfo->argtype[methinfo->rettype.arrayArg].type, 
-						args[methinfo->rettype.arrayArg]); 
+						methinfo->argtype[methinfo->rettype.arrayArg].type,
+						args[methinfo->rettype.arrayArg]);
 					if (count == -1 && PyErr_Occurred()) {
 						goto error;
 					}
 
 	/* Do this at the end to ensure we work correctly when
 	 * 'res' is 'pyself' and 'pyself' those are the only
-	 * references from Python (that is, 'pyself' is a 
+	 * references from Python (that is, 'pyself' is a
 	 * "transient" reference.
 	 */
 	if (pyself) {
 	}
 
 	PyGILState_Release(state);
-	
+
 	return;
 
 error:
 	PyObjCErr_ToObjCWithGILState(&state);
 }
 
-/* 
+/*
  * Return an IMP that is suitable for forwarding a method with the specified
  * signature from Objective-C to Python.
  */
 	} else if (PyObjCNativeSelector_Check(callable)) {
 		PyObjCMethodSignature* sig = PyObjCSelector_GetMetadata(callable);
 		 int result = Py_SIZE(sig) - 1;
-		 
+
 		 Py_DECREF(sig);
 		 return result;
 
 		if (stubUserdata->argCount == Py_SIZE(methinfo) && !haveVarArgs && !haveVarKwds) {
 			/* OK */
 		} else if ((stubUserdata->argCount <= 1) && (haveVarArgs || haveVarKwds)) {
-			/* OK: 
-			 *    def m(self, *args, **kwds), or 
-			 *    def m(*args, **kwds)  
+			/* OK:
+			 *    def m(self, *args, **kwds), or
+			 *    def m(*args, **kwds)
 			 */
 		} else {
 			/* Wrong number of arguments, raise an error */
 			PyErr_Format(PyObjCExc_BadPrototypeError,
 				"Objective-C expects %"PY_FORMAT_SIZE_T"d arguments, Python argument has %d arguments for %R",
-				Py_SIZE(methinfo), stubUserdata->argCount, 
+				Py_SIZE(methinfo), stubUserdata->argCount,
 				callable);
 			Py_DECREF(methinfo);
 			PyMem_Free(stubUserdata);
 			/* Wrong number of arguments, raise an error */
 			PyErr_Format(PyObjCExc_BadPrototypeError,
 				"Objective-C expects %"PY_FORMAT_SIZE_T"d arguments, Python argument has %d arguments for %R",
-				Py_SIZE(methinfo) - 1, stubUserdata->argCount, 
+				Py_SIZE(methinfo) - 1, stubUserdata->argCount,
 				callable);
 			Py_DECREF(methinfo);
 			PyMem_Free(stubUserdata);
 }
 
 IMP
-PyObjCFFI_MakeIMPForPyObjCSelector(PyObjCSelector *aSelector) 
+PyObjCFFI_MakeIMPForPyObjCSelector(PyObjCSelector *aSelector)
 {
 	if (PyObjCNativeSelector_Check(aSelector)) {
-		PyObjCNativeSelector *nativeSelector = 
+		PyObjCNativeSelector *nativeSelector =
 			(PyObjCNativeSelector *) aSelector;
 		Method aMeth;
 
 
 		PyObjCPythonSelector *pythonSelector = (PyObjCPythonSelector *) aSelector;
 		PyObjCMethodSignature* methinfo = PyObjCMethodSignature_ForSelector(
-				pythonSelector->sel_class, 
+				pythonSelector->sel_class,
 				(pythonSelector->sel_flags & PyObjCSelector_kCLASS_METHOD) != 0,
 				pythonSelector->sel_selector,
 				pythonSelector->sel_python_signature,
 			/* Wrong number of arguments, raise an error */
 			PyErr_Format(PyObjCExc_BadPrototypeError,
 				"Objective-C expects %"PY_FORMAT_SIZE_T"d arguments, Python argument has %d arguments for %R",
-				Py_SIZE(methinfo) - 1, stubUserdata->argCount, 
+				Py_SIZE(methinfo) - 1, stubUserdata->argCount,
 				callable);
 			Py_DECREF(methinfo);
 			PyMem_Free(stubUserdata);
  */
 int PyObjCFFI_CountArguments(
 		PyObjCMethodSignature* methinfo, Py_ssize_t argOffset,
-		Py_ssize_t* byref_in_count, 
+		Py_ssize_t* byref_in_count,
 		Py_ssize_t* byref_out_count,
 		Py_ssize_t* plain_count,
 		Py_ssize_t* argbuf_len,
 	Py_ssize_t itemSize;
 
 	*byref_in_count = *byref_out_count = *plain_count = 0;
-	
+
 	for (i = argOffset; i < Py_SIZE(methinfo); i++) {
 		const char *argtype = methinfo->argtype[i].type;
 #if 0
 	void* buffer = NULL;
 	Py_ssize_t bufferlen = 0;
 
-	/* We have to do two passes over the argument array: the first to deal 
-	 * with plain arguments, the second deals with arrays whose size is 
+	/* We have to do two passes over the argument array: the first to deal
+	 * with plain arguments, the second deals with arrays whose size is
 	 * the value of another argument.
 	 */
 
 			py_arg ++;
 
 			if (argument == Py_None) {
-				/* Fall through to the default 
+				/* Fall through to the default
 				 * behaviour
 				 */
 				error = 1; /* misuse of this flag ... */
 				} else {
 					PyErr_Format(
 						PyExc_ValueError,
-						"argument %" PY_FORMAT_SIZE_T "d isn't allowed to be NULL", 
+						"argument %" PY_FORMAT_SIZE_T "d isn't allowed to be NULL",
 						i - argOffset);
 					error = -1;
 				}
 			} else {
 
 				switch (methinfo->argtype[i].ptrType) {
-				case PyObjC_kFixedLengthArray: 
-				case PyObjC_kVariableLengthArray: 
+				case PyObjC_kFixedLengthArray:
+				case PyObjC_kVariableLengthArray:
 				case PyObjC_kArrayCountInArg:
 					if (PyObject_AsWriteBuffer(argument, &buffer, &bufferlen) != -1) {
 						error = 1;
 				default:
 					PyErr_Format(
 						PyExc_ValueError,
-						"argument %" PY_FORMAT_SIZE_T "d must be None or objc.NULL", 
+						"argument %" PY_FORMAT_SIZE_T "d must be None or objc.NULL",
 						i - argOffset);
 					error = -1;
 				}
 
 			}  else if (error == 0) {
 				continue;
-				
-			} 
+
+			}
 
 			switch (methinfo->argtype[i].ptrType) {
 			case PyObjC_kPointerPlain:
-				argbuf_cur = align(argbuf_cur, 
+				argbuf_cur = align(argbuf_cur,
 					PyObjCRT_AlignOfType(resttype));
 				sz = PyObjCRT_SizeOfType(resttype);
 				byref[i] = PyMem_Malloc(sz);
 				break;
 
 			case PyObjC_kNullTerminatedArray:
-				PyErr_SetString(PyExc_TypeError, 
+				PyErr_SetString(PyExc_TypeError,
 					"NULL-terminated 'out' arguments are not supported");
 				return -1;
 
 					return -1;
 				}
 				error = depythonify_c_value (
-					argtype, 
-					argument, 
+					argtype,
+					argument,
 					byref[i]);
 
 				arglist[i] = signature_to_ffi_type(argtype);
 					}
 
 					error = depythonify_c_value (
-						argtype, 
-						argument, 
+						argtype,
+						argument,
 						arg);
 
 					arglist[i] = signature_to_ffi_type(argtype);
 									PyErr_Clear();
 
 									closure = PyObjCFFI_MakeFunctionClosure(
-											methinfo->argtype[i].callable, 
+											methinfo->argtype[i].callable,
 											argument
 										);
 									if (closure == NULL) {
 						case PyObjC_kPointerPlain:
 							byref[i] = PyMem_Malloc(PyObjCRT_SizeOfType(resttype));
 							error = depythonify_c_value (
-								resttype, 
-								argument, 
-								byref[i]); 
+								resttype,
+								argument,
+								byref[i]);
 							break;
 
 
 										PyErr_NoMemory();
 										error = -1;
 									} else {
-										error = depythonify_c_array_nullterminated(resttype, 
+										error = depythonify_c_array_nullterminated(resttype,
 											count,
 											seq,
 											byref[i], methinfo->argtype[i].alreadyRetained, methinfo->argtype[i].alreadyCFRetained);
 					if (methinfo->argtype[i].printfFormat) {
 						printf_format = argument;
 						Py_INCREF(argument);
-					} 
+					}
 					error = depythonify_c_value (
-						argtype+1, 
-						argument, 
+						argtype+1,
+						argument,
 						arg);
 
 					arglist[i] = signature_to_ffi_type(
 							printf_format = argument;
 							Py_INCREF(argument);
 
-						} 
+						}
 						error = depythonify_c_value (
-							argtype, 
-							argument, 
+							argtype,
+							argument,
 							arg);
 
 						arglist[i] = signature_to_ffi_type(argtype);
 								PyErr_Clear();
 
 								closure = PyObjCFFI_MakeFunctionClosure(
-										methinfo->argtype[i].callable, 
+										methinfo->argtype[i].callable,
 										argument
 									);
 								if (closure == NULL) {
 				}
 
 				error = depythonify_c_value (
-					argtype, 
-					argument, 
+					argtype,
+					argument,
 					arg);
 
 				arglist[i] = signature_to_ffi_type(argtype);
 
 				if (methinfo->argtype[i].ptrType == PyObjC_kArrayCountInArg) {
 					count = extract_count(
-							methinfo->argtype[methinfo->argtype[i].arrayArg].type, 
-							values[methinfo->argtype[i].arrayArg]); 
+							methinfo->argtype[methinfo->argtype[i].arrayArg].type,
+							values[methinfo->argtype[i].arrayArg]);
 					if (count == -1 && PyErr_Occurred()) {
 						return -1;
 					}
 				if (argtype[0] == _C_OUT) argtype ++;
 
 				argument = PyTuple_GET_ITEM (args, py_arg);
-				py_arg ++; 
+				py_arg ++;
 
 				switch (*argtype) {
 				case _C_INOUT:
 
 							case PyObjC_kArrayCountInArg:
 								count = extract_count(
-										methinfo->argtype[methinfo->argtype[i].arrayArg].type, 
-										values[methinfo->argtype[i].arrayArg]); 
+										methinfo->argtype[methinfo->argtype[i].arrayArg].type,
+										values[methinfo->argtype[i].arrayArg]);
 								if (count == -1 && PyErr_Occurred()) {
 									return -1;
 								}
 
 						case PyObjC_kArrayCountInArg:
 							count = extract_count(
-									methinfo->argtype[methinfo->argtype[i].arrayArg].type, 
-									values[methinfo->argtype[i].arrayArg]); 
+									methinfo->argtype[methinfo->argtype[i].arrayArg].type,
+									values[methinfo->argtype[i].arrayArg]);
 							if (count == -1 && PyErr_Occurred()) {
 								return -1;
 							}
 							arglist[i] = &ffi_type_pointer;
 							values[i] = byref + i;
 						}
-					}	
+					}
 				}
 			}
 		}
 		if (r == -1) {
 			return -1;
 		}
-		Py_DECREF(printf_format); 
+		Py_DECREF(printf_format);
 		printf_format = NULL;
 
 		return r;
 
 		r = parse_varargs_array(
 				methinfo,
-				args, py_arg, byref, 
+				args, py_arg, byref,
 				arglist, values, -1);
 		if (r == -1) {
 			return -1;
 
 		r = parse_varargs_array(
 				methinfo,
-				args, py_arg, byref, 
+				args, py_arg, byref,
 				arglist, values, cnt);
 		if (r == -1) {
 			return -1;
 }
 
 
-PyObject* 
+PyObject*
 PyObjCFFI_BuildResult(
 	PyObjCMethodSignature* methinfo, Py_ssize_t argOffset,
 	void* pRetval, void** byref, struct byref_attr* byref_attr,
-	Py_ssize_t byref_out_count, PyObject* self, int flags, 
+	Py_ssize_t byref_out_count, PyObject* self, int flags,
 	void** argvalues)
 {
 	PyObject* objc_result = NULL;
 				if (methinfo->rettype.alreadyRetained) {
 					if (PyObjCObject_Check(objc_result)) {
 						/* pythonify_c_return_value has retained the object, but we already
-						 * own a reference, therefore give the ref away again 
+						 * own a reference, therefore give the ref away again
 						 */
 						[PyObjCObject_GetObject(objc_result) release];
 					}
 				if (methinfo->rettype.alreadyCFRetained) {
 					if (PyObjCObject_Check(objc_result)) {
 						/* pythonify_c_return_value has retained the object, but we already
-						 * own a reference, therefore give the ref away again 
+						 * own a reference, therefore give the ref away again
 						 */
 						CFRelease(PyObjCObject_GetObject(objc_result));
 					}
 						}
 					}
 					break;
-				
+
 				case PyObjC_kFixedLengthArray:
 					if (*(void**)pRetval == NULL) {
 						Py_INCREF(PyObjC_NULL);
 
 					} else {
 						objc_result = PyObjC_CArrayToPython2(
-							resttype, 
+							resttype,
 							*(void**)pRetval,
 							methinfo->rettype.arrayArg, methinfo->rettype.alreadyRetained, methinfo->rettype.alreadyCFRetained);
 						if (objc_result == NULL) {
 					break;
 
 				case PyObjC_kArrayCountInArg:
-					
+
 					if (*(void**)pRetval == NULL) {
 						Py_INCREF(PyObjC_NULL);
 						objc_result = PyObjC_NULL;
 			if (methinfo->rettype.alreadyRetained) {
 				if (PyObjCObject_Check(objc_result)) {
 					/* pythonify_c_return_value has retained the object, but we already
-					 * own a reference, therefore give the ref away again 
+					 * own a reference, therefore give the ref away again
 					 */
 					[PyObjCObject_GetObject(objc_result) release];
 				}
 			if (methinfo->rettype.alreadyCFRetained) {
 				if (PyObjCObject_Check(objc_result)) {
 					/* pythonify_c_return_value has retained the object, but we already
-					 * own a reference, therefore give the ref away again 
+					 * own a reference, therefore give the ref away again
 					 */
 					CFRelease(PyObjCObject_GetObject(objc_result));
 				}
 							} else {
 								count = methinfo->argtype[i].arrayArg;
 							}
-							
+
 							if (*resttype == _C_UNICHAR) {
-								
+
 								int byteorder = 0;
 								v = PyUnicode_DecodeUTF16(
 									arg, count*2, NULL, &byteorder);
 								if (!v) goto error_cleanup;
 
 							} else {
-								v = PyObjC_CArrayToPython2(resttype, 
+								v = PyObjC_CArrayToPython2(resttype,
 									arg,
 									count, methinfo->argtype[i].alreadyRetained, methinfo->argtype[i].alreadyCFRetained);
 								if (!v) goto error_cleanup;
 								count = extract_count(methinfo->rettype.type, pRetval);
 								if (count == -1 && PyErr_Occurred()) goto error_cleanup;
 
-								v = PyObjC_CArrayToPython2(resttype, 
+								v = PyObjC_CArrayToPython2(resttype,
 									arg,
 									count, methinfo->argtype[i].alreadyRetained, methinfo->argtype[i].alreadyCFRetained);
 								if (!v) goto error_cleanup;
 								v = PyObjC_VarList_New(methinfo->rettype.type, pRetval);
 								if (!v) goto error_cleanup;
 							}
-							
+
 							break;
 
 						case PyObjC_kNullTerminatedArray:
 
 							} else {
 								count = extract_count(
-									methinfo->argtype[methinfo->argtype[i].arrayArgOut].type, 
+									methinfo->argtype[methinfo->argtype[i].arrayArgOut].type,
 									argvalues[methinfo->argtype[i].arrayArgOut]);
 							}
 							if (count == -1 && PyErr_Occurred()) goto error_cleanup;
 					}
 
 					if (result != NULL) {
-						if (PyTuple_SetItem(result, 
+						if (PyTuple_SetItem(result,
 							py_arg++, v) < 0) {
 
 							Py_DECREF(v);
 	 */
 	argbuf_len = align(resultSize, sizeof(void*));
 	r = PyObjCFFI_CountArguments(
-		methinfo, 2, 
-		&byref_in_count, 
+		methinfo, 2,
+		&byref_in_count,
 		&byref_out_count,
 		&plain_count,
 		&argbuf_len,
 	}
 
 
-	/* 
+	/*
 	 * We need input arguments for every normal argument and for every
 	 * input argument that is passed by reference.
 	 */
 		}
 		if (methinfo->null_terminated_array) {
 			if (PyTuple_Size(args) < Py_SIZE(methinfo) - 3) {
-				PyErr_Format(PyExc_TypeError, 
+				PyErr_Format(PyExc_TypeError,
 					"Need %"PY_FORMAT_SIZE_T"d arguments, got %"PY_FORMAT_SIZE_T"d",
-					Py_SIZE(methinfo) - 3, 
+					Py_SIZE(methinfo) - 3,
 					PyTuple_Size(args));
 				goto error_cleanup;
 			}
 	}
 
 
-	argbuf = PyMem_Malloc(argbuf_len); 
+	argbuf = PyMem_Malloc(argbuf_len);
 	if (argbuf == 0) {
 		PyErr_NoMemory();
 		goto error_cleanup;
 	}
 
 	if (variadicAllArgs) {
-		if (PyObjCFFI_AllocByRef(Py_SIZE(methinfo)+PyTuple_Size(args), 
+		if (PyObjCFFI_AllocByRef(Py_SIZE(methinfo)+PyTuple_Size(args),
 					&byref, &byref_attr) < 0) {
 			goto error_cleanup;
 		}
 		}
 	}
 
-	/* Set 'self' argument, for class methods we use the class */ 
+	/* Set 'self' argument, for class methods we use the class */
 	if (flags & PyObjCSelector_kCLASS_METHOD) {
 		if (PyObjCObject_Check(self)) {
 			self_obj = PyObjCObject_GetObject(self);
 			}
 
 		} else {
-			PyErr_Format(PyExc_TypeError, 
-				"Need objective-C object or class as self, not an instance of '%s'", 
+			PyErr_Format(PyExc_TypeError,
+				"Need objective-C object or class as self, not an instance of '%s'",
 					Py_TYPE(self)->tp_name);
 			goto error_cleanup;
 		}
 		values[1] = &theSel;
 		msgResult = argbuf;
 		argbuf_cur = align(resultSize, sizeof(void*));
-		
+
 	} else {
 		objc_superSetReceiver(super, self_obj);
 		if (meth->sel_flags & PyObjCSelector_kCLASS_METHOD) {
-			objc_superSetClass(super, 
+			objc_superSetClass(super,
 					object_getClass(meth->sel_class));
 		} else {
 			objc_superSetClass(super,  meth->sel_class);
 		}
 
 		useStret = 0;
-		if (*rettype == _C_STRUCT_B && 
+		if (*rettype == _C_STRUCT_B &&
 #ifdef  __ppc64__
 			ffi64_stret_needs_ptr(signature_to_ffi_return_type(rettype), NULL, NULL)
 
 			(resultSize > SMALL_STRUCT_LIMIT
 #ifdef __i386__
 			 /* darwin/x86 ABI is slightly odd ;-) */
-			 || (resultSize != 1 
-				&& resultSize != 2 
-				&& resultSize != 4 
+			 || (resultSize != 1
+				&& resultSize != 2
+				&& resultSize != 4
 				&& resultSize != 8)
 #endif
 #ifdef __x86_64__
 			 /* darwin/x86-64 ABI is slightly odd ;-) */
-			 || (resultSize != 1 
-				&& resultSize != 2 
-				&& resultSize != 4 
+			 || (resultSize != 1
+				&& resultSize != 2
+				&& resultSize != 4
 				&& resultSize != 8
 				&& resultSize != 16
 				)
 			)
 #endif /* !__ppc64__ */
 			) {
-		
+
 			useStret = 1;
 		}
 		superPtr = &super;
 
 	PyObjC_DURING
 		if (PyObjCIMP_Check(aMeth)) {
-			ffi_call(&cif, FFI_FN(PyObjCIMP_GetIMP(aMeth)), 
+			ffi_call(&cif, FFI_FN(PyObjCIMP_GetIMP(aMeth)),
 				msgResult, values);
 
 		} else {
 			if (useStret) {
-				ffi_call(&cif, FFI_FN(objc_msgSendSuper_stret), 
+				ffi_call(&cif, FFI_FN(objc_msgSendSuper_stret),
 					msgResult, values);
 			} else {
-				ffi_call(&cif, FFI_FN(objc_msgSendSuper), 
+				ffi_call(&cif, FFI_FN(objc_msgSendSuper),
 					msgResult, values);
 
 			}
 	}
 
 	result = PyObjCFFI_BuildResult(methinfo, 2, msgResult, byref,
-			byref_attr, byref_out_count, 
+			byref_attr, byref_out_count,
 			self, flags, values);
 
 	if (variadicAllArgs) {
 		return NULL;
 	}
 
-	rv = ffi_prep_cif(cif, FFI_DEFAULT_ABI, Py_SIZE(methinfo), 
+	rv = ffi_prep_cif(cif, FFI_DEFAULT_ABI, Py_SIZE(methinfo),
 		cl_ret_type, cl_arg_types);
 
 	if (rv != FFI_OK) {
 	return (IMP)cl;
 }
 
-/* 
+/*
  * PyObjCFFI_FreeClosure - Free the closure created by PyObjCFFI_MakeClosure
  *
  * Returns the userdata.

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

 /*
  * Implementation of objective-C object wrapper
  *
- * NOTE: We're using CFRetain and CFRelease to manage the retaincount of the Objective-C 
+ * NOTE: We're using CFRetain and CFRelease to manage the retaincount of the Objective-C
  * objects because that will do the right thing when Garbage Collection is involved.
  */
 #include "pyobjc.h"
 
 #include <objc/Object.h>
 
-/* 
+/*
  * Support for NSKeyValueObserving on MacOS X 10.3 and later.
- *      
- */     
+ *
+ */
 
-/* 
+/*
  * XXX: for reasons beyond my current comprehension the "legacy" block must be active, otherwise we
  * get a fatal python error.
  */
 	if (_checkedKVO == 0) {
 		if ([NSObject instancesRespondToSelector:@selector(willChangeValueForKey:)] &&
 			[NSObject instancesRespondToSelector:@selector(didChangeValueForKey:)]) {
-			_checkedKVO = 1; 
+			_checkedKVO = 1;
 
 		} else {
 
 
 static void
 _UseKVO(NSObject *self, NSString *key, BOOL willChange)
-{           
+{
     PyObjC_DURING
         int _checkedKVO = _KVOHackLevel();
         if (_checkedKVO == -1 || [key characterAtIndex:0] == (unichar)'_') {
         }
     PyObjC_HANDLER
     PyObjC_ENDHANDLER
-}           
+}
 
-#else 
+#else
 
 static void
 _UseKVO(NSObject *self, NSString *key, BOOL willChange)
-{           
+{
     PyObjC_DURING
         if ([key characterAtIndex:0] == (unichar)'_') {
 	    /* pass */
         }
     PyObjC_HANDLER
     PyObjC_ENDHANDLER
-}           
+}
 
 #endif
-			
+
 static PyObject*
 object_new(
 	PyTypeObject*  type __attribute__((__unused__)),
 		return PyObjC_IdToPython(p);
 
 	} else {
-		PyErr_SetString(PyExc_TypeError, 
+		PyErr_SetString(PyExc_TypeError,
 			"Use class methods to instantiate new Objective-C objects");
 		return NULL;
 	}
 
 	if (PyObjCObject_IsBlock(obj)) {
 		PyObjCMethodSignature* v = PyObjCObject_GetBlock(obj);
-		PyObjCObject_SET_BLOCK(obj, NULL);	
+		PyObjCObject_SET_BLOCK(obj, NULL);
 		Py_XDECREF(v);
 	}
-			
 
-	if (PyObjCObject_GetFlags(obj) != PyObjCObject_kDEALLOC_HELPER 
+
+	if (PyObjCObject_GetFlags(obj) != PyObjCObject_kDEALLOC_HELPER
 			&& PyObjCObject_GetObject(obj) != nil) {
 		/* Release the proxied object, we don't have to do this when
 		 * there is no proxied object.
 				& PyObjCObject_kSHOULD_NOT_RELEASE)) {
 			/* pass */
 
-		} else if (((PyObjCObject*)obj)->flags 
+		} else if (((PyObjCObject*)obj)->flags
 				& PyObjCObject_kUNINITIALIZED) {
-			/* Freeing of an uninitialized object, just leak because 
+			/* Freeing of an uninitialized object, just leak because
 			 * there is no reliable manner to free such objects.
 			 *
-			 * - [obj release] doesn't work because some classes 
+			 * - [obj release] doesn't work because some classes
 			 *   cause crashes for uninitialized objects
-			 * - [[obj init] release] also doesn't work because 
+			 * - [[obj init] release] also doesn't work because
 			 *   not all classes implement -init
-			 * - [obj dealloc] doesn't work for class 
+			 * - [obj dealloc] doesn't work for class
 			 *   clusters like NSArray.
 			 */
 			char buf[256];
-			snprintf(buf, sizeof(buf), 
+			snprintf(buf, sizeof(buf),
 				"leaking an uninitialized object of type %s",
 				Py_TYPE(obj)->tp_name);
 			PyErr_Warn(PyObjCExc_UnInitDeallocWarning, buf);
 			PyObjC_DURING
 				if (((PyObjCObject*)obj)->flags & PyObjCObject_kCFOBJECT) {
 					CFRelease(((PyObjCObject*)obj)->objc_object);
-				} else if (strcmp(object_getClassName(((PyObjCObject*)obj)->objc_object), 
+				} else if (strcmp(object_getClassName(((PyObjCObject*)obj)->objc_object),
 						"NSAutoreleasePool") != 0) {
 
 				        CFRelease(((PyObjCObject*)obj)->objc_object);
 		 */
 
 	} else {
-		/* Special hack for KVO on MacOS X, when an object is observed it's 
+		/* Special hack for KVO on MacOS X, when an object is observed it's
 		 * ISA is changed by the runtime. We change the python type as well.
 		 */
 		tp = (PyTypeObject*)PyObjCClass_New(object_getClass(obj_inst));
 // XXX: You'd expect the code below works, but it actually doesn't. Need to check why.
 //			Py_DECREF(Py_TYPE(obj));
 //			Py_TYPE(obj) = tp;
-//			
+//
 
 			PyObjCClass_CheckMethodList((PyObject*)tp, 0);
 			dict = tp->tp_dict;
 	}
 
 	f = NULL;
-	if (descr != NULL 
+	if (descr != NULL
 #if PY_MAJOR_VERSION == 2
 		&& PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)
 #endif
 	if (strcmp(PyBytes_AS_STRING(bytes), "__del__") == 0) {
 		res = PyObjCClass_GetDelMethod((PyObject*)Py_TYPE(obj));
 		if (res != NULL) {
-			/* XXX: bind self */	
+			/* XXX: bind self */
 		}
 		goto done;
 	}
 done:
 	if (res != NULL) {
 		/* class methods cannot be accessed through instances */
-		if (PyObjCSelector_Check(res) 
+		if (PyObjCSelector_Check(res)
 				&& PyObjCSelector_IsClassMethod(res)) {
 			Py_DECREF(res);
 #if PY_MAJOR_VERSION == 2
 	id obj_inst;
 	NSString *obj_name;
 	PyObject* bytes;
-	
+
 	if (PyUnicode_Check(name)) {
 		bytes = PyUnicode_AsEncodedString(name, NULL, NULL);
 		if (bytes == NULL) return -1;
 	}
 	descr = _type_lookup(tp, name);
 	f = NULL;
-	if (descr != NULL 
+	if (descr != NULL
 #if PY_MAJOR_VERSION == 2
 		&& PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS)
 #endif
 		PyObject *dict;
 
 		dict = *dictptr;
-		
+
 		if (dict == NULL && value != NULL) {
 			dict = PyDict_New();
 			if (dict == NULL) {
 				res = -1;
 				goto done;
 			}
-			
+
 			*dictptr = dict;
 		}
 		if (dict != NULL) {
 }
 
 PyDoc_STRVAR(objc_get_real_class_doc, "Return the current ISA of the object");
-static PyObject* 
+static PyObject*
 objc_get_real_class(PyObject* self, void* closure __attribute__((__unused__)))
 {
 	id obj_object;
 		return  -1;
 	}
 
-	if (newVal != NULL) {
-		if (!PyObjCMethodSignature_Check(newVal)) {
-			PyErr_SetString(PyExc_TypeError, "New value must be a method signature");
-			return -1;
-		}
-	}
+        if (newVal == NULL) {
+            PyErr_SetString(PyExc_TypeError, "Cannot delete __block_signature__ attribute");
+            return -1;
+        }
+
+
+        if (newVal == Py_None) {
+            newVal = NULL;
+
+#if 0
+        } else if (PyDict_Check(newVal)) {
+            newVal = PyObjCMethodSignature_WithMetaData(NULL, newVal);
+            if (newVal == NULL) {
+                return -1;
+            }
+#endif
+
+        } else if (PyObjCMethodSignature_Check(newVal)) {
+            Py_INCREF(newVal);
+
+        } else {
+                PyErr_SetString(PyExc_TypeError, "New value must be a method signature");
+                return -1;
+        }
 
 	PyObject* v = (PyObject*)PyObjCObject_GetBlock(self);
 	if (v != NULL) {
 	}
 
 
-	Py_XINCREF(newVal);
 	PyObjCObject_SET_BLOCK(self, (PyObjCMethodSignature*)newVal);
 	return 0;
 }
 	object_getattro,			/* tp_getattro */
 	object_setattro,			/* tp_setattro */
 	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT 
+	Py_TPFLAGS_DEFAULT
 		| Py_TPFLAGS_BASETYPE,          /* tp_flags */
  	0,					/* tp_doc */
  	0,					/* tp_traverse */
      },
 #if PY_MAJOR_VERSION == 2
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 #if PY_VERSION_HEX >= 0x02050000
        , 0
 #endif
      }, /* as_number */
      { 0, 0, 0 },			/* as_mapping */
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },	/* as_sequence */
-     { 0, 0, 0, 0 
+     { 0, 0, 0, 0
 #if PY_VERSION_HEX >= 0x02060000
 	 , 0, 0
 #endif
      0,					/* name */
      0,					/* slots */
 #else /* Python 3 */
-     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 
+     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
      }, /* as_number */
      { 0,0,0
      }, /* as_mapping */
  *  Allocate a proxy object for use during the call of __del__,
  *  this isn't a full-featured proxy object.
  */
-PyObject* 
+PyObject*
 _PyObjCObject_NewDeallocHelper(id objc_object)
 {
 	PyObject* res;
 	}
 
 	PyObjCClass_CheckMethodList((PyObject*)Py_TYPE(res), 1);
-	
+
 	((PyObjCObject*)res)->objc_object = objc_object;
 	((PyObjCObject*)res)->flags = PyObjCObject_kDEALLOC_HELPER;
 	return res;
 		 * zero out the instance.
 		 */
 		char buf[256];
-		snprintf(buf, sizeof(buf), 
+		snprintf(buf, sizeof(buf),
 			"revived Objective-C object of type %s. Object is zero-ed out.",
 			Py_TYPE(obj)->tp_name);
 
 }
 
 
-PyObject* 
+PyObject*
 PyObjCObject_New(id objc_object, int flags, int retain)
 {
 	Class cls = object_getClass(objc_object);
 		flags |= PyObjCObject_kBLOCK;
 	}
 
-	/* This should be in the tp_alloc for the new class, but 
+	/* This should be in the tp_alloc for the new class, but
 	 * adding a tp_alloc to PyObjCClass_Type doesn't seem to help
 	 */
 	PyObjCClass_CheckMethodList((PyObject*)Py_TYPE(res), 1);
-	
+
 	((PyObjCObject*)res)->objc_object = objc_object;
 	((PyObjCObject*)res)->flags = flags;
 
         }
 
 	if (retain) {
-		if (strcmp(object_getClassName(objc_object), 
+		if (strcmp(object_getClassName(objc_object),
 						"NSAutoreleasePool") != 0) {
 			/* NSAutoreleasePool doesn't like retain */
 			CFRetain(objc_object);
 	return res;
 }
 
-PyObject* 
+PyObject*
 PyObjCObject_FindSelector(PyObject* object, SEL selector)
 {
 	PyObject* meth;
-	
+
 	meth = PyObjCClass_FindSelector((PyObject*)Py_TYPE(object), selector, NO);
 
 	if (meth == NULL) {
-		return NULL; 
+		return NULL;
 	} else {
 		return meth;
-	}	
+	}
 }
 
 id
 		PyErr_Format(PyExc_TypeError,
 			"'objc.objc_object' expected, got '%s'",
 			Py_TYPE(object)->tp_name);
-		
+
 	}
 	return PyObjCObject_GetObject(object);
 }
 
-void        
+void
 PyObjCObject_ClearObject(PyObject* object)
 {
 	if (!PyObjCObject_Check(object)) {
 		PyErr_Format(PyExc_TypeError,
 			"'objc.objc_object' expected, got '%s'",
 			Py_TYPE(object)->tp_name);
-		
+
 	}
 	PyObjC_UnregisterPythonProxy(
 			((PyObjCObject*)object)->objc_object, object);

pyobjc-core/Modules/objc/selector.m

  * This is meant to be used to add _C_IN, _C_OUT and _C_INOUT specifiers for
  * pass-by-reference parameters.
  *
- * We register class names because the actual class may not yet be available. 
- * The list of replacements is not sorted in any way, it is expected to be 
+ * We register class names because the actual class may not yet be available.
+ * The list of replacements is not sorted in any way, it is expected to be
  * short and the list won't be checked very often.\
  *
  * Alternative implementation: { SEL: [ (class_name, signature), ... ], ... }
  */
 static PyObject* replacement_signatures = NULL;
 
-int 
+int
 ObjC_SignatureForSelector(char* class_name, SEL selector, char* signature)
 {
 	PyObject* replacement;
 	return r;
 }
 
-static char* 
+static char*
 PyObjC_FindReplacementSignature(Class cls, SEL selector)
 {
 	PyObject* replacement;
 	return Py_None;
 }
 
-PyDoc_STRVAR(base_class_method_doc, 
+PyDoc_STRVAR(base_class_method_doc,
 	"True if this is a class method, False otherwise");
 static PyObject*
 base_class_method(PyObject* _self, void* closure __attribute__((__unused__)))
 	return PyBool_FromLong(0 != (self->sel_flags & PyObjCSelector_kCLASS_METHOD));
 }
 
-PyDoc_STRVAR(base_required_doc, 
+PyDoc_STRVAR(base_required_doc,
 	"True if this is a required method, False otherwise");
 static PyObject*
 base_required(PyObject* _self, void* closure __attribute__((__unused__)))
 		base_class_method_doc,
 		0
 	},
-	{ 
-		"definingClass", 
-		base_class, 
+	{
+		"definingClass",
+		base_class,
 		0,
-		base_class_doc, 
+		base_class_doc,
 		0
 	},
-	{ 
-		"signature", 
-		base_signature, 
+	{
+		"signature",
+		base_signature,
 		base_signature_setter,
-		base_signature_doc, 
+		base_signature_doc,
 		0
 	},
 	{
 		base_native_signature_doc,
 		0
 	},
-	{ 
-		"self", 
-		base_self, 
+	{
+		"self",
+		base_self,
 		0,
-		base_self_doc, 
+		base_self_doc,
 		0
 	},
-	{ 
-		"selector",  
-		base_selector, 
-		0, 
+	{
+		"selector",
+		base_selector,
+		0,
 		base_selector_doc,
 		0
 	},
-	{ 
-		"__name__",  
-		base_selector, 
-		0, 
+	{
+		"__name__",
+		base_selector,
+		0,
 		base_selector_doc,
 		0
 	},
 static void
 sel_dealloc(PyObject* object)
 {
-	PyObjCSelector* self = (PyObjCSelector*)object;	
+	PyObjCSelector* self = (PyObjCSelector*)object;
 	Py_XDECREF(self->sel_methinfo);
 	self->sel_methinfo = NULL;
 
 		PyMem_Free((char*)self->sel_native_signature);
 		self->sel_native_signature = NULL;
 	}
-	if (self->sel_self) { 
-		Py_DECREF(self->sel_self); 
+	if (self->sel_self) {
+		Py_DECREF(self->sel_self);
 		self->sel_self = NULL;
 	}
 	Py_TYPE(object)->tp_free(object);
 
 static int
 base_descr_set(
-		PyObject* self __attribute__((__unused__)), 
+		PyObject* self __attribute__((__unused__)),
 		PyObject* obj __attribute__((__unused__)), PyObject* value)
 {
 	if (value == NULL) {
 	PyObject* pyres;
 
 	if (kwds != NULL && PyObject_Size(kwds) != 0) {
-		PyErr_SetString(PyExc_TypeError, 
+		PyErr_SetString(PyExc_TypeError,
 		    "Objective-C selectorrs don't support keyword arguments");
 		return NULL;
 	}
 		execute = self->sel_call_func;
 	} else {
 		execute = PyObjC_FindCallFunc(
-				self->sel_class, 
+				self->sel_class,
 				self->sel_selector);
 		if (execute == NULL) return NULL;
 		self->sel_call_func = execute;
 		myClass = PyObjCClass_New(self->sel_class);
 		if (!(PyObject_IsInstance(pyself, myClass)
 #if PY_MAJOR_VERSION == 2
-			|| (PyString_Check(pyself) && class_isSubclassOf(self->sel_class, [NSString class])) 
+			|| (PyString_Check(pyself) && class_isSubclassOf(self->sel_class, [NSString class]))
 #endif
-			|| (PyUnicode_Check(pyself) && class_isSubclassOf(self->sel_class, [NSString class])) 
+			|| (PyUnicode_Check(pyself) && class_isSubclassOf(self->sel_class, [NSString class]))
 		)) {
 			Py_DECREF(arglist);
 			Py_DECREF(myClass);
 			return NULL;
 		}
 		Py_DECREF(myClass);
-		
+
 
 		pyres = res = execute((PyObject*)self, pyself, arglist);
 		if (pyres != NULL
 		if (self->sel_flags & PyObjCSelector_kRETURNS_UNINITIALIZED) {
 			((PyObjCObject*)pyres)->flags |= PyObjCObject_kUNINITIALIZED;
 		} else if (((PyObjCObject*)pyself)->flags & PyObjCObject_kUNINITIALIZED) {
-			((PyObjCObject*)pyself)->flags &= 
+			((PyObjCObject*)pyself)->flags &=
 				~PyObjCObject_kUNINITIALIZED;
 			if (self->sel_self && self->sel_self != pyres && !PyErr_Occurred()) {
 				PyObjCObject_ClearObject(self->sel_self);
 	if (meth->sel_self != NULL || obj == Py_None) {
 		Py_INCREF(meth);
 		return (PyObject*)meth;
-	} 
+	}
 
 	if (class != nil && PyType_Check(class) && PyType_IsSubtype((PyTypeObject*)class, &PyObjCClass_Type)) {
 		class = PyObjCClass_ClassForMetaClass(class);
 		NS_DURING
 			if ([cls instancesRespondToSelector:sel]) {
 				methsig = [cls instanceMethodSignatureForSelector:sel];
-				retval = PyObjCSelector_NewNative(cls, sel, 
+				retval = PyObjCSelector_NewNative(cls, sel,
 					PyObjC_NSMethodSignatureToTypeString(methsig, buf, sizeof(buf)), 0);
 			} else if ((Object_class != nil) && (cls != Object_class) && nil != (methsig = [(NSObject*)cls methodSignatureForSelector:sel])) {
-				retval = PyObjCSelector_NewNative(cls, sel, 
+				retval = PyObjCSelector_NewNative(cls, sel,
 					PyObjC_NSMethodSignatureToTypeString(
 						methsig, buf, sizeof(buf)), 1);
 			} else {
 				PyObjCNativeSelector* res;
 
 				res =  (PyObjCNativeSelector*)PyObjCSelector_NewNative(
-					object_getClass(object), sel, 
-					PyObjC_NSMethodSignatureToTypeString(methsig, 
+					object_getClass(object), sel,
+					PyObjC_NSMethodSignatureToTypeString(methsig,
 						buf, sizeof(buf)), 0);
 				if (res != NULL) {
 					/* Bind the method to self */
 
 
 PyObject*
-PyObjCSelector_NewNative(Class class, 
+PyObjCSelector_NewNative(Class class,
 			SEL selector, const char* signature, int class_method)
 {
 	PyObjCNativeSelector* result;
 static char gSheetMethodSignature[] = { _C_VOID, _C_ID, _C_SEL, _C_ID, _C_INT, _C_PTR , _C_VOID, 0 };
 
 PyObject*
-PyObjCSelector_New(PyObject* callable, 
+PyObjCSelector_New(PyObject* callable,
 	SEL selector, const char* signature, int class_method, Class cls)
 {
 	PyObjCPythonSelector* result;
 
 	return (PyObject*)result;
 }
-	
+
 
 /*
- * Selector type for python selectors (that is, selectors that are 
+ * Selector type for python selectors (that is, selectors that are
  * implemented as python methods)
  *
  * This one can be allocated from python code.
  */
 
-static long 
+static long
 pysel_hash(PyObject* o)
 {
 	PyObjCPythonSelector* self = (PyObjCPythonSelector*)o;
 				same = 0;
 			}
 			r = PyObject_RichCompareBool(
-					sel_a->callable, 
+					sel_a->callable,
 					sel_b->callable, Py_EQ);
 			if (r == -1) {
 				return NULL;
  *
  * pysel_call needs to compensate for this, which is done by this function.
  */
-static PyObject* 
+static PyObject*
 compensate_arglist(PyObject* _self, PyObject* args, PyObject* kwds)
 {
 	/* XXX: need to do a full metadata processing run here to get exactly the right
 				if (self->sel_methinfo->argtype[i].type[0] == _C_OUT) {
 					PyObject* a = PyTuple_GET_ITEM(args, first_arg + i - 2);
 					if (a != Py_None && a != PyObjC_NULL) {
-						PyErr_Format(PyExc_TypeError, 
+						PyErr_Format(PyExc_TypeError,
 							"argument %" PY_FORMAT_SIZE_T "d is an output argument but is passed a value other than None or objc.NULL (%s)",
 							i-1-first_arg, PyObject_REPR(args));
 						return NULL;
 			for (i = 2; i < Py_SIZE(methinfo); i++) {
 				if (methinfo->argtype[i].type[0] == _C_OUT) {
 					PyTuple_SET_ITEM(real_args, i-2+first_arg, Py_None);
-					Py_INCREF(Py_None); 
+					Py_INCREF(Py_None);
 				} else {
 					PyTuple_SET_ITEM(real_args, i-2+first_arg, PyTuple_GET_ITEM(args, pyarg));
 					Py_INCREF(PyTuple_GET_ITEM(args, pyarg));
 	PyObject* result;
 
 	if (self->callable == NULL) {
-		PyErr_Format(PyExc_TypeError, 
+		PyErr_Format(PyExc_TypeError,
 			"Calling abstract methods with selector %s",
 			sel_getName(self->sel_selector));
 		return NULL;
 			self_arg = PyTuple_GET_ITEM(args, 0);
 			if (!PyObjCObject_Check(self_arg) && !PyObjCClass_Check(self_arg)) {
 				Py_DECREF(args);
-				PyErr_Format(PyExc_TypeError, 
+				PyErr_Format(PyExc_TypeError,
 					"Expecting an Objective-C class or "
 					"instance as self, got a %s",
 					Py_TYPE(self_arg)->tp_name);
 	/*
 	 * Assume callable will check arguments
 	 */
-	if (self->sel_self == NULL) { 
+	if (self->sel_self == NULL) {
 		result  = PyObject_Call(self->callable, args, kwargs);
 		Py_DECREF(args);
 
 			Py_XINCREF(v);
 			PyTuple_SET_ITEM(actual_args, i+1, v);
 		}
-		result = PyObject_Call(self->callable, 
-			actual_args, kwargs);	
+		result = PyObject_Call(self->callable,
+			actual_args, kwargs);
 		Py_DECREF(actual_args);
 		Py_DECREF(args);
 	}
 	return result;
 }
 
-static char* 
+static char*
 pysel_default_signature(PyObject* callable)
 {
 	PyCodeObject* func_code;
 	Py_ssize_t    buffer_len;
 	Py_ssize_t    i;
 	int           was_none;
-	
+
 	if (PyFunction_Check(callable)) {
 		func_code = (PyCodeObject*)PyFunction_GetCode(callable);
 	} else if (PyMethod_Check(callable)) {
 		return NULL;
 	}
 
-	
+
 	/* arguments + return-type + selector */
 	result = PyMem_Malloc(arg_count+3);
 	if (result == 0) {
 		return NULL;
 	}
 
-	/* 
+	/*
 	   Scan bytecode to find return statements.  If any non-bare return
 	   statement exists, then set the return type to @ (id).
 	*/
 static SEL
 pysel_default_selector(PyObject* callable)
 {
-	char buf[1024]; 
+	char buf[1024];
 	char* cur;
 	PyObject* name = PyObject_GetAttrString(callable, "__name__");
 
 SEL
 PyObjCSelector_DefaultSelector(const char* methname)
 {
-	char buf[1024]; 
+	char buf[1024];
 	char* cur;
 	Py_ssize_t ln;
 
 		}
 	}
 
-	/* Skip leading underscores, '_doFoo_' is probably '_doFoo:' in 
+	/* Skip leading underscores, '_doFoo_' is probably '_doFoo:' in
 	 * Objective-C, not ':doFoo:'.
 	 *
 	 * Also if the name starts and ends with two underscores, return
 	 * it unmodified. This avoids mangling of Python's special methods.
 	 *
-	 * Both are heuristics and could be the wrong choice, but either 
+	 * Both are heuristics and could be the wrong choice, but either
 	 * form is very unlikely to exist in ObjC code.
 	 */
 	cur = buf;
 }
 
 static char*
-python_signature_to_objc(char* rettype, char* argtypes, char* buf, 
+python_signature_to_objc(char* rettype, char* argtypes, char* buf,
 	size_t buflen)
 {
 	char* result = buf;
 
 	if (buflen < 4) {
-		PyErr_SetString(PyExc_RuntimeError, 
+		PyErr_SetString(PyExc_RuntimeError,
 			"Too small buffer for python_signature_to_objc");
 		return NULL;
 	}
 		*buf++ = '\0';
 		return result;
 	}
-	
+
 	/* encode arguments */
 	while (buflen > 0 && *argtypes) {
 		*buf = pytype_to_objc(*argtypes++);
 	}
 
 	if (buflen == 0) {
-		PyErr_SetString(PyExc_RuntimeError, 
+		PyErr_SetString(PyExc_RuntimeError,
 			"Too small buffer for python_signature_to_objc");
 		return NULL;
 	}
 	*buf = 0;
 	return result;
 }
-	
+
 
 /* TODO: Check value of 'signature' */
 static PyObject*
-pysel_new(PyTypeObject* type __attribute__((__unused__)), 
+pysel_new(PyTypeObject* type __attribute__((__unused__)),
 	  PyObject* args, PyObject* kwds)
 {
-static	char*	keywords[] = { "function", "selector", "signature", 
-				"isClassMethod", "argumentTypes", 
+static	char*	keywords[] = { "function", "selector", "signature",
+				"isClassMethod", "argumentTypes",
 				"returnType", "isRequired", "isHidden", NULL };
 	PyObjCPythonSelector* result;
 	PyObject* callable;
 	int       required = 1;
 	int       hidden = 0;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, 
+	if (!PyArg_ParseTupleAndKeywords(args, kwds,
 				"O|"Py_ARG_BYTES Py_ARG_BYTES"issii:selector",
 			keywords, &callable, &selector, &signature,
 			&class_method, &argtypes, &rettype, &required, &hidden)) {
 			cur = PyObjCRT_SkipTypeSpec(cur);
 			if (cur == NULL) {
 				PyErr_SetString(
-					PyExc_ValueError, 
+					PyExc_ValueError,
 					"invalid signature");
 				return NULL;
 			}
 				Py_None, &PyList_Type);
 		if (tmp == NULL) {
 			return NULL;
-		} 
+		}
 
 		if (PyFunction_Check(tmp)) {
 			/* A 'staticmethod' instance, cannot convert */