Author: Matti Picus <[email protected]>
Branch: rw-PyString_AS_STRING
Changeset: r85174:737eb2235db4
Date: 2016-06-15 01:06 +0300
http://bitbucket.org/pypy/pypy/changeset/737eb2235db4/
Log: use length in new_str, fix typos in test
diff --git a/pypy/module/cpyext/bytesobject.py
b/pypy/module/cpyext/bytesobject.py
--- a/pypy/module/cpyext/bytesobject.py
+++ b/pypy/module/cpyext/bytesobject.py
@@ -79,11 +79,9 @@
called. Refcount of the result is 1.
"""
typedescr = get_typedescr(space.w_str.layout.typedef)
- py_obj = typedescr.allocate(space, space.w_str)
+ py_obj = typedescr.allocate(space, space.w_str, length)
py_str = rffi.cast(PyStringObject, py_obj)
-
- buflen = length + 1
- py_str.c_ob_size = length
+ py_str.c_ob_shash = -1
py_str.c_ob_sstate = rffi.cast(rffi.INT, 0) # SSTATE_NOT_INTERNED
return py_str
@@ -223,7 +221,6 @@
# XXX always create a new string so far
py_str = rffi.cast(PyStringObject, ref[0])
if pyobj_has_w_obj(py_str):
- import pdb;pdb.set_trace()
raise oefmt(space.w_SystemError,
"_PyString_Resize called on already created string")
try:
diff --git a/pypy/module/cpyext/test/test_bytesobject.py
b/pypy/module/cpyext/test/test_bytesobject.py
--- a/pypy/module/cpyext/test/test_bytesobject.py
+++ b/pypy/module/cpyext/test/test_bytesobject.py
@@ -445,22 +445,22 @@
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_sval[0] = 'a'
- py_str.c_sval[1] = 'b'
- py_str.c_sval[2] = 'c'
+ 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)
api._PyString_Resize(ar, 3)
py_str = rffi.cast(PyStringObject, ar[0])
assert py_str.c_ob_size == 3
- assert py_str.c_sval[1] == 'b'
- assert py_str.c_sval[3] == '\x00'
+ 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)
api._PyString_Resize(ar, 10)
py_str = rffi.cast(PyStringObject, ar[0])
assert py_str.c_ob_size == 10
- assert py_str.c_sval[1] == 'b'
- assert py_str.c_sval[10] == '\x00'
+ assert py_str.c_ob_sval[1] == 'b'
+ assert py_str.c_ob_sval[10] == '\x00'
Py_DecRef(space, ar[0])
lltype.free(ar, flavor='raw')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit