\item[\samp{u\#} (Unicode object) {[Py_UNICODE *, int]}]
This variant on \samp{u} stores into two C variables, the first one
a pointer to a Unicode data buffer, the second one its length.
+Non-Unicode objects are handled by interpreting their read buffer
+pointer as pointer to a Py_UNICODE array.
\item[\samp{es} (string, Unicode object or character buffer compatible
object) {[const char *encoding, char **buffer]}]
#endif /* ifdef HAVE_LONG_LONG */
+#ifdef Py_USING_UNICODE
+
+/* Test the u and u# codes for PyArg_ParseTuple. May leak memory in case
+ of an error.
+*/
+static PyObject *
+test_u_code(PyObject *self, PyObject *args)
+{
+ PyObject *tuple, *obj;
+ Py_UNICODE *value;
+ int len;
+
+ if (!PyArg_ParseTuple(args, ":test_u_code"))
+ return NULL;
+
+ tuple = PyTuple_New(1);
+ if (tuple == NULL)
+ return NULL;
+
+ obj = PyUnicode_Decode("test", strlen("test"),
+ "ascii", NULL);
+ if (obj == NULL)
+ return NULL;
+
+ PyTuple_SET_ITEM(tuple, 0, obj);
+
+ value = 0;
+ if (PyArg_ParseTuple(tuple, "u:test_u_code", &value) < 0)
+ return NULL;
+ if (value != PyUnicode_AS_UNICODE(obj))
+ return raiseTestError("test_u_code",
+ "u code returned wrong value for u'test'");
+ value = 0;
+ if (PyArg_ParseTuple(tuple, "u#:test_u_code", &value, &len) < 0)
+ return NULL;
+ if (value != PyUnicode_AS_UNICODE(obj) ||
+ len != PyUnicode_GET_SIZE(obj))
+ return raiseTestError("test_u_code",
+ "u# code returned wrong values for u'test'");
+
+ Py_DECREF(tuple);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+#endif
+
static PyObject *
raise_exception(PyObject *self, PyObject *args)
{
#ifdef HAVE_LONG_LONG
{"test_longlong_api", test_longlong_api, METH_VARARGS},
{"test_L_code", test_L_code, METH_VARARGS},
+#endif
+#ifdef Py_USING_UNICODE
+ {"test_u_code", test_u_code, METH_VARARGS},
#endif
{NULL, NULL} /* sentinel */
};
if (*format == '#') { /* any buffer-like object */
void **p = (void **)va_arg(*p_va, char **);
int *q = va_arg(*p_va, int *);
+ if (PyUnicode_Check(arg)) {
+ *p = PyUnicode_AS_UNICODE(arg);
+ *q = PyUnicode_GET_SIZE(arg);
+ }
+ else {
char *buf;
int count = convertbuffer(arg, p, &buf);
-
if (count < 0)
return converterr(buf, arg, msgbuf, bufsize);
*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