Py_hash_t hash);
PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
struct _Py_Identifier *key);
+PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
PyObject *mp, PyObject *key, PyObject *defaultobj);
PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
{
PyObject *dialect_obj;
- dialect_obj = PyDict_GetItem(_csvstate_global->dialects, name_obj);
+ dialect_obj = PyDict_GetItemWithError(_csvstate_global->dialects, name_obj);
if (dialect_obj == NULL) {
if (!PyErr_Occurred())
PyErr_Format(_csvstate_global->error_obj, "unknown dialect");
static PyObject *
csv_unregister_dialect(PyObject *module, PyObject *name_obj)
{
- if (PyDict_DelItem(_csvstate_global->dialects, name_obj) < 0)
- return PyErr_Format(_csvstate_global->error_obj, "unknown dialect");
+ if (PyDict_DelItem(_csvstate_global->dialects, name_obj) < 0) {
+ if (PyErr_ExceptionMatches(PyExc_KeyError)) {
+ PyErr_Format(_csvstate_global->error_obj, "unknown dialect");
+ }
+ return NULL;
+ }
Py_RETURN_NONE;
}
if (attrib_str == NULL) {
return NULL;
}
- PyObject *attrib = PyDict_GetItem(kwds, attrib_str);
+ PyObject *attrib = PyDict_GetItemWithError(kwds, attrib_str);
if (attrib) {
/* If attrib was found in kwds, copy its value and remove it from
Py_DECREF(attrib);
attrib = NULL;
}
- } else {
+ }
+ else if (!PyErr_Occurred()) {
attrib = PyDict_New();
}
if (!self->extra || self->extra->attrib == Py_None)
value = default_value;
else {
- value = PyDict_GetItem(self->extra->attrib, key);
- if (!value)
+ value = PyDict_GetItemWithError(self->extra->attrib, key);
+ if (!value) {
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
value = default_value;
+ }
}
Py_INCREF(value);
if (!key)
return NULL;
- value = PyDict_GetItem(self->names, key);
+ value = PyDict_GetItemWithError(self->names, key);
if (value) {
Py_INCREF(value);
- } else {
+ }
+ else if (!PyErr_Occurred()) {
/* new name. convert to universal name, and decode as
necessary */
if (!key)
return;
- value = PyDict_GetItem(self->entity, key);
+ value = PyDict_GetItemWithError(self->entity, key);
if (value) {
if (TreeBuilder_CheckExact(self->target))
key = scanstring_unicode(pystr, idx + 1, s->strict, &next_idx);
if (key == NULL)
goto bail;
- memokey = PyDict_GetItem(s->memo, key);
+ memokey = PyDict_GetItemWithError(s->memo, key);
if (memokey != NULL) {
Py_INCREF(memokey);
Py_DECREF(key);
key = memokey;
}
+ else if (PyErr_Occurred()) {
+ goto bail;
+ }
else {
if (PyDict_SetItem(s->memo, key, key) < 0)
goto bail;
void* ptr;
Py_ssize_t i, j;
- if (index < 0 || index >= self->groups) {
- /* raise IndexError if we were given a bad group number */
- PyErr_SetString(
- PyExc_IndexError,
- "no such group"
- );
- return NULL;
- }
-
+ assert(0 <= index && index < self->groups);
index *= 2;
if (self->string == Py_None || self->mark[index] < 0) {
return 0;
if (PyIndex_Check(index)) {
- return PyNumber_AsSsize_t(index, NULL);
+ i = PyNumber_AsSsize_t(index, NULL);
}
+ else {
+ i = -1;
- i = -1;
-
- if (self->pattern->groupindex) {
- index = PyDict_GetItem(self->pattern->groupindex, index);
- if (index && PyLong_Check(index)) {
- i = PyLong_AsSsize_t(index);
+ if (self->pattern->groupindex) {
+ index = PyDict_GetItemWithError(self->pattern->groupindex, index);
+ if (index && PyLong_Check(index)) {
+ i = PyLong_AsSsize_t(index);
+ }
}
}
+ if (i < 0 || i >= self->groups) {
+ /* raise IndexError if we were given a bad group number */
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_IndexError, "no such group");
+ }
+ return -1;
+ }
return i;
}
static PyObject*
match_getslice(MatchObject* self, PyObject* index, PyObject* def)
{
- return match_getslice_by_index(self, match_getindex(self, index), def);
+ Py_ssize_t i = match_getindex(self, index);
+
+ if (i < 0) {
+ return NULL;
+ }
+
+ return match_getslice_by_index(self, i, def);
}
/*[clinic input]
{
Py_ssize_t index = match_getindex(self, group);
- if (index < 0 || index >= self->groups) {
- PyErr_SetString(
- PyExc_IndexError,
- "no such group"
- );
+ if (index < 0) {
return -1;
}
{
Py_ssize_t index = match_getindex(self, group);
- if (index < 0 || index >= self->groups) {
- PyErr_SetString(
- PyExc_IndexError,
- "no such group"
- );
+ if (index < 0) {
return -1;
}
{
Py_ssize_t index = match_getindex(self, group);
- if (index < 0 || index >= self->groups) {
- PyErr_SetString(
- PyExc_IndexError,
- "no such group"
- );
+ if (index < 0) {
return NULL;
}
return 0;
}
- s_object = PyDict_GetItem(cache, fmt);
+ s_object = PyDict_GetItemWithError(cache, fmt);
if (s_object != NULL) {
Py_INCREF(s_object);
*ptr = (PyStructObject *)s_object;
return Py_CLEANUP_SUPPORTED;
}
+ else if (PyErr_Occurred()) {
+ return 0;
+ }
s_object = PyObject_CallFunctionObjArgs((PyObject *)(&PyStructType), fmt, NULL);
if (s_object != NULL) {
Example_getattro(ExampleObject *self, PyObject *name)
{
if (self->x_attr != NULL) {
- PyObject *v = PyDict_GetItem(self->x_attr, name);
+ PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
Py_INCREF(v);
return v;
}
+ else if (PyErr_Occurred()) {
+ return NULL;
+ }
}
return PyObject_GenericGetAttr((PyObject *)self, name);
}
}
if (v == NULL) {
int rv = PyDict_DelItemString(self->x_attr, name);
- if (rv < 0)
+ if (rv < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
PyErr_SetString(PyExc_AttributeError,
"delete non-existing Example attribute");
return rv;
return NULL;
}
- dummy = PyDict_GetItem(tdict, self->key);
+ dummy = PyDict_GetItemWithError(tdict, self->key);
if (dummy == NULL) {
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
ldict = _local_create_dummy(self);
if (ldict == NULL)
return NULL;
(PyObject *)self, name, ldict, 0);
/* Optimization: just look in dict ourselves */
- value = PyDict_GetItem(ldict, name);
- if (value == NULL)
- /* Fall back on generic to get __class__ and __dict__ */
- return _PyObject_GenericGetAttrWithDict(
- (PyObject *)self, name, ldict, 0);
-
- Py_INCREF(value);
- return value;
+ value = PyDict_GetItemWithError(ldict, name);
+ if (value != NULL) {
+ Py_INCREF(value);
+ return value;
+ }
+ else if (PyErr_Occurred()) {
+ return NULL;
+ }
+ /* Fall back on generic to get __class__ and __dict__ */
+ return _PyObject_GenericGetAttrWithDict(
+ (PyObject *)self, name, ldict, 0);
}
/* Called when a dummy is destroyed. */
self = (localobject *) obj;
if (self->dummies != NULL) {
PyObject *ldict;
- ldict = PyDict_GetItem(self->dummies, dummyweakref);
+ ldict = PyDict_GetItemWithError(self->dummies, dummyweakref);
if (ldict != NULL) {
PyDict_DelItem(self->dummies, dummyweakref);
}
static PyObject *
zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
+ _Py_IDENTIFIER(fillvalue);
ziplongestobject *lz;
Py_ssize_t i;
PyObject *ittuple; /* tuple of iterators */
Py_ssize_t tuplesize;
if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_GET_SIZE(kwds) > 0) {
- fillvalue = PyDict_GetItemString(kwds, "fillvalue");
- if (fillvalue == NULL || PyDict_GET_SIZE(kwds) > 1) {
- PyErr_SetString(PyExc_TypeError,
- "zip_longest() got an unexpected keyword argument");
+ fillvalue = NULL;
+ if (PyDict_GET_SIZE(kwds) == 1) {
+ fillvalue = _PyDict_GetItemIdWithError(kwds, &PyId_fillvalue);
+ }
+ if (fillvalue == NULL) {
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError,
+ "zip_longest() got an unexpected keyword argument");
+ }
return NULL;
}
}
static int
pymain_sys_path_add_path0(PyInterpreterState *interp, PyObject *path0)
{
+ _Py_IDENTIFIER(path);
PyObject *sys_path;
PyObject *sysdict = interp->sysdict;
if (sysdict != NULL) {
- sys_path = PyDict_GetItemString(sysdict, "path");
+ sys_path = _PyDict_GetItemIdWithError(sysdict, &PyId_path);
+ if (sys_path == NULL && PyErr_Occurred()) {
+ goto error;
+ }
}
else {
sys_path = NULL;
*/
if (PyDict_DelItem(posix_putenv_garbage, name)) {
/* really not much we can do; just leak */
+ if (!PyErr_ExceptionMatches(PyExc_KeyError)) {
+ return NULL;
+ }
PyErr_Clear();
}
Py_RETURN_NONE;
return result;
if (!self->intern)
return result;
- value = PyDict_GetItem(self->intern, result);
+ value = PyDict_GetItemWithError(self->intern, result);
if (!value) {
- if (PyDict_SetItem(self->intern, result, result) == 0)
+ if (!PyErr_Occurred() &&
+ PyDict_SetItem(self->intern, result, result) == 0)
+ {
return result;
+ }
else {
Py_DECREF(result);
return NULL;
hi->getset.set = (setter)xmlparse_handler_setter;
hi->getset.closure = &handler_info[i];
- PyObject *descr;
- if (PyDict_GetItemString(Xmlparsetype.tp_dict, hi->name))
- continue;
- descr = PyDescr_NewGetSet(&Xmlparsetype, &hi->getset);
-
+ PyObject *descr = PyDescr_NewGetSet(&Xmlparsetype, &hi->getset);
if (descr == NULL)
return -1;
+
+ if (PyDict_GetItemWithError(Xmlparsetype.tp_dict, PyDescr_NAME(descr))) {
+ Py_DECREF(descr);
+ continue;
+ }
+ else if (PyErr_Occurred()) {
+ Py_DECREF(descr);
+ return -1;
+ }
if (PyDict_SetItem(Xmlparsetype.tp_dict, PyDescr_NAME(descr), descr) < 0) {
Py_DECREF(descr);
return -1;
Py_DECREF(m);
return NULL;
}
- errors_module = PyDict_GetItem(d, errmod_name);
- if (errors_module == NULL) {
+ errors_module = PyDict_GetItemWithError(d, errmod_name);
+ if (errors_module == NULL && !PyErr_Occurred()) {
errors_module = PyModule_New(MODULE_NAME ".errors");
if (errors_module != NULL) {
_PyImport_SetModule(errmod_name, errors_module);
}
}
Py_DECREF(errmod_name);
- model_module = PyDict_GetItem(d, modelmod_name);
- if (model_module == NULL) {
+ model_module = PyDict_GetItemWithError(d, modelmod_name);
+ if (model_module == NULL && !PyErr_Occurred()) {
model_module = PyModule_New(MODULE_NAME ".model");
if (model_module != NULL) {
_PyImport_SetModule(modelmod_name, model_module);
key = PyLong_FromLong(fd);
if (key == NULL)
return NULL;
- if (PyDict_GetItem(self->dict, key) == NULL) {
- errno = ENOENT;
- PyErr_SetFromErrno(PyExc_OSError);
+ if (PyDict_GetItemWithError(self->dict, key) == NULL) {
+ if (!PyErr_Occurred()) {
+ errno = ENOENT;
+ PyErr_SetFromErrno(PyExc_OSError);
+ }
Py_DECREF(key);
return NULL;
}
Xxo_getattro(XxoObject *self, PyObject *name)
{
if (self->x_attr != NULL) {
- PyObject *v = PyDict_GetItem(self->x_attr, name);
+ PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
Py_INCREF(v);
return v;
}
+ else if (PyErr_Occurred()) {
+ return NULL;
+ }
}
return PyObject_GenericGetAttr((PyObject *)self, name);
}
}
if (v == NULL) {
int rv = PyDict_DelItemString(self->x_attr, name);
- if (rv < 0)
+ if (rv < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
PyErr_SetString(PyExc_AttributeError,
"delete non-existing Xxo attribute");
return rv;
Xxo_getattro(XxoObject *self, PyObject *name)
{
if (self->x_attr != NULL) {
- PyObject *v = PyDict_GetItem(self->x_attr, name);
+ PyObject *v = PyDict_GetItemWithError(self->x_attr, name);
if (v != NULL) {
Py_INCREF(v);
return v;
}
+ else if (PyErr_Occurred()) {
+ return NULL;
+ }
}
return PyObject_GenericGetAttr((PyObject *)self, name);
}
}
if (v == NULL) {
int rv = PyDict_DelItemString(self->x_attr, name);
- if (rv < 0)
+ if (rv < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
PyErr_SetString(PyExc_AttributeError,
"delete non-existing Xxo attribute");
return rv;
return PyDict_GetItemWithError(dp, kv);
}
+PyObject *
+_PyDict_GetItemStringWithError(PyObject *v, const char *key)
+{
+ PyObject *kv, *rv;
+ kv = PyUnicode_FromString(key);
+ if (kv == NULL) {
+ return NULL;
+ }
+ rv = PyDict_GetItemWithError(v, kv);
+ Py_DECREF(kv);
+ return rv;
+}
+
/* Fast version of global value lookup (LOAD_GLOBAL).
* Lookup in globals, then builtins.
*
value = PySequence_Fast_GET_ITEM(fast, 1);
Py_INCREF(key);
Py_INCREF(value);
- if (override || PyDict_GetItem(d, key) == NULL) {
- int status = PyDict_SetItem(d, key, value);
- if (status < 0) {
+ if (override) {
+ if (PyDict_SetItem(d, key, value) < 0) {
+ Py_DECREF(key);
+ Py_DECREF(value);
+ goto Fail;
+ }
+ }
+ else if (PyDict_GetItemWithError(d, key) == NULL) {
+ if (PyErr_Occurred() || PyDict_SetItem(d, key, value) < 0) {
Py_DECREF(key);
Py_DECREF(value);
goto Fail;
}
}
+
Py_DECREF(key);
Py_DECREF(value);
Py_DECREF(fast);
return -1;
for (key = PyIter_Next(iter); key; key = PyIter_Next(iter)) {
- if (override != 1 && PyDict_GetItem(a, key) != NULL) {
- if (override != 0) {
- _PyErr_SetKeyError(key);
+ if (override != 1) {
+ if (PyDict_GetItemWithError(a, key) != NULL) {
+ if (override != 0) {
+ _PyErr_SetKeyError(key);
+ Py_DECREF(key);
+ Py_DECREF(iter);
+ return -1;
+ }
+ Py_DECREF(key);
+ continue;
+ }
+ else if (PyErr_Occurred()) {
Py_DECREF(key);
Py_DECREF(iter);
return -1;
}
- Py_DECREF(key);
- continue;
}
value = PyObject_GetItem(b, key);
if (value == NULL) {
if (myerrno && PyLong_Check(myerrno) &&
errnomap && (PyObject *) type == PyExc_OSError) {
PyObject *newtype;
- newtype = PyDict_GetItem(errnomap, myerrno);
+ newtype = PyDict_GetItemWithError(errnomap, myerrno);
if (newtype) {
assert(PyType_Check(newtype));
type = (PyTypeObject *) newtype;
}
#endif
if (back == NULL || back->f_globals != globals) {
- builtins = _PyDict_GetItemId(globals, &PyId___builtins__);
+ builtins = _PyDict_GetItemIdWithError(globals, &PyId___builtins__);
if (builtins) {
if (PyModule_Check(builtins)) {
builtins = PyModule_GetDict(builtins);
}
}
if (builtins == NULL) {
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
/* No builtins! Make up a minimal one
Give them 'None', at least. */
builtins = PyDict_New();
/* __module__: If module name is in globals, use it.
Otherwise, use None. */
- module = PyDict_GetItem(globals, __name__);
+ module = PyDict_GetItemWithError(globals, __name__);
if (module) {
Py_INCREF(module);
op->func_module = module;
}
+ else if (PyErr_Occurred()) {
+ Py_DECREF(op);
+ return NULL;
+ }
if (qualname)
op->func_qualname = qualname;
else
module_dir(PyObject *self, PyObject *args)
{
_Py_IDENTIFIER(__dict__);
+ _Py_IDENTIFIER(__dir__);
PyObject *result = NULL;
PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__);
if (dict != NULL) {
if (PyDict_Check(dict)) {
- PyObject *dirfunc = PyDict_GetItemString(dict, "__dir__");
+ PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__);
if (dirfunc) {
result = _PyObject_CallNoArg(dirfunc);
}
- else {
+ else if (!PyErr_Occurred()) {
result = PyDict_Keys(dict);
}
}
if (PyUnicode_Check(key) && PyUnicode_GET_LENGTH(key) > 0) {
PyObject *value, *item;
- value = PyDict_GetItem(d, key);
+ value = PyDict_GetItemWithError(d, key);
if (value != NULL) {
- item = PyUnicode_FromFormat("%S=%R", key, value);
+ item = PyUnicode_FromFormat("%U=%R", key, value);
if (item == NULL) {
loop_error = 1;
}
Py_DECREF(item);
}
}
+ else if (PyErr_Occurred()) {
+ loop_error = 1;
+ }
}
Py_DECREF(key);
dictptr = _PyObject_GetDictPtr(obj);
if (dictptr != NULL && (dict = *dictptr) != NULL) {
Py_INCREF(dict);
- attr = PyDict_GetItem(dict, name);
+ attr = PyDict_GetItemWithError(dict, name);
if (attr != NULL) {
Py_INCREF(attr);
*method = attr;
Py_XDECREF(descr);
return 0;
}
- Py_DECREF(dict);
+ else {
+ Py_DECREF(dict);
+ if (PyErr_Occurred()) {
+ Py_XDECREF(descr);
+ return 0;
+ }
+ }
}
if (meth_found) {
}
if (dict != NULL) {
Py_INCREF(dict);
- res = PyDict_GetItem(dict, name);
+ res = PyDict_GetItemWithError(dict, name);
if (res != NULL) {
Py_INCREF(res);
Py_DECREF(dict);
goto done;
}
- Py_DECREF(dict);
+ else {
+ Py_DECREF(dict);
+ if (PyErr_Occurred()) {
+ if (suppress && PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ PyErr_Clear();
+ }
+ else {
+ goto done;
+ }
+ }
+ }
}
if (f != NULL) {
early on startup. */
if (dict == NULL)
return 0;
- list = _PyDict_GetItemId(dict, &PyId_Py_Repr);
+ list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
if (list == NULL) {
+ if (PyErr_Occurred()) {
+ return -1;
+ }
list = PyList_New(0);
if (list == NULL)
return -1;
if (dict == NULL)
goto finally;
- list = _PyDict_GetItemId(dict, &PyId_Py_Repr);
+ list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
if (list == NULL || !PyList_Check(list))
goto finally;
PyObject *mod;
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
- mod = _PyDict_GetItemId(type->tp_dict, &PyId___module__);
+ mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__);
if (mod == NULL) {
- PyErr_Format(PyExc_AttributeError, "__module__");
+ if (!PyErr_Occurred()) {
+ PyErr_Format(PyExc_AttributeError, "__module__");
+ }
return NULL;
}
Py_INCREF(mod);
/* type itself has an __abstractmethods__ descriptor (this). Don't return
that. */
if (type != &PyType_Type)
- mod = _PyDict_GetItemId(type->tp_dict, &PyId___abstractmethods__);
+ mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___abstractmethods__);
if (!mod) {
- PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__);
- if (message)
- PyErr_SetObject(PyExc_AttributeError, message);
+ if (!PyErr_Occurred()) {
+ PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__);
+ if (message)
+ PyErr_SetObject(PyExc_AttributeError, message);
+ }
return NULL;
}
Py_INCREF(mod);
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) {
return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc);
}
- result = _PyDict_GetItemId(type->tp_dict, &PyId___doc__);
+ result = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__);
if (result == NULL) {
- result = Py_None;
- Py_INCREF(result);
+ if (!PyErr_Occurred()) {
+ result = Py_None;
+ Py_INCREF(result);
+ }
}
else if (Py_TYPE(result)->tp_descr_get) {
result = Py_TYPE(result)->tp_descr_get(result, NULL,
goto error;
/* Check for a __slots__ sequence variable in dict, and count it */
- slots = _PyDict_GetItemId(dict, &PyId___slots__);
+ slots = _PyDict_GetItemIdWithError(dict, &PyId___slots__);
nslots = 0;
add_dict = 0;
add_weak = 0;
may_add_dict = base->tp_dictoffset == 0;
may_add_weak = base->tp_weaklistoffset == 0 && base->tp_itemsize == 0;
if (slots == NULL) {
+ if (PyErr_Occurred()) {
+ goto error;
+ }
if (may_add_dict) {
add_dict++;
}
goto error;
}
PyList_SET_ITEM(newslots, j, tmp);
- if (PyDict_GetItem(dict, tmp)) {
+ if (PyDict_GetItemWithError(dict, tmp)) {
/* CPython inserts __qualname__ and __classcell__ (when needed)
into the namespace when creating a class. They will be deleted
below so won't act as class variables. */
goto error;
}
}
+ else if (PyErr_Occurred()) {
+ Py_DECREF(newslots);
+ goto error;
+ }
j++;
}
assert(j == nslots - add_dict - add_weak);
type->tp_dict = dict;
/* Set __module__ in the dict */
- if (_PyDict_GetItemId(dict, &PyId___module__) == NULL) {
+ if (_PyDict_GetItemIdWithError(dict, &PyId___module__) == NULL) {
+ if (PyErr_Occurred()) {
+ goto error;
+ }
tmp = PyEval_GetGlobals();
if (tmp != NULL) {
- tmp = _PyDict_GetItemId(tmp, &PyId___name__);
+ tmp = _PyDict_GetItemIdWithError(tmp, &PyId___name__);
if (tmp != NULL) {
if (_PyDict_SetItemId(dict, &PyId___module__,
tmp) < 0)
goto error;
}
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
}
}
/* Set ht_qualname to dict['__qualname__'] if available, else to
__name__. The __qualname__ accessor will look for ht_qualname.
*/
- qualname = _PyDict_GetItemId(dict, &PyId___qualname__);
+ qualname = _PyDict_GetItemIdWithError(dict, &PyId___qualname__);
if (qualname != NULL) {
if (!PyUnicode_Check(qualname)) {
PyErr_Format(PyExc_TypeError,
goto error;
}
}
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
et->ht_qualname = qualname ? qualname : et->ht_name;
Py_INCREF(et->ht_qualname);
if (qualname != NULL && _PyDict_DelItemId(dict, &PyId___qualname__) < 0)
if that fails, it will still look into __dict__.
*/
{
- PyObject *doc = _PyDict_GetItemId(dict, &PyId___doc__);
+ PyObject *doc = _PyDict_GetItemIdWithError(dict, &PyId___doc__);
if (doc != NULL && PyUnicode_Check(doc)) {
Py_ssize_t len;
const char *doc_str;
memcpy(tp_doc, doc_str, len + 1);
type->tp_doc = tp_doc;
}
+ else if (doc == NULL && PyErr_Occurred()) {
+ goto error;
+ }
}
/* Special-case __new__: if it's a plain function,
make it a static function */
- tmp = _PyDict_GetItemId(dict, &PyId___new__);
+ tmp = _PyDict_GetItemIdWithError(dict, &PyId___new__);
if (tmp != NULL && PyFunction_Check(tmp)) {
tmp = PyStaticMethod_New(tmp);
if (tmp == NULL)
}
Py_DECREF(tmp);
}
+ else if (tmp == NULL && PyErr_Occurred()) {
+ goto error;
+ }
/* Special-case __init_subclass__ and __class_getitem__:
if they are plain functions, make them classmethods */
- tmp = _PyDict_GetItemId(dict, &PyId___init_subclass__);
+ tmp = _PyDict_GetItemIdWithError(dict, &PyId___init_subclass__);
if (tmp != NULL && PyFunction_Check(tmp)) {
tmp = PyClassMethod_New(tmp);
if (tmp == NULL)
}
Py_DECREF(tmp);
}
+ else if (tmp == NULL && PyErr_Occurred()) {
+ goto error;
+ }
- tmp = _PyDict_GetItemId(dict, &PyId___class_getitem__);
+ tmp = _PyDict_GetItemIdWithError(dict, &PyId___class_getitem__);
if (tmp != NULL && PyFunction_Check(tmp)) {
tmp = PyClassMethod_New(tmp);
if (tmp == NULL)
}
Py_DECREF(tmp);
}
+ else if (tmp == NULL && PyErr_Occurred()) {
+ goto error;
+ }
/* Add descriptors for custom slots from __slots__, or for __dict__ */
mp = PyHeapType_GET_MEMBERS(et);
type->tp_free = PyObject_Del;
/* store type in class' cell if one is supplied */
- cell = _PyDict_GetItemId(dict, &PyId___classcell__);
+ cell = _PyDict_GetItemIdWithError(dict, &PyId___classcell__);
if (cell != NULL) {
/* At least one method requires a reference to its defining class */
if (!PyCell_Check(cell)) {
goto error;
}
PyCell_Set(cell, (PyObject *) type);
- _PyDict_DelItemId(dict, &PyId___classcell__);
- PyErr_Clear();
+ if (_PyDict_DelItemId(dict, &PyId___classcell__) < 0) {
+ goto error;
+ }
+ }
+ else if (PyErr_Occurred()) {
+ goto error;
}
/* Initialize the rest */
}
if (type->tp_flags & Py_TPFLAGS_IS_ABSTRACT) {
- PyObject *abstract_methods = NULL;
- PyObject *builtins;
- PyObject *sorted;
- PyObject *sorted_methods = NULL;
- PyObject *joined = NULL;
+ PyObject *abstract_methods;
+ PyObject *sorted_methods;
+ PyObject *joined;
PyObject *comma;
_Py_static_string(comma_id, ", ");
- _Py_IDENTIFIER(sorted);
/* Compute ", ".join(sorted(type.__abstractmethods__))
into joined. */
abstract_methods = type_abstractmethods(type, NULL);
if (abstract_methods == NULL)
- goto error;
- builtins = PyEval_GetBuiltins();
- if (builtins == NULL)
- goto error;
- sorted = _PyDict_GetItemId(builtins, &PyId_sorted);
- if (sorted == NULL)
- goto error;
- sorted_methods = PyObject_CallFunctionObjArgs(sorted,
- abstract_methods,
- NULL);
+ return NULL;
+ sorted_methods = PySequence_List(abstract_methods);
+ Py_DECREF(abstract_methods);
if (sorted_methods == NULL)
- goto error;
+ return NULL;
+ if (PyList_Sort(sorted_methods)) {
+ Py_DECREF(sorted_methods);
+ return NULL;
+ }
comma = _PyUnicode_FromId(&comma_id);
- if (comma == NULL)
- goto error;
+ if (comma == NULL) {
+ Py_DECREF(sorted_methods);
+ return NULL;
+ }
joined = PyUnicode_Join(comma, sorted_methods);
+ Py_DECREF(sorted_methods);
if (joined == NULL)
- goto error;
+ return NULL;
PyErr_Format(PyExc_TypeError,
"Can't instantiate abstract class %s "
"with abstract methods %U",
type->tp_name,
joined);
- error:
- Py_XDECREF(joined);
- Py_XDECREF(sorted_methods);
- Py_XDECREF(abstract_methods);
+ Py_DECREF(joined);
return NULL;
}
return type->tp_alloc(type, 0);
if (objreduce == NULL) {
objreduce = _PyDict_GetItemId(PyBaseObject_Type.tp_dict,
&PyId___reduce__);
- if (objreduce == NULL)
- return NULL;
}
- reduce = _PyObject_GetAttrId(self, &PyId___reduce__);
- if (reduce == NULL)
- PyErr_Clear();
- else {
+ if (_PyObject_LookupAttrId(self, &PyId___reduce__, &reduce) < 0) {
+ return NULL;
+ }
+ if (reduce != NULL) {
PyObject *cls, *clsreduce;
int override;
add_methods(PyTypeObject *type, PyMethodDef *meth)
{
PyObject *dict = type->tp_dict;
+ PyObject *name;
for (; meth->ml_name != NULL; meth++) {
PyObject *descr;
int err;
int isdescr = 1;
- if (PyDict_GetItemString(dict, meth->ml_name) &&
- !(meth->ml_flags & METH_COEXIST))
- continue;
if (meth->ml_flags & METH_CLASS) {
if (meth->ml_flags & METH_STATIC) {
PyErr_SetString(PyExc_ValueError,
descr = PyDescr_NewClassMethod(type, meth);
}
else if (meth->ml_flags & METH_STATIC) {
- PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL);
+ PyObject *cfunc = PyCFunction_NewEx(meth, (PyObject*)type, NULL);
if (cfunc == NULL)
return -1;
descr = PyStaticMethod_New(cfunc);
}
if (descr == NULL)
return -1;
+
if (isdescr) {
- err = PyDict_SetItem(dict, PyDescr_NAME(descr), descr);
+ name = PyDescr_NAME(descr);
}
else {
- err = PyDict_SetItemString(dict, meth->ml_name, descr);
+ name = PyUnicode_FromString(meth->ml_name);
+ if (name == NULL) {
+ Py_DECREF(descr);
+ return -1;
+ }
+ }
+
+ if (!(meth->ml_flags & METH_COEXIST)) {
+ if (PyDict_GetItemWithError(dict, name)) {
+ if (!isdescr) {
+ Py_DECREF(name);
+ }
+ Py_DECREF(descr);
+ continue;
+ }
+ else if (PyErr_Occurred()) {
+ if (!isdescr) {
+ Py_DECREF(name);
+ }
+ return -1;
+ }
+ }
+ err = PyDict_SetItem(dict, name, descr);
+ if (!isdescr) {
+ Py_DECREF(name);
}
Py_DECREF(descr);
if (err < 0)
PyObject *dict = type->tp_dict;
for (; memb->name != NULL; memb++) {
- PyObject *descr;
- if (PyDict_GetItemString(dict, memb->name))
- continue;
- descr = PyDescr_NewMember(type, memb);
+ PyObject *descr = PyDescr_NewMember(type, memb);
if (descr == NULL)
return -1;
+
+ if (PyDict_GetItemWithError(dict, PyDescr_NAME(descr))) {
+ Py_DECREF(descr);
+ continue;
+ }
+ else if (PyErr_Occurred()) {
+ Py_DECREF(descr);
+ return -1;
+ }
if (PyDict_SetItem(dict, PyDescr_NAME(descr), descr) < 0) {
Py_DECREF(descr);
return -1;
PyObject *dict = type->tp_dict;
for (; gsp->name != NULL; gsp++) {
- PyObject *descr;
- if (PyDict_GetItemString(dict, gsp->name))
- continue;
- descr = PyDescr_NewGetSet(type, gsp);
-
+ PyObject *descr = PyDescr_NewGetSet(type, gsp);
if (descr == NULL)
return -1;
+
+ if (PyDict_GetItemWithError(dict, PyDescr_NAME(descr))) {
+ continue;
+ }
+ else if (PyErr_Occurred()) {
+ Py_DECREF(descr);
+ return -1;
+ }
if (PyDict_SetItem(dict, PyDescr_NAME(descr), descr) < 0) {
Py_DECREF(descr);
return -1;
/* if the type dictionary doesn't contain a __doc__, set it from
the tp_doc slot.
*/
- if (_PyDict_GetItemId(type->tp_dict, &PyId___doc__) == NULL) {
+ if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__) == NULL) {
+ if (PyErr_Occurred()) {
+ goto error;
+ }
if (type->tp_doc != NULL) {
const char *old_doc = _PyType_DocWithoutSignature(type->tp_name,
type->tp_doc);
This signals that __hash__ is not inherited.
*/
if (type->tp_hash == NULL) {
- if (_PyDict_GetItemId(type->tp_dict, &PyId___hash__) == NULL) {
- if (_PyDict_SetItemId(type->tp_dict, &PyId___hash__, Py_None) < 0)
+ if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___hash__) == NULL) {
+ if (PyErr_Occurred() ||
+ _PyDict_SetItemId(type->tp_dict, &PyId___hash__, Py_None) < 0)
+ {
goto error;
+ }
type->tp_hash = PyObject_HashNotImplemented;
}
}
{
PyObject *func;
- if (_PyDict_GetItemId(type->tp_dict, &PyId___new__) != NULL)
+ if (_PyDict_GetItemIdWithError(type->tp_dict, &PyId___new__) != NULL)
return 0;
+ if (PyErr_Occurred())
+ return -1;
func = PyCFunction_NewEx(tp_new_methoddef, (PyObject *)type, NULL);
if (func == NULL)
return -1;
assert(PyType_Check(subclass));
/* Avoid recursing down into unaffected classes */
dict = subclass->tp_dict;
- if (dict != NULL && PyDict_Check(dict) &&
- PyDict_GetItem(dict, name) != NULL)
- continue;
+ if (dict != NULL && PyDict_Check(dict)) {
+ if (PyDict_GetItemWithError(dict, name) != NULL) {
+ continue;
+ }
+ if (PyErr_Occurred()) {
+ return -1;
+ }
+ }
if (update_subclasses(subclass, name, callback, data) < 0)
return -1;
}
ptr = slotptr(type, p->offset);
if (!ptr || !*ptr)
continue;
- if (PyDict_GetItem(dict, p->name_strobj))
+ if (PyDict_GetItemWithError(dict, p->name_strobj))
continue;
+ if (PyErr_Occurred()) {
+ return -1;
+ }
if (*ptr == (void *)PyObject_HashNotImplemented) {
/* Classes may prevent the inheritance of the tp_hash
slot by storing PyObject_HashNotImplemented in it. Make it
goto skip;
/* keep a strong reference to mro because starttype->tp_mro can be
- replaced during PyDict_GetItem(dict, name) */
+ replaced during PyDict_GetItemWithError(dict, name) */
Py_INCREF(mro);
do {
PyObject *res, *tmp, *dict;
dict = ((PyTypeObject *)tmp)->tp_dict;
assert(dict != NULL && PyDict_Check(dict));
- res = PyDict_GetItem(dict, name);
+ res = PyDict_GetItemWithError(dict, name);
if (res != NULL) {
Py_INCREF(res);
Py_DECREF(mro);
return res;
}
+ else if (PyErr_Occurred()) {
+ return NULL;
+ }
i++;
} while (i < n);
if (key == NULL)
return -1;
- version_obj = _PyDict_GetItemId(registry, &PyId_version);
+ version_obj = _PyDict_GetItemIdWithError(registry, &PyId_version);
if (version_obj == NULL
|| !PyLong_CheckExact(version_obj)
|| PyLong_AsLong(version_obj) != _PyRuntime.warnings.filters_version)
Py_DECREF(version_obj);
}
else {
- already_warned = PyDict_GetItem(registry, key);
+ already_warned = PyDict_GetItemWithError(registry, key);
if (already_warned != NULL) {
int rc = PyObject_IsTrue(already_warned);
if (rc != 0)
return rc;
}
+ else if (PyErr_Occurred()) {
+ return -1;
+ }
}
/* This warning wasn't found in the registry, set it. */
setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
PyObject **module, PyObject **registry)
{
+ _Py_IDENTIFIER(__warningregistry__);
+ _Py_IDENTIFIER(__name__);
PyObject *globals;
/* Setup globals, filename and lineno. */
/* Setup registry. */
assert(globals != NULL);
assert(PyDict_Check(globals));
- *registry = PyDict_GetItemString(globals, "__warningregistry__");
+ *registry = _PyDict_GetItemIdWithError(globals, &PyId___warningregistry__);
if (*registry == NULL) {
int rc;
+ if (PyErr_Occurred()) {
+ return 0;
+ }
*registry = PyDict_New();
if (*registry == NULL)
return 0;
- rc = PyDict_SetItemString(globals, "__warningregistry__", *registry);
+ rc = _PyDict_SetItemId(globals, &PyId___warningregistry__, *registry);
if (rc < 0)
goto handle_error;
}
Py_INCREF(*registry);
/* Setup module. */
- *module = PyDict_GetItemString(globals, "__name__");
+ *module = _PyDict_GetItemIdWithError(globals, &PyId___name__);
if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
+ else if (PyErr_Occurred()) {
+ goto handle_error;
+ }
else {
*module = PyUnicode_FromString("<string>");
if (*module == NULL)
return NULL;
}
- meta = _PyDict_GetItemId(mkw, &PyId_metaclass);
+ meta = _PyDict_GetItemIdWithError(mkw, &PyId_metaclass);
if (meta != NULL) {
Py_INCREF(meta);
if (_PyDict_DelItemId(mkw, &PyId_metaclass) < 0) {
/* metaclass is explicitly given, check if it's indeed a class */
isclass = PyType_Check(meta);
}
+ else if (PyErr_Occurred()) {
+ Py_DECREF(mkw);
+ Py_DECREF(bases);
+ return NULL;
+ }
}
if (meta == NULL) {
/* if there are no bases, use type: */
return NULL;
}
- if (_PyDict_GetItemId(globals, &PyId___builtins__) == NULL) {
+ if (_PyDict_GetItemIdWithError(globals, &PyId___builtins__) == NULL) {
if (_PyDict_SetItemId(globals, &PyId___builtins__,
PyEval_GetBuiltins()) != 0)
return NULL;
}
+ else if (PyErr_Occurred()) {
+ return NULL;
+ }
if (PyCode_Check(source)) {
if (PyCode_GetNumFree((PyCodeObject *)source) > 0) {
locals->ob_type->tp_name);
return NULL;
}
- if (_PyDict_GetItemId(globals, &PyId___builtins__) == NULL) {
+ if (_PyDict_GetItemIdWithError(globals, &PyId___builtins__) == NULL) {
if (_PyDict_SetItemId(globals, &PyId___builtins__,
PyEval_GetBuiltins()) != 0)
return NULL;
}
+ else if (PyErr_Occurred()) {
+ return NULL;
+ }
if (PyCode_Check(source)) {
if (PyCode_GetNumFree((PyCodeObject *)source) > 0) {
PyObject *bc;
if (PyDict_CheckExact(f->f_builtins)) {
- bc = _PyDict_GetItemId(f->f_builtins, &PyId___build_class__);
+ bc = _PyDict_GetItemIdWithError(f->f_builtins, &PyId___build_class__);
if (bc == NULL) {
- PyErr_SetString(PyExc_NameError,
- "__build_class__ not found");
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_NameError,
+ "__build_class__ not found");
+ }
goto error;
}
Py_INCREF(bc);
int err;
err = PyDict_DelItem(f->f_globals, name);
if (err != 0) {
- format_exc_check_arg(
- PyExc_NameError, NAME_ERROR_MSG, name);
+ if (PyErr_ExceptionMatches(PyExc_KeyError)) {
+ format_exc_check_arg(
+ PyExc_NameError, NAME_ERROR_MSG, name);
+ }
goto error;
}
DISPATCH();
goto error;
}
if (PyDict_CheckExact(locals)) {
- v = PyDict_GetItem(locals, name);
- Py_XINCREF(v);
+ v = PyDict_GetItemWithError(locals, name);
+ if (v != NULL) {
+ Py_INCREF(v);
+ }
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
}
else {
v = PyObject_GetItem(locals, name);
}
}
if (v == NULL) {
- v = PyDict_GetItem(f->f_globals, name);
- Py_XINCREF(v);
- if (v == NULL) {
+ v = PyDict_GetItemWithError(f->f_globals, name);
+ if (v != NULL) {
+ Py_INCREF(v);
+ }
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
+ else {
if (PyDict_CheckExact(f->f_builtins)) {
- v = PyDict_GetItem(f->f_builtins, name);
+ v = PyDict_GetItemWithError(f->f_builtins, name);
if (v == NULL) {
- format_exc_check_arg(
+ if (!PyErr_Occurred()) {
+ format_exc_check_arg(
PyExc_NameError,
NAME_ERROR_MSG, name);
+ }
goto error;
}
Py_INCREF(v);
assert(idx >= 0 && idx < PyTuple_GET_SIZE(co->co_freevars));
name = PyTuple_GET_ITEM(co->co_freevars, idx);
if (PyDict_CheckExact(locals)) {
- value = PyDict_GetItem(locals, name);
- Py_XINCREF(value);
+ value = PyDict_GetItemWithError(locals, name);
+ if (value != NULL) {
+ Py_INCREF(value);
+ }
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
}
else {
value = PyObject_GetItem(locals, name);
}
/* check if __annotations__ in locals()... */
if (PyDict_CheckExact(f->f_locals)) {
- ann_dict = _PyDict_GetItemId(f->f_locals,
+ ann_dict = _PyDict_GetItemIdWithError(f->f_locals,
&PyId___annotations__);
if (ann_dict == NULL) {
+ if (PyErr_Occurred()) {
+ goto error;
+ }
/* ...if not, create a new one */
ann_dict = PyDict_New();
if (ann_dict == NULL) {
continue;
name = PyTuple_GET_ITEM(co->co_varnames, i);
if (kwdefs != NULL) {
- PyObject *def = PyDict_GetItem(kwdefs, name);
+ PyObject *def = PyDict_GetItemWithError(kwdefs, name);
if (def) {
Py_INCREF(def);
SETLOCAL(i, def);
continue;
}
+ else if (PyErr_Occurred()) {
+ goto fail;
+ }
}
missing++;
}
PyObject *import_func, *res;
PyObject* stack[5];
- import_func = _PyDict_GetItemId(f->f_builtins, &PyId___import__);
+ import_func = _PyDict_GetItemIdWithError(f->f_builtins, &PyId___import__);
if (import_func == NULL) {
- PyErr_SetString(PyExc_ImportError, "__import__ not found");
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_ImportError, "__import__ not found");
+ }
return NULL;
}
PyObject *names = f->f_code->co_names;
PyObject *name = GETITEM(names, oparg);
PyObject *locals = f->f_locals;
- if (locals && PyDict_CheckExact(locals) &&
- PyDict_GetItem(locals, name) == v) {
- if (PyDict_DelItem(locals, name) != 0) {
- PyErr_Clear();
+ if (locals && PyDict_CheckExact(locals)) {
+ PyObject *w = PyDict_GetItemWithError(locals, name);
+ if ((w == v && PyDict_DelItem(locals, name) != 0) ||
+ (w == NULL && PyErr_Occurred()))
+ {
+ Py_DECREF(v);
+ return NULL;
}
}
break;
PyUnicode_InternInPlace(&v);
/* First, try to lookup the name in the registry dictionary */
- result = PyDict_GetItem(interp->codec_search_cache, v);
+ result = PyDict_GetItemWithError(interp->codec_search_cache, v);
if (result != NULL) {
Py_INCREF(result);
Py_DECREF(v);
return result;
}
+ else if (PyErr_Occurred()) {
+ Py_DECREF(v);
+ return NULL;
+ }
/* Next, scan the search functions in order of registration */
args = PyTuple_New(1);
if (name==NULL)
name = "strict";
- handler = PyDict_GetItemString(interp->codec_error_registry, name);
- if (!handler)
- PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name);
- else
+ handler = _PyDict_GetItemStringWithError(interp->codec_error_registry, name);
+ if (handler) {
Py_INCREF(handler);
+ }
+ else if (!PyErr_Occurred()) {
+ PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name);
+ }
return handler;
}
PyObject *
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
{
+ _Py_IDENTIFIER(__module__);
const char *dot;
PyObject *modulename = NULL;
PyObject *classname = NULL;
if (dict == NULL)
goto failure;
}
- if (PyDict_GetItemString(dict, "__module__") == NULL) {
+ if (_PyDict_GetItemIdWithError(dict, &PyId___module__) == NULL) {
+ if (PyErr_Occurred()) {
+ goto failure;
+ }
modulename = PyUnicode_FromStringAndSize(name,
(Py_ssize_t)(dot-name));
if (modulename == NULL)
goto failure;
- if (PyDict_SetItemString(dict, "__module__", modulename) != 0)
+ if (_PyDict_SetItemId(dict, &PyId___module__, modulename) != 0)
goto failure;
}
if (PyTuple_Check(base)) {
current_arg = PyTuple_GET_ITEM(args, i);
}
else if (nkwargs && i >= pos) {
- current_arg = PyDict_GetItemString(kwargs, kwlist[i]);
- if (current_arg)
+ current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
+ if (current_arg) {
--nkwargs;
+ }
+ else if (PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
}
else {
current_arg = NULL;
Py_ssize_t j;
/* make sure there are no arguments given by name and position */
for (i = pos; i < nargs; i++) {
- current_arg = PyDict_GetItemString(kwargs, kwlist[i]);
+ current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
if (current_arg) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
kwlist[i], i+1);
return cleanreturn(0, &freelist);
}
+ else if (PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
}
/* make sure there are no extraneous keyword arguments */
j = 0;
}
static PyObject*
-find_keyword(PyObject *kwargs, PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
+find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
{
Py_ssize_t i, nkwargs;
- if (kwargs != NULL) {
- return PyDict_GetItem(kwargs, key);
- }
nkwargs = PyTuple_GET_SIZE(kwnames);
for (i=0; i < nkwargs; i++) {
PyObject *kwname = PyTuple_GET_ITEM(kwnames, i);
}
else if (nkwargs && i >= pos) {
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
- current_arg = find_keyword(kwargs, kwnames, kwstack, keyword);
- if (current_arg)
+ if (kwargs != NULL) {
+ current_arg = PyDict_GetItemWithError(kwargs, keyword);
+ if (!current_arg && PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
+ }
+ else {
+ current_arg = find_keyword(kwnames, kwstack, keyword);
+ }
+ if (current_arg) {
--nkwargs;
+ }
}
else {
current_arg = NULL;
/* make sure there are no arguments given by name and position */
for (i = pos; i < nargs; i++) {
keyword = PyTuple_GET_ITEM(kwtuple, i - pos);
- current_arg = find_keyword(kwargs, kwnames, kwstack, keyword);
+ if (kwargs != NULL) {
+ current_arg = PyDict_GetItemWithError(kwargs, keyword);
+ if (!current_arg && PyErr_Occurred()) {
+ return cleanreturn(0, &freelist);
+ }
+ }
+ else {
+ current_arg = find_keyword(kwnames, kwstack, keyword);
+ }
if (current_arg) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
for (p = sys_files; *p != NULL; p+=2) {
if (Py_VerboseFlag)
PySys_WriteStderr("# restore sys.%s\n", *p);
- value = PyDict_GetItemString(interp->sysdict, *(p+1));
- if (value == NULL)
+ value = _PyDict_GetItemStringWithError(interp->sysdict, *(p+1));
+ if (value == NULL) {
+ if (PyErr_Occurred()) {
+ PyErr_WriteUnraisable(NULL);
+ }
value = Py_None;
+ }
if (PyDict_SetItemString(interp->sysdict, *p, value) < 0) {
PyErr_WriteUnraisable(NULL);
}
key = PyTuple_Pack(2, filename, name);
if (key == NULL)
return NULL;
- def = (PyModuleDef *)PyDict_GetItem(extensions, key);
+ def = (PyModuleDef *)PyDict_GetItemWithError(extensions, key);
Py_DECREF(key);
if (def == NULL)
return NULL;
static PyObject *
module_dict_for_exec(PyObject *name)
{
+ _Py_IDENTIFIER(__builtins__);
PyObject *m, *d = NULL;
m = PyImport_AddModuleObject(name);
/* If the module is being reloaded, we get the old module back
and re-use its dict to exec the new code. */
d = PyModule_GetDict(m);
- if (PyDict_GetItemString(d, "__builtins__") == NULL) {
- if (PyDict_SetItemString(d, "__builtins__",
- PyEval_GetBuiltins()) != 0) {
+ if (_PyDict_GetItemIdWithError(d, &PyId___builtins__) == NULL) {
+ if (PyErr_Occurred() ||
+ _PyDict_SetItemId(d, &PyId___builtins__,
+ PyEval_GetBuiltins()) != 0)
+ {
remove_module(name);
return NULL;
}
if (nhooks < 0)
return NULL; /* Shouldn't happen */
- importer = PyDict_GetItem(path_importer_cache, p);
- if (importer != NULL)
+ importer = PyDict_GetItemWithError(path_importer_cache, p);
+ if (importer != NULL || PyErr_Occurred())
return importer;
/* set path_importer_cache[p] to None to avoid recursion */
PyErr_SetString(PyExc_TypeError, "globals must be a dict");
goto error;
}
- package = _PyDict_GetItemId(globals, &PyId___package__);
+ package = _PyDict_GetItemIdWithError(globals, &PyId___package__);
if (package == Py_None) {
package = NULL;
}
- spec = _PyDict_GetItemId(globals, &PyId___spec__);
+ else if (package == NULL && PyErr_Occurred()) {
+ goto error;
+ }
+ spec = _PyDict_GetItemIdWithError(globals, &PyId___spec__);
+ if (spec == NULL && PyErr_Occurred()) {
+ goto error;
+ }
if (package != NULL) {
Py_INCREF(package);
goto error;
}
- package = _PyDict_GetItemId(globals, &PyId___name__);
+ package = _PyDict_GetItemIdWithError(globals, &PyId___name__);
if (package == NULL) {
- PyErr_SetString(PyExc_KeyError, "'__name__' not in globals");
+ if (!PyErr_Occurred()) {
+ PyErr_SetString(PyExc_KeyError, "'__name__' not in globals");
+ }
goto error;
}
goto error;
}
- if (_PyDict_GetItemId(globals, &PyId___path__) == NULL) {
+ if (_PyDict_GetItemIdWithError(globals, &PyId___path__) == NULL) {
Py_ssize_t dot;
- if (PyUnicode_READY(package) < 0) {
+ if (PyErr_Occurred() || PyUnicode_READY(package) < 0) {
goto error;
}
k = PyLong_FromVoidPtr(key);
if (k == NULL)
return NULL;
- v = PyDict_GetItem(st->st_blocks, k);
+ v = PyDict_GetItemWithError(st->st_blocks, k);
if (v) {
assert(PySTEntry_Check(v));
Py_INCREF(v);
}
- else {
+ else if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_KeyError,
"unknown symbol table entry");
}
}
while ((name = PyIter_Next(itr))) {
- v = PyDict_GetItem(symbols, name);
+ v = PyDict_GetItemWithError(symbols, name);
/* Handle symbol that already exists in this scope */
if (v) {
Py_DECREF(name);
continue;
}
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
/* Handle global symbol */
if (bound && !PySet_Contains(bound, name)) {
Py_DECREF(name);
if (!mangled)
return 0;
dict = ste->ste_symbols;
- if ((o = PyDict_GetItem(dict, mangled))) {
+ if ((o = PyDict_GetItemWithError(dict, mangled))) {
val = PyLong_AS_LONG(o);
if ((flag & DEF_PARAM) && (val & DEF_PARAM)) {
/* Is it better to use 'mangled' or 'name' here? */
goto error;
}
val |= flag;
- } else
+ }
+ else if (PyErr_Occurred()) {
+ goto error;
+ }
+ else {
val = flag;
+ }
o = PyLong_FromLong(val);
if (o == NULL)
goto error;