Mercurial > cpython-lru_cache-weakref
diff Python/getargs.c @ 12570:3dbe41380266 legacy-trunk
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.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 03 May 2000 15:17:02 +0000 |
| parents | 13a16793bb1c |
| children | 5648df74395f |
line wrap: on
line diff
--- a/Python/getargs.c Wed May 03 15:11:47 2000 +0000 +++ b/Python/getargs.c Wed May 03 15:17:02 2000 +0000 @@ -777,6 +777,38 @@ 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 **);
