[pypy-svn] r75527 - in pypy/trunk/pypy/translator/c: src test
arigo at codespeak.net
arigo at codespeak.net
Wed Jun 23 15:31:47 CEST 2010
Author: arigo
Date: Wed Jun 23 15:31:45 2010
New Revision: 75527
Modified:
pypy/trunk/pypy/translator/c/src/support.h
pypy/trunk/pypy/translator/c/test/test_typed.py
Log:
Test and fix on platforms where CPython's unichar size differs from a
wchar_t. This is also a fix for test_nonmoving_unicode in
pypy.rpython.lltypesystem.test.test_rffi.
Modified: pypy/trunk/pypy/translator/c/src/support.h
==============================================================================
--- pypy/trunk/pypy/translator/c/src/support.h (original)
+++ pypy/trunk/pypy/translator/c/src/support.h Wed Jun 23 15:31:45 2010
@@ -26,7 +26,7 @@
PyString_FromStringAndSize(_RPyString_AsString(rpystr), RPyString_Size(rpystr))
#define PyUnicode_FromRPyUnicode(rpystr) \
- PyUnicode_FromUnicode(_RPyUnicode_AsUnicode(rpystr), RPyUnicode_Size(rpystr))
+ _PyUnicode_FromRPyUnicode(_RPyUnicode_AsUnicode(rpystr), RPyUnicode_Size(rpystr))
#define PyString_ToRPyString(s, rpystr) \
memcpy(_RPyString_AsString(rpystr), PyString_AS_STRING(s), \
@@ -128,6 +128,7 @@
PyObject *PyTuple_GetItem_WithIncref(PyObject *tuple, int index);
int PyTuple_SetItem_WithIncref(PyObject *tuple, int index, PyObject *o);
int PySequence_Contains_with_exc(PyObject *seq, PyObject *ob);
+PyObject* _PyUnicode_FromRPyUnicode(wchar_t *items, long length);
/* implementations */
@@ -501,6 +502,17 @@
return ret;
}
+PyObject* _PyUnicode_FromRPyUnicode(wchar_t *items, long length)
+{
+ PyObject *u = PyUnicode_FromUnicode(NULL, length);
+ long i;
+ for (i=0; i<length; i++) {
+ /* xxx possibly silently truncate the unichars */
+ PyUnicode_AS_UNICODE(u)[i] = items[i];
+ }
+ return u;
+}
+
#endif /* PYPY_STANDALONE */
#endif /* PYPY_NOT_MAIN_FILE */
Modified: pypy/trunk/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/trunk/pypy/translator/c/test/test_typed.py (original)
+++ pypy/trunk/pypy/translator/c/test/test_typed.py Wed Jun 23 15:31:45 2010
@@ -783,3 +783,9 @@
del a[:]
f = self.getcompiled(func_swap, [])
+
+ def test_returns_unicode(self):
+ def func(i):
+ return u'hello' + unichr(i)
+ f = self.getcompiled(func, [int])
+ assert f(0x1234) == u'hello\u1234'
More information about the Pypy-commit
mailing list