[pypy-svn] pypy default: Added support for Py_UNICODE_COPY and test.
ademan
commits-noreply at bitbucket.org
Fri Feb 18 09:04:08 CET 2011
Author: Daniel Roberts <Ademan555 at gmail.com>
Branch:
Changeset: r42133:fb1b5246077b
Date: 2011-02-18 00:03 -0800
http://bitbucket.org/pypy/pypy/changeset/fb1b5246077b/
Log: Added support for Py_UNICODE_COPY and test.
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -225,3 +225,23 @@
def test_compare(self, space, api):
assert api.PyUnicode_Compare(space.wrap('a'), space.wrap('b')) == -1
+
+ def test_copy(self, space, api):
+ w_x = space.wrap(u"abcd\u0660")
+ target_chunk, _ = rffi.alloc_unicodebuffer(space.int_w(space.len(w_x)))
+ #lltype.malloc(Py_UNICODE, space.int_w(space.len(w_x)), flavor='raw')
+
+ x_chunk = api.PyUnicode_AS_UNICODE(w_x)
+ api.Py_UNICODE_COPY(target_chunk, x_chunk, 4)
+ w_y = api.PyUnicode_FromUnicode(target_chunk, 4)
+
+ assert space.eq_w(w_y, space.wrap(u"abcd"))
+
+ size = api.PyUnicode_GET_SIZE(w_x)
+ api.Py_UNICODE_COPY(target_chunk, x_chunk, size)
+ w_y = api.PyUnicode_FromUnicode(target_chunk, size)
+
+ assert space.eq_w(w_y, w_x)
+
+ lltype.free(target_chunk, flavor='raw')
+
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -1,5 +1,6 @@
from pypy.interpreter.error import OperationError
from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.rpython.lltypesystem import llmemory
from pypy.module.unicodedata import unicodedb
from pypy.module.cpyext.api import (
CANNOT_FAIL, Py_ssize_t, build_type_checkers, cpython_api,
@@ -439,3 +440,10 @@
"""Compare two strings and return -1, 0, 1 for less than, equal, and greater
than, respectively."""
return space.int_w(space.cmp(w_left, w_right))
+
+ at cpython_api([rffi.CWCHARP, rffi.CWCHARP, Py_ssize_t], lltype.Void)
+def Py_UNICODE_COPY(space, target, source, length):
+ """Roughly equivalent to memcpy() only the base size is Py_UNICODE
+ copies sizeof(Py_UNICODE) * length bytes from source to target"""
+ for i in range(0, length):
+ target[i] = source[i]
More information about the Pypy-commit
mailing list