"""
Tests PyConfig_Get() and PyConfig_Set() C API (PEP 741).
"""
+import os
import sys
import sysconfig
import types
finally:
config_set(name, old_value)
+ def test_config_set_cpu_count(self):
+ config_get = _testcapi.config_get
+ config_set = _testcapi.config_set
+
+ old_value = config_get('cpu_count')
+ try:
+ config_set('cpu_count', 123)
+ self.assertEqual(os.cpu_count(), 123)
+ finally:
+ config_set('cpu_count', old_value)
+
def test_config_set_read_only(self):
# Test PyConfig_Set() on read-only options
config_set = _testcapi.config_set
for name, value in (
("allocator", 0), # PyPreConfig member
- ("cpu_count", 8),
+ ("perf_profiling", 8),
("dev_mode", True),
("filesystem_encoding", "utf-8"),
):
SPEC(base_executable, WSTR_OPT, PUBLIC, SYS_ATTR("_base_executable")),
SPEC(base_prefix, WSTR_OPT, PUBLIC, SYS_ATTR("base_prefix")),
SPEC(bytes_warning, UINT, PUBLIC, SYS_FLAG(9)),
+ SPEC(cpu_count, INT, PUBLIC, NO_SYS),
SPEC(exec_prefix, WSTR_OPT, PUBLIC, SYS_ATTR("exec_prefix")),
SPEC(executable, WSTR_OPT, PUBLIC, SYS_ATTR("executable")),
SPEC(inspect, BOOL, PUBLIC, SYS_FLAG(1)),
SPEC(check_hash_pycs_mode, WSTR, READ_ONLY, NO_SYS),
SPEC(code_debug_ranges, BOOL, READ_ONLY, NO_SYS),
SPEC(configure_c_stdio, BOOL, READ_ONLY, NO_SYS),
- SPEC(cpu_count, INT, READ_ONLY, NO_SYS),
SPEC(dev_mode, BOOL, READ_ONLY, NO_SYS), // sys.flags.dev_mode
SPEC(dump_refs, BOOL, READ_ONLY, NO_SYS),
SPEC(dump_refs_file, WSTR_OPT, READ_ONLY, NO_SYS),
}
+// Set PyConfig.ATTR integer member
+static int
+config_set_int_attr(const PyConfigSpec *spec, int value)
+{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyConfig *config = &interp->config;
+ int *member = config_get_spec_member(config, spec);
+ *member = value;
+ return 0;
+}
+
+
int
PyConfig_Set(const char *name, PyObject *value)
{
Py_UNREACHABLE();
}
-
if (spec->sys.attr != NULL) {
// Set the sys attribute, but don't set PyInterpreterState.config
// to keep the code simple.
return PySys_SetObject(spec->sys.attr, value);
}
- else if (spec->sys.flag_index >= 0 && has_int_value) {
- return config_set_sys_flag(spec, int_value);
- }
- else if (strcmp(spec->name, "int_max_str_digits") == 0 && has_int_value) {
- return _PySys_SetIntMaxStrDigits(int_value);
+ else if (has_int_value) {
+ if (spec->sys.flag_index >= 0) {
+ return config_set_sys_flag(spec, int_value);
+ }
+ else if (strcmp(spec->name, "int_max_str_digits") == 0) {
+ return _PySys_SetIntMaxStrDigits(int_value);
+ }
+ else {
+ return config_set_int_attr(spec, int_value);
+ }
}
cannot_set: