gh-108314: Add PyDict_ContainsString() function (#108323)
This commit is contained in:
@@ -413,10 +413,11 @@ _PyRun_SimpleFileObject(FILE *fp, PyObject *filename, int closeit,
|
||||
PyObject *dict = PyModule_GetDict(main_module); // borrowed ref
|
||||
|
||||
int set_file_name = 0;
|
||||
if (_PyDict_GetItemStringWithError(dict, "__file__") == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
goto done;
|
||||
}
|
||||
int has_file = PyDict_ContainsString(dict, "__file__");
|
||||
if (has_file < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (!has_file) {
|
||||
if (PyDict_SetItemString(dict, "__file__", filename) < 0) {
|
||||
goto done;
|
||||
}
|
||||
@@ -1713,13 +1714,17 @@ run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, Py
|
||||
_PyRuntime.signals.unhandled_keyboard_interrupt = 0;
|
||||
|
||||
/* Set globals['__builtins__'] if it doesn't exist */
|
||||
if (globals != NULL && _PyDict_GetItemStringWithError(globals, "__builtins__") == NULL) {
|
||||
if (PyErr_Occurred() ||
|
||||
PyDict_SetItemString(globals, "__builtins__",
|
||||
tstate->interp->builtins) < 0)
|
||||
{
|
||||
if (globals != NULL) {
|
||||
int has_builtins = PyDict_ContainsString(globals, "__builtins__");
|
||||
if (has_builtins < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (!has_builtins) {
|
||||
if (PyDict_SetItemString(globals, "__builtins__",
|
||||
tstate->interp->builtins) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v = PyEval_EvalCode((PyObject*)co, globals, locals);
|
||||
|
||||
Reference in New Issue
Block a user