cpython/Programs/_testembed.c

#ifndef Py_BUILD_CORE_MODULE
#define Py_BUILD_CORE_MODULE
#endif

/* Always enable assertion (even in release mode) */
#undef NDEBUG

#include <Python.h>
#include "pycore_initconfig.h"    // _PyConfig_InitCompatConfig()
#include "pycore_runtime.h"       // _PyRuntime
#include "pycore_pythread.h"      // PyThread_start_joinable_thread()
#include "pycore_import.h"        // _PyImport_FrozenBootstrap
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>               // putenv()
#include <wchar.h>

// These functions were removed from Python 3.13 API but are still exported
// for the stable ABI. We want to test them in this program.
extern void PySys_AddWarnOption(const wchar_t *s);
extern void PySys_AddXOption(const wchar_t *s);
extern void Py_SetPath(const wchar_t *path);


int main_argc;
char **main_argv;

/*********************************************************
 * Embedded interpreter tests that need a custom exe
 *
 * Executed via Lib/test/test_embed.py
 *********************************************************/

// Use to display the usage
#define PROGRAM

/* Use path starting with "./" avoids a search along the PATH */
#define PROGRAM_NAME
#define PROGRAM_NAME_UTF8

#define INIT_LOOPS

// Ignore Py_DEPRECATED() compiler warnings: deprecated functions are
// tested on purpose here.
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS


static void error(const char *msg)
{}


static void config_set_string(PyConfig *config, wchar_t **config_str, const wchar_t *str)
{}


static void config_set_program_name(PyConfig *config)
{}


static void init_from_config_clear(PyConfig *config)
{}


static void _testembed_Py_InitializeFromConfig(void)
{}

static void _testembed_Py_Initialize(void)
{}


static int test_import_in_subinterpreters(void)
{}


/*****************************************************
 * Test repeated initialisation and subinterpreters
 *****************************************************/

static void print_subinterp(void)
{}

static int test_repeated_init_and_subinterpreters(void)
{}

#define EMBEDDED_EXT_NAME

static PyModuleDef embedded_ext =;

static PyObject*
PyInit_embedded_ext(void)
{}

/****************************************************************************
 * Call Py_Initialize()/Py_Finalize() multiple times and execute Python code
 ***************************************************************************/

// Used by bpo-46417 to test that structseq types used by the sys module are
// cleared properly and initialized again properly when Python is finalized
// multiple times.
static int test_repeated_init_exec(void)
{}

/****************************************************************************
 * Test the Py_Initialize(Ex) convenience/compatibility wrappers
 ***************************************************************************/
// This is here to help ensure there are no wrapper resource leaks (gh-96853)
static int test_repeated_simple_init(void)
{}


/*****************************************************
 * Test forcing a particular IO encoding
 *****************************************************/

static void check_stdio_details(const wchar_t *encoding, const wchar_t *errors)
{}

static int test_forced_io_encoding(void)
{}

/*********************************************************
 * Test parts of the C-API that work before initialization
 *********************************************************/

/* The pre-initialization tests tend to break by segfaulting, so explicitly
 * flushed progress messages make the broken API easier to find when they fail.
 */
#define _Py_EMBED_PREINIT_CHECK(msg)

static int test_pre_initialization_api(void)
{}


/* bpo-33042: Ensure embedding apps can predefine sys module options */
static int test_pre_initialization_sys_options(void)
{}


/* bpo-20891: Avoid race condition when initialising the GIL */
static void bpo20891_thread(void *lockp)
{}

static int test_bpo20891(void)
{}

static int test_initialize_twice(void)
{}

static int test_initialize_pymain(void)
{}


static void
dump_config(void)
{}


static int test_init_initialize_config(void)
{}


static void config_set_argv(PyConfig *config, Py_ssize_t argc, wchar_t * const *argv)
{}


static void
config_set_wide_string_list(PyConfig *config, PyWideStringList *list,
                            Py_ssize_t length, wchar_t **items)
{}


static int check_init_compat_config(int preinit)
{}


static int test_preinit_compat_config(void)
{}


static int test_init_compat_config(void)
{}


static int test_init_global_config(void)
{}


static int test_init_from_config(void)
{}


static int check_init_parse_argv(int parse_argv)
{}


static int test_init_parse_argv(void)
{}


static int test_init_dont_parse_argv(void)
{}


static void set_most_env_vars(void)
{}


static void set_all_env_vars(void)
{}


static int test_init_compat_env(void)
{}


static int test_init_python_env(void)
{}


static void set_all_env_vars_dev_mode(void)
{}


static int test_init_env_dev_mode(void)
{}


static int test_init_env_dev_mode_alloc(void)
{}


static int test_init_isolated_flag(void)
{}


/* PyPreConfig.isolated=1, PyConfig.isolated=0 */
static int test_preinit_isolated1(void)
{}


/* PyPreConfig.isolated=0, PyConfig.isolated=1 */
static int test_preinit_isolated2(void)
{}


static int test_preinit_dont_parse_argv(void)
{}


static int test_preinit_parse_argv(void)
{}




static void set_all_global_config_variables(void)
{}


static int check_preinit_isolated_config(int preinit)
{}


static int test_preinit_isolated_config(void)
{}


static int test_init_isolated_config(void)
{}


static int check_init_python_config(int preinit)
{}


static int test_preinit_python_config(void)
{}


static int test_init_python_config(void)
{}


static int test_init_dont_configure_locale(void)
{}


static int test_init_dev_mode(void)
{}

static PyObject *_open_code_hook(PyObject *path, void *data)
{}

static int test_open_code_hook(void)
{}

static int _audit_hook_clear_count =;

static int _audit_hook(const char *event, PyObject *args, void *userdata)
{}

static int _test_audit(Py_ssize_t setValue)
{}

static int test_audit(void)
{}

static int test_audit_tuple(void)
{}

static volatile int _audit_subinterpreter_interpreter_count =;

static int _audit_subinterpreter_hook(const char *event, PyObject *args, void *userdata)
{}

static int test_audit_subinterpreter(void)
{}

AuditRunCommandTest;

static int _audit_hook_run(const char *eventName, PyObject *args, void *userData)
{}

static int test_audit_run_command(void)
{}

static int test_audit_run_file(void)
{}

static int run_audit_run_test(int argc, wchar_t **argv, void *test)
{}

static int test_audit_run_interactivehook(void)
{}

static int test_audit_run_startup(void)
{}

static int test_audit_run_stdin(void)
{}

static int test_init_read_set(void)
{}


static int test_init_sys_add(void)
{}


static int test_init_setpath(void)
{}


static int test_init_setpath_config(void)
{}


static int test_init_setpythonhome(void)
{}


static int test_init_is_python_build(void)
{}


static int test_init_warnoptions(void)
{}


static int tune_config(void)
{}


static int test_init_set_config(void)
{}


static int initconfig_getint(PyInitConfig *config, const char *name)
{}


static int test_initconfig_api(void)
{}


static int test_initconfig_get_api(void)
{}


static int test_initconfig_exit(void)
{}


static PyModuleDef_Slot extension_slots[] =;

static struct PyModuleDef extension_module =;

static PyObject* init_my_test_extension(void)
{}


static int test_initconfig_module(void)
{}


static void configure_init_main(PyConfig *config)
{}


static int test_init_run_main(void)
{}


static int test_init_main(void)
{}


static int test_run_main(void)
{}


static int test_run_main_loop(void)
{}


static int test_get_argc_argv(void)
{}


static int check_use_frozen_modules(const char *rawval)
{}

static int test_init_use_frozen_modules(void)
{}


static int test_unicode_id_init(void)
{}


static int test_init_main_interpreter_settings(void)
{}

static void do_init(void *unused)
{}

static int test_init_in_background_thread(void)
{}


#ifndef MS_WINDOWS
#include "test_frozenmain.h"      // M_test_frozenmain

static int test_frozenmain(void)
{}
#endif  // !MS_WINDOWS

static int test_repeated_init_and_inittab(void)
{}

static void wrap_allocator(PyMemAllocatorEx *allocator);
static void unwrap_allocator(PyMemAllocatorEx *allocator);

static void *
malloc_wrapper(void *ctx, size_t size)
{}

static void *
calloc_wrapper(void *ctx, size_t nelem, size_t elsize)
{}

static void *
realloc_wrapper(void *ctx, void *ptr, size_t new_size)
{}

static void
free_wrapper(void *ctx, void *ptr)
{}

static void
wrap_allocator(PyMemAllocatorEx *allocator)
{}

static void
unwrap_allocator(PyMemAllocatorEx *allocator)
{}

static int
test_get_incomplete_frame(void)
{}


/* *********************************************************
 * List of test cases and the function that implements it.
 *
 * Names are compared case-sensitively with the first
 * argument. If no match is found, or no first argument was
 * provided, the names of all test cases are printed and
 * the exit code will be -1.
 *
 * The int returned from test functions is used as the exit
 * code, and test_capi treats all non-zero exit codes as a
 * failed test.
 *********************************************************/
struct TestCase
{};

static struct TestCase TestCases[] =;


int main(int argc, char *argv[])
{}