summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-05-03 15:17:02 (GMT)
committerFred Drake <fdrake@acm.org>2000-05-03 15:17:02 (GMT)
commit25871c001f55941fec83e7ce9832e5f45c69a8cf (patch)
tree82d9108087ec195c76712a9e1fa87de0223c7970 /Python
parentae08853fb0c77067baa2b8bdc28f4e74df4f9f68 (diff)
downloadcpython-25871c001f55941fec83e7ce9832e5f45c69a8cf.zip
cpython-25871c001f55941fec83e7ce9832e5f45c69a8cf.tar.gz
cpython-25871c001f55941fec83e7ce9832e5f45c69a8cf.tar.bz2
Brian Hooper <brian_takashi@hotmail.com>:
Added 'u' and 'u#' tags for PyArg_ParseTuple - these turn a PyUnicodeObject argument into a Py_UNICODE * buffer, or a Py_UNICODE * buffer plus a length with the '#'. Also added an analog to 'U' for Py_BuildValue.
Diffstat (limited to 'Python')
-rw-r--r--Python/getargs.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 1e88a88..0579aff 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -777,6 +777,38 @@ convertsimple1(arg, p_format, p_va)
break;
}
+ case 'u': /* raw unicode buffer (Py_UNICODE *) */
+ {
+ if (*format == '#') { /* any buffer-like object */
+ void **p = (void **)va_arg(*p_va, char **);
+ PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
+ int *q = va_arg(*p_va, int *);
+ int count;
+
+ if ( pb == NULL ||
+ pb->bf_getreadbuffer == NULL ||
+ pb->bf_getsegcount == NULL )
+ return "read-only buffer";
+ if ( (*pb->bf_getsegcount)(arg, NULL) != 1 )
+ return "single-segment read-only buffer";
+ if ( (count =
+ (*pb->bf_getreadbuffer)(arg, 0, p)) < 0 )
+ return "(unspecified)";
+ /* buffer interface returns bytes, we want
+ length in characters */
+ *q = count/(sizeof(Py_UNICODE));
+ format++;
+ } else {
+ Py_UNICODE **p = va_arg(*p_va, Py_UNICODE **);
+
+ if (PyUnicode_Check(arg))
+ *p = PyUnicode_AS_UNICODE(arg);
+ else
+ return "unicode";
+ }
+ break;
+ }
+
case 'S': /* string object */
{
PyObject **p = va_arg(*p_va, PyObject **);