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:
Mark Shannon 2023-01-05 16:05:51 +00:00 committed by GitHub
parent f20c553a45
commit 28187141cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 336 additions and 361 deletions

View file

@ -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"