[pypy-svn] r31814 - in pypy/branch/no-zeroing-assumption-3/pypy: rpython rpython/lltypesystem rpython/lltypesystem/module rpython/module rpython/test translator/c
mwh at codespeak.net
mwh at codespeak.net
Wed Aug 30 00:37:16 CEST 2006
Author: mwh
Date: Wed Aug 30 00:37:12 2006
New Revision: 31814
Modified:
pypy/branch/no-zeroing-assumption-3/pypy/rpython/annlowlevel.py
pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py
pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/module/ll_os.py
pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py
pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py
pypy/branch/no-zeroing-assumption-3/pypy/rpython/module/support.py
pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py
pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py
pypy/branch/no-zeroing-assumption-3/pypy/translator/c/extfunc.py
Log:
define a mallocstr() helper that zeros the hash when needed and use it all over
the place.
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/annlowlevel.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/annlowlevel.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/annlowlevel.py Wed Aug 30 00:37:12 2006
@@ -100,6 +100,13 @@
funcdesc2 = bk.getdesc(x)
return pol.default_specialize(funcdesc2, args_s)
+ def specialize__semierased(funcdesc, args_s):
+ a2l = annmodel.annotation_to_lltype
+ l2a = annmodel.lltype_to_annotation
+ args_s[:] = [l2a(a2l(s)) for s in args_s]
+ return LowLevelAnnotatorPolicy.default_specialize(funcdesc, args_s)
+ specialize__semierased = staticmethod(specialize__semierased)
+
specialize__ll = default_specialize
def annotate_lowlevel_helper(annotator, ll_function, args_s, policy=None):
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/ll_str.py Wed Aug 30 00:37:12 2006
@@ -7,7 +7,7 @@
return ll_int2dec(i)
def ll_int2dec(i):
- from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.lltypesystem.rstr import mallocstr
temp = malloc(CHAR_ARRAY, 20)
len = 0
sign = 0
@@ -25,7 +25,7 @@
i //= 10
len += 1
len += sign
- result = malloc(STR, len)
+ result = mallocstr(len)
result.hash = 0
if sign:
result.chars[0] = '-'
@@ -43,7 +43,7 @@
hex_chars[i] = "%x"%i
def ll_int2hex(i, addPrefix):
- from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.lltypesystem.rstr import mallocstr
temp = malloc(CHAR_ARRAY, 20)
len = 0
sign = 0
@@ -61,7 +61,7 @@
len += sign
if addPrefix:
len += 2
- result = malloc(STR, len)
+ result = mallocstr(len)
result.hash = 0
j = 0
if sign:
@@ -77,9 +77,9 @@
return result
def ll_int2oct(i, addPrefix):
- from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.lltypesystem.rstr import mallocstr
if i == 0:
- result = malloc(STR, 1)
+ result = mallocstr(1)
result.hash = 0
result.chars[0] = '0'
return result
@@ -96,7 +96,7 @@
len += sign
if addPrefix:
len += 1
- result = malloc(STR, len)
+ result = mallocstr(len)
result.hash = 0
j = 0
if sign:
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/module/ll_os.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/module/ll_os.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/module/ll_os.py Wed Aug 30 00:37:12 2006
@@ -35,27 +35,27 @@
ll_pipe_result = staticmethod(ll_pipe_result)
def ll_os_read(cls, fd, count):
- from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.lltypesystem.rstr import mallocstr
if count < 0:
raise OSError(errno.EINVAL, None)
- buffer = lltype.malloc(STR, count)
+ buffer = mallocstr(count)
n = cls.ll_read_into(fd, buffer)
if n != count:
- s = lltype.malloc(STR, n)
+ s = mallocstr(n)
ll_strcpy(s, buffer, n)
buffer = s
return buffer
def ll_os_readlink(cls, path):
- from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.lltypesystem.rstr import mallocstr
bufsize = 1023
while 1:
- buffer = lltype.malloc(STR, bufsize)
+ buffer = mallocstr(bufsize)
n = cls.ll_readlink_into(cls, path, buffer)
if n < bufsize:
break
bufsize *= 4 # overflow, try again with a bigger buffer
- s = lltype.malloc(STR, n)
+ s = mallocstr(n)
ll_strcpy(s, buffer, n)
return s
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rclass.py Wed Aug 30 00:37:12 2006
@@ -571,8 +571,7 @@
instance = cast_pointer(OBJECTPTR, i)
from pypy.rpython.lltypesystem import rstr
nameLen = len(instance.typeptr.name)
- nameString = malloc(rstr.STR, nameLen-1)
- nameString.hash = 0
+ nameString = rstr.mallocstr(nameLen-1)
i = 0
while i < nameLen - 1:
nameString.chars[i] = instance.typeptr.name[i]
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/lltypesystem/rstr.py Wed Aug 30 00:37:12 2006
@@ -1,7 +1,7 @@
from weakref import WeakValueDictionary
from pypy.annotation.pairtype import pairtype
from pypy.rpython.error import TyperError
-from pypy.rpython.objectmodel import malloc_zero_filled
+from pypy.rpython.objectmodel import malloc_zero_filled, we_are_translated
from pypy.rpython.robject import PyObjRepr, pyobj_repr
from pypy.rpython.rarithmetic import _hash_string
from pypy.rpython.rmodel import inputconst, IntegerRepr
@@ -46,7 +46,7 @@
try:
return CONST_STR_CACHE[value]
except KeyError:
- p = malloc(STR, len(value))
+ p = mallocstr(len(value))
for i in range(len(value)):
p.chars[i] = value[i]
p.hash = 0
@@ -111,9 +111,10 @@
def mallocstr(length):
r = malloc(STR, length)
- if not malloc_zero_filled:
+ if not we_are_translated() or not malloc_zero_filled:
r.hash = 0
return r
+mallocstr._annspecialcase_ = 'specialize:semierased'
# ____________________________________________________________
#
@@ -125,8 +126,7 @@
class LLHelpers(AbstractLLHelpers):
def ll_char_mul(ch, times):
- newstr = malloc(STR, times)
- newstr.hash = 0
+ newstr = mallocstr(times)
j = 0
while j < times:
newstr.chars[j] = ch
@@ -140,8 +140,7 @@
return s.chars[i]
def ll_chr2str(ch):
- s = malloc(STR, 1)
- s.hash = 0
+ s = mallocstr(1)
s.chars[0] = ch
return s
@@ -161,8 +160,7 @@
def ll_strconcat(s1, s2):
len1 = len(s1.chars)
len2 = len(s2.chars)
- newstr = malloc(STR, len1 + len2)
- newstr.hash = 0
+ newstr = mallocstr(len1 + len2)
j = 0
while j < len1:
newstr.chars[j] = s1.chars[j]
@@ -187,8 +185,7 @@
while lpos < rpos and s.chars[rpos] == ch:
rpos -= 1
r_len = rpos - lpos + 1
- result = malloc(STR, r_len)
- result.hash = 0
+ result = mallocstr(r_len)
i = 0
j = lpos
while i < r_len:
@@ -203,8 +200,7 @@
if s_len == 0:
return emptystr
i = 0
- result = malloc(STR, s_len)
- result.hash = 0
+ result = mallocstr(s_len)
while i < s_len:
ch = s_chars[i]
if 'a' <= ch <= 'z':
@@ -219,8 +215,7 @@
if s_len == 0:
return emptystr
i = 0
- result = malloc(STR, s_len)
- result.hash = 0
+ result = mallocstr(s_len)
while i < s_len:
ch = s_chars[i]
if 'A' <= ch <= 'Z':
@@ -240,8 +235,7 @@
while i < num_items:
itemslen += len(items[i].chars)
i += 1
- result = malloc(STR, itemslen + s_len * (num_items - 1))
- result.hash = 0
+ result = mallocstr(itemslen + s_len * (num_items - 1))
res_chars = result.chars
res_index = 0
i = 0
@@ -461,8 +455,7 @@
while i < num_items:
itemslen += len(items[i].chars)
i += 1
- result = malloc(STR, itemslen)
- result.hash = 0
+ result = mallocstr(itemslen)
res_chars = result.chars
res_index = 0
i = 0
@@ -479,8 +472,7 @@
def ll_join_chars(length, chars):
num_chars = length
- result = malloc(STR, num_chars)
- result.hash = 0
+ result = mallocstr(num_chars)
res_chars = result.chars
i = 0
while i < num_chars:
@@ -490,8 +482,7 @@
def ll_stringslice_startonly(s1, start):
len1 = len(s1.chars)
- newstr = malloc(STR, len1 - start)
- newstr.hash = 0
+ newstr = mallocstr(len1 - start)
j = 0
while start < len1:
newstr.chars[j] = s1.chars[start]
@@ -506,8 +497,7 @@
if start == 0:
return s1
stop = len(s1.chars)
- newstr = malloc(STR, stop - start)
- newstr.hash = 0
+ newstr = mallocstr(stop - start)
j = 0
while start < stop:
newstr.chars[j] = s1.chars[start]
@@ -518,8 +508,7 @@
def ll_stringslice_minusone(s1):
newlen = len(s1.chars) - 1
assert newlen >= 0
- newstr = malloc(STR, newlen)
- newstr.hash = 0
+ newstr = mallocstr(newlen)
j = 0
while j < newlen:
newstr.chars[j] = s1.chars[j]
@@ -542,8 +531,7 @@
resindex = 0
while j < strlen:
if chars[j] == c:
- item = items[resindex] = malloc(STR, j - i)
- item.hash = 0
+ item = items[resindex] = mallocstr(j - i)
newchars = item.chars
k = i
while k < j:
@@ -552,8 +540,7 @@
resindex += 1
i = j + 1
j += 1
- item = items[resindex] = malloc(STR, j - i)
- item.hash = 0
+ item = items[resindex] = mallocstr(j - i)
newchars = item.chars
k = i
while k < j:
@@ -565,8 +552,7 @@
def ll_replace_chr_chr(s, c1, c2):
length = len(s.chars)
- newstr = malloc(STR, length)
- newstr.hash = 0
+ newstr = mallocstr(length)
src = s.chars
dst = newstr.chars
j = 0
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/module/support.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/module/support.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/module/support.py Wed Aug 30 00:37:12 2006
@@ -10,10 +10,10 @@
_mixin_ = True
def to_rstr(s):
- from pypy.rpython.lltypesystem.rstr import STR
+ from pypy.rpython.lltypesystem.rstr import STR, mallocstr
if s is None:
return lltype.nullptr(STR)
- p = malloc(STR, len(s))
+ p = mallocstr(len(s))
for i in range(len(s)):
p.chars[i] = s[i]
return p
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rdict.py Wed Aug 30 00:37:12 2006
@@ -510,10 +510,9 @@
def test_deleted_entry_reusage_with_colliding_hashes(self):
def lowlevelhash(value):
- p = lltype.malloc(rstr.STR, len(value))
+ p = rstr.mallocstr(len(value))
for i in range(len(value)):
p.chars[i] = value[i]
- p.hash = 0
return rstr.LLHelpers.ll_strhash(p)
def func(c1, c2):
Modified: pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/rpython/test/test_rstr.py Wed Aug 30 00:37:12 2006
@@ -1,7 +1,7 @@
import random
from pypy.rpython.lltypesystem.lltype import *
from pypy.rpython.rstr import AbstractLLHelpers
-from pypy.rpython.lltypesystem.rstr import LLHelpers, STR
+from pypy.rpython.lltypesystem.rstr import LLHelpers, mallocstr
from pypy.rpython.rtyper import RPythonTyper, TyperError
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rpython.llinterp import LLException
@@ -597,10 +597,9 @@
EMPTY_STRING_HASH = -1
def llstr(self, s):
- p = malloc(STR, len(s))
+ p = mallocstr(len(s))
for i in range(len(s)):
p.chars[i] = s[i]
- p.hash = 0
return p
def test_ll_find_rfind(self):
Modified: pypy/branch/no-zeroing-assumption-3/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/branch/no-zeroing-assumption-3/pypy/translator/c/extfunc.py (original)
+++ pypy/branch/no-zeroing-assumption-3/pypy/translator/c/extfunc.py Wed Aug 30 00:37:12 2006
@@ -2,7 +2,7 @@
from pypy.objspace.flow.model import FunctionGraph
from pypy.rpython.lltypesystem import lltype
from pypy.translator.c.support import cdecl
-from pypy.rpython.lltypesystem.rstr import STR
+from pypy.rpython.lltypesystem.rstr import STR, mallocstr
from pypy.rpython.lltypesystem import rstr
from pypy.rpython.lltypesystem import rlist
from pypy.rpython.module import ll_time, ll_math, ll_strtod
@@ -121,7 +121,7 @@
def predeclare_utility_functions(db, rtyper):
# Common utility functions
def RPyString_New(length=lltype.Signed):
- return lltype.malloc(STR, length)
+ return mallocstr(length)
# !!!
# be extremely careful passing a gc tracked object
More information about the Pypy-commit
mailing list