[pypy-svn] r15719 - in pypy/dist/pypy: module/marshal module/marshal/test objspace/std
tismer at codespeak.net
tismer at codespeak.net
Sat Aug 6 12:51:57 CEST 2005
Author: tismer
Date: Sat Aug 6 12:51:55 2005
New Revision: 15719
Modified:
pypy/dist/pypy/module/marshal/interp_marshal.py
pypy/dist/pypy/module/marshal/test/test_marshalimpl.py
pypy/dist/pypy/objspace/std/marshal_impl.py
Log:
enabling marshal:
I stumble dover some quirks. Empty dicts for instance don't work.
Appears like a bug, since we have provisions for empty dicts.
There are some other observations and thoughts which got to pypy-dev.
Modified: pypy/dist/pypy/module/marshal/interp_marshal.py
==============================================================================
--- pypy/dist/pypy/module/marshal/interp_marshal.py (original)
+++ pypy/dist/pypy/module/marshal/interp_marshal.py Sat Aug 6 12:51:55 2005
@@ -144,7 +144,7 @@
space = self.space
raise OperationError(space.w_ValueError, space.wrap(msg))
-DONT_USE_MM_HACK = False
+DONT_USE_MM_HACK = True # im_func is not RPython :-(
class Marshaller(_Base):
# _annspecialcase_ = "specialize:ctr_location" # polymorphic
@@ -160,9 +160,20 @@
* APPLEVEL_STACK_COST + TEST_CONST)
self.cpy_nesting = 0 # contribution to compatibility
self.stringtable = {}
+ # since we currently probably can't reach the stringtable (we can't
+ # find interned strings), try to convince rtyper that this is
+ #really a string dict.
+ s = 'hello'
+ self.stringtable[s] = space.wrap(s)
+ del self.stringtable[s]
self.stackless = False
self._stack = None
- self._iddict = {}
+ #self._iddict = {}
+ # XXX consider adding the dict later when it is needed.
+ # XXX I would also love to use an IntDict for this, if
+ # we had that. Otherwise I'd need to either make strings
+ # from ids (not all that bad) or use a real dict.
+ # How expensive would that be?
## currently we cannot use a put that is a bound method
## from outside. Same holds for get.
@@ -170,7 +181,8 @@
self.writer.write(s)
def atom(self, typecode):
- assert type(typecode) is str and len(typecode) == 1
+ #assert type(typecode) is str and len(typecode) == 1
+ # type(char) not supported
self.put(typecode)
def atom_int(self, typecode, x):
@@ -193,13 +205,16 @@
def atom_strlist(self, typecode, tc2, x):
self.atom_int(typecode, len(x))
+ atom_str = self.atom_str
for item in x:
- if type(item) is not str:
- self.raise_exc('object with wrong type in strlist')
- self.atom_str(tc2, item)
+ # type(str) seems to be forbidden
+ #if type(item) is not str:
+ # self.raise_exc('object with wrong type in strlist')
+ atom_str(tc2, item)
def start(self, typecode):
- assert type(typecode) is str and len(typecode) == 1
+ #assert type(typecode) is str and len(typecode) == 1
+ # type(char) not supported
self.put(typecode)
def put_short(self, x):
@@ -268,18 +283,12 @@
def put_list_w(self, list_w, lng):
if DONT_USE_MM_HACK:
- # inlining makes no sense without the hack
- self.nesting += 1
- self.put_int(lng)
- idx = 0
- while idx < lng:
- self.put_w_obj(list_w[idx])
- idx += 1
- self.nesting -= 1
- return
-
- # inlined version, two stack levels, only!
- self.nesting += 2
+ nest = 4
+ marshal_w = self.space.marshal_w
+ else:
+ nest = 2
+ # inlined version, two stack levels, only, with the hack!
+ self.nesting += nest
self.put_int(lng)
idx = 0
space = self.space
@@ -290,14 +299,17 @@
if do_nested:
while idx < lng:
w_obj = list_w[idx]
- self._get_mm_marshal(w_obj)(space, w_obj, self)
+ if DONT_USE_MM_HACK:
+ marshal_w(w_obj, self)
+ else:
+ self._get_mm_marshal(w_obj)(space, w_obj, self)
idx += 1
else:
while idx < lng:
w_obj = list_w[idx]
self._run_stackless(w_obj)
idx += 1
- self.nesting -= 2
+ self.nesting -= nest
if CPYTHON_COMPATIBLE:
self.cpy_nesting -= 1
@@ -306,7 +318,19 @@
def invalid_typecode(space, u, tc):
- u.raise_exc('invalid typecode in unmarshal: %r' % tc)
+ # %r not supported in rpython
+ #u.raise_exc('invalid typecode in unmarshal: %r' % tc)
+ c = ord(tc)
+ if c < 32 or c > 126:
+ s = '\\x' + hex(c)
+ elif tc == '\\':
+ s = r'\\'
+ else:
+ s = tc
+ q = "'"
+ if s[0] == "'":
+ q = '"'
+ u.raise_exc('invalid typecode in unmarshal: ' + q + s + q)
def register(codes, func):
"""NOT_RPYTHON"""
Modified: pypy/dist/pypy/module/marshal/test/test_marshalimpl.py
==============================================================================
--- pypy/dist/pypy/module/marshal/test/test_marshalimpl.py (original)
+++ pypy/dist/pypy/module/marshal/test/test_marshalimpl.py Sat Aug 6 12:51:55 2005
@@ -10,7 +10,7 @@
for do_hack in (False, True):
interp_marshal.DONT_USE_MM_HACK = not do_hack
if not do_hack:
- interp_cost = 5
+ interp_cost = 4
else:
interp_cost = 2
stacklimit = interp_marshal.nesting_limit - (curdepth + 1) * app_cost - interp_marshal.TEST_CONST
Modified: pypy/dist/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/dist/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/dist/pypy/objspace/std/marshal_impl.py Sat Aug 6 12:51:55 2005
@@ -30,7 +30,7 @@
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
-import longobject
+import longobject, dictobject
from pypy.objspace.std.strutil import string_to_float
from pypy.module.marshal.interp_marshal import register
@@ -344,14 +344,18 @@
m.atom(TYPE_NULL)
def unmarshal_Dict(space, u, tc):
- items_w = []
+ # since primitive lists are not optimized and we don't know
+ # the dict size in advance, use the dict's setitem instead
+ # of building a list of tuples.
+ w_dic = W_DictObject(space, [])
+ setter = dictobject.setitem__Dict_ANY_ANY
while 1:
w_key = u.get_w_obj(True)
if w_key is None:
break
w_value = u.get_w_obj(False)
- items_w.append( (w_key, w_value) )
- return W_DictObject(space, items_w)
+ setter(space, w_dic, w_key, w_value)
+ return w_dic
register(TYPE_DICT, unmarshal_Dict)
def unmarshal_NULL(self, u, tc):
More information about the Pypy-commit
mailing list