summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-04-28 14:42:37 (GMT)
committerFred Drake <fdrake@acm.org>2000-04-28 14:42:37 (GMT)
commit25d34473c3c2429f0bf5c27e147fe57c6a718e99 (patch)
treefade54950fa8e087869d217f0a4f7c4349dbb33c /Python
parent6664bb87dc821e777184c8ea88539a2fdde49501 (diff)
downloadcpython-25d34473c3c2429f0bf5c27e147fe57c6a718e99.zip
cpython-25d34473c3c2429f0bf5c27e147fe57c6a718e99.tar.gz
cpython-25d34473c3c2429f0bf5c27e147fe57c6a718e99.tar.bz2
Brian Hooper <brian_takashi@hotmail.com>:
Here's a patch which changes modsupport to add 'u' and 'u#', to support building Unicode objects from a null-terminated Py_UNICODE *, and a Py_UNICODE * with length, respectively. [Conversion from 'U' to 'u' by Fred, based on python-dev comments.] Note that the use of None for NULL values of the Py_UNICODE* value is still in; I'm not sure of the conclusion on that issue.
Diffstat (limited to 'Python')
-rw-r--r--Python/modsupport.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/Python/modsupport.c b/Python/modsupport.c
index f86ca91..7b40286 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -232,6 +232,15 @@ do_mklist(p_format, p_va, endchar, n)
return v;
}
+static int
+_ustrlen(Py_UNICODE *u)
+{
+ int i = 0;
+ Py_UNICODE *v = u;
+ while (*v != 0) { i++; v++; }
+ return i;
+}
+
static PyObject *
do_mktuple(p_format, p_va, endchar, n)
char **p_format;
@@ -295,7 +304,28 @@ do_mkvalue(p_format, p_va)
case 'L':
return PyLong_FromLongLong((LONG_LONG)va_arg(*p_va, LONG_LONG));
#endif
-
+ case 'u':
+ {
+ PyObject *v;
+ Py_UNICODE *u = va_arg(*p_va, Py_UNICODE *);
+ int n;
+ if (**p_format == '#') {
+ ++*p_format;
+ n = va_arg(*p_va, int);
+ }
+ else
+ n = -1;
+ if (u == NULL) {
+ v = Py_None;
+ Py_INCREF(v);
+ }
+ else {
+ if (n < 0)
+ n = _ustrlen(u);
+ v = PyUnicode_FromUnicode(u, n);
+ }
+ return v;
+ }
case 'f':
case 'd':
return PyFloat_FromDouble(