Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct-2
Changeset: r91305:f23167f0f132
Date: 2017-05-15 19:02 +0200
http://bitbucket.org/pypy/pypy/changeset/f23167f0f132/
Log: bah, the base_ofs needs to be proven constant at translation time.
Try to help the rtyper
diff --git a/pypy/objspace/std/bytearrayobject.py
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -8,7 +8,8 @@
from rpython.rlib.rgc import (resizable_list_supporting_raw_ptr,
nonmoving_raw_ptr_for_resizable_list)
from rpython.rlib import jit
-from rpython.rlib.buffer import GCBuffer, get_gc_data_for_list_of_chars
+from rpython.rlib.buffer import (GCBuffer, get_gc_data_for_list_of_chars,
+ get_gc_data_offset_for_list_of_chars)
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.gateway import WrappedDefault, interp2app, unwrap_spec
@@ -1304,6 +1305,9 @@
def _get_gc_data(self):
return get_gc_data_for_list_of_chars(self.ba._data)
+ def _get_gc_data_offset(self):
+ return get_gc_data_offset_for_list_of_chars()
+
@specialize.argtype(1)
def _memcmp(selfvalue, buffer, length):
diff --git a/rpython/rlib/buffer.py b/rpython/rlib/buffer.py
--- a/rpython/rlib/buffer.py
+++ b/rpython/rlib/buffer.py
@@ -4,6 +4,7 @@
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rtyper.lltypesystem.rstr import STR
+from rpython.rtyper.lltypesystem.rlist import LIST_OF
from rpython.rtyper.annlowlevel import llstr
from rpython.rlib.objectmodel import specialize
from rpython.rlib import jit
@@ -131,14 +132,17 @@
typed_read and typed_write in terms of llop.gc_load_indexed and
llop.gc_store_indexed.
- Subclasses MUST override the _get_gc_data method.
+ Subclasses MUST override the _get_gc_* methods.
"""
_immutable_ = True
_attrs_ = ['readonly']
def _get_gc_data(self):
+ raise NotImplementedError
+
+ def _get_gc_data_offset(self):
"""
- Return a tuple (data, base_offset), whose items can be used with
+ Return the offset to use with _get_gc_data() for calling
llop.gc_{load,store}_indexed.
"""
raise NotImplementedError
@@ -148,7 +152,8 @@
"""
Read the value of type TP starting at byte_offset. No bounds checks
"""
- lldata, base_ofs = self._get_gc_data()
+ lldata = self._get_gc_data()
+ base_ofs = self._get_gc_data_offset()
scale_factor = llmemory.sizeof(lltype.Char)
return llop.gc_load_indexed(TP, lldata, byte_offset,
scale_factor, base_ofs)
@@ -160,7 +165,8 @@
"""
if self.readonly:
raise CannotWrite
- lldata, base_ofs = self._get_gc_data()
+ lldata = self._get_gc_data()
+ base_ofs = self._get_gc_data_offset()
scale_factor = llmemory.sizeof(lltype.Char)
value = lltype.cast_primitive(TP, value)
return llop.gc_store_indexed(lltype.Void, lldata, byte_offset, value,
@@ -170,10 +176,11 @@
def get_gc_data_for_list_of_chars(data):
ll_data = ll_for_resizable_list(data)
ll_items = ll_data.items
- LIST = lltype.typeOf(ll_data).TO # rlist.LIST_OF(lltype.Char)
- base_ofs = llmemory.itemoffsetof(LIST.items.TO, 0)
- ll_items = lltype.cast_opaque_ptr(llmemory.GCREF, ll_items)
- return ll_items, base_ofs
+ return lltype.cast_opaque_ptr(llmemory.GCREF, ll_items)
+
+def get_gc_data_offset_for_list_of_chars():
+ LIST = LIST_OF(lltype.Char)
+ return llmemory.itemoffsetof(LIST.items.TO, 0)
class ByteBuffer(GCBuffer):
@@ -198,6 +205,9 @@
def _get_gc_data(self):
return get_gc_data_for_list_of_chars(self.data)
+ def _get_gc_data_offset(self):
+ return get_gc_data_offset_for_list_of_chars()
+
class StringBuffer(GCBuffer):
_attrs_ = ['readonly', 'value']
@@ -232,12 +242,13 @@
# may still raise ValueError on some GCs
return rffi.get_raw_address_of_string(self.value)
+ def _get_gc_data_offset(self):
+ return (llmemory.offsetof(STR, 'chars') +
+ llmemory.itemoffsetof(STR.chars, 0))
+
def _get_gc_data(self):
lls = llstr(self.value)
- lls = lltype.cast_opaque_ptr(llmemory.GCREF, lls)
- base_ofs = (llmemory.offsetof(STR, 'chars') +
- llmemory.itemoffsetof(STR.chars, 0))
- return lls, base_ofs
+ return lltype.cast_opaque_ptr(llmemory.GCREF, lls)
class SubBuffer(Buffer):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit