#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE …
#endif
#undef NDEBUG
#include "Python.h"
#include "pycore_backoff.h"
#include "pycore_bitutils.h"
#include "pycore_bytesobject.h"
#include "pycore_ceval.h"
#include "pycore_code.h"
#include "pycore_compile.h"
#include "pycore_context.h"
#include "pycore_dict.h"
#include "pycore_fileutils.h"
#include "pycore_flowgraph.h"
#include "pycore_frame.h"
#include "pycore_gc.h"
#include "pycore_hashtable.h"
#include "pycore_initconfig.h"
#include "pycore_instruction_sequence.h"
#include "pycore_interp.h"
#include "pycore_long.h"
#include "pycore_object.h"
#include "pycore_optimizer.h"
#include "pycore_pathconfig.h"
#include "pycore_pyerrors.h"
#include "pycore_pylifecycle.h"
#include "pycore_pystate.h"
#include "clinic/_testinternalcapi.c.h"
#include "_testinternalcapi/parts.h"
#define MODULE_NAME …
static PyObject *
_get_current_module(void)
{ … }
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)
{ … }
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)
{ … }
static PyObject *
_testinternalcapi_compiler_cleandoc_impl(PyObject *module, PyObject *doc)
{ … }
static PyObject *
_testinternalcapi_new_instruction_sequence_impl(PyObject *module)
{ … }
static PyObject *
_testinternalcapi_compiler_codegen_impl(PyObject *module, PyObject *ast,
PyObject *filename, int optimize,
int compile_mode)
{ … }
static PyObject *
_testinternalcapi_optimize_cfg_impl(PyObject *module, PyObject *instructions,
PyObject *consts, int nlocals)
{ … }
static int
get_nonnegative_int_from_dict(PyObject *dict, const char *key) { … }
static PyObject *
_testinternalcapi_assemble_code_object_impl(PyObject *module,
PyObject *filename,
PyObject *instructions,
PyObject *metadata)
{ … }
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;
}
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)
{ … }
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)
{ … }
static PyObject *
test_tstate_capi(PyObject *self, PyObject *Py_UNUSED(args))
{ … }
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)
{ … }
static PyObject *
create_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
{ … }
static PyObject *
destroy_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
{ … }
static PyObject *
exec_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
{ … }
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)
{ … }
static PyObject *
_testinternalcapi_test_long_numbits_impl(PyObject *module)
{ … }
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)
{ … }
static PyObject *
type_assign_specific_version_unsafe(PyObject *self, PyObject *args)
{ … }
static PyObject *
gh_119213_getargs_impl(PyObject *module, PyObject *spam)
{ … }
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[] = …;
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)
{ … }