◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
20 changes: 12 additions & 8 deletions Include/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);


typedef struct {
int ignore_environment;
int use_hash_seed;
unsigned long hash_seed;
int _disable_importlib; /* Needed by freeze_importlib */
char *allocator;
int faulthandler;
int tracemalloc; /* Number of saved frames, 0=don't trace */
int importtime; /* -X importtime */
int dev_mode; /* -X dev */
} _PyCoreConfig;

#define _PyCoreConfig_INIT \
Expand All @@ -42,10 +44,12 @@ typedef struct {
.hash_seed = 0, \
._disable_importlib = 0, \
.allocator = NULL, \
.faulthandler = 0, \
.tracemalloc = 0, \
.importtime = 0, \
.dev_mode = 0}

/* Placeholders while working on the new configuration API
*
Expand Down
10 changes: 9 additions & 1 deletion Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1384,14 +1384,22 @@ pymain_parse_envvars(_PyMain *pymain)
}
core_config->allocator = Py_GETENV("PYTHONMALLOC");

/* More complex options: env var and/or -X option */
if (pymain_get_env_var("PYTHONFAULTHANDLER")
|| pymain_get_xoption(pymain, L"faulthandler")) {
core_config->faulthandler = 1;
}
if (pymain_get_env_var("PYTHONPROFILEIMPORTTIME")
|| pymain_get_xoption(pymain, L"importtime")) {
core_config->importtime = 1;
}
if (pymain_init_tracemalloc(pymain) < 0) {
return -1;
Expand Down
11 changes: 3 additions & 8 deletions Objects/tupleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ static Py_ssize_t count_tracked = 0;
static void
show_track(void)
{
PyObject *xoptions, *value;
_Py_IDENTIFIER(showalloccount);

xoptions = PySys_GetXOptions();
if (xoptions == NULL)
return;
value = _PyDict_GetItemId(xoptions, &PyId_showalloccount);
if (value != Py_True)
return;

fprintf(stderr, "Tuples created: %" PY_FORMAT_SIZE_T "d\n",
count_tracked + count_untracked);
Expand Down
7 changes: 3 additions & 4 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,8 +1674,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}
}
else {
/* 1 -- true, 0 -- false, -1 -- not initialized */
int importtime = interp->core_config.importtime;
static int import_level;
static _PyTime_t accumulated;

Expand All @@ -1686,7 +1685,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
* Anyway, importlib._find_and_load is much slower than
* _PyDict_GetItemIdWithError().
*/
if (importtime) {
static int header = 1;
if (header) {
fputs("import time: self [us] | cumulative | imported package\n",
Expand All @@ -1712,7 +1711,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
PyDTrace_IMPORT_FIND_LOAD_DONE(PyUnicode_AsUTF8(abs_name),
mod != NULL);

if (importtime) {
_PyTime_t cum = _PyTime_GetPerfCounter() - t1;

import_level--;
Expand Down
6 changes: 5 additions & 1 deletion Python/pythonrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
int ret, err;
PyCompilerFlags local_flags;
int nomem_count = 0;

filename = PyUnicode_DecodeFSDefault(filename_str);
if (filename == NULL) {
Expand Down @@ -134,8 +137,9 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
nomem_count = 0;
}
#ifdef Py_REF_DEBUG
if (_PyDebug_XOptionShowRefCount() == Py_True)
_PyDebug_PrintTotalRefs();
#endif
} while (ret != E_EOF);
Py_DECREF(filename);
Expand Down
Toggle all file notes Toggle all file annotations