[PyObjC-svn] r2020 - trunk/pyobjc/pyobjc-core/Modules/objc

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Wed Oct  8 14:21:35 2008
New Revision: 2020

Log:
Add support for decodeing function-pointers in the
result of function, that is
  <retval type='^?' function_pointer='true'>
  ...
  </retval>


Modified:
   trunk/pyobjc/pyobjc-core/Modules/objc/function.h
   trunk/pyobjc/pyobjc-core/Modules/objc/function.m
   trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/function.h
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/function.h	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/function.h	Wed Oct  8 14:21:35 2008
@@ -9,6 +9,9 @@
 extern PyObject*
 PyObjCFunc_New(PyObject* name, void* func, const char* signature, PyObject* doc, PyObject* meta);
 
+extern PyObject* 
+PyObjCFunc_WithMethodSignature(PyObject* name, void* func, PyObjCMethodSignature* signature);
+
 extern PyObjCMethodSignature*
 PyObjCFunc_GetMethodSignature(PyObject* func);
 

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	Wed Oct  8 14:21:35 2008
@@ -291,6 +291,30 @@
 	0					/* tp_del */
 };
 
+PyObject*
+PyObjCFunc_WithMethodSignature(PyObject* name, void* func, PyObjCMethodSignature* methinfo)
+{
+	func_object* result;
+
+	result = PyObject_NEW(func_object, &PyObjCFunc_Type);
+	if (result == NULL) return NULL;
+
+	result->function = func;
+	result->doc = NULL;
+	result->name = name;
+	Py_XINCREF(name);
+	result->module = NULL;
+	result->methinfo = methinfo;
+	Py_XINCREF(methinfo);
+
+	result->cif = PyObjCFFI_CIFForSignature(result->methinfo);
+	if (result->cif == NULL) {
+		Py_DECREF(result);
+		return NULL;	
+	}
+	
+	return (PyObject*)result;
+}
 
 
 PyObject* 

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	Wed Oct  8 14:21:35 2008
@@ -2949,7 +2949,18 @@
 		}
 
 		/* Pointer values: */
-		if (*tp == _C_CHARPTR || (*tp == _C_PTR && !PyObjCPointerWrapper_HaveWrapper(tp))) {
+		if (tp[0] == _C_PTR && tp[1] == _C_UNDEF && methinfo->rettype.callable) {
+			if (*(void**)pRetval == NULL) {
+				objc_result = Py_None;
+				Py_INCREF(Py_None);
+			} else {
+				objc_result = PyObjCFunc_WithMethodSignature(NULL, *(void**)pRetval, methinfo->rettype.callable);
+				if (objc_result == NULL) {
+					return NULL;
+				}
+			}
+
+		} else if (*tp == _C_CHARPTR || (*tp == _C_PTR && !PyObjCPointerWrapper_HaveWrapper(tp))) {
 			const char* resttype = tp + 1;
 			if (*tp == _C_CHARPTR) {
 				resttype = gCharEncoding;

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
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.