mirror of
https://github.com/python/cpython.git
synced 2025-07-20 17:55:21 +00:00
bpo-36900: Replace global conf vars with config (GH-13299)
Replace global configuration variables with core_config read from the current interpreter. Cleanup dynload_hpux.c.
This commit is contained in:
parent
3c93153f7d
commit
c96be811fa
9 changed files with 51 additions and 37 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "Python.h"
|
||||
|
||||
#include "Python-ast.h"
|
||||
#include "pycore_pystate.h" /* _PyInterpreterState_GET_UNSAFE() */
|
||||
#include "ast.h"
|
||||
#include "code.h"
|
||||
#include "symtable.h"
|
||||
|
@ -310,6 +311,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
|
|||
PyCodeObject *co = NULL;
|
||||
PyCompilerFlags local_flags;
|
||||
int merged;
|
||||
_PyCoreConfig *config = &_PyInterpreterState_GET_UNSAFE()->core_config;
|
||||
|
||||
if (!__doc__) {
|
||||
__doc__ = PyUnicode_InternFromString("__doc__");
|
||||
|
@ -338,7 +340,7 @@ PyAST_CompileObject(mod_ty mod, PyObject *filename, PyCompilerFlags *flags,
|
|||
c.c_future->ff_features = merged;
|
||||
flags->cf_flags = merged;
|
||||
c.c_flags = flags;
|
||||
c.c_optimize = (optimize == -1) ? Py_OptimizeFlag : optimize;
|
||||
c.c_optimize = (optimize == -1) ? config->optimization_level : optimize;
|
||||
c.c_nestlevel = 0;
|
||||
|
||||
if (!_PyAST_Optimize(mod, arena, c.c_optimize)) {
|
||||
|
|
|
@ -19,48 +19,47 @@ dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
|
|||
const char *shortname,
|
||||
const char *pathname, FILE *fp)
|
||||
{
|
||||
dl_funcptr p;
|
||||
shl_t lib;
|
||||
int flags;
|
||||
char funcname[258];
|
||||
|
||||
flags = BIND_FIRST | BIND_DEFERRED;
|
||||
if (Py_VerboseFlag) {
|
||||
int flags = BIND_FIRST | BIND_DEFERRED;
|
||||
int verbose = _PyInterpreterState_GET_UNSAFE()->core_config.verbose;
|
||||
if (verbose) {
|
||||
flags = BIND_FIRST | BIND_IMMEDIATE |
|
||||
BIND_NONFATAL | BIND_VERBOSE;
|
||||
printf("shl_load %s\n",pathname);
|
||||
}
|
||||
lib = shl_load(pathname, flags, 0);
|
||||
|
||||
shl_t lib = shl_load(pathname, flags, 0);
|
||||
/* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */
|
||||
if (lib == NULL) {
|
||||
char buf[256];
|
||||
PyObject *pathname_ob = NULL;
|
||||
PyObject *buf_ob = NULL;
|
||||
PyObject *shortname_ob = NULL;
|
||||
|
||||
if (Py_VerboseFlag)
|
||||
if (verbose) {
|
||||
perror(pathname);
|
||||
}
|
||||
char buf[256];
|
||||
PyOS_snprintf(buf, sizeof(buf), "Failed to load %.200s",
|
||||
pathname);
|
||||
buf_ob = PyUnicode_FromString(buf);
|
||||
shortname_ob = PyUnicode_FromString(shortname);
|
||||
pathname_ob = PyUnicode_FromString(pathname);
|
||||
PyObject *buf_ob = PyUnicode_FromString(buf);
|
||||
PyObject *shortname_ob = PyUnicode_FromString(shortname);
|
||||
PyObject *pathname_ob = PyUnicode_FromString(pathname);
|
||||
PyErr_SetImportError(buf_ob, shortname_ob, pathname_ob);
|
||||
Py_DECREF(buf_ob);
|
||||
Py_DECREF(shortname_ob);
|
||||
Py_DECREF(pathname_ob);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char funcname[258];
|
||||
PyOS_snprintf(funcname, sizeof(funcname), FUNCNAME_PATTERN,
|
||||
prefix, shortname);
|
||||
if (Py_VerboseFlag)
|
||||
if (verbose) {
|
||||
printf("shl_findsym %s\n", funcname);
|
||||
}
|
||||
|
||||
dl_funcptr p;
|
||||
if (shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p) == -1) {
|
||||
shl_unload(lib);
|
||||
p = NULL;
|
||||
}
|
||||
if (p == NULL && Py_VerboseFlag)
|
||||
if (p == NULL && verbose) {
|
||||
perror(funcname);
|
||||
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -150,12 +150,13 @@ init_importlib(PyInterpreterState *interp, PyObject *sysmod)
|
|||
PyObject *importlib;
|
||||
PyObject *impmod;
|
||||
PyObject *value;
|
||||
int verbose = interp->core_config.verbose;
|
||||
|
||||
/* Import _importlib through its frozen version, _frozen_importlib. */
|
||||
if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) {
|
||||
return _Py_INIT_ERR("can't import _frozen_importlib");
|
||||
}
|
||||
else if (Py_VerboseFlag) {
|
||||
else if (verbose) {
|
||||
PySys_FormatStderr("import _frozen_importlib # frozen\n");
|
||||
}
|
||||
importlib = PyImport_AddModule("_frozen_importlib");
|
||||
|
@ -175,7 +176,7 @@ init_importlib(PyInterpreterState *interp, PyObject *sysmod)
|
|||
if (impmod == NULL) {
|
||||
return _Py_INIT_ERR("can't import _imp");
|
||||
}
|
||||
else if (Py_VerboseFlag) {
|
||||
else if (verbose) {
|
||||
PySys_FormatStderr("import _imp # builtin\n");
|
||||
}
|
||||
if (_PyImport_SetModuleString("_imp", impmod) < 0) {
|
||||
|
|
|
@ -591,10 +591,12 @@ handle_system_exit(void)
|
|||
PyObject *exception, *value, *tb;
|
||||
int exitcode = 0;
|
||||
|
||||
if (Py_InspectFlag)
|
||||
int inspect = _PyInterpreterState_GET_UNSAFE()->core_config.inspect;
|
||||
if (inspect) {
|
||||
/* Don't exit if -i flag was given. This flag is set to 0
|
||||
* when entering interactive mode for inspecting. */
|
||||
return;
|
||||
}
|
||||
|
||||
PyErr_Fetch(&exception, &value, &tb);
|
||||
fflush(stdout);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue