EMPTY_STRING_SIZE = sys.getsizeof(b'')
+INVALID_NFRAME = (-1, 2**30)
def get_frames(nframe, lineno_delta):
stdout = stdout.rstrip()
self.assertEqual(stdout, b'False')
+ def test_env_var_disabled(self):
+ # tracing at startup
+ code = 'import tracemalloc; print(tracemalloc.is_tracing())'
+ ok, stdout, stderr = assert_python_ok('-c', code, PYTHONTRACEMALLOC='0')
+ stdout = stdout.rstrip()
+ self.assertEqual(stdout, b'False')
+
def test_env_var_enabled_at_startup(self):
# tracing at startup
code = 'import tracemalloc; print(tracemalloc.is_tracing())'
def test_env_var_invalid(self):
- for nframe in (-1, 0, 2**30):
+ for nframe in INVALID_NFRAME:
with self.subTest(nframe=nframe):
self.check_env_var_invalid(nframe)
self.fail(f"unexpeced output: {stderr!a}")
def test_sys_xoptions_invalid(self):
- for nframe in (-1, 0, 2**30):
+ for nframe in INVALID_NFRAME:
with self.subTest(nframe=nframe):
self.check_sys_xoptions_invalid(nframe)
int nframe;
int valid;
+ if (config->tracemalloc >= 0) {
+ return _Py_INIT_OK();
+ }
+
const char *env = config_get_env_var(config, "PYTHONTRACEMALLOC");
if (env) {
if (!pymain_str_to_int(env, &nframe)) {
- valid = (nframe >= 1);
+ valid = (nframe >= 0);
}
else {
valid = 0;
const wchar_t *sep = wcschr(xoption, L'=');
if (sep) {
if (!pymain_wstr_to_int(sep + 1, &nframe)) {
- valid = (nframe >= 1);
+ valid = (nframe >= 0);
}
else {
valid = 0;
config_init_locale(config);
- /* Signal handlers are installed by default */
- if (config->install_signal_handlers < 0) {
- config->install_signal_handlers = 1;
- }
-
if (config->_install_importlib) {
err = _PyCoreConfig_InitPathConfig(config);
if (_Py_INIT_FAILED(err)) {
return err;
}
}
+
+ /* default values */
+ if (config->tracemalloc < 0) {
+ config->tracemalloc = 0;
+ }
+ if (config->install_signal_handlers < 0) {
+ /* Signal handlers are installed by default */
+ config->install_signal_handlers = 1;
+ }
+
return _Py_INIT_OK();
}