mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
GH-99005: Add CALL_INTRINSIC_1
instruction (GH-100771)
* Remove PRINT_EXPR instruction * Remove STOPITERATION_ERROR instruction * Remove IMPORT_STAR instruction
This commit is contained in:
parent
f20c553a45
commit
28187141cc
19 changed files with 336 additions and 361 deletions
|
@ -12,6 +12,7 @@
|
|||
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
|
||||
#include "pycore_code.h"
|
||||
#include "pycore_function.h"
|
||||
#include "pycore_intrinsics.h"
|
||||
#include "pycore_long.h" // _PyLong_GetZero()
|
||||
#include "pycore_object.h" // _PyObject_GC_TRACK()
|
||||
#include "pycore_moduleobject.h" // PyModuleObject
|
||||
|
@ -538,20 +539,11 @@ dummy_func(
|
|||
ERROR_IF(err, error);
|
||||
}
|
||||
|
||||
inst(PRINT_EXPR, (value --)) {
|
||||
PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(displayhook));
|
||||
PyObject *res;
|
||||
// Can't use ERROR_IF here.
|
||||
if (hook == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_RuntimeError,
|
||||
"lost sys.displayhook");
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(true, error);
|
||||
}
|
||||
res = PyObject_CallOneArg(hook, value);
|
||||
DECREF_INPUTS();
|
||||
inst(CALL_INTRINSIC_1, (value -- res)) {
|
||||
assert(oparg <= MAX_INTRINSIC_1);
|
||||
res = _PyIntrinsics_UnaryFunctions[oparg](tstate, value);
|
||||
Py_DECREF(value);
|
||||
ERROR_IF(res == NULL, error);
|
||||
Py_DECREF(res);
|
||||
}
|
||||
|
||||
// stack effect: (__array[oparg] -- )
|
||||
|
@ -867,47 +859,6 @@ dummy_func(
|
|||
}
|
||||
}
|
||||
|
||||
inst(STOPITERATION_ERROR) {
|
||||
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
|
||||
PyObject *exc = TOP();
|
||||
assert(PyExceptionInstance_Check(exc));
|
||||
const char *msg = NULL;
|
||||
if (PyErr_GivenExceptionMatches(exc, PyExc_StopIteration)) {
|
||||
msg = "generator raised StopIteration";
|
||||
if (frame->f_code->co_flags & CO_ASYNC_GENERATOR) {
|
||||
msg = "async generator raised StopIteration";
|
||||
}
|
||||
else if (frame->f_code->co_flags & CO_COROUTINE) {
|
||||
msg = "coroutine raised StopIteration";
|
||||
}
|
||||
}
|
||||
else if ((frame->f_code->co_flags & CO_ASYNC_GENERATOR) &&
|
||||
PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration))
|
||||
{
|
||||
/* code in `gen` raised a StopAsyncIteration error:
|
||||
raise a RuntimeError.
|
||||
*/
|
||||
msg = "async generator raised StopAsyncIteration";
|
||||
}
|
||||
if (msg != NULL) {
|
||||
PyObject *message = _PyUnicode_FromASCII(msg, strlen(msg));
|
||||
if (message == NULL) {
|
||||
goto error;
|
||||
}
|
||||
PyObject *error = PyObject_CallOneArg(PyExc_RuntimeError, message);
|
||||
if (error == NULL) {
|
||||
Py_DECREF(message);
|
||||
goto error;
|
||||
}
|
||||
assert(PyExceptionInstance_Check(error));
|
||||
SET_TOP(error);
|
||||
PyException_SetCause(error, Py_NewRef(exc));
|
||||
// Steal exc reference, rather than Py_NewRef+Py_DECREF
|
||||
PyException_SetContext(error, exc);
|
||||
Py_DECREF(message);
|
||||
}
|
||||
}
|
||||
|
||||
inst(LOAD_ASSERTION_ERROR, ( -- value)) {
|
||||
value = Py_NewRef(PyExc_AssertionError);
|
||||
}
|
||||
|
@ -2065,27 +2016,6 @@ dummy_func(
|
|||
ERROR_IF(res == NULL, error);
|
||||
}
|
||||
|
||||
inst(IMPORT_STAR, (from --)) {
|
||||
PyObject *locals;
|
||||
int err;
|
||||
if (_PyFrame_FastToLocalsWithError(frame) < 0) {
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(true, error);
|
||||
}
|
||||
|
||||
locals = LOCALS();
|
||||
if (locals == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_SystemError,
|
||||
"no locals found during 'import *'");
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(true, error);
|
||||
}
|
||||
err = import_all_from(tstate, locals, from);
|
||||
_PyFrame_LocalsToFast(frame, 0);
|
||||
DECREF_INPUTS();
|
||||
ERROR_IF(err, error);
|
||||
}
|
||||
|
||||
inst(IMPORT_FROM, (from -- from, res)) {
|
||||
PyObject *name = GETITEM(names, oparg);
|
||||
res = import_from(tstate, from, name);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "pycore_ceval.h" // _PyEval_SignalAsyncExc()
|
||||
#include "pycore_code.h"
|
||||
#include "pycore_function.h"
|
||||
#include "pycore_intrinsics.h"
|
||||
#include "pycore_long.h" // _PyLong_GetZero()
|
||||
#include "pycore_object.h" // _PyObject_GC_TRACK()
|
||||
#include "pycore_moduleobject.h" // PyModuleObject
|
||||
|
@ -204,7 +205,6 @@ static void dtrace_function_return(_PyInterpreterFrame *);
|
|||
static PyObject * import_name(PyThreadState *, _PyInterpreterFrame *,
|
||||
PyObject *, PyObject *, PyObject *);
|
||||
static PyObject * import_from(PyThreadState *, PyObject *, PyObject *);
|
||||
static int import_all_from(PyThreadState *, PyObject *, PyObject *);
|
||||
static void format_exc_check_arg(PyThreadState *, PyObject *, const char *, PyObject *);
|
||||
static void format_exc_unbound(PyThreadState *tstate, PyCodeObject *co, int oparg);
|
||||
static int check_args_iterable(PyThreadState *, PyObject *func, PyObject *vararg);
|
||||
|
@ -3156,95 +3156,6 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
|
||||
{
|
||||
PyObject *all, *dict, *name, *value;
|
||||
int skip_leading_underscores = 0;
|
||||
int pos, err;
|
||||
|
||||
if (_PyObject_LookupAttr(v, &_Py_ID(__all__), &all) < 0) {
|
||||
return -1; /* Unexpected error */
|
||||
}
|
||||
if (all == NULL) {
|
||||
if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &dict) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (dict == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_ImportError,
|
||||
"from-import-* object has no __dict__ and no __all__");
|
||||
return -1;
|
||||
}
|
||||
all = PyMapping_Keys(dict);
|
||||
Py_DECREF(dict);
|
||||
if (all == NULL)
|
||||
return -1;
|
||||
skip_leading_underscores = 1;
|
||||
}
|
||||
|
||||
for (pos = 0, err = 0; ; pos++) {
|
||||
name = PySequence_GetItem(all, pos);
|
||||
if (name == NULL) {
|
||||
if (!_PyErr_ExceptionMatches(tstate, PyExc_IndexError)) {
|
||||
err = -1;
|
||||
}
|
||||
else {
|
||||
_PyErr_Clear(tstate);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!PyUnicode_Check(name)) {
|
||||
PyObject *modname = PyObject_GetAttr(v, &_Py_ID(__name__));
|
||||
if (modname == NULL) {
|
||||
Py_DECREF(name);
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
if (!PyUnicode_Check(modname)) {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"module __name__ must be a string, not %.100s",
|
||||
Py_TYPE(modname)->tp_name);
|
||||
}
|
||||
else {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"%s in %U.%s must be str, not %.100s",
|
||||
skip_leading_underscores ? "Key" : "Item",
|
||||
modname,
|
||||
skip_leading_underscores ? "__dict__" : "__all__",
|
||||
Py_TYPE(name)->tp_name);
|
||||
}
|
||||
Py_DECREF(modname);
|
||||
Py_DECREF(name);
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
if (skip_leading_underscores) {
|
||||
if (PyUnicode_READY(name) == -1) {
|
||||
Py_DECREF(name);
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
if (PyUnicode_READ_CHAR(name, 0) == '_') {
|
||||
Py_DECREF(name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
value = PyObject_GetAttr(v, name);
|
||||
if (value == NULL)
|
||||
err = -1;
|
||||
else if (PyDict_CheckExact(locals))
|
||||
err = PyDict_SetItem(locals, name, value);
|
||||
else
|
||||
err = PyObject_SetItem(locals, name, value);
|
||||
Py_DECREF(name);
|
||||
Py_XDECREF(value);
|
||||
if (err != 0)
|
||||
break;
|
||||
}
|
||||
Py_DECREF(all);
|
||||
return err;
|
||||
}
|
||||
|
||||
#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\
|
||||
"BaseException is not allowed"
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "pycore_ast.h" // _PyAST_GetDocString()
|
||||
#include "pycore_code.h" // _PyCode_New()
|
||||
#include "pycore_compile.h" // _PyFuture_FromAST()
|
||||
#include "pycore_intrinsics.h"
|
||||
#include "pycore_long.h" // _PyLong_GetZero()
|
||||
#include "pycore_opcode.h" // _PyOpcode_Caches
|
||||
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
|
||||
|
@ -1113,15 +1114,11 @@ stack_effect(int opcode, int oparg, int jump)
|
|||
case GET_ITER:
|
||||
return 0;
|
||||
|
||||
case PRINT_EXPR:
|
||||
return -1;
|
||||
case LOAD_BUILD_CLASS:
|
||||
return 1;
|
||||
|
||||
case RETURN_VALUE:
|
||||
return -1;
|
||||
case IMPORT_STAR:
|
||||
return -1;
|
||||
case SETUP_ANNOTATIONS:
|
||||
return 0;
|
||||
case ASYNC_GEN_WRAP:
|
||||
|
@ -1216,10 +1213,6 @@ stack_effect(int opcode, int oparg, int jump)
|
|||
* of __(a)enter__ and push 2 values before jumping to the handler
|
||||
* if an exception be raised. */
|
||||
return jump ? 1 : 0;
|
||||
|
||||
case STOPITERATION_ERROR:
|
||||
return 0;
|
||||
|
||||
case PREP_RERAISE_STAR:
|
||||
return -1;
|
||||
case RERAISE:
|
||||
|
@ -1249,7 +1242,8 @@ stack_effect(int opcode, int oparg, int jump)
|
|||
return 0;
|
||||
case CALL:
|
||||
return -1-oparg;
|
||||
|
||||
case CALL_INTRINSIC_1:
|
||||
return 0;
|
||||
case CALL_FUNCTION_EX:
|
||||
return -2 - ((oparg & 0x01) != 0);
|
||||
case MAKE_FUNCTION:
|
||||
|
@ -2604,7 +2598,7 @@ wrap_in_stopiteration_handler(struct compiler *c)
|
|||
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
|
||||
ADDOP(c, NO_LOCATION, RETURN_VALUE);
|
||||
USE_LABEL(c, handler);
|
||||
ADDOP(c, NO_LOCATION, STOPITERATION_ERROR);
|
||||
ADDOP_I(c, NO_LOCATION, CALL_INTRINSIC_1, INTRINSIC_STOPITERATION_ERROR);
|
||||
ADDOP_I(c, NO_LOCATION, RERAISE, 1);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -3953,7 +3947,8 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
|||
|
||||
if (i == 0 && PyUnicode_READ_CHAR(alias->name, 0) == '*') {
|
||||
assert(n == 1);
|
||||
ADDOP(c, LOC(s), IMPORT_STAR);
|
||||
ADDOP_I(c, LOC(s), CALL_INTRINSIC_1, INTRINSIC_IMPORT_STAR);
|
||||
ADDOP(c, NO_LOCATION, POP_TOP);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -4005,7 +4000,8 @@ compiler_stmt_expr(struct compiler *c, location loc, expr_ty value)
|
|||
{
|
||||
if (c->c_interactive && c->c_nestlevel <= 1) {
|
||||
VISIT(c, expr, value);
|
||||
ADDOP(c, loc, PRINT_EXPR);
|
||||
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_PRINT);
|
||||
ADDOP(c, NO_LOCATION, POP_TOP);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
|
82
Python/generated_cases.c.h
generated
82
Python/generated_cases.c.h
generated
|
@ -684,22 +684,14 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(PRINT_EXPR) {
|
||||
TARGET(CALL_INTRINSIC_1) {
|
||||
PyObject *value = PEEK(1);
|
||||
PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(displayhook));
|
||||
PyObject *res;
|
||||
// Can't use ERROR_IF here.
|
||||
if (hook == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_RuntimeError,
|
||||
"lost sys.displayhook");
|
||||
Py_DECREF(value);
|
||||
if (true) goto pop_1_error;
|
||||
}
|
||||
res = PyObject_CallOneArg(hook, value);
|
||||
assert(oparg <= MAX_INTRINSIC_1);
|
||||
res = _PyIntrinsics_UnaryFunctions[oparg](tstate, value);
|
||||
Py_DECREF(value);
|
||||
if (res == NULL) goto pop_1_error;
|
||||
Py_DECREF(res);
|
||||
STACK_SHRINK(1);
|
||||
POKE(1, res);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
@ -1045,48 +1037,6 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(STOPITERATION_ERROR) {
|
||||
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
|
||||
PyObject *exc = TOP();
|
||||
assert(PyExceptionInstance_Check(exc));
|
||||
const char *msg = NULL;
|
||||
if (PyErr_GivenExceptionMatches(exc, PyExc_StopIteration)) {
|
||||
msg = "generator raised StopIteration";
|
||||
if (frame->f_code->co_flags & CO_ASYNC_GENERATOR) {
|
||||
msg = "async generator raised StopIteration";
|
||||
}
|
||||
else if (frame->f_code->co_flags & CO_COROUTINE) {
|
||||
msg = "coroutine raised StopIteration";
|
||||
}
|
||||
}
|
||||
else if ((frame->f_code->co_flags & CO_ASYNC_GENERATOR) &&
|
||||
PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration))
|
||||
{
|
||||
/* code in `gen` raised a StopAsyncIteration error:
|
||||
raise a RuntimeError.
|
||||
*/
|
||||
msg = "async generator raised StopAsyncIteration";
|
||||
}
|
||||
if (msg != NULL) {
|
||||
PyObject *message = _PyUnicode_FromASCII(msg, strlen(msg));
|
||||
if (message == NULL) {
|
||||
goto error;
|
||||
}
|
||||
PyObject *error = PyObject_CallOneArg(PyExc_RuntimeError, message);
|
||||
if (error == NULL) {
|
||||
Py_DECREF(message);
|
||||
goto error;
|
||||
}
|
||||
assert(PyExceptionInstance_Check(error));
|
||||
SET_TOP(error);
|
||||
PyException_SetCause(error, Py_NewRef(exc));
|
||||
// Steal exc reference, rather than Py_NewRef+Py_DECREF
|
||||
PyException_SetContext(error, exc);
|
||||
Py_DECREF(message);
|
||||
}
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(LOAD_ASSERTION_ERROR) {
|
||||
PyObject *value;
|
||||
value = Py_NewRef(PyExc_AssertionError);
|
||||
|
@ -2401,30 +2351,6 @@
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(IMPORT_STAR) {
|
||||
PyObject *from = PEEK(1);
|
||||
PyObject *locals;
|
||||
int err;
|
||||
if (_PyFrame_FastToLocalsWithError(frame) < 0) {
|
||||
Py_DECREF(from);
|
||||
if (true) goto pop_1_error;
|
||||
}
|
||||
|
||||
locals = LOCALS();
|
||||
if (locals == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_SystemError,
|
||||
"no locals found during 'import *'");
|
||||
Py_DECREF(from);
|
||||
if (true) goto pop_1_error;
|
||||
}
|
||||
err = import_all_from(tstate, locals, from);
|
||||
_PyFrame_LocalsToFast(frame, 0);
|
||||
Py_DECREF(from);
|
||||
if (err) goto pop_1_error;
|
||||
STACK_SHRINK(1);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
TARGET(IMPORT_FROM) {
|
||||
PyObject *from = PEEK(1);
|
||||
PyObject *res;
|
||||
|
|
194
Python/intrinsics.c
Normal file
194
Python/intrinsics.c
Normal file
|
@ -0,0 +1,194 @@
|
|||
|
||||
#define _PY_INTERPRETER
|
||||
|
||||
#include "Python.h"
|
||||
#include "pycore_frame.h"
|
||||
#include "pycore_runtime.h"
|
||||
#include "pycore_global_objects.h"
|
||||
#include "pycore_intrinsics.h"
|
||||
#include "pycore_pyerrors.h"
|
||||
|
||||
|
||||
|
||||
static PyObject *
|
||||
no_intrinsic(PyThreadState* tstate, PyObject *unused)
|
||||
{
|
||||
_PyErr_SetString(tstate, PyExc_SystemError, "invalid intrinsic function");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
print_expr(PyThreadState* tstate, PyObject *value)
|
||||
{
|
||||
PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(displayhook));
|
||||
// Can't use ERROR_IF here.
|
||||
if (hook == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_RuntimeError,
|
||||
"lost sys.displayhook");
|
||||
return NULL;
|
||||
}
|
||||
return PyObject_CallOneArg(hook, value);
|
||||
}
|
||||
|
||||
static int
|
||||
import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
|
||||
{
|
||||
PyObject *all, *dict, *name, *value;
|
||||
int skip_leading_underscores = 0;
|
||||
int pos, err;
|
||||
|
||||
if (_PyObject_LookupAttr(v, &_Py_ID(__all__), &all) < 0) {
|
||||
return -1; /* Unexpected error */
|
||||
}
|
||||
if (all == NULL) {
|
||||
if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &dict) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (dict == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_ImportError,
|
||||
"from-import-* object has no __dict__ and no __all__");
|
||||
return -1;
|
||||
}
|
||||
all = PyMapping_Keys(dict);
|
||||
Py_DECREF(dict);
|
||||
if (all == NULL)
|
||||
return -1;
|
||||
skip_leading_underscores = 1;
|
||||
}
|
||||
|
||||
for (pos = 0, err = 0; ; pos++) {
|
||||
name = PySequence_GetItem(all, pos);
|
||||
if (name == NULL) {
|
||||
if (!_PyErr_ExceptionMatches(tstate, PyExc_IndexError)) {
|
||||
err = -1;
|
||||
}
|
||||
else {
|
||||
_PyErr_Clear(tstate);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!PyUnicode_Check(name)) {
|
||||
PyObject *modname = PyObject_GetAttr(v, &_Py_ID(__name__));
|
||||
if (modname == NULL) {
|
||||
Py_DECREF(name);
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
if (!PyUnicode_Check(modname)) {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"module __name__ must be a string, not %.100s",
|
||||
Py_TYPE(modname)->tp_name);
|
||||
}
|
||||
else {
|
||||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"%s in %U.%s must be str, not %.100s",
|
||||
skip_leading_underscores ? "Key" : "Item",
|
||||
modname,
|
||||
skip_leading_underscores ? "__dict__" : "__all__",
|
||||
Py_TYPE(name)->tp_name);
|
||||
}
|
||||
Py_DECREF(modname);
|
||||
Py_DECREF(name);
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
if (skip_leading_underscores) {
|
||||
if (PyUnicode_READY(name) == -1) {
|
||||
Py_DECREF(name);
|
||||
err = -1;
|
||||
break;
|
||||
}
|
||||
if (PyUnicode_READ_CHAR(name, 0) == '_') {
|
||||
Py_DECREF(name);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
value = PyObject_GetAttr(v, name);
|
||||
if (value == NULL)
|
||||
err = -1;
|
||||
else if (PyDict_CheckExact(locals))
|
||||
err = PyDict_SetItem(locals, name, value);
|
||||
else
|
||||
err = PyObject_SetItem(locals, name, value);
|
||||
Py_DECREF(name);
|
||||
Py_XDECREF(value);
|
||||
if (err < 0)
|
||||
break;
|
||||
}
|
||||
Py_DECREF(all);
|
||||
return err;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
import_star(PyThreadState* tstate, PyObject *from)
|
||||
{
|
||||
_PyInterpreterFrame *frame = tstate->cframe->current_frame;
|
||||
if (_PyFrame_FastToLocalsWithError(frame) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *locals = frame->f_locals;
|
||||
if (locals == NULL) {
|
||||
_PyErr_SetString(tstate, PyExc_SystemError,
|
||||
"no locals found during 'import *'");
|
||||
return NULL;
|
||||
}
|
||||
int err = import_all_from(tstate, locals, from);
|
||||
_PyFrame_LocalsToFast(frame, 0);
|
||||
if (err < 0) {
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
stopiteration_error(PyThreadState* tstate, PyObject *exc)
|
||||
{
|
||||
_PyInterpreterFrame *frame = tstate->cframe->current_frame;
|
||||
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
|
||||
assert(PyExceptionInstance_Check(exc));
|
||||
const char *msg = NULL;
|
||||
if (PyErr_GivenExceptionMatches(exc, PyExc_StopIteration)) {
|
||||
msg = "generator raised StopIteration";
|
||||
if (frame->f_code->co_flags & CO_ASYNC_GENERATOR) {
|
||||
msg = "async generator raised StopIteration";
|
||||
}
|
||||
else if (frame->f_code->co_flags & CO_COROUTINE) {
|
||||
msg = "coroutine raised StopIteration";
|
||||
}
|
||||
}
|
||||
else if ((frame->f_code->co_flags & CO_ASYNC_GENERATOR) &&
|
||||
PyErr_GivenExceptionMatches(exc, PyExc_StopAsyncIteration))
|
||||
{
|
||||
/* code in `gen` raised a StopAsyncIteration error:
|
||||
raise a RuntimeError.
|
||||
*/
|
||||
msg = "async generator raised StopAsyncIteration";
|
||||
}
|
||||
if (msg != NULL) {
|
||||
PyObject *message = _PyUnicode_FromASCII(msg, strlen(msg));
|
||||
if (message == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
PyObject *error = PyObject_CallOneArg(PyExc_RuntimeError, message);
|
||||
if (error == NULL) {
|
||||
Py_DECREF(message);
|
||||
return NULL;
|
||||
}
|
||||
assert(PyExceptionInstance_Check(error));
|
||||
PyException_SetCause(error, Py_NewRef(exc));
|
||||
// Steal exc reference, rather than Py_NewRef+Py_DECREF
|
||||
PyException_SetContext(error, Py_NewRef(exc));
|
||||
Py_DECREF(message);
|
||||
return error;
|
||||
}
|
||||
return Py_NewRef(exc);
|
||||
}
|
||||
|
||||
instrinsic_func1
|
||||
_PyIntrinsics_UnaryFunctions[] = {
|
||||
[0] = no_intrinsic,
|
||||
[INTRINSIC_PRINT] = print_expr,
|
||||
[INTRINSIC_IMPORT_STAR] = import_star,
|
||||
[INTRINSIC_STOPITERATION_ERROR] = stopiteration_error,
|
||||
};
|
42
Python/opcode_targets.h
generated
42
Python/opcode_targets.h
generated
|
@ -62,30 +62,30 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_STORE_SUBSCR,
|
||||
&&TARGET_DELETE_SUBSCR,
|
||||
&&TARGET_FOR_ITER_TUPLE,
|
||||
&&TARGET_STOPITERATION_ERROR,
|
||||
&&TARGET_FOR_ITER_RANGE,
|
||||
&&TARGET_FOR_ITER_GEN,
|
||||
&&TARGET_LOAD_ATTR_CLASS,
|
||||
&&TARGET_LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN,
|
||||
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_GET_ITER,
|
||||
&&TARGET_GET_YIELD_FROM_ITER,
|
||||
&&TARGET_PRINT_EXPR,
|
||||
&&TARGET_LOAD_BUILD_CLASS,
|
||||
&&TARGET_LOAD_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_LOAD_ATTR_MODULE,
|
||||
&&TARGET_LOAD_ASSERTION_ERROR,
|
||||
&&TARGET_RETURN_GENERATOR,
|
||||
&&TARGET_LOAD_BUILD_CLASS,
|
||||
&&TARGET_LOAD_ATTR_PROPERTY,
|
||||
&&TARGET_LOAD_ATTR_SLOT,
|
||||
&&TARGET_LOAD_ASSERTION_ERROR,
|
||||
&&TARGET_RETURN_GENERATOR,
|
||||
&&TARGET_LOAD_ATTR_WITH_HINT,
|
||||
&&TARGET_LOAD_ATTR_METHOD_LAZY_DICT,
|
||||
&&TARGET_LOAD_ATTR_METHOD_NO_DICT,
|
||||
&&TARGET_LOAD_ATTR_METHOD_WITH_VALUES,
|
||||
&&TARGET_LOAD_CONST__LOAD_FAST,
|
||||
&&TARGET_LOAD_FAST__LOAD_CONST,
|
||||
&&TARGET_LIST_TO_TUPLE,
|
||||
&&TARGET_RETURN_VALUE,
|
||||
&&TARGET_IMPORT_STAR,
|
||||
&&TARGET_LOAD_FAST__LOAD_FAST,
|
||||
&&TARGET_SETUP_ANNOTATIONS,
|
||||
&&TARGET_LOAD_CONST__LOAD_FAST,
|
||||
&&TARGET_LOAD_GLOBAL_BUILTIN,
|
||||
&&TARGET_ASYNC_GEN_WRAP,
|
||||
&&TARGET_PREP_RERAISE_STAR,
|
||||
&&TARGET_POP_EXCEPT,
|
||||
|
@ -112,7 +112,7 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_JUMP_FORWARD,
|
||||
&&TARGET_JUMP_IF_FALSE_OR_POP,
|
||||
&&TARGET_JUMP_IF_TRUE_OR_POP,
|
||||
&&TARGET_LOAD_FAST__LOAD_CONST,
|
||||
&&TARGET_LOAD_GLOBAL_MODULE,
|
||||
&&TARGET_POP_JUMP_IF_FALSE,
|
||||
&&TARGET_POP_JUMP_IF_TRUE,
|
||||
&&TARGET_LOAD_GLOBAL,
|
||||
|
@ -120,7 +120,7 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_CONTAINS_OP,
|
||||
&&TARGET_RERAISE,
|
||||
&&TARGET_COPY,
|
||||
&&TARGET_LOAD_FAST__LOAD_FAST,
|
||||
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_BINARY_OP,
|
||||
&&TARGET_SEND,
|
||||
&&TARGET_LOAD_FAST,
|
||||
|
@ -140,9 +140,9 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_STORE_DEREF,
|
||||
&&TARGET_DELETE_DEREF,
|
||||
&&TARGET_JUMP_BACKWARD,
|
||||
&&TARGET_LOAD_GLOBAL_BUILTIN,
|
||||
&&TARGET_STORE_ATTR_SLOT,
|
||||
&&TARGET_CALL_FUNCTION_EX,
|
||||
&&TARGET_LOAD_GLOBAL_MODULE,
|
||||
&&TARGET_STORE_ATTR_WITH_HINT,
|
||||
&&TARGET_EXTENDED_ARG,
|
||||
&&TARGET_LIST_APPEND,
|
||||
&&TARGET_SET_ADD,
|
||||
|
@ -152,27 +152,27 @@ static void *opcode_targets[256] = {
|
|||
&&TARGET_YIELD_VALUE,
|
||||
&&TARGET_RESUME,
|
||||
&&TARGET_MATCH_CLASS,
|
||||
&&TARGET_STORE_ATTR_INSTANCE_VALUE,
|
||||
&&TARGET_STORE_ATTR_SLOT,
|
||||
&&TARGET_STORE_FAST__LOAD_FAST,
|
||||
&&TARGET_STORE_FAST__STORE_FAST,
|
||||
&&TARGET_FORMAT_VALUE,
|
||||
&&TARGET_BUILD_CONST_KEY_MAP,
|
||||
&&TARGET_BUILD_STRING,
|
||||
&&TARGET_STORE_ATTR_WITH_HINT,
|
||||
&&TARGET_STORE_FAST__LOAD_FAST,
|
||||
&&TARGET_STORE_FAST__STORE_FAST,
|
||||
&&TARGET_STORE_SUBSCR_DICT,
|
||||
&&TARGET_STORE_SUBSCR_LIST_INT,
|
||||
&&TARGET_UNPACK_SEQUENCE_LIST,
|
||||
&&TARGET_UNPACK_SEQUENCE_TUPLE,
|
||||
&&TARGET_LIST_EXTEND,
|
||||
&&TARGET_SET_UPDATE,
|
||||
&&TARGET_DICT_MERGE,
|
||||
&&TARGET_DICT_UPDATE,
|
||||
&&TARGET_STORE_SUBSCR_LIST_INT,
|
||||
&&TARGET_UNPACK_SEQUENCE_LIST,
|
||||
&&TARGET_UNPACK_SEQUENCE_TUPLE,
|
||||
&&TARGET_UNPACK_SEQUENCE_TWO_TUPLE,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_CALL,
|
||||
&&TARGET_KW_NAMES,
|
||||
&&_unknown_opcode,
|
||||
&&TARGET_CALL_INTRINSIC_1,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
&&_unknown_opcode,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue