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

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Wed Apr  1 10:08:52 2009
New Revision: 2128

Log:
Make it possible to use writable python buffers
as the backingstore for an "variable-sized" output
arguments.

This makes it possible to use NSBitmapImageRep getPixel:atX:y:
from Python.


Modified:
   trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m	Wed Apr  1 10:08:52 2009
@@ -763,6 +763,30 @@
 
 	/* A more complex array */
 
+#if PY_VERSION_HEX >= 0x02060000
+	if (PyObject_CheckBuffer(obj)) {
+		/* An object that implements the new-style buffer interface.
+		 * Use the buffer interface description to check if the buffer
+		 * type is compatible with what we expect.
+		 * 
+		 * Specifically:
+		 * - If the C code expects an array of basic types:
+		 *   the buffer must be a single-dimensional array of 
+		 *   a compatible type. 
+		 * - If the C code expects and array of structures:
+		 *   The python array must be two dimensional, one row
+		 *   in the python array corresponds to one struct "instance"
+		 * - If the C code expects a multi-dimensional array: 
+		 *   the python buffer must have a compatible dimension.
+		 *
+		 * The array must be large enough and  mustn't contain holes
+		 * in the fragment that gets used by us.
+		 */
+
+	}
+
+#endif
+
 	if (array_check(pythonList)) {
 		/* An array.array. Only convert if the typestr describes an
 		 * simple type of the same type as the array, or a struct/array
@@ -832,9 +856,9 @@
 				return -1;
 			}
 			*array = buf;
-			*bufobj = pythonList;
-			Py_INCREF(pythonList);
 		}
+		*bufobj = pythonList;
+		Py_INCREF(pythonList);
 		return SHOULD_IGNORE;
 
 #ifdef PyObjC_ENABLE_NUMARRAY

------------------------------------------------------------------------------
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.