[Python-3000-checkins] r58455 - in python/branches/py3k: Modules/_sre.c Modules/posixmodule.c Objects/unicodeobject.c Python/getargs.c

alexandre.vassalotti python-3000-checkins at python.org
Sun Oct 14 04:05:52 CEST 2007


Author: alexandre.vassalotti
Date: Sun Oct 14 04:05:51 2007
New Revision: 58455

Modified:
   python/branches/py3k/Modules/_sre.c
   python/branches/py3k/Modules/posixmodule.c
   python/branches/py3k/Objects/unicodeobject.c
   python/branches/py3k/Python/getargs.c
Log:
Remove the buffer API from PyUnicode as specified by PEP 3137.  Also,
fix the error message of the 't' format unit, in getargs.c, so that it
asks for bytes, instead of string.


Modified: python/branches/py3k/Modules/_sre.c
==============================================================================
--- python/branches/py3k/Modules/_sre.c	(original)
+++ python/branches/py3k/Modules/_sre.c	Sun Oct 14 04:05:51 2007
@@ -1674,6 +1674,15 @@
     void* ptr;
     Py_buffer view;
 
+    /* Unicode objects do not support the buffer API. So, get the data
+       directly instead. */
+    if (PyUnicode_Check(string)) {
+        ptr = (void *)PyUnicode_AS_DATA(string);
+        *p_length = PyUnicode_GET_SIZE(string);
+        *p_charsize = sizeof(Py_UNICODE);
+        return ptr;
+    }
+
     /* get pointer to string buffer */
     view.len = -1;
     buffer = Py_Type(string)->tp_as_buffer;

Modified: python/branches/py3k/Modules/posixmodule.c
==============================================================================
--- python/branches/py3k/Modules/posixmodule.c	(original)
+++ python/branches/py3k/Modules/posixmodule.c	Sun Oct 14 04:05:51 2007
@@ -2135,7 +2135,8 @@
     FILEFINDBUF3   ep;
     APIRET rc;
 
-    if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len))
+    if (!PyArg_ParseTuple(args, "et#:listdir", 
+                          Py_FileSystemDefaultEncoding, &name, &len))
         return NULL;
     if (len >= MAX_PATH) {
 		PyErr_SetString(PyExc_ValueError, "path too long");

Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c	(original)
+++ python/branches/py3k/Objects/unicodeobject.c	Sun Oct 14 04:05:51 2007
@@ -8113,15 +8113,6 @@
 };
 
 
-static int
-unicode_buffer_getbuffer(PyUnicodeObject *self, Py_buffer *view, int flags)
-{
-
-    return PyBuffer_FillInfo(view, (void *)self->str,
-                             PyUnicode_GET_DATA_SIZE(self), 1, flags);
-}
-
-
 /* Helpers for PyUnicode_Format() */
 
 static PyObject *
@@ -8815,11 +8806,6 @@
     return NULL;
 }
 
-static PyBufferProcs unicode_as_buffer = {
-    (getbufferproc) unicode_buffer_getbuffer,
-    NULL,
-};
-
 static PyObject *
 unicode_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
 
@@ -8903,7 +8889,7 @@
     (reprfunc) unicode_str,	 	/* tp_str */
     PyObject_GenericGetAttr, 		/* tp_getattro */
     0,			 		/* tp_setattro */
-    &unicode_as_buffer,			/* tp_as_buffer */
+    0, 					/* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | 
         Py_TPFLAGS_UNICODE_SUBCLASS,	/* tp_flags */
     unicode_doc,			/* tp_doc */

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Sun Oct 14 04:05:51 2007
@@ -1252,7 +1252,7 @@
 				arg, msgbuf, bufsize);
 		if (pb == NULL || pb->bf_getbuffer == NULL)
 			return converterr(
-				"string or read-only character buffer",
+				"bytes or read-only character buffer",
 				arg, msgbuf, bufsize);
 
 		if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0) 


More information about the Python-3000-checkins mailing list