def w_throw(self, w_type=None, w_value=None, w_traceback=None): space = self.space if space.is_w(w_type, space.w_None): w_type = self.costate.w_GreenletExit # Code copied from RAISE_VARARGS but slightly modified. Not too nice. operror = OperationError(w_type, w_value) operror.normalize_exception(space) if not space.is_w(w_traceback, space.w_None): from pypy.interpreter import pytraceback tb = space.interpclass_w(w_traceback) if tb is None or not space.is_true( space.isinstance( tb, space.gettypeobject( pytraceback.PyTraceback.typedef))): raise OperationError( space.w_TypeError, space.wrap("throw: arg 3 must be a traceback or None")) operror.application_traceback = tb # Dead greenlet: turn GreenletExit into a regular return if self.isdead() and operror.match(space, self.costate.w_GreenletExit): args_w = [operror.get_w_value(space)] else: syncstate.push_exception(operror) args_w = None return self.w_switch(args_w)
def throw(self, w_type, w_val, w_tb): from pypy.interpreter.pytraceback import check_traceback space = self.space if w_val is None: w_val = space.w_None msg = "throw() third argument must be a traceback object" if space.is_none(w_tb): tb = None else: tb = check_traceback(space, w_tb, msg) operr = OperationError(w_type, w_val, tb) operr.normalize_exception(space) # note: w_yielded_from is always None if 'self.running' if (self.w_yielded_from is not None and operr.match(space, space.w_GeneratorExit)): try: self._gen_close_iter(space) except OperationError as e: return self.send_error(e) if tb is None: tb = space.getattr(operr.get_w_value(space), space.newtext('__traceback__')) if not space.is_w(tb, space.w_None): operr.set_traceback(tb) return self.send_error(operr)
def PyErr_NormalizeException(space, exc_p, val_p, tb_p): """Under certain circumstances, the values returned by PyErr_Fetch() below can be "unnormalized", meaning that *exc is a class object but *val is not an instance of the same class. This function can be used to instantiate the class in that case. If the values are already normalized, nothing happens. The delayed normalization is implemented to improve performance.""" operr = OperationError(from_ref(space, exc_p[0]), from_ref(space, val_p[0])) operr.normalize_exception(space) Py_DecRef(space, exc_p[0]) Py_DecRef(space, val_p[0]) exc_p[0] = make_ref(space, operr.w_type) val_p[0] = make_ref(space, operr.get_w_value(space))
def throw(self, w_type, w_val, w_tb): from pypy.interpreter.pytraceback import check_traceback space = self.space msg = "throw() third argument must be a traceback object" if space.is_none(w_tb): tb = None else: tb = check_traceback(space, w_tb, msg) operr = OperationError(w_type, w_val, tb) operr.normalize_exception(space) if tb is None: tb = space.getattr(operr.get_w_value(space), space.wrap('__traceback__')) if not space.is_w(tb, space.w_None): operr.set_traceback(tb) return self.send_ex(space.w_None, operr)
def w_throw(self, w_type=None, w_value=None, w_traceback=None): space = self.space if space.is_w(w_type, space.w_None): w_type = self.costate.w_GreenletExit # Code copied from RAISE_VARARGS but slightly modified. Not too nice. operror = OperationError(w_type, w_value) operror.normalize_exception(space) if not space.is_w(w_traceback, space.w_None): from pypy.interpreter import pytraceback tb = space.interpclass_w(w_traceback) if tb is None or not space.is_true(space.isinstance(tb, space.gettypeobject(pytraceback.PyTraceback.typedef))): raise OperationError(space.w_TypeError, space.wrap("throw: arg 3 must be a traceback or None")) operror.set_traceback(tb) # Dead greenlet: turn GreenletExit into a regular return if self.isdead() and operror.match(space, self.costate.w_GreenletExit): args_w = [operror.get_w_value(space)] else: syncstate.push_exception(operror) args_w = None return self.w_switch(args_w)
def PyErr_NormalizeException(space, exc_p, val_p, tb_p): """Under certain circumstances, the values returned by PyErr_Fetch() below can be "unnormalized", meaning that *exc is a class object but *val is not an instance of the same class. This function can be used to instantiate the class in that case. If the values are already normalized, nothing happens. The delayed normalization is implemented to improve performance.""" if exc_p[0]: w_etype = from_ref(space, exc_p[0]) else: # There is no exception, so nothing to do return if val_p[0]: w_evalue = from_ref(space, val_p[0]) else: # On CPython, PyErr_SetNone actually sets val to NULL. # Sensible code should probably never trigger this path on PyPy, but... w_evalue = space.w_None operr = OperationError(w_etype, w_evalue) operr.normalize_exception(space) decref(space, exc_p[0]) decref(space, val_p[0]) exc_p[0] = make_ref(space, operr.w_type) val_p[0] = make_ref(space, operr.get_w_value(space))
def normalize_exc(space, w_type, w_value=None, w_tb=None): operr = OperationError(w_type, w_value, w_tb) operr.normalize_exception(space) return operr.get_w_value(space)