cpython/Modules/_testinternalcapi.c

/*
 * C Extension module to test Python internal C APIs (Include/internal).
 */

#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE
#endif

/* Always enable assertions */
#undef NDEBUG

#include "Python.h"
#include "pycore_backoff.h"       // JUMP_BACKWARD_INITIAL_VALUE
#include "pycore_bitutils.h"      // _Py_bswap32()
#include "pycore_bytesobject.h"   // _PyBytes_Find()
#include "pycore_ceval.h"         // _PyEval_AddPendingCall()
#include "pycore_code.h"          // _PyCode_GetTLBCFast()
#include "pycore_compile.h"       // _PyCompile_CodeGen()
#include "pycore_context.h"       // _PyContext_NewHamtForTests()
#include "pycore_dict.h"          // _PyManagedDictPointer_GetValues()
#include "pycore_fileutils.h"     // _Py_normpath()
#include "pycore_flowgraph.h"     // _PyCompile_OptimizeCfg()
#include "pycore_frame.h"         // _PyInterpreterFrame
#include "pycore_gc.h"            // PyGC_Head
#include "pycore_hashtable.h"     // _Py_hashtable_new()
#include "pycore_initconfig.h"    // _Py_GetConfigsAsDict()
#include "pycore_instruction_sequence.h"  // _PyInstructionSequence_New()
#include "pycore_interp.h"        // _PyInterpreterState_GetConfigCopy()
#include "pycore_long.h"          // _PyLong_Sign()
#include "pycore_object.h"        // _PyObject_IsFreed()
#include "pycore_optimizer.h"     // _Py_UopsSymbol, etc.
#include "pycore_pathconfig.h"    // _PyPathConfig_ClearGlobal()
#include "pycore_pyerrors.h"      // _PyErr_ChainExceptions1()
#include "pycore_pylifecycle.h"   // _PyInterpreterConfig_AsDict()
#include "pycore_pystate.h"       // _PyThreadState_GET()

#include "clinic/_testinternalcapi.c.h"

// Include test definitions from _testinternalcapi/
#include "_testinternalcapi/parts.h"


#define MODULE_NAME


static PyObject *
_get_current_module(void)
{}


/* module state *************************************************************/

module_state;

static inline module_state *
get_module_state(PyObject *mod)
{}

static int
traverse_module_state(module_state *state, visitproc visit, void *arg)
{}

static int
clear_module_state(module_state *state)
{}


/* module functions *********************************************************/

/*[clinic input]
module _testinternalcapi
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=7bb583d8c9eb9a78]*/
static PyObject *
get_configs(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject*
get_recursion_depth(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject*
get_c_recursion_remaining(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject*
test_bswap(PyObject *self, PyObject *Py_UNUSED(args))
{}


static int
check_popcount(uint32_t x, int expected)
{}


static PyObject*
test_popcount(PyObject *self, PyObject *Py_UNUSED(args))
{}


static int
check_bit_length(unsigned long x, int expected)
{}


static PyObject*
test_bit_length(PyObject *self, PyObject *Py_UNUSED(args))
{}


#define TO_PTR(ch)
#define FROM_PTR(ptr)
#define VALUE(key)

static Py_uhash_t
hash_char(const void *key)
{}


static int
hashtable_cb(_Py_hashtable_t *table,
             const void *key_ptr, const void *value_ptr,
             void *user_data)
{}


static PyObject*
test_hashtable(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject *
test_get_config(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
{}


static PyObject *
test_set_config(PyObject *Py_UNUSED(self), PyObject *dict)
{}


static PyObject *
test_reset_path_config(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(arg))
{}


static int
check_edit_cost(const char *a, const char *b, Py_ssize_t expected)
{}

static PyObject *
test_edit_cost(PyObject *self, PyObject *Py_UNUSED(args))
{}


static int
check_bytes_find(const char *haystack0, const char *needle0,
                 int offset, Py_ssize_t expected)
{}

static int
check_bytes_find_large(Py_ssize_t len_haystack, Py_ssize_t len_needle,
                       const char *needle)
{}

static PyObject *
test_bytes_find(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject *
normalize_path(PyObject *self, PyObject *filename)
{}

static PyObject *
get_getpath_codeobject(PyObject *self, PyObject *Py_UNUSED(args)) {}


static PyObject *
encode_locale_ex(PyObject *self, PyObject *args)
{}


static PyObject *
decode_locale_ex(PyObject *self, PyObject *args)
{}

static PyObject *
set_eval_frame_default(PyObject *self, PyObject *Py_UNUSED(args))
{}

static PyObject *
record_eval(PyThreadState *tstate, struct _PyInterpreterFrame *f, int exc)
{}


static PyObject *
set_eval_frame_record(PyObject *self, PyObject *list)
{}

/*[clinic input]

_testinternalcapi.compiler_cleandoc -> object

    doc: unicode

C implementation of inspect.cleandoc().
[clinic start generated code]*/

static PyObject *
_testinternalcapi_compiler_cleandoc_impl(PyObject *module, PyObject *doc)
/*[clinic end generated code: output=2dd203a80feff5bc input=2de03fab931d9cdc]*/
{}

/*[clinic input]

_testinternalcapi.new_instruction_sequence -> object

Return a new, empty InstructionSequence.
[clinic start generated code]*/

static PyObject *
_testinternalcapi_new_instruction_sequence_impl(PyObject *module)
/*[clinic end generated code: output=ea4243fddb9057fd input=1dec2591b173be83]*/
{}

/*[clinic input]

_testinternalcapi.compiler_codegen -> object

  ast: object
  filename: object
  optimize: int
  compile_mode: int = 0

Apply compiler code generation to an AST.
[clinic start generated code]*/

static PyObject *
_testinternalcapi_compiler_codegen_impl(PyObject *module, PyObject *ast,
                                        PyObject *filename, int optimize,
                                        int compile_mode)
/*[clinic end generated code: output=40a68f6e13951cc8 input=a0e00784f1517cd7]*/
{}


/*[clinic input]

_testinternalcapi.optimize_cfg -> object

  instructions: object
  consts: object
  nlocals: int

Apply compiler optimizations to an instruction list.
[clinic start generated code]*/

static PyObject *
_testinternalcapi_optimize_cfg_impl(PyObject *module, PyObject *instructions,
                                    PyObject *consts, int nlocals)
/*[clinic end generated code: output=57c53c3a3dfd1df0 input=6a96d1926d58d7e5]*/
{}

static int
get_nonnegative_int_from_dict(PyObject *dict, const char *key) {}

/*[clinic input]

_testinternalcapi.assemble_code_object -> object

  filename: object
  instructions: object
  metadata: object

Create a code object for the given instructions.
[clinic start generated code]*/

static PyObject *
_testinternalcapi_assemble_code_object_impl(PyObject *module,
                                            PyObject *filename,
                                            PyObject *instructions,
                                            PyObject *metadata)
/*[clinic end generated code: output=38003dc16a930f48 input=e713ad77f08fb3a8]*/

{}


// Maybe this could be replaced by get_interpreter_config()?
static PyObject *
get_interp_settings(PyObject *self, PyObject *args)
{}


static PyObject *
clear_extension(PyObject *self, PyObject *args)
{}

static PyObject *
write_perf_map_entry(PyObject *self, PyObject *args)
{}

static PyObject *
perf_map_state_teardown(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
{}

static PyObject *
iframe_getcode(PyObject *self, PyObject *frame)
{}

static PyObject *
iframe_getline(PyObject *self, PyObject *frame)
{}

static PyObject *
iframe_getlasti(PyObject *self, PyObject *frame)
{}

static PyObject *
get_co_framesize(PyObject *self, PyObject *arg)
{}

#ifdef _Py_TIER2

static PyObject *
new_counter_optimizer(PyObject *self, PyObject *arg)
{
    return _PyOptimizer_NewCounter();
}

static PyObject *
new_uop_optimizer(PyObject *self, PyObject *arg)
{
    return _PyOptimizer_NewUOpOptimizer();
}

static PyObject *
set_optimizer(PyObject *self, PyObject *opt)
{
    if (opt == Py_None) {
        opt = NULL;
    }
    if (_Py_SetTier2Optimizer((_PyOptimizerObject*)opt) < 0) {
        return NULL;
    }
    Py_RETURN_NONE;
}

static PyObject *
get_optimizer(PyObject *self, PyObject *Py_UNUSED(ignored))
{
    PyObject *opt = NULL;
#ifdef _Py_TIER2
    opt = (PyObject *)_Py_GetOptimizer();
#endif
    if (opt == NULL) {
        Py_RETURN_NONE;
    }
    return opt;
}

static PyObject *
add_executor_dependency(PyObject *self, PyObject *args)
{
    PyObject *exec;
    PyObject *obj;
    if (!PyArg_ParseTuple(args, "OO", &exec, &obj)) {
        return NULL;
    }
    /* No way to tell in general if exec is an executor, so we only accept
     * counting_executor */
    if (strcmp(Py_TYPE(exec)->tp_name, "counting_executor")) {
        PyErr_SetString(PyExc_TypeError, "argument must be a counting_executor");
        return NULL;
    }
    _Py_Executor_DependsOn((_PyExecutorObject *)exec, obj);
    Py_RETURN_NONE;
}

static PyObject *
invalidate_executors(PyObject *self, PyObject *obj)
{
    PyInterpreterState *interp = PyInterpreterState_Get();
    _Py_Executors_InvalidateDependency(interp, obj, 1);
    Py_RETURN_NONE;
}

#endif

static int _pending_callback(void *arg)
{}

/* The following requests n callbacks to _pending_callback.  It can be
 * run from any python thread.
 */
static PyObject *
pending_threadfunc(PyObject *self, PyObject *args, PyObject *kwargs)
{}


static struct {} pending_identify_result;

static int
_pending_identify_callback(void *arg)
{}

static PyObject *
pending_identify(PyObject *self, PyObject *args)
{}

static PyObject *
tracemalloc_get_traceback(PyObject *self, PyObject *args)
{}


// Test PyThreadState C API
static PyObject *
test_tstate_capi(PyObject *self, PyObject *Py_UNUSED(args))
{}


/* Test _PyUnicode_TransformDecimalAndSpaceToASCII() */
static PyObject *
unicode_transformdecimalandspacetoascii(PyObject *self, PyObject *arg)
{}


struct atexit_data {};

static void
callback(void *data)
{}

static PyObject *
test_atexit(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject *
test_pyobject_is_freed(const char *test_name, PyObject *op)
{}

static PyObject *
check_pyobject_null_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject *
check_pyobject_uninitialized_is_freed(PyObject *self,
                                      PyObject *Py_UNUSED(args))
{}


static PyObject *
check_pyobject_forbidden_bytes_is_freed(PyObject *self,
                                        PyObject *Py_UNUSED(args))
{}


static PyObject *
check_pyobject_freed_is_freed(PyObject *self, PyObject *Py_UNUSED(args))
{}


static PyObject *
test_pymem_getallocatorsname(PyObject *self, PyObject *args)
{}

static PyObject *
get_object_dict_values(PyObject *self, PyObject *obj)
{}


static PyObject*
new_hamt(PyObject *self, PyObject *args)
{}


static PyObject*
dict_getitem_knownhash(PyObject *self, PyObject *args)
{}


static int
_init_interp_config_from_object(PyInterpreterConfig *config, PyObject *obj)
{}

static PyInterpreterState *
_new_interpreter(PyInterpreterConfig *config, long whence)
{}

// This exists mostly for testing the _interpreters module, as an
// alternative to _interpreters.create()
static PyObject *
create_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
{}

// This exists mostly for testing the _interpreters module, as an
// alternative to _interpreters.destroy()
static PyObject *
destroy_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
{}

// This exists mostly for testing the _interpreters module, as an
// alternative to _interpreters.destroy()
static PyObject *
exec_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
{}


/* To run some code in a sub-interpreter.

Generally you can use test.support.interpreters,
but we keep this helper as a distinct implementation.
That's especially important for testing test.support.interpreters.
*/
static PyObject *
run_in_subinterp_with_config(PyObject *self, PyObject *args, PyObject *kwargs)
{}


static PyObject *
normalize_interp_id(PyObject *self, PyObject *idobj)
{}

static PyObject *
next_interpreter_id(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject *
unused_interpreter_id(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyObject *
interpreter_exists(PyObject *self, PyObject *idobj)
{}

static PyObject *
get_interpreter_refcount(PyObject *self, PyObject *idobj)
{}

static PyObject *
link_interpreter_refcount(PyObject *self, PyObject *idobj)
{}

static PyObject *
unlink_interpreter_refcount(PyObject *self, PyObject *idobj)
{}

static PyObject *
interpreter_refcount_linked(PyObject *self, PyObject *idobj)
{}


static void
_xid_capsule_destructor(PyObject *capsule)
{}

static PyObject *
get_crossinterp_data(PyObject *self, PyObject *args)
{}

static PyObject *
restore_crossinterp_data(PyObject *self, PyObject *args)
{}


static PyObject *
raiseTestError(const char* test_name, const char* msg)
{}


/*[clinic input]
_testinternalcapi.test_long_numbits
[clinic start generated code]*/

static PyObject *
_testinternalcapi_test_long_numbits_impl(PyObject *module)
/*[clinic end generated code: output=745d62d120359434 input=f14ca6f638e44dad]*/
{}

static PyObject *
compile_perf_trampoline_entry(PyObject *self, PyObject *args)
{}

static PyObject *
perf_trampoline_set_persist_after_fork(PyObject *self, PyObject *args)
{}


static PyObject *
get_rare_event_counters(PyObject *self, PyObject *type)
{}

static PyObject *
reset_rare_event_counters(PyObject *self, PyObject *Py_UNUSED(type))
{}


#ifdef Py_GIL_DISABLED
static PyObject *
get_py_thread_id(PyObject *self, PyObject *Py_UNUSED(ignored))
{
    uintptr_t tid = _Py_ThreadId();
    Py_BUILD_ASSERT(sizeof(unsigned long long) >= sizeof(tid));
    return PyLong_FromUnsignedLongLong(tid);
}

static PyCodeObject *
get_code(PyObject *obj)
{
    if (PyCode_Check(obj)) {
        return (PyCodeObject *)obj;
    }
    else if (PyFunction_Check(obj)) {
        return (PyCodeObject *)PyFunction_GetCode(obj);
    }
    return (PyCodeObject *)PyErr_Format(
        PyExc_TypeError, "expected function or code object, got %s",
        Py_TYPE(obj)->tp_name);
}

static PyObject *
get_tlbc(PyObject *Py_UNUSED(module), PyObject *obj)
{
    PyCodeObject *code = get_code(obj);
    if (code == NULL) {
        return NULL;
    }
    _Py_CODEUNIT *bc = _PyCode_GetTLBCFast(PyThreadState_GET(), code);
    if (bc == NULL) {
        Py_RETURN_NONE;
    }
    return PyBytes_FromStringAndSize((const char *)bc, _PyCode_NBYTES(code));
}

static PyObject *
get_tlbc_id(PyObject *Py_UNUSED(module), PyObject *obj)
{
    PyCodeObject *code = get_code(obj);
    if (code == NULL) {
        return NULL;
    }
    _Py_CODEUNIT *bc = _PyCode_GetTLBCFast(PyThreadState_GET(), code);
    if (bc == NULL) {
        Py_RETURN_NONE;
    }
    return PyLong_FromVoidPtr(bc);
}
#endif

static PyObject *
has_inline_values(PyObject *self, PyObject *obj)
{}


// Circumvents standard version assignment machinery - use with caution and only on
// short-lived heap types
static PyObject *
type_assign_specific_version_unsafe(PyObject *self, PyObject *args)
{}

/*[clinic input]
gh_119213_getargs

    spam: object = None

Test _PyArg_Parser.kwtuple
[clinic start generated code]*/

static PyObject *
gh_119213_getargs_impl(PyObject *module, PyObject *spam)
/*[clinic end generated code: output=d8d9c95d5b446802 input=65ef47511da80fc2]*/
{}


static PyObject *
get_static_builtin_types(PyObject *self, PyObject *Py_UNUSED(ignored))
{}


static PyObject *
identify_type_slot_wrappers(PyObject *self, PyObject *Py_UNUSED(ignored))
{}


static PyObject *
has_deferred_refcount(PyObject *self, PyObject *op)
{}

static PyObject *
get_tracked_heap_size(PyObject *self, PyObject *Py_UNUSED(ignored))
{}

static PyMethodDef module_functions[] =;


/* initialization function */

static int
module_exec(PyObject *module)
{}

static struct PyModuleDef_Slot module_slots[] =;

static int
module_traverse(PyObject *module, visitproc visit, void *arg)
{}

static int
module_clear(PyObject *module)
{}

static void
module_free(void *module)
{}

static struct PyModuleDef _testcapimodule =;


PyMODINIT_FUNC
PyInit__testinternalcapi(void)
{}