diff --git a/docs/api-reference/function-index.rst b/docs/api-reference/function-index.rst index 3ee758a57..c5495c110 100644 --- a/docs/api-reference/function-index.rst +++ b/docs/api-reference/function-index.rst @@ -9,7 +9,6 @@ HPy Core API Function Index ########################### -* :c:func:`HPyModule_Create` * :c:func:`HPy_Dup` * :c:func:`HPy_Close` * :c:func:`HPyLong_FromInt32_t` diff --git a/docs/examples/mixed-example/mixed.c b/docs/examples/mixed-example/mixed.c index d5db36f8c..c5c04e4fc 100644 --- a/docs/examples/mixed-example/mixed.c +++ b/docs/examples/mixed-example/mixed.c @@ -39,20 +39,11 @@ static PyMethodDef py_defines[] = { }; static HPyModuleDef moduledef = { - .name = "mixed", .doc = "HPy Example of mixing CPython API and HPy API", - .size = -1, + .size = 0, .defines = hpy_defines, .legacy_methods = py_defines }; -HPy_MODINIT(mixed) -static HPy init_mixed_impl(HPyContext *ctx) -{ - HPy m; - m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - return m; -} +HPy_MODINIT(mixed, moduledef) diff --git a/docs/examples/simple-example/simple.c b/docs/examples/simple-example/simple.c index 4d9b94550..49883a950 100644 --- a/docs/examples/simple-example/simple.c +++ b/docs/examples/simple-example/simple.c @@ -31,17 +31,13 @@ static HPyDef *SimpleMethods[] = { }; static HPyModuleDef simple = { - .name = "simple", .doc = "HPy Example", - .size = -1, + .size = 0, .defines = SimpleMethods, .legacy_methods = NULL }; // END: methodsdef // BEGIN: moduledef -HPy_MODINIT(simple) -HPy init_simple_impl(HPyContext *ctx) { - return HPyModule_Create(ctx, &simple); -} +HPy_MODINIT(simple, simple) // END: moduledef \ No newline at end of file diff --git a/docs/examples/snippets/hpyvarargs.c b/docs/examples/snippets/hpyvarargs.c index 1a616eb35..e67c600dc 100644 --- a/docs/examples/snippets/hpyvarargs.c +++ b/docs/examples/snippets/hpyvarargs.c @@ -36,14 +36,10 @@ static HPyDef *SimpleMethods[] = { }; // END: methodsdef -static HPyModuleDef simple = { - .name = "hpyvarargs", +static HPyModuleDef def = { .doc = "HPy Example of varargs calling convention", - .size = -1, + .size = 0, .defines = SimpleMethods }; -HPy_MODINIT(hpyvarargs) -HPy init_hpyvarargs_impl(HPyContext *ctx) { - return HPyModule_Create(ctx, &simple); -} +HPy_MODINIT(hpyvarargs, def) diff --git a/docs/examples/snippets/snippets.c b/docs/examples/snippets/snippets.c index 6790d4ac1..fa926d09e 100644 --- a/docs/examples/snippets/snippets.c +++ b/docs/examples/snippets/snippets.c @@ -73,13 +73,9 @@ static HPyDef *Methods[] = { }; static HPyModuleDef snippets = { - .name = "snippets", .doc = "Various HPy code snippets for the docs", - .size = -1, + .size = 0, .defines = Methods }; -HPy_MODINIT(snippets) -HPy init_snippets_impl(HPyContext *ctx) { - return HPyModule_Create(ctx, &snippets); -} +HPy_MODINIT(snippets, snippets) diff --git a/docs/misc/embedding.rst b/docs/misc/embedding.rst index 08cb568ab..cb85d2bc1 100644 --- a/docs/misc/embedding.rst +++ b/docs/misc/embedding.rst @@ -43,8 +43,4 @@ Also refer to the API reference :ref:`api-reference/hpy-type:hpy module`. // ... } - HPy_MODINIT(hpymodA) - static HPy init_hpymodA_impl(HPyContext *ctx) - { - // ... - } + HPy_MODINIT(extension_name, hpymodA) diff --git a/docs/porting-example/index.rst b/docs/porting-example/index.rst index 5b530c743..8551b4b6b 100644 --- a/docs/porting-example/index.rst +++ b/docs/porting-example/index.rst @@ -107,31 +107,42 @@ Similarly we replace ``PyModuleDef`` with ``HPyModuleDef``: .. literalinclude:: steps/step_01_hpy_legacy.c :lineno-match: :start-at: // Legacy module methods (the "dot" method is still a PyCFunction) - :end-before: HPy_MODINIT(step_01_hpy_legacy) + :end-before: // END-OF: HPyModuleDef Like the type, the list of ported methods in ``module_defines`` is initially -empty and all the methods are still in ``PointModuleMethods`` which has -been renamed to ``PointModuleLegacyMethods``. +almost empty: all the regular methods are still in ``PointModuleMethods`` which has +been renamed to ``PointModuleLegacyMethods``. However, because HPy supports only +multiphase module initialization, we must convert our module initialization code +to an "exec" slot on the module and add that slot to ``module_defines``. Now all that is left is to replace the module initialization function with -one that uses ``HPy_MODINIT``: +one that uses ``HPy_MODINIT``. The first argument is the name of the extension, +i.e., what was ``XXX`` in ``PyInit_XXX``, and the second argument +is the ``HPyModuleDef``. .. literalinclude:: steps/step_01_hpy_legacy.c :lineno-match: - :start-at: HPy_MODINIT(step_01_hpy_legacy) + :start-at: HPy_MODINIT(step_01_hpy_legacy, moduledef) And we're done! -Note that the initialization function now takes an ``HPyContext *`` as an -argument and that this ``ctx`` is passed as the first argument to calls to -HPy API methods. +Instead of the ``PyInit_XXX``, we now have an "exec" slot on the module. +We implement it with a C function that that takes an ``HPyContext *ctx`` and ``HPy mod`` +as arguments. The ``ctx`` must be forwarded as the first argument to calls to +HPy API methods. The ``mod`` argument is a handle for the module object. The runtime +creates the module for us from the provided ``HPyModuleDef``. There is no need to +call API like ``PyModule_Create`` explicitly. -``PyModule_Create`` is replaced with ``HPyModule_Create`` and ``PyType_FromSpec`` -is replaced by ``HPyType_FromSpec``. +Next step is to replace ``PyType_FromSpec`` by ``HPyType_FromSpec``. ``HPy_SetAttr_s`` is used to add the ``Point`` class to the module. HPy requires no special ``PyModule_AddObject`` method. +.. literalinclude:: steps/step_01_hpy_legacy.c + :lineno-match: + :start-at: HPyDef_SLOT(module_exec, HPy_mod_exec) + :end-at: } + Step 02: Transition some methods to HPy --------------------------------------- @@ -338,7 +349,7 @@ and the module definition is simpler too: .. literalinclude:: steps/step_03_hpy_final.c :lineno-match: :start-at: static HPyDef *module_defines[] = { - :end-before: HPy_MODINIT(step_03_hpy_final) + :end-before: HPy_MODINIT(step_03_hpy_final, moduledef) Now that the port is complete, when we compile our extension in HPy universal mode, we obtain a built extension that depends only on the HPy ABI diff --git a/docs/porting-example/steps/step_01_hpy_legacy.c b/docs/porting-example/steps/step_01_hpy_legacy.c index 2578944db..48137cc58 100644 --- a/docs/porting-example/steps/step_01_hpy_legacy.c +++ b/docs/porting-example/steps/step_01_hpy_legacy.c @@ -143,36 +143,47 @@ static HPyType_Spec Point_Type_spec = { .defines = point_defines, }; +// HPy supports only multiphase module initialization, so we must migrate the +// single phase initialization by extracting the code that populates the module +// object with attributes into a separate 'exec' slot. The module is not +// created manually by calling API like PyModule_Create, but the runtime creates +// the module for us from the specification in HPyModuleDef, and we can provide +// additional slots to populate the module before its initialization is finalized +HPyDef_SLOT(module_exec, HPy_mod_exec) +static int module_exec_impl(HPyContext *ctx, HPy mod) +{ + HPy point_type = HPyType_FromSpec(ctx, &Point_Type_spec, NULL); + if (HPy_IsNull(point_type)) + return -1; + HPy_SetAttr_s(ctx, mod, "Point", point_type); + return 0; +} + // Legacy module methods (the "dot" method is still a PyCFunction) static PyMethodDef PointModuleLegacyMethods[] = { {"dot", (PyCFunction)dot, METH_VARARGS, "Dot product."}, {NULL, NULL, 0, NULL} }; -// HPy module methods (no methods have been ported yet) +// HPy module methods: no regular methods have been ported yet, +// but we add the module execute slot static HPyDef *module_defines[] = { + &module_exec, NULL }; static HPyModuleDef moduledef = { - .name = "step_01_hpy_legacy", + // .name = "step_01_hpy_legacy", + // ^-- .name is not needed for multiphase module initialization, + // it is always taken from the ModuleSpec .doc = "Point module (Step 1; All legacy methods)", - .size = -1, + .size = 0, .legacy_methods = PointModuleLegacyMethods, .defines = module_defines, }; +// END-OF: HPyModuleDef -HPy_MODINIT(step_01_hpy_legacy) -static HPy init_step_01_hpy_legacy_impl(HPyContext *ctx) -{ - HPy m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - - HPy point_type = HPyType_FromSpec(ctx, &Point_Type_spec, NULL); - if (HPy_IsNull(point_type)) - return HPy_NULL; - HPy_SetAttr_s(ctx, m, "Point", point_type); - - return m; -} +// HPy_MODINIT takes the extension name, i.e., what would be XXX in PyInit_XXX, +// and the module definition. The module will be created by the runtime and +// passed to the HPy_mod_exec slots if any are defined +HPy_MODINIT(step_01_hpy_legacy, moduledef) diff --git a/docs/porting-example/steps/step_02_hpy_legacy.c b/docs/porting-example/steps/step_02_hpy_legacy.c index 3907c4477..bb4e43589 100644 --- a/docs/porting-example/steps/step_02_hpy_legacy.c +++ b/docs/porting-example/steps/step_02_hpy_legacy.c @@ -140,30 +140,28 @@ static PyMethodDef PointModuleLegacyMethods[] = { {NULL, NULL, 0, NULL} }; -// HPy module methods (no methods have been ported yet) +HPyDef_SLOT(module_exec, HPy_mod_exec) +static int module_exec_impl(HPyContext *ctx, HPy mod) +{ + HPy point_type = HPyType_FromSpec(ctx, &Point_Type_spec, NULL); + if (HPy_IsNull(point_type)) + return -1; + HPy_SetAttr_s(ctx, mod, "Point", point_type); + return 0; +} + +// HPy module methods: no regular methods have been ported yet, +// but we add the module execute slot static HPyDef *module_defines[] = { + &module_exec, NULL }; static HPyModuleDef moduledef = { - .name = "step_02_hpy_legacy", .doc = "Point module (Step 2; Porting some methods)", - .size = -1, + .size = 0, .legacy_methods = PointModuleLegacyMethods, .defines = module_defines, }; -HPy_MODINIT(step_02_hpy_legacy) -static HPy init_step_02_hpy_legacy_impl(HPyContext *ctx) -{ - HPy m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - - HPy point_type = HPyType_FromSpec(ctx, &Point_Type_spec, NULL); - if (HPy_IsNull(point_type)) - return HPy_NULL; - HPy_SetAttr_s(ctx, m, "Point", point_type); - - return m; -} +HPy_MODINIT(step_02_hpy_legacy, moduledef) diff --git a/docs/porting-example/steps/step_03_hpy_final.c b/docs/porting-example/steps/step_03_hpy_final.c index 9c2e9fa2a..2c9a3f5c0 100644 --- a/docs/porting-example/steps/step_03_hpy_final.c +++ b/docs/porting-example/steps/step_03_hpy_final.c @@ -125,30 +125,27 @@ static HPyType_Spec Point_Type_spec = { .defines = point_defines }; +HPyDef_SLOT(module_exec, HPy_mod_exec) +static int module_exec_impl(HPyContext *ctx, HPy mod) +{ + HPy point_type = HPyType_FromSpec(ctx, &Point_Type_spec, NULL); + if (HPy_IsNull(point_type)) + return -1; + HPy_SetAttr_s(ctx, mod, "Point", point_type); + return 0; +} + // HPy module methods static HPyDef *module_defines[] = { + &module_exec, &dot, NULL }; static HPyModuleDef moduledef = { - .name = "step_03_hpy_final", .doc = "Point module (Step 3; Porting complete)", - .size = -1, + .size = 0, .defines = module_defines, }; -HPy_MODINIT(step_03_hpy_final) -static HPy init_step_03_hpy_final_impl(HPyContext *ctx) -{ - HPy m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - - HPy point_type = HPyType_FromSpec(ctx, &Point_Type_spec, NULL); - if (HPy_IsNull(point_type)) - return HPy_NULL; - HPy_SetAttr_s(ctx, m, "Point", point_type); - - return m; -} +HPy_MODINIT(step_03_hpy_final, moduledef) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index 60a0b11de..81008f403 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -397,6 +397,17 @@ static UHPy new_DebugHandleObj(HPyContext *uctx, UHPy u_DebugHandleType, /* ~~~~~~ definition of the module hpy.debug._debug ~~~~~~~ */ +HPyDef_SLOT(module_exec, HPy_mod_exec) +static int module_exec_impl(HPyContext *uctx, HPy m) +{ + UHPy h_DebugHandleType = HPyType_FromSpec(uctx, &DebugHandleType_spec, NULL); + if (HPy_IsNull(h_DebugHandleType)) + return -1; + HPy_SetAttr_s(uctx, m, "DebugHandle", h_DebugHandleType); + HPy_Close(uctx, h_DebugHandleType); + return 0; +} + static HPyDef *module_defines[] = { &new_generation, &get_open_handles, @@ -408,28 +419,14 @@ static HPyDef *module_defines[] = { &set_on_invalid_handle, &set_on_invalid_builder_handle, &set_handle_stack_trace_limit, + &module_exec, NULL }; static HPyModuleDef moduledef = { - .name = "hpy.debug._debug", .doc = "HPy debug mode", - .size = -1, + .size = 0, .defines = module_defines }; - -HPy_MODINIT(_debug) -static UHPy init__debug_impl(HPyContext *uctx) -{ - UHPy m = HPyModule_Create(uctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - - UHPy h_DebugHandleType = HPyType_FromSpec(uctx, &DebugHandleType_spec, NULL); - if (HPy_IsNull(h_DebugHandleType)) - return HPy_NULL; - HPy_SetAttr_s(uctx, m, "DebugHandle", h_DebugHandleType); - HPy_Close(uctx, h_DebugHandleType); - return m; -} +HPy_MODINIT(_debug, moduledef) diff --git a/hpy/debug/src/autogen_debug_ctx_init.h b/hpy/debug/src/autogen_debug_ctx_init.h index c3d2b7b4d..6c7b4e15a 100644 --- a/hpy/debug/src/autogen_debug_ctx_init.h +++ b/hpy/debug/src/autogen_debug_ctx_init.h @@ -10,7 +10,6 @@ */ -DHPy debug_ctx_Module_Create(HPyContext *dctx, HPyModuleDef *def); DHPy debug_ctx_Dup(HPyContext *dctx, DHPy h); void debug_ctx_Close(HPyContext *dctx, DHPy h); DHPy debug_ctx_Long_FromInt32_t(HPyContext *dctx, int32_t value); @@ -262,7 +261,6 @@ static inline void debug_ctx_init_fields(HPyContext *dctx, HPyContext *uctx) dctx->h_CapsuleType = DHPy_open_immortal(dctx, uctx->h_CapsuleType); dctx->h_SliceType = DHPy_open_immortal(dctx, uctx->h_SliceType); dctx->h_Builtins = DHPy_open_immortal(dctx, uctx->h_Builtins); - dctx->ctx_Module_Create = &debug_ctx_Module_Create; dctx->ctx_Dup = &debug_ctx_Dup; dctx->ctx_Close = &debug_ctx_Close; dctx->ctx_Long_FromInt32_t = &debug_ctx_Long_FromInt32_t; diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index d91eb09b8..b5c7014ca 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -12,11 +12,6 @@ #include "debug_internal.h" -DHPy debug_ctx_Module_Create(HPyContext *dctx, HPyModuleDef *def) -{ - return DHPy_open(dctx, HPyModule_Create(get_info(dctx)->uctx, def)); -} - DHPy debug_ctx_Dup(HPyContext *dctx, DHPy h) { return DHPy_open(dctx, HPy_Dup(get_info(dctx)->uctx, DHPy_unwrap(dctx, h))); diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index ea81c7eda..e26d16d14 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -24,7 +24,9 @@ #include #include "debug_internal.h" #include "hpy/runtime/ctx_type.h" // for call_traverseproc_from_trampoline +#include "hpy/runtime/ctx_module.h" #include "handles.h" // for _py2h and _h2py + #if defined(_MSC_VER) # include /* for alloca() */ #endif @@ -193,6 +195,17 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext *dctx, PyCapsule_GetContext(capsule)); return; } + case HPyFunc_MOD_CREATE: { + HPyFunc_unaryfunc f = (HPyFunc_unaryfunc)func; + _HPyFunc_args_UNARYFUNC *a = (_HPyFunc_args_UNARYFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0); + DHPy_close_and_check(dctx, dh_arg0); + a->result = _dh2py(dctx, dh_result); + _HPyModule_CheckCreateSlotResult(&a->result); + DHPy_close(dctx, dh_result); + return; + } #include "autogen_debug_ctx_call.i" default: Py_FatalError("Unsupported HPyFunc_Signature in debug_ctx_cpython.c"); diff --git a/hpy/debug/src/include/hpy_debug.h b/hpy/debug/src/include/hpy_debug.h index b8caee682..f2fb9471b 100644 --- a/hpy/debug/src/include/hpy_debug.h +++ b/hpy/debug/src/include/hpy_debug.h @@ -46,6 +46,12 @@ void hpy_debug_close_handle(HPyContext *dctx, HPy dh); extern "C" #endif HPy_EXPORTED_SYMBOL -HPy HPyInit__debug(HPyContext *uctx); +HPyModuleDef* HPyInit__debug(); + +#ifdef ___cplusplus +extern "C" +#endif +HPy_EXPORTED_SYMBOL +void HPyInitGlobalContext__debug(HPyContext *ctx); #endif /* HPY_DEBUG_H */ diff --git a/hpy/devel/include/hpy/autogen_hpyfunc_declare.h b/hpy/devel/include/hpy/autogen_hpyfunc_declare.h index b506f7532..9ef2713d8 100644 --- a/hpy/devel/include/hpy/autogen_hpyfunc_declare.h +++ b/hpy/devel/include/hpy/autogen_hpyfunc_declare.h @@ -45,6 +45,7 @@ #define _HPyFunc_DECLARE_HPyFunc_TRAVERSEPROC(SYM) static int SYM(void *object, HPyFunc_visitproc visit, void *arg) #define _HPyFunc_DECLARE_HPyFunc_DESTRUCTOR(SYM) static void SYM(HPyContext *ctx, HPy) #define _HPyFunc_DECLARE_HPyFunc_DESTROYFUNC(SYM) static void SYM(void *) +#define _HPyFunc_DECLARE_HPyFunc_MOD_CREATE(SYM) static HPy SYM(HPyContext *ctx, HPy) typedef HPy (*HPyFunc_noargs)(HPyContext *ctx, HPy self); typedef HPy (*HPyFunc_o)(HPyContext *ctx, HPy self, HPy arg); @@ -81,3 +82,4 @@ typedef void (*HPyFunc_releasebufferproc)(HPyContext *ctx, HPy, HPy_buffer *); typedef int (*HPyFunc_traverseproc)(void *object, HPyFunc_visitproc visit, void *arg); typedef void (*HPyFunc_destructor)(HPyContext *ctx, HPy); typedef void (*HPyFunc_destroyfunc)(void *); +typedef HPy (*HPyFunc_mod_create)(HPyContext *ctx, HPy); diff --git a/hpy/devel/include/hpy/autogen_hpyslot.h b/hpy/devel/include/hpy/autogen_hpyslot.h index 599dfec2d..ba9729341 100644 --- a/hpy/devel/include/hpy/autogen_hpyslot.h +++ b/hpy/devel/include/hpy/autogen_hpyslot.h @@ -68,6 +68,8 @@ typedef enum { HPy_nb_inplace_matrix_multiply = 76, HPy_tp_finalize = 80, HPy_tp_destroy = 1000, + HPy_mod_create = 2000, + HPy_mod_exec = 2001, } HPySlot_Slot; #define _HPySlot_SIG__HPy_bf_getbuffer HPyFunc_GETBUFFERPROC @@ -127,3 +129,5 @@ typedef enum { #define _HPySlot_SIG__HPy_nb_inplace_matrix_multiply HPyFunc_BINARYFUNC #define _HPySlot_SIG__HPy_tp_finalize HPyFunc_DESTRUCTOR #define _HPySlot_SIG__HPy_tp_destroy HPyFunc_DESTROYFUNC +#define _HPySlot_SIG__HPy_mod_create HPyFunc_MOD_CREATE +#define _HPySlot_SIG__HPy_mod_exec HPyFunc_INQUIRY diff --git a/hpy/devel/include/hpy/cpy_types.h b/hpy/devel/include/hpy/cpy_types.h index f32eda3e1..461a02858 100644 --- a/hpy/devel/include/hpy/cpy_types.h +++ b/hpy/devel/include/hpy/cpy_types.h @@ -19,6 +19,7 @@ typedef struct FORBIDDEN_cpy_PyObject cpy_PyObject; typedef struct FORBIDDEN_PyMethodDef cpy_PyMethodDef; +typedef struct FORBIDDEN_PyModuleDef cpy_PyModuleDef; typedef struct FORBIDDEN_bufferinfo cpy_Py_buffer; // declare the following API functions as _HPY_LEGACY, which triggers an @@ -31,6 +32,7 @@ HPyAPI_FUNC _HPY_LEGACY HPy HPy_FromPyObject(HPyContext *ctx, cpy_PyObject *obj) // Python.h has already been included by the main hpy.h typedef PyObject cpy_PyObject; typedef PyMethodDef cpy_PyMethodDef; +typedef PyModuleDef cpy_PyModuleDef; typedef Py_buffer cpy_Py_buffer; #endif /* HPY_ABI_UNIVERSAL */ diff --git a/hpy/devel/include/hpy/cpython/hpyfunc_trampolines.h b/hpy/devel/include/hpy/cpython/hpyfunc_trampolines.h index ec03269cd..926811882 100644 --- a/hpy/devel/include/hpy/cpython/hpyfunc_trampolines.h +++ b/hpy/devel/include/hpy/cpython/hpyfunc_trampolines.h @@ -111,4 +111,16 @@ typedef int (*_HPyCFunction_RELEASEBUFFERPROC)(HPyContext *, HPy, HPy_buffer *); PyCapsule_GetContext(capsule)); \ } +extern void +_HPyModule_CheckCreateSlotResult(cpy_PyObject **result); + +#define _HPyFunc_TRAMPOLINE_HPyFunc_MOD_CREATE(SYM, IMPL) \ + static cpy_PyObject* SYM(cpy_PyObject *spec, cpy_PyModuleDef *def) \ + { \ + (void) def; /* avoid 'unused' warning */ \ + cpy_PyObject* result = _h2py(IMPL(_HPyGetContext(), _py2h(spec))); \ + _HPyModule_CheckCreateSlotResult(&result); \ + return result; \ + } + #endif // HPY_CPYTHON_HPYFUNC_TRAMPOLINES_H diff --git a/hpy/devel/include/hpy/hpyfunc.h b/hpy/devel/include/hpy/hpyfunc.h index a639b90c7..654c525ee 100644 --- a/hpy/devel/include/hpy/hpyfunc.h +++ b/hpy/devel/include/hpy/hpyfunc.h @@ -41,6 +41,8 @@ typedef enum { HPyFunc_DESTRUCTOR, HPyFunc_CAPSULE_DESTRUCTOR, + HPyFunc_MOD_CREATE, + } HPyFunc_Signature; /* The typedefs corresponding to the various HPyFunc_Signature members diff --git a/hpy/devel/include/hpy/hpymodule.h b/hpy/devel/include/hpy/hpymodule.h index 3e0a82860..324e9ea6d 100644 --- a/hpy/devel/include/hpy/hpymodule.h +++ b/hpy/devel/include/hpy/hpymodule.h @@ -26,14 +26,30 @@ extern HPyContext *_ctx_for_trampolines; #endif +/** + * Definition of a Python module. Pointer to this struct is returned from + * the HPy initialization function ``HPyInit_{extname}`` and the Python + * interpreter creates a Python module from it. HPy supports only the + * multi-phase module initialization approach (PEP 451). + * + * There is no HPy API to create a Python module manually, i.e., equivalent + * of ``PyModule_Create`` or ``PyModule_FromDefAndSpec``, for the time being, + * but may be added if a use-case arises. + * + * Note: unlike Python/C API, HPy module definition does not specify module + * name. The name if always taken from the ModuleSpec, which is also the case + * in multi-phase module initialization on Python/C API. + */ typedef struct { - /** The Python name of module (UTF-8 encoded) */ - const char* name; - /** Docstring of the type (UTF-8 encoded; may be ``NULL``) */ const char* doc; - /** The size (in bytes) of the module state structure. */ + /** + * The size (in bytes) of the module state structure. If set to zero, + * then the module will not get allocated and assigned any HPy module state. + * Negative size, unlike in Python/C API, does not have any specific meaning + * and will produce a runtime error. + */ HPy_ssize_t size; /** @@ -63,22 +79,22 @@ typedef struct { #if defined(__cplusplus) -# define HPyVERSION_FUNC extern "C" HPy_EXPORTED_SYMBOL uint32_t -# define HPyMODINIT_FUNC extern "C" HPy_EXPORTED_SYMBOL HPy +# define HPy_EXPORTED_FUNC extern "C" HPy_EXPORTED_SYMBOL #else /* __cplusplus */ -# define HPyVERSION_FUNC HPy_EXPORTED_SYMBOL uint32_t -# define HPyMODINIT_FUNC HPy_EXPORTED_SYMBOL HPy +# define HPy_EXPORTED_FUNC HPy_EXPORTED_SYMBOL #endif /* __cplusplus */ #ifdef HPY_ABI_CPYTHON +// helpers provided by HPy runtime: +#include "hpy/runtime/ctx_module.h" + // module initialization in the CPython case -#define HPy_MODINIT(modname) \ - static HPy init_##modname##_impl(HPyContext *ctx); \ - PyMODINIT_FUNC \ - PyInit_##modname(void) \ - { \ - return _h2py(init_##modname##_impl(_HPyGetContext())); \ +#define HPy_MODINIT(ext_name, mod_def) \ + PyMODINIT_FUNC \ + PyInit_##ext_name(void) \ + { \ + return _HPyModuleDef_AsPyInit(&mod_def); \ } #else // HPY_ABI_CPYTHON @@ -96,42 +112,47 @@ typedef struct { * ``get_required_hpy_minor_version_`` * The HPy minor version this module was built with. * - * ``HPyInit_`` - * The init function that will be called by the interpreter. - * - * The macro expects that there is a function ``init_`` that does - * the actual initialization of the module. + * ``HPyModuleDef* HPyInit_`` + * The init function that will be called by the interpreter. This function + * does not have an access to HPyContext and thus cannot call any HPy APIs. + * The purpose of this function is to return a pointer to a HPyModuleDef + * structure that will serve as a specification of the module that should be + * created by the interpreter. HPy supports only multi-phase module + * initialization (PEP 451). Any module initialization code can be added + * to the HPy_mod_execute slot of the module if needed. * * Example: * * .. code-block:: c * - * HPy_MODINIT(mymodule) - * static HPy init_mymodule(HPyContext *ctx) - * { - * // ... - * } + * HPy_MODINIT(myextension_shared_library_filename, my_hpy_module_def) */ -#define HPy_MODINIT(modname) \ - HPyVERSION_FUNC \ - get_required_hpy_major_version_##modname() \ - { \ - return HPY_ABI_VERSION; \ - } \ - HPyVERSION_FUNC \ - get_required_hpy_minor_version_##modname() \ - { \ - return HPY_ABI_VERSION_MINOR; \ - } \ - _HPy_CTX_MODIFIER HPyContext *_ctx_for_trampolines; \ - static HPy init_##modname##_impl(HPyContext *ctx); \ - HPyMODINIT_FUNC \ - HPyInit_##modname(HPyContext *ctx) \ - { \ - _ctx_for_trampolines = ctx; \ - return init_##modname##_impl(ctx); \ +#define HPy_MODINIT(ext_name, mod_def) \ + HPy_EXPORTED_FUNC uint32_t \ + get_required_hpy_major_version_##ext_name() \ + { \ + return HPY_ABI_VERSION; \ + } \ + HPy_EXPORTED_FUNC uint32_t \ + get_required_hpy_minor_version_##ext_name() \ + { \ + return HPY_ABI_VERSION_MINOR; \ + } \ + _HPy_CTX_MODIFIER HPyContext *_ctx_for_trampolines; \ + HPy_EXPORTED_FUNC void \ + HPyInitGlobalContext_##ext_name(HPyContext *ctx) \ + { \ + _ctx_for_trampolines = ctx; \ + } \ + HPy_EXPORTED_FUNC HPyModuleDef* \ + HPyInit_##ext_name() \ + { \ + return &mod_def; \ } +// Implementation note: the global HPyContext is used by the CPython +// trampolines generated by the HPyDef_XXX macros + #endif // HPY_ABI_CPYTHON #endif // HPY_UNIVERSAL_HPYMODULE_H diff --git a/hpy/devel/include/hpy/runtime/ctx_module.h b/hpy/devel/include/hpy/runtime/ctx_module.h new file mode 100644 index 000000000..8cb6549cc --- /dev/null +++ b/hpy/devel/include/hpy/runtime/ctx_module.h @@ -0,0 +1,25 @@ +#ifndef HPY_COMMON_RUNTIME_CTX_MODULE_H +#define HPY_COMMON_RUNTIME_CTX_MODULE_H + +#include +#include "hpy.h" + +// Helper functions for CPython implementation (both CPython ABI and +// HPy universal module impl for CPython) + +/** Converts HPy module definition to CPython module definition for multiphase + * initialization */ +_HPy_HIDDEN PyModuleDef* +_HPyModuleDef_CreatePyModuleDef(HPyModuleDef *hpydef); + +/** Converts HPy module definition to PyObject that wraps CPython module + * definition for multiphase initialization */ +_HPy_HIDDEN PyObject* +_HPyModuleDef_AsPyInit(HPyModuleDef *hpydef); + +/** Implements the extra HPy specific validation that should be applied to the + * result of the HPy_mod_create slot. */ +_HPy_HIDDEN void +_HPyModule_CheckCreateSlotResult(PyObject **result); + +#endif //HPY_COMMON_RUNTIME_CTX_MODULE_H diff --git a/hpy/devel/include/hpy/universal/autogen_ctx.h b/hpy/devel/include/hpy/universal/autogen_ctx.h index 2bc60c7ab..b6f45628f 100644 --- a/hpy/devel/include/hpy/universal/autogen_ctx.h +++ b/hpy/devel/include/hpy/universal/autogen_ctx.h @@ -91,7 +91,6 @@ struct _HPyContext_s { HPy h_UnicodeType; HPy h_TupleType; HPy h_ListType; - HPy (*ctx_Module_Create)(HPyContext *ctx, HPyModuleDef *def); HPy (*ctx_Dup)(HPyContext *ctx, HPy h); void (*ctx_Close)(HPyContext *ctx, HPy h); HPy (*ctx_Long_FromInt32_t)(HPyContext *ctx, int32_t value); diff --git a/hpy/devel/include/hpy/universal/autogen_trampolines.h b/hpy/devel/include/hpy/universal/autogen_trampolines.h index b223b793d..583d2a1fd 100644 --- a/hpy/devel/include/hpy/universal/autogen_trampolines.h +++ b/hpy/devel/include/hpy/universal/autogen_trampolines.h @@ -10,10 +10,6 @@ */ -HPyAPI_FUNC HPy HPyModule_Create(HPyContext *ctx, HPyModuleDef *def) { - return ctx->ctx_Module_Create ( ctx, def ); -} - HPyAPI_FUNC HPy HPy_Dup(HPyContext *ctx, HPy h) { return ctx->ctx_Dup ( ctx, h ); } diff --git a/hpy/devel/include/hpy/universal/hpyfunc_trampolines.h b/hpy/devel/include/hpy/universal/hpyfunc_trampolines.h index daf80fd67..18a35da62 100644 --- a/hpy/devel/include/hpy/universal/hpyfunc_trampolines.h +++ b/hpy/devel/include/hpy/universal/hpyfunc_trampolines.h @@ -168,5 +168,20 @@ typedef struct { HPyFunc_CAPSULE_DESTRUCTOR, (HPyCFunction)IMPL, capsule); \ } +typedef struct { + cpy_PyObject *spec; + cpy_PyObject *result; +} _HPyFunc_args_MOD_CREATE; + +#define _HPyFunc_TRAMPOLINE_HPyFunc_MOD_CREATE(SYM, IMPL) \ + static cpy_PyObject* SYM(cpy_PyObject *spec, cpy_PyModuleDef *def) \ + { \ + (void) def; /* avoid 'unused' warning */ \ + _HPyFunc_args_UNARYFUNC a = { spec }; \ + _HPy_CallRealFunctionFromTrampoline( \ + _ctx_for_trampolines, HPyFunc_MOD_CREATE, (HPyCFunction)IMPL, &a); \ + return a.result; \ + } + #endif // HPY_UNIVERSAL_HPYFUNC_TRAMPOLINES_H diff --git a/hpy/devel/src/runtime/ctx_module.c b/hpy/devel/src/runtime/ctx_module.c index 209e23e83..8d318c03e 100644 --- a/hpy/devel/src/runtime/ctx_module.c +++ b/hpy/devel/src/runtime/ctx_module.c @@ -7,32 +7,146 @@ # include "handles.h" #endif +#define NON_DEFAULT_MESSAGE \ + "This is not allowed because custom " \ + "HPy_mod_create slot cannot return a builtin module " \ + "object and cannot make any use of any other data " \ + "defined in the HPyModuleDef. Either do not define " \ + "HPy_mod_create slot and let the runtime create a builtin " \ + "module object from the provided HPyModuleDef, or do not define " \ + "anything else but the HPy_mod_create slot." + static PyModuleDef empty_moduledef = { PyModuleDef_HEAD_INIT }; -_HPy_HIDDEN HPy -ctx_Module_Create(HPyContext *ctx, HPyModuleDef *hpydef) +static PyModuleDef_Slot* create_mod_slots(HPyModuleDef *hpydef, bool *found_create) { - // create a new PyModuleDef + size_t slots_count = 0; + bool found_non_create = false; + for (int i = 0; hpydef->defines[i] != NULL; i++) { + HPyDef *src = hpydef->defines[i]; + if (src->kind != HPyDef_Kind_Slot) { + found_non_create = true; + continue; + } + slots_count++; + if (src->slot.slot == HPy_mod_create) { + if (*found_create) { + PyErr_SetString(PyExc_SystemError, "Multiple definitions " + "of the HPy_mod_create " + "slot in HPyModuleDef.defines."); + return NULL; + } + *found_create = true; + } else if (src->slot.slot != HPy_mod_exec) { + PyErr_Format(PyExc_SystemError, "Unsupported slot in " + "HPyModuleDef.defines (value: %d).", + (int) src->slot.slot); + return NULL; + } else { + assert(src->slot.slot == HPy_mod_exec); + found_non_create = true; + } + } + if (*found_create && found_non_create) { + PyErr_Format(PyExc_SystemError, + "HPyModuleDef defines a HPy_mod_create slot and some other " + "slots or methods. " NON_DEFAULT_MESSAGE); + return NULL; + } + + PyModuleDef_Slot* m_slots = (PyModuleDef_Slot*)PyMem_Calloc( + slots_count + 1, sizeof(PyModuleDef_Slot)); + m_slots[slots_count].slot = 0; + m_slots[slots_count].value = NULL; + size_t slot_index = 0; + for (int i = 0; hpydef->defines[i] != NULL; i++) { + HPyDef *src = hpydef->defines[i]; + if (src->kind != HPyDef_Kind_Slot) + continue; + int py_slot; + if (src->slot.slot == HPy_mod_create) { + py_slot = Py_mod_create; + } else { + assert(src->slot.slot == HPy_mod_exec); + py_slot = Py_mod_exec; + } + m_slots[slot_index].slot = py_slot; + m_slots[slot_index].value = (void*) src->slot.cpy_trampoline; + slot_index++; + } + return m_slots; +} - // we can't free this memory because it is stitched into moduleobject. We - // just make it immortal for now, eventually we should think whether or - // not to free it if/when we unload the module +_HPy_HIDDEN PyModuleDef* +_HPyModuleDef_CreatePyModuleDef(HPyModuleDef *hpydef) +{ PyModuleDef *def = (PyModuleDef*)PyMem_Malloc(sizeof(PyModuleDef)); if (def == NULL) { PyErr_NoMemory(); - return HPy_NULL; + return NULL; } memcpy(def, &empty_moduledef, sizeof(PyModuleDef)); - def->m_name = hpydef->name; def->m_doc = hpydef->doc; - def->m_size = hpydef->size; + if (hpydef->size < 0) { + PyErr_SetString(PyExc_SystemError, "HPy does not permit " + "HPyModuleDef.size < 0"); + goto error; + } else if (hpydef->size > 0) { + // GH-328 + PyErr_SetString(PyExc_SystemError, "Module state is not supported yet " + "in HPy, set HPyModuleDef.size = 0 " + "if module state is not needed"); + goto error; + } + def->m_methods = create_method_defs(hpydef->defines, hpydef->legacy_methods); if (def->m_methods == NULL) { + goto error; + } + + if (hpydef->defines != NULL) { + bool found_create = false; + def->m_slots = create_mod_slots(hpydef, &found_create); + if (def->m_slots == NULL) { + goto error; + } + if (found_create && (hpydef->legacy_methods || hpydef->size > 0 || + hpydef->doc != NULL || hpydef->globals != NULL)) { + PyErr_Format(PyExc_SystemError, + "HPyModuleDef defines a HPy_mod_create slot and some " + "of the other fields are not set to their default " + "value. " NON_DEFAULT_MESSAGE); + goto error; + } + } + + return def; +error: + if (def != NULL) { PyMem_Free(def); - return HPy_NULL; } - PyObject *result = PyModule_Create(def); - return _py2h(result); + return NULL; +} + +_HPy_HIDDEN PyObject* +_HPyModuleDef_AsPyInit(HPyModuleDef *hpydef) +{ + PyModuleDef *def = _HPyModuleDef_CreatePyModuleDef(hpydef); + if (def == NULL) { + return NULL; + } + return PyModuleDef_Init(def); +} + +_HPy_HIDDEN void +_HPyModule_CheckCreateSlotResult(PyObject **result) +{ + if (*result != NULL && PyModule_Check(*result)) { + PyErr_SetString(PyExc_SystemError, + "HPy_mod_create slot returned a builtin module object. " + "This is currently not supported."); + *result = NULL; + } } diff --git a/hpy/tools/autogen/hpyfunc.py b/hpy/tools/autogen/hpyfunc.py index 64fbe943e..6089d47e9 100644 --- a/hpy/tools/autogen/hpyfunc.py +++ b/hpy/tools/autogen/hpyfunc.py @@ -4,7 +4,7 @@ from .parse import toC, find_typedecl NO_CALL = ('NOARGS', 'O', 'VARARGS', 'KEYWORDS', 'INITPROC', 'DESTROYFUNC', - 'GETBUFFERPROC', 'RELEASEBUFFERPROC', 'TRAVERSEPROC') + 'GETBUFFERPROC', 'RELEASEBUFFERPROC', 'TRAVERSEPROC', 'MOD_CREATE') NO_TRAMPOLINE = NO_CALL + ('RICHCMPFUNC',) class autogen_hpyfunc_declare_h(AutoGenFile): @@ -20,6 +20,8 @@ def generate(self): # declare a function named 'SYM' of the appropriate type funcdecl = hpyfunc.node.type.type symdecl = deepcopy(funcdecl) + if isinstance(symdecl.type, c_ast.PtrDecl): + symdecl.type = symdecl.type.type symdecl.type.declname = 'SYM' symdecl = toC(symdecl) # @@ -55,9 +57,11 @@ def generate(self): continue # tramp_node = deepcopy(hpyfunc.node.type.type) + if isinstance(tramp_node.type, c_ast.PtrDecl): + tramp_node.type = tramp_node.type.type tramp_node.type.declname = 'SYM' tramp_node = hpy_to_cpy(tramp_node) - assert toC(tramp_node.args.params[0].type) == 'HPyContext *' + assert toC(tramp_node.args.params[0].type) in ['void', 'HPyContext *'] tramp_node.args.params = [hpy_to_cpy(p) for p in tramp_node.args.params[1:]] for i, param in enumerate(tramp_node.args.params): @@ -144,6 +148,8 @@ def generate(self): continue # tramp_node = deepcopy(hpyfunc.node.type.type) + if isinstance(tramp_node.type, c_ast.PtrDecl): + tramp_node.type = tramp_node.type.type tramp_node.type.declname = 'SYM' tramp_node = hpy_to_cpy(tramp_node) tramp_node.args.params = [hpy_to_cpy(p) diff --git a/hpy/tools/autogen/public_api.h b/hpy/tools/autogen/public_api.h index 250d51edc..8dee35940 100644 --- a/hpy/tools/autogen/public_api.h +++ b/hpy/tools/autogen/public_api.h @@ -96,154 +96,152 @@ HPy_ID(73) HPy h_FloatType; /* built-in 'float' */ HPy_ID(74) HPy h_UnicodeType; /* built-in 'str' */ HPy_ID(75) HPy h_TupleType; /* built-in 'tuple' */ HPy_ID(76) HPy h_ListType; /* built-in 'list' */ -HPy_ID(239) HPy h_ComplexType; /* built-in 'complex' */ -HPy_ID(240) HPy h_BytesType; /* built-in 'bytes' */ -HPy_ID(241) HPy h_MemoryViewType; /* built-in 'memoryview' */ -HPy_ID(242) HPy h_CapsuleType; /* built-in 'capsule' */ -HPy_ID(243) HPy h_SliceType; /* built-in 'slice' */ +HPy_ID(238) HPy h_ComplexType; /* built-in 'complex' */ +HPy_ID(239) HPy h_BytesType; /* built-in 'bytes' */ +HPy_ID(240) HPy h_MemoryViewType; /* built-in 'memoryview' */ +HPy_ID(241) HPy h_CapsuleType; /* built-in 'capsule' */ +HPy_ID(242) HPy h_SliceType; /* built-in 'slice' */ /* Reflection */ -HPy_ID(244) HPy h_Builtins; /* dict of builtins */ +HPy_ID(243) HPy h_Builtins; /* dict of builtins */ #endif HPy_ID(77) -HPy HPyModule_Create(HPyContext *ctx, HPyModuleDef *def); -HPy_ID(78) HPy HPy_Dup(HPyContext *ctx, HPy h); -HPy_ID(79) +HPy_ID(78) void HPy_Close(HPyContext *ctx, HPy h); -HPy_ID(80) +HPy_ID(79) HPy HPyLong_FromInt32_t(HPyContext *ctx, int32_t value); -HPy_ID(81) +HPy_ID(80) HPy HPyLong_FromUInt32_t(HPyContext *ctx, uint32_t value); -HPy_ID(82) +HPy_ID(81) HPy HPyLong_FromInt64_t(HPyContext *ctx, int64_t v); -HPy_ID(83) +HPy_ID(82) HPy HPyLong_FromUInt64_t(HPyContext *ctx, uint64_t v); -HPy_ID(84) +HPy_ID(83) HPy HPyLong_FromSize_t(HPyContext *ctx, size_t value); -HPy_ID(85) +HPy_ID(84) HPy HPyLong_FromSsize_t(HPyContext *ctx, HPy_ssize_t value); -HPy_ID(86) +HPy_ID(85) int32_t HPyLong_AsInt32_t(HPyContext *ctx, HPy h); -HPy_ID(87) +HPy_ID(86) uint32_t HPyLong_AsUInt32_t(HPyContext *ctx, HPy h); -HPy_ID(88) +HPy_ID(87) uint32_t HPyLong_AsUInt32_tMask(HPyContext *ctx, HPy h); -HPy_ID(89) +HPy_ID(88) int64_t HPyLong_AsInt64_t(HPyContext *ctx, HPy h); -HPy_ID(90) +HPy_ID(89) uint64_t HPyLong_AsUInt64_t(HPyContext *ctx, HPy h); -HPy_ID(91) +HPy_ID(90) uint64_t HPyLong_AsUInt64_tMask(HPyContext *ctx, HPy h); -HPy_ID(92) +HPy_ID(91) size_t HPyLong_AsSize_t(HPyContext *ctx, HPy h); -HPy_ID(93) +HPy_ID(92) HPy_ssize_t HPyLong_AsSsize_t(HPyContext *ctx, HPy h); -HPy_ID(94) +HPy_ID(93) void* HPyLong_AsVoidPtr(HPyContext *ctx, HPy h); -HPy_ID(95) +HPy_ID(94) double HPyLong_AsDouble(HPyContext *ctx, HPy h); -HPy_ID(96) +HPy_ID(95) HPy HPyFloat_FromDouble(HPyContext *ctx, double v); -HPy_ID(97) +HPy_ID(96) double HPyFloat_AsDouble(HPyContext *ctx, HPy h); -HPy_ID(98) +HPy_ID(97) HPy HPyBool_FromBool(HPyContext *ctx, bool v); /* abstract.h */ -HPy_ID(99) +HPy_ID(98) HPy_ssize_t HPy_Length(HPyContext *ctx, HPy h); -HPy_ID(100) +HPy_ID(99) int HPyNumber_Check(HPyContext *ctx, HPy h); -HPy_ID(101) +HPy_ID(100) HPy HPy_Add(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(102) +HPy_ID(101) HPy HPy_Subtract(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(103) +HPy_ID(102) HPy HPy_Multiply(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(104) +HPy_ID(103) HPy HPy_MatrixMultiply(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(105) +HPy_ID(104) HPy HPy_FloorDivide(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(106) +HPy_ID(105) HPy HPy_TrueDivide(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(107) +HPy_ID(106) HPy HPy_Remainder(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(108) +HPy_ID(107) HPy HPy_Divmod(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(109) +HPy_ID(108) HPy HPy_Power(HPyContext *ctx, HPy h1, HPy h2, HPy h3); -HPy_ID(110) +HPy_ID(109) HPy HPy_Negative(HPyContext *ctx, HPy h1); -HPy_ID(111) +HPy_ID(110) HPy HPy_Positive(HPyContext *ctx, HPy h1); -HPy_ID(112) +HPy_ID(111) HPy HPy_Absolute(HPyContext *ctx, HPy h1); -HPy_ID(113) +HPy_ID(112) HPy HPy_Invert(HPyContext *ctx, HPy h1); -HPy_ID(114) +HPy_ID(113) HPy HPy_Lshift(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(115) +HPy_ID(114) HPy HPy_Rshift(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(116) +HPy_ID(115) HPy HPy_And(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(117) +HPy_ID(116) HPy HPy_Xor(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(118) +HPy_ID(117) HPy HPy_Or(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(119) +HPy_ID(118) HPy HPy_Index(HPyContext *ctx, HPy h1); -HPy_ID(120) +HPy_ID(119) HPy HPy_Long(HPyContext *ctx, HPy h1); -HPy_ID(121) +HPy_ID(120) HPy HPy_Float(HPyContext *ctx, HPy h1); -HPy_ID(122) +HPy_ID(121) HPy HPy_InPlaceAdd(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(123) +HPy_ID(122) HPy HPy_InPlaceSubtract(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(124) +HPy_ID(123) HPy HPy_InPlaceMultiply(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(125) +HPy_ID(124) HPy HPy_InPlaceMatrixMultiply(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(126) +HPy_ID(125) HPy HPy_InPlaceFloorDivide(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(127) +HPy_ID(126) HPy HPy_InPlaceTrueDivide(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(128) +HPy_ID(127) HPy HPy_InPlaceRemainder(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(129) +HPy_ID(128) HPy HPy_InPlacePower(HPyContext *ctx, HPy h1, HPy h2, HPy h3); -HPy_ID(130) +HPy_ID(129) HPy HPy_InPlaceLshift(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(131) +HPy_ID(130) HPy HPy_InPlaceRshift(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(132) +HPy_ID(131) HPy HPy_InPlaceAnd(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(133) +HPy_ID(132) HPy HPy_InPlaceXor(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(134) +HPy_ID(133) HPy HPy_InPlaceOr(HPyContext *ctx, HPy h1, HPy h2); -HPy_ID(135) +HPy_ID(134) int HPyCallable_Check(HPyContext *ctx, HPy h); -HPy_ID(136) +HPy_ID(135) HPy HPy_CallTupleDict(HPyContext *ctx, HPy callable, HPy args, HPy kw); /* pyerrors.h */ -HPy_ID(137) +HPy_ID(136) void HPy_FatalError(HPyContext *ctx, const char *message); -HPy_ID(138) +HPy_ID(137) HPy HPyErr_SetString(HPyContext *ctx, HPy h_type, const char *utf8_message); -HPy_ID(139) +HPy_ID(138) HPy HPyErr_SetObject(HPyContext *ctx, HPy h_type, HPy h_value); /** @@ -261,7 +259,7 @@ HPy HPyErr_SetObject(HPyContext *ctx, HPy h_type, HPy h_value); * :return: * always returns ``HPy_NULL`` */ -HPy_ID(140) +HPy_ID(139) HPy HPyErr_SetFromErrnoWithFilename(HPyContext *ctx, HPy h_type, const char *filename_fsencoded); /** @@ -285,28 +283,28 @@ HPy HPyErr_SetFromErrnoWithFilename(HPyContext *ctx, HPy h_type, const char *fil * :return: * always returns ``HPy_NULL`` */ -HPy_ID(141) +HPy_ID(140) HPy HPyErr_SetFromErrnoWithFilenameObjects(HPyContext *ctx, HPy h_type, HPy filename1, HPy filename2); /* note: HPyErr_Occurred() returns a flag 0-or-1, instead of a 'PyObject *' */ -HPy_ID(142) +HPy_ID(141) int HPyErr_Occurred(HPyContext *ctx); -HPy_ID(143) +HPy_ID(142) int HPyErr_ExceptionMatches(HPyContext *ctx, HPy exc); -HPy_ID(144) +HPy_ID(143) HPy HPyErr_NoMemory(HPyContext *ctx); -HPy_ID(145) +HPy_ID(144) void HPyErr_Clear(HPyContext *ctx); -HPy_ID(146) +HPy_ID(145) HPy HPyErr_NewException(HPyContext *ctx, const char *utf8_name, HPy base, HPy dict); -HPy_ID(147) +HPy_ID(146) HPy HPyErr_NewExceptionWithDoc(HPyContext *ctx, const char *utf8_name, const char *utf8_doc, HPy base, HPy dict); -HPy_ID(148) +HPy_ID(147) int HPyErr_WarnEx(HPyContext *ctx, HPy category, const char *utf8_message, HPy_ssize_t stack_level); -HPy_ID(149) +HPy_ID(148) void HPyErr_WriteUnraisable(HPyContext *ctx, HPy obj); /* object.h */ -HPy_ID(150) +HPy_ID(149) int HPy_IsTrue(HPyContext *ctx, HPy h); /** @@ -322,186 +320,186 @@ int HPy_IsTrue(HPyContext *ctx, HPy h); * * :returns: a handle of the created type on success, ``HPy_NULL`` on failure. */ -HPy_ID(151) +HPy_ID(150) HPy HPyType_FromSpec(HPyContext *ctx, HPyType_Spec *spec, HPyType_SpecParam *params); -HPy_ID(152) +HPy_ID(151) HPy HPyType_GenericNew(HPyContext *ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw); -HPy_ID(153) +HPy_ID(152) HPy HPy_GetAttr(HPyContext *ctx, HPy obj, HPy name); -HPy_ID(154) +HPy_ID(153) HPy HPy_GetAttr_s(HPyContext *ctx, HPy obj, const char *utf8_name); -HPy_ID(155) +HPy_ID(154) int HPy_HasAttr(HPyContext *ctx, HPy obj, HPy name); -HPy_ID(156) +HPy_ID(155) int HPy_HasAttr_s(HPyContext *ctx, HPy obj, const char *utf8_name); -HPy_ID(157) +HPy_ID(156) int HPy_SetAttr(HPyContext *ctx, HPy obj, HPy name, HPy value); -HPy_ID(158) +HPy_ID(157) int HPy_SetAttr_s(HPyContext *ctx, HPy obj, const char *utf8_name, HPy value); -HPy_ID(159) +HPy_ID(158) HPy HPy_GetItem(HPyContext *ctx, HPy obj, HPy key); -HPy_ID(160) +HPy_ID(159) HPy HPy_GetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx); -HPy_ID(161) +HPy_ID(160) HPy HPy_GetItem_s(HPyContext *ctx, HPy obj, const char *utf8_key); -HPy_ID(162) +HPy_ID(161) int HPy_Contains(HPyContext *ctx, HPy container, HPy key); -HPy_ID(163) +HPy_ID(162) int HPy_SetItem(HPyContext *ctx, HPy obj, HPy key, HPy value); -HPy_ID(164) +HPy_ID(163) int HPy_SetItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx, HPy value); -HPy_ID(165) +HPy_ID(164) int HPy_SetItem_s(HPyContext *ctx, HPy obj, const char *utf8_key, HPy value); -HPy_ID(236) +HPy_ID(235) int HPy_DelItem(HPyContext *ctx, HPy obj, HPy key); -HPy_ID(237) +HPy_ID(236) int HPy_DelItem_i(HPyContext *ctx, HPy obj, HPy_ssize_t idx); -HPy_ID(238) +HPy_ID(237) int HPy_DelItem_s(HPyContext *ctx, HPy obj, const char *utf8_key); -HPy_ID(166) +HPy_ID(165) HPy HPy_Type(HPyContext *ctx, HPy obj); // WARNING: HPy_TypeCheck could be tweaked/removed in the future, see issue #160 -HPy_ID(167) +HPy_ID(166) int HPy_TypeCheck(HPyContext *ctx, HPy obj, HPy type); -HPy_ID(168) +HPy_ID(167) int HPy_Is(HPyContext *ctx, HPy obj, HPy other); -HPy_ID(169) +HPy_ID(168) void* _HPy_AsStruct_Object(HPyContext *ctx, HPy h); -HPy_ID(170) +HPy_ID(169) void* _HPy_AsStruct_Legacy(HPyContext *ctx, HPy h); -HPy_ID(229) +HPy_ID(228) void* _HPy_AsStruct_Type(HPyContext *ctx, HPy h); -HPy_ID(230) +HPy_ID(229) void* _HPy_AsStruct_Long(HPyContext *ctx, HPy h); -HPy_ID(231) +HPy_ID(230) void* _HPy_AsStruct_Float(HPyContext *ctx, HPy h); -HPy_ID(232) +HPy_ID(231) void* _HPy_AsStruct_Unicode(HPyContext *ctx, HPy h); -HPy_ID(233) +HPy_ID(232) void* _HPy_AsStruct_Tuple(HPyContext *ctx, HPy h); -HPy_ID(234) +HPy_ID(233) void* _HPy_AsStruct_List(HPyContext *ctx, HPy h); -HPy_ID(235) +HPy_ID(234) HPyType_BuiltinShape _HPyType_GetBuiltinShape(HPyContext *ctx, HPy h_type); -HPy_ID(171) +HPy_ID(170) HPy _HPy_New(HPyContext *ctx, HPy h_type, void **data); -HPy_ID(172) +HPy_ID(171) HPy HPy_Repr(HPyContext *ctx, HPy obj); -HPy_ID(173) +HPy_ID(172) HPy HPy_Str(HPyContext *ctx, HPy obj); -HPy_ID(174) +HPy_ID(173) HPy HPy_ASCII(HPyContext *ctx, HPy obj); -HPy_ID(175) +HPy_ID(174) HPy HPy_Bytes(HPyContext *ctx, HPy obj); -HPy_ID(176) +HPy_ID(175) HPy HPy_RichCompare(HPyContext *ctx, HPy v, HPy w, int op); -HPy_ID(177) +HPy_ID(176) int HPy_RichCompareBool(HPyContext *ctx, HPy v, HPy w, int op); -HPy_ID(178) +HPy_ID(177) HPy_hash_t HPy_Hash(HPyContext *ctx, HPy obj); /* bytesobject.h */ -HPy_ID(179) +HPy_ID(178) int HPyBytes_Check(HPyContext *ctx, HPy h); -HPy_ID(180) +HPy_ID(179) HPy_ssize_t HPyBytes_Size(HPyContext *ctx, HPy h); -HPy_ID(181) +HPy_ID(180) HPy_ssize_t HPyBytes_GET_SIZE(HPyContext *ctx, HPy h); -HPy_ID(182) +HPy_ID(181) const char* HPyBytes_AsString(HPyContext *ctx, HPy h); -HPy_ID(183) +HPy_ID(182) const char* HPyBytes_AS_STRING(HPyContext *ctx, HPy h); -HPy_ID(184) +HPy_ID(183) HPy HPyBytes_FromString(HPyContext *ctx, const char *bytes); -HPy_ID(185) +HPy_ID(184) HPy HPyBytes_FromStringAndSize(HPyContext *ctx, const char *bytes, HPy_ssize_t len); /* unicodeobject.h */ -HPy_ID(186) +HPy_ID(185) HPy HPyUnicode_FromString(HPyContext *ctx, const char *utf8); -HPy_ID(187) +HPy_ID(186) int HPyUnicode_Check(HPyContext *ctx, HPy h); -HPy_ID(188) +HPy_ID(187) HPy HPyUnicode_AsASCIIString(HPyContext *ctx, HPy h); -HPy_ID(189) +HPy_ID(188) HPy HPyUnicode_AsLatin1String(HPyContext *ctx, HPy h); -HPy_ID(190) +HPy_ID(189) HPy HPyUnicode_AsUTF8String(HPyContext *ctx, HPy h); -HPy_ID(191) +HPy_ID(190) const char* HPyUnicode_AsUTF8AndSize(HPyContext *ctx, HPy h, HPy_ssize_t *size); -HPy_ID(192) +HPy_ID(191) HPy HPyUnicode_FromWideChar(HPyContext *ctx, const wchar_t *w, HPy_ssize_t size); -HPy_ID(193) +HPy_ID(192) HPy HPyUnicode_DecodeFSDefault(HPyContext *ctx, const char *v); -HPy_ID(194) +HPy_ID(193) HPy HPyUnicode_DecodeFSDefaultAndSize(HPyContext *ctx, const char *v, HPy_ssize_t size); -HPy_ID(195) +HPy_ID(194) HPy HPyUnicode_EncodeFSDefault(HPyContext *ctx, HPy h); -HPy_ID(196) +HPy_ID(195) HPy_UCS4 HPyUnicode_ReadChar(HPyContext *ctx, HPy h, HPy_ssize_t index); -HPy_ID(197) +HPy_ID(196) HPy HPyUnicode_DecodeASCII(HPyContext *ctx, const char *ascii, HPy_ssize_t size, const char *errors); -HPy_ID(198) +HPy_ID(197) HPy HPyUnicode_DecodeLatin1(HPyContext *ctx, const char *latin1, HPy_ssize_t size, const char *errors); /* listobject.h */ -HPy_ID(199) +HPy_ID(198) int HPyList_Check(HPyContext *ctx, HPy h); -HPy_ID(200) +HPy_ID(199) HPy HPyList_New(HPyContext *ctx, HPy_ssize_t len); -HPy_ID(201) +HPy_ID(200) int HPyList_Append(HPyContext *ctx, HPy h_list, HPy h_item); /* dictobject.h */ -HPy_ID(202) +HPy_ID(201) int HPyDict_Check(HPyContext *ctx, HPy h); -HPy_ID(203) +HPy_ID(202) HPy HPyDict_New(HPyContext *ctx); /* tupleobject.h */ -HPy_ID(204) +HPy_ID(203) int HPyTuple_Check(HPyContext *ctx, HPy h); -HPy_ID(205) +HPy_ID(204) HPy HPyTuple_FromArray(HPyContext *ctx, HPy items[], HPy_ssize_t n); // note: HPyTuple_Pack is implemented as a macro in common/macros.h /* import.h */ -HPy_ID(206) +HPy_ID(205) HPy HPyImport_ImportModule(HPyContext *ctx, const char *utf8_name); /* pycapsule.h */ -HPy_ID(245) +HPy_ID(244) HPy HPyCapsule_New(HPyContext *ctx, void *pointer, const char *utf8_name, HPyCapsule_Destructor *destructor); -HPy_ID(246) +HPy_ID(245) void* HPyCapsule_Get(HPyContext *ctx, HPy capsule, _HPyCapsule_key key, const char *utf8_name); -HPy_ID(247) +HPy_ID(246) int HPyCapsule_IsValid(HPyContext *ctx, HPy capsule, const char *utf8_name); -HPy_ID(248) +HPy_ID(247) int HPyCapsule_Set(HPyContext *ctx, HPy capsule, _HPyCapsule_key key, void *value); /* integration with the old CPython API */ -HPy_ID(207) +HPy_ID(206) HPy HPy_FromPyObject(HPyContext *ctx, cpy_PyObject *obj); -HPy_ID(208) +HPy_ID(207) cpy_PyObject *HPy_AsPyObject(HPyContext *ctx, HPy h); /* internal helpers which need to be exposed to modules for practical reasons :( */ -HPy_ID(209) +HPy_ID(208) void _HPy_CallRealFunctionFromTrampoline(HPyContext *ctx, HPyFunc_Signature sig, HPyCFunction func, @@ -519,7 +517,7 @@ void _HPy_CallRealFunctionFromTrampoline(HPyContext *ctx, * :param size: * The number of elements to hold. */ -HPy_ID(210) +HPy_ID(209) HPyListBuilder HPyListBuilder_New(HPyContext *ctx, HPy_ssize_t size); /** @@ -538,7 +536,7 @@ HPyListBuilder HPyListBuilder_New(HPyContext *ctx, HPy_ssize_t size); * HPy **never** steals handles and so, ``h_item`` needs to be closed by * the caller. */ -HPy_ID(211) +HPy_ID(210) void HPyListBuilder_Set(HPyContext *ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item); @@ -556,7 +554,7 @@ void HPyListBuilder_Set(HPyContext *ctx, HPyListBuilder builder, * during building or earlier when creating the builder or setting the * items. */ -HPy_ID(212) +HPy_ID(211) HPy HPyListBuilder_Build(HPyContext *ctx, HPyListBuilder builder); /** @@ -569,7 +567,7 @@ HPy HPyListBuilder_Build(HPyContext *ctx, HPyListBuilder builder); * :param builder: * A tuple builder handle. */ -HPy_ID(213) +HPy_ID(212) void HPyListBuilder_Cancel(HPyContext *ctx, HPyListBuilder builder); /** @@ -582,7 +580,7 @@ void HPyListBuilder_Cancel(HPyContext *ctx, HPyListBuilder builder); * :param size: * The number of elements to hold. */ -HPy_ID(214) +HPy_ID(213) HPyTupleBuilder HPyTupleBuilder_New(HPyContext *ctx, HPy_ssize_t size); /** @@ -601,7 +599,7 @@ HPyTupleBuilder HPyTupleBuilder_New(HPyContext *ctx, HPy_ssize_t size); * HPy **never** steals handles and so, ``h_item`` needs to be closed by * the caller. */ -HPy_ID(215) +HPy_ID(214) void HPyTupleBuilder_Set(HPyContext *ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item); @@ -619,7 +617,7 @@ void HPyTupleBuilder_Set(HPyContext *ctx, HPyTupleBuilder builder, * during building or earlier when creating the builder or setting the * items. */ -HPy_ID(216) +HPy_ID(215) HPy HPyTupleBuilder_Build(HPyContext *ctx, HPyTupleBuilder builder); /** @@ -632,18 +630,18 @@ HPy HPyTupleBuilder_Build(HPyContext *ctx, HPyTupleBuilder builder); * :param builder: * A tuple builder handle. */ -HPy_ID(217) +HPy_ID(216) void HPyTupleBuilder_Cancel(HPyContext *ctx, HPyTupleBuilder builder); /* Helper for correctly closing handles */ -HPy_ID(218) +HPy_ID(217) HPyTracker HPyTracker_New(HPyContext *ctx, HPy_ssize_t size); -HPy_ID(219) +HPy_ID(218) int HPyTracker_Add(HPyContext *ctx, HPyTracker ht, HPy h); -HPy_ID(220) +HPy_ID(219) void HPyTracker_ForgetAll(HPyContext *ctx, HPyTracker ht); -HPy_ID(221) +HPy_ID(220) void HPyTracker_Close(HPyContext *ctx, HPyTracker ht); /** @@ -678,9 +676,9 @@ void HPyTracker_Close(HPyContext *ctx, HPyTracker ht); * needs to add write and/or read barriers on the objects. They are ignored by * CPython but e.g. PyPy needs a write barrier. */ -HPy_ID(222) +HPy_ID(221) void HPyField_Store(HPyContext *ctx, HPy target_object, HPyField *target_field, HPy h); -HPy_ID(223) +HPy_ID(222) HPy HPyField_Load(HPyContext *ctx, HPy source_object, HPyField source_field); /** @@ -705,9 +703,9 @@ HPy HPyField_Load(HPyContext *ctx, HPy source_object, HPyField source_field); * HPy_BEGIN_LEAVE_PYTHON/HPy_END_LEAVE_PYTHON becomes equivalent to * Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS. */ -HPy_ID(224) +HPy_ID(223) void HPy_ReenterPythonExecution(HPyContext *ctx, HPyThreadState state); -HPy_ID(225) +HPy_ID(224) HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx); /** @@ -764,13 +762,13 @@ HPyThreadState HPy_LeavePythonExecution(HPyContext *ctx); * also be activated only by some runtime option, letting the HPy implementation * use more optimized HPyGlobal implementation otherwise. */ -HPy_ID(226) +HPy_ID(225) void HPyGlobal_Store(HPyContext *ctx, HPyGlobal *global, HPy h); -HPy_ID(227) +HPy_ID(226) HPy HPyGlobal_Load(HPyContext *ctx, HPyGlobal global); /* Debugging helpers */ -HPy_ID(228) +HPy_ID(227) void _HPy_Dump(HPyContext *ctx, HPy h); @@ -821,6 +819,9 @@ typedef void (*HPyFunc_destructor)(HPyContext *ctx, HPy); typedef void (*HPyFunc_destroyfunc)(void *); +// Note: separate type, because we need a different trampoline +typedef HPy (*HPyFunc_mod_create)(HPyContext *ctx, HPy); + /* ~~~ HPySlot_Slot ~~~ @@ -921,4 +922,20 @@ typedef enum { /* extra HPy slots */ HPy_tp_destroy = SLOT(1000, HPyFunc_DESTROYFUNC), + /** + * Module create slot: the function receives loader spec and should + * return an HPy handle representing the module. Currently, creating + * real module objects cannot be done by user code, so the only other + * useful thing that this slot can do is to create another object that + * can work as a module, such as SimpleNamespace. + */ + HPy_mod_create = SLOT(2000, HPyFunc_MOD_CREATE), + /** + * Module exec slot: the function receives module object that was created + * by the runtime from HPyModuleDef. This slot can do any initialization + * of the module, such as adding types. There can be multiple exec slots + * and they will be executed in the declaration order. + */ + HPy_mod_exec = SLOT(2001, HPyFunc_INQUIRY), + } HPySlot_Slot; diff --git a/hpy/tools/valgrind/hpy.supp b/hpy/tools/valgrind/hpy.supp index 2f82b3444..c1139552a 100644 --- a/hpy/tools/valgrind/hpy.supp +++ b/hpy/tools/valgrind/hpy.supp @@ -1,9 +1,9 @@ { - + <_HPyModuleDef_CreatePyModuleDef_leak> Memcheck:Leak match-leak-kinds: definite,indirect ... - fun:ctx_Module_Create + fun:_HPyModuleDef_CreatePyModuleDef ... } diff --git a/hpy/trace/src/_tracemod.c b/hpy/trace/src/_tracemod.c index f4a5f8748..e8bbb207e 100644 --- a/hpy/trace/src/_tracemod.c +++ b/hpy/trace/src/_tracemod.c @@ -199,15 +199,9 @@ static HPyDef *module_defines[] = { }; static HPyModuleDef moduledef = { - .name = "hpy.trace._trace", .doc = "HPy trace mode", - .size = -1, + .size = 0, .defines = module_defines }; - -HPy_MODINIT(_trace) -static HPy init__trace_impl(HPyContext *uctx) -{ - return HPyModule_Create(uctx, &moduledef); -} +HPy_MODINIT(_trace, moduledef) diff --git a/hpy/trace/src/autogen_trace_ctx_init.h b/hpy/trace/src/autogen_trace_ctx_init.h index fc000d9c4..f43b143eb 100644 --- a/hpy/trace/src/autogen_trace_ctx_init.h +++ b/hpy/trace/src/autogen_trace_ctx_init.h @@ -10,7 +10,6 @@ */ -HPy trace_ctx_Module_Create(HPyContext *tctx, HPyModuleDef *def); HPy trace_ctx_Dup(HPyContext *tctx, HPy h); void trace_ctx_Close(HPyContext *tctx, HPy h); HPy trace_ctx_Long_FromInt32_t(HPyContext *tctx, int32_t value); @@ -179,8 +178,8 @@ static inline void trace_ctx_init_info(HPyTraceInfo *info, HPyContext *uctx) { info->magic_number = HPY_TRACE_MAGIC; info->uctx = uctx; - info->call_counts = (uint64_t *)calloc(249, sizeof(uint64_t)); - info->durations = (_HPyTime_t *)calloc(249, sizeof(_HPyTime_t)); + info->call_counts = (uint64_t *)calloc(248, sizeof(uint64_t)); + info->durations = (_HPyTime_t *)calloc(248, sizeof(_HPyTime_t)); info->on_enter_func = HPy_NULL; info->on_exit_func = HPy_NULL; } @@ -279,7 +278,6 @@ static inline void trace_ctx_init_fields(HPyContext *tctx, HPyContext *uctx) tctx->h_CapsuleType = uctx->h_CapsuleType; tctx->h_SliceType = uctx->h_SliceType; tctx->h_Builtins = uctx->h_Builtins; - tctx->ctx_Module_Create = &trace_ctx_Module_Create; tctx->ctx_Dup = &trace_ctx_Dup; tctx->ctx_Close = &trace_ctx_Close; tctx->ctx_Long_FromInt32_t = &trace_ctx_Long_FromInt32_t; diff --git a/hpy/trace/src/autogen_trace_func_table.c b/hpy/trace/src/autogen_trace_func_table.c index 7d8bb3e7d..74750abb0 100644 --- a/hpy/trace/src/autogen_trace_func_table.c +++ b/hpy/trace/src/autogen_trace_func_table.c @@ -12,7 +12,7 @@ #include "trace_internal.h" -#define TRACE_NFUNC 166 +#define TRACE_NFUNC 165 #define NO_FUNC "" static const char *trace_func_table[] = { @@ -93,7 +93,6 @@ static const char *trace_func_table[] = { NO_FUNC, NO_FUNC, NO_FUNC, - "ctx_Module_Create", "ctx_Dup", "ctx_Close", "ctx_Long_FromInt32_t", @@ -275,7 +274,7 @@ int hpy_trace_get_nfunc(void) const char * hpy_trace_get_func_name(int idx) { - if (idx >= 0 && idx < 249) + if (idx >= 0 && idx < 248) return trace_func_table[idx]; return NULL; } diff --git a/hpy/trace/src/autogen_trace_wrappers.c b/hpy/trace/src/autogen_trace_wrappers.c index 5a504d209..1aec00c9c 100644 --- a/hpy/trace/src/autogen_trace_wrappers.c +++ b/hpy/trace/src/autogen_trace_wrappers.c @@ -12,2118 +12,2105 @@ #include "trace_internal.h" -HPy trace_ctx_Module_Create(HPyContext *tctx, HPyModuleDef *def) -{ - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 77); - HPyContext *uctx = info->uctx; - _HPyTime_t _ts_start, _ts_end; - _HPyClockStatus_t r0, r1; - r0 = get_monotonic_clock(&_ts_start); - HPy res = HPyModule_Create(uctx, def); - r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 77, r0, r1, &_ts_start, &_ts_end); - return res; -} - HPy trace_ctx_Dup(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 78); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 77); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Dup(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 78, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 77, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Close(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 79); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 78); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_Close(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 79, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 78, r0, r1, &_ts_start, &_ts_end); } HPy trace_ctx_Long_FromInt32_t(HPyContext *tctx, int32_t value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 80); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 79); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyLong_FromInt32_t(uctx, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 80, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 79, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Long_FromUInt32_t(HPyContext *tctx, uint32_t value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 81); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 80); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyLong_FromUInt32_t(uctx, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 81, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 80, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Long_FromInt64_t(HPyContext *tctx, int64_t v) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 82); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 81); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyLong_FromInt64_t(uctx, v); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 82, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 81, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Long_FromUInt64_t(HPyContext *tctx, uint64_t v) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 83); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 82); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyLong_FromUInt64_t(uctx, v); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 83, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 82, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Long_FromSize_t(HPyContext *tctx, size_t value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 84); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 83); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyLong_FromSize_t(uctx, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 84, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 83, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Long_FromSsize_t(HPyContext *tctx, HPy_ssize_t value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 85); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 84); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyLong_FromSsize_t(uctx, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 85, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 84, r0, r1, &_ts_start, &_ts_end); return res; } int32_t trace_ctx_Long_AsInt32_t(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 86); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 85); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int32_t res = HPyLong_AsInt32_t(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 86, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 85, r0, r1, &_ts_start, &_ts_end); return res; } uint32_t trace_ctx_Long_AsUInt32_t(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 87); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 86); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); uint32_t res = HPyLong_AsUInt32_t(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 87, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 86, r0, r1, &_ts_start, &_ts_end); return res; } uint32_t trace_ctx_Long_AsUInt32_tMask(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 88); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 87); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); uint32_t res = HPyLong_AsUInt32_tMask(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 88, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 87, r0, r1, &_ts_start, &_ts_end); return res; } int64_t trace_ctx_Long_AsInt64_t(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 89); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 88); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int64_t res = HPyLong_AsInt64_t(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 89, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 88, r0, r1, &_ts_start, &_ts_end); return res; } uint64_t trace_ctx_Long_AsUInt64_t(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 90); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 89); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); uint64_t res = HPyLong_AsUInt64_t(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 90, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 89, r0, r1, &_ts_start, &_ts_end); return res; } uint64_t trace_ctx_Long_AsUInt64_tMask(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 91); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 90); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); uint64_t res = HPyLong_AsUInt64_tMask(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 91, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 90, r0, r1, &_ts_start, &_ts_end); return res; } size_t trace_ctx_Long_AsSize_t(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 92); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 91); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); size_t res = HPyLong_AsSize_t(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 92, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 91, r0, r1, &_ts_start, &_ts_end); return res; } HPy_ssize_t trace_ctx_Long_AsSsize_t(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 93); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 92); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_ssize_t res = HPyLong_AsSsize_t(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 93, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 92, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_Long_AsVoidPtr(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 94); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 93); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = HPyLong_AsVoidPtr(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 94, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 93, r0, r1, &_ts_start, &_ts_end); return res; } double trace_ctx_Long_AsDouble(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 95); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 94); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); double res = HPyLong_AsDouble(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 95, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 94, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Float_FromDouble(HPyContext *tctx, double v) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 96); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 95); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyFloat_FromDouble(uctx, v); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 96, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 95, r0, r1, &_ts_start, &_ts_end); return res; } double trace_ctx_Float_AsDouble(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 97); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 96); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); double res = HPyFloat_AsDouble(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 97, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 96, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Bool_FromBool(HPyContext *tctx, bool v) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 98); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 97); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyBool_FromBool(uctx, v); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 98, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 97, r0, r1, &_ts_start, &_ts_end); return res; } HPy_ssize_t trace_ctx_Length(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 99); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 98); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_ssize_t res = HPy_Length(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 99, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 98, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Number_Check(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 100); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 99); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyNumber_Check(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 100, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 99, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Add(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 101); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 100); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Add(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 101, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 100, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Subtract(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 102); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 101); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Subtract(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 102, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 101, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Multiply(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 103); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 102); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Multiply(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 103, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 102, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_MatrixMultiply(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 104); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 103); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_MatrixMultiply(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 104, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 103, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_FloorDivide(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 105); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 104); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_FloorDivide(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 105, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 104, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_TrueDivide(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 106); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 105); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_TrueDivide(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 106, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 105, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Remainder(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 107); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 106); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Remainder(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 107, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 106, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Divmod(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 108); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 107); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Divmod(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 108, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 107, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Power(HPyContext *tctx, HPy h1, HPy h2, HPy h3) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 109); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 108); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Power(uctx, h1, h2, h3); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 109, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 108, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Negative(HPyContext *tctx, HPy h1) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 110); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 109); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Negative(uctx, h1); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 110, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 109, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Positive(HPyContext *tctx, HPy h1) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 111); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 110); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Positive(uctx, h1); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 111, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 110, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Absolute(HPyContext *tctx, HPy h1) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 112); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 111); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Absolute(uctx, h1); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 112, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 111, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Invert(HPyContext *tctx, HPy h1) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 113); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 112); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Invert(uctx, h1); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 113, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 112, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Lshift(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 114); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 113); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Lshift(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 114, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 113, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Rshift(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 115); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 114); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Rshift(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 115, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 114, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_And(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 116); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 115); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_And(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 116, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 115, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Xor(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 117); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 116); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Xor(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 117, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 116, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Or(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 118); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 117); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Or(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 118, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 117, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Index(HPyContext *tctx, HPy h1) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 119); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 118); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Index(uctx, h1); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 119, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 118, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Long(HPyContext *tctx, HPy h1) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 120); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 119); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Long(uctx, h1); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 120, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 119, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Float(HPyContext *tctx, HPy h1) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 121); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 120); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Float(uctx, h1); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 121, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 120, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceAdd(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 122); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 121); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceAdd(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 122, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 121, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceSubtract(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 123); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 122); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceSubtract(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 123, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 122, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceMultiply(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 124); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 123); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceMultiply(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 124, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 123, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceMatrixMultiply(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 125); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 124); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceMatrixMultiply(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 125, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 124, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceFloorDivide(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 126); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 125); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceFloorDivide(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 126, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 125, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceTrueDivide(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 127); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 126); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceTrueDivide(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 127, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 126, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceRemainder(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 128); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 127); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceRemainder(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 128, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 127, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlacePower(HPyContext *tctx, HPy h1, HPy h2, HPy h3) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 129); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 128); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlacePower(uctx, h1, h2, h3); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 129, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 128, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceLshift(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 130); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 129); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceLshift(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 130, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 129, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceRshift(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 131); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 130); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceRshift(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 131, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 130, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceAnd(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 132); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 131); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceAnd(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 132, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 131, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceXor(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 133); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 132); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceXor(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 133, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 132, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_InPlaceOr(HPyContext *tctx, HPy h1, HPy h2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 134); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 133); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_InPlaceOr(uctx, h1, h2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 134, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 133, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Callable_Check(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 135); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 134); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyCallable_Check(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 135, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 134, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_CallTupleDict(HPyContext *tctx, HPy callable, HPy args, HPy kw) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 136); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 135); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_CallTupleDict(uctx, callable, args, kw); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 136, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 135, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Err_SetString(HPyContext *tctx, HPy h_type, const char *utf8_message) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 138); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 137); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyErr_SetString(uctx, h_type, utf8_message); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 138, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 137, r0, r1, &_ts_start, &_ts_end); } void trace_ctx_Err_SetObject(HPyContext *tctx, HPy h_type, HPy h_value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 139); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 138); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyErr_SetObject(uctx, h_type, h_value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 139, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 138, r0, r1, &_ts_start, &_ts_end); } HPy trace_ctx_Err_SetFromErrnoWithFilename(HPyContext *tctx, HPy h_type, const char *filename_fsencoded) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 140); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 139); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyErr_SetFromErrnoWithFilename(uctx, h_type, filename_fsencoded); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 140, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 139, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Err_SetFromErrnoWithFilenameObjects(HPyContext *tctx, HPy h_type, HPy filename1, HPy filename2) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 141); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 140); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyErr_SetFromErrnoWithFilenameObjects(uctx, h_type, filename1, filename2); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 141, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 140, r0, r1, &_ts_start, &_ts_end); } int trace_ctx_Err_Occurred(HPyContext *tctx) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 142); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 141); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyErr_Occurred(uctx); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 142, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 141, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Err_ExceptionMatches(HPyContext *tctx, HPy exc) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 143); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 142); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyErr_ExceptionMatches(uctx, exc); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 143, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 142, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Err_NoMemory(HPyContext *tctx) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 144); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 143); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyErr_NoMemory(uctx); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 144, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 143, r0, r1, &_ts_start, &_ts_end); } void trace_ctx_Err_Clear(HPyContext *tctx) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 145); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 144); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyErr_Clear(uctx); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 145, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 144, r0, r1, &_ts_start, &_ts_end); } HPy trace_ctx_Err_NewException(HPyContext *tctx, const char *utf8_name, HPy base, HPy dict) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 146); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 145); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyErr_NewException(uctx, utf8_name, base, dict); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 146, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 145, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Err_NewExceptionWithDoc(HPyContext *tctx, const char *utf8_name, const char *utf8_doc, HPy base, HPy dict) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 147); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 146); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyErr_NewExceptionWithDoc(uctx, utf8_name, utf8_doc, base, dict); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 147, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 146, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Err_WarnEx(HPyContext *tctx, HPy category, const char *utf8_message, HPy_ssize_t stack_level) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 148); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 147); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyErr_WarnEx(uctx, category, utf8_message, stack_level); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 148, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 147, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Err_WriteUnraisable(HPyContext *tctx, HPy obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 149); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 148); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyErr_WriteUnraisable(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 149, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 148, r0, r1, &_ts_start, &_ts_end); } int trace_ctx_IsTrue(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 150); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 149); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_IsTrue(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 150, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 149, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Type_FromSpec(HPyContext *tctx, HPyType_Spec *spec, HPyType_SpecParam *params) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 151); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 150); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyType_FromSpec(uctx, spec, params); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 151, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 150, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Type_GenericNew(HPyContext *tctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 152); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 151); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyType_GenericNew(uctx, type, args, nargs, kw); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 152, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 151, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_GetAttr(HPyContext *tctx, HPy obj, HPy name) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 153); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 152); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_GetAttr(uctx, obj, name); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 153, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 152, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_GetAttr_s(HPyContext *tctx, HPy obj, const char *utf8_name) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 154); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 153); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_GetAttr_s(uctx, obj, utf8_name); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 154, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 153, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_HasAttr(HPyContext *tctx, HPy obj, HPy name) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 155); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 154); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_HasAttr(uctx, obj, name); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 155, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 154, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_HasAttr_s(HPyContext *tctx, HPy obj, const char *utf8_name) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 156); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 155); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_HasAttr_s(uctx, obj, utf8_name); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 156, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 155, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_SetAttr(HPyContext *tctx, HPy obj, HPy name, HPy value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 157); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 156); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_SetAttr(uctx, obj, name, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 157, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 156, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_SetAttr_s(HPyContext *tctx, HPy obj, const char *utf8_name, HPy value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 158); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 157); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_SetAttr_s(uctx, obj, utf8_name, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 158, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 157, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_GetItem(HPyContext *tctx, HPy obj, HPy key) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 159); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 158); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_GetItem(uctx, obj, key); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 159, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 158, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_GetItem_i(HPyContext *tctx, HPy obj, HPy_ssize_t idx) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 160); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 159); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_GetItem_i(uctx, obj, idx); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 160, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 159, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_GetItem_s(HPyContext *tctx, HPy obj, const char *utf8_key) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 161); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 160); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_GetItem_s(uctx, obj, utf8_key); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 161, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 160, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Contains(HPyContext *tctx, HPy container, HPy key) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 162); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 161); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_Contains(uctx, container, key); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 162, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 161, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_SetItem(HPyContext *tctx, HPy obj, HPy key, HPy value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 163); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 162); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_SetItem(uctx, obj, key, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 163, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 162, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_SetItem_i(HPyContext *tctx, HPy obj, HPy_ssize_t idx, HPy value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 164); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 163); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_SetItem_i(uctx, obj, idx, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 164, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 163, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_SetItem_s(HPyContext *tctx, HPy obj, const char *utf8_key, HPy value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 165); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 164); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_SetItem_s(uctx, obj, utf8_key, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 165, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 164, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_DelItem(HPyContext *tctx, HPy obj, HPy key) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 236); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 235); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_DelItem(uctx, obj, key); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 236, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 235, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_DelItem_i(HPyContext *tctx, HPy obj, HPy_ssize_t idx) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 237); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 236); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_DelItem_i(uctx, obj, idx); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 237, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 236, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_DelItem_s(HPyContext *tctx, HPy obj, const char *utf8_key) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 238); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 237); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_DelItem_s(uctx, obj, utf8_key); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 238, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 237, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Type(HPyContext *tctx, HPy obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 166); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 165); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Type(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 166, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 165, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_TypeCheck(HPyContext *tctx, HPy obj, HPy type) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 167); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 166); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_TypeCheck(uctx, obj, type); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 167, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 166, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Is(HPyContext *tctx, HPy obj, HPy other) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 168); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 167); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_Is(uctx, obj, other); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 168, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 167, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_Object(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 169); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 168); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_Object(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 169, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 168, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_Legacy(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 170); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 169); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_Legacy(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 170, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 169, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_Type(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 229); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 228); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_Type(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 229, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 228, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_Long(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 230); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 229); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_Long(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 230, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 229, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_Float(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 231); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 230); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_Float(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 231, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 230, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_Unicode(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 232); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 231); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_Unicode(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 232, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 231, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_Tuple(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 233); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 232); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_Tuple(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 233, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 232, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_AsStruct_List(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 234); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 233); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = _HPy_AsStruct_List(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 234, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 233, r0, r1, &_ts_start, &_ts_end); return res; } HPyType_BuiltinShape trace_ctx_Type_GetBuiltinShape(HPyContext *tctx, HPy h_type) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 235); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 234); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyType_BuiltinShape res = _HPyType_GetBuiltinShape(uctx, h_type); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 235, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 234, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_New(HPyContext *tctx, HPy h_type, void **data) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 171); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 170); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = _HPy_New(uctx, h_type, data); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 171, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 170, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Repr(HPyContext *tctx, HPy obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 172); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 171); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Repr(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 172, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 171, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Str(HPyContext *tctx, HPy obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 173); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 172); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Str(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 173, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 172, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_ASCII(HPyContext *tctx, HPy obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 174); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 173); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_ASCII(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 174, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 173, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Bytes(HPyContext *tctx, HPy obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 175); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 174); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_Bytes(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 175, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 174, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_RichCompare(HPyContext *tctx, HPy v, HPy w, int op) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 176); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 175); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_RichCompare(uctx, v, w, op); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 176, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 175, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_RichCompareBool(HPyContext *tctx, HPy v, HPy w, int op) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 177); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 176); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPy_RichCompareBool(uctx, v, w, op); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 177, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 176, r0, r1, &_ts_start, &_ts_end); return res; } HPy_hash_t trace_ctx_Hash(HPyContext *tctx, HPy obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 178); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 177); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_hash_t res = HPy_Hash(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 178, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 177, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Bytes_Check(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 179); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 178); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyBytes_Check(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 179, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 178, r0, r1, &_ts_start, &_ts_end); return res; } HPy_ssize_t trace_ctx_Bytes_Size(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 180); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 179); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_ssize_t res = HPyBytes_Size(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 180, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 179, r0, r1, &_ts_start, &_ts_end); return res; } HPy_ssize_t trace_ctx_Bytes_GET_SIZE(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 181); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 180); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_ssize_t res = HPyBytes_GET_SIZE(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 181, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 180, r0, r1, &_ts_start, &_ts_end); return res; } const char *trace_ctx_Bytes_AsString(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 182); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 181); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); const char * res = HPyBytes_AsString(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 182, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 181, r0, r1, &_ts_start, &_ts_end); return res; } const char *trace_ctx_Bytes_AS_STRING(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 183); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 182); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); const char * res = HPyBytes_AS_STRING(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 183, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 182, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Bytes_FromString(HPyContext *tctx, const char *bytes) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 184); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 183); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyBytes_FromString(uctx, bytes); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 184, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 183, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Bytes_FromStringAndSize(HPyContext *tctx, const char *bytes, HPy_ssize_t len) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 185); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 184); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyBytes_FromStringAndSize(uctx, bytes, len); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 185, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 184, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_FromString(HPyContext *tctx, const char *utf8) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 186); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 185); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_FromString(uctx, utf8); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 186, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 185, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Unicode_Check(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 187); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 186); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyUnicode_Check(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 187, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 186, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_AsASCIIString(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 188); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 187); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_AsASCIIString(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 188, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 187, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_AsLatin1String(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 189); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 188); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_AsLatin1String(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 189, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 188, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_AsUTF8String(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 190); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 189); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_AsUTF8String(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 190, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 189, r0, r1, &_ts_start, &_ts_end); return res; } const char *trace_ctx_Unicode_AsUTF8AndSize(HPyContext *tctx, HPy h, HPy_ssize_t *size) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 191); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 190); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); const char * res = HPyUnicode_AsUTF8AndSize(uctx, h, size); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 191, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 190, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_FromWideChar(HPyContext *tctx, const wchar_t *w, HPy_ssize_t size) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 192); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 191); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_FromWideChar(uctx, w, size); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 192, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 191, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_DecodeFSDefault(HPyContext *tctx, const char *v) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 193); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 192); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_DecodeFSDefault(uctx, v); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 193, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 192, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_DecodeFSDefaultAndSize(HPyContext *tctx, const char *v, HPy_ssize_t size) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 194); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 193); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_DecodeFSDefaultAndSize(uctx, v, size); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 194, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 193, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_EncodeFSDefault(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 195); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 194); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_EncodeFSDefault(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 195, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 194, r0, r1, &_ts_start, &_ts_end); return res; } HPy_UCS4 trace_ctx_Unicode_ReadChar(HPyContext *tctx, HPy h, HPy_ssize_t index) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 196); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 195); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_UCS4 res = HPyUnicode_ReadChar(uctx, h, index); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 196, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 195, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_DecodeASCII(HPyContext *tctx, const char *ascii, HPy_ssize_t size, const char *errors) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 197); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 196); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_DecodeASCII(uctx, ascii, size, errors); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 197, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 196, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Unicode_DecodeLatin1(HPyContext *tctx, const char *latin1, HPy_ssize_t size, const char *errors) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 198); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 197); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyUnicode_DecodeLatin1(uctx, latin1, size, errors); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 198, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 197, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_List_Check(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 199); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 198); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyList_Check(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 199, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 198, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_List_New(HPyContext *tctx, HPy_ssize_t len) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 200); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 199); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyList_New(uctx, len); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 200, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 199, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_List_Append(HPyContext *tctx, HPy h_list, HPy h_item) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 201); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 200); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyList_Append(uctx, h_list, h_item); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 201, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 200, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Dict_Check(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 202); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 201); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyDict_Check(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 202, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 201, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Dict_New(HPyContext *tctx) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 203); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 202); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyDict_New(uctx); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 203, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 202, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Tuple_Check(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 204); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 203); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyTuple_Check(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 204, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 203, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Tuple_FromArray(HPyContext *tctx, HPy items[], HPy_ssize_t n) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 205); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 204); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyTuple_FromArray(uctx, items, n); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 205, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 204, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Import_ImportModule(HPyContext *tctx, const char *utf8_name) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 206); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 205); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyImport_ImportModule(uctx, utf8_name); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 206, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 205, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_Capsule_New(HPyContext *tctx, void *pointer, const char *utf8_name, HPyCapsule_Destructor *destructor) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 245); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 244); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyCapsule_New(uctx, pointer, utf8_name, destructor); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 245, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 244, r0, r1, &_ts_start, &_ts_end); return res; } void *trace_ctx_Capsule_Get(HPyContext *tctx, HPy capsule, _HPyCapsule_key key, const char *utf8_name) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 246); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 245); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); void * res = HPyCapsule_Get(uctx, capsule, key, utf8_name); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 246, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 245, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Capsule_IsValid(HPyContext *tctx, HPy capsule, const char *utf8_name) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 247); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 246); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyCapsule_IsValid(uctx, capsule, utf8_name); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 247, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 246, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Capsule_Set(HPyContext *tctx, HPy capsule, _HPyCapsule_key key, void *value) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 248); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 247); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyCapsule_Set(uctx, capsule, key, value); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 248, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 247, r0, r1, &_ts_start, &_ts_end); return res; } HPy trace_ctx_FromPyObject(HPyContext *tctx, cpy_PyObject *obj) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 207); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 206); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPy_FromPyObject(uctx, obj); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 207, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 206, r0, r1, &_ts_start, &_ts_end); return res; } cpy_PyObject *trace_ctx_AsPyObject(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 208); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 207); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); cpy_PyObject * res = HPy_AsPyObject(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 208, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 207, r0, r1, &_ts_start, &_ts_end); return res; } HPyListBuilder trace_ctx_ListBuilder_New(HPyContext *tctx, HPy_ssize_t size) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 210); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 209); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyListBuilder res = HPyListBuilder_New(uctx, size); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 210, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 209, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_ListBuilder_Set(HPyContext *tctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 211); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 210); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyListBuilder_Set(uctx, builder, index, h_item); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 211, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 210, r0, r1, &_ts_start, &_ts_end); } HPy trace_ctx_ListBuilder_Build(HPyContext *tctx, HPyListBuilder builder) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 212); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 211); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyListBuilder_Build(uctx, builder); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 212, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 211, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_ListBuilder_Cancel(HPyContext *tctx, HPyListBuilder builder) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 213); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 212); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyListBuilder_Cancel(uctx, builder); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 213, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 212, r0, r1, &_ts_start, &_ts_end); } HPyTupleBuilder trace_ctx_TupleBuilder_New(HPyContext *tctx, HPy_ssize_t size) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 214); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 213); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyTupleBuilder res = HPyTupleBuilder_New(uctx, size); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 214, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 213, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_TupleBuilder_Set(HPyContext *tctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 215); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 214); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyTupleBuilder_Set(uctx, builder, index, h_item); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 215, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 214, r0, r1, &_ts_start, &_ts_end); } HPy trace_ctx_TupleBuilder_Build(HPyContext *tctx, HPyTupleBuilder builder) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 216); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 215); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyTupleBuilder_Build(uctx, builder); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 216, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 215, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_TupleBuilder_Cancel(HPyContext *tctx, HPyTupleBuilder builder) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 217); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 216); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyTupleBuilder_Cancel(uctx, builder); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 217, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 216, r0, r1, &_ts_start, &_ts_end); } HPyTracker trace_ctx_Tracker_New(HPyContext *tctx, HPy_ssize_t size) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 218); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 217); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyTracker res = HPyTracker_New(uctx, size); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 218, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 217, r0, r1, &_ts_start, &_ts_end); return res; } int trace_ctx_Tracker_Add(HPyContext *tctx, HPyTracker ht, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 219); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 218); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); int res = HPyTracker_Add(uctx, ht, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 219, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 218, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Tracker_ForgetAll(HPyContext *tctx, HPyTracker ht) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 220); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 219); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyTracker_ForgetAll(uctx, ht); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 220, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 219, r0, r1, &_ts_start, &_ts_end); } void trace_ctx_Tracker_Close(HPyContext *tctx, HPyTracker ht) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 221); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 220); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyTracker_Close(uctx, ht); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 221, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 220, r0, r1, &_ts_start, &_ts_end); } void trace_ctx_Field_Store(HPyContext *tctx, HPy target_object, HPyField *target_field, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 222); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 221); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyField_Store(uctx, target_object, target_field, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 222, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 221, r0, r1, &_ts_start, &_ts_end); } HPy trace_ctx_Field_Load(HPyContext *tctx, HPy source_object, HPyField source_field) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 223); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 222); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyField_Load(uctx, source_object, source_field); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 223, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 222, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_ReenterPythonExecution(HPyContext *tctx, HPyThreadState state) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 224); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 223); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy_ReenterPythonExecution(uctx, state); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 224, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 223, r0, r1, &_ts_start, &_ts_end); } HPyThreadState trace_ctx_LeavePythonExecution(HPyContext *tctx) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 225); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 224); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyThreadState res = HPy_LeavePythonExecution(uctx); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 225, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 224, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Global_Store(HPyContext *tctx, HPyGlobal *global, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 226); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 225); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPyGlobal_Store(uctx, global, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 226, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 225, r0, r1, &_ts_start, &_ts_end); } HPy trace_ctx_Global_Load(HPyContext *tctx, HPyGlobal global) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 227); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 226); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); HPy res = HPyGlobal_Load(uctx, global); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 227, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 226, r0, r1, &_ts_start, &_ts_end); return res; } void trace_ctx_Dump(HPyContext *tctx, HPy h) { - HPyTraceInfo *info = hpy_trace_on_enter(tctx, 228); + HPyTraceInfo *info = hpy_trace_on_enter(tctx, 227); HPyContext *uctx = info->uctx; _HPyTime_t _ts_start, _ts_end; _HPyClockStatus_t r0, r1; r0 = get_monotonic_clock(&_ts_start); _HPy_Dump(uctx, h); r1 = get_monotonic_clock(&_ts_end); - hpy_trace_on_exit(info, 228, r0, r1, &_ts_start, &_ts_end); + hpy_trace_on_exit(info, 227, r0, r1, &_ts_start, &_ts_end); } diff --git a/hpy/trace/src/include/hpy_trace.h b/hpy/trace/src/include/hpy_trace.h index 9fbed67f8..e75b76186 100644 --- a/hpy/trace/src/include/hpy_trace.h +++ b/hpy/trace/src/include/hpy_trace.h @@ -31,6 +31,12 @@ const char * hpy_trace_get_func_name(int idx); extern "C" #endif HPy_EXPORTED_SYMBOL -HPy HPyInit__trace(HPyContext *uctx); +HPyModuleDef* HPyInit__trace(); + +#ifdef ___cplusplus +extern "C" +#endif +HPy_EXPORTED_SYMBOL +void HPyInitGlobalContext__trace(HPyContext *ctx); #endif /* HPY_TRACE_H */ diff --git a/hpy/universal/src/autogen_ctx_def.h b/hpy/universal/src/autogen_ctx_def.h index 8aae17197..350c25ae6 100644 --- a/hpy/universal/src/autogen_ctx_def.h +++ b/hpy/universal/src/autogen_ctx_def.h @@ -15,7 +15,6 @@ struct _HPyContext_s g_universal_ctx = { ._private = NULL, .abi_version = HPY_ABI_VERSION, /* h_None & co. are initialized by init_universal_ctx() */ - .ctx_Module_Create = &ctx_Module_Create, .ctx_Dup = &ctx_Dup, .ctx_Close = &ctx_Close, .ctx_Long_FromInt32_t = &ctx_Long_FromInt32_t, diff --git a/hpy/universal/src/ctx_meth.c b/hpy/universal/src/ctx_meth.c index 2739a0ba0..119672755 100644 --- a/hpy/universal/src/ctx_meth.c +++ b/hpy/universal/src/ctx_meth.c @@ -1,6 +1,7 @@ #include #include "ctx_meth.h" #include "hpy/runtime/ctx_type.h" +#include "hpy/runtime/ctx_module.h" #include "handles.h" static void _buffer_h2py(HPyContext *ctx, const HPy_buffer *src, Py_buffer *dest) @@ -120,6 +121,13 @@ ctx_CallRealFunctionFromTrampoline(HPyContext *ctx, HPyFunc_Signature sig, PyCapsule_GetContext(capsule)); return; } + case HPyFunc_MOD_CREATE: { + HPyFunc_unaryfunc f = (HPyFunc_unaryfunc)func; + _HPyFunc_args_UNARYFUNC *a = (_HPyFunc_args_UNARYFUNC*)args; + a->result = _h2py(f(ctx, _py2h(a->arg0))); + _HPyModule_CheckCreateSlotResult(&a->result); + return; + } #include "autogen_ctx_call.i" default: Py_FatalError("Unsupported HPyFunc_Signature in ctx_meth.c"); diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index f2798725a..761a04ee2 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -17,6 +17,7 @@ #include "hpy/version.h" #include "hpy_debug.h" #include "hpy_trace.h" +#include "hpy/runtime/ctx_module.h" #ifdef PYPY_VERSION # error "Cannot build hpy.universal on top of PyPy. PyPy comes with its own version of it" @@ -45,9 +46,12 @@ typedef enum { // MODE_TRACE_DEBUG = 4 } HPyMode; -typedef HPy (*InitFuncPtr)(HPyContext *ctx); +typedef uint32_t (*VersionGetterFuncPtr)(void); +typedef HPyModuleDef* (*InitFuncPtr)(void); +typedef void (*InitContextFuncPtr)(HPyContext*); -static const char *prefix = "HPyInit"; +static const char *init_prefix = "HPyInit"; +static const char *init_ctx_prefix = "HPyInitGlobalContext_"; static inline int _hpy_strncmp_ignore_case(const char *s0, const char *s1, size_t n) @@ -149,21 +153,28 @@ static bool validate_abi_tag(const char *shortname, const char *soname, return false; } -typedef uint32_t (*version_getter)(void); +static void dlsym_error(const char *soname, const char *symbol_name) { + const char *error = dlerror(); + if (error == NULL) + error = "no error message provided by the system"; + PyErr_Format(PyExc_RuntimeError, + "Error during loading of the HPy extension module at " + "path '%s' while trying to find symbol '%s'. Did you use" + "the HPy_MODINIT macro to register your module? Error " + "message from dlsym/WinAPI: %s", soname, symbol_name, error); +} -static PyObject *do_load(PyObject *name_unicode, PyObject *path, HPyMode mode) +static PyObject *do_load(PyObject *name_unicode, PyObject *path, HPyMode mode, PyObject *spec) { PyObject *name = NULL; PyObject *pathbytes = NULL; + PyModuleDef *pydef = NULL; + PyObject *py_mod = NULL; name = get_encoded_name(name_unicode); if (name == NULL) { goto error; } - const char *shortname = PyBytes_AS_STRING(name); - char init_name[258]; - PyOS_snprintf(init_name, sizeof(init_name), "%.20s_%.200s", - prefix, shortname); pathbytes = PyUnicode_EncodeFSDefault(path); if (pathbytes == NULL) @@ -181,11 +192,12 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path, HPyMode mode) goto error; } + const char *shortname = PyBytes_AS_STRING(name); char minor_version_symbol_name[258]; char major_version_symbol_name[258]; - PyOS_snprintf(minor_version_symbol_name, sizeof(init_name), + PyOS_snprintf(minor_version_symbol_name, sizeof(minor_version_symbol_name), "get_required_hpy_minor_version_%.200s", shortname); - PyOS_snprintf(major_version_symbol_name, sizeof(init_name), + PyOS_snprintf(major_version_symbol_name, sizeof(major_version_symbol_name), "get_required_hpy_major_version_%.200s", shortname); void *minor_version_ptr = dlsym(mylib, minor_version_symbol_name); void *major_version_ptr = dlsym(mylib, major_version_symbol_name); @@ -200,8 +212,8 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path, HPyMode mode) soname, minor_version_symbol_name, major_version_symbol_name, error); goto error; } - uint32_t required_minor_version = ((version_getter) minor_version_ptr)(); - uint32_t required_major_version = ((version_getter) major_version_ptr)(); + uint32_t required_minor_version = ((VersionGetterFuncPtr) minor_version_ptr)(); + uint32_t required_major_version = ((VersionGetterFuncPtr) major_version_ptr)(); if (required_major_version != HPY_ABI_VERSION || required_minor_version > HPY_ABI_VERSION_MINOR) { // For now, we have only one major version, but in the future at this // point we would decide which HPyContext to create @@ -218,32 +230,58 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path, HPyMode mode) goto error; } + HPyContext *ctx = get_context(mode); + if (ctx == NULL) + goto error; + + char init_ctx_name[258]; + PyOS_snprintf(init_ctx_name, sizeof(init_ctx_name), "%.20s_%.200s", + init_ctx_prefix, shortname); + void *initctxfn = dlsym(mylib, init_ctx_name); + if (initctxfn == NULL) { + dlsym_error(soname, init_ctx_name); + goto error; + } + ((InitContextFuncPtr)initctxfn)(ctx); + + char init_name[258]; + PyOS_snprintf(init_name, sizeof(init_name), "%.20s_%.200s", + init_prefix, shortname); void *initfn = dlsym(mylib, init_name); if (initfn == NULL) { - const char *error = dlerror(); - if (error == NULL) - error = "no error message provided by the system"; + dlsym_error(soname, init_name); + goto error; + } + + HPyModuleDef* hpydef = ((InitFuncPtr)initfn)(); + if (hpydef == NULL) { PyErr_Format(PyExc_RuntimeError, "Error during loading of the HPy extension module at " - "path '%s' while trying to find symbol '%s'. Did you use" - "the HPy_MODINIT macro to register your module? Error " - "message from dlsym/WinAPI: %s", soname, init_name, error); + "path '%s'. Function '%s' returned NULL.", soname, init_name); goto error; } - HPyContext *ctx = get_context(mode); - if (ctx == NULL) + pydef = _HPyModuleDef_CreatePyModuleDef(hpydef); + if (pydef == NULL) { goto error; - HPy h_mod = ((InitFuncPtr)initfn)(ctx); - if (HPy_IsNull(h_mod)) + } + + py_mod = PyModule_FromDefAndSpec(pydef, spec); + if (py_mod == NULL) goto error; - PyObject *py_mod = HPy_AsPyObject(ctx, h_mod); - HPy_Close(ctx, h_mod); + + if (PyModule_Check(py_mod)) { + if (PyModule_ExecDef(py_mod, pydef) != 0) + goto error; + } Py_XDECREF(name); Py_XDECREF(pathbytes); return py_mod; error: + Py_XDECREF(py_mod); + if (pydef != NULL) + PyMem_Free(pydef); Py_XDECREF(name); Py_XDECREF(pathbytes); return NULL; @@ -251,13 +289,14 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path, HPyMode mode) static PyObject *load(PyObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"name", "path", "debug", "mode", NULL}; + static char *kwlist[] = {"name", "path", "spec", "debug", "mode", NULL}; PyObject *name_unicode; PyObject *path; + PyObject *spec; int debug = 0; int mode = -1; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|pi", kwlist, - &name_unicode, &path, &debug, &mode)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO|pi", kwlist, + &name_unicode, &path, &spec, &debug, &mode)) { return NULL; } HPyMode hmode = debug ? MODE_DEBUG : MODE_UNIVERSAL; @@ -266,7 +305,7 @@ static PyObject *load(PyObject *self, PyObject *args, PyObject *kwargs) { hmode = (HPyMode) mode; } - return do_load(name_unicode, path, hmode); + return do_load(name_unicode, path, hmode, spec); } static HPyMode get_mode_from_string(const char *s, Py_ssize_t n) @@ -424,7 +463,7 @@ load_bootstrap(PyObject *self, PyObject *args, PyObject *kwargs) s_module_name, log_msg); } - m = do_load(module_name, file, hmode); + m = do_load(module_name, file, hmode, spec); if (m == NULL) return NULL; @@ -464,7 +503,7 @@ static PyModuleDef_Slot hpymodule_slots[] = { {0, NULL}, }; -static struct PyModuleDef hpydef = { +static struct PyModuleDef hpy_pydef = { PyModuleDef_HEAD_INIT, .m_name = "hpy.universal", .m_doc = "HPy universal runtime for CPython", @@ -473,28 +512,67 @@ static struct PyModuleDef hpydef = { .m_slots = hpymodule_slots, }; +static int initialize_module(HPyContext *ctx, PyObject *hpy_universal, const char* name, + const char *full_name, HPyModuleDef *hpydef, + PyObject* spec_from_file_and_location, PyObject *location) +{ + PyObject *spec = NULL, *new_mod = NULL; + int result = -1; + + spec = PyObject_CallFunction(spec_from_file_and_location, "sO", full_name, location); + PyModuleDef *pydef = _HPyModuleDef_CreatePyModuleDef(hpydef); + new_mod = PyModule_FromDefAndSpec(pydef, spec); + if (new_mod == NULL) + goto cleanup; + + if (PyModule_ExecDef(new_mod, pydef) != 0) + goto cleanup; + + Py_INCREF(new_mod); // PyModule_AddObject steals the reference + if (PyModule_AddObject(hpy_universal, name, new_mod) < 0) + goto cleanup; + + result = 0; + +cleanup: + Py_XDECREF(new_mod); + Py_XDECREF(spec); + return result; +} // module initialization function int exec_module(PyObject* mod) { HPyContext *ctx = &g_universal_ctx; - HPy h_debug_mod = HPyInit__debug(ctx); - if (HPy_IsNull(h_debug_mod)) + + PyObject *importlib_util = PyImport_ImportModule("importlib.util"); + if (importlib_util == NULL) return -1; - PyObject *_debug_mod = HPy_AsPyObject(ctx, h_debug_mod); - HPy_Close(ctx, h_debug_mod); - if (PyModule_AddObject(mod, "_debug", _debug_mod) < 0) + PyObject *spec_from_file_and_location = PyObject_GetAttrString(importlib_util, "spec_from_file_location"); + Py_DecRef(importlib_util); + if (spec_from_file_and_location == NULL) return -1; - HPy h_trace_mod = HPyInit__trace(ctx); - if (HPy_IsNull(h_trace_mod)) + PyObject *current_mod_spec = PyObject_GetAttrString(mod, "__spec__"); + if (current_mod_spec == NULL) return -1; - PyObject *_trace_mod = HPy_AsPyObject(ctx, h_trace_mod); - HPy_Close(ctx, h_trace_mod); - if (PyModule_AddObject(mod, "_trace", _trace_mod) < 0) + PyObject *location = PyObject_GetAttrString(current_mod_spec, "origin"); + if (location == NULL) return -1; + HPyInitGlobalContext__debug(ctx); + int result = initialize_module(ctx, mod, "_debug", "hpy.debug._debug", + HPyInit__debug(), spec_from_file_and_location, location); + if (result != 0) + return result; + + HPyInitGlobalContext__trace(ctx); + result = initialize_module(ctx, mod, "_trace", "hpy.trace._trace", + HPyInit__trace(), spec_from_file_and_location, location); + if (result != 0) + return result; + for (int i=0; hpy_mode_names[i]; i++) { if (PyModule_AddIntConstant(mod, hpy_mode_names[i], i) < 0) @@ -607,6 +685,6 @@ PyMODINIT_FUNC PyInit_universal(void) { init_universal_ctx(&g_universal_ctx); - PyObject *mod = PyModuleDef_Init(&hpydef); + PyObject *mod = PyModuleDef_Init(&hpy_pydef); return mod; } diff --git a/microbench/src/hpy_simple.c b/microbench/src/hpy_simple.c index b8f2e186f..d252b3b2a 100644 --- a/microbench/src/hpy_simple.c +++ b/microbench/src/hpy_simple.c @@ -103,6 +103,17 @@ static HPyType_Spec Foo_spec = { /* Module defines */ +HPyDef_SLOT(init_hpy_simple, HPy_mod_exec) +static int init_hpy_simple_impl(HPyContext *ctx, HPy m) +{ + HPy h_Foo = HPyType_FromSpec(ctx, &Foo_spec, NULL); + if (HPy_IsNull(h_Foo)) + return -1; + HPy_SetAttr_s(ctx, m, "Foo", h_Foo); + HPy_SetAttr_s(ctx, m, "HTFoo", h_Foo); + return 0; +} + static HPyDef *module_defines[] = { &noargs, &onearg, @@ -111,27 +122,14 @@ static HPyDef *module_defines[] = { &call_with_tuple_and_dict, &allocate_int, &allocate_tuple, + &init_hpy_simple, NULL }; - static HPyModuleDef moduledef = { - .name = "hpy_simple", .doc = "HPy microbenchmarks", - .size = -1, + .size = 0, .defines = module_defines, }; -HPy_MODINIT(hpy_simple) -static HPy init_hpy_simple_impl(HPyContext *ctx) -{ - HPy m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - HPy h_Foo = HPyType_FromSpec(ctx, &Foo_spec, NULL); - if (HPy_IsNull(h_Foo)) - return HPy_NULL; - HPy_SetAttr_s(ctx, m, "Foo", h_Foo); - HPy_SetAttr_s(ctx, m, "HTFoo", h_Foo); - return m; -} +HPy_MODINIT(hpy_simple, moduledef) diff --git a/proof-of-concept/pof.c b/proof-of-concept/pof.c index 37f74b271..4b9527332 100644 --- a/proof-of-concept/pof.c +++ b/proof-of-concept/pof.c @@ -79,30 +79,30 @@ static HPyType_Spec point_type_spec = { .defines = point_type_defines }; +HPyDef_SLOT(mod_exec, HPy_mod_exec) +static int mod_exec_impl(HPyContext *ctx, HPy m) +{ + HPy h_point_type = HPyType_FromSpec(ctx, &point_type_spec, NULL); + if (HPy_IsNull(h_point_type)) + return -1; + HPy_SetAttr_s(ctx, m, "Point", h_point_type); + HPy_Close(ctx, h_point_type); + return 0; +} + static HPyDef *module_defines[] = { &do_nothing, &double_obj, &add_ints, &add_ints_kw, + &mod_exec, NULL }; + static HPyModuleDef moduledef = { - .name = "pof", .doc = "HPy Proof of Concept", - .size = -1, + .size = 0, .defines = module_defines }; -HPy_MODINIT(pof) -static HPy init_pof_impl(HPyContext *ctx) -{ - HPy m, h_point_type; - m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - h_point_type = HPyType_FromSpec(ctx, &point_type_spec, NULL); - if (HPy_IsNull(h_point_type)) - return HPy_NULL; - HPy_SetAttr_s(ctx, m, "Point", h_point_type); - return m; -} +HPy_MODINIT(pof, moduledef) \ No newline at end of file diff --git a/proof-of-concept/pofcpp.cpp b/proof-of-concept/pofcpp.cpp index 94b95f919..004b4a04a 100644 --- a/proof-of-concept/pofcpp.cpp +++ b/proof-of-concept/pofcpp.cpp @@ -72,6 +72,7 @@ static HPyDef *point_type_defines[] = { &Point_repr, NULL }; + static HPyType_Spec point_type_spec = { .name = "pofcpp.Point", .basicsize = sizeof(PointObject), @@ -79,17 +80,28 @@ static HPyType_Spec point_type_spec = { .defines = point_type_defines }; +HPyDef_SLOT(mod_exec, HPy_mod_exec) +static int mod_exec_impl(HPyContext *ctx, HPy m) +{ + HPy h_point_type = HPyType_FromSpec(ctx, &point_type_spec, NULL); + if (HPy_IsNull(h_point_type)) + return -1; + HPy_SetAttr_s(ctx, m, "Point", h_point_type); + HPy_Close(ctx, h_point_type); + return 0; +} + static HPyDef *module_defines[] = { &do_nothing, &double_obj, &add_ints, &add_ints_kw, + &mod_exec, NULL }; static HPyModuleDef moduledef = { - .name = "pofcpp", .doc = "HPy c++ Proof of Concept", - .size = -1, + .size = 0, .defines = module_defines }; @@ -97,19 +109,7 @@ static HPyModuleDef moduledef = { extern "C" { #endif -HPy_MODINIT(pofcpp) -static HPy init_pofcpp_impl(HPyContext *ctx) -{ - HPy m, h_point_type; - m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - h_point_type = HPyType_FromSpec(ctx, &point_type_spec, NULL); - if (HPy_IsNull(h_point_type)) - return HPy_NULL; - HPy_SetAttr_s(ctx, m, "Point", h_point_type); - return m; -} +HPy_MODINIT(pofcpp, moduledef) #ifdef __cplusplus } diff --git a/proof-of-concept/pofpackage/bar.cpp b/proof-of-concept/pofpackage/bar.cpp index 724fde7c8..01726d2d6 100644 --- a/proof-of-concept/pofpackage/bar.cpp +++ b/proof-of-concept/pofpackage/bar.cpp @@ -28,9 +28,8 @@ static HPyDef *module_defines[] = { NULL }; static HPyModuleDef moduledef = { - .name = "bar", .doc = "HPy C++ Proof of Concept", - .size = -1, + .size = 0, .defines = module_defines }; @@ -39,15 +38,7 @@ extern "C" { #endif -HPy_MODINIT(bar) -static HPy init_bar_impl(HPyContext *ctx) -{ - HPy m; - m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - return m; -} +HPy_MODINIT(bar, moduledef) #ifdef __cplusplus } diff --git a/proof-of-concept/pofpackage/foo.c b/proof-of-concept/pofpackage/foo.c index 4b0b9e443..3a265efa2 100644 --- a/proof-of-concept/pofpackage/foo.c +++ b/proof-of-concept/pofpackage/foo.c @@ -12,18 +12,9 @@ static HPyDef *module_defines[] = { NULL }; static HPyModuleDef moduledef = { - .name = "foo", .doc = "HPy Proof of Concept", - .size = -1, + .size = 0, .defines = module_defines }; -HPy_MODINIT(foo) -static HPy init_foo_impl(HPyContext *ctx) -{ - HPy m; - m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - return m; -} +HPy_MODINIT(foo, moduledef) diff --git a/test/hpy_devel/test_distutils.py b/test/hpy_devel/test_distutils.py index 4c97b6a26..00bbb3a52 100644 --- a/test/hpy_devel/test_distutils.py +++ b/test/hpy_devel/test_distutils.py @@ -154,15 +154,10 @@ def gen_project(self): // the simplest possible HPy module #include static HPyModuleDef moduledef = { - .name = "hpymod", .doc = "hpymod with HPy ABI: " HPY_ABI, }; - HPy_MODINIT(hpymod) - static HPy init_hpymod_impl(HPyContext *ctx) - { - return HPyModule_Create(ctx, &moduledef); - } + HPy_MODINIT(hpymod, moduledef) """) self.writefile('hpymod_legacy.c', """ @@ -180,16 +175,11 @@ def gen_project(self): }; static HPyModuleDef moduledef = { - .name = "hpymod_legacy", .doc = "hpymod_legacy with HPy ABI: " HPY_ABI, .legacy_methods = my_legacy_methods, }; - HPy_MODINIT(hpymod_legacy) - static HPy init_hpymod_legacy_impl(HPyContext *ctx) - { - return HPyModule_Create(ctx, &moduledef); - } + HPy_MODINIT(hpymod_legacy, moduledef) """) def gen_setup_py(self, src): diff --git a/test/support.py b/test/support.py index f6d2bd9a6..5337b00dd 100644 --- a/test/support.py +++ b/test/support.py @@ -76,36 +76,35 @@ class DefaultExtensionTemplate(object): INIT_TEMPLATE = textwrap.dedent( """ + HPyDef_SLOT(generated_init, HPy_mod_exec) + static int generated_init_impl(HPyContext *ctx, HPy m) + { + // Shouldn't really happen, but jut to silence the unused label warning + if (HPy_IsNull(m)) + goto MODINIT_ERROR; + + %(init_types)s + return 0; + + MODINIT_ERROR: + return -1; + } + static HPyDef *moduledefs[] = { %(defines)s + &generated_init, NULL }; %(globals_defs)s static HPyModuleDef moduledef = { - .name = "%(name)s", .doc = "some test for hpy", - .size = -1, + .size = 0, .legacy_methods = %(legacy_methods)s, .defines = moduledefs, %(globals_field)s }; - HPy_MODINIT(%(name)s) - static HPy init_%(name)s_impl(HPyContext *ctx) - { - HPy m = HPy_NULL; - m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - goto MODINIT_ERROR; - %(init_types)s - return m; - - MODINIT_ERROR: - - if (!HPy_IsNull(m)) - HPy_Close(ctx, m); - return HPy_NULL; - } + HPy_MODINIT(%(name)s, moduledef) """) r_marker = re.compile(r"^\s*@([A-Za-z_]+)(\(.*\))?$") @@ -206,6 +205,9 @@ def EXTRA_INIT_FUNC(self, func): src = reindent(src, 4) self.type_table.append(src.format(func=func)) + def HPy_MODINIT(self, mod): + return "HPy_MODINIT({}, {})".format(self.name, mod) + class Spec(object): def __init__(self, name, origin): @@ -354,9 +356,12 @@ def load_universal_module(self, name, so_filename, mode): 'trace', 'hybrid+trace') import sys import hpy.universal + import importlib.util assert name not in sys.modules - mod = hpy.universal.load(name, so_filename, mode=mode) + spec = importlib.util.spec_from_file_location(name, so_filename) + mod = hpy.universal.load(name, so_filename, spec, mode=mode) mod.__file__ = so_filename + mod.__spec__ = spec return mod def load_cpython_module(self, name, so_filename): @@ -398,7 +403,9 @@ def run(self, mod, code): # HPy module load_module = "import sys;" + \ "import hpy.universal;" + \ - "mod = hpy.universal.load('{name}', '{so_filename}', debug={debug});" + "import importlib.util;" + \ + "spec = importlib.util.spec_from_file_location('{name}', '{so_filename}');" + \ + "mod = hpy.universal.load('{name}', '{so_filename}', spec, debug={debug});" escaped_filename = mod.so_filename.replace("\\", "\\\\") # Needed for Windows paths load_module = load_module.format(name=mod.name, so_filename=escaped_filename, debug=self.hpy_abi == 'debug') diff --git a/test/test_hpymodule.py b/test/test_hpymodule.py index c513ccb84..f154485ff 100644 --- a/test/test_hpymodule.py +++ b/test/test_hpymodule.py @@ -1,26 +1,283 @@ +import types +import pytest from .support import HPyTest class TestModule(HPyTest): - def test_HPyModule_Create(self): + def test_HPyModule_simple(self): + """ + The simplest fully declarative module creation. + """ mod = self.make_module(""" HPyDef_METH(f, "f", HPyFunc_NOARGS) static HPy f_impl(HPyContext *ctx, HPy self) { - HPyModuleDef def = { - .name = "foo", + return HPyLong_FromLong(ctx, 42); + } + + static HPyDef *moduledefs[] = { &f, NULL }; + static HPyModuleDef moduledef = { + .doc = "Some doc", + .size = 0, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, + }; + + @HPy_MODINIT(moduledef) + """) + assert mod.__name__ == mod.__spec__.name + assert mod.__doc__ == "Some doc" + assert mod.f() == 42 + + def test_HPyModule_custom_exec(self): + """ + Module that defines several exec slots. HPy specifies that the slots + will be executed in declaration order. Exec slots can add new types, + and other objects into the module. They can also initialize other + objects. The exec slots will be called on every new instance of the + module, for example, when it is imported in several subinterpreters. + """ + mod = self.make_module(""" + HPyDef_SLOT(exec1, HPy_mod_exec) + static int exec1_impl(HPyContext *ctx, HPy mod) + { + HPy list = HPyList_New(ctx, 0); + if (HPy_IsNull(list)) + return -1; + HPy_SetAttr_s(ctx, mod, "data", list); + HPy_Close(ctx, list); + return 0; + } + + HPyDef_SLOT(exec2, HPy_mod_exec) + static int exec2_impl(HPyContext *ctx, HPy mod) + { + HPy list = HPy_GetAttr_s(ctx, mod, "data"); + if (HPy_IsNull(list)) + return -1; + if (HPy_Length(ctx, list) != 0) { + HPyErr_SetString(ctx, ctx->h_RuntimeError, "Unexpected: len(list) != 0"); + return -1; + } + HPy item = HPyLong_FromLong(ctx, 42); + HPyList_Append(ctx, list, item); + HPy_Close(ctx, item); + HPy_Close(ctx, list); + return 0; + } + + static HPyDef *moduledefs[] = { + &exec1, + &exec2, + NULL + }; + + static HPyModuleDef moduledef = { + .doc = "Some doc", + .size = 0, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, + }; + + @HPy_MODINIT(moduledef) + """) + assert mod.data == [42] + + def test_HPyModule_custom_create_returns_non_module(self): + """ + Module that defines create slot that returns non module object. This + is, for the time being, the only supported way to implement the module + 'create' slot. HPy intentionally does not expose direct API to create + a module object. Module objects are created for the extension by the + runtime and the extension can only populate that module object in the + init slots. + """ + mod = self.make_module(""" + HPyDef_SLOT(create, HPy_mod_create) + static HPy create_impl(HPyContext *ctx, HPy spec) + { + HPy result = HPy_NULL, dict = HPy_NULL, ns_type = HPy_NULL; + + HPy types = HPyImport_ImportModule(ctx, "types"); + if (HPy_IsNull(types)) + return HPy_NULL; + + ns_type = HPy_GetAttr_s(ctx, types, "SimpleNamespace"); + if (HPy_IsNull(types)) + goto cleanup; + dict = HPyDict_New(ctx); + HPy_SetItem_s(ctx, dict, "spec", spec); + result = HPy_CallTupleDict(ctx, ns_type, HPy_NULL, dict); + if (HPy_IsNull(result)) + goto cleanup; + + cleanup: + HPy_Close(ctx, dict); + HPy_Close(ctx, types); + HPy_Close(ctx, ns_type); + return result; + } + + static HPyDef *moduledefs[] = { + &create, + NULL + }; + + static HPyModuleDef moduledef = { + .doc = NULL, + .size = 0, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, + }; + + @HPy_MODINIT(moduledef) + """) + assert isinstance(mod, types.SimpleNamespace) + assert mod.spec is mod.__spec__ + + def test_HPyModule_error_when_create_returns_module(self): + """ + The HPy_mod_create slot cannot return a builtin module object. + HPy does not expose any API to create builtin module objects and, until + there are any actual use-cases, the purpose of the 'create' slot is to + create non-builtin-module objects. + """ + expected_message = "HPy_mod_create slot returned a builtin module " \ + "object. This is currently not supported." + with pytest.raises(SystemError, match=expected_message): + self.make_module(""" + HPyDef_SLOT(create, HPy_mod_create) + static HPy create_impl(HPyContext *ctx, HPy spec) + { + return HPyImport_ImportModule(ctx, "types"); + } + + static HPyDef *moduledefs[] = { + &create, + NULL + }; + + static HPyModuleDef moduledef = { + .doc = NULL, + .size = 0, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, + }; + + @HPy_MODINIT(moduledef) + """) + + def test_HPyModule_create_raises(self): + with pytest.raises(RuntimeError, match="Test error"): + self.make_module(""" + HPyDef_SLOT(create, HPy_mod_create) + static HPy create_impl(HPyContext *ctx, HPy spec) + { + HPyErr_SetString(ctx, ctx->h_RuntimeError, "Test error"); + return HPy_NULL; + } + + static HPyDef *moduledefs[] = { + &create, + NULL + }; + + static HPyModuleDef moduledef = { + .doc = NULL, + .size = 0, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, + }; + + @HPy_MODINIT(moduledef) + """) + + def test_HPyModule_create_and_nondefault_values(self): + expected_message = r'^HPyModuleDef defines a HPy_mod_create slot.*' + with pytest.raises(SystemError, match=expected_message): + self.make_module(""" + HPyDef_SLOT(create, HPy_mod_create) + static HPy create_impl(HPyContext *ctx, HPy spec) + { + HPyErr_SetString(ctx, ctx->h_RuntimeError, "Test error"); + return HPy_NULL; + } + + static HPyDef *moduledefs[] = { + &create, + NULL + }; + + static HPyModuleDef moduledef = { + .doc = "Some doc - this is non-default", + .size = 0, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, + }; + + @HPy_MODINIT(moduledef) + """) + + def test_HPyModule_create_and_exec_slots(self): + expected_message = r'^HPyModuleDef defines a HPy_mod_create slot.*' + with pytest.raises(SystemError, match=expected_message): + self.make_module(""" + HPyDef_SLOT(create, HPy_mod_create) + static HPy create_impl(HPyContext *ctx, HPy spec) + { + HPyErr_SetString(ctx, ctx->h_RuntimeError, "Test error"); + return HPy_NULL; + } + + HPyDef_SLOT(exec, HPy_mod_exec) + static int exec_impl(HPyContext *ctx, HPy mod) + { + return 0; + } + + static HPyDef *moduledefs[] = { + &create, + &exec, + NULL + }; + + static HPyModuleDef moduledef = { + .doc = NULL, + .size = 0, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, + }; + + @HPy_MODINIT(moduledef) + """) + + def test_HPyModule_negative_size(self): + """ + The simplest fully declarative module creation. + """ + expected_message = "HPy does not permit HPyModuleDef.size < 0" + with pytest.raises(SystemError, match=expected_message): + self.make_module(""" + HPyDef_METH(f, "f", HPyFunc_NOARGS) + static HPy f_impl(HPyContext *ctx, HPy self) + { + return HPyLong_FromLong(ctx, 42); + } + + static HPyDef *moduledefs[] = { &f, NULL }; + static HPyModuleDef moduledef = { .doc = "Some doc", .size = -1, + .legacy_methods = NULL, + .defines = moduledefs, + .globals = NULL, }; - return HPyModule_Create(ctx, &def); - } - @EXPORT(f) - @INIT - """) - m = mod.f() - assert m.__name__ == "foo" - assert m.__doc__ == "Some doc" - assert m.__package__ is None - assert m.__loader__ is None - assert m.__spec__ is None - assert set(vars(m).keys()) == { - '__name__', '__doc__', '__package__', '__loader__', '__spec__'} + + @HPy_MODINIT(moduledef) + """)