cpython/Modules/_testmultiphase.c


/* Testing module for multi-phase initialization of extension modules (PEP 489)
 */
#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE
#endif

#include "Python.h"
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
#include "pycore_namespace.h"     // _PyNamespace_New()

/* State for testing module state access from methods */

meth_state;

/*[clinic input]
module _testmultiphase

class _testmultiphase.StateAccessType "StateAccessTypeObject *" "!StateAccessType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=bab9f2fe3bd312ff]*/

/* Example objects */
ExampleObject;

testmultiphase_state;

StateAccessTypeObject;

/* Example methods */

static int
Example_traverse(ExampleObject *self, visitproc visit, void *arg)
{}

static void
Example_finalize(ExampleObject *self)
{}

static PyObject *
Example_demo(ExampleObject *self, PyObject *args)
{}

#include "clinic/_testmultiphase.c.h"

static PyMethodDef Example_methods[] =;

static PyObject *
Example_getattro(ExampleObject *self, PyObject *name)
{}

static int
Example_setattr(ExampleObject *self, const char *name, PyObject *v)
{}

static PyType_Slot Example_Type_slots[] =;

static PyType_Spec Example_Type_spec =;


static PyModuleDef def_meth_state_access;
static PyModuleDef def_nonmodule;
static PyModuleDef def_nonmodule_with_methods;

/*[clinic input]
_testmultiphase.StateAccessType.get_defining_module

    cls: defining_class

Return the module of the defining class.

Also tests that result of PyType_GetModuleByDef matches defining_class's
module.
[clinic start generated code]*/

static PyObject *
_testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject *self,
                                                         PyTypeObject *cls)
/*[clinic end generated code: output=ba2a14284a5d0921 input=d2c7245c8a9d06f8]*/
{}

/*[clinic input]
_testmultiphase.StateAccessType.getmodulebydef_bad_def

    cls: defining_class

Test that result of PyType_GetModuleByDef with a bad def is NULL.
[clinic start generated code]*/

static PyObject *
_testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(StateAccessTypeObject *self,
                                                            PyTypeObject *cls)
/*[clinic end generated code: output=64509074dfcdbd31 input=edaff09aa4788204]*/
{}

/*[clinic input]
_testmultiphase.StateAccessType.increment_count_clinic

    cls: defining_class
    /
    n: int = 1
    *
    twice: bool = False

Add 'n' from the module-state counter.

Pass 'twice' to double that amount.

This tests Argument Clinic support for defining_class.
[clinic start generated code]*/

static PyObject *
_testmultiphase_StateAccessType_increment_count_clinic_impl(StateAccessTypeObject *self,
                                                            PyTypeObject *cls,
                                                            int n, int twice)
/*[clinic end generated code: output=3b34f86bc5473204 input=551d482e1fe0b8f5]*/
{}

PyDoc_STRVAR(_StateAccessType_decrement_count__doc__,
"decrement_count($self, /, n=1, *, twice=None)\n"
"--\n"
"\n"
"Add 'n' from the module-state counter.\n"
"Pass 'twice' to double that amount.\n"
"(This is to test both positional and keyword arguments.");

// Intentionally does not use Argument Clinic
static PyObject *
_StateAccessType_increment_count_noclinic(StateAccessTypeObject *self,
                                          PyTypeObject *defining_class,
                                          PyObject *const *args,
                                          Py_ssize_t nargs,
                                          PyObject *kwnames)
{}

/*[clinic input]
_testmultiphase.StateAccessType.get_count

    cls: defining_class

Return the value of the module-state counter.
[clinic start generated code]*/

static PyObject *
_testmultiphase_StateAccessType_get_count_impl(StateAccessTypeObject *self,
                                               PyTypeObject *cls)
/*[clinic end generated code: output=64600f95b499a319 input=d5d181f12384849f]*/
{}

static PyMethodDef StateAccessType_methods[] =;

static PyType_Slot StateAccessType_Type_slots[] =;

static PyType_Spec StateAccessType_spec =;

/* Function of two integers returning integer */

PyDoc_STRVAR(testexport_foo_doc,
"foo(i,j)\n\
\n\
Return the sum of i and j.");

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

/* Test that PyState registration fails  */

PyDoc_STRVAR(call_state_registration_func_doc,
"register_state(0): call PyState_FindModule()\n\
register_state(1): call PyState_AddModule()\n\
register_state(2): call PyState_RemoveModule()");

static PyObject *
call_state_registration_func(PyObject *mod, PyObject *args)
{}


static PyType_Slot Str_Type_slots[] =;

static PyType_Spec Str_Type_spec =;

static PyMethodDef testexport_methods[] =;

static int execfunc(PyObject *m)
{}

/* Helper for module definitions; there'll be a lot of them */

#define TEST_MODULE_DEF(name, slots, methods)

static PyModuleDef_Slot main_slots[] =;

static PyModuleDef main_def =;

PyMODINIT_FUNC
PyInit__testmultiphase(void)
{}


/**** Importing a non-module object ****/

/* Create a SimpleNamespace(three=3) */
static PyObject*
createfunc_nonmodule(PyObject *spec, PyModuleDef *def)
{}

static PyModuleDef_Slot slots_create_nonmodule[] =;

static PyModuleDef def_nonmodule =;

PyMODINIT_FUNC
PyInit__testmultiphase_nonmodule(void)
{}

PyDoc_STRVAR(nonmodule_bar_doc,
"bar(i,j)\n\
\n\
Return the difference of i - j.");

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

static PyMethodDef nonmodule_methods[] =;

static PyModuleDef def_nonmodule_with_methods =;

PyMODINIT_FUNC
PyInit__testmultiphase_nonmodule_with_methods(void)
{}

/**** Non-ASCII-named modules ****/

static PyModuleDef_Slot nonascii_slots[] =;

static PyModuleDef def_nonascii_latin =;

PyMODINIT_FUNC
PyInitU__testmultiphase_zkouka_naten_evc07gi8e(void)
{}

static PyModuleDef def_nonascii_kana =;

PyMODINIT_FUNC
PyInitU_eckzbwbhc6jpgzcx415x(void)
{}

/*** Module with a single-character name ***/

PyMODINIT_FUNC
PyInit_x(void)
{}

/**** Testing NULL slots ****/

static PyModuleDef null_slots_def =;

PyMODINIT_FUNC
PyInit__testmultiphase_null_slots(void)
{}

/**** Problematic modules ****/

static PyModuleDef_Slot slots_bad_large[] =;

static PyModuleDef def_bad_large =;

PyMODINIT_FUNC
PyInit__testmultiphase_bad_slot_large(void)
{}

static PyModuleDef_Slot slots_bad_negative[] =;

static PyModuleDef def_bad_negative =;

PyMODINIT_FUNC
PyInit__testmultiphase_bad_slot_negative(void)
{}

static PyModuleDef def_create_int_with_state =;

PyMODINIT_FUNC
PyInit__testmultiphase_create_int_with_state(void)
{}


static PyModuleDef def_negative_size =;

PyMODINIT_FUNC
PyInit__testmultiphase_negative_size(void)
{}


static PyModuleDef uninitialized_def =;

PyMODINIT_FUNC
PyInit__testmultiphase_export_uninitialized(void)
{}

PyMODINIT_FUNC
PyInit__testmultiphase_export_null(void)
{}

PyMODINIT_FUNC
PyInit__testmultiphase_export_raise(void)
{}

PyMODINIT_FUNC
PyInit__testmultiphase_export_unreported_exception(void)
{}

static PyObject*
createfunc_noop(PyObject *spec, PyModuleDef *def)
{}

static PyModuleDef_Slot slots_multiple_create_slots[] =;

static PyModuleDef def_multiple_create_slots =;

PyMODINIT_FUNC
PyInit__testmultiphase_multiple_create_slots(void)
{}

static PyObject*
createfunc_null(PyObject *spec, PyModuleDef *def)
{}

static PyModuleDef_Slot slots_create_null[] =;

static PyModuleDef def_create_null =;

PyMODINIT_FUNC
PyInit__testmultiphase_create_null(void)
{}

static PyObject*
createfunc_raise(PyObject *spec, PyModuleDef *def)
{}

static PyModuleDef_Slot slots_create_raise[] =;

static PyModuleDef def_create_raise =;

PyMODINIT_FUNC
PyInit__testmultiphase_create_raise(void)
{}

static PyObject*
createfunc_unreported_exception(PyObject *spec, PyModuleDef *def)
{}

static PyModuleDef_Slot slots_create_unreported_exception[] =;

static PyModuleDef def_create_unreported_exception =;

PyMODINIT_FUNC
PyInit__testmultiphase_create_unreported_exception(void)
{}

static PyModuleDef_Slot slots_nonmodule_with_exec_slots[] =;

static PyModuleDef def_nonmodule_with_exec_slots =;

PyMODINIT_FUNC
PyInit__testmultiphase_nonmodule_with_exec_slots(void)
{}

static int
execfunc_err(PyObject *mod)
{}

static PyModuleDef_Slot slots_exec_err[] =;

static PyModuleDef def_exec_err =;

PyMODINIT_FUNC
PyInit__testmultiphase_exec_err(void)
{}

static int
execfunc_raise(PyObject *spec)
{}

static PyModuleDef_Slot slots_exec_raise[] =;

static PyModuleDef def_exec_raise =;

PyMODINIT_FUNC
PyInit__testmultiphase_exec_raise(void)
{}

static int
execfunc_unreported_exception(PyObject *mod)
{}

static PyModuleDef_Slot slots_exec_unreported_exception[] =;

static PyModuleDef def_exec_unreported_exception =;

PyMODINIT_FUNC
PyInit__testmultiphase_exec_unreported_exception(void)
{}

static int
meth_state_access_exec(PyObject *m)
{}

static PyModuleDef_Slot meth_state_access_slots[] =;

static PyModuleDef def_meth_state_access =;

PyMODINIT_FUNC
PyInit__testmultiphase_meth_state_access(void)
{}

static PyModuleDef def_module_state_shared =;

PyMODINIT_FUNC
PyInit__test_module_state_shared(void)
{}


/* multiple interpreters support */

static PyModuleDef_Slot slots_multiple_multiple_interpreters_slots[] =;

static PyModuleDef def_multiple_multiple_interpreters_slots =;

PyMODINIT_FUNC
PyInit__testmultiphase_multiple_multiple_interpreters_slots(void)
{}

static PyModuleDef_Slot non_isolated_slots[] =;

static PyModuleDef non_isolated_def =;

PyMODINIT_FUNC
PyInit__test_non_isolated(void)
{}


static PyModuleDef_Slot shared_gil_only_slots[] =;

static PyModuleDef shared_gil_only_def =;

PyMODINIT_FUNC
PyInit__test_shared_gil_only(void)
{}