[Python-3000-checkins] r58448 - in python/branches/py3k: Include/object.h Modules/arraymodule.c Objects/abstract.c Objects/unicodeobject.c Python/getargs.c

travis.oliphant python-3000-checkins at python.org
Sat Oct 13 23:03:28 CEST 2007


Author: travis.oliphant
Date: Sat Oct 13 23:03:27 2007
New Revision: 58448

Modified:
   python/branches/py3k/Include/object.h
   python/branches/py3k/Modules/arraymodule.c
   python/branches/py3k/Objects/abstract.c
   python/branches/py3k/Objects/unicodeobject.c
   python/branches/py3k/Python/getargs.c
Log:
Eliminate use of PyBUF_CHARACTER flag which is no longer part of the buffer interface.  Fix up array module to export the correct format for wide-builds.

Modified: python/branches/py3k/Include/object.h
==============================================================================
--- python/branches/py3k/Include/object.h	(original)
+++ python/branches/py3k/Include/object.h	Sat Oct 13 23:03:27 2007
@@ -160,18 +160,17 @@
 
         /* Flags for getting buffers */
 #define PyBUF_SIMPLE 0
-#define PyBUF_CHARACTER 1
-#define PyBUF_WRITABLE 0x0002
+#define PyBUF_WRITABLE 0x0001
 /*  we used to include an E, backwards compatible alias  */
 #define PyBUF_WRITEABLE PyBUF_WRITABLE
-#define PyBUF_LOCK 0x0004
-#define PyBUF_FORMAT 0x0008
-#define PyBUF_ND 0x0010
-#define PyBUF_STRIDES (0x0020 | PyBUF_ND)
-#define PyBUF_C_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
-#define PyBUF_F_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
-#define PyBUF_ANY_CONTIGUOUS (0x0100 | PyBUF_STRIDES)
-#define PyBUF_INDIRECT (0x0200 | PyBUF_STRIDES)
+#define PyBUF_LOCK 0x0002
+#define PyBUF_FORMAT 0x0004
+#define PyBUF_ND 0x0008
+#define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
 
 #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
 #define PyBUF_CONTIG_RO (PyBUF_ND)

Modified: python/branches/py3k/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k/Modules/arraymodule.c	(original)
+++ python/branches/py3k/Modules/arraymodule.c	Sat Oct 13 23:03:27 2007
@@ -385,7 +385,7 @@
 static struct arraydescr descriptors[] = {
 	{'b', 1, b_getitem, b_setitem, "b"},
 	{'B', 1, BB_getitem, BB_setitem, "B"},
-	{'u', sizeof(Py_UNICODE), u_getitem, u_setitem, "U"},
+	{'u', sizeof(Py_UNICODE), u_getitem, u_setitem, "u"},
 	{'h', sizeof(short), h_getitem, h_setitem, "h"},
 	{'H', sizeof(short), HH_getitem, HH_setitem, "H"},
 	{'i', sizeof(int), i_getitem, i_setitem, "i"},
@@ -1784,11 +1784,6 @@
 static int
 array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
 {
-        if ((flags & PyBUF_CHARACTER)) {
-                PyErr_SetString(PyExc_TypeError,
-                                "Cannot be a character buffer");
-                return -1;
-        }
         if ((flags & PyBUF_LOCK)) {
                 PyErr_SetString(PyExc_BufferError,
                                 "Cannot lock data");
@@ -1815,6 +1810,11 @@
         view->internal = NULL;
         if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) {
                 view->format = self->ob_descr->formats;
+#ifdef Py_UNICODE_WIDE
+		if (self->ob_descr->typecode == 'u') {
+			view->formats = "w";
+		}
+#endif
         }
 
  finish:

Modified: python/branches/py3k/Objects/abstract.c
==============================================================================
--- python/branches/py3k/Objects/abstract.c	(original)
+++ python/branches/py3k/Objects/abstract.c	Sat Oct 13 23:03:27 2007
@@ -236,7 +236,7 @@
 				"expected an object with the buffer interface");
 		return -1;
 	}
-	if ((*pb->bf_getbuffer)(obj, &view, PyBUF_CHARACTER)) return -1;
+	if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE)) return -1;
 
 	*buffer = view.buf;
 	*buffer_len = view.len;

Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c	(original)
+++ python/branches/py3k/Objects/unicodeobject.c	Sat Oct 13 23:03:27 2007
@@ -8117,10 +8117,6 @@
 unicode_buffer_getbuffer(PyUnicodeObject *self, Py_buffer *view, int flags)
 {
 
-    if (flags & PyBUF_CHARACTER) {
-        PyErr_SetString(PyExc_SystemError, "can't use str as char buffer");
-        return -1;
-    }
     return PyBuffer_FillInfo(view, (void *)self->str,
                              PyUnicode_GET_DATA_SIZE(self), 1, flags);
 }

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Sat Oct 13 23:03:27 2007
@@ -1237,7 +1237,9 @@
                         (*pb->bf_releasebuffer)(arg, &view);
 		break;
 	}
-		
+
+	  /*TEO: This can be eliminated --- here only for backward
+	    compatibility */
 	case 't': { /* 8-bit character buffer, read-only access */
 		char **p = va_arg(*p_va, char **);
 		PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
@@ -1253,7 +1255,7 @@
 				"string or read-only character buffer",
 				arg, msgbuf, bufsize);
 
-		if ((*pb->bf_getbuffer)(arg, &view, PyBUF_CHARACTER) != 0) 
+		if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0) 
 			return converterr("string or single-segment read-only buffer",
                                           arg, msgbuf, bufsize);
 


More information about the Python-3000-checkins mailing list