Author: Matti Picus <[email protected]>
Branch: rw-PyString_AS_STRING
Changeset: r85172:098123589947
Date: 2016-06-15 00:48 +0300
http://bitbucket.org/pypy/pypy/changeset/098123589947/
Log: rework c_ob_size, it is len(w_str) but the size of c_ob_sval is
c_ob_size
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
@@ -94,10 +94,10 @@
"""
py_str = rffi.cast(PyStringObject, py_obj)
s = space.str_w(w_obj)
- if py_str.c_ob_size <= len(s):
+ if py_str.c_ob_size < len(s):
raise oefmt(space.w_ValueError,
"string_attach called on object with ob_size %d but trying to
store %d",
- py_str.c_ob_size, len(s) + 1)
+ py_str.c_ob_size, len(s))
rffi.c_memcpy(py_str.c_ob_sval, rffi.str2charp(s), len(s))
py_str.c_ob_sval[len(s)] = '\0'
py_str.c_ob_shash = space.hash_w(w_obj)
@@ -116,7 +116,6 @@
py_str.c_ob_shash = space.hash_w(w_obj)
py_str.c_ob_sstate = rffi.cast(rffi.INT, 1) # SSTATE_INTERNED_MORTAL
track_reference(space, py_obj, w_obj)
- print 'string_realize',s,py_str.c_ob_size
return w_obj
@cpython_api([PyObject], lltype.Void, header=None)
@@ -204,7 +203,7 @@
def PyString_Size(space, ref):
if from_ref(space, rffi.cast(PyObject, ref.c_ob_type)) is space.w_str:
ref = rffi.cast(PyStringObject, ref)
- return ref.c_ob_size - 1
+ return ref.c_ob_size
else:
w_obj = from_ref(space, ref)
return space.len_w(w_obj)
@@ -224,6 +223,7 @@
# 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/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -47,14 +47,14 @@
size = pytype.c_tp_basicsize
else:
size = rffi.sizeof(self.basestruct)
- if itemcount:
+ if pytype.c_tp_itemsize:
size += itemcount * pytype.c_tp_itemsize
assert size >= rffi.sizeof(PyObject.TO)
buf = lltype.malloc(rffi.VOIDP.TO, size,
flavor='raw', zero=True,
add_memory_pressure=True)
pyobj = rffi.cast(PyObject, buf)
- if itemcount:
+ if pytype.c_tp_itemsize:
pyvarobj = rffi.cast(PyVarObject, pyobj)
pyvarobj.c_ob_size = itemcount
pyobj.c_ob_refcnt = 1
@@ -164,7 +164,7 @@
pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type))
typedescr = get_typedescr(w_obj.typedef)
if pytype.c_tp_itemsize != 0:
- itemcount = space.len_w(w_obj) + 1 # PyStringObject and subclasses
+ itemcount = space.len_w(w_obj) # PyStringObject and subclasses
else:
itemcount = 0
py_obj = typedescr.allocate(space, w_type, itemcount=itemcount)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit