}
-static void _testembed_Py_InitializeFromConfig(void)
+static void _testembed_initialize(void)
{
PyConfig config;
_PyConfig_InitCompatConfig(&config);
init_from_config_clear(&config);
}
-static void _testembed_Py_Initialize(void)
-{
- Py_SetProgramName(PROGRAM_NAME);
- Py_Initialize();
-}
-
static int test_import_in_subinterpreters(void)
{
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
PyThreadState_Swap(Py_NewInterpreter());
return PyRun_SimpleString("import readline"); // gh-124160
}
for (int i=1; i <= INIT_LOOPS; i++) {
printf("--- Pass %d ---\n", i);
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
mainstate = PyThreadState_Get();
PyEval_ReleaseThread(mainstate);
code = main_argv[i+2];
}
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
int err = PyRun_SimpleString(code);
Py_Finalize();
if (err) {
fprintf(stderr, "--- Loop #%d ---\n", i);
fflush(stderr);
- _testembed_Py_Initialize();
+ _testembed_initialize();
Py_Finalize();
printf("Finalized\n"); // Give test_embed some output to check
}
/* the test doesn't support custom memory allocators */
putenv("PYTHONMALLOC=");
- /* Leading "./" ensures getpath.c can still find the standard library */
- _Py_EMBED_PREINIT_CHECK("Checking Py_DecodeLocale\n");
- wchar_t *program = Py_DecodeLocale("./spam", NULL);
- if (program == NULL) {
- fprintf(stderr, "Fatal error: cannot decode program name\n");
- return 1;
- }
- _Py_EMBED_PREINIT_CHECK("Checking Py_SetProgramName\n");
- Py_SetProgramName(program);
-
- _Py_EMBED_PREINIT_CHECK("Checking !Py_IsInitialized pre-initialization\n");
- if (Py_IsInitialized()) {
- fprintf(stderr, "Fatal error: initialized before initialization!\n");
- return 1;
- }
-
_Py_EMBED_PREINIT_CHECK("Initializing interpreter\n");
- Py_Initialize();
+ _testembed_initialize();
_Py_EMBED_PREINIT_CHECK("Checking Py_IsInitialized post-initialization\n");
if (!Py_IsInitialized()) {
fprintf(stderr, "Fatal error: still initialized after finalization!\n");
return 1;
}
-
- _Py_EMBED_PREINIT_CHECK("Freeing memory allocated by Py_DecodeLocale\n");
- PyMem_RawFree(program);
return 0;
}
dynamic_xoption = NULL;
_Py_EMBED_PREINIT_CHECK("Initializing interpreter\n");
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
_Py_EMBED_PREINIT_CHECK("Check sys module contents\n");
PyRun_SimpleString(
"import sys; "
return 1;
}
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
unsigned long thrd = PyThread_start_new_thread(bpo20891_thread, &lock);
if (thrd == PYTHREAD_INVALID_THREAD_ID) {
static int test_initialize_twice(void)
{
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
/* bpo-33932: Calling Py_Initialize() twice should do nothing
* (and not crash!). */
L"print(f'Py_Main() after Py_Initialize: "
L"sys.argv={sys.argv}')"),
L"arg2"};
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
/* bpo-34008: Calling Py_Main() after Py_Initialize() must not crash */
Py_Main(Py_ARRAY_LENGTH(argv), argv);
static int test_init_initialize_config(void)
{
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
dump_config();
Py_Finalize();
return 0;
putenv("PYTHONUTF8=0");
Py_UTF8Mode = 1;
- /* Test initialization from global configuration variables (Py_xxx) */
- Py_SetProgramName(L"./globalvar");
-
/* Py_IsolatedFlag is not tested */
Py_NoSiteFlag = 1;
Py_BytesWarningFlag = 1;
/* FIXME: test Py_LegacyWindowsFSEncodingFlag */
/* FIXME: test Py_LegacyWindowsStdioFlag */
- Py_Initialize();
+ _testembed_initialize();
dump_config();
Py_Finalize();
return 0;
putenv("PYTHONPYCACHEPREFIX=env_pycache_prefix");
config_set_string(&config, &config.pycache_prefix, L"conf_pycache_prefix");
- Py_SetProgramName(L"./globalvar");
config_set_string(&config, &config.program_name, L"./conf_program_name");
wchar_t* argv[] = {
/* Test initialization from environment variables */
Py_IgnoreEnvironmentFlag = 0;
set_all_env_vars();
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
dump_config();
Py_Finalize();
return 0;
/* Test initialization from environment variables */
Py_IgnoreEnvironmentFlag = 0;
set_all_env_vars_dev_mode();
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
dump_config();
Py_Finalize();
return 0;
#else
putenv("PYTHONMALLOC=mimalloc");
#endif
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
dump_config();
Py_Finalize();
return 0;
}
Py_IgnoreEnvironmentFlag = 0;
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
result = 0;
PyObject *r = PyFile_OpenCode("$$test-filename");
Py_IgnoreEnvironmentFlag = 0;
PySys_AddAuditHook(_audit_hook, &sawSet);
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
if (PySys_Audit("_testembed.raise", NULL) == 0) {
printf("No error raised");
// we need at least one hook, otherwise code checking for
// PySys_AuditTuple() is skipped.
PySys_AddAuditHook(_audit_hook, &sawSet);
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
ASSERT(!PyErr_Occurred(), 0);
{
Py_IgnoreEnvironmentFlag = 0;
PySys_AddAuditHook(_audit_subinterpreter_hook, NULL);
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
Py_NewInterpreter();
Py_NewInterpreter();
};
// Initialize Python once without using the identifier
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
Py_Finalize();
// Now initialize Python multiple times and use the identifier.
// The first _PyUnicode_FromId() call initializes the identifier index.
for (int i=0; i<3; i++) {
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
PyObject *str1, *str2;
static int test_init_main_interpreter_settings(void)
{
- _testembed_Py_Initialize();
+ _testembed_initialize();
(void) PyRun_SimpleStringFlags(
"import _testinternalcapi, json; "
"print(json.dumps(_testinternalcapi.get_interp_settings(0)))",
static void do_init(void *unused)
{
- _testembed_Py_Initialize();
+ _testembed_initialize();
Py_Finalize();
}
static int
test_get_incomplete_frame(void)
{
- _testembed_Py_InitializeFromConfig();
+ _testembed_initialize();
PyMemAllocatorEx allocator;
wrap_allocator(&allocator);
// Force an allocation with an incomplete (generator) frame: