[pypy-svn] r17463 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Sun Sep 11 17:43:09 CEST 2005
Author: arigo
Date: Sun Sep 11 17:43:08 2005
New Revision: 17463
Modified:
pypy/dist/pypy/rpython/rdict.py
pypy/dist/pypy/rpython/rpbc.py
pypy/dist/pypy/rpython/test/test_rclass.py
Log:
Reverted the change of rpbc.py in r17455, which broke start_new_thread()
in translator/c/test/test_extfunc.py. Worked around the problem
differently.
Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py (original)
+++ pypy/dist/pypy/rpython/rdict.py Sun Sep 11 17:43:08 2005
@@ -121,10 +121,17 @@
return self.dict_cache[key]
except KeyError:
self.setup()
+ l_dict = ll_newdict(self)
+ self.dict_cache[key] = l_dict
+ r_key = self.key_repr
+ r_value = self.value_repr
if isinstance(dictobj, objectmodel.r_dict):
- l_eqfn = self.r_rdict_eqfn .convert_const(dictobj.key_eq)
- l_hashfn = self.r_rdict_hashfn.convert_const(dictobj.key_hash)
- l_dict = ll_newdict_custom_eq_hash(l_eqfn, l_hashfn, self)
+ if self.r_rdict_eqfn.lowleveltype != lltype.Void:
+ l_fn = self.r_rdict_eqfn.convert_const(dictobj.key_eq)
+ l_dict.fnkeyeq = l_fn
+ if self.r_rdict_hashfn.lowleveltype != lltype.Void:
+ l_fn = self.r_rdict_hashfn.convert_const(dictobj.key_hash)
+ l_dict.fnkeyhash = l_fn
# a dummy object with ll_keyeq and ll_keyhash methods to
# pass to ll_dict_setitem()
class Dummy:
@@ -145,9 +152,6 @@
dummy = Dummy()
dummy.cache = []
- self.dict_cache[key] = l_dict
- r_key = self.key_repr
- r_value = self.value_repr
for dictkeycontainer, dictvalue in dictobj._dict.items():
llkey = r_key.convert_const(dictkeycontainer.key)
llvalue = r_value.convert_const(dictvalue)
@@ -156,10 +160,6 @@
return l_dict
else:
- l_dict = ll_newdict(self)
- self.dict_cache[key] = l_dict
- r_key = self.key_repr
- r_value = self.value_repr
for dictkey, dictvalue in dictobj.items():
llkey = r_key.convert_const(dictkey)
llvalue = r_value.convert_const(dictvalue)
@@ -409,23 +409,12 @@
DICT_INITSIZE = 8
def ll_newdict(dictrepr):
- assert not dictrepr.custom_eq_hash # use ll_newdict_custom_eq_hash() instead
d = lltype.malloc(dictrepr.DICT)
d.entries = lltype.malloc(dictrepr.DICTENTRYARRAY, DICT_INITSIZE)
d.num_items = 0 # but still be explicit
d.num_pristine_entries = DICT_INITSIZE
return d
-def ll_newdict_custom_eq_hash(eqfn, hashfn, dictrepr):
- assert dictrepr.custom_eq_hash
- d = lltype.malloc(dictrepr.DICT)
- d.entries = lltype.malloc(dictrepr.DICTENTRYARRAY, DICT_INITSIZE)
- d.num_items = 0 # but still be explicit
- d.num_pristine_entries = DICT_INITSIZE
- d.fnkeyeq = eqfn
- d.fnkeyhash = hashfn
- return d
-
def ll_copy_extra_data(targetdict, sourcedict, dictrepr):
if dictrepr.custom_eq_hash:
targetdict.fnkeyeq = sourcedict.fnkeyeq
@@ -449,8 +438,13 @@
r_dict.r_rdict_hashfn)
crepr = hop.inputconst(lltype.Void, r_dict)
hop.exception_cannot_occur()
- v_result = hop.gendirectcall(ll_newdict_custom_eq_hash,
- v_eqfn, v_hashfn, crepr)
+ v_result = hop.gendirectcall(ll_newdict, crepr)
+ if r_dict.r_rdict_eqfn.lowleveltype != lltype.Void:
+ cname = hop.inputconst(Void, 'fnkeyeq')
+ hop.genop('setfield', [v_result, cname, v_eqfn])
+ if r_dict.r_rdict_hashfn.lowleveltype != lltype.Void:
+ cname = hop.inputconst(Void, 'fnkeyhash')
+ hop.genop('setfield', [v_result, cname, v_hashfn])
return v_result
# ____________________________________________________________
Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py (original)
+++ pypy/dist/pypy/rpython/rpbc.py Sun Sep 11 17:43:08 2005
@@ -402,11 +402,8 @@
if value not in self.function_signatures():
raise TyperError("%r not in %r" % (value,
self.s_pbc.prebuiltinstances))
- if self.lowleveltype == Void:
- return None
- else:
- f, rinputs, rresult = self.function_signatures()[value]
- return f
+ f, rinputs, rresult = self.function_signatures()[value]
+ return f
def rtype_simple_call(self, hop):
f, rinputs, rresult = self.function_signatures().itervalues().next()
Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py (original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py Sun Sep 11 17:43:08 2005
@@ -321,3 +321,13 @@
assert res is False
res = interpret(f, [0])
assert res is False
+
+def test_void_fnptr():
+ def g():
+ return 42
+ def f():
+ e = EmptyBase()
+ e.attr = g
+ return e.attr()
+ res = interpret(f, [])
+ assert res == 42
More information about the Pypy-commit
mailing list