예제 #1
0
 def test_unicode_resize(self, space, api):
     py_uni = new_empty_unicode(space, 10)
     ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
     py_uni.c_buffer[0] = u'a'
     py_uni.c_buffer[1] = u'b'
     py_uni.c_buffer[2] = u'c'
     ar[0] = rffi.cast(PyObject, py_uni)
     api.PyUnicode_Resize(ar, 3)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert py_uni.c_size == 3
     assert py_uni.c_buffer[1] == u'b'
     assert py_uni.c_buffer[3] == u'\x00'
     # the same for growing
     ar[0] = rffi.cast(PyObject, py_uni)
     api.PyUnicode_Resize(ar, 10)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert py_uni.c_size == 10
     assert py_uni.c_buffer[1] == 'b'
     assert py_uni.c_buffer[10] == '\x00'
     Py_DecRef(space, ar[0])
     lltype.free(ar, flavor='raw')
예제 #2
0
 def test_unicode_resize(self, space, api):
     py_uni = new_empty_unicode(space, 10)
     ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
     py_uni.c_buffer[0] = u'a'
     py_uni.c_buffer[1] = u'b'
     py_uni.c_buffer[2] = u'c'
     ar[0] = rffi.cast(PyObject, py_uni)
     api.PyUnicode_Resize(ar, 3)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert py_uni.c_size == 3
     assert py_uni.c_buffer[1] == u'b'
     assert py_uni.c_buffer[3] == u'\x00'
     # the same for growing
     ar[0] = rffi.cast(PyObject, py_uni)
     api.PyUnicode_Resize(ar, 10)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert py_uni.c_size == 10
     assert py_uni.c_buffer[1] == 'b'
     assert py_uni.c_buffer[10] == '\x00'
     Py_DecRef(space, ar[0])
     lltype.free(ar, flavor='raw')
예제 #3
0
 def test_unicode_resize(self, space, api):
     py_uni = new_empty_unicode(space, 10)
     ar = lltype.malloc(PyObjectP.TO, 1, flavor="raw")
     py_uni.c_buffer[0] = u"a"
     py_uni.c_buffer[1] = u"b"
     py_uni.c_buffer[2] = u"c"
     ar[0] = rffi.cast(PyObject, py_uni)
     api.PyUnicode_Resize(ar, 3)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert py_uni.c_size == 3
     assert py_uni.c_buffer[1] == u"b"
     assert py_uni.c_buffer[3] == u"\x00"
     # the same for growing
     ar[0] = rffi.cast(PyObject, py_uni)
     api.PyUnicode_Resize(ar, 10)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert py_uni.c_size == 10
     assert py_uni.c_buffer[1] == "b"
     assert py_uni.c_buffer[10] == "\x00"
     Py_DecRef(space, ar[0])
     lltype.free(ar, flavor="raw")
예제 #4
0
 def test_unicode_resize(self, space):
     py_uni = new_empty_unicode(space, 10)
     ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
     buf = get_wbuffer(py_uni)
     buf[0] = u'a'
     buf[1] = u'b'
     buf[2] = u'c'
     ar[0] = rffi.cast(PyObject, py_uni)
     PyUnicode_Resize(space, ar, 3)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert get_wsize(py_uni) == 3
     assert get_wbuffer(py_uni)[1] == u'b'
     assert get_wbuffer(py_uni)[3] == u'\x00'
     # the same for growing
     ar[0] = rffi.cast(PyObject, py_uni)
     PyUnicode_Resize(space, ar, 10)
     py_uni = rffi.cast(PyUnicodeObject, ar[0])
     assert get_wsize(py_uni) == 10
     assert get_wbuffer(py_uni)[1] == 'b'
     assert get_wbuffer(py_uni)[10] == '\x00'
     decref(space, ar[0])
     lltype.free(ar, flavor='raw')
예제 #5
0
 def as_py_uni(val):
     py_obj = new_empty_unicode(space, len(val))
     w_obj = space.wrap(val)
     # calls _PyUnicode_Ready
     unicode_attach(space, py_obj, w_obj)
     return py_obj
 def as_py_uni(val):
     py_obj = new_empty_unicode(space, len(val))
     set_wbuffer(py_obj, rffi.unicode2wcharp(val))
     return py_obj