1. Ronald Oussoren
  2. pyobjc

Commits

Ronald Oussoren  committed 11c86da

"Fix" for bug #1146224

Due to the way PyObjC is implemented you cannot use varargs function (either
*args or **kwds) as methods. If you try to you'll get unexpected behaviour.

This patch makes using *args or **kwds on objc-methods illegal. Fixing the
issues would be preferable, but is a lot of work.

  • Participants
  • Parent commits 42ba0a9
  • Branches pyobjc-ancient

Comments (0)

Files changed (1)

File Modules/objc/selector.m

View file
 		PyErr_SetString(PyExc_TypeError, 
 				"expecting function or method");
 		return NULL;
-	}
+	} else {
+		PyCodeObject* c = NULL;
+		if (PyFunction_Check(callable)) {
+			c = (PyCodeObject*)PyFunction_GetCode(callable);
+		} else {
+			PyObject* func;
+
+			func = PyMethod_Function(callable);
+			if (PyFunction_Check(func)) {
+				c = (PyCodeObject*)PyFunction_GetCode(func);
+			}
+		}
+
+
+		if (c != NULL && (c->co_flags & CO_VARARGS)) {
+			PyErr_SetString(PyExc_TypeError,
+				"Using function with *args as an objc method");
+			return NULL;
+		}
+		if (c != NULL && (c->co_flags & CO_VARKEYWORDS)) {
+			PyErr_SetString(PyExc_TypeError,
+				"Using function with **args as an objc method");
+			return NULL;
+		}
+	} 
+
+
 
 	if (pyname == NULL) {
 		/* No name specified, use the function name */