Author: Lars Wassermann <[email protected]>
Branch:
Changeset: r127:d0d2369575cf
Date: 2013-03-06 21:14 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/d0d2369575cf/
Log: (cfbolz, lwassermann): Added type-checks in several places to pacify
pypy. In most cases, the program will abort, if the wrong types are
supplied. The stack can now only contain model.W_Object-instances.
Generic shadows can now only exists for model.W_PointersObject.
diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -260,6 +260,10 @@
elif isinstance(w_v, model.W_SmallInteger): return float(w_v.value)
raise UnwrappingError()
+ def unwrap_pointersobject(self, w_v):
+ if not isinstance(w_v, model.W_PointersObject):
+ raise UnwrappingError()
+ return w_v
def unwrap_array(self, w_array):
# Check that our argument has pointers format and the class:
if not w_array.getclass(self).is_same_object(self.w_Array):
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -93,6 +93,7 @@
elif spec is float:
args += (interp.space.unwrap_float(w_arg), )
elif spec is object:
+ assert isinstance(w_arg, model.W_Object)
args += (w_arg, )
elif spec is str:
assert isinstance(w_arg, model.W_BytesObject)
@@ -963,7 +964,9 @@
interp.space.w_Process):
raise PrimitiveFailedError()
s_frame.push(w_rcvr) # w_rcvr is the result in the old frame
- return wrapper.ProcessWrapper(interp.space,
w_rcvr).resume(s_frame.w_self()).as_context_get_shadow(interp.space)
+ w_frame = wrapper.ProcessWrapper(interp.space,
w_rcvr).resume(s_frame.w_self())
+ w_frame = interp.space.unwrap_pointersobject(w_frame)
+ return w_frame.as_context_get_shadow(interp.space)
@expose_primitive(SUSPEND, unwrap_spec=[object])
def func(interp, s_frame, w_rcvr, result_is_new_frame=True):
@@ -972,7 +975,9 @@
interp.space.w_Process):
raise PrimitiveFailedError()
s_frame.push(w_rcvr) # w_rcvr is the result in the old frame
- return wrapper.ProcessWrapper(interp.space,
w_rcvr).suspend(s_frame.w_self()).as_context_get_shadow(interp.space)
+ w_frame = wrapper.ProcessWrapper(interp.space,
w_rcvr).suspend(s_frame.w_self())
+ w_frame = interp.space.unwrap_pointersobject(w_frame)
+ return w_frame.as_context_get_shadow(interp.space)
@expose_primitive(FLUSH_CACHE, unwrap_spec=[object])
def func(interp, s_frame, w_rcvr):
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -798,8 +798,10 @@
def returnTopFromMethod(self, interp, current_bytecode):
if self.is_closure_context():
# this is a context for a blockClosure
- s_outerContext = self.w_closure_or_nil.fetch(self.space,
- constants.BLKCLSR_OUTER_CONTEXT).get_shadow(self.space)
+ w_outerContext = self.w_closure_or_nil.fetch(self.space,
+ constants.BLKCLSR_OUTER_CONTEXT)
+ assert isinstance(w_outerContext, model.W_PointersObject)
+ s_outerContext = w_outerContext.as_context_get_shadow(self.space)
# XXX check whether we can actually return from that context
if s_outerContext.pc() == -1:
raise error.BlockCannotReturnError()
diff --git a/spyvm/wrapper.py b/spyvm/wrapper.py
--- a/spyvm/wrapper.py
+++ b/spyvm/wrapper.py
@@ -226,7 +226,10 @@
def asContextWithSender(self, w_aContext, arguments):
from spyvm import shadow
- s_outerContext = self.outerContext().get_shadow(self.space)
+ w_outerContext = self.outerContext()
+ if not isinstance(w_outerContext, model.W_PointersObject):
+ raise PrimitiveFailedError
+ s_outerContext = w_outerContext.as_context_get_shadow(self.space)
s_method =
s_outerContext.w_method().as_compiledmethod_get_shadow(self.space)
w_receiver = s_outerContext.w_receiver()
w_new_frame = shadow.MethodContextShadow.make_context(self.space,
s_method, w_receiver,
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit