Esempio n. 1
0
 def test_string_buffer(self, space):
     py_str = new_empty_str(space, 10)
     c_buf = py_str.c_ob_type.c_tp_as_buffer
     assert c_buf
     py_obj = rffi.cast(PyObject, py_str)
     size = rffi.sizeof(Py_buffer)
     ref = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw', zero=True)
     ref = rffi.cast(Py_bufferP, ref)
     assert generic_cpy_call(space, c_buf.c_bf_getbuffer,
                         py_obj, ref, rffi.cast(rffi.INT_real, 0)) == 0
     lltype.free(ref, flavor='raw')
     decref(space, py_obj)
Esempio n. 2
0
 def test_string_buffer(self, space, api):
     py_str = new_empty_str(space, 10)
     c_buf = py_str.c_ob_type.c_tp_as_buffer
     assert c_buf
     py_obj = rffi.cast(PyObject, py_str)
     assert c_buf.c_bf_getsegcount(py_obj, lltype.nullptr(Py_ssize_tP.TO)) == 1
     ref = lltype.malloc(Py_ssize_tP.TO, 1, flavor='raw')
     assert c_buf.c_bf_getsegcount(py_obj, ref) == 1
     assert ref[0] == 10
     lltype.free(ref, flavor='raw')
     ref = lltype.malloc(rffi.VOIDPP.TO, 1, flavor='raw')
     assert c_buf.c_bf_getreadbuffer(py_obj, 0, ref) == 10
     lltype.free(ref, flavor='raw')
     Py_DecRef(space, py_obj)
Esempio n. 3
0
 def test_string_buffer(self, space, api):
     py_str = new_empty_str(space, 10)
     c_buf = py_str.c_ob_type.c_tp_as_buffer
     assert c_buf
     py_obj = rffi.cast(PyObject, py_str)
     assert c_buf.c_bf_getsegcount(py_obj,
                                   lltype.nullptr(Py_ssize_tP.TO)) == 1
     ref = lltype.malloc(Py_ssize_tP.TO, 1, flavor='raw')
     assert c_buf.c_bf_getsegcount(py_obj, ref) == 1
     assert ref[0] == 10
     lltype.free(ref, flavor='raw')
     ref = lltype.malloc(rffi.VOIDPP.TO, 1, flavor='raw')
     assert c_buf.c_bf_getreadbuffer(py_obj, 0, ref) == 10
     lltype.free(ref, flavor='raw')
     Py_DecRef(space, py_obj)
Esempio n. 4
0
 def test_string_resize(self, space, api):
     py_str = new_empty_str(space, 10)
     ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
     py_str.c_buffer[0] = 'a'
     py_str.c_buffer[1] = 'b'
     py_str.c_buffer[2] = 'c'
     ar[0] = rffi.cast(PyObject, py_str)
     api._PyString_Resize(ar, 3)
     py_str = rffi.cast(PyStringObject, ar[0])
     assert py_str.c_size == 3
     assert py_str.c_buffer[1] == 'b'
     assert py_str.c_buffer[3] == '\x00'
     # the same for growing
     ar[0] = rffi.cast(PyObject, py_str)
     api._PyString_Resize(ar, 10)
     py_str = rffi.cast(PyStringObject, ar[0])
     assert py_str.c_size == 10
     assert py_str.c_buffer[1] == 'b'
     assert py_str.c_buffer[10] == '\x00'
     Py_DecRef(space, ar[0])
     lltype.free(ar, flavor='raw')
Esempio n. 5
0
 def test_bytes_resize(self, space):
     py_str = new_empty_str(space, 10)
     ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw')
     py_str.c_ob_sval[0] = 'a'
     py_str.c_ob_sval[1] = 'b'
     py_str.c_ob_sval[2] = 'c'
     ar[0] = rffi.cast(PyObject, py_str)
     _PyString_Resize(space, ar, 3)
     py_str = rffi.cast(PyBytesObject, ar[0])
     assert py_str.c_ob_size == 3
     assert py_str.c_ob_sval[1] == 'b'
     assert py_str.c_ob_sval[3] == '\x00'
     # the same for growing
     ar[0] = rffi.cast(PyObject, py_str)
     _PyString_Resize(space, ar, 10)
     py_str = rffi.cast(PyBytesObject, ar[0])
     assert py_str.c_ob_size == 10
     assert py_str.c_ob_sval[1] == 'b'
     assert py_str.c_ob_sval[10] == '\x00'
     decref(space, ar[0])
     lltype.free(ar, flavor='raw')