diff options
author | Brett Cannon <brett@python.org> | 2013-05-04 18:11:30 -0400 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2013-05-04 18:11:30 -0400 |
commit | 1028c31378f3db5d176647d92e852b855a623525 (patch) | |
tree | 9c168bc0cdc45b2ed88069b10c672c10a48f2267 /Python/pythonrun.c | |
parent | ffa2ce77300628e4a4ddbacd76e2119adee0f273 (diff) | |
parent | 53f2354eb1979158ae3124ea75c76ff4b84280c4 (diff) | |
download | cpython-1028c31378f3db5d176647d92e852b855a623525.tar.gz |
merge w/ 3.3
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ddda4a4cd0..cf2ecf1cb1 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -35,12 +35,30 @@ #define PATH_MAX MAXPATHLEN #endif +#ifdef Py_REF_DEBUG +static +void _print_total_refs(void) { + PyObject *xoptions, *key, *value; + xoptions = PySys_GetXOptions(); + if (xoptions == NULL) + return; + key = PyUnicode_FromString("showrefcount"); + if (key == NULL) + return; + value = PyDict_GetItem(xoptions, key); + Py_DECREF(key); + if (value == Py_True) + fprintf(stderr, + "[%" PY_FORMAT_SIZE_T "d refs, " + "%" PY_FORMAT_SIZE_T "d blocks]\n", + _Py_GetRefTotal(), _Py_GetAllocatedBlocks()); +} +#endif + #ifndef Py_REF_DEBUG #define PRINT_TOTAL_REFS() #else /* Py_REF_DEBUG */ -#define PRINT_TOTAL_REFS() fprintf(stderr, \ - "[%" PY_FORMAT_SIZE_T "d refs]\n", \ - _Py_GetRefTotal()) +#define PRINT_TOTAL_REFS() _print_total_refs() #endif #ifdef __cplusplus @@ -825,7 +843,7 @@ Py_GetPythonHome(void) static void initmain(PyInterpreterState *interp) { - PyObject *m, *d; + PyObject *m, *d, *loader; m = PyImport_AddModule("__main__"); if (m == NULL) Py_FatalError("can't create __main__ module"); @@ -846,7 +864,8 @@ initmain(PyInterpreterState *interp) * be set if __main__ gets further initialized later in the startup * process. */ - if (PyDict_GetItemString(d, "__loader__") == NULL) { + loader = PyDict_GetItemString(d, "__loader__"); + if (loader == NULL || loader == Py_None) { PyObject *loader = PyObject_GetAttrString(interp->importlib, "BuiltinImporter"); if (loader == NULL) { |