[pypy-svn] r73450 - in pypy/branch/cpython-extension/pypy/module/cpyext: include test
afa at codespeak.net
afa at codespeak.net
Tue Apr 6 13:20:47 CEST 2010
Author: afa
Date: Tue Apr 6 13:20:46 2010
New Revision: 73450
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
pypy/branch/cpython-extension/pypy/module/cpyext/include/unicodeobject.h
pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py
Log:
Support platforms (guess which) where sizeof(wchar_t)==2.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/Python.h Tue Apr 6 13:20:46 2010
@@ -14,6 +14,14 @@
#define HAVE_UNICODE
#define WITHOUT_COMPLEX
+/* PyPy supposes Py_UNICODE == wchar_t */
+#define HAVE_USABLE_WCHAR_T 1
+#ifndef _WIN32
+#define Py_UNICODE_SIZE 4
+#else
+#define Py_UNICODE_SIZE 2
+#endif
+
/* Compat stuff */
#ifndef _WIN32
# include <inttypes.h>
@@ -23,6 +31,7 @@
# define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
# define PyAPI_DATA(RTYPE) extern RTYPE
#else
+# define MS_WIN32 1
# include <crtdefs.h>
# define Py_DEPRECATED(VERSION_UNUSED)
# ifdef Py_BUILD_CORE
@@ -31,6 +40,7 @@
# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
# endif
#endif
+
#define Py_ssize_t long
#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/unicodeobject.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/unicodeobject.h (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/unicodeobject.h Tue Apr 6 13:20:46 2010
@@ -13,10 +13,14 @@
} PyUnicodeObject;
-//XXX
-typedef unsigned int Py_UCS4;
-// pypy only supports only UCS4
+typedef unsigned int Py_UCS4;
+#ifdef HAVE_USABLE_WCHAR_T
+#define PY_UNICODE_TYPE wchar_t
+#elif Py_UNICODE_SIZE == 4
#define PY_UNICODE_TYPE Py_UCS4
+#else
+#define PY_UNICODE_TYPE unsigned short
+#endif
typedef PY_UNICODE_TYPE Py_UNICODE;
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py Tue Apr 6 13:20:46 2010
@@ -1,13 +1,13 @@
# encoding: iso-8859-15
from pypy.module.cpyext.test.test_api import BaseApiTest
from pypy.module.cpyext.unicodeobject import Py_UNICODE
-from pypy.rpython.lltypesystem import rffi
+from pypy.rpython.lltypesystem import rffi, lltype
class TestUnicode(BaseApiTest):
def test_unicodeobject(self, space, api):
assert api.PyUnicode_GET_SIZE(space.wrap(u'späm')) == 4
- # XXX assuming UCS-4
- assert api.PyUnicode_GET_DATA_SIZE(space.wrap(u'späm')) == 16
+ unichar = rffi.sizeof(lltype.UniChar)
+ assert api.PyUnicode_GET_DATA_SIZE(space.wrap(u'späm')) == 4 * unichar
def test_AS_DATA(self, space, api):
word = space.wrap(u'spam')
More information about the Pypy-commit
mailing list