From 1cd887a33e7852e98032916d8f2815910e7dee52 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 15 Dec 2020 11:49:54 +0100 Subject: [PATCH 01/65] temporarily comment this out, see issue #140 --- hpy/devel/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hpy/devel/__init__.py b/hpy/devel/__init__.py index 33be1a011..55deb6e03 100644 --- a/hpy/devel/__init__.py +++ b/hpy/devel/__init__.py @@ -240,8 +240,9 @@ def write_stub(self, output_dir, ext, compile=False): ext._full_name, output_dir) stub_file = (os.path.join(output_dir, *ext._full_name.split('.')) + '.py') - if compile and os.path.exists(stub_file): - raise DistutilsError(stub_file + " already exists! Please delete.") + ## XXX uncomment this when we fix issue 140 + ## if compile and os.path.exists(stub_file): + ## raise DistutilsError(stub_file + " already exists! Please delete.") ext_file = os.path.basename(ext._file_name) module_name = ext_file.split(".")[0] if not self.dry_run: From 4551d10e87c5a3562e8d68e088aec0b64dc94f67 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 15 Dec 2020 12:05:58 +0100 Subject: [PATCH 02/65] Add two fields to HPyContext: - name: mostly used only to make it easier to distinguish the context inside gdb, will be useful when we introduce the debug ctx - _private: to make it possible to store additional data on the ctx, implementation-defined --- hpy/devel/include/cpython/hpy.h | 6 +++--- hpy/devel/include/universal/autogen_ctx.h | 2 ++ hpy/tools/autogen/ctx.py | 8 ++++++++ hpy/universal/src/autogen_ctx_def.h | 2 ++ test/test_debug.py | 25 +++++++++++++++++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/test_debug.py diff --git a/hpy/devel/include/cpython/hpy.h b/hpy/devel/include/cpython/hpy.h index 8f97c4be1..a12586efc 100644 --- a/hpy/devel/include/cpython/hpy.h +++ b/hpy/devel/include/cpython/hpy.h @@ -45,6 +45,7 @@ typedef Py_hash_t HPy_hash_t; // this should maybe autogenerated from public_api.h typedef struct _HPyContext_s { + const char *name; /* Constants */ HPy h_None; HPy h_True; @@ -140,9 +141,8 @@ static inline void* HPy_AsVoidP(HPy h) { return (void*)h._o; } HPyAPI_FUNC(HPyContext) _HPyGetContext(void) { HPyContext ctx = &_global_ctx; - if (HPy_IsNull(ctx->h_None)) { - // XXX: we need to find a better way to check whether the ctx is - // initialized or not + if (!ctx->name) { + ctx->name = "HPy CPython ABI", /* Constants */ ctx->h_None = _py2h(Py_None); ctx->h_True = _py2h(Py_True); diff --git a/hpy/devel/include/universal/autogen_ctx.h b/hpy/devel/include/universal/autogen_ctx.h index 044c93ffd..002be1c36 100644 --- a/hpy/devel/include/universal/autogen_ctx.h +++ b/hpy/devel/include/universal/autogen_ctx.h @@ -9,6 +9,8 @@ */ struct _HPyContext_s { + const char *name; // used just to make debugging and testing easier + void *_private; // used by implementations to store custom data int ctx_version; HPy h_None; HPy h_True; diff --git a/hpy/tools/autogen/ctx.py b/hpy/tools/autogen/ctx.py index cedfef0e5..4d6854718 100644 --- a/hpy/tools/autogen/ctx.py +++ b/hpy/tools/autogen/ctx.py @@ -8,6 +8,8 @@ class autogen_ctx_h(AutoGenFile): PATH = 'hpy/devel/include/universal/autogen_ctx.h' ## struct _HPyContext_s { + ## const char *name; + ## void *_private; ## int ctx_version; ## HPy h_None; ## ... @@ -19,6 +21,8 @@ def generate(self): lines = [] w = lines.append w('struct _HPyContext_s {') + w(' const char *name; // used just to make debugging and testing easier') + w(' void *_private; // used by implementations to store custom data') w(' int ctx_version;') for var in self.api.variables: w(' %s;' % self.declare_var(var)) @@ -46,6 +50,8 @@ class autogen_ctx_def_h(AutoGenFile): PATH = 'hpy/universal/src/autogen_ctx_def.h' ## struct _HPyContext_s global_ctx = { + ## .name = "...", + ## ._private = NULL, ## .ctx_version = 1, ## .h_None = {CONSTANT_H_NONE}, ## ... @@ -57,6 +63,8 @@ def generate(self): lines = [] w = lines.append w('struct _HPyContext_s global_ctx = {') + w(' .name = "HPy Universal ABI (CPython backend)",') + w(' ._private = NULL,') w(' .ctx_version = 1,') for var in self.api.variables: w(' .%s = {CONSTANT_%s},' % (var.name, var.name.upper())) diff --git a/hpy/universal/src/autogen_ctx_def.h b/hpy/universal/src/autogen_ctx_def.h index 5a34ce240..eb46c9674 100644 --- a/hpy/universal/src/autogen_ctx_def.h +++ b/hpy/universal/src/autogen_ctx_def.h @@ -9,6 +9,8 @@ */ struct _HPyContext_s global_ctx = { + .name = "HPy Universal ABI (CPython backend)", + ._private = NULL, .ctx_version = 1, .h_None = {CONSTANT_H_NONE}, .h_True = {CONSTANT_H_TRUE}, diff --git a/test/test_debug.py b/test/test_debug.py new file mode 100644 index 000000000..4d44d08b0 --- /dev/null +++ b/test/test_debug.py @@ -0,0 +1,25 @@ +from .support import HPyTest + + +class TestDebug(HPyTest): + + def test_ctx_name(self, hpy_abi): + mod = self.make_module(""" + HPyDef_METH(f, "f", f_impl, HPyFunc_NOARGS) + static HPy f_impl(HPyContext ctx, HPy self) + { + return HPyUnicode_FromString(ctx, ctx->name); + } + + @EXPORT(f) + @INIT + """) + ctx_name = mod.f() + if hpy_abi == 'cpython': + assert ctx_name == 'HPy CPython ABI' + elif hpy_abi == 'universal': + # this can be "HPy Universal ABI (CPython backend)" or + # "... (PyPy backend)", etc. + assert ctx_name.startswith('HPy Universal ABI') + else: + assert False, 'unexpected hpy_abi: %s' % hpy_abi From 97803d8a2657e3f009f11274a7abb48f8cfb30a9 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 15 Dec 2020 16:27:09 +0100 Subject: [PATCH 03/65] WIP: introduce hpy.debug. In particular, hpy.debug._ctx is a C module which wraps an existing HPyContext. So far, it just prints a string when calling HPy_Add and delegates everything else to the original context. --- Makefile | 12 ++++++++-- hpy/debug/src/_ctx.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ hpy/debug/src/_ctx.h | 28 +++++++++++++++++++++++ setup_hpy_debug.py | 19 ++++++++++++++++ test/test_debug.py | 25 ++++++++++++++++++++ 5 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 hpy/debug/src/_ctx.c create mode 100644 hpy/debug/src/_ctx.h create mode 100644 setup_hpy_debug.py diff --git a/Makefile b/Makefile index e1f7e349d..f88acaf66 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,16 @@ -all: +.PHONY: all +all: hpy.universal hpy.debug + +.PHONY: hpy.universal +hpy.universal: python3 setup.py build_ext -if +.PHONY: hpy.debug +hpy.debug: + python3 setup_hpy_debug.py --hpy-abi=universal build_ext -if + debug: - HPY_DEBUG=1 python3 setup.py build_ext -if + HPY_DEBUG=1 make all autogen: python3 -m hpy.tools.autogen . diff --git a/hpy/debug/src/_ctx.c b/hpy/debug/src/_ctx.c new file mode 100644 index 000000000..73a41396c --- /dev/null +++ b/hpy/debug/src/_ctx.c @@ -0,0 +1,54 @@ +#include "_ctx.h" +#include +#include + + +static HPy dbg_Add(HPyContext ctx, HPy a, HPy b) +{ + printf("dbg_Add...\n"); + HPyDebugInfo *info = get_info(ctx); + return HPy_Add(info->original_ctx, a, b); +} + +HPyDef_METH(get_debug_ctx, "get_debug_ctx", get_debug_ctx_impl, HPyFunc_NOARGS) +static HPy get_debug_ctx_impl(HPyContext ctx, HPy self) +{ + // XXX: these mallocs are never freed + + // initialize info + HPyDebugInfo *info = malloc(sizeof(HPyDebugInfo)); + info->magic_number = HPY_DEBUG_MAGIC; + info->original_ctx = ctx; + + // initialize ctx2 + HPyContext ctx2 = malloc(sizeof(struct _HPyContext_s)); + memcpy(ctx2, ctx, sizeof(struct _HPyContext_s)); + ctx2->name = "HPy Debug Mode"; + ctx2->_private = info; + ctx2->ctx_Add = dbg_Add; + return HPyLong_FromLong(ctx, (long)ctx2); +} + + +static HPyDef *module_defines[] = { + &get_debug_ctx, + NULL +}; + +static HPyModuleDef moduledef = { + HPyModuleDef_HEAD_INIT, + .m_name = "hpy.debug._ctx", + .m_doc = "HPy debug context", + .m_size = -1, + .defines = module_defines +}; + + +HPy_MODINIT(_ctx) +static HPy init__ctx_impl(HPyContext ctx) +{ + HPy m = HPyModule_Create(ctx, &moduledef); + if (HPy_IsNull(m)) + return HPy_NULL; + return m; +} diff --git a/hpy/debug/src/_ctx.h b/hpy/debug/src/_ctx.h new file mode 100644 index 000000000..9cd3869a0 --- /dev/null +++ b/hpy/debug/src/_ctx.h @@ -0,0 +1,28 @@ +#ifndef HPY_DEBUG__CTX_H +#define HPY_DEBUG__CTX_H + +#include +#include "hpy.h" + + +#ifndef HPY_UNIVERSAL_ABI +# error "hpy.debug should be built with --hpy-abi=universal" +#endif + +// "deboff" is the closest to "debug" I could come up with :) +static const long HPY_DEBUG_MAGIC = 0xDEB0FF; + +typedef struct { + long magic_number; // used just for sanity checks + HPyContext original_ctx; +} HPyDebugInfo; + +static HPyDebugInfo *get_info(HPyContext ctx) +{ + HPyDebugInfo *info = (HPyDebugInfo*)ctx->_private; + assert(info->magic_number == HPY_DEBUG_MAGIC); // sanity check + return info; +} + + +#endif /* HPY_DEBUG__CTX_H */ diff --git a/setup_hpy_debug.py b/setup_hpy_debug.py new file mode 100644 index 000000000..8b07b242f --- /dev/null +++ b/setup_hpy_debug.py @@ -0,0 +1,19 @@ +import os +from setuptools import setup, Extension + +if 'HPY_DEBUG' in os.environ: + EXTRA_COMPILE_ARGS = ['-g', '-O0'] +else: + EXTRA_COMPILE_ARGS = [] + +setup( + name="hpy.debug", + hpy_ext_modules=[ + Extension('hpy.debug._ctx', + extra_compile_args=EXTRA_COMPILE_ARGS, + sources=[ + 'hpy/debug/src/_ctx.c', + ]), + ], + setup_requires=['hpy.devel'], +) diff --git a/test/test_debug.py b/test/test_debug.py index 4d44d08b0..8e27468c9 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -23,3 +23,28 @@ def test_ctx_name(self, hpy_abi): assert ctx_name.startswith('HPy Universal ABI') else: assert False, 'unexpected hpy_abi: %s' % hpy_abi + + + def test_temp(self, hpy_abi): + import pytest + if hpy_abi != 'universal': + pytest.skip() + mod = self.make_module(""" + HPyDef_METH(f, "f", f_impl, HPyFunc_O) + static HPy f_impl(HPyContext ctx, HPy self, HPy arg) + { + HPyContext ctx2 = (HPyContext)HPyLong_AsLong(ctx, arg); + HPy a = HPyLong_FromLong(ctx, 4); + HPy b = HPyLong_FromLong(ctx, 5); + HPy res = HPy_Add(ctx2, a, b); // note, we are using ctx2! + HPy_Close(ctx, a); + HPy_Close(ctx, b); + return res; + } + @EXPORT(f) + @INIT + """) + from hpy.debug._ctx import get_debug_ctx + ctx2 = get_debug_ctx() + res = mod.f(ctx2) + assert res == 9 From 2d868ecfdb49fa3fc4d40314fe40c1e287168a43 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 15 Dec 2020 17:43:29 +0100 Subject: [PATCH 04/65] refactor _ctx.c to use a statically allocated debug_ctx/debug_info, and to intiialize them at module init time --- hpy/debug/src/_ctx.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/hpy/debug/src/_ctx.c b/hpy/debug/src/_ctx.c index 73a41396c..b3faaf099 100644 --- a/hpy/debug/src/_ctx.c +++ b/hpy/debug/src/_ctx.c @@ -2,6 +2,15 @@ #include #include +static HPyDebugInfo debug_info = { + .magic_number = HPY_DEBUG_MAGIC, + .original_ctx = NULL, +}; + +static struct _HPyContext_s debug_ctx = { + .name = NULL, +}; + static HPy dbg_Add(HPyContext ctx, HPy a, HPy b) { @@ -10,23 +19,28 @@ static HPy dbg_Add(HPyContext ctx, HPy a, HPy b) return HPy_Add(info->original_ctx, a, b); } +void debug_ctx_init(HPyContext original_ctx) +{ + if (debug_ctx.name) + return; // already initialized + + // initialize debug_info + debug_info.original_ctx = original_ctx; + + // initialize debug_ctx: eventually we will autogen a static initializer + // for debug_ctx. For now, just copy&fix + memcpy(&debug_ctx, original_ctx, sizeof(struct _HPyContext_s)); + debug_ctx.name = "HPy Debug Mode"; + debug_ctx._private = &debug_info; + debug_ctx.ctx_Add = dbg_Add; +} + + HPyDef_METH(get_debug_ctx, "get_debug_ctx", get_debug_ctx_impl, HPyFunc_NOARGS) static HPy get_debug_ctx_impl(HPyContext ctx, HPy self) { - // XXX: these mallocs are never freed - - // initialize info - HPyDebugInfo *info = malloc(sizeof(HPyDebugInfo)); - info->magic_number = HPY_DEBUG_MAGIC; - info->original_ctx = ctx; - - // initialize ctx2 - HPyContext ctx2 = malloc(sizeof(struct _HPyContext_s)); - memcpy(ctx2, ctx, sizeof(struct _HPyContext_s)); - ctx2->name = "HPy Debug Mode"; - ctx2->_private = info; - ctx2->ctx_Add = dbg_Add; - return HPyLong_FromLong(ctx, (long)ctx2); + assert(debug_ctx.name != NULL); + return HPyLong_FromLong(ctx, (long)&debug_ctx); } @@ -50,5 +64,6 @@ static HPy init__ctx_impl(HPyContext ctx) HPy m = HPyModule_Create(ctx, &moduledef); if (HPy_IsNull(m)) return HPy_NULL; + debug_ctx_init(ctx); return m; } From c379b34888b22b7cadafd6b1bd0ac5866bf189e5 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 10:13:38 +0100 Subject: [PATCH 05/65] rename global_ctx into g_universal_ctx: I think it's clearer and we will need to distinguish it from g_debug_ctx later --- hpy/tools/autogen/ctx.py | 4 ++-- hpy/universal/src/api.h | 2 +- hpy/universal/src/autogen_ctx_def.h | 2 +- hpy/universal/src/hpymodule.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hpy/tools/autogen/ctx.py b/hpy/tools/autogen/ctx.py index 4d6854718..fdaa2bead 100644 --- a/hpy/tools/autogen/ctx.py +++ b/hpy/tools/autogen/ctx.py @@ -49,7 +49,7 @@ def declare_func(self, func): class autogen_ctx_def_h(AutoGenFile): PATH = 'hpy/universal/src/autogen_ctx_def.h' - ## struct _HPyContext_s global_ctx = { + ## struct _HPyContext_s g_universal_ctx = { ## .name = "...", ## ._private = NULL, ## .ctx_version = 1, @@ -62,7 +62,7 @@ class autogen_ctx_def_h(AutoGenFile): def generate(self): lines = [] w = lines.append - w('struct _HPyContext_s global_ctx = {') + w('struct _HPyContext_s g_universal_ctx = {') w(' .name = "HPy Universal ABI (CPython backend)",') w(' ._private = NULL,') w(' .ctx_version = 1,') diff --git a/hpy/universal/src/api.h b/hpy/universal/src/api.h index 555bec3a1..7db2ffa71 100644 --- a/hpy/universal/src/api.h +++ b/hpy/universal/src/api.h @@ -4,6 +4,6 @@ #include "hpy.h" #define HPyAPI_STORAGE _HPy_HIDDEN -extern struct _HPyContext_s global_ctx; +extern struct _HPyContext_s g_universal_ctx; #endif /* HPY_API_H */ diff --git a/hpy/universal/src/autogen_ctx_def.h b/hpy/universal/src/autogen_ctx_def.h index eb46c9674..6515f8c86 100644 --- a/hpy/universal/src/autogen_ctx_def.h +++ b/hpy/universal/src/autogen_ctx_def.h @@ -8,7 +8,7 @@ */ -struct _HPyContext_s global_ctx = { +struct _HPyContext_s g_universal_ctx = { .name = "HPy Universal ABI (CPython backend)", ._private = NULL, .ctx_version = 1, diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 35892a80e..13798777b 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -115,7 +115,7 @@ static PyObject *load_from_spec(PyObject *self, PyObject *spec) goto error; } - HPy mod = ((InitFuncPtr)initfn)(&global_ctx); + HPy mod = ((InitFuncPtr)initfn)(&g_universal_ctx); if (HPy_IsNull(mod)) goto error; PyObject *py_mod = _h2py(mod); From c3c97c1f672b7b66a33f79281c7b329075ab0a1d Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 11:12:07 +0100 Subject: [PATCH 06/65] WIP 1 --- hpy/universal/src/hpymodule.c | 43 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 13798777b..9c65464c2 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -69,17 +69,11 @@ get_encoded_name(PyObject *name) { return NULL; } - -static PyObject *load_from_spec(PyObject *self, PyObject *spec) +static PyObject *do_load(PyObject *name_unicode, PyObject *path) { - PyObject *name_unicode, *name; - PyObject *path = NULL; + PyObject *name = NULL; PyObject *pathbytes = NULL; - name_unicode = PyObject_GetAttrString(spec, "name"); - if (name_unicode == NULL) { - return NULL; - } name = get_encoded_name(name_unicode); if (name == NULL) { goto error; @@ -89,9 +83,6 @@ static PyObject *load_from_spec(PyObject *self, PyObject *spec) PyOS_snprintf(init_name, sizeof(init_name), "%.20s_%.200s", prefix, shortname); - path = PyObject_GetAttrString(spec, "origin"); - if (path == NULL) - goto error; pathbytes = PyUnicode_EncodeFSDefault(path); if (pathbytes == NULL) goto error; @@ -121,19 +112,41 @@ static PyObject *load_from_spec(PyObject *self, PyObject *spec) PyObject *py_mod = _h2py(mod); // XXX close the handle - Py_DECREF(name_unicode); Py_XDECREF(name); - Py_XDECREF(path); Py_XDECREF(pathbytes); return py_mod; error: - Py_DECREF(name_unicode); Py_XDECREF(name); - Py_XDECREF(path); Py_XDECREF(pathbytes); return NULL; } +static PyObject *load_from_spec(PyObject *self, PyObject *spec) +{ + PyObject *name_unicode = NULL; + PyObject *path = NULL; + + name_unicode = PyObject_GetAttrString(spec, "name"); + if (name_unicode == NULL) { + goto error; + } + path = PyObject_GetAttrString(spec, "origin"); + if (path == NULL) + goto error; + + PyObject *py_mod = do_load(name_unicode, path); + Py_DECREF(name_unicode); + Py_DECREF(path); + return py_mod; + + error: + Py_XDECREF(name_unicode); + Py_XDECREF(path); + return NULL; +} + + + static PyObject *get_version(PyObject *self, PyObject *ignored) { return Py_BuildValue("ss", HPY_VERSION, HPY_GIT_REVISION); From 0f939eea65d666e0976d764bdfdb275aea766a5a Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 15:32:27 +0100 Subject: [PATCH 07/65] WIP: introduce a new function hpy.universal.load, which will be used to load modules in debug mode --- hpy/universal/src/hpymodule.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 9c65464c2..4aea34169 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -121,6 +121,23 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path) return NULL; } +static PyObject *load(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = {"name", "path", NULL}; + PyObject *name_unicode; + PyObject *path; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwlist, + &name_unicode, &path)) { + return NULL; + } + return do_load(name_unicode, path); +} + +/* + I think we should eventually kill this. We introduced it to anticipate + using an import hook, but now that we are using a .py stub it seems no + longer necessary and makes it harder to pass additional params such as "debug" +*/ static PyObject *load_from_spec(PyObject *self, PyObject *spec) { PyObject *name_unicode = NULL; @@ -146,7 +163,6 @@ static PyObject *load_from_spec(PyObject *self, PyObject *spec) } - static PyObject *get_version(PyObject *self, PyObject *ignored) { return Py_BuildValue("ss", HPY_VERSION, HPY_GIT_REVISION); @@ -154,6 +170,7 @@ static PyObject *get_version(PyObject *self, PyObject *ignored) static PyMethodDef HPyMethods[] = { {"set_debug", (PyCFunction)set_debug, METH_O, "TODO"}, + {"load", (PyCFunction)load, METH_VARARGS | METH_KEYWORDS, "Load a .hpy.so"}, {"load_from_spec", (PyCFunction)load_from_spec, METH_O, "Load a .hpy.so"}, {"get_version", (PyCFunction)get_version, METH_NOARGS, "Return a tuple ('version', 'git revision')"}, {NULL, NULL, 0, NULL} From 3141873e109a66d5f39226e81a1a9fc719021436 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 16:31:53 +0100 Subject: [PATCH 08/65] kill hpy.universal.load_from_spec: rename it into load(), which takes the name and the path as two normal arguments --- hpy/devel/__init__.py | 10 ++-------- hpy/universal/src/hpymodule.c | 31 ------------------------------- 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/hpy/devel/__init__.py b/hpy/devel/__init__.py index 55deb6e03..bca887527 100644 --- a/hpy/devel/__init__.py +++ b/hpy/devel/__init__.py @@ -100,17 +100,11 @@ def handle_hpy_ext_modules(dist, attr, hpy_ext_modules): _HPY_UNIVERSAL_MODULE_STUB_TEMPLATE = """ -class Spec: - def __init__(self, name, origin): - self.name = name - self.origin = origin - - def __bootstrap__(): import sys, pkg_resources - from hpy.universal import load_from_spec + from hpy.universal import load ext_filepath = pkg_resources.resource_filename(__name__, {ext_file!r}) - m = load_from_spec(Spec({module_name!r}, ext_filepath)) + m = load({module_name!r}, ext_filepath) m.__file__ = ext_filepath sys.modules[__name__] = m diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 4aea34169..0af186829 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -133,36 +133,6 @@ static PyObject *load(PyObject *self, PyObject *args, PyObject *kwargs) return do_load(name_unicode, path); } -/* - I think we should eventually kill this. We introduced it to anticipate - using an import hook, but now that we are using a .py stub it seems no - longer necessary and makes it harder to pass additional params such as "debug" -*/ -static PyObject *load_from_spec(PyObject *self, PyObject *spec) -{ - PyObject *name_unicode = NULL; - PyObject *path = NULL; - - name_unicode = PyObject_GetAttrString(spec, "name"); - if (name_unicode == NULL) { - goto error; - } - path = PyObject_GetAttrString(spec, "origin"); - if (path == NULL) - goto error; - - PyObject *py_mod = do_load(name_unicode, path); - Py_DECREF(name_unicode); - Py_DECREF(path); - return py_mod; - - error: - Py_XDECREF(name_unicode); - Py_XDECREF(path); - return NULL; -} - - static PyObject *get_version(PyObject *self, PyObject *ignored) { return Py_BuildValue("ss", HPY_VERSION, HPY_GIT_REVISION); @@ -171,7 +141,6 @@ static PyObject *get_version(PyObject *self, PyObject *ignored) static PyMethodDef HPyMethods[] = { {"set_debug", (PyCFunction)set_debug, METH_O, "TODO"}, {"load", (PyCFunction)load, METH_VARARGS | METH_KEYWORDS, "Load a .hpy.so"}, - {"load_from_spec", (PyCFunction)load_from_spec, METH_O, "Load a .hpy.so"}, {"get_version", (PyCFunction)get_version, METH_NOARGS, "Return a tuple ('version', 'git revision')"}, {NULL, NULL, 0, NULL} }; From ba3392476d3d3082ea80402e9d0dec65634393cb Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 17:06:35 +0100 Subject: [PATCH 09/65] Partially undo some of the changes introduced by PR #124 (merged by commit 22a05e8) - we need to have different code path to load universal and cpython modules, because soon we will introduce loading universal modules in debug mode. - The idea of having a single function to load both universal and cpython modules was nice, but it ended up being too complicated and fragile; in particular, we had to monkey-patch sys.path, undo the insertion in sys.modules, etc.: the original idea was that tests should interact with the importing system as little as possible, to ensure isolation. - Now we have some very minor code duplication, but the logic in each function is way simpler. --- test/support.py | 65 ++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/test/support.py b/test/support.py index 417320a54..01f106565 100644 --- a/test/support.py +++ b/test/support.py @@ -199,33 +199,38 @@ def compile_module(self, ExtensionTemplate, main_src, name, extra_sources): def make_module(self, ExtensionTemplate, main_src, name, extra_sources): """ Compile & load a module. This is NOT a proper import: e.g. - the module is not put into sys.modules + the module is not put into sys.modules. + + We don't want to unnecessarily modify the global state inside tests: + if you are writing a test which needs a proper import, you should not + use make_module but explicitly use compile_module and import it + manually as requied by your test. """ - mod_filename = self.compile_module( + so_filename = self.compile_module( ExtensionTemplate, main_src, name, extra_sources) - return self.load_module(name, mod_filename) - - def load_module(self, name, mod_filename): - # It is important to do the imports only here, because this file will - # be imported also by PyPy tests which runs on Python2 - import importlib - import sys - import os - if name in sys.modules: - raise ValueError( - "Test module {!r} already present in sys.modules".format(name)) - importlib.invalidate_caches() - mod_dir = os.path.dirname(mod_filename) - try: - sys.path.insert(0, mod_dir) - module = importlib.import_module(name) - finally: - # assert that the module import didn't change the sys.path entry - # that was added above, then remove the entry. - assert sys.path[0] == mod_dir - del sys.path[0] - if name in sys.modules: - del sys.modules[name] + if self.hpy_abi == 'universal': + return self.load_universal_module(name, so_filename) + elif self.hpy_abi == 'cpython': + return self.load_cpython_module(name, so_filename) + else: + assert False + + def load_universal_module(self, name, so_filename): + assert self.hpy_abi == 'universal' + import hpy.universal + return hpy.universal.load(name, so_filename) + + def load_cpython_module(self, name, so_filename): + assert self.hpy_abi == 'cpython' + # we've got a normal CPython module compiled with the CPython API/ABI, + # let's load it normally. It is important to do the imports only here, + # because this file will be imported also by PyPy tests which runs on + # Python2 + import importlib.util + from importlib.machinery import ExtensionFileLoader + spec = importlib.util.spec_from_file_location(name, so_filename) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) return module @@ -292,11 +297,11 @@ def _build(tmpdir, ext, hpy_devel, hpy_abi, compiler_verbose=0, debug=None): dist.run_command('build_ext') cmd_obj = dist.get_command_obj('build_ext') outputs = cmd_obj.get_outputs() - if hpy_abi == "cpython": - [mod_filename] = [x for x in outputs if not x.endswith(".py")] - else: - [mod_filename] = [x for x in outputs if x.endswith(".py")] + sonames = [x for x in outputs if + not x.endswith(".py") and not x.endswith(".pyc")] + assert len(sonames) == 1, 'build_ext is not supposed to return multiple DLLs' + soname = sonames[0] finally: distutils.log.set_threshold(old_level) - return mod_filename + return soname From 18c4a34eb8f1867c8bf3763a41b6d6cab9196cde Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 18:29:38 +0100 Subject: [PATCH 10/65] Implement hpy.universal.load(..., debug=True) It is now possible to load an universal module in debug mode: in that case hpy.universal imports hpy.debug._ctx and asks it to wrap the global context. At the moment the only difference is that the debug ctx has a different ctx->name, but this is enough to make test_debug.test_ctx_name passing! Moreover, the hpy_abi pytest fixture now can 'cpython', 'universal' or 'debug', which means that all tests will be automatically tested also in debug mode. In theory, we could cache the result of the compilation since 'universal' and 'debug' compiles the very same .hpy.so file, but on my machine the compilation itself seems very fast, so I'm not sure it is worth the complexity. We might want to revisit it in the future. --- hpy/debug/src/_ctx.c | 2 +- hpy/devel/__init__.py | 5 +++- hpy/universal/src/hpymodule.c | 51 ++++++++++++++++++++++++++++++----- test/conftest.py | 2 +- test/support.py | 17 ++++++++---- test/test_debug.py | 2 ++ 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/hpy/debug/src/_ctx.c b/hpy/debug/src/_ctx.c index b3faaf099..02f77041e 100644 --- a/hpy/debug/src/_ctx.c +++ b/hpy/debug/src/_ctx.c @@ -30,7 +30,7 @@ void debug_ctx_init(HPyContext original_ctx) // initialize debug_ctx: eventually we will autogen a static initializer // for debug_ctx. For now, just copy&fix memcpy(&debug_ctx, original_ctx, sizeof(struct _HPyContext_s)); - debug_ctx.name = "HPy Debug Mode"; + debug_ctx.name = "HPy Debug Mode ABI"; debug_ctx._private = &debug_info; debug_ctx.ctx_Add = dbg_Add; } diff --git a/hpy/devel/__init__.py b/hpy/devel/__init__.py index bca887527..29291e722 100644 --- a/hpy/devel/__init__.py +++ b/hpy/devel/__init__.py @@ -187,9 +187,12 @@ def _finalize_hpy_ext(self, ext): if ext.hpy_abi == 'cpython': ext.sources += self.hpydevel.get_ctx_sources() ext._hpy_needs_stub = False - if ext.hpy_abi == 'universal': + elif ext.hpy_abi == 'universal': ext.define_macros.append(('HPY_UNIVERSAL_ABI', None)) ext._hpy_needs_stub = True + else: + raise DistutilsError('Unknown HPy ABI: %s. Valid values are: ' + 'cpython, universal' % ext.hpy_abi) def finalize_options(self): self._extensions = self.distribution.ext_modules or [] diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 0af186829..c166d2c1d 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -26,6 +26,43 @@ static PyObject *set_debug(PyObject *self, PyObject *args) static const char *prefix = "HPyInit"; +static HPyContext get_context(int debug) +{ + if (!debug) + // standard case, just return the plain universal ctx + return &g_universal_ctx; + + // debug context: get it from hpy.debug._ctx. + // WARNING: if you try to call load("hpy.debug._ctx", ..., debug=True) you + // might get infinite recursion here + PyObject *mod = NULL; + PyObject *debug_ctx_addr = NULL; + HPyContext debug_ctx = NULL; + mod = PyImport_ImportModule("hpy.debug._ctx"); + if (!mod) + goto error; + + // XXX: maybe we should use a PyCapsule to export the ctx and/or the + // function which wraps the ctx? + debug_ctx_addr = PyObject_CallMethod(mod, "get_debug_ctx", ""); + if (!debug_ctx_addr) + goto error; + + debug_ctx = (HPyContext)PyLong_AsLong(debug_ctx_addr); + if (PyErr_Occurred()) + goto error; + + Py_DECREF(mod); + Py_DECREF(debug_ctx_addr); + return debug_ctx; + + error: + Py_XDECREF(mod); + Py_XDECREF(debug_ctx_addr); + return NULL; +} + + static PyObject * get_encoded_name(PyObject *name) { PyObject *tmp; @@ -69,7 +106,7 @@ get_encoded_name(PyObject *name) { return NULL; } -static PyObject *do_load(PyObject *name_unicode, PyObject *path) +static PyObject *do_load(PyObject *name_unicode, PyObject *path, int debug) { PyObject *name = NULL; PyObject *pathbytes = NULL; @@ -106,7 +143,8 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path) goto error; } - HPy mod = ((InitFuncPtr)initfn)(&g_universal_ctx); + HPyContext ctx = get_context(debug); + HPy mod = ((InitFuncPtr)initfn)(ctx); if (HPy_IsNull(mod)) goto error; PyObject *py_mod = _h2py(mod); @@ -123,14 +161,15 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path) static PyObject *load(PyObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"name", "path", NULL}; + static char *kwlist[] = {"name", "path", "debug", NULL}; PyObject *name_unicode; PyObject *path; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO", kwlist, - &name_unicode, &path)) { + int debug = 0; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|p", kwlist, + &name_unicode, &path, &debug)) { return NULL; } - return do_load(name_unicode, path); + return do_load(name_unicode, path, debug); } static PyObject *get_version(PyObject *self, PyObject *ignored) diff --git a/test/conftest.py b/test/conftest.py index b601413f7..2581619aa 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -11,7 +11,7 @@ def hpy_devel(request): from hpy.devel import HPyDevel return HPyDevel() -@pytest.fixture(params=['cpython', 'universal']) +@pytest.fixture(params=['cpython', 'universal', 'debug']) def hpy_abi(request): return request.param diff --git a/test/support.py b/test/support.py index 01f106565..9f08c3e11 100644 --- a/test/support.py +++ b/test/support.py @@ -190,9 +190,14 @@ def compile_module(self, ExtensionTemplate, main_src, name, extra_sources): extra_compile_args=compile_args, extra_link_args=link_args) + hpy_abi = self.hpy_abi + if hpy_abi == 'debug': + # there is no compile-time difference between universal and debug + # extensions. The only difference happens at load time + hpy_abi = 'universal' so_filename = c_compile(str(self.tmpdir), ext, hpy_devel=self.hpy_devel, - hpy_abi=self.hpy_abi, + hpy_abi=hpy_abi, compiler_verbose=self.compiler_verbose) return so_filename @@ -209,16 +214,18 @@ def make_module(self, ExtensionTemplate, main_src, name, extra_sources): so_filename = self.compile_module( ExtensionTemplate, main_src, name, extra_sources) if self.hpy_abi == 'universal': - return self.load_universal_module(name, so_filename) + return self.load_universal_module(name, so_filename, debug=False) + elif self.hpy_abi == 'debug': + return self.load_universal_module(name, so_filename, debug=True) elif self.hpy_abi == 'cpython': return self.load_cpython_module(name, so_filename) else: assert False - def load_universal_module(self, name, so_filename): - assert self.hpy_abi == 'universal' + def load_universal_module(self, name, so_filename, debug): + assert self.hpy_abi in ('universal', 'debug') import hpy.universal - return hpy.universal.load(name, so_filename) + return hpy.universal.load(name, so_filename, debug=debug) def load_cpython_module(self, name, so_filename): assert self.hpy_abi == 'cpython' diff --git a/test/test_debug.py b/test/test_debug.py index 8e27468c9..ff8174917 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -21,6 +21,8 @@ def test_ctx_name(self, hpy_abi): # this can be "HPy Universal ABI (CPython backend)" or # "... (PyPy backend)", etc. assert ctx_name.startswith('HPy Universal ABI') + elif hpy_abi == 'debug': + assert ctx_name.startswith('HPy Debug Mode ABI') else: assert False, 'unexpected hpy_abi: %s' % hpy_abi From 85ae3ae7be424d656d77fd0531ad102ddeeba7e4 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 18:51:42 +0100 Subject: [PATCH 11/65] blindly try to fix the tests --- azure-pipelines.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8085bac82..119f73cd3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -26,7 +26,9 @@ jobs: pythonVersion: $(python.version) - script: python -m pip install --upgrade pip wheel displayName: 'Install dependencies' - - script: python -m pip install . + - script: | + python -m pip install . + python setup_hpy_debug.py install # there is no way to use pip with this :( displayName: 'Build project' - script: | pip install pytest pytest-azurepipelines pytest-xdist From dd0c650649a3a40d9967291fc477f161066e970b Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 16 Dec 2020 18:55:30 +0100 Subject: [PATCH 12/65] try again --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 119f73cd3..1b91a13a5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -28,7 +28,7 @@ jobs: displayName: 'Install dependencies' - script: | python -m pip install . - python setup_hpy_debug.py install # there is no way to use pip with this :( + python setup_hpy_debug.py --hpy-abi=universal install # there is no way to use pip with this :( displayName: 'Build project' - script: | pip install pytest pytest-azurepipelines pytest-xdist From fa5849f9cf440a22d1b2afe653af761e7cd55e2d Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 17 Dec 2020 11:14:08 +0100 Subject: [PATCH 13/65] Completely change the approach and greatly simplify the code. The original approach was to have a separate hpy.debug module which wraps a generic ctx into a debug ctx; hpy.debug could in theory be distributed independently than hpy.universal and be used both by CPython, PyPy, GraalPython, etc. The theory was nice but in practice it made the code and file structure unnecessarily complex. The new approach is: - keep hpy/debuc/src/*.c: this is still a generic implementation of the debug mode which wraps a generic context - bundle the debug code inside hpy.universal - PyPy/GraalPython/etc. will be able to vendor hpy/debug/src/*.c and compile it together with their own implementation of HPy --- Makefile | 6 +--- azure-pipelines.yml | 4 +-- hpy/debug/src/{_ctx.c => debug_ctx.c} | 44 ++++++--------------------- hpy/debug/src/{_ctx.h => debug_ctx.h} | 14 ++++----- hpy/debug/src/hpy_debug.h | 8 +++++ hpy/universal/src/hpymodule.c | 36 +++------------------- setup.py | 2 ++ setup_hpy_debug.py | 19 ------------ test/test_debug.py | 25 --------------- 9 files changed, 32 insertions(+), 126 deletions(-) rename hpy/debug/src/{_ctx.c => debug_ctx.c} (51%) rename hpy/debug/src/{_ctx.h => debug_ctx.h} (72%) create mode 100644 hpy/debug/src/hpy_debug.h delete mode 100644 setup_hpy_debug.py diff --git a/Makefile b/Makefile index f88acaf66..e16b95306 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,10 @@ .PHONY: all -all: hpy.universal hpy.debug +all: hpy.universal .PHONY: hpy.universal hpy.universal: python3 setup.py build_ext -if -.PHONY: hpy.debug -hpy.debug: - python3 setup_hpy_debug.py --hpy-abi=universal build_ext -if - debug: HPY_DEBUG=1 make all diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1b91a13a5..8085bac82 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -26,9 +26,7 @@ jobs: pythonVersion: $(python.version) - script: python -m pip install --upgrade pip wheel displayName: 'Install dependencies' - - script: | - python -m pip install . - python setup_hpy_debug.py --hpy-abi=universal install # there is no way to use pip with this :( + - script: python -m pip install . displayName: 'Build project' - script: | pip install pytest pytest-azurepipelines pytest-xdist diff --git a/hpy/debug/src/_ctx.c b/hpy/debug/src/debug_ctx.c similarity index 51% rename from hpy/debug/src/_ctx.c rename to hpy/debug/src/debug_ctx.c index 02f77041e..1af01dba7 100644 --- a/hpy/debug/src/_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -1,4 +1,5 @@ -#include "_ctx.h" +#include "hpy_debug.h" +#include "debug_ctx.h" #include #include @@ -11,7 +12,6 @@ static struct _HPyContext_s debug_ctx = { .name = NULL, }; - static HPy dbg_Add(HPyContext ctx, HPy a, HPy b) { printf("dbg_Add...\n"); @@ -21,8 +21,11 @@ static HPy dbg_Add(HPyContext ctx, HPy a, HPy b) void debug_ctx_init(HPyContext original_ctx) { - if (debug_ctx.name) - return; // already initialized + if (debug_ctx.name) { + // already initialized + assert(get_info(debug_ctx)->original_ctx == original_ctx); // sanity check + return; + } // initialize debug_info debug_info.original_ctx = original_ctx; @@ -35,35 +38,8 @@ void debug_ctx_init(HPyContext original_ctx) debug_ctx.ctx_Add = dbg_Add; } - -HPyDef_METH(get_debug_ctx, "get_debug_ctx", get_debug_ctx_impl, HPyFunc_NOARGS) -static HPy get_debug_ctx_impl(HPyContext ctx, HPy self) -{ - assert(debug_ctx.name != NULL); - return HPyLong_FromLong(ctx, (long)&debug_ctx); -} - - -static HPyDef *module_defines[] = { - &get_debug_ctx, - NULL -}; - -static HPyModuleDef moduledef = { - HPyModuleDef_HEAD_INIT, - .m_name = "hpy.debug._ctx", - .m_doc = "HPy debug context", - .m_size = -1, - .defines = module_defines -}; - - -HPy_MODINIT(_ctx) -static HPy init__ctx_impl(HPyContext ctx) +HPyContext hpy_debug_get_ctx(HPyContext original_ctx) { - HPy m = HPyModule_Create(ctx, &moduledef); - if (HPy_IsNull(m)) - return HPy_NULL; - debug_ctx_init(ctx); - return m; + debug_ctx_init(original_ctx); + return &debug_ctx; } diff --git a/hpy/debug/src/_ctx.h b/hpy/debug/src/debug_ctx.h similarity index 72% rename from hpy/debug/src/_ctx.h rename to hpy/debug/src/debug_ctx.h index 9cd3869a0..588b7e518 100644 --- a/hpy/debug/src/_ctx.h +++ b/hpy/debug/src/debug_ctx.h @@ -1,14 +1,12 @@ -#ifndef HPY_DEBUG__CTX_H -#define HPY_DEBUG__CTX_H +#ifndef HPY_DEBUG_CTX_H +#define HPY_DEBUG_CTX_H + +// this header is for internal use. The public API of the debug mode is in +// hpy_debug.h #include #include "hpy.h" - -#ifndef HPY_UNIVERSAL_ABI -# error "hpy.debug should be built with --hpy-abi=universal" -#endif - // "deboff" is the closest to "debug" I could come up with :) static const long HPY_DEBUG_MAGIC = 0xDEB0FF; @@ -25,4 +23,4 @@ static HPyDebugInfo *get_info(HPyContext ctx) } -#endif /* HPY_DEBUG__CTX_H */ +#endif /* HPY_DEBUG_CTX_H */ diff --git a/hpy/debug/src/hpy_debug.h b/hpy/debug/src/hpy_debug.h new file mode 100644 index 000000000..699c4e6f8 --- /dev/null +++ b/hpy/debug/src/hpy_debug.h @@ -0,0 +1,8 @@ +#ifndef HPY_DEBUG_H +#define HPY_DEBUG_H + +#include "hpy.h" + +HPyContext hpy_debug_get_ctx(HPyContext original_ctx); + +#endif /* HPY_DEBUG_H */ diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index c166d2c1d..97b3332df 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -11,6 +11,7 @@ #include "api.h" #include "handles.h" #include "common/version.h" +#include "hpy_debug.h" #ifdef PYPY_VERSION # error "Cannot build hpy.univeral on top of PyPy. PyPy comes with its own version of it" @@ -28,41 +29,12 @@ static const char *prefix = "HPyInit"; static HPyContext get_context(int debug) { - if (!debug) - // standard case, just return the plain universal ctx + if (debug) + return hpy_debug_get_ctx(&g_universal_ctx); + else return &g_universal_ctx; - - // debug context: get it from hpy.debug._ctx. - // WARNING: if you try to call load("hpy.debug._ctx", ..., debug=True) you - // might get infinite recursion here - PyObject *mod = NULL; - PyObject *debug_ctx_addr = NULL; - HPyContext debug_ctx = NULL; - mod = PyImport_ImportModule("hpy.debug._ctx"); - if (!mod) - goto error; - - // XXX: maybe we should use a PyCapsule to export the ctx and/or the - // function which wraps the ctx? - debug_ctx_addr = PyObject_CallMethod(mod, "get_debug_ctx", ""); - if (!debug_ctx_addr) - goto error; - - debug_ctx = (HPyContext)PyLong_AsLong(debug_ctx_addr); - if (PyErr_Occurred()) - goto error; - - Py_DECREF(mod); - Py_DECREF(debug_ctx_addr); - return debug_ctx; - - error: - Py_XDECREF(mod); - Py_XDECREF(debug_ctx_addr); - return NULL; } - static PyObject * get_encoded_name(PyObject *name) { PyObject *tmp; diff --git a/setup.py b/setup.py index 37fbe2797..0f99538be 100644 --- a/setup.py +++ b/setup.py @@ -56,10 +56,12 @@ def get_scm_config(): 'hpy/devel/src/runtime/ctx_listbuilder.c', 'hpy/devel/src/runtime/ctx_tuple.c', 'hpy/devel/src/runtime/ctx_tuplebuilder.c', + 'hpy/debug/src/debug_ctx.c', ], include_dirs=[ 'hpy/devel/include', 'hpy/universal/src', + 'hpy/debug/src', ], extra_compile_args=[ '-DHPY_UNIVERSAL_ABI', diff --git a/setup_hpy_debug.py b/setup_hpy_debug.py deleted file mode 100644 index 8b07b242f..000000000 --- a/setup_hpy_debug.py +++ /dev/null @@ -1,19 +0,0 @@ -import os -from setuptools import setup, Extension - -if 'HPY_DEBUG' in os.environ: - EXTRA_COMPILE_ARGS = ['-g', '-O0'] -else: - EXTRA_COMPILE_ARGS = [] - -setup( - name="hpy.debug", - hpy_ext_modules=[ - Extension('hpy.debug._ctx', - extra_compile_args=EXTRA_COMPILE_ARGS, - sources=[ - 'hpy/debug/src/_ctx.c', - ]), - ], - setup_requires=['hpy.devel'], -) diff --git a/test/test_debug.py b/test/test_debug.py index ff8174917..bbbc822d6 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -25,28 +25,3 @@ def test_ctx_name(self, hpy_abi): assert ctx_name.startswith('HPy Debug Mode ABI') else: assert False, 'unexpected hpy_abi: %s' % hpy_abi - - - def test_temp(self, hpy_abi): - import pytest - if hpy_abi != 'universal': - pytest.skip() - mod = self.make_module(""" - HPyDef_METH(f, "f", f_impl, HPyFunc_O) - static HPy f_impl(HPyContext ctx, HPy self, HPy arg) - { - HPyContext ctx2 = (HPyContext)HPyLong_AsLong(ctx, arg); - HPy a = HPyLong_FromLong(ctx, 4); - HPy b = HPyLong_FromLong(ctx, 5); - HPy res = HPy_Add(ctx2, a, b); // note, we are using ctx2! - HPy_Close(ctx, a); - HPy_Close(ctx, b); - return res; - } - @EXPORT(f) - @INIT - """) - from hpy.debug._ctx import get_debug_ctx - ctx2 = get_debug_ctx() - res = mod.f(ctx2) - assert res == 9 From d8a173641aef4ab846d1aaa6f35ba2de6891cc1b Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 17 Dec 2020 11:29:14 +0100 Subject: [PATCH 14/65] some compilers complain that I can't use a static const in a static initializer. Try with a define --- hpy/debug/src/debug_ctx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hpy/debug/src/debug_ctx.h b/hpy/debug/src/debug_ctx.h index 588b7e518..15789a538 100644 --- a/hpy/debug/src/debug_ctx.h +++ b/hpy/debug/src/debug_ctx.h @@ -7,8 +7,8 @@ #include #include "hpy.h" -// "deboff" is the closest to "debug" I could come up with :) -static const long HPY_DEBUG_MAGIC = 0xDEB0FF; +// "debooff" is the closest to "debug" I could come up with :) +#define HPY_DEBUG_MAGIC 0xDEB00FF typedef struct { long magic_number; // used just for sanity checks From d40d85da2a9436e314e70a96439acb7d22d2ae0d Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 17 Dec 2020 11:42:15 +0100 Subject: [PATCH 15/65] test_FatalError needs __file__: make sure it is available also when we load universal modules --- test/support.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/support.py b/test/support.py index 9f08c3e11..57f08443f 100644 --- a/test/support.py +++ b/test/support.py @@ -225,7 +225,9 @@ def make_module(self, ExtensionTemplate, main_src, name, extra_sources): def load_universal_module(self, name, so_filename, debug): assert self.hpy_abi in ('universal', 'debug') import hpy.universal - return hpy.universal.load(name, so_filename, debug=debug) + mod = hpy.universal.load(name, so_filename, debug=debug) + mod.__file__ = so_filename + return mod def load_cpython_module(self, name, so_filename): assert self.hpy_abi == 'cpython' From 2caaa3bbb39637660d5f9ca35bcc1a22ceefb483 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 17 Dec 2020 11:55:58 +0100 Subject: [PATCH 16/65] distutils uses -DNDEBUG by default: make sure to re-enable asserts when we run make debug; this also catches a type error in an assert which was compiled away --- hpy/debug/src/debug_ctx.c | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 1af01dba7..81201b72d 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -23,7 +23,7 @@ void debug_ctx_init(HPyContext original_ctx) { if (debug_ctx.name) { // already initialized - assert(get_info(debug_ctx)->original_ctx == original_ctx); // sanity check + assert(get_info(&debug_ctx)->original_ctx == original_ctx); // sanity check return; } diff --git a/setup.py b/setup.py index 0f99538be..237f25a1e 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, Extension if 'HPY_DEBUG' in os.environ: - EXTRA_COMPILE_ARGS = ['-g', '-O0'] + EXTRA_COMPILE_ARGS = ['-g', '-O0', '-UNDEBUG'] else: EXTRA_COMPILE_ARGS = [] From d6fcfe78a6d49d70a0801d50d2ef5dfca5266345 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Mon, 21 Dec 2020 16:01:58 +0200 Subject: [PATCH 17/65] Move .load_module to test_importing and add some protection against modules ending up in sys.modules. --- test/support.py | 29 +++++++---------------------- test/test_importing.py | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/test/support.py b/test/support.py index 37a74da50..3594796c6 100644 --- a/test/support.py +++ b/test/support.py @@ -224,7 +224,9 @@ def make_module(self, ExtensionTemplate, main_src, name, extra_sources): def load_universal_module(self, name, so_filename, debug): assert self.hpy_abi in ('universal', 'debug') + import sys import hpy.universal + assert name not in sys.modules mod = hpy.universal.load(name, so_filename, debug=debug) mod.__file__ = so_filename return mod @@ -236,33 +238,16 @@ def load_cpython_module(self, name, so_filename): # because this file will be imported also by PyPy tests which runs on # Python2 import importlib.util - spec = importlib.util.spec_from_file_location(name, so_filename) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - return module - - def load_module(self, name, mod_filename): - # It is important to do the imports only here, because this file will - # be imported also by PyPy tests which runs on Python2 - import importlib import sys - import os - if name in sys.modules: - raise ValueError( - "Test module {!r} already present in sys.modules".format(name)) - importlib.invalidate_caches() - mod_dir = os.path.dirname(mod_filename) - sys.path.insert(0, mod_dir) + assert name not in sys.modules + spec = importlib.util.spec_from_file_location(name, so_filename) try: - module = importlib.import_module(name) - assert sys.modules[name] is module + # module_from_spec adds the module to sys.modules + module = importlib.util.module_from_spec(spec) finally: - # assert that the module import didn't change the sys.path entry - # that was added above, then remove the entry. - assert sys.path[0] == mod_dir - del sys.path[0] if name in sys.modules: del sys.modules[name] + spec.loader.exec_module(module) return module diff --git a/test/test_importing.py b/test/test_importing.py index 94de0b11d..7630fa541 100644 --- a/test/test_importing.py +++ b/test/test_importing.py @@ -3,6 +3,28 @@ class TestImporting(HPyTest): + def full_import(self, name, mod_filename): + import importlib + import sys + import os + if name in sys.modules: + raise ValueError( + "Test module {!r} already present in sys.modules".format(name)) + importlib.invalidate_caches() + mod_dir = os.path.dirname(mod_filename) + sys.path.insert(0, mod_dir) + try: + module = importlib.import_module(name) + assert sys.modules[name] is module + finally: + # assert that the module import didn't change the sys.path entry + # that was added above, then remove the entry. + assert sys.path[0] == mod_dir + del sys.path[0] + if name in sys.modules: + del sys.modules[name] + return module + def test_importing_attributes(self): import pytest if not self.supports_ordinary_make_module_imports(): @@ -10,6 +32,7 @@ def test_importing_attributes(self): mod = self.make_module(""" @INIT """, name='mytest') + mod = self.full_import(mod.__name__, mod.__file__) assert mod.__name__ == 'mytest' assert mod.__package__ == '' assert mod.__doc__ == 'some test for hpy' From b6fffec68975c3e109d39d6783b75a2d830c7cef Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 30 Dec 2020 15:29:23 +0100 Subject: [PATCH 18/65] autogenerate the debug wrappers and the definition of the debug ctx. Currently the wrappers simply forwards everything to the original ctx --- hpy/debug/src/autogen_debug_ctx.h | 327 ++++++++++++++ hpy/debug/src/autogen_debug_wrappers.c | 599 +++++++++++++++++++++++++ hpy/debug/src/debug_ctx.c | 62 ++- hpy/debug/src/debug_ctx.h | 2 +- hpy/tools/autogen/__main__.py | 3 + hpy/tools/autogen/debug.py | 79 ++++ setup.py | 1 + 7 files changed, 1054 insertions(+), 19 deletions(-) create mode 100644 hpy/debug/src/autogen_debug_ctx.h create mode 100644 hpy/debug/src/autogen_debug_wrappers.c create mode 100644 hpy/tools/autogen/debug.py diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h new file mode 100644 index 000000000..bdfa8b114 --- /dev/null +++ b/hpy/debug/src/autogen_debug_ctx.h @@ -0,0 +1,327 @@ + +/* + DO NOT EDIT THIS FILE! + + This file is automatically generated by hpy.tools.autogen.debug.autogen_debug_ctx_def_h + See also hpy.tools.autogen and hpy/tools/public_api.h + + Run this to regenerate: + make autogen + +*/ + +HPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def); +HPy debug_ctx_Dup(HPyContext ctx, HPy h); +void debug_ctx_Close(HPyContext ctx, HPy h); +HPy debug_ctx_Long_FromLong(HPyContext ctx, long value); +HPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value); +HPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v); +HPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v); +HPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value); +HPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value); +long debug_ctx_Long_AsLong(HPyContext ctx, HPy h); +unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, HPy h); +unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, HPy h); +long long debug_ctx_Long_AsLongLong(HPyContext ctx, HPy h); +unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, HPy h); +unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, HPy h); +size_t debug_ctx_Long_AsSize_t(HPyContext ctx, HPy h); +HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, HPy h); +HPy debug_ctx_Float_FromDouble(HPyContext ctx, double v); +double debug_ctx_Float_AsDouble(HPyContext ctx, HPy h); +HPy_ssize_t debug_ctx_Length(HPyContext ctx, HPy h); +int debug_ctx_Number_Check(HPyContext ctx, HPy h); +HPy debug_ctx_Add(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Subtract(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Multiply(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_MatrixMultiply(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_FloorDivide(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_TrueDivide(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Remainder(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Divmod(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Power(HPyContext ctx, HPy h1, HPy h2, HPy h3); +HPy debug_ctx_Negative(HPyContext ctx, HPy h1); +HPy debug_ctx_Positive(HPyContext ctx, HPy h1); +HPy debug_ctx_Absolute(HPyContext ctx, HPy h1); +HPy debug_ctx_Invert(HPyContext ctx, HPy h1); +HPy debug_ctx_Lshift(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Rshift(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_And(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Xor(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Or(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_Index(HPyContext ctx, HPy h1); +HPy debug_ctx_Long(HPyContext ctx, HPy h1); +HPy debug_ctx_Float(HPyContext ctx, HPy h1); +HPy debug_ctx_InPlaceAdd(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceSubtract(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceMultiply(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceRemainder(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlacePower(HPyContext ctx, HPy h1, HPy h2, HPy h3); +HPy debug_ctx_InPlaceLshift(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceRshift(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceAnd(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceXor(HPyContext ctx, HPy h1, HPy h2); +HPy debug_ctx_InPlaceOr(HPyContext ctx, HPy h1, HPy h2); +void debug_ctx_Err_SetString(HPyContext ctx, HPy h_type, const char *message); +void debug_ctx_Err_SetObject(HPyContext ctx, HPy h_type, HPy h_value); +int debug_ctx_Err_Occurred(HPyContext ctx); +HPy debug_ctx_Err_NoMemory(HPyContext ctx); +void debug_ctx_Err_Clear(HPyContext ctx); +int debug_ctx_IsTrue(HPyContext ctx, HPy h); +HPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params); +HPy debug_ctx_Type_GenericNew(HPyContext ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw); +HPy debug_ctx_GetAttr(HPyContext ctx, HPy obj, HPy name); +HPy debug_ctx_GetAttr_s(HPyContext ctx, HPy obj, const char *name); +int debug_ctx_HasAttr(HPyContext ctx, HPy obj, HPy name); +int debug_ctx_HasAttr_s(HPyContext ctx, HPy obj, const char *name); +int debug_ctx_SetAttr(HPyContext ctx, HPy obj, HPy name, HPy value); +int debug_ctx_SetAttr_s(HPyContext ctx, HPy obj, const char *name, HPy value); +HPy debug_ctx_GetItem(HPyContext ctx, HPy obj, HPy key); +HPy debug_ctx_GetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx); +HPy debug_ctx_GetItem_s(HPyContext ctx, HPy obj, const char *key); +int debug_ctx_SetItem(HPyContext ctx, HPy obj, HPy key, HPy value); +int debug_ctx_SetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx, HPy value); +int debug_ctx_SetItem_s(HPyContext ctx, HPy obj, const char *key, HPy value); +void *debug_ctx_Cast(HPyContext ctx, HPy h); +HPy debug_ctx_New(HPyContext ctx, HPy h_type, void **data); +HPy debug_ctx_Repr(HPyContext ctx, HPy obj); +HPy debug_ctx_Str(HPyContext ctx, HPy obj); +HPy debug_ctx_ASCII(HPyContext ctx, HPy obj); +HPy debug_ctx_Bytes(HPyContext ctx, HPy obj); +HPy debug_ctx_RichCompare(HPyContext ctx, HPy v, HPy w, int op); +int debug_ctx_RichCompareBool(HPyContext ctx, HPy v, HPy w, int op); +HPy_hash_t debug_ctx_Hash(HPyContext ctx, HPy obj); +int debug_ctx_Bytes_Check(HPyContext ctx, HPy h); +HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, HPy h); +HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, HPy h); +char *debug_ctx_Bytes_AsString(HPyContext ctx, HPy h); +char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, HPy h); +HPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v); +HPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len); +HPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8); +int debug_ctx_Unicode_Check(HPyContext ctx, HPy h); +HPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, HPy h); +HPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size); +int debug_ctx_List_Check(HPyContext ctx, HPy h); +HPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len); +int debug_ctx_List_Append(HPyContext ctx, HPy h_list, HPy h_item); +int debug_ctx_Dict_Check(HPyContext ctx, HPy h); +HPy debug_ctx_Dict_New(HPyContext ctx); +void debug_ctx_FatalError(HPyContext ctx, const char *message); +HPy debug_ctx_Tuple_FromArray(HPyContext ctx, HPy items[], HPy_ssize_t n); +HPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj); +cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, HPy h); +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args); +void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self); +HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); +void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item); +HPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder); +void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder); +HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); +void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item); +HPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder); +void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder); +HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size); +int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, HPy h); +void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht); +void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht); + +static struct _HPyContext_s g_debug_ctx = { + .name = "HPy Debug Mode ABI", + ._private = NULL, + .ctx_version = 1, + .h_None = HPy_NULL, + .h_True = HPy_NULL, + .h_False = HPy_NULL, + .h_BaseException = HPy_NULL, + .h_Exception = HPy_NULL, + .h_StopAsyncIteration = HPy_NULL, + .h_StopIteration = HPy_NULL, + .h_GeneratorExit = HPy_NULL, + .h_ArithmeticError = HPy_NULL, + .h_LookupError = HPy_NULL, + .h_AssertionError = HPy_NULL, + .h_AttributeError = HPy_NULL, + .h_BufferError = HPy_NULL, + .h_EOFError = HPy_NULL, + .h_FloatingPointError = HPy_NULL, + .h_OSError = HPy_NULL, + .h_ImportError = HPy_NULL, + .h_ModuleNotFoundError = HPy_NULL, + .h_IndexError = HPy_NULL, + .h_KeyError = HPy_NULL, + .h_KeyboardInterrupt = HPy_NULL, + .h_MemoryError = HPy_NULL, + .h_NameError = HPy_NULL, + .h_OverflowError = HPy_NULL, + .h_RuntimeError = HPy_NULL, + .h_RecursionError = HPy_NULL, + .h_NotImplementedError = HPy_NULL, + .h_SyntaxError = HPy_NULL, + .h_IndentationError = HPy_NULL, + .h_TabError = HPy_NULL, + .h_ReferenceError = HPy_NULL, + .h_SystemError = HPy_NULL, + .h_SystemExit = HPy_NULL, + .h_TypeError = HPy_NULL, + .h_UnboundLocalError = HPy_NULL, + .h_UnicodeError = HPy_NULL, + .h_UnicodeEncodeError = HPy_NULL, + .h_UnicodeDecodeError = HPy_NULL, + .h_UnicodeTranslateError = HPy_NULL, + .h_ValueError = HPy_NULL, + .h_ZeroDivisionError = HPy_NULL, + .h_BlockingIOError = HPy_NULL, + .h_BrokenPipeError = HPy_NULL, + .h_ChildProcessError = HPy_NULL, + .h_ConnectionError = HPy_NULL, + .h_ConnectionAbortedError = HPy_NULL, + .h_ConnectionRefusedError = HPy_NULL, + .h_ConnectionResetError = HPy_NULL, + .h_FileExistsError = HPy_NULL, + .h_FileNotFoundError = HPy_NULL, + .h_InterruptedError = HPy_NULL, + .h_IsADirectoryError = HPy_NULL, + .h_NotADirectoryError = HPy_NULL, + .h_PermissionError = HPy_NULL, + .h_ProcessLookupError = HPy_NULL, + .h_TimeoutError = HPy_NULL, + .h_Warning = HPy_NULL, + .h_UserWarning = HPy_NULL, + .h_DeprecationWarning = HPy_NULL, + .h_PendingDeprecationWarning = HPy_NULL, + .h_SyntaxWarning = HPy_NULL, + .h_RuntimeWarning = HPy_NULL, + .h_FutureWarning = HPy_NULL, + .h_ImportWarning = HPy_NULL, + .h_UnicodeWarning = HPy_NULL, + .h_BytesWarning = HPy_NULL, + .h_ResourceWarning = HPy_NULL, + .h_BaseObjectType = HPy_NULL, + .h_TypeType = HPy_NULL, + .h_LongType = HPy_NULL, + .h_UnicodeType = HPy_NULL, + .h_TupleType = HPy_NULL, + .h_ListType = HPy_NULL, + .ctx_Module_Create = &debug_ctx_Module_Create, + .ctx_Dup = &debug_ctx_Dup, + .ctx_Close = &debug_ctx_Close, + .ctx_Long_FromLong = &debug_ctx_Long_FromLong, + .ctx_Long_FromUnsignedLong = &debug_ctx_Long_FromUnsignedLong, + .ctx_Long_FromLongLong = &debug_ctx_Long_FromLongLong, + .ctx_Long_FromUnsignedLongLong = &debug_ctx_Long_FromUnsignedLongLong, + .ctx_Long_FromSize_t = &debug_ctx_Long_FromSize_t, + .ctx_Long_FromSsize_t = &debug_ctx_Long_FromSsize_t, + .ctx_Long_AsLong = &debug_ctx_Long_AsLong, + .ctx_Long_AsUnsignedLong = &debug_ctx_Long_AsUnsignedLong, + .ctx_Long_AsUnsignedLongMask = &debug_ctx_Long_AsUnsignedLongMask, + .ctx_Long_AsLongLong = &debug_ctx_Long_AsLongLong, + .ctx_Long_AsUnsignedLongLong = &debug_ctx_Long_AsUnsignedLongLong, + .ctx_Long_AsUnsignedLongLongMask = &debug_ctx_Long_AsUnsignedLongLongMask, + .ctx_Long_AsSize_t = &debug_ctx_Long_AsSize_t, + .ctx_Long_AsSsize_t = &debug_ctx_Long_AsSsize_t, + .ctx_Float_FromDouble = &debug_ctx_Float_FromDouble, + .ctx_Float_AsDouble = &debug_ctx_Float_AsDouble, + .ctx_Length = &debug_ctx_Length, + .ctx_Number_Check = &debug_ctx_Number_Check, + .ctx_Add = &debug_ctx_Add, + .ctx_Subtract = &debug_ctx_Subtract, + .ctx_Multiply = &debug_ctx_Multiply, + .ctx_MatrixMultiply = &debug_ctx_MatrixMultiply, + .ctx_FloorDivide = &debug_ctx_FloorDivide, + .ctx_TrueDivide = &debug_ctx_TrueDivide, + .ctx_Remainder = &debug_ctx_Remainder, + .ctx_Divmod = &debug_ctx_Divmod, + .ctx_Power = &debug_ctx_Power, + .ctx_Negative = &debug_ctx_Negative, + .ctx_Positive = &debug_ctx_Positive, + .ctx_Absolute = &debug_ctx_Absolute, + .ctx_Invert = &debug_ctx_Invert, + .ctx_Lshift = &debug_ctx_Lshift, + .ctx_Rshift = &debug_ctx_Rshift, + .ctx_And = &debug_ctx_And, + .ctx_Xor = &debug_ctx_Xor, + .ctx_Or = &debug_ctx_Or, + .ctx_Index = &debug_ctx_Index, + .ctx_Long = &debug_ctx_Long, + .ctx_Float = &debug_ctx_Float, + .ctx_InPlaceAdd = &debug_ctx_InPlaceAdd, + .ctx_InPlaceSubtract = &debug_ctx_InPlaceSubtract, + .ctx_InPlaceMultiply = &debug_ctx_InPlaceMultiply, + .ctx_InPlaceMatrixMultiply = &debug_ctx_InPlaceMatrixMultiply, + .ctx_InPlaceFloorDivide = &debug_ctx_InPlaceFloorDivide, + .ctx_InPlaceTrueDivide = &debug_ctx_InPlaceTrueDivide, + .ctx_InPlaceRemainder = &debug_ctx_InPlaceRemainder, + .ctx_InPlacePower = &debug_ctx_InPlacePower, + .ctx_InPlaceLshift = &debug_ctx_InPlaceLshift, + .ctx_InPlaceRshift = &debug_ctx_InPlaceRshift, + .ctx_InPlaceAnd = &debug_ctx_InPlaceAnd, + .ctx_InPlaceXor = &debug_ctx_InPlaceXor, + .ctx_InPlaceOr = &debug_ctx_InPlaceOr, + .ctx_Err_SetString = &debug_ctx_Err_SetString, + .ctx_Err_SetObject = &debug_ctx_Err_SetObject, + .ctx_Err_Occurred = &debug_ctx_Err_Occurred, + .ctx_Err_NoMemory = &debug_ctx_Err_NoMemory, + .ctx_Err_Clear = &debug_ctx_Err_Clear, + .ctx_IsTrue = &debug_ctx_IsTrue, + .ctx_Type_FromSpec = &debug_ctx_Type_FromSpec, + .ctx_Type_GenericNew = &debug_ctx_Type_GenericNew, + .ctx_GetAttr = &debug_ctx_GetAttr, + .ctx_GetAttr_s = &debug_ctx_GetAttr_s, + .ctx_HasAttr = &debug_ctx_HasAttr, + .ctx_HasAttr_s = &debug_ctx_HasAttr_s, + .ctx_SetAttr = &debug_ctx_SetAttr, + .ctx_SetAttr_s = &debug_ctx_SetAttr_s, + .ctx_GetItem = &debug_ctx_GetItem, + .ctx_GetItem_i = &debug_ctx_GetItem_i, + .ctx_GetItem_s = &debug_ctx_GetItem_s, + .ctx_SetItem = &debug_ctx_SetItem, + .ctx_SetItem_i = &debug_ctx_SetItem_i, + .ctx_SetItem_s = &debug_ctx_SetItem_s, + .ctx_Cast = &debug_ctx_Cast, + .ctx_New = &debug_ctx_New, + .ctx_Repr = &debug_ctx_Repr, + .ctx_Str = &debug_ctx_Str, + .ctx_ASCII = &debug_ctx_ASCII, + .ctx_Bytes = &debug_ctx_Bytes, + .ctx_RichCompare = &debug_ctx_RichCompare, + .ctx_RichCompareBool = &debug_ctx_RichCompareBool, + .ctx_Hash = &debug_ctx_Hash, + .ctx_Bytes_Check = &debug_ctx_Bytes_Check, + .ctx_Bytes_Size = &debug_ctx_Bytes_Size, + .ctx_Bytes_GET_SIZE = &debug_ctx_Bytes_GET_SIZE, + .ctx_Bytes_AsString = &debug_ctx_Bytes_AsString, + .ctx_Bytes_AS_STRING = &debug_ctx_Bytes_AS_STRING, + .ctx_Bytes_FromString = &debug_ctx_Bytes_FromString, + .ctx_Bytes_FromStringAndSize = &debug_ctx_Bytes_FromStringAndSize, + .ctx_Unicode_FromString = &debug_ctx_Unicode_FromString, + .ctx_Unicode_Check = &debug_ctx_Unicode_Check, + .ctx_Unicode_AsUTF8String = &debug_ctx_Unicode_AsUTF8String, + .ctx_Unicode_FromWideChar = &debug_ctx_Unicode_FromWideChar, + .ctx_List_Check = &debug_ctx_List_Check, + .ctx_List_New = &debug_ctx_List_New, + .ctx_List_Append = &debug_ctx_List_Append, + .ctx_Dict_Check = &debug_ctx_Dict_Check, + .ctx_Dict_New = &debug_ctx_Dict_New, + .ctx_FatalError = &debug_ctx_FatalError, + .ctx_Tuple_FromArray = &debug_ctx_Tuple_FromArray, + .ctx_FromPyObject = &debug_ctx_FromPyObject, + .ctx_AsPyObject = &debug_ctx_AsPyObject, + .ctx_CallRealFunctionFromTrampoline = &debug_ctx_CallRealFunctionFromTrampoline, + .ctx_CallDestroyAndThenDealloc = &debug_ctx_CallDestroyAndThenDealloc, + .ctx_ListBuilder_New = &debug_ctx_ListBuilder_New, + .ctx_ListBuilder_Set = &debug_ctx_ListBuilder_Set, + .ctx_ListBuilder_Build = &debug_ctx_ListBuilder_Build, + .ctx_ListBuilder_Cancel = &debug_ctx_ListBuilder_Cancel, + .ctx_TupleBuilder_New = &debug_ctx_TupleBuilder_New, + .ctx_TupleBuilder_Set = &debug_ctx_TupleBuilder_Set, + .ctx_TupleBuilder_Build = &debug_ctx_TupleBuilder_Build, + .ctx_TupleBuilder_Cancel = &debug_ctx_TupleBuilder_Cancel, + .ctx_Tracker_New = &debug_ctx_Tracker_New, + .ctx_Tracker_Add = &debug_ctx_Tracker_Add, + .ctx_Tracker_ForgetAll = &debug_ctx_Tracker_ForgetAll, + .ctx_Tracker_Close = &debug_ctx_Tracker_Close, +}; diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c new file mode 100644 index 000000000..336849625 --- /dev/null +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -0,0 +1,599 @@ + +/* + DO NOT EDIT THIS FILE! + + This file is automatically generated by hpy.tools.autogen.debug.autogen_debug_wrappers + See also hpy.tools.autogen and hpy/tools/public_api.h + + Run this to regenerate: + make autogen + +*/ + +#include "debug_ctx.h" + +HPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) +{ + return HPyModule_Create(get_info(ctx)->original_ctx, def); +} + +HPy debug_ctx_Dup(HPyContext ctx, HPy h) +{ + return HPy_Dup(get_info(ctx)->original_ctx, h); +} + +void debug_ctx_Close(HPyContext ctx, HPy h) +{ + HPy_Close(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Long_FromLong(HPyContext ctx, long value) +{ + return HPyLong_FromLong(get_info(ctx)->original_ctx, value); +} + +HPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) +{ + return HPyLong_FromUnsignedLong(get_info(ctx)->original_ctx, value); +} + +HPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) +{ + return HPyLong_FromLongLong(get_info(ctx)->original_ctx, v); +} + +HPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) +{ + return HPyLong_FromUnsignedLongLong(get_info(ctx)->original_ctx, v); +} + +HPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) +{ + return HPyLong_FromSize_t(get_info(ctx)->original_ctx, value); +} + +HPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) +{ + return HPyLong_FromSsize_t(get_info(ctx)->original_ctx, value); +} + +long debug_ctx_Long_AsLong(HPyContext ctx, HPy h) +{ + return HPyLong_AsLong(get_info(ctx)->original_ctx, h); +} + +unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, HPy h) +{ + return HPyLong_AsUnsignedLong(get_info(ctx)->original_ctx, h); +} + +unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, HPy h) +{ + return HPyLong_AsUnsignedLongMask(get_info(ctx)->original_ctx, h); +} + +long long debug_ctx_Long_AsLongLong(HPyContext ctx, HPy h) +{ + return HPyLong_AsLongLong(get_info(ctx)->original_ctx, h); +} + +unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, HPy h) +{ + return HPyLong_AsUnsignedLongLong(get_info(ctx)->original_ctx, h); +} + +unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, HPy h) +{ + return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->original_ctx, h); +} + +size_t debug_ctx_Long_AsSize_t(HPyContext ctx, HPy h) +{ + return HPyLong_AsSize_t(get_info(ctx)->original_ctx, h); +} + +HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, HPy h) +{ + return HPyLong_AsSsize_t(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Float_FromDouble(HPyContext ctx, double v) +{ + return HPyFloat_FromDouble(get_info(ctx)->original_ctx, v); +} + +double debug_ctx_Float_AsDouble(HPyContext ctx, HPy h) +{ + return HPyFloat_AsDouble(get_info(ctx)->original_ctx, h); +} + +HPy_ssize_t debug_ctx_Length(HPyContext ctx, HPy h) +{ + return HPy_Length(get_info(ctx)->original_ctx, h); +} + +int debug_ctx_Number_Check(HPyContext ctx, HPy h) +{ + return HPyNumber_Check(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Add(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Add(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Subtract(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Subtract(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Multiply(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Multiply(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_MatrixMultiply(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_MatrixMultiply(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_FloorDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_FloorDivide(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_TrueDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_TrueDivide(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Remainder(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Remainder(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Divmod(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Divmod(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Power(HPyContext ctx, HPy h1, HPy h2, HPy h3) +{ + return HPy_Power(get_info(ctx)->original_ctx, h1, h2, h3); +} + +HPy debug_ctx_Negative(HPyContext ctx, HPy h1) +{ + return HPy_Negative(get_info(ctx)->original_ctx, h1); +} + +HPy debug_ctx_Positive(HPyContext ctx, HPy h1) +{ + return HPy_Positive(get_info(ctx)->original_ctx, h1); +} + +HPy debug_ctx_Absolute(HPyContext ctx, HPy h1) +{ + return HPy_Absolute(get_info(ctx)->original_ctx, h1); +} + +HPy debug_ctx_Invert(HPyContext ctx, HPy h1) +{ + return HPy_Invert(get_info(ctx)->original_ctx, h1); +} + +HPy debug_ctx_Lshift(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Lshift(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Rshift(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Rshift(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_And(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_And(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Xor(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Xor(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Or(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_Or(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_Index(HPyContext ctx, HPy h1) +{ + return HPy_Index(get_info(ctx)->original_ctx, h1); +} + +HPy debug_ctx_Long(HPyContext ctx, HPy h1) +{ + return HPy_Long(get_info(ctx)->original_ctx, h1); +} + +HPy debug_ctx_Float(HPyContext ctx, HPy h1) +{ + return HPy_Float(get_info(ctx)->original_ctx, h1); +} + +HPy debug_ctx_InPlaceAdd(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceAdd(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceSubtract(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceSubtract(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceMultiply(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceMultiply(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceMatrixMultiply(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceFloorDivide(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceTrueDivide(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceRemainder(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceRemainder(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlacePower(HPyContext ctx, HPy h1, HPy h2, HPy h3) +{ + return HPy_InPlacePower(get_info(ctx)->original_ctx, h1, h2, h3); +} + +HPy debug_ctx_InPlaceLshift(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceLshift(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceRshift(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceRshift(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceAnd(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceAnd(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceXor(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceXor(get_info(ctx)->original_ctx, h1, h2); +} + +HPy debug_ctx_InPlaceOr(HPyContext ctx, HPy h1, HPy h2) +{ + return HPy_InPlaceOr(get_info(ctx)->original_ctx, h1, h2); +} + +void debug_ctx_Err_SetString(HPyContext ctx, HPy h_type, const char *message) +{ + HPyErr_SetString(get_info(ctx)->original_ctx, h_type, message); +} + +void debug_ctx_Err_SetObject(HPyContext ctx, HPy h_type, HPy h_value) +{ + HPyErr_SetObject(get_info(ctx)->original_ctx, h_type, h_value); +} + +int debug_ctx_Err_Occurred(HPyContext ctx) +{ + return HPyErr_Occurred(get_info(ctx)->original_ctx); +} + +HPy debug_ctx_Err_NoMemory(HPyContext ctx) +{ + return HPyErr_NoMemory(get_info(ctx)->original_ctx); +} + +void debug_ctx_Err_Clear(HPyContext ctx) +{ + HPyErr_Clear(get_info(ctx)->original_ctx); +} + +int debug_ctx_IsTrue(HPyContext ctx, HPy h) +{ + return HPy_IsTrue(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) +{ + return HPyType_FromSpec(get_info(ctx)->original_ctx, spec, params); +} + +HPy debug_ctx_Type_GenericNew(HPyContext ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw) +{ + return HPyType_GenericNew(get_info(ctx)->original_ctx, type, args, nargs, kw); +} + +HPy debug_ctx_GetAttr(HPyContext ctx, HPy obj, HPy name) +{ + return HPy_GetAttr(get_info(ctx)->original_ctx, obj, name); +} + +HPy debug_ctx_GetAttr_s(HPyContext ctx, HPy obj, const char *name) +{ + return HPy_GetAttr_s(get_info(ctx)->original_ctx, obj, name); +} + +int debug_ctx_HasAttr(HPyContext ctx, HPy obj, HPy name) +{ + return HPy_HasAttr(get_info(ctx)->original_ctx, obj, name); +} + +int debug_ctx_HasAttr_s(HPyContext ctx, HPy obj, const char *name) +{ + return HPy_HasAttr_s(get_info(ctx)->original_ctx, obj, name); +} + +int debug_ctx_SetAttr(HPyContext ctx, HPy obj, HPy name, HPy value) +{ + return HPy_SetAttr(get_info(ctx)->original_ctx, obj, name, value); +} + +int debug_ctx_SetAttr_s(HPyContext ctx, HPy obj, const char *name, HPy value) +{ + return HPy_SetAttr_s(get_info(ctx)->original_ctx, obj, name, value); +} + +HPy debug_ctx_GetItem(HPyContext ctx, HPy obj, HPy key) +{ + return HPy_GetItem(get_info(ctx)->original_ctx, obj, key); +} + +HPy debug_ctx_GetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx) +{ + return HPy_GetItem_i(get_info(ctx)->original_ctx, obj, idx); +} + +HPy debug_ctx_GetItem_s(HPyContext ctx, HPy obj, const char *key) +{ + return HPy_GetItem_s(get_info(ctx)->original_ctx, obj, key); +} + +int debug_ctx_SetItem(HPyContext ctx, HPy obj, HPy key, HPy value) +{ + return HPy_SetItem(get_info(ctx)->original_ctx, obj, key, value); +} + +int debug_ctx_SetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx, HPy value) +{ + return HPy_SetItem_i(get_info(ctx)->original_ctx, obj, idx, value); +} + +int debug_ctx_SetItem_s(HPyContext ctx, HPy obj, const char *key, HPy value) +{ + return HPy_SetItem_s(get_info(ctx)->original_ctx, obj, key, value); +} + +void *debug_ctx_Cast(HPyContext ctx, HPy h) +{ + return _HPy_Cast(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_New(HPyContext ctx, HPy h_type, void **data) +{ + return _HPy_New(get_info(ctx)->original_ctx, h_type, data); +} + +HPy debug_ctx_Repr(HPyContext ctx, HPy obj) +{ + return HPy_Repr(get_info(ctx)->original_ctx, obj); +} + +HPy debug_ctx_Str(HPyContext ctx, HPy obj) +{ + return HPy_Str(get_info(ctx)->original_ctx, obj); +} + +HPy debug_ctx_ASCII(HPyContext ctx, HPy obj) +{ + return HPy_ASCII(get_info(ctx)->original_ctx, obj); +} + +HPy debug_ctx_Bytes(HPyContext ctx, HPy obj) +{ + return HPy_Bytes(get_info(ctx)->original_ctx, obj); +} + +HPy debug_ctx_RichCompare(HPyContext ctx, HPy v, HPy w, int op) +{ + return HPy_RichCompare(get_info(ctx)->original_ctx, v, w, op); +} + +int debug_ctx_RichCompareBool(HPyContext ctx, HPy v, HPy w, int op) +{ + return HPy_RichCompareBool(get_info(ctx)->original_ctx, v, w, op); +} + +HPy_hash_t debug_ctx_Hash(HPyContext ctx, HPy obj) +{ + return HPy_Hash(get_info(ctx)->original_ctx, obj); +} + +int debug_ctx_Bytes_Check(HPyContext ctx, HPy h) +{ + return HPyBytes_Check(get_info(ctx)->original_ctx, h); +} + +HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, HPy h) +{ + return HPyBytes_Size(get_info(ctx)->original_ctx, h); +} + +HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, HPy h) +{ + return HPyBytes_GET_SIZE(get_info(ctx)->original_ctx, h); +} + +char *debug_ctx_Bytes_AsString(HPyContext ctx, HPy h) +{ + return HPyBytes_AsString(get_info(ctx)->original_ctx, h); +} + +char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, HPy h) +{ + return HPyBytes_AS_STRING(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) +{ + return HPyBytes_FromString(get_info(ctx)->original_ctx, v); +} + +HPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) +{ + return HPyBytes_FromStringAndSize(get_info(ctx)->original_ctx, v, len); +} + +HPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) +{ + return HPyUnicode_FromString(get_info(ctx)->original_ctx, utf8); +} + +int debug_ctx_Unicode_Check(HPyContext ctx, HPy h) +{ + return HPyUnicode_Check(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, HPy h) +{ + return HPyUnicode_AsUTF8String(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) +{ + return HPyUnicode_FromWideChar(get_info(ctx)->original_ctx, w, size); +} + +int debug_ctx_List_Check(HPyContext ctx, HPy h) +{ + return HPyList_Check(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) +{ + return HPyList_New(get_info(ctx)->original_ctx, len); +} + +int debug_ctx_List_Append(HPyContext ctx, HPy h_list, HPy h_item) +{ + return HPyList_Append(get_info(ctx)->original_ctx, h_list, h_item); +} + +int debug_ctx_Dict_Check(HPyContext ctx, HPy h) +{ + return HPyDict_Check(get_info(ctx)->original_ctx, h); +} + +HPy debug_ctx_Dict_New(HPyContext ctx) +{ + return HPyDict_New(get_info(ctx)->original_ctx); +} + +void debug_ctx_FatalError(HPyContext ctx, const char *message) +{ + HPy_FatalError(get_info(ctx)->original_ctx, message); +} + +HPy debug_ctx_Tuple_FromArray(HPyContext ctx, HPy items[], HPy_ssize_t n) +{ + return HPyTuple_FromArray(get_info(ctx)->original_ctx, items, n); +} + +HPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) +{ + return HPy_FromPyObject(get_info(ctx)->original_ctx, obj); +} + +cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, HPy h) +{ + return HPy_AsPyObject(get_info(ctx)->original_ctx, h); +} + +void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self) +{ + _HPy_CallDestroyAndThenDealloc(get_info(ctx)->original_ctx, func, self); +} + +HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) +{ + return HPyListBuilder_New(get_info(ctx)->original_ctx, initial_size); +} + +void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item) +{ + HPyListBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item); +} + +HPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) +{ + return HPyListBuilder_Build(get_info(ctx)->original_ctx, builder); +} + +void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder) +{ + HPyListBuilder_Cancel(get_info(ctx)->original_ctx, builder); +} + +HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) +{ + return HPyTupleBuilder_New(get_info(ctx)->original_ctx, initial_size); +} + +void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item) +{ + HPyTupleBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item); +} + +HPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) +{ + return HPyTupleBuilder_Build(get_info(ctx)->original_ctx, builder); +} + +void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder) +{ + HPyTupleBuilder_Cancel(get_info(ctx)->original_ctx, builder); +} + +HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size) +{ + return HPyTracker_New(get_info(ctx)->original_ctx, size); +} + +int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, HPy h) +{ + return HPyTracker_Add(get_info(ctx)->original_ctx, ht, h); +} + +void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht) +{ + HPyTracker_ForgetAll(get_info(ctx)->original_ctx, ht); +} + +void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) +{ + HPyTracker_Close(get_info(ctx)->original_ctx, ht); +} + diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 81201b72d..1d04543f8 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -1,27 +1,33 @@ +#include +#include #include "hpy_debug.h" #include "debug_ctx.h" -#include -#include +#include "autogen_debug_ctx.h" static HPyDebugInfo debug_info = { .magic_number = HPY_DEBUG_MAGIC, .original_ctx = NULL, }; -static struct _HPyContext_s debug_ctx = { - .name = NULL, -}; -static HPy dbg_Add(HPyContext ctx, HPy a, HPy b) +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, + HPyFunc_Signature sig, + void *func, void *args) { - printf("dbg_Add...\n"); - HPyDebugInfo *info = get_info(ctx); - return HPy_Add(info->original_ctx, a, b); + fprintf(stderr, + "FATAL ERROR! debug_ctx_CallRealFunctionFromTrampoline should never be " + "called! This probably means that the debug_ctx was not initialized " + "properly\n"); + abort(); } -void debug_ctx_init(HPyContext original_ctx) +// NOTE: at the moment this function assumes that original_ctx is always the +// same. If/when we migrate to a system in which we can have multiple +// independent contexts, this function should ensure to create a different +// debug wrapper for each of them. +static void debug_ctx_init(HPyContext original_ctx) { - if (debug_ctx.name) { + if (g_debug_ctx._private != NULL) { // already initialized assert(get_info(&debug_ctx)->original_ctx == original_ctx); // sanity check return; @@ -29,17 +35,37 @@ void debug_ctx_init(HPyContext original_ctx) // initialize debug_info debug_info.original_ctx = original_ctx; + g_debug_ctx._private = &debug_info; + + /* CallRealFunctionFromTrampoline is special, since it is responsible to + retrieve and pass the appropriate context to the HPy functions on + CPython. Note that this is used ONLY on CPython, other implementations + should be able to call HPy functions natively without any need for + trampolines. + + Quick recap of what happens: + + 1. HPy_MODINIT defines a per-module _ctx_for_trampolines + + 2. universal.load(..., debug=True) passes g_debug_ctx to MODINIT, which + stores it in _ctx_for_trampolines + + 3. when CPython calls an HPy function, it goes through the trampoline + which calls CallRealFunctionFromTrampoline + + 4. the default implementation retrieves the ctx from + _ctx_for_trampolines (which will contain either g_universal_ctx or + g_debug_ctx depending on how the module was loaded) and passes it to + the HPy func. - // initialize debug_ctx: eventually we will autogen a static initializer - // for debug_ctx. For now, just copy&fix - memcpy(&debug_ctx, original_ctx, sizeof(struct _HPyContext_s)); - debug_ctx.name = "HPy Debug Mode ABI"; - debug_ctx._private = &debug_info; - debug_ctx.ctx_Add = dbg_Add; + 5. So, the default implementation does exactly what we want! Let's just + copy it from original_ctx + */ + g_debug_ctx.ctx_CallRealFunctionFromTrampoline = original_ctx->ctx_CallRealFunctionFromTrampoline; } HPyContext hpy_debug_get_ctx(HPyContext original_ctx) { debug_ctx_init(original_ctx); - return &debug_ctx; + return &g_debug_ctx; } diff --git a/hpy/debug/src/debug_ctx.h b/hpy/debug/src/debug_ctx.h index 15789a538..568a36153 100644 --- a/hpy/debug/src/debug_ctx.h +++ b/hpy/debug/src/debug_ctx.h @@ -15,7 +15,7 @@ typedef struct { HPyContext original_ctx; } HPyDebugInfo; -static HPyDebugInfo *get_info(HPyContext ctx) +static inline HPyDebugInfo *get_info(HPyContext ctx) { HPyDebugInfo *info = (HPyDebugInfo*)ctx->_private; assert(info->magic_number == HPY_DEBUG_MAGIC); // sanity check diff --git a/hpy/tools/autogen/__main__.py b/hpy/tools/autogen/__main__.py index 62b0d8699..11fe52d68 100644 --- a/hpy/tools/autogen/__main__.py +++ b/hpy/tools/autogen/__main__.py @@ -16,6 +16,7 @@ from .hpyfunc import autogen_ctx_call_i from .hpyfunc import autogen_cpython_hpyfunc_trampoline_h from .hpyslot import autogen_hpyslot_h +from .debug import autogen_debug_ctx_def_h, autogen_debug_wrappers from .pypy import autogen_pypy_txt def main(): @@ -37,6 +38,8 @@ def main(): autogen_ctx_call_i, autogen_cpython_hpyfunc_trampoline_h, autogen_hpyslot_h, + autogen_debug_ctx_def_h, + autogen_debug_wrappers, autogen_pypy_txt): cls(api).write(outdir) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py new file mode 100644 index 000000000..e3fd5b205 --- /dev/null +++ b/hpy/tools/autogen/debug.py @@ -0,0 +1,79 @@ +from copy import deepcopy +from pycparser import c_ast +from .autogenfile import AutoGenFile +from .parse import toC, find_typedecl + +def get_debug_signature(func): + newnode = deepcopy(func.node) + typedecl = find_typedecl(newnode) + # rename the function + typedecl.declname = 'debug_%s' % func.ctx_name() + return toC(newnode) + +class autogen_debug_ctx_def_h(AutoGenFile): + PATH = 'hpy/debug/src/autogen_debug_ctx.h' + + def generate(self): + lines = [] + w = lines.append + # emit the declarations for all the debug_ctx_* functions + for func in self.api.functions: + w(get_debug_signature(func) + ';') + + # emit a static ctx which uses the various debug_ctx_* functions + w('') + w('static struct _HPyContext_s g_debug_ctx = {') + w(' .name = "HPy Debug Mode ABI",') + w(' ._private = NULL,') + w(' .ctx_version = 1,') + for var in self.api.variables: + w(' .%s = HPy_NULL,' % (var.name,)) + for func in self.api.functions: + w(' .%s = &debug_%s,' % (func.ctx_name(), func.ctx_name())) + w('};') + return '\n'.join(lines) + + +class autogen_debug_wrappers(AutoGenFile): + PATH = 'hpy/debug/src/autogen_debug_wrappers.c' + + NO_WRAPPER = set([ + '_HPy_CallRealFunctionFromTrampoline', + ]) + + def generate(self): + lines = [] + w = lines.append + w('#include "debug_ctx.h"') + w('') + for func in self.api.functions: + debug_wrapper = self.gen_debug_wrapper(func) + if debug_wrapper: + w(debug_wrapper) + w('') + return '\n'.join(lines) + + def gen_debug_wrapper(self, func): + if func.name in self.NO_WRAPPER: + return + # + assert not func.is_varargs() + def get_params(): + lst = [p.name for p in func.node.type.args.params] + assert lst[0] == 'ctx' + lst[0] = 'get_info(ctx)->original_ctx' + return ', '.join(lst) + # + params = get_params() + rettype = toC(func.node.type.type) + # + lines = [] + w = lines.append + w(get_debug_signature(func)) + w('{') + if rettype == 'void': + w(f' {func.name}({params});') + else: + w(f' return {func.name}({params});') + w('}') + return '\n'.join(lines) diff --git a/setup.py b/setup.py index 237f25a1e..2a6caf845 100644 --- a/setup.py +++ b/setup.py @@ -57,6 +57,7 @@ def get_scm_config(): 'hpy/devel/src/runtime/ctx_tuple.c', 'hpy/devel/src/runtime/ctx_tuplebuilder.c', 'hpy/debug/src/debug_ctx.c', + 'hpy/debug/src/autogen_debug_wrappers.c', ], include_dirs=[ 'hpy/devel/include', From 099bedb8a97cb891b847435a0eee512e7ad53bf7 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 31 Dec 2020 11:22:22 +0100 Subject: [PATCH 19/65] ignore these two files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 4978ee2cf..5bbe6c8c7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,10 @@ hpy/tools/autogen/autogen_pypy.txt hpy/devel/include/common/version.h hpy/devel/version.py +# stubs created by setup.py when doing build_ext --inplace +proof-of-concept/pof.py +proof-of-concept/pofpackage/foo.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] From ee5150060468d62d2dc3c1bc5b3a85905e85b987 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 31 Dec 2020 11:31:00 +0100 Subject: [PATCH 20/65] Introduce a _debug module which will contain the python-level interface to the debug mode. The module is written in HPy itself so that it will be easily reusable by other implementations if they want. However, differently than a "standard" HPy extension it is not loaded using dlopen. Instead, it is built together with hpy.universal and manually "imported" by it at startup. --- hpy/debug/src/_debugmod.c | 33 +++++++++++++++++++ hpy/debug/src/autogen_debug_wrappers.c | 2 +- hpy/debug/src/debug_ctx.c | 3 +- .../src/{debug_ctx.h => debug_internal.h} | 13 ++++---- hpy/debug/src/hpy_debug.h | 8 ----- hpy/debug/src/include/hpy_debug.h | 14 ++++++++ hpy/tools/autogen/debug.py | 2 +- hpy/universal/src/hpymodule.c | 24 +++++++++++++- setup.py | 3 +- 9 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 hpy/debug/src/_debugmod.c rename hpy/debug/src/{debug_ctx.h => debug_internal.h} (67%) delete mode 100644 hpy/debug/src/hpy_debug.h create mode 100644 hpy/debug/src/include/hpy_debug.h diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c new file mode 100644 index 000000000..140858431 --- /dev/null +++ b/hpy/debug/src/_debugmod.c @@ -0,0 +1,33 @@ +// Python-level interface for the _debug module. Written in HPy itself, the +// idea is that it should be reusable by other implementations + +#include "hpy.h" + +HPyDef_METH(hello, "hello", hello_impl, HPyFunc_NOARGS) +static HPy hello_impl(HPyContext ctx, HPy self) +{ + return HPyUnicode_FromString(ctx, "hello world"); +} + +static HPyDef *module_defines[] = { + &hello, + NULL +}; + +static HPyModuleDef moduledef = { + HPyModuleDef_HEAD_INIT, + .m_name = "hpy.debug._debug", + .m_doc = "HPy debug mode", + .m_size = -1, + .defines = module_defines +}; + + +HPy_MODINIT(_debug) +static HPy init__debug_impl(HPyContext ctx) +{ + HPy m = HPyModule_Create(ctx, &moduledef); + if (HPy_IsNull(m)) + return HPy_NULL; + return m; +} diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index 336849625..df0fbc3da 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -10,7 +10,7 @@ */ -#include "debug_ctx.h" +#include "debug_internal.h" HPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) { diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 1d04543f8..3143286f2 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -1,7 +1,6 @@ #include #include -#include "hpy_debug.h" -#include "debug_ctx.h" +#include "debug_internal.h" #include "autogen_debug_ctx.h" static HPyDebugInfo debug_info = { diff --git a/hpy/debug/src/debug_ctx.h b/hpy/debug/src/debug_internal.h similarity index 67% rename from hpy/debug/src/debug_ctx.h rename to hpy/debug/src/debug_internal.h index 568a36153..a306dd644 100644 --- a/hpy/debug/src/debug_ctx.h +++ b/hpy/debug/src/debug_internal.h @@ -1,11 +1,12 @@ -#ifndef HPY_DEBUG_CTX_H -#define HPY_DEBUG_CTX_H - -// this header is for internal use. The public API of the debug mode is in -// hpy_debug.h +/* Internal header for all the files in hpy/debug/src. The public API is in + include/hpy_debug.h +*/ +#ifndef HPY_DEBUG_INTERNAL_H +#define HPY_DEBUG_INTERNAL_H #include #include "hpy.h" +#include "hpy_debug.h" // "debooff" is the closest to "debug" I could come up with :) #define HPY_DEBUG_MAGIC 0xDEB00FF @@ -23,4 +24,4 @@ static inline HPyDebugInfo *get_info(HPyContext ctx) } -#endif /* HPY_DEBUG_CTX_H */ +#endif /* HPY_DEBUG_INTERNAL_H */ diff --git a/hpy/debug/src/hpy_debug.h b/hpy/debug/src/hpy_debug.h deleted file mode 100644 index 699c4e6f8..000000000 --- a/hpy/debug/src/hpy_debug.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef HPY_DEBUG_H -#define HPY_DEBUG_H - -#include "hpy.h" - -HPyContext hpy_debug_get_ctx(HPyContext original_ctx); - -#endif /* HPY_DEBUG_H */ diff --git a/hpy/debug/src/include/hpy_debug.h b/hpy/debug/src/include/hpy_debug.h new file mode 100644 index 000000000..a49c28a08 --- /dev/null +++ b/hpy/debug/src/include/hpy_debug.h @@ -0,0 +1,14 @@ +#ifndef HPY_DEBUG_H +#define HPY_DEBUG_H + +#include "hpy.h" + +HPyContext hpy_debug_get_ctx(HPyContext original_ctx); + +// this is the HPy init function created by HPy_MODINIT. In CPython's version +// of hpy.universal the code is embedded inside the extension, so we can call +// this function directly instead of dlopen it. This is similar to what +// CPython does for its own built-in modules +HPy HPyInit__debug(HPyContext ctx); + +#endif /* HPY_DEBUG_H */ diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index e3fd5b205..eae846686 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -44,7 +44,7 @@ class autogen_debug_wrappers(AutoGenFile): def generate(self): lines = [] w = lines.append - w('#include "debug_ctx.h"') + w('#include "debug_internal.h"') w('') for func in self.api.functions: debug_wrapper = self.gen_debug_wrapper(func) diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 97b3332df..89854c68c 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -156,6 +156,11 @@ static PyMethodDef HPyMethods[] = { {NULL, NULL, 0, NULL} }; +static int exec_module(PyObject *mod); +static PyModuleDef_Slot hpymodule_slots[] = { + {Py_mod_exec, exec_module}, + {0, NULL}, +}; static struct PyModuleDef hpydef = { PyModuleDef_HEAD_INIT, @@ -163,11 +168,28 @@ static struct PyModuleDef hpydef = { .m_doc = "HPy universal runtime for CPython", .m_size = 0, .m_methods = HPyMethods, + .m_slots = hpymodule_slots, }; +// 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)) + 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) + return -1; + + return 0; +} + PyMODINIT_FUNC PyInit_universal(void) { - return PyModuleDef_Init(&hpydef); + PyObject *mod = PyModuleDef_Init(&hpydef); + return mod; } diff --git a/setup.py b/setup.py index 2a6caf845..d6c222c56 100644 --- a/setup.py +++ b/setup.py @@ -57,12 +57,13 @@ def get_scm_config(): 'hpy/devel/src/runtime/ctx_tuple.c', 'hpy/devel/src/runtime/ctx_tuplebuilder.c', 'hpy/debug/src/debug_ctx.c', + 'hpy/debug/src/_debugmod.c', 'hpy/debug/src/autogen_debug_wrappers.c', ], include_dirs=[ 'hpy/devel/include', 'hpy/universal/src', - 'hpy/debug/src', + 'hpy/debug/src/include', ], extra_compile_args=[ '-DHPY_UNIVERSAL_ABI', From 616d2c2c42c5b75cd6d8ddae41a89b625fe58116 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 31 Dec 2020 16:51:16 +0100 Subject: [PATCH 21/65] introduce DHPy, which is the debug mode's version of a handle, and modify autogen accordingly. See the comments inside the code for more info --- hpy/debug/src/autogen_debug_ctx.h | 1052 +++++++++++++++++++----- hpy/debug/src/autogen_debug_wrappers.c | 424 +++++----- hpy/debug/src/debug_internal.h | 44 +- hpy/tools/autogen/debug.py | 99 ++- 4 files changed, 1168 insertions(+), 451 deletions(-) diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h index bdfa8b114..d1c4e9ab1 100644 --- a/hpy/debug/src/autogen_debug_ctx.h +++ b/hpy/debug/src/autogen_debug_ctx.h @@ -10,124 +10,728 @@ */ -HPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def); -HPy debug_ctx_Dup(HPyContext ctx, HPy h); -void debug_ctx_Close(HPyContext ctx, HPy h); -HPy debug_ctx_Long_FromLong(HPyContext ctx, long value); -HPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value); -HPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v); -HPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v); -HPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value); -HPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value); -long debug_ctx_Long_AsLong(HPyContext ctx, HPy h); -unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, HPy h); -unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, HPy h); -long long debug_ctx_Long_AsLongLong(HPyContext ctx, HPy h); -unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, HPy h); -unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, HPy h); -size_t debug_ctx_Long_AsSize_t(HPyContext ctx, HPy h); -HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, HPy h); -HPy debug_ctx_Float_FromDouble(HPyContext ctx, double v); -double debug_ctx_Float_AsDouble(HPyContext ctx, HPy h); -HPy_ssize_t debug_ctx_Length(HPyContext ctx, HPy h); -int debug_ctx_Number_Check(HPyContext ctx, HPy h); -HPy debug_ctx_Add(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Subtract(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Multiply(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_MatrixMultiply(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_FloorDivide(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_TrueDivide(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Remainder(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Divmod(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Power(HPyContext ctx, HPy h1, HPy h2, HPy h3); -HPy debug_ctx_Negative(HPyContext ctx, HPy h1); -HPy debug_ctx_Positive(HPyContext ctx, HPy h1); -HPy debug_ctx_Absolute(HPyContext ctx, HPy h1); -HPy debug_ctx_Invert(HPyContext ctx, HPy h1); -HPy debug_ctx_Lshift(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Rshift(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_And(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Xor(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Or(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_Index(HPyContext ctx, HPy h1); -HPy debug_ctx_Long(HPyContext ctx, HPy h1); -HPy debug_ctx_Float(HPyContext ctx, HPy h1); -HPy debug_ctx_InPlaceAdd(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceSubtract(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceMultiply(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceRemainder(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlacePower(HPyContext ctx, HPy h1, HPy h2, HPy h3); -HPy debug_ctx_InPlaceLshift(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceRshift(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceAnd(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceXor(HPyContext ctx, HPy h1, HPy h2); -HPy debug_ctx_InPlaceOr(HPyContext ctx, HPy h1, HPy h2); -void debug_ctx_Err_SetString(HPyContext ctx, HPy h_type, const char *message); -void debug_ctx_Err_SetObject(HPyContext ctx, HPy h_type, HPy h_value); + +/* +The debug_ctx_* functions contain the actualy logic: they receive and +return handles of type DHPy. + +The _adapter_debug_* helpers cast DHPy into HPy and viceversa, to get +functions those signature is compatible to what is declared in the +HPyContext. Note that they are no-op, since the internal repr of DHPy +and HPy is the same (but the first is seen as a pointer to DHPy_s the +second as a small struct containining an integer), but the C standard +forbids casting function pointers whose arguments have nominally +different types, so we need to write the adapters manually. +*/ + +DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def); +HPy _adapter_debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) +{ + return _d2h(debug_ctx_Module_Create(ctx, def)); +} + +DHPy debug_ctx_Dup(HPyContext ctx, DHPy h); +HPy _adapter_debug_ctx_Dup(HPyContext ctx, HPy h) +{ + return _d2h(debug_ctx_Dup(ctx, _h2d(h))); +} + +void debug_ctx_Close(HPyContext ctx, DHPy h); +void _adapter_debug_ctx_Close(HPyContext ctx, HPy h) +{ + debug_ctx_Close(ctx, _h2d(h)); +} + +DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value); +HPy _adapter_debug_ctx_Long_FromLong(HPyContext ctx, long value) +{ + return _d2h(debug_ctx_Long_FromLong(ctx, value)); +} + +DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value); +HPy _adapter_debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) +{ + return _d2h(debug_ctx_Long_FromUnsignedLong(ctx, value)); +} + +DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v); +HPy _adapter_debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) +{ + return _d2h(debug_ctx_Long_FromLongLong(ctx, v)); +} + +DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v); +HPy _adapter_debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) +{ + return _d2h(debug_ctx_Long_FromUnsignedLongLong(ctx, v)); +} + +DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value); +HPy _adapter_debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) +{ + return _d2h(debug_ctx_Long_FromSize_t(ctx, value)); +} + +DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value); +HPy _adapter_debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) +{ + return _d2h(debug_ctx_Long_FromSsize_t(ctx, value)); +} + +long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h); +long _adapter_debug_ctx_Long_AsLong(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsLong(ctx, _h2d(h)); +} + +unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h); +unsigned long _adapter_debug_ctx_Long_AsUnsignedLong(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsUnsignedLong(ctx, _h2d(h)); +} + +unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h); +unsigned long _adapter_debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsUnsignedLongMask(ctx, _h2d(h)); +} + +long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h); +long long _adapter_debug_ctx_Long_AsLongLong(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsLongLong(ctx, _h2d(h)); +} + +unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h); +unsigned long long _adapter_debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsUnsignedLongLong(ctx, _h2d(h)); +} + +unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h); +unsigned long long _adapter_debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsUnsignedLongLongMask(ctx, _h2d(h)); +} + +size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h); +size_t _adapter_debug_ctx_Long_AsSize_t(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsSize_t(ctx, _h2d(h)); +} + +HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h); +HPy_ssize_t _adapter_debug_ctx_Long_AsSsize_t(HPyContext ctx, HPy h) +{ + return debug_ctx_Long_AsSsize_t(ctx, _h2d(h)); +} + +DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v); +HPy _adapter_debug_ctx_Float_FromDouble(HPyContext ctx, double v) +{ + return _d2h(debug_ctx_Float_FromDouble(ctx, v)); +} + +double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h); +double _adapter_debug_ctx_Float_AsDouble(HPyContext ctx, HPy h) +{ + return debug_ctx_Float_AsDouble(ctx, _h2d(h)); +} + +HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h); +HPy_ssize_t _adapter_debug_ctx_Length(HPyContext ctx, HPy h) +{ + return debug_ctx_Length(ctx, _h2d(h)); +} + +int debug_ctx_Number_Check(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_Number_Check(HPyContext ctx, HPy h) +{ + return debug_ctx_Number_Check(ctx, _h2d(h)); +} + +DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Add(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Add(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Subtract(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Subtract(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Multiply(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Multiply(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_MatrixMultiply(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_MatrixMultiply(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_FloorDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_FloorDivide(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_TrueDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_TrueDivide(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Remainder(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Remainder(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Divmod(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Divmod(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); +HPy _adapter_debug_ctx_Power(HPyContext ctx, HPy h1, HPy h2, HPy h3) +{ + return _d2h(debug_ctx_Power(ctx, _h2d(h1), _h2d(h2), _h2d(h3))); +} + +DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1); +HPy _adapter_debug_ctx_Negative(HPyContext ctx, HPy h1) +{ + return _d2h(debug_ctx_Negative(ctx, _h2d(h1))); +} + +DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1); +HPy _adapter_debug_ctx_Positive(HPyContext ctx, HPy h1) +{ + return _d2h(debug_ctx_Positive(ctx, _h2d(h1))); +} + +DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1); +HPy _adapter_debug_ctx_Absolute(HPyContext ctx, HPy h1) +{ + return _d2h(debug_ctx_Absolute(ctx, _h2d(h1))); +} + +DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1); +HPy _adapter_debug_ctx_Invert(HPyContext ctx, HPy h1) +{ + return _d2h(debug_ctx_Invert(ctx, _h2d(h1))); +} + +DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Lshift(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Lshift(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Rshift(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Rshift(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_And(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_And(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Xor(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Xor(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_Or(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_Or(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_Index(HPyContext ctx, DHPy h1); +HPy _adapter_debug_ctx_Index(HPyContext ctx, HPy h1) +{ + return _d2h(debug_ctx_Index(ctx, _h2d(h1))); +} + +DHPy debug_ctx_Long(HPyContext ctx, DHPy h1); +HPy _adapter_debug_ctx_Long(HPyContext ctx, HPy h1) +{ + return _d2h(debug_ctx_Long(ctx, _h2d(h1))); +} + +DHPy debug_ctx_Float(HPyContext ctx, DHPy h1); +HPy _adapter_debug_ctx_Float(HPyContext ctx, HPy h1) +{ + return _d2h(debug_ctx_Float(ctx, _h2d(h1))); +} + +DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceAdd(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceAdd(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceSubtract(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceSubtract(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceMultiply(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceMultiply(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceMatrixMultiply(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceFloorDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceFloorDivide(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceTrueDivide(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceTrueDivide(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceRemainder(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceRemainder(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); +HPy _adapter_debug_ctx_InPlacePower(HPyContext ctx, HPy h1, HPy h2, HPy h3) +{ + return _d2h(debug_ctx_InPlacePower(ctx, _h2d(h1), _h2d(h2), _h2d(h3))); +} + +DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceLshift(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceLshift(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceRshift(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceRshift(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceAnd(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceAnd(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceXor(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceXor(ctx, _h2d(h1), _h2d(h2))); +} + +DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2); +HPy _adapter_debug_ctx_InPlaceOr(HPyContext ctx, HPy h1, HPy h2) +{ + return _d2h(debug_ctx_InPlaceOr(ctx, _h2d(h1), _h2d(h2))); +} + +void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message); +void _adapter_debug_ctx_Err_SetString(HPyContext ctx, HPy h_type, const char *message) +{ + debug_ctx_Err_SetString(ctx, _h2d(h_type), message); +} + +void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value); +void _adapter_debug_ctx_Err_SetObject(HPyContext ctx, HPy h_type, HPy h_value) +{ + debug_ctx_Err_SetObject(ctx, _h2d(h_type), _h2d(h_value)); +} + int debug_ctx_Err_Occurred(HPyContext ctx); -HPy debug_ctx_Err_NoMemory(HPyContext ctx); +int _adapter_debug_ctx_Err_Occurred(HPyContext ctx) +{ + return debug_ctx_Err_Occurred(ctx); +} + +DHPy debug_ctx_Err_NoMemory(HPyContext ctx); +HPy _adapter_debug_ctx_Err_NoMemory(HPyContext ctx) +{ + return _d2h(debug_ctx_Err_NoMemory(ctx)); +} + void debug_ctx_Err_Clear(HPyContext ctx); -int debug_ctx_IsTrue(HPyContext ctx, HPy h); -HPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params); -HPy debug_ctx_Type_GenericNew(HPyContext ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw); -HPy debug_ctx_GetAttr(HPyContext ctx, HPy obj, HPy name); -HPy debug_ctx_GetAttr_s(HPyContext ctx, HPy obj, const char *name); -int debug_ctx_HasAttr(HPyContext ctx, HPy obj, HPy name); -int debug_ctx_HasAttr_s(HPyContext ctx, HPy obj, const char *name); -int debug_ctx_SetAttr(HPyContext ctx, HPy obj, HPy name, HPy value); -int debug_ctx_SetAttr_s(HPyContext ctx, HPy obj, const char *name, HPy value); -HPy debug_ctx_GetItem(HPyContext ctx, HPy obj, HPy key); -HPy debug_ctx_GetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx); -HPy debug_ctx_GetItem_s(HPyContext ctx, HPy obj, const char *key); -int debug_ctx_SetItem(HPyContext ctx, HPy obj, HPy key, HPy value); -int debug_ctx_SetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx, HPy value); -int debug_ctx_SetItem_s(HPyContext ctx, HPy obj, const char *key, HPy value); -void *debug_ctx_Cast(HPyContext ctx, HPy h); -HPy debug_ctx_New(HPyContext ctx, HPy h_type, void **data); -HPy debug_ctx_Repr(HPyContext ctx, HPy obj); -HPy debug_ctx_Str(HPyContext ctx, HPy obj); -HPy debug_ctx_ASCII(HPyContext ctx, HPy obj); -HPy debug_ctx_Bytes(HPyContext ctx, HPy obj); -HPy debug_ctx_RichCompare(HPyContext ctx, HPy v, HPy w, int op); -int debug_ctx_RichCompareBool(HPyContext ctx, HPy v, HPy w, int op); -HPy_hash_t debug_ctx_Hash(HPyContext ctx, HPy obj); -int debug_ctx_Bytes_Check(HPyContext ctx, HPy h); -HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, HPy h); -HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, HPy h); -char *debug_ctx_Bytes_AsString(HPyContext ctx, HPy h); -char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, HPy h); -HPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v); -HPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len); -HPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8); -int debug_ctx_Unicode_Check(HPyContext ctx, HPy h); -HPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, HPy h); -HPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size); -int debug_ctx_List_Check(HPyContext ctx, HPy h); -HPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len); -int debug_ctx_List_Append(HPyContext ctx, HPy h_list, HPy h_item); -int debug_ctx_Dict_Check(HPyContext ctx, HPy h); -HPy debug_ctx_Dict_New(HPyContext ctx); +void _adapter_debug_ctx_Err_Clear(HPyContext ctx) +{ + debug_ctx_Err_Clear(ctx); +} + +int debug_ctx_IsTrue(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_IsTrue(HPyContext ctx, HPy h) +{ + return debug_ctx_IsTrue(ctx, _h2d(h)); +} + +DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params); +HPy _adapter_debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) +{ + return _d2h(debug_ctx_Type_FromSpec(ctx, spec, params)); +} + +DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw); +HPy _adapter_debug_ctx_Type_GenericNew(HPyContext ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw) +{ + return _d2h(debug_ctx_Type_GenericNew(ctx, _h2d(type), (DHPy *)args, nargs, _h2d(kw))); +} + +DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name); +HPy _adapter_debug_ctx_GetAttr(HPyContext ctx, HPy obj, HPy name) +{ + return _d2h(debug_ctx_GetAttr(ctx, _h2d(obj), _h2d(name))); +} + +DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name); +HPy _adapter_debug_ctx_GetAttr_s(HPyContext ctx, HPy obj, const char *name) +{ + return _d2h(debug_ctx_GetAttr_s(ctx, _h2d(obj), name)); +} + +int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name); +int _adapter_debug_ctx_HasAttr(HPyContext ctx, HPy obj, HPy name) +{ + return debug_ctx_HasAttr(ctx, _h2d(obj), _h2d(name)); +} + +int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name); +int _adapter_debug_ctx_HasAttr_s(HPyContext ctx, HPy obj, const char *name) +{ + return debug_ctx_HasAttr_s(ctx, _h2d(obj), name); +} + +int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value); +int _adapter_debug_ctx_SetAttr(HPyContext ctx, HPy obj, HPy name, HPy value) +{ + return debug_ctx_SetAttr(ctx, _h2d(obj), _h2d(name), _h2d(value)); +} + +int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value); +int _adapter_debug_ctx_SetAttr_s(HPyContext ctx, HPy obj, const char *name, HPy value) +{ + return debug_ctx_SetAttr_s(ctx, _h2d(obj), name, _h2d(value)); +} + +DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key); +HPy _adapter_debug_ctx_GetItem(HPyContext ctx, HPy obj, HPy key) +{ + return _d2h(debug_ctx_GetItem(ctx, _h2d(obj), _h2d(key))); +} + +DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx); +HPy _adapter_debug_ctx_GetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx) +{ + return _d2h(debug_ctx_GetItem_i(ctx, _h2d(obj), idx)); +} + +DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key); +HPy _adapter_debug_ctx_GetItem_s(HPyContext ctx, HPy obj, const char *key) +{ + return _d2h(debug_ctx_GetItem_s(ctx, _h2d(obj), key)); +} + +int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value); +int _adapter_debug_ctx_SetItem(HPyContext ctx, HPy obj, HPy key, HPy value) +{ + return debug_ctx_SetItem(ctx, _h2d(obj), _h2d(key), _h2d(value)); +} + +int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value); +int _adapter_debug_ctx_SetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx, HPy value) +{ + return debug_ctx_SetItem_i(ctx, _h2d(obj), idx, _h2d(value)); +} + +int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value); +int _adapter_debug_ctx_SetItem_s(HPyContext ctx, HPy obj, const char *key, HPy value) +{ + return debug_ctx_SetItem_s(ctx, _h2d(obj), key, _h2d(value)); +} + +void *debug_ctx_Cast(HPyContext ctx, DHPy h); +void *_adapter_debug_ctx_Cast(HPyContext ctx, HPy h) +{ + return debug_ctx_Cast(ctx, _h2d(h)); +} + +DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data); +HPy _adapter_debug_ctx_New(HPyContext ctx, HPy h_type, void **data) +{ + return _d2h(debug_ctx_New(ctx, _h2d(h_type), data)); +} + +DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj); +HPy _adapter_debug_ctx_Repr(HPyContext ctx, HPy obj) +{ + return _d2h(debug_ctx_Repr(ctx, _h2d(obj))); +} + +DHPy debug_ctx_Str(HPyContext ctx, DHPy obj); +HPy _adapter_debug_ctx_Str(HPyContext ctx, HPy obj) +{ + return _d2h(debug_ctx_Str(ctx, _h2d(obj))); +} + +DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj); +HPy _adapter_debug_ctx_ASCII(HPyContext ctx, HPy obj) +{ + return _d2h(debug_ctx_ASCII(ctx, _h2d(obj))); +} + +DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj); +HPy _adapter_debug_ctx_Bytes(HPyContext ctx, HPy obj) +{ + return _d2h(debug_ctx_Bytes(ctx, _h2d(obj))); +} + +DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op); +HPy _adapter_debug_ctx_RichCompare(HPyContext ctx, HPy v, HPy w, int op) +{ + return _d2h(debug_ctx_RichCompare(ctx, _h2d(v), _h2d(w), op)); +} + +int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op); +int _adapter_debug_ctx_RichCompareBool(HPyContext ctx, HPy v, HPy w, int op) +{ + return debug_ctx_RichCompareBool(ctx, _h2d(v), _h2d(w), op); +} + +HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj); +HPy_hash_t _adapter_debug_ctx_Hash(HPyContext ctx, HPy obj) +{ + return debug_ctx_Hash(ctx, _h2d(obj)); +} + +int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_Bytes_Check(HPyContext ctx, HPy h) +{ + return debug_ctx_Bytes_Check(ctx, _h2d(h)); +} + +HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h); +HPy_ssize_t _adapter_debug_ctx_Bytes_Size(HPyContext ctx, HPy h) +{ + return debug_ctx_Bytes_Size(ctx, _h2d(h)); +} + +HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h); +HPy_ssize_t _adapter_debug_ctx_Bytes_GET_SIZE(HPyContext ctx, HPy h) +{ + return debug_ctx_Bytes_GET_SIZE(ctx, _h2d(h)); +} + +char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h); +char *_adapter_debug_ctx_Bytes_AsString(HPyContext ctx, HPy h) +{ + return debug_ctx_Bytes_AsString(ctx, _h2d(h)); +} + +char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h); +char *_adapter_debug_ctx_Bytes_AS_STRING(HPyContext ctx, HPy h) +{ + return debug_ctx_Bytes_AS_STRING(ctx, _h2d(h)); +} + +DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v); +HPy _adapter_debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) +{ + return _d2h(debug_ctx_Bytes_FromString(ctx, v)); +} + +DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len); +HPy _adapter_debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) +{ + return _d2h(debug_ctx_Bytes_FromStringAndSize(ctx, v, len)); +} + +DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8); +HPy _adapter_debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) +{ + return _d2h(debug_ctx_Unicode_FromString(ctx, utf8)); +} + +int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_Unicode_Check(HPyContext ctx, HPy h) +{ + return debug_ctx_Unicode_Check(ctx, _h2d(h)); +} + +DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h); +HPy _adapter_debug_ctx_Unicode_AsUTF8String(HPyContext ctx, HPy h) +{ + return _d2h(debug_ctx_Unicode_AsUTF8String(ctx, _h2d(h))); +} + +DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size); +HPy _adapter_debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) +{ + return _d2h(debug_ctx_Unicode_FromWideChar(ctx, w, size)); +} + +int debug_ctx_List_Check(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_List_Check(HPyContext ctx, HPy h) +{ + return debug_ctx_List_Check(ctx, _h2d(h)); +} + +DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len); +HPy _adapter_debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) +{ + return _d2h(debug_ctx_List_New(ctx, len)); +} + +int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item); +int _adapter_debug_ctx_List_Append(HPyContext ctx, HPy h_list, HPy h_item) +{ + return debug_ctx_List_Append(ctx, _h2d(h_list), _h2d(h_item)); +} + +int debug_ctx_Dict_Check(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_Dict_Check(HPyContext ctx, HPy h) +{ + return debug_ctx_Dict_Check(ctx, _h2d(h)); +} + +DHPy debug_ctx_Dict_New(HPyContext ctx); +HPy _adapter_debug_ctx_Dict_New(HPyContext ctx) +{ + return _d2h(debug_ctx_Dict_New(ctx)); +} + void debug_ctx_FatalError(HPyContext ctx, const char *message); -HPy debug_ctx_Tuple_FromArray(HPyContext ctx, HPy items[], HPy_ssize_t n); -HPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj); -cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, HPy h); +void _adapter_debug_ctx_FatalError(HPyContext ctx, const char *message) +{ + debug_ctx_FatalError(ctx, message); +} + +DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n); +HPy _adapter_debug_ctx_Tuple_FromArray(HPyContext ctx, HPy items[], HPy_ssize_t n) +{ + return _d2h(debug_ctx_Tuple_FromArray(ctx, (DHPy *)items, n)); +} + +DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj); +HPy _adapter_debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) +{ + return _d2h(debug_ctx_FromPyObject(ctx, obj)); +} + +cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h); +cpy_PyObject *_adapter_debug_ctx_AsPyObject(HPyContext ctx, HPy h) +{ + return debug_ctx_AsPyObject(ctx, _h2d(h)); +} + void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args); +void _adapter_debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args) +{ + debug_ctx_CallRealFunctionFromTrampoline(ctx, sig, func, args); +} + void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self); +void _adapter_debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self) +{ + debug_ctx_CallDestroyAndThenDealloc(ctx, func, self); +} + HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item); -HPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder); +HPyListBuilder _adapter_debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) +{ + return debug_ctx_ListBuilder_New(ctx, initial_size); +} + +void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item); +void _adapter_debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item) +{ + debug_ctx_ListBuilder_Set(ctx, builder, index, _h2d(h_item)); +} + +DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder); +HPy _adapter_debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) +{ + return _d2h(debug_ctx_ListBuilder_Build(ctx, builder)); +} + void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder); +void _adapter_debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder) +{ + debug_ctx_ListBuilder_Cancel(ctx, builder); +} + HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item); -HPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder); +HPyTupleBuilder _adapter_debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) +{ + return debug_ctx_TupleBuilder_New(ctx, initial_size); +} + +void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item); +void _adapter_debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item) +{ + debug_ctx_TupleBuilder_Set(ctx, builder, index, _h2d(h_item)); +} + +DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder); +HPy _adapter_debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) +{ + return _d2h(debug_ctx_TupleBuilder_Build(ctx, builder)); +} + void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder); +void _adapter_debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder) +{ + debug_ctx_TupleBuilder_Cancel(ctx, builder); +} + HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size); -int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, HPy h); +HPyTracker _adapter_debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size) +{ + return debug_ctx_Tracker_New(ctx, size); +} + +int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h); +int _adapter_debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, HPy h) +{ + return debug_ctx_Tracker_Add(ctx, ht, _h2d(h)); +} + void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht); +void _adapter_debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht) +{ + debug_ctx_Tracker_ForgetAll(ctx, ht); +} + void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht); +void _adapter_debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) +{ + debug_ctx_Tracker_Close(ctx, ht); +} + static struct _HPyContext_s g_debug_ctx = { .name = "HPy Debug Mode ABI", @@ -206,122 +810,122 @@ static struct _HPyContext_s g_debug_ctx = { .h_UnicodeType = HPy_NULL, .h_TupleType = HPy_NULL, .h_ListType = HPy_NULL, - .ctx_Module_Create = &debug_ctx_Module_Create, - .ctx_Dup = &debug_ctx_Dup, - .ctx_Close = &debug_ctx_Close, - .ctx_Long_FromLong = &debug_ctx_Long_FromLong, - .ctx_Long_FromUnsignedLong = &debug_ctx_Long_FromUnsignedLong, - .ctx_Long_FromLongLong = &debug_ctx_Long_FromLongLong, - .ctx_Long_FromUnsignedLongLong = &debug_ctx_Long_FromUnsignedLongLong, - .ctx_Long_FromSize_t = &debug_ctx_Long_FromSize_t, - .ctx_Long_FromSsize_t = &debug_ctx_Long_FromSsize_t, - .ctx_Long_AsLong = &debug_ctx_Long_AsLong, - .ctx_Long_AsUnsignedLong = &debug_ctx_Long_AsUnsignedLong, - .ctx_Long_AsUnsignedLongMask = &debug_ctx_Long_AsUnsignedLongMask, - .ctx_Long_AsLongLong = &debug_ctx_Long_AsLongLong, - .ctx_Long_AsUnsignedLongLong = &debug_ctx_Long_AsUnsignedLongLong, - .ctx_Long_AsUnsignedLongLongMask = &debug_ctx_Long_AsUnsignedLongLongMask, - .ctx_Long_AsSize_t = &debug_ctx_Long_AsSize_t, - .ctx_Long_AsSsize_t = &debug_ctx_Long_AsSsize_t, - .ctx_Float_FromDouble = &debug_ctx_Float_FromDouble, - .ctx_Float_AsDouble = &debug_ctx_Float_AsDouble, - .ctx_Length = &debug_ctx_Length, - .ctx_Number_Check = &debug_ctx_Number_Check, - .ctx_Add = &debug_ctx_Add, - .ctx_Subtract = &debug_ctx_Subtract, - .ctx_Multiply = &debug_ctx_Multiply, - .ctx_MatrixMultiply = &debug_ctx_MatrixMultiply, - .ctx_FloorDivide = &debug_ctx_FloorDivide, - .ctx_TrueDivide = &debug_ctx_TrueDivide, - .ctx_Remainder = &debug_ctx_Remainder, - .ctx_Divmod = &debug_ctx_Divmod, - .ctx_Power = &debug_ctx_Power, - .ctx_Negative = &debug_ctx_Negative, - .ctx_Positive = &debug_ctx_Positive, - .ctx_Absolute = &debug_ctx_Absolute, - .ctx_Invert = &debug_ctx_Invert, - .ctx_Lshift = &debug_ctx_Lshift, - .ctx_Rshift = &debug_ctx_Rshift, - .ctx_And = &debug_ctx_And, - .ctx_Xor = &debug_ctx_Xor, - .ctx_Or = &debug_ctx_Or, - .ctx_Index = &debug_ctx_Index, - .ctx_Long = &debug_ctx_Long, - .ctx_Float = &debug_ctx_Float, - .ctx_InPlaceAdd = &debug_ctx_InPlaceAdd, - .ctx_InPlaceSubtract = &debug_ctx_InPlaceSubtract, - .ctx_InPlaceMultiply = &debug_ctx_InPlaceMultiply, - .ctx_InPlaceMatrixMultiply = &debug_ctx_InPlaceMatrixMultiply, - .ctx_InPlaceFloorDivide = &debug_ctx_InPlaceFloorDivide, - .ctx_InPlaceTrueDivide = &debug_ctx_InPlaceTrueDivide, - .ctx_InPlaceRemainder = &debug_ctx_InPlaceRemainder, - .ctx_InPlacePower = &debug_ctx_InPlacePower, - .ctx_InPlaceLshift = &debug_ctx_InPlaceLshift, - .ctx_InPlaceRshift = &debug_ctx_InPlaceRshift, - .ctx_InPlaceAnd = &debug_ctx_InPlaceAnd, - .ctx_InPlaceXor = &debug_ctx_InPlaceXor, - .ctx_InPlaceOr = &debug_ctx_InPlaceOr, - .ctx_Err_SetString = &debug_ctx_Err_SetString, - .ctx_Err_SetObject = &debug_ctx_Err_SetObject, - .ctx_Err_Occurred = &debug_ctx_Err_Occurred, - .ctx_Err_NoMemory = &debug_ctx_Err_NoMemory, - .ctx_Err_Clear = &debug_ctx_Err_Clear, - .ctx_IsTrue = &debug_ctx_IsTrue, - .ctx_Type_FromSpec = &debug_ctx_Type_FromSpec, - .ctx_Type_GenericNew = &debug_ctx_Type_GenericNew, - .ctx_GetAttr = &debug_ctx_GetAttr, - .ctx_GetAttr_s = &debug_ctx_GetAttr_s, - .ctx_HasAttr = &debug_ctx_HasAttr, - .ctx_HasAttr_s = &debug_ctx_HasAttr_s, - .ctx_SetAttr = &debug_ctx_SetAttr, - .ctx_SetAttr_s = &debug_ctx_SetAttr_s, - .ctx_GetItem = &debug_ctx_GetItem, - .ctx_GetItem_i = &debug_ctx_GetItem_i, - .ctx_GetItem_s = &debug_ctx_GetItem_s, - .ctx_SetItem = &debug_ctx_SetItem, - .ctx_SetItem_i = &debug_ctx_SetItem_i, - .ctx_SetItem_s = &debug_ctx_SetItem_s, - .ctx_Cast = &debug_ctx_Cast, - .ctx_New = &debug_ctx_New, - .ctx_Repr = &debug_ctx_Repr, - .ctx_Str = &debug_ctx_Str, - .ctx_ASCII = &debug_ctx_ASCII, - .ctx_Bytes = &debug_ctx_Bytes, - .ctx_RichCompare = &debug_ctx_RichCompare, - .ctx_RichCompareBool = &debug_ctx_RichCompareBool, - .ctx_Hash = &debug_ctx_Hash, - .ctx_Bytes_Check = &debug_ctx_Bytes_Check, - .ctx_Bytes_Size = &debug_ctx_Bytes_Size, - .ctx_Bytes_GET_SIZE = &debug_ctx_Bytes_GET_SIZE, - .ctx_Bytes_AsString = &debug_ctx_Bytes_AsString, - .ctx_Bytes_AS_STRING = &debug_ctx_Bytes_AS_STRING, - .ctx_Bytes_FromString = &debug_ctx_Bytes_FromString, - .ctx_Bytes_FromStringAndSize = &debug_ctx_Bytes_FromStringAndSize, - .ctx_Unicode_FromString = &debug_ctx_Unicode_FromString, - .ctx_Unicode_Check = &debug_ctx_Unicode_Check, - .ctx_Unicode_AsUTF8String = &debug_ctx_Unicode_AsUTF8String, - .ctx_Unicode_FromWideChar = &debug_ctx_Unicode_FromWideChar, - .ctx_List_Check = &debug_ctx_List_Check, - .ctx_List_New = &debug_ctx_List_New, - .ctx_List_Append = &debug_ctx_List_Append, - .ctx_Dict_Check = &debug_ctx_Dict_Check, - .ctx_Dict_New = &debug_ctx_Dict_New, - .ctx_FatalError = &debug_ctx_FatalError, - .ctx_Tuple_FromArray = &debug_ctx_Tuple_FromArray, - .ctx_FromPyObject = &debug_ctx_FromPyObject, - .ctx_AsPyObject = &debug_ctx_AsPyObject, - .ctx_CallRealFunctionFromTrampoline = &debug_ctx_CallRealFunctionFromTrampoline, - .ctx_CallDestroyAndThenDealloc = &debug_ctx_CallDestroyAndThenDealloc, - .ctx_ListBuilder_New = &debug_ctx_ListBuilder_New, - .ctx_ListBuilder_Set = &debug_ctx_ListBuilder_Set, - .ctx_ListBuilder_Build = &debug_ctx_ListBuilder_Build, - .ctx_ListBuilder_Cancel = &debug_ctx_ListBuilder_Cancel, - .ctx_TupleBuilder_New = &debug_ctx_TupleBuilder_New, - .ctx_TupleBuilder_Set = &debug_ctx_TupleBuilder_Set, - .ctx_TupleBuilder_Build = &debug_ctx_TupleBuilder_Build, - .ctx_TupleBuilder_Cancel = &debug_ctx_TupleBuilder_Cancel, - .ctx_Tracker_New = &debug_ctx_Tracker_New, - .ctx_Tracker_Add = &debug_ctx_Tracker_Add, - .ctx_Tracker_ForgetAll = &debug_ctx_Tracker_ForgetAll, - .ctx_Tracker_Close = &debug_ctx_Tracker_Close, + .ctx_Module_Create = &_adapter_debug_ctx_Module_Create, + .ctx_Dup = &_adapter_debug_ctx_Dup, + .ctx_Close = &_adapter_debug_ctx_Close, + .ctx_Long_FromLong = &_adapter_debug_ctx_Long_FromLong, + .ctx_Long_FromUnsignedLong = &_adapter_debug_ctx_Long_FromUnsignedLong, + .ctx_Long_FromLongLong = &_adapter_debug_ctx_Long_FromLongLong, + .ctx_Long_FromUnsignedLongLong = &_adapter_debug_ctx_Long_FromUnsignedLongLong, + .ctx_Long_FromSize_t = &_adapter_debug_ctx_Long_FromSize_t, + .ctx_Long_FromSsize_t = &_adapter_debug_ctx_Long_FromSsize_t, + .ctx_Long_AsLong = &_adapter_debug_ctx_Long_AsLong, + .ctx_Long_AsUnsignedLong = &_adapter_debug_ctx_Long_AsUnsignedLong, + .ctx_Long_AsUnsignedLongMask = &_adapter_debug_ctx_Long_AsUnsignedLongMask, + .ctx_Long_AsLongLong = &_adapter_debug_ctx_Long_AsLongLong, + .ctx_Long_AsUnsignedLongLong = &_adapter_debug_ctx_Long_AsUnsignedLongLong, + .ctx_Long_AsUnsignedLongLongMask = &_adapter_debug_ctx_Long_AsUnsignedLongLongMask, + .ctx_Long_AsSize_t = &_adapter_debug_ctx_Long_AsSize_t, + .ctx_Long_AsSsize_t = &_adapter_debug_ctx_Long_AsSsize_t, + .ctx_Float_FromDouble = &_adapter_debug_ctx_Float_FromDouble, + .ctx_Float_AsDouble = &_adapter_debug_ctx_Float_AsDouble, + .ctx_Length = &_adapter_debug_ctx_Length, + .ctx_Number_Check = &_adapter_debug_ctx_Number_Check, + .ctx_Add = &_adapter_debug_ctx_Add, + .ctx_Subtract = &_adapter_debug_ctx_Subtract, + .ctx_Multiply = &_adapter_debug_ctx_Multiply, + .ctx_MatrixMultiply = &_adapter_debug_ctx_MatrixMultiply, + .ctx_FloorDivide = &_adapter_debug_ctx_FloorDivide, + .ctx_TrueDivide = &_adapter_debug_ctx_TrueDivide, + .ctx_Remainder = &_adapter_debug_ctx_Remainder, + .ctx_Divmod = &_adapter_debug_ctx_Divmod, + .ctx_Power = &_adapter_debug_ctx_Power, + .ctx_Negative = &_adapter_debug_ctx_Negative, + .ctx_Positive = &_adapter_debug_ctx_Positive, + .ctx_Absolute = &_adapter_debug_ctx_Absolute, + .ctx_Invert = &_adapter_debug_ctx_Invert, + .ctx_Lshift = &_adapter_debug_ctx_Lshift, + .ctx_Rshift = &_adapter_debug_ctx_Rshift, + .ctx_And = &_adapter_debug_ctx_And, + .ctx_Xor = &_adapter_debug_ctx_Xor, + .ctx_Or = &_adapter_debug_ctx_Or, + .ctx_Index = &_adapter_debug_ctx_Index, + .ctx_Long = &_adapter_debug_ctx_Long, + .ctx_Float = &_adapter_debug_ctx_Float, + .ctx_InPlaceAdd = &_adapter_debug_ctx_InPlaceAdd, + .ctx_InPlaceSubtract = &_adapter_debug_ctx_InPlaceSubtract, + .ctx_InPlaceMultiply = &_adapter_debug_ctx_InPlaceMultiply, + .ctx_InPlaceMatrixMultiply = &_adapter_debug_ctx_InPlaceMatrixMultiply, + .ctx_InPlaceFloorDivide = &_adapter_debug_ctx_InPlaceFloorDivide, + .ctx_InPlaceTrueDivide = &_adapter_debug_ctx_InPlaceTrueDivide, + .ctx_InPlaceRemainder = &_adapter_debug_ctx_InPlaceRemainder, + .ctx_InPlacePower = &_adapter_debug_ctx_InPlacePower, + .ctx_InPlaceLshift = &_adapter_debug_ctx_InPlaceLshift, + .ctx_InPlaceRshift = &_adapter_debug_ctx_InPlaceRshift, + .ctx_InPlaceAnd = &_adapter_debug_ctx_InPlaceAnd, + .ctx_InPlaceXor = &_adapter_debug_ctx_InPlaceXor, + .ctx_InPlaceOr = &_adapter_debug_ctx_InPlaceOr, + .ctx_Err_SetString = &_adapter_debug_ctx_Err_SetString, + .ctx_Err_SetObject = &_adapter_debug_ctx_Err_SetObject, + .ctx_Err_Occurred = &_adapter_debug_ctx_Err_Occurred, + .ctx_Err_NoMemory = &_adapter_debug_ctx_Err_NoMemory, + .ctx_Err_Clear = &_adapter_debug_ctx_Err_Clear, + .ctx_IsTrue = &_adapter_debug_ctx_IsTrue, + .ctx_Type_FromSpec = &_adapter_debug_ctx_Type_FromSpec, + .ctx_Type_GenericNew = &_adapter_debug_ctx_Type_GenericNew, + .ctx_GetAttr = &_adapter_debug_ctx_GetAttr, + .ctx_GetAttr_s = &_adapter_debug_ctx_GetAttr_s, + .ctx_HasAttr = &_adapter_debug_ctx_HasAttr, + .ctx_HasAttr_s = &_adapter_debug_ctx_HasAttr_s, + .ctx_SetAttr = &_adapter_debug_ctx_SetAttr, + .ctx_SetAttr_s = &_adapter_debug_ctx_SetAttr_s, + .ctx_GetItem = &_adapter_debug_ctx_GetItem, + .ctx_GetItem_i = &_adapter_debug_ctx_GetItem_i, + .ctx_GetItem_s = &_adapter_debug_ctx_GetItem_s, + .ctx_SetItem = &_adapter_debug_ctx_SetItem, + .ctx_SetItem_i = &_adapter_debug_ctx_SetItem_i, + .ctx_SetItem_s = &_adapter_debug_ctx_SetItem_s, + .ctx_Cast = &_adapter_debug_ctx_Cast, + .ctx_New = &_adapter_debug_ctx_New, + .ctx_Repr = &_adapter_debug_ctx_Repr, + .ctx_Str = &_adapter_debug_ctx_Str, + .ctx_ASCII = &_adapter_debug_ctx_ASCII, + .ctx_Bytes = &_adapter_debug_ctx_Bytes, + .ctx_RichCompare = &_adapter_debug_ctx_RichCompare, + .ctx_RichCompareBool = &_adapter_debug_ctx_RichCompareBool, + .ctx_Hash = &_adapter_debug_ctx_Hash, + .ctx_Bytes_Check = &_adapter_debug_ctx_Bytes_Check, + .ctx_Bytes_Size = &_adapter_debug_ctx_Bytes_Size, + .ctx_Bytes_GET_SIZE = &_adapter_debug_ctx_Bytes_GET_SIZE, + .ctx_Bytes_AsString = &_adapter_debug_ctx_Bytes_AsString, + .ctx_Bytes_AS_STRING = &_adapter_debug_ctx_Bytes_AS_STRING, + .ctx_Bytes_FromString = &_adapter_debug_ctx_Bytes_FromString, + .ctx_Bytes_FromStringAndSize = &_adapter_debug_ctx_Bytes_FromStringAndSize, + .ctx_Unicode_FromString = &_adapter_debug_ctx_Unicode_FromString, + .ctx_Unicode_Check = &_adapter_debug_ctx_Unicode_Check, + .ctx_Unicode_AsUTF8String = &_adapter_debug_ctx_Unicode_AsUTF8String, + .ctx_Unicode_FromWideChar = &_adapter_debug_ctx_Unicode_FromWideChar, + .ctx_List_Check = &_adapter_debug_ctx_List_Check, + .ctx_List_New = &_adapter_debug_ctx_List_New, + .ctx_List_Append = &_adapter_debug_ctx_List_Append, + .ctx_Dict_Check = &_adapter_debug_ctx_Dict_Check, + .ctx_Dict_New = &_adapter_debug_ctx_Dict_New, + .ctx_FatalError = &_adapter_debug_ctx_FatalError, + .ctx_Tuple_FromArray = &_adapter_debug_ctx_Tuple_FromArray, + .ctx_FromPyObject = &_adapter_debug_ctx_FromPyObject, + .ctx_AsPyObject = &_adapter_debug_ctx_AsPyObject, + .ctx_CallRealFunctionFromTrampoline = &_adapter_debug_ctx_CallRealFunctionFromTrampoline, + .ctx_CallDestroyAndThenDealloc = &_adapter_debug_ctx_CallDestroyAndThenDealloc, + .ctx_ListBuilder_New = &_adapter_debug_ctx_ListBuilder_New, + .ctx_ListBuilder_Set = &_adapter_debug_ctx_ListBuilder_Set, + .ctx_ListBuilder_Build = &_adapter_debug_ctx_ListBuilder_Build, + .ctx_ListBuilder_Cancel = &_adapter_debug_ctx_ListBuilder_Cancel, + .ctx_TupleBuilder_New = &_adapter_debug_ctx_TupleBuilder_New, + .ctx_TupleBuilder_Set = &_adapter_debug_ctx_TupleBuilder_Set, + .ctx_TupleBuilder_Build = &_adapter_debug_ctx_TupleBuilder_Build, + .ctx_TupleBuilder_Cancel = &_adapter_debug_ctx_TupleBuilder_Cancel, + .ctx_Tracker_New = &_adapter_debug_ctx_Tracker_New, + .ctx_Tracker_Add = &_adapter_debug_ctx_Tracker_Add, + .ctx_Tracker_ForgetAll = &_adapter_debug_ctx_Tracker_ForgetAll, + .ctx_Tracker_Close = &_adapter_debug_ctx_Tracker_Close, }; diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index df0fbc3da..2fad44462 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -12,289 +12,289 @@ #include "debug_internal.h" -HPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) +DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) { - return HPyModule_Create(get_info(ctx)->original_ctx, def); + return _h2d(HPyModule_Create(get_info(ctx)->original_ctx, def)); } -HPy debug_ctx_Dup(HPyContext ctx, HPy h) +DHPy debug_ctx_Dup(HPyContext ctx, DHPy h) { - return HPy_Dup(get_info(ctx)->original_ctx, h); + return _h2d(HPy_Dup(get_info(ctx)->original_ctx, h->h)); } -void debug_ctx_Close(HPyContext ctx, HPy h) +void debug_ctx_Close(HPyContext ctx, DHPy h) { - HPy_Close(get_info(ctx)->original_ctx, h); + HPy_Close(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_Long_FromLong(HPyContext ctx, long value) +DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value) { - return HPyLong_FromLong(get_info(ctx)->original_ctx, value); + return _h2d(HPyLong_FromLong(get_info(ctx)->original_ctx, value)); } -HPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) +DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) { - return HPyLong_FromUnsignedLong(get_info(ctx)->original_ctx, value); + return _h2d(HPyLong_FromUnsignedLong(get_info(ctx)->original_ctx, value)); } -HPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) +DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) { - return HPyLong_FromLongLong(get_info(ctx)->original_ctx, v); + return _h2d(HPyLong_FromLongLong(get_info(ctx)->original_ctx, v)); } -HPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) +DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) { - return HPyLong_FromUnsignedLongLong(get_info(ctx)->original_ctx, v); + return _h2d(HPyLong_FromUnsignedLongLong(get_info(ctx)->original_ctx, v)); } -HPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) +DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) { - return HPyLong_FromSize_t(get_info(ctx)->original_ctx, value); + return _h2d(HPyLong_FromSize_t(get_info(ctx)->original_ctx, value)); } -HPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) +DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) { - return HPyLong_FromSsize_t(get_info(ctx)->original_ctx, value); + return _h2d(HPyLong_FromSsize_t(get_info(ctx)->original_ctx, value)); } -long debug_ctx_Long_AsLong(HPyContext ctx, HPy h) +long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h) { - return HPyLong_AsLong(get_info(ctx)->original_ctx, h); + return HPyLong_AsLong(get_info(ctx)->original_ctx, h->h); } -unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, HPy h) +unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLong(get_info(ctx)->original_ctx, h); + return HPyLong_AsUnsignedLong(get_info(ctx)->original_ctx, h->h); } -unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, HPy h) +unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongMask(get_info(ctx)->original_ctx, h); + return HPyLong_AsUnsignedLongMask(get_info(ctx)->original_ctx, h->h); } -long long debug_ctx_Long_AsLongLong(HPyContext ctx, HPy h) +long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h) { - return HPyLong_AsLongLong(get_info(ctx)->original_ctx, h); + return HPyLong_AsLongLong(get_info(ctx)->original_ctx, h->h); } -unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, HPy h) +unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongLong(get_info(ctx)->original_ctx, h); + return HPyLong_AsUnsignedLongLong(get_info(ctx)->original_ctx, h->h); } -unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, HPy h) +unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->original_ctx, h); + return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->original_ctx, h->h); } -size_t debug_ctx_Long_AsSize_t(HPyContext ctx, HPy h) +size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h) { - return HPyLong_AsSize_t(get_info(ctx)->original_ctx, h); + return HPyLong_AsSize_t(get_info(ctx)->original_ctx, h->h); } -HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, HPy h) +HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h) { - return HPyLong_AsSsize_t(get_info(ctx)->original_ctx, h); + return HPyLong_AsSsize_t(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_Float_FromDouble(HPyContext ctx, double v) +DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v) { - return HPyFloat_FromDouble(get_info(ctx)->original_ctx, v); + return _h2d(HPyFloat_FromDouble(get_info(ctx)->original_ctx, v)); } -double debug_ctx_Float_AsDouble(HPyContext ctx, HPy h) +double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h) { - return HPyFloat_AsDouble(get_info(ctx)->original_ctx, h); + return HPyFloat_AsDouble(get_info(ctx)->original_ctx, h->h); } -HPy_ssize_t debug_ctx_Length(HPyContext ctx, HPy h) +HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h) { - return HPy_Length(get_info(ctx)->original_ctx, h); + return HPy_Length(get_info(ctx)->original_ctx, h->h); } -int debug_ctx_Number_Check(HPyContext ctx, HPy h) +int debug_ctx_Number_Check(HPyContext ctx, DHPy h) { - return HPyNumber_Check(get_info(ctx)->original_ctx, h); + return HPyNumber_Check(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_Add(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Add(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Add(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Subtract(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Subtract(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Subtract(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Multiply(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Multiply(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Multiply(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_MatrixMultiply(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_MatrixMultiply(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_MatrixMultiply(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_FloorDivide(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_FloorDivide(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_FloorDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_TrueDivide(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_TrueDivide(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_TrueDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Remainder(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Remainder(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Remainder(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Divmod(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Divmod(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Divmod(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Power(HPyContext ctx, HPy h1, HPy h2, HPy h3) +DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) { - return HPy_Power(get_info(ctx)->original_ctx, h1, h2, h3); + return _h2d(HPy_Power(get_info(ctx)->original_ctx, h1->h, h2->h, h3->h)); } -HPy debug_ctx_Negative(HPyContext ctx, HPy h1) +DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1) { - return HPy_Negative(get_info(ctx)->original_ctx, h1); + return _h2d(HPy_Negative(get_info(ctx)->original_ctx, h1->h)); } -HPy debug_ctx_Positive(HPyContext ctx, HPy h1) +DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1) { - return HPy_Positive(get_info(ctx)->original_ctx, h1); + return _h2d(HPy_Positive(get_info(ctx)->original_ctx, h1->h)); } -HPy debug_ctx_Absolute(HPyContext ctx, HPy h1) +DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1) { - return HPy_Absolute(get_info(ctx)->original_ctx, h1); + return _h2d(HPy_Absolute(get_info(ctx)->original_ctx, h1->h)); } -HPy debug_ctx_Invert(HPyContext ctx, HPy h1) +DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1) { - return HPy_Invert(get_info(ctx)->original_ctx, h1); + return _h2d(HPy_Invert(get_info(ctx)->original_ctx, h1->h)); } -HPy debug_ctx_Lshift(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Lshift(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Lshift(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Rshift(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Rshift(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Rshift(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_And(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_And(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_And(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Xor(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Xor(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Xor(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Or(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_Or(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_Or(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_Index(HPyContext ctx, HPy h1) +DHPy debug_ctx_Index(HPyContext ctx, DHPy h1) { - return HPy_Index(get_info(ctx)->original_ctx, h1); + return _h2d(HPy_Index(get_info(ctx)->original_ctx, h1->h)); } -HPy debug_ctx_Long(HPyContext ctx, HPy h1) +DHPy debug_ctx_Long(HPyContext ctx, DHPy h1) { - return HPy_Long(get_info(ctx)->original_ctx, h1); + return _h2d(HPy_Long(get_info(ctx)->original_ctx, h1->h)); } -HPy debug_ctx_Float(HPyContext ctx, HPy h1) +DHPy debug_ctx_Float(HPyContext ctx, DHPy h1) { - return HPy_Float(get_info(ctx)->original_ctx, h1); + return _h2d(HPy_Float(get_info(ctx)->original_ctx, h1->h)); } -HPy debug_ctx_InPlaceAdd(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceAdd(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceAdd(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceSubtract(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceSubtract(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceSubtract(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceMultiply(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceMultiply(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceMultiply(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceMatrixMultiply(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceMatrixMultiply(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceFloorDivide(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceFloorDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceTrueDivide(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceTrueDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceRemainder(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceRemainder(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceRemainder(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlacePower(HPyContext ctx, HPy h1, HPy h2, HPy h3) +DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) { - return HPy_InPlacePower(get_info(ctx)->original_ctx, h1, h2, h3); + return _h2d(HPy_InPlacePower(get_info(ctx)->original_ctx, h1->h, h2->h, h3->h)); } -HPy debug_ctx_InPlaceLshift(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceLshift(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceLshift(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceRshift(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceRshift(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceRshift(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceAnd(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceAnd(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceAnd(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceXor(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceXor(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceXor(get_info(ctx)->original_ctx, h1->h, h2->h)); } -HPy debug_ctx_InPlaceOr(HPyContext ctx, HPy h1, HPy h2) +DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2) { - return HPy_InPlaceOr(get_info(ctx)->original_ctx, h1, h2); + return _h2d(HPy_InPlaceOr(get_info(ctx)->original_ctx, h1->h, h2->h)); } -void debug_ctx_Err_SetString(HPyContext ctx, HPy h_type, const char *message) +void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message) { - HPyErr_SetString(get_info(ctx)->original_ctx, h_type, message); + HPyErr_SetString(get_info(ctx)->original_ctx, h_type->h, message); } -void debug_ctx_Err_SetObject(HPyContext ctx, HPy h_type, HPy h_value) +void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value) { - HPyErr_SetObject(get_info(ctx)->original_ctx, h_type, h_value); + HPyErr_SetObject(get_info(ctx)->original_ctx, h_type->h, h_value->h); } int debug_ctx_Err_Occurred(HPyContext ctx) @@ -302,9 +302,9 @@ int debug_ctx_Err_Occurred(HPyContext ctx) return HPyErr_Occurred(get_info(ctx)->original_ctx); } -HPy debug_ctx_Err_NoMemory(HPyContext ctx) +DHPy debug_ctx_Err_NoMemory(HPyContext ctx) { - return HPyErr_NoMemory(get_info(ctx)->original_ctx); + return _h2d(HPyErr_NoMemory(get_info(ctx)->original_ctx)); } void debug_ctx_Err_Clear(HPyContext ctx) @@ -312,204 +312,204 @@ void debug_ctx_Err_Clear(HPyContext ctx) HPyErr_Clear(get_info(ctx)->original_ctx); } -int debug_ctx_IsTrue(HPyContext ctx, HPy h) +int debug_ctx_IsTrue(HPyContext ctx, DHPy h) { - return HPy_IsTrue(get_info(ctx)->original_ctx, h); + return HPy_IsTrue(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) +DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) { - return HPyType_FromSpec(get_info(ctx)->original_ctx, spec, params); + return _h2d(HPyType_FromSpec(get_info(ctx)->original_ctx, spec, params)); } -HPy debug_ctx_Type_GenericNew(HPyContext ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw) +DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw) { - return HPyType_GenericNew(get_info(ctx)->original_ctx, type, args, nargs, kw); + return _h2d(HPyType_GenericNew(get_info(ctx)->original_ctx, type->h, (HPy *)args, nargs, kw->h)); } -HPy debug_ctx_GetAttr(HPyContext ctx, HPy obj, HPy name) +DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name) { - return HPy_GetAttr(get_info(ctx)->original_ctx, obj, name); + return _h2d(HPy_GetAttr(get_info(ctx)->original_ctx, obj->h, name->h)); } -HPy debug_ctx_GetAttr_s(HPyContext ctx, HPy obj, const char *name) +DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name) { - return HPy_GetAttr_s(get_info(ctx)->original_ctx, obj, name); + return _h2d(HPy_GetAttr_s(get_info(ctx)->original_ctx, obj->h, name)); } -int debug_ctx_HasAttr(HPyContext ctx, HPy obj, HPy name) +int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name) { - return HPy_HasAttr(get_info(ctx)->original_ctx, obj, name); + return HPy_HasAttr(get_info(ctx)->original_ctx, obj->h, name->h); } -int debug_ctx_HasAttr_s(HPyContext ctx, HPy obj, const char *name) +int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name) { - return HPy_HasAttr_s(get_info(ctx)->original_ctx, obj, name); + return HPy_HasAttr_s(get_info(ctx)->original_ctx, obj->h, name); } -int debug_ctx_SetAttr(HPyContext ctx, HPy obj, HPy name, HPy value) +int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value) { - return HPy_SetAttr(get_info(ctx)->original_ctx, obj, name, value); + return HPy_SetAttr(get_info(ctx)->original_ctx, obj->h, name->h, value->h); } -int debug_ctx_SetAttr_s(HPyContext ctx, HPy obj, const char *name, HPy value) +int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value) { - return HPy_SetAttr_s(get_info(ctx)->original_ctx, obj, name, value); + return HPy_SetAttr_s(get_info(ctx)->original_ctx, obj->h, name, value->h); } -HPy debug_ctx_GetItem(HPyContext ctx, HPy obj, HPy key) +DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key) { - return HPy_GetItem(get_info(ctx)->original_ctx, obj, key); + return _h2d(HPy_GetItem(get_info(ctx)->original_ctx, obj->h, key->h)); } -HPy debug_ctx_GetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx) +DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx) { - return HPy_GetItem_i(get_info(ctx)->original_ctx, obj, idx); + return _h2d(HPy_GetItem_i(get_info(ctx)->original_ctx, obj->h, idx)); } -HPy debug_ctx_GetItem_s(HPyContext ctx, HPy obj, const char *key) +DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key) { - return HPy_GetItem_s(get_info(ctx)->original_ctx, obj, key); + return _h2d(HPy_GetItem_s(get_info(ctx)->original_ctx, obj->h, key)); } -int debug_ctx_SetItem(HPyContext ctx, HPy obj, HPy key, HPy value) +int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value) { - return HPy_SetItem(get_info(ctx)->original_ctx, obj, key, value); + return HPy_SetItem(get_info(ctx)->original_ctx, obj->h, key->h, value->h); } -int debug_ctx_SetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx, HPy value) +int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value) { - return HPy_SetItem_i(get_info(ctx)->original_ctx, obj, idx, value); + return HPy_SetItem_i(get_info(ctx)->original_ctx, obj->h, idx, value->h); } -int debug_ctx_SetItem_s(HPyContext ctx, HPy obj, const char *key, HPy value) +int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value) { - return HPy_SetItem_s(get_info(ctx)->original_ctx, obj, key, value); + return HPy_SetItem_s(get_info(ctx)->original_ctx, obj->h, key, value->h); } -void *debug_ctx_Cast(HPyContext ctx, HPy h) +void *debug_ctx_Cast(HPyContext ctx, DHPy h) { - return _HPy_Cast(get_info(ctx)->original_ctx, h); + return _HPy_Cast(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_New(HPyContext ctx, HPy h_type, void **data) +DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data) { - return _HPy_New(get_info(ctx)->original_ctx, h_type, data); + return _h2d(_HPy_New(get_info(ctx)->original_ctx, h_type->h, data)); } -HPy debug_ctx_Repr(HPyContext ctx, HPy obj) +DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj) { - return HPy_Repr(get_info(ctx)->original_ctx, obj); + return _h2d(HPy_Repr(get_info(ctx)->original_ctx, obj->h)); } -HPy debug_ctx_Str(HPyContext ctx, HPy obj) +DHPy debug_ctx_Str(HPyContext ctx, DHPy obj) { - return HPy_Str(get_info(ctx)->original_ctx, obj); + return _h2d(HPy_Str(get_info(ctx)->original_ctx, obj->h)); } -HPy debug_ctx_ASCII(HPyContext ctx, HPy obj) +DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj) { - return HPy_ASCII(get_info(ctx)->original_ctx, obj); + return _h2d(HPy_ASCII(get_info(ctx)->original_ctx, obj->h)); } -HPy debug_ctx_Bytes(HPyContext ctx, HPy obj) +DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj) { - return HPy_Bytes(get_info(ctx)->original_ctx, obj); + return _h2d(HPy_Bytes(get_info(ctx)->original_ctx, obj->h)); } -HPy debug_ctx_RichCompare(HPyContext ctx, HPy v, HPy w, int op) +DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op) { - return HPy_RichCompare(get_info(ctx)->original_ctx, v, w, op); + return _h2d(HPy_RichCompare(get_info(ctx)->original_ctx, v->h, w->h, op)); } -int debug_ctx_RichCompareBool(HPyContext ctx, HPy v, HPy w, int op) +int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op) { - return HPy_RichCompareBool(get_info(ctx)->original_ctx, v, w, op); + return HPy_RichCompareBool(get_info(ctx)->original_ctx, v->h, w->h, op); } -HPy_hash_t debug_ctx_Hash(HPyContext ctx, HPy obj) +HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj) { - return HPy_Hash(get_info(ctx)->original_ctx, obj); + return HPy_Hash(get_info(ctx)->original_ctx, obj->h); } -int debug_ctx_Bytes_Check(HPyContext ctx, HPy h) +int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h) { - return HPyBytes_Check(get_info(ctx)->original_ctx, h); + return HPyBytes_Check(get_info(ctx)->original_ctx, h->h); } -HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, HPy h) +HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h) { - return HPyBytes_Size(get_info(ctx)->original_ctx, h); + return HPyBytes_Size(get_info(ctx)->original_ctx, h->h); } -HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, HPy h) +HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h) { - return HPyBytes_GET_SIZE(get_info(ctx)->original_ctx, h); + return HPyBytes_GET_SIZE(get_info(ctx)->original_ctx, h->h); } -char *debug_ctx_Bytes_AsString(HPyContext ctx, HPy h) +char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h) { - return HPyBytes_AsString(get_info(ctx)->original_ctx, h); + return HPyBytes_AsString(get_info(ctx)->original_ctx, h->h); } -char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, HPy h) +char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h) { - return HPyBytes_AS_STRING(get_info(ctx)->original_ctx, h); + return HPyBytes_AS_STRING(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) +DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) { - return HPyBytes_FromString(get_info(ctx)->original_ctx, v); + return _h2d(HPyBytes_FromString(get_info(ctx)->original_ctx, v)); } -HPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) +DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) { - return HPyBytes_FromStringAndSize(get_info(ctx)->original_ctx, v, len); + return _h2d(HPyBytes_FromStringAndSize(get_info(ctx)->original_ctx, v, len)); } -HPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) +DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) { - return HPyUnicode_FromString(get_info(ctx)->original_ctx, utf8); + return _h2d(HPyUnicode_FromString(get_info(ctx)->original_ctx, utf8)); } -int debug_ctx_Unicode_Check(HPyContext ctx, HPy h) +int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h) { - return HPyUnicode_Check(get_info(ctx)->original_ctx, h); + return HPyUnicode_Check(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, HPy h) +DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h) { - return HPyUnicode_AsUTF8String(get_info(ctx)->original_ctx, h); + return _h2d(HPyUnicode_AsUTF8String(get_info(ctx)->original_ctx, h->h)); } -HPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) +DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) { - return HPyUnicode_FromWideChar(get_info(ctx)->original_ctx, w, size); + return _h2d(HPyUnicode_FromWideChar(get_info(ctx)->original_ctx, w, size)); } -int debug_ctx_List_Check(HPyContext ctx, HPy h) +int debug_ctx_List_Check(HPyContext ctx, DHPy h) { - return HPyList_Check(get_info(ctx)->original_ctx, h); + return HPyList_Check(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) +DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) { - return HPyList_New(get_info(ctx)->original_ctx, len); + return _h2d(HPyList_New(get_info(ctx)->original_ctx, len)); } -int debug_ctx_List_Append(HPyContext ctx, HPy h_list, HPy h_item) +int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item) { - return HPyList_Append(get_info(ctx)->original_ctx, h_list, h_item); + return HPyList_Append(get_info(ctx)->original_ctx, h_list->h, h_item->h); } -int debug_ctx_Dict_Check(HPyContext ctx, HPy h) +int debug_ctx_Dict_Check(HPyContext ctx, DHPy h) { - return HPyDict_Check(get_info(ctx)->original_ctx, h); + return HPyDict_Check(get_info(ctx)->original_ctx, h->h); } -HPy debug_ctx_Dict_New(HPyContext ctx) +DHPy debug_ctx_Dict_New(HPyContext ctx) { - return HPyDict_New(get_info(ctx)->original_ctx); + return _h2d(HPyDict_New(get_info(ctx)->original_ctx)); } void debug_ctx_FatalError(HPyContext ctx, const char *message) @@ -517,19 +517,19 @@ void debug_ctx_FatalError(HPyContext ctx, const char *message) HPy_FatalError(get_info(ctx)->original_ctx, message); } -HPy debug_ctx_Tuple_FromArray(HPyContext ctx, HPy items[], HPy_ssize_t n) +DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n) { - return HPyTuple_FromArray(get_info(ctx)->original_ctx, items, n); + return _h2d(HPyTuple_FromArray(get_info(ctx)->original_ctx, (HPy *)items, n)); } -HPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) +DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) { - return HPy_FromPyObject(get_info(ctx)->original_ctx, obj); + return _h2d(HPy_FromPyObject(get_info(ctx)->original_ctx, obj)); } -cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, HPy h) +cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h) { - return HPy_AsPyObject(get_info(ctx)->original_ctx, h); + return HPy_AsPyObject(get_info(ctx)->original_ctx, h->h); } void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self) @@ -542,14 +542,14 @@ HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_siz return HPyListBuilder_New(get_info(ctx)->original_ctx, initial_size); } -void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item) +void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyListBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item); + HPyListBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item->h); } -HPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) +DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) { - return HPyListBuilder_Build(get_info(ctx)->original_ctx, builder); + return _h2d(HPyListBuilder_Build(get_info(ctx)->original_ctx, builder)); } void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder) @@ -562,14 +562,14 @@ HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_s return HPyTupleBuilder_New(get_info(ctx)->original_ctx, initial_size); } -void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item) +void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyTupleBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item); + HPyTupleBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item->h); } -HPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) +DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) { - return HPyTupleBuilder_Build(get_info(ctx)->original_ctx, builder); + return _h2d(HPyTupleBuilder_Build(get_info(ctx)->original_ctx, builder)); } void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder) @@ -582,9 +582,9 @@ HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size) return HPyTracker_New(get_info(ctx)->original_ctx, size); } -int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, HPy h) +int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h) { - return HPyTracker_Add(get_info(ctx)->original_ctx, ht, h); + return HPyTracker_Add(get_info(ctx)->original_ctx, ht, h->h); } void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht) diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index a306dd644..07074bc1c 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -8,12 +8,54 @@ #include "hpy.h" #include "hpy_debug.h" -// "debooff" is the closest to "debug" I could come up with :) #define HPY_DEBUG_MAGIC 0xDEB00FF +/* The Debug context is a wrapper around an underlying context, which we will + call Universal. The signatures of API functions are the same, but the HPy + types represents very different things: + + * HPys belonging by the Universal ctx are opaque (from our point of view) + * HPys belonging by the Debug ctx are pointers to a struct called DHPy_s + + Every DHPy is a wrapper around an universal HPy. To get the underlying + universal HPy, you can use its ->h field. + + To wrap an universal HPy into a DHPy, you need to call DHPy_new: this + function should be called only ONCE for each handle, and only if it + "fresh": it will record the DHPy into a list of open handles so that it can + be checked later. + + To avoid confusion and to prevent passing wrong handles by mistake, all the + various debug_ctx_* functions take and return DHPys. Inside + autogen_ctx_def.h there are no-op adapters which converts the DHPys into + HPys to make the C compiler happy. See also the corresponding comment + there. _d2h and _h2d "cast" a DHPy into an HPy, and they should be used + ONLY by the adapters. +*/ + +struct DHPy_s { + HPy h; + struct DHPy_s *next; +}; +typedef struct DHPy_s *DHPy; /* "Debug HPy" */ + + +/* ======================================================== */ +/* These two functions should be used ONLY be the adapters! */ +static inline HPy _d2h(DHPy dh) { + return (HPy){ ._i = (HPy_ssize_t)dh }; +} +static inline DHPy _h2d(HPy h) { + return (DHPy)h._i; +} +/* ======================================================== */ + + typedef struct { long magic_number; // used just for sanity checks HPyContext original_ctx; + DHPy *open_handles; // linked list + DHPy *closed_handles; // linked list } HPyDebugInfo; static inline HPyDebugInfo *get_info(HPyContext ctx) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index eae846686..dfa919323 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -1,14 +1,28 @@ from copy import deepcopy +import textwrap from pycparser import c_ast from .autogenfile import AutoGenFile from .parse import toC, find_typedecl -def get_debug_signature(func): - newnode = deepcopy(func.node) +class HPy_2_DHPy_Visitor(c_ast.NodeVisitor): + "Visitor which renames all HPy types to DHPy" + + def visit_IdentifierType(self, node): + if node.names == ['HPy']: + node.names = ['DHPy'] + +def funcnode_with_new_name(node, name): + newnode = deepcopy(node) typedecl = find_typedecl(newnode) - # rename the function - typedecl.declname = 'debug_%s' % func.ctx_name() - return toC(newnode) + typedecl.declname = name + return newnode + +def get_debug_wrapper_node(func): + newnode = funcnode_with_new_name(func.node, 'debug_%s' % func.ctx_name()) + # fix all the types + visitor = HPy_2_DHPy_Visitor() + visitor.visit(newnode) + return newnode class autogen_debug_ctx_def_h(AutoGenFile): PATH = 'hpy/debug/src/autogen_debug_ctx.h' @@ -16,9 +30,23 @@ class autogen_debug_ctx_def_h(AutoGenFile): def generate(self): lines = [] w = lines.append - # emit the declarations for all the debug_ctx_* functions + w(textwrap.dedent(""" + /* + The debug_ctx_* functions contain the actualy logic: they receive and + return handles of type DHPy. + + The _adapter_debug_* helpers cast DHPy into HPy and viceversa, to get + functions those signature is compatible to what is declared in the + HPyContext. Note that they are no-op, since the internal repr of DHPy + and HPy is the same (but the first is seen as a pointer to DHPy_s the + second as a small struct containining an integer), but the C standard + forbids casting function pointers whose arguments have nominally + different types, so we need to write the adapters manually. + */ + """)) + # emit the declarations and adapters for all the debug_ctx_* functions for func in self.api.functions: - w(get_debug_signature(func) + ';') + self.generate_adapter(w, func) # emit a static ctx which uses the various debug_ctx_* functions w('') @@ -29,10 +57,42 @@ def generate(self): for var in self.api.variables: w(' .%s = HPy_NULL,' % (var.name,)) for func in self.api.functions: - w(' .%s = &debug_%s,' % (func.ctx_name(), func.ctx_name())) + w(' .%s = &_adapter_debug_%s,' % (func.ctx_name(), func.ctx_name())) w('};') return '\n'.join(lines) + def generate_adapter(self, w, func): + name = 'debug_%s' % func.ctx_name() + wrapper_node = get_debug_wrapper_node(func) + w(toC(wrapper_node) + ';') # signature of the debug_ctx_* function + # + # emit the adapter + node = funcnode_with_new_name(func.node, '_adapter_%s' % name) + signature = toC(node) + rettype = toC(node.type.type) + def get_params(): + lst = [] + for p in node.type.args.params: + if toC(p.type) == 'HPy': + lst.append('_h2d(%s)' % p.name) + elif toC(p.type) in ('HPy *', 'HPy []'): + lst.append('(DHPy *)%s' % p.name) + else: + lst.append(p.name) + return ', '.join(lst) + params = get_params() + + w(signature) + w('{') + if rettype == 'void': + w(f' {name}({params});') + elif rettype == 'HPy': + w(f' return _d2h({name}({params}));') + else: + w(f' return {name}({params});') + w('}') + w('') + class autogen_debug_wrappers(AutoGenFile): PATH = 'hpy/debug/src/autogen_debug_wrappers.c' @@ -58,21 +118,32 @@ def gen_debug_wrapper(self, func): return # assert not func.is_varargs() + node = get_debug_wrapper_node(func) + signature = toC(node) + rettype = toC(node.type.type) + # def get_params(): - lst = [p.name for p in func.node.type.args.params] - assert lst[0] == 'ctx' - lst[0] = 'get_info(ctx)->original_ctx' + lst = [] + for p in node.type.args.params: + if p.name == 'ctx': + lst.append('get_info(ctx)->original_ctx') + elif toC(p.type) == 'DHPy': + lst.append('%s->h' % p.name) + elif toC(p.type) in ('DHPy *', 'DHPy []'): + lst.append('(HPy *)%s' % p.name) + else: + lst.append(p.name) return ', '.join(lst) - # params = get_params() - rettype = toC(func.node.type.type) # lines = [] w = lines.append - w(get_debug_signature(func)) + w(signature) w('{') if rettype == 'void': w(f' {func.name}({params});') + elif rettype == 'DHPy': + w(f' return _h2d({func.name}({params}));') else: w(f' return {func.name}({params});') w('}') From 34bb3d08a5ef17da67ebdeccbb7a6d32b341f7eb Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 31 Dec 2020 18:05:08 +0100 Subject: [PATCH 22/65] start to write and to test the logic to create debug handles --- hpy/debug/src/_debugmod.c | 31 +++++++++++++++++++++++++++---- hpy/debug/src/debug_ctx.c | 2 ++ hpy/debug/src/debug_handles.c | 12 ++++++++++++ hpy/debug/src/debug_internal.h | 6 ++++-- setup.py | 1 + 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 hpy/debug/src/debug_handles.c diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index 140858431..1f93633b5 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -2,15 +2,38 @@ // idea is that it should be reusable by other implementations #include "hpy.h" +#include "debug_internal.h" -HPyDef_METH(hello, "hello", hello_impl, HPyFunc_NOARGS) -static HPy hello_impl(HPyContext ctx, HPy self) +/* WARNING: all the functions called _test_* are used only for testing. They + are not supposed to be used outside tests */ + +HPyDef_METH(_test_DHPy_new, "_test_DHPy_new", _test_DHPy_new_impl, HPyFunc_O) +static HPy _test_DHPy_new_impl(HPyContext ctx, HPy self, HPy arg) +{ + HPyContext debug_ctx = hpy_debug_get_ctx(ctx); + HPy h2 = HPy_Dup(ctx, arg); + DHPy dh = DHPy_new(debug_ctx, h2); + // return the numeric value of the pointer, although it's a bit useless + return HPyLong_FromSsize_t(ctx, (HPy_ssize_t)dh); +} + +HPyDef_METH(_test_get_open_handles, "_test_get_open_handles", _test_get_open_handles_impl, HPyFunc_NOARGS) +static HPy _test_get_open_handles_impl(HPyContext ctx, HPy self) { - return HPyUnicode_FromString(ctx, "hello world"); + HPyContext debug_ctx = hpy_debug_get_ctx(ctx); + HPyDebugInfo *info = get_info(debug_ctx); + HPy hlist = HPyList_New(ctx, 0); + DHPy dh = info->open_handles; + while (dh != NULL) { + HPyList_Append(ctx, hlist, dh->h); + dh = dh->next; + } + return hlist; } static HPyDef *module_defines[] = { - &hello, + &_test_DHPy_new, + &_test_get_open_handles, NULL }; diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 3143286f2..979a5f910 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -34,6 +34,8 @@ static void debug_ctx_init(HPyContext original_ctx) // initialize debug_info debug_info.original_ctx = original_ctx; + debug_info.open_handles = NULL; + debug_info.closed_handles = NULL; g_debug_ctx._private = &debug_info; /* CallRealFunctionFromTrampoline is special, since it is responsible to diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c new file mode 100644 index 000000000..4bf2b4aa4 --- /dev/null +++ b/hpy/debug/src/debug_handles.c @@ -0,0 +1,12 @@ +#include "debug_internal.h" + +DHPy DHPy_new(HPyContext ctx, HPy h) +{ + HPyDebugInfo *info = get_info(ctx); + DHPy dh = malloc(sizeof(struct DHPy_s)); + dh->h = h; + dh->next = info->open_handles; + info->open_handles = dh; + return dh; +} + diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index 07074bc1c..2b61c4742 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -39,6 +39,8 @@ struct DHPy_s { }; typedef struct DHPy_s *DHPy; /* "Debug HPy" */ +DHPy DHPy_new(HPyContext ctx, HPy h); + /* ======================================================== */ /* These two functions should be used ONLY be the adapters! */ @@ -54,8 +56,8 @@ static inline DHPy _h2d(HPy h) { typedef struct { long magic_number; // used just for sanity checks HPyContext original_ctx; - DHPy *open_handles; // linked list - DHPy *closed_handles; // linked list + DHPy open_handles; // linked list + DHPy closed_handles; // linked list } HPyDebugInfo; static inline HPyDebugInfo *get_info(HPyContext ctx) diff --git a/setup.py b/setup.py index d6c222c56..9dff395ab 100644 --- a/setup.py +++ b/setup.py @@ -57,6 +57,7 @@ def get_scm_config(): 'hpy/devel/src/runtime/ctx_tuple.c', 'hpy/devel/src/runtime/ctx_tuplebuilder.c', 'hpy/debug/src/debug_ctx.c', + 'hpy/debug/src/debug_handles.c', 'hpy/debug/src/_debugmod.c', 'hpy/debug/src/autogen_debug_wrappers.c', ], From cc439cfb60db62d7b3ff2279edadc76bbfec2eea Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 11 Jan 2021 18:23:27 +0100 Subject: [PATCH 23/65] initialize debug_ctx->h_None & co.: test_noop passes again --- hpy/debug/src/autogen_debug_ctx.h | 78 ++++++++++++++++++++++++++++++- hpy/debug/src/debug_ctx.c | 3 ++ hpy/tools/autogen/__main__.py | 4 +- hpy/tools/autogen/debug.py | 12 ++++- 4 files changed, 92 insertions(+), 5 deletions(-) diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h index d1c4e9ab1..fc69b1d6f 100644 --- a/hpy/debug/src/autogen_debug_ctx.h +++ b/hpy/debug/src/autogen_debug_ctx.h @@ -2,7 +2,7 @@ /* DO NOT EDIT THIS FILE! - This file is automatically generated by hpy.tools.autogen.debug.autogen_debug_ctx_def_h + This file is automatically generated by hpy.tools.autogen.debug.autogen_debug_ctx_h See also hpy.tools.autogen and hpy/tools/public_api.h Run this to regenerate: @@ -732,6 +732,82 @@ void _adapter_debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) debug_ctx_Tracker_Close(ctx, ht); } +static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext original_ctx) +{ + ctx->h_None = _d2h(DHPy_new(ctx, original_ctx->h_None)); + ctx->h_True = _d2h(DHPy_new(ctx, original_ctx->h_True)); + ctx->h_False = _d2h(DHPy_new(ctx, original_ctx->h_False)); + ctx->h_BaseException = _d2h(DHPy_new(ctx, original_ctx->h_BaseException)); + ctx->h_Exception = _d2h(DHPy_new(ctx, original_ctx->h_Exception)); + ctx->h_StopAsyncIteration = _d2h(DHPy_new(ctx, original_ctx->h_StopAsyncIteration)); + ctx->h_StopIteration = _d2h(DHPy_new(ctx, original_ctx->h_StopIteration)); + ctx->h_GeneratorExit = _d2h(DHPy_new(ctx, original_ctx->h_GeneratorExit)); + ctx->h_ArithmeticError = _d2h(DHPy_new(ctx, original_ctx->h_ArithmeticError)); + ctx->h_LookupError = _d2h(DHPy_new(ctx, original_ctx->h_LookupError)); + ctx->h_AssertionError = _d2h(DHPy_new(ctx, original_ctx->h_AssertionError)); + ctx->h_AttributeError = _d2h(DHPy_new(ctx, original_ctx->h_AttributeError)); + ctx->h_BufferError = _d2h(DHPy_new(ctx, original_ctx->h_BufferError)); + ctx->h_EOFError = _d2h(DHPy_new(ctx, original_ctx->h_EOFError)); + ctx->h_FloatingPointError = _d2h(DHPy_new(ctx, original_ctx->h_FloatingPointError)); + ctx->h_OSError = _d2h(DHPy_new(ctx, original_ctx->h_OSError)); + ctx->h_ImportError = _d2h(DHPy_new(ctx, original_ctx->h_ImportError)); + ctx->h_ModuleNotFoundError = _d2h(DHPy_new(ctx, original_ctx->h_ModuleNotFoundError)); + ctx->h_IndexError = _d2h(DHPy_new(ctx, original_ctx->h_IndexError)); + ctx->h_KeyError = _d2h(DHPy_new(ctx, original_ctx->h_KeyError)); + ctx->h_KeyboardInterrupt = _d2h(DHPy_new(ctx, original_ctx->h_KeyboardInterrupt)); + ctx->h_MemoryError = _d2h(DHPy_new(ctx, original_ctx->h_MemoryError)); + ctx->h_NameError = _d2h(DHPy_new(ctx, original_ctx->h_NameError)); + ctx->h_OverflowError = _d2h(DHPy_new(ctx, original_ctx->h_OverflowError)); + ctx->h_RuntimeError = _d2h(DHPy_new(ctx, original_ctx->h_RuntimeError)); + ctx->h_RecursionError = _d2h(DHPy_new(ctx, original_ctx->h_RecursionError)); + ctx->h_NotImplementedError = _d2h(DHPy_new(ctx, original_ctx->h_NotImplementedError)); + ctx->h_SyntaxError = _d2h(DHPy_new(ctx, original_ctx->h_SyntaxError)); + ctx->h_IndentationError = _d2h(DHPy_new(ctx, original_ctx->h_IndentationError)); + ctx->h_TabError = _d2h(DHPy_new(ctx, original_ctx->h_TabError)); + ctx->h_ReferenceError = _d2h(DHPy_new(ctx, original_ctx->h_ReferenceError)); + ctx->h_SystemError = _d2h(DHPy_new(ctx, original_ctx->h_SystemError)); + ctx->h_SystemExit = _d2h(DHPy_new(ctx, original_ctx->h_SystemExit)); + ctx->h_TypeError = _d2h(DHPy_new(ctx, original_ctx->h_TypeError)); + ctx->h_UnboundLocalError = _d2h(DHPy_new(ctx, original_ctx->h_UnboundLocalError)); + ctx->h_UnicodeError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeError)); + ctx->h_UnicodeEncodeError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeEncodeError)); + ctx->h_UnicodeDecodeError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeDecodeError)); + ctx->h_UnicodeTranslateError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeTranslateError)); + ctx->h_ValueError = _d2h(DHPy_new(ctx, original_ctx->h_ValueError)); + ctx->h_ZeroDivisionError = _d2h(DHPy_new(ctx, original_ctx->h_ZeroDivisionError)); + ctx->h_BlockingIOError = _d2h(DHPy_new(ctx, original_ctx->h_BlockingIOError)); + ctx->h_BrokenPipeError = _d2h(DHPy_new(ctx, original_ctx->h_BrokenPipeError)); + ctx->h_ChildProcessError = _d2h(DHPy_new(ctx, original_ctx->h_ChildProcessError)); + ctx->h_ConnectionError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionError)); + ctx->h_ConnectionAbortedError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionAbortedError)); + ctx->h_ConnectionRefusedError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionRefusedError)); + ctx->h_ConnectionResetError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionResetError)); + ctx->h_FileExistsError = _d2h(DHPy_new(ctx, original_ctx->h_FileExistsError)); + ctx->h_FileNotFoundError = _d2h(DHPy_new(ctx, original_ctx->h_FileNotFoundError)); + ctx->h_InterruptedError = _d2h(DHPy_new(ctx, original_ctx->h_InterruptedError)); + ctx->h_IsADirectoryError = _d2h(DHPy_new(ctx, original_ctx->h_IsADirectoryError)); + ctx->h_NotADirectoryError = _d2h(DHPy_new(ctx, original_ctx->h_NotADirectoryError)); + ctx->h_PermissionError = _d2h(DHPy_new(ctx, original_ctx->h_PermissionError)); + ctx->h_ProcessLookupError = _d2h(DHPy_new(ctx, original_ctx->h_ProcessLookupError)); + ctx->h_TimeoutError = _d2h(DHPy_new(ctx, original_ctx->h_TimeoutError)); + ctx->h_Warning = _d2h(DHPy_new(ctx, original_ctx->h_Warning)); + ctx->h_UserWarning = _d2h(DHPy_new(ctx, original_ctx->h_UserWarning)); + ctx->h_DeprecationWarning = _d2h(DHPy_new(ctx, original_ctx->h_DeprecationWarning)); + ctx->h_PendingDeprecationWarning = _d2h(DHPy_new(ctx, original_ctx->h_PendingDeprecationWarning)); + ctx->h_SyntaxWarning = _d2h(DHPy_new(ctx, original_ctx->h_SyntaxWarning)); + ctx->h_RuntimeWarning = _d2h(DHPy_new(ctx, original_ctx->h_RuntimeWarning)); + ctx->h_FutureWarning = _d2h(DHPy_new(ctx, original_ctx->h_FutureWarning)); + ctx->h_ImportWarning = _d2h(DHPy_new(ctx, original_ctx->h_ImportWarning)); + ctx->h_UnicodeWarning = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeWarning)); + ctx->h_BytesWarning = _d2h(DHPy_new(ctx, original_ctx->h_BytesWarning)); + ctx->h_ResourceWarning = _d2h(DHPy_new(ctx, original_ctx->h_ResourceWarning)); + ctx->h_BaseObjectType = _d2h(DHPy_new(ctx, original_ctx->h_BaseObjectType)); + ctx->h_TypeType = _d2h(DHPy_new(ctx, original_ctx->h_TypeType)); + ctx->h_LongType = _d2h(DHPy_new(ctx, original_ctx->h_LongType)); + ctx->h_UnicodeType = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeType)); + ctx->h_TupleType = _d2h(DHPy_new(ctx, original_ctx->h_TupleType)); + ctx->h_ListType = _d2h(DHPy_new(ctx, original_ctx->h_ListType)); +} static struct _HPyContext_s g_debug_ctx = { .name = "HPy Debug Mode ABI", diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 979a5f910..0ce30cd11 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -38,6 +38,9 @@ static void debug_ctx_init(HPyContext original_ctx) debug_info.closed_handles = NULL; g_debug_ctx._private = &debug_info; + // initialze ctx->h_None, etc. + debug_init_prebuilt_handles(&g_debug_ctx, original_ctx); + /* CallRealFunctionFromTrampoline is special, since it is responsible to retrieve and pass the appropriate context to the HPy functions on CPython. Note that this is used ONLY on CPython, other implementations diff --git a/hpy/tools/autogen/__main__.py b/hpy/tools/autogen/__main__.py index 11fe52d68..aeec3899c 100644 --- a/hpy/tools/autogen/__main__.py +++ b/hpy/tools/autogen/__main__.py @@ -16,7 +16,7 @@ from .hpyfunc import autogen_ctx_call_i from .hpyfunc import autogen_cpython_hpyfunc_trampoline_h from .hpyslot import autogen_hpyslot_h -from .debug import autogen_debug_ctx_def_h, autogen_debug_wrappers +from .debug import autogen_debug_ctx_h, autogen_debug_wrappers from .pypy import autogen_pypy_txt def main(): @@ -38,7 +38,7 @@ def main(): autogen_ctx_call_i, autogen_cpython_hpyfunc_trampoline_h, autogen_hpyslot_h, - autogen_debug_ctx_def_h, + autogen_debug_ctx_h, autogen_debug_wrappers, autogen_pypy_txt): cls(api).write(outdir) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index dfa919323..4a88d6851 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -24,7 +24,7 @@ def get_debug_wrapper_node(func): visitor.visit(newnode) return newnode -class autogen_debug_ctx_def_h(AutoGenFile): +class autogen_debug_ctx_h(AutoGenFile): PATH = 'hpy/debug/src/autogen_debug_ctx.h' def generate(self): @@ -47,7 +47,7 @@ def generate(self): # emit the declarations and adapters for all the debug_ctx_* functions for func in self.api.functions: self.generate_adapter(w, func) - + self.generate_init_prebuilt_handles(w) # emit a static ctx which uses the various debug_ctx_* functions w('') w('static struct _HPyContext_s g_debug_ctx = {') @@ -93,6 +93,14 @@ def get_params(): w('}') w('') + def generate_init_prebuilt_handles(self, w): + w('static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext original_ctx)') + w('{') + for var in self.api.variables: + name = var.name + w(f' ctx->{name} = _d2h(DHPy_new(ctx, original_ctx->{name}));') + w('}') + class autogen_debug_wrappers(AutoGenFile): PATH = 'hpy/debug/src/autogen_debug_wrappers.c' From 95770eef0ddf29a16855352d4211094e0d652c1f Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 11 Jan 2021 18:28:26 +0100 Subject: [PATCH 24/65] add a helper script to invoke pytest inside gdb --- gdb-py.test | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 gdb-py.test diff --git a/gdb-py.test b/gdb-py.test new file mode 100755 index 000000000..165f037de --- /dev/null +++ b/gdb-py.test @@ -0,0 +1,3 @@ +#!/bin/bash + +gdb --eval-command run --args python3 -m pytest "$@" From dca923ad87e0b3ee5e7b8a561362c5a3824c48c9 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 11 Jan 2021 18:33:50 +0100 Subject: [PATCH 25/65] fix indentation --- hpy/universal/src/ctx_meth.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/hpy/universal/src/ctx_meth.c b/hpy/universal/src/ctx_meth.c index 42580aced..3e2bdd92b 100644 --- a/hpy/universal/src/ctx_meth.c +++ b/hpy/universal/src/ctx_meth.c @@ -31,26 +31,26 @@ ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, return; } case HPyFunc_KEYWORDS: { - HPyFunc_keywords f = (HPyFunc_keywords)func; - _HPyFunc_args_KEYWORDS *a = (_HPyFunc_args_KEYWORDS*)args; - Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); - HPy h_args[nargs * sizeof(HPy)]; - for (Py_ssize_t i = 0; i < nargs; i++) { - h_args[i] = _py2h(PyTuple_GET_ITEM(a->args, i)); - } - a->result = _h2py(f(ctx, _py2h(a->self), h_args, nargs, _py2h(a->kw))); - return; + HPyFunc_keywords f = (HPyFunc_keywords)func; + _HPyFunc_args_KEYWORDS *a = (_HPyFunc_args_KEYWORDS*)args; + Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); + HPy h_args[nargs * sizeof(HPy)]; + for (Py_ssize_t i = 0; i < nargs; i++) { + h_args[i] = _py2h(PyTuple_GET_ITEM(a->args, i)); + } + a->result = _h2py(f(ctx, _py2h(a->self), h_args, nargs, _py2h(a->kw))); + return; } case HPyFunc_INITPROC: { - HPyFunc_initproc f = (HPyFunc_initproc)func; - _HPyFunc_args_INITPROC *a = (_HPyFunc_args_INITPROC*)args; - Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); - HPy h_args[nargs * sizeof(HPy)]; - for (Py_ssize_t i = 0; i < nargs; i++) { - h_args[i] = _py2h(PyTuple_GET_ITEM(a->args, i)); - } - a->result = f(ctx, _py2h(a->self), h_args, nargs, _py2h(a->kw)); - return; + HPyFunc_initproc f = (HPyFunc_initproc)func; + _HPyFunc_args_INITPROC *a = (_HPyFunc_args_INITPROC*)args; + Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); + HPy h_args[nargs * sizeof(HPy)]; + for (Py_ssize_t i = 0; i < nargs; i++) { + h_args[i] = _py2h(PyTuple_GET_ITEM(a->args, i)); + } + a->result = f(ctx, _py2h(a->self), h_args, nargs, _py2h(a->kw)); + return; } #include "autogen_ctx_call.i" default: From f58cda4b900b147fb6e93d07847c458b3357b3f0 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 12 Jan 2021 18:01:32 +0100 Subject: [PATCH 26/65] typo --- hpy/debug/src/debug_ctx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 0ce30cd11..3fa1cba1c 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -28,7 +28,7 @@ static void debug_ctx_init(HPyContext original_ctx) { if (g_debug_ctx._private != NULL) { // already initialized - assert(get_info(&debug_ctx)->original_ctx == original_ctx); // sanity check + assert(get_info(&g_debug_ctx)->original_ctx == original_ctx); // sanity check return; } From f7270fc02cd2beb8fc36588a8c7badd373d70912 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 12 Jan 2021 18:39:58 +0100 Subject: [PATCH 27/65] make autogen after merging master --- hpy/debug/src/autogen_debug_ctx.h | 36 +++++++++++++++++++++++--- hpy/debug/src/autogen_debug_wrappers.c | 24 +++++++++++++++-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h index fc69b1d6f..d92baea7c 100644 --- a/hpy/debug/src/autogen_debug_ctx.h +++ b/hpy/debug/src/autogen_debug_ctx.h @@ -354,6 +354,24 @@ HPy _adapter_debug_ctx_InPlaceOr(HPyContext ctx, HPy h1, HPy h2) return _d2h(debug_ctx_InPlaceOr(ctx, _h2d(h1), _h2d(h2))); } +int debug_ctx_Callable_Check(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_Callable_Check(HPyContext ctx, HPy h) +{ + return debug_ctx_Callable_Check(ctx, _h2d(h)); +} + +DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw); +HPy _adapter_debug_ctx_CallTupleDict(HPyContext ctx, HPy callable, HPy args, HPy kw) +{ + return _d2h(debug_ctx_CallTupleDict(ctx, _h2d(callable), _h2d(args), _h2d(kw))); +} + +void debug_ctx_FatalError(HPyContext ctx, const char *message); +void _adapter_debug_ctx_FatalError(HPyContext ctx, const char *message) +{ + debug_ctx_FatalError(ctx, message); +} + void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message); void _adapter_debug_ctx_Err_SetString(HPyContext ctx, HPy h_type, const char *message) { @@ -624,10 +642,10 @@ HPy _adapter_debug_ctx_Dict_New(HPyContext ctx) return _d2h(debug_ctx_Dict_New(ctx)); } -void debug_ctx_FatalError(HPyContext ctx, const char *message); -void _adapter_debug_ctx_FatalError(HPyContext ctx, const char *message) +int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h); +int _adapter_debug_ctx_Tuple_Check(HPyContext ctx, HPy h) { - debug_ctx_FatalError(ctx, message); + return debug_ctx_Tuple_Check(ctx, _h2d(h)); } DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n); @@ -732,6 +750,12 @@ void _adapter_debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) debug_ctx_Tracker_Close(ctx, ht); } +void debug_ctx_Dump(HPyContext ctx, DHPy h); +void _adapter_debug_ctx_Dump(HPyContext ctx, HPy h) +{ + debug_ctx_Dump(ctx, _h2d(h)); +} + static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext original_ctx) { ctx->h_None = _d2h(DHPy_new(ctx, original_ctx->h_None)); @@ -941,6 +965,9 @@ static struct _HPyContext_s g_debug_ctx = { .ctx_InPlaceAnd = &_adapter_debug_ctx_InPlaceAnd, .ctx_InPlaceXor = &_adapter_debug_ctx_InPlaceXor, .ctx_InPlaceOr = &_adapter_debug_ctx_InPlaceOr, + .ctx_Callable_Check = &_adapter_debug_ctx_Callable_Check, + .ctx_CallTupleDict = &_adapter_debug_ctx_CallTupleDict, + .ctx_FatalError = &_adapter_debug_ctx_FatalError, .ctx_Err_SetString = &_adapter_debug_ctx_Err_SetString, .ctx_Err_SetObject = &_adapter_debug_ctx_Err_SetObject, .ctx_Err_Occurred = &_adapter_debug_ctx_Err_Occurred, @@ -986,7 +1013,7 @@ static struct _HPyContext_s g_debug_ctx = { .ctx_List_Append = &_adapter_debug_ctx_List_Append, .ctx_Dict_Check = &_adapter_debug_ctx_Dict_Check, .ctx_Dict_New = &_adapter_debug_ctx_Dict_New, - .ctx_FatalError = &_adapter_debug_ctx_FatalError, + .ctx_Tuple_Check = &_adapter_debug_ctx_Tuple_Check, .ctx_Tuple_FromArray = &_adapter_debug_ctx_Tuple_FromArray, .ctx_FromPyObject = &_adapter_debug_ctx_FromPyObject, .ctx_AsPyObject = &_adapter_debug_ctx_AsPyObject, @@ -1004,4 +1031,5 @@ static struct _HPyContext_s g_debug_ctx = { .ctx_Tracker_Add = &_adapter_debug_ctx_Tracker_Add, .ctx_Tracker_ForgetAll = &_adapter_debug_ctx_Tracker_ForgetAll, .ctx_Tracker_Close = &_adapter_debug_ctx_Tracker_Close, + .ctx_Dump = &_adapter_debug_ctx_Dump, }; diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index 2fad44462..113f0928e 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -287,6 +287,21 @@ DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2) return _h2d(HPy_InPlaceOr(get_info(ctx)->original_ctx, h1->h, h2->h)); } +int debug_ctx_Callable_Check(HPyContext ctx, DHPy h) +{ + return HPyCallable_Check(get_info(ctx)->original_ctx, h->h); +} + +DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw) +{ + return _h2d(HPy_CallTupleDict(get_info(ctx)->original_ctx, callable->h, args->h, kw->h)); +} + +void debug_ctx_FatalError(HPyContext ctx, const char *message) +{ + HPy_FatalError(get_info(ctx)->original_ctx, message); +} + void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message) { HPyErr_SetString(get_info(ctx)->original_ctx, h_type->h, message); @@ -512,9 +527,9 @@ DHPy debug_ctx_Dict_New(HPyContext ctx) return _h2d(HPyDict_New(get_info(ctx)->original_ctx)); } -void debug_ctx_FatalError(HPyContext ctx, const char *message) +int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h) { - HPy_FatalError(get_info(ctx)->original_ctx, message); + return HPyTuple_Check(get_info(ctx)->original_ctx, h->h); } DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n) @@ -597,3 +612,8 @@ void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) HPyTracker_Close(get_info(ctx)->original_ctx, ht); } +void debug_ctx_Dump(HPyContext ctx, DHPy h) +{ + _HPy_Dump(get_info(ctx)->original_ctx, h->h); +} + From d0f7fb7d6ebb252ae2767734dcdecca5e4fee721 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 12 Jan 2021 22:26:05 +0100 Subject: [PATCH 28/65] Big refactoring in hpy.universal handles Originally, we decided to represent handles as index into a list in anticipation of adding a "enable debug mode" flag. However, the new design is that the debug mode is a wrapper around a generic universal ctx: the debug ctx itself will take care of allocating all the necessary stuff to keep track of debug handles and it's no longer necessary to put this complication into hpy.universal. As a result, we can now implement hpy.universal handles which directly points to PyObject*, although we use some bitwise trick to ensure that casting HPy into PyObject* doesn't work. This should also make hpy.universal slightly faster than before. Incidentally, this also fixes a bad memory leak which was unnoticed until now: CallRealFunctionFromTrampoline converts the PyObject* args into HPy by calling _py2h: until now such a call allocated new handles which were never freed! With the new implementation of _py2h the problem goes away since we no longer allocate anything, although it must be noted that the new debug mode will have the same problem and thus will need a proper solution. --- hpy/tools/autogen/ctx.py | 3 +- hpy/universal/src/autogen_ctx_def.h | 74 +---------- hpy/universal/src/ctx_misc.c | 3 +- hpy/universal/src/handles.c | 192 ---------------------------- hpy/universal/src/handles.h | 100 ++------------- hpy/universal/src/hpymodule.c | 89 +++++++++++++ setup.py | 1 - 7 files changed, 107 insertions(+), 355 deletions(-) delete mode 100644 hpy/universal/src/handles.c diff --git a/hpy/tools/autogen/ctx.py b/hpy/tools/autogen/ctx.py index fdaa2bead..6d7adb2af 100644 --- a/hpy/tools/autogen/ctx.py +++ b/hpy/tools/autogen/ctx.py @@ -66,8 +66,7 @@ def generate(self): w(' .name = "HPy Universal ABI (CPython backend)",') w(' ._private = NULL,') w(' .ctx_version = 1,') - for var in self.api.variables: - w(' .%s = {CONSTANT_%s},' % (var.name, var.name.upper())) + w(' /* h_None & co. are initialized by init_universal_ctx() */') for func in self.api.functions: w(' .%s = &%s,' % (func.ctx_name(), func.ctx_name())) w('};') diff --git a/hpy/universal/src/autogen_ctx_def.h b/hpy/universal/src/autogen_ctx_def.h index d179cb5b0..26a4e93fe 100644 --- a/hpy/universal/src/autogen_ctx_def.h +++ b/hpy/universal/src/autogen_ctx_def.h @@ -14,79 +14,7 @@ struct _HPyContext_s g_universal_ctx = { .name = "HPy Universal ABI (CPython backend)", ._private = NULL, .ctx_version = 1, - .h_None = {CONSTANT_H_NONE}, - .h_True = {CONSTANT_H_TRUE}, - .h_False = {CONSTANT_H_FALSE}, - .h_BaseException = {CONSTANT_H_BASEEXCEPTION}, - .h_Exception = {CONSTANT_H_EXCEPTION}, - .h_StopAsyncIteration = {CONSTANT_H_STOPASYNCITERATION}, - .h_StopIteration = {CONSTANT_H_STOPITERATION}, - .h_GeneratorExit = {CONSTANT_H_GENERATOREXIT}, - .h_ArithmeticError = {CONSTANT_H_ARITHMETICERROR}, - .h_LookupError = {CONSTANT_H_LOOKUPERROR}, - .h_AssertionError = {CONSTANT_H_ASSERTIONERROR}, - .h_AttributeError = {CONSTANT_H_ATTRIBUTEERROR}, - .h_BufferError = {CONSTANT_H_BUFFERERROR}, - .h_EOFError = {CONSTANT_H_EOFERROR}, - .h_FloatingPointError = {CONSTANT_H_FLOATINGPOINTERROR}, - .h_OSError = {CONSTANT_H_OSERROR}, - .h_ImportError = {CONSTANT_H_IMPORTERROR}, - .h_ModuleNotFoundError = {CONSTANT_H_MODULENOTFOUNDERROR}, - .h_IndexError = {CONSTANT_H_INDEXERROR}, - .h_KeyError = {CONSTANT_H_KEYERROR}, - .h_KeyboardInterrupt = {CONSTANT_H_KEYBOARDINTERRUPT}, - .h_MemoryError = {CONSTANT_H_MEMORYERROR}, - .h_NameError = {CONSTANT_H_NAMEERROR}, - .h_OverflowError = {CONSTANT_H_OVERFLOWERROR}, - .h_RuntimeError = {CONSTANT_H_RUNTIMEERROR}, - .h_RecursionError = {CONSTANT_H_RECURSIONERROR}, - .h_NotImplementedError = {CONSTANT_H_NOTIMPLEMENTEDERROR}, - .h_SyntaxError = {CONSTANT_H_SYNTAXERROR}, - .h_IndentationError = {CONSTANT_H_INDENTATIONERROR}, - .h_TabError = {CONSTANT_H_TABERROR}, - .h_ReferenceError = {CONSTANT_H_REFERENCEERROR}, - .h_SystemError = {CONSTANT_H_SYSTEMERROR}, - .h_SystemExit = {CONSTANT_H_SYSTEMEXIT}, - .h_TypeError = {CONSTANT_H_TYPEERROR}, - .h_UnboundLocalError = {CONSTANT_H_UNBOUNDLOCALERROR}, - .h_UnicodeError = {CONSTANT_H_UNICODEERROR}, - .h_UnicodeEncodeError = {CONSTANT_H_UNICODEENCODEERROR}, - .h_UnicodeDecodeError = {CONSTANT_H_UNICODEDECODEERROR}, - .h_UnicodeTranslateError = {CONSTANT_H_UNICODETRANSLATEERROR}, - .h_ValueError = {CONSTANT_H_VALUEERROR}, - .h_ZeroDivisionError = {CONSTANT_H_ZERODIVISIONERROR}, - .h_BlockingIOError = {CONSTANT_H_BLOCKINGIOERROR}, - .h_BrokenPipeError = {CONSTANT_H_BROKENPIPEERROR}, - .h_ChildProcessError = {CONSTANT_H_CHILDPROCESSERROR}, - .h_ConnectionError = {CONSTANT_H_CONNECTIONERROR}, - .h_ConnectionAbortedError = {CONSTANT_H_CONNECTIONABORTEDERROR}, - .h_ConnectionRefusedError = {CONSTANT_H_CONNECTIONREFUSEDERROR}, - .h_ConnectionResetError = {CONSTANT_H_CONNECTIONRESETERROR}, - .h_FileExistsError = {CONSTANT_H_FILEEXISTSERROR}, - .h_FileNotFoundError = {CONSTANT_H_FILENOTFOUNDERROR}, - .h_InterruptedError = {CONSTANT_H_INTERRUPTEDERROR}, - .h_IsADirectoryError = {CONSTANT_H_ISADIRECTORYERROR}, - .h_NotADirectoryError = {CONSTANT_H_NOTADIRECTORYERROR}, - .h_PermissionError = {CONSTANT_H_PERMISSIONERROR}, - .h_ProcessLookupError = {CONSTANT_H_PROCESSLOOKUPERROR}, - .h_TimeoutError = {CONSTANT_H_TIMEOUTERROR}, - .h_Warning = {CONSTANT_H_WARNING}, - .h_UserWarning = {CONSTANT_H_USERWARNING}, - .h_DeprecationWarning = {CONSTANT_H_DEPRECATIONWARNING}, - .h_PendingDeprecationWarning = {CONSTANT_H_PENDINGDEPRECATIONWARNING}, - .h_SyntaxWarning = {CONSTANT_H_SYNTAXWARNING}, - .h_RuntimeWarning = {CONSTANT_H_RUNTIMEWARNING}, - .h_FutureWarning = {CONSTANT_H_FUTUREWARNING}, - .h_ImportWarning = {CONSTANT_H_IMPORTWARNING}, - .h_UnicodeWarning = {CONSTANT_H_UNICODEWARNING}, - .h_BytesWarning = {CONSTANT_H_BYTESWARNING}, - .h_ResourceWarning = {CONSTANT_H_RESOURCEWARNING}, - .h_BaseObjectType = {CONSTANT_H_BASEOBJECTTYPE}, - .h_TypeType = {CONSTANT_H_TYPETYPE}, - .h_LongType = {CONSTANT_H_LONGTYPE}, - .h_UnicodeType = {CONSTANT_H_UNICODETYPE}, - .h_TupleType = {CONSTANT_H_TUPLETYPE}, - .h_ListType = {CONSTANT_H_LISTTYPE}, + /* h_None & co. are initialized by init_universal_ctx() */ .ctx_Module_Create = &ctx_Module_Create, .ctx_Dup = &ctx_Dup, .ctx_Close = &ctx_Close, diff --git a/hpy/universal/src/ctx_misc.c b/hpy/universal/src/ctx_misc.c index a45dcfd2a..9afa98fc7 100644 --- a/hpy/universal/src/ctx_misc.c +++ b/hpy/universal/src/ctx_misc.c @@ -21,7 +21,8 @@ ctx_AsPyObject(HPyContext ctx, HPy h) HPyAPI_STORAGE void ctx_Close(HPyContext ctx, HPy h) { - _hclose(h); + PyObject *obj = _h2py(h); + Py_XDECREF(obj); } HPyAPI_STORAGE HPy diff --git a/hpy/universal/src/handles.c b/hpy/universal/src/handles.c deleted file mode 100644 index 79675da25..000000000 --- a/hpy/universal/src/handles.c +++ /dev/null @@ -1,192 +0,0 @@ -#include -#include -#include "hpy.h" -#include "handles.h" - - -#define hpy_assert(condition, ...) \ - do { \ - if (!(condition)) { \ - fprintf(stderr, "*** HPY HANDLES ERROR ***\n"); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ - abort(); \ - } \ - } while (0) - - -/* XXX we should turn the fast-path of _py2h and _h2py into macros in api.h */ - -static PyObject **all_handles; -static Py_ssize_t h_num_allocated = 0; -static Py_ssize_t h_free_list = -1; -static Py_ssize_t h_free_list_2 = -1; -/* note: h_free_list_2 is only here for debugging. We can push freed - handles directly into h_free_list. But using two free lists makes - reuses occur later and in a less deterministic order. */ - -static void -allocate_more_handles(void) -{ - if (h_free_list_2 >= 0) { - h_free_list = h_free_list_2; - h_free_list_2 = -1; - return; - } - - Py_ssize_t base = (h_num_allocated < CONSTANT_H__TOTAL ? - CONSTANT_H__TOTAL : h_num_allocated); - Py_ssize_t i, allocate = (base / 2) * 3 + 32; - PyObject **new_handles = PyMem_Malloc(sizeof(PyObject *) * allocate); - memcpy(new_handles, all_handles, sizeof(PyObject *) * h_num_allocated); - - for (i = allocate - 1; i >= base; i--) { - new_handles[i] = (PyObject *)((h_free_list << 1) | 1); - h_free_list = i; - } - - if (h_num_allocated == 0) { - new_handles[CONSTANT_H_NULL] = NULL; - /* Constants */ - new_handles[CONSTANT_H_NONE] = Py_None; - new_handles[CONSTANT_H_TRUE] = Py_True; - new_handles[CONSTANT_H_FALSE] = Py_False; - /* Exceptions */ - new_handles[CONSTANT_H_BASEEXCEPTION] = PyExc_BaseException; - new_handles[CONSTANT_H_EXCEPTION] = PyExc_Exception; - new_handles[CONSTANT_H_STOPASYNCITERATION] = PyExc_StopAsyncIteration; - new_handles[CONSTANT_H_STOPITERATION] = PyExc_StopIteration; - new_handles[CONSTANT_H_GENERATOREXIT] = PyExc_GeneratorExit; - new_handles[CONSTANT_H_ARITHMETICERROR] = PyExc_ArithmeticError; - new_handles[CONSTANT_H_LOOKUPERROR] = PyExc_LookupError; - new_handles[CONSTANT_H_ASSERTIONERROR] = PyExc_AssertionError; - new_handles[CONSTANT_H_ATTRIBUTEERROR] = PyExc_AttributeError; - new_handles[CONSTANT_H_BUFFERERROR] = PyExc_BufferError; - new_handles[CONSTANT_H_EOFERROR] = PyExc_EOFError; - new_handles[CONSTANT_H_FLOATINGPOINTERROR] = PyExc_FloatingPointError; - new_handles[CONSTANT_H_OSERROR] = PyExc_OSError; - new_handles[CONSTANT_H_IMPORTERROR] = PyExc_ImportError; - new_handles[CONSTANT_H_MODULENOTFOUNDERROR] = PyExc_ModuleNotFoundError; - new_handles[CONSTANT_H_INDEXERROR] = PyExc_IndexError; - new_handles[CONSTANT_H_KEYERROR] = PyExc_KeyError; - new_handles[CONSTANT_H_KEYBOARDINTERRUPT] = PyExc_KeyboardInterrupt; - new_handles[CONSTANT_H_MEMORYERROR] = PyExc_MemoryError; - new_handles[CONSTANT_H_NAMEERROR] = PyExc_NameError; - new_handles[CONSTANT_H_OVERFLOWERROR] = PyExc_OverflowError; - new_handles[CONSTANT_H_RUNTIMEERROR] = PyExc_RuntimeError; - new_handles[CONSTANT_H_RECURSIONERROR] = PyExc_RecursionError; - new_handles[CONSTANT_H_NOTIMPLEMENTEDERROR] = PyExc_NotImplementedError; - new_handles[CONSTANT_H_SYNTAXERROR] = PyExc_SyntaxError; - new_handles[CONSTANT_H_INDENTATIONERROR] = PyExc_IndentationError; - new_handles[CONSTANT_H_TABERROR] = PyExc_TabError; - new_handles[CONSTANT_H_REFERENCEERROR] = PyExc_ReferenceError; - new_handles[CONSTANT_H_SYSTEMERROR] = PyExc_SystemError; - new_handles[CONSTANT_H_SYSTEMEXIT] = PyExc_SystemExit; - new_handles[CONSTANT_H_TYPEERROR] = PyExc_TypeError; - new_handles[CONSTANT_H_UNBOUNDLOCALERROR] = PyExc_UnboundLocalError; - new_handles[CONSTANT_H_UNICODEERROR] = PyExc_UnicodeError; - new_handles[CONSTANT_H_UNICODEENCODEERROR] = PyExc_UnicodeEncodeError; - new_handles[CONSTANT_H_UNICODEDECODEERROR] = PyExc_UnicodeDecodeError; - new_handles[CONSTANT_H_UNICODETRANSLATEERROR] = PyExc_UnicodeTranslateError; - new_handles[CONSTANT_H_VALUEERROR] = PyExc_ValueError; - new_handles[CONSTANT_H_ZERODIVISIONERROR] = PyExc_ZeroDivisionError; - new_handles[CONSTANT_H_BLOCKINGIOERROR] = PyExc_BlockingIOError; - new_handles[CONSTANT_H_BROKENPIPEERROR] = PyExc_BrokenPipeError; - new_handles[CONSTANT_H_CHILDPROCESSERROR] = PyExc_ChildProcessError; - new_handles[CONSTANT_H_CONNECTIONERROR] = PyExc_ConnectionError; - new_handles[CONSTANT_H_CONNECTIONABORTEDERROR] = PyExc_ConnectionAbortedError; - new_handles[CONSTANT_H_CONNECTIONREFUSEDERROR] = PyExc_ConnectionRefusedError; - new_handles[CONSTANT_H_CONNECTIONRESETERROR] = PyExc_ConnectionResetError; - new_handles[CONSTANT_H_FILEEXISTSERROR] = PyExc_FileExistsError; - new_handles[CONSTANT_H_FILENOTFOUNDERROR] = PyExc_FileNotFoundError; - new_handles[CONSTANT_H_INTERRUPTEDERROR] = PyExc_InterruptedError; - new_handles[CONSTANT_H_ISADIRECTORYERROR] = PyExc_IsADirectoryError; - new_handles[CONSTANT_H_NOTADIRECTORYERROR] = PyExc_NotADirectoryError; - new_handles[CONSTANT_H_PERMISSIONERROR] = PyExc_PermissionError; - new_handles[CONSTANT_H_PROCESSLOOKUPERROR] = PyExc_ProcessLookupError; - new_handles[CONSTANT_H_TIMEOUTERROR] = PyExc_TimeoutError; - /* Warnings */ - new_handles[CONSTANT_H_WARNING] = PyExc_Warning; - new_handles[CONSTANT_H_USERWARNING] = PyExc_UserWarning; - new_handles[CONSTANT_H_DEPRECATIONWARNING] = PyExc_DeprecationWarning; - new_handles[CONSTANT_H_PENDINGDEPRECATIONWARNING] = PyExc_PendingDeprecationWarning; - new_handles[CONSTANT_H_SYNTAXWARNING] = PyExc_SyntaxWarning; - new_handles[CONSTANT_H_RUNTIMEWARNING] = PyExc_RuntimeWarning; - new_handles[CONSTANT_H_FUTUREWARNING] = PyExc_FutureWarning; - new_handles[CONSTANT_H_IMPORTWARNING] = PyExc_ImportWarning; - new_handles[CONSTANT_H_UNICODEWARNING] = PyExc_UnicodeWarning; - new_handles[CONSTANT_H_BYTESWARNING] = PyExc_BytesWarning; - new_handles[CONSTANT_H_RESOURCEWARNING] = PyExc_ResourceWarning; - /* Types */ - new_handles[CONSTANT_H_BASEOBJECTTYPE] = (PyObject *)&PyBaseObject_Type; - new_handles[CONSTANT_H_TYPETYPE] = (PyObject *)&PyType_Type; - new_handles[CONSTANT_H_LONGTYPE] = (PyObject *)&PyLong_Type; - new_handles[CONSTANT_H_UNICODETYPE] = (PyObject *)&PyUnicode_Type; - new_handles[CONSTANT_H_TUPLETYPE] = (PyObject *)&PyTuple_Type; - new_handles[CONSTANT_H_LISTTYPE] = (PyObject *)&PyList_Type; - /* Check total */ - hpy_assert(CONSTANT_H__TOTAL == 74, - "update handles.c with the list of constants"); - } - - PyMem_Free(all_handles); - all_handles = new_handles; - h_num_allocated = allocate; -} - -HPy -_py2h(PyObject *obj) -{ - if (obj == NULL) { - // Return the existing copy of HPy_NULL and don't create a new - // handle. - return HPy_NULL; - } - if (h_free_list < 0) { - allocate_more_handles(); - } - Py_ssize_t i = h_free_list; - h_free_list = ((Py_ssize_t)all_handles[i]) >> 1; - all_handles[i] = obj; - return (HPy){i}; -} - -PyObject * -_h2py(HPy h) -{ - hpy_assert(h._i >= 0 && h._i < h_num_allocated, - "using an HPy containing garbage: _i = %p", (void *)h._i); - // If HPy_IsNull(h), the h._i = 0 and the line below returns the - // pointer attached to the 0th handle, i.e. NULL. - PyObject *result = all_handles[h._i]; - if (h._i == 0) { - hpy_assert(result == NULL, "handle number 0 doesn't contain NULL"); - return NULL; - } - hpy_assert((((Py_ssize_t)result) & 1) == 0, - "using an HPy that was freed already (or never allocated): _i = %p", - (void *)h._i); - hpy_assert(result != NULL, - "NULL PyObject unexpected in handle _i = %p", (void *)h._i); - hpy_assert(Py_REFCNT(result) > 0, - "bogus (freed?) PyObject found in handle _i = %p", (void *)h._i); - return result; -} - -void -_hclose(HPy h) -{ - Py_ssize_t i = h._i; - hpy_assert(i >= 0 && i < h_num_allocated, - "freeing an HPy containing garbage: _i = %p", (void *)i); - hpy_assert(i != 0, "freeing HPy_NULL is not allowed"); - PyObject *old = all_handles[i]; - hpy_assert((((Py_ssize_t)old) & 1) == 0, - "freeing an HPy that was freed already (or never allocated): _i = %p", - (void *)i); - hpy_assert(Py_REFCNT(old) > 0, - "bogus PyObject found while freeing handle _i = %p", (void *)h._i); - all_handles[i] = (PyObject *)((h_free_list_2 << 1) | 1); - h_free_list_2 = i; - Py_DECREF(old); -} diff --git a/hpy/universal/src/handles.h b/hpy/universal/src/handles.h index b9fb0f9ad..96fd06dc6 100644 --- a/hpy/universal/src/handles.h +++ b/hpy/universal/src/handles.h @@ -2,93 +2,21 @@ #define HPY_HANDLES_H #include +#include "hpy.h" -// this should maybe autogenerated from public_api.h -enum { - CONSTANT_H_NULL = 0, - /* Constants */ - CONSTANT_H_NONE, - CONSTANT_H_TRUE, - CONSTANT_H_FALSE, - /* Exceptions */ - CONSTANT_H_BASEEXCEPTION, - CONSTANT_H_EXCEPTION, - CONSTANT_H_STOPASYNCITERATION, - CONSTANT_H_STOPITERATION, - CONSTANT_H_GENERATOREXIT, - CONSTANT_H_ARITHMETICERROR, - CONSTANT_H_LOOKUPERROR, - CONSTANT_H_ASSERTIONERROR, - CONSTANT_H_ATTRIBUTEERROR, - CONSTANT_H_BUFFERERROR, - CONSTANT_H_EOFERROR, - CONSTANT_H_FLOATINGPOINTERROR, - CONSTANT_H_OSERROR, - CONSTANT_H_IMPORTERROR, - CONSTANT_H_MODULENOTFOUNDERROR, - CONSTANT_H_INDEXERROR, - CONSTANT_H_KEYERROR, - CONSTANT_H_KEYBOARDINTERRUPT, - CONSTANT_H_MEMORYERROR, - CONSTANT_H_NAMEERROR, - CONSTANT_H_OVERFLOWERROR, - CONSTANT_H_RUNTIMEERROR, - CONSTANT_H_RECURSIONERROR, - CONSTANT_H_NOTIMPLEMENTEDERROR, - CONSTANT_H_SYNTAXERROR, - CONSTANT_H_INDENTATIONERROR, - CONSTANT_H_TABERROR, - CONSTANT_H_REFERENCEERROR, - CONSTANT_H_SYSTEMERROR, - CONSTANT_H_SYSTEMEXIT, - CONSTANT_H_TYPEERROR, - CONSTANT_H_UNBOUNDLOCALERROR, - CONSTANT_H_UNICODEERROR, - CONSTANT_H_UNICODEENCODEERROR, - CONSTANT_H_UNICODEDECODEERROR, - CONSTANT_H_UNICODETRANSLATEERROR, - CONSTANT_H_VALUEERROR, - CONSTANT_H_ZERODIVISIONERROR, - CONSTANT_H_BLOCKINGIOERROR, - CONSTANT_H_BROKENPIPEERROR, - CONSTANT_H_CHILDPROCESSERROR, - CONSTANT_H_CONNECTIONERROR, - CONSTANT_H_CONNECTIONABORTEDERROR, - CONSTANT_H_CONNECTIONREFUSEDERROR, - CONSTANT_H_CONNECTIONRESETERROR, - CONSTANT_H_FILEEXISTSERROR, - CONSTANT_H_FILENOTFOUNDERROR, - CONSTANT_H_INTERRUPTEDERROR, - CONSTANT_H_ISADIRECTORYERROR, - CONSTANT_H_NOTADIRECTORYERROR, - CONSTANT_H_PERMISSIONERROR, - CONSTANT_H_PROCESSLOOKUPERROR, - CONSTANT_H_TIMEOUTERROR, - /* Warnings */ - CONSTANT_H_WARNING, - CONSTANT_H_USERWARNING, - CONSTANT_H_DEPRECATIONWARNING, - CONSTANT_H_PENDINGDEPRECATIONWARNING, - CONSTANT_H_SYNTAXWARNING, - CONSTANT_H_RUNTIMEWARNING, - CONSTANT_H_FUTUREWARNING, - CONSTANT_H_IMPORTWARNING, - CONSTANT_H_UNICODEWARNING, - CONSTANT_H_BYTESWARNING, - CONSTANT_H_RESOURCEWARNING, - /* Types */ - CONSTANT_H_BASEOBJECTTYPE, - CONSTANT_H_TYPETYPE, - CONSTANT_H_LONGTYPE, - CONSTANT_H_UNICODETYPE, - CONSTANT_H_TUPLETYPE, - CONSTANT_H_LISTTYPE, - /* Total */ - CONSTANT_H__TOTAL, -}; +// represent handles as ~address. The main reason is to make sure that if +// people casts HPy to PyObject* directly, things explode. -HPy _py2h(PyObject *); -PyObject *_h2py(HPy); -void _hclose(HPy); +static inline HPy _py2h(PyObject *obj) { + if (obj == NULL) + return HPy_NULL; + return (HPy){~(HPy_ssize_t)obj}; +} + +static inline PyObject *_h2py(HPy h) { + if HPy_IsNull(h) + return NULL; + return (PyObject *)~h._i; +} #endif /* HPY_HANDLES_H */ diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 89854c68c..d64dc8a48 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -187,9 +187,98 @@ int exec_module(PyObject* mod) { return 0; } +static void init_universal_ctx(HPyContext ctx) +{ + if (!HPy_IsNull(ctx->h_None)) + // already initialized + return; + + // XXX this code is basically the same as found in cpython/hpy.h. We + // should probably share and/or autogenerate both versions + /* Constants */ + ctx->h_None = _py2h(Py_None); + ctx->h_True = _py2h(Py_True); + ctx->h_False = _py2h(Py_False); + /* Exceptions */ + ctx->h_BaseException = _py2h(PyExc_BaseException); + ctx->h_Exception = _py2h(PyExc_Exception); + ctx->h_StopAsyncIteration = _py2h(PyExc_StopAsyncIteration); + ctx->h_StopIteration = _py2h(PyExc_StopIteration); + ctx->h_GeneratorExit = _py2h(PyExc_GeneratorExit); + ctx->h_ArithmeticError = _py2h(PyExc_ArithmeticError); + ctx->h_LookupError = _py2h(PyExc_LookupError); + ctx->h_AssertionError = _py2h(PyExc_AssertionError); + ctx->h_AttributeError = _py2h(PyExc_AttributeError); + ctx->h_BufferError = _py2h(PyExc_BufferError); + ctx->h_EOFError = _py2h(PyExc_EOFError); + ctx->h_FloatingPointError = _py2h(PyExc_FloatingPointError); + ctx->h_OSError = _py2h(PyExc_OSError); + ctx->h_ImportError = _py2h(PyExc_ImportError); + ctx->h_ModuleNotFoundError = _py2h(PyExc_ModuleNotFoundError); + ctx->h_IndexError = _py2h(PyExc_IndexError); + ctx->h_KeyError = _py2h(PyExc_KeyError); + ctx->h_KeyboardInterrupt = _py2h(PyExc_KeyboardInterrupt); + ctx->h_MemoryError = _py2h(PyExc_MemoryError); + ctx->h_NameError = _py2h(PyExc_NameError); + ctx->h_OverflowError = _py2h(PyExc_OverflowError); + ctx->h_RuntimeError = _py2h(PyExc_RuntimeError); + ctx->h_RecursionError = _py2h(PyExc_RecursionError); + ctx->h_NotImplementedError = _py2h(PyExc_NotImplementedError); + ctx->h_SyntaxError = _py2h(PyExc_SyntaxError); + ctx->h_IndentationError = _py2h(PyExc_IndentationError); + ctx->h_TabError = _py2h(PyExc_TabError); + ctx->h_ReferenceError = _py2h(PyExc_ReferenceError); + ctx->h_SystemError = _py2h(PyExc_SystemError); + ctx->h_SystemExit = _py2h(PyExc_SystemExit); + ctx->h_TypeError = _py2h(PyExc_TypeError); + ctx->h_UnboundLocalError = _py2h(PyExc_UnboundLocalError); + ctx->h_UnicodeError = _py2h(PyExc_UnicodeError); + ctx->h_UnicodeEncodeError = _py2h(PyExc_UnicodeEncodeError); + ctx->h_UnicodeDecodeError = _py2h(PyExc_UnicodeDecodeError); + ctx->h_UnicodeTranslateError = _py2h(PyExc_UnicodeTranslateError); + ctx->h_ValueError = _py2h(PyExc_ValueError); + ctx->h_ZeroDivisionError = _py2h(PyExc_ZeroDivisionError); + ctx->h_BlockingIOError = _py2h(PyExc_BlockingIOError); + ctx->h_BrokenPipeError = _py2h(PyExc_BrokenPipeError); + ctx->h_ChildProcessError = _py2h(PyExc_ChildProcessError); + ctx->h_ConnectionError = _py2h(PyExc_ConnectionError); + ctx->h_ConnectionAbortedError = _py2h(PyExc_ConnectionAbortedError); + ctx->h_ConnectionRefusedError = _py2h(PyExc_ConnectionRefusedError); + ctx->h_ConnectionResetError = _py2h(PyExc_ConnectionResetError); + ctx->h_FileExistsError = _py2h(PyExc_FileExistsError); + ctx->h_FileNotFoundError = _py2h(PyExc_FileNotFoundError); + ctx->h_InterruptedError = _py2h(PyExc_InterruptedError); + ctx->h_IsADirectoryError = _py2h(PyExc_IsADirectoryError); + ctx->h_NotADirectoryError = _py2h(PyExc_NotADirectoryError); + ctx->h_PermissionError = _py2h(PyExc_PermissionError); + ctx->h_ProcessLookupError = _py2h(PyExc_ProcessLookupError); + ctx->h_TimeoutError = _py2h(PyExc_TimeoutError); + /* Warnings */ + ctx->h_Warning = _py2h(PyExc_Warning); + ctx->h_UserWarning = _py2h(PyExc_UserWarning); + ctx->h_DeprecationWarning = _py2h(PyExc_DeprecationWarning); + ctx->h_PendingDeprecationWarning = _py2h(PyExc_PendingDeprecationWarning); + ctx->h_SyntaxWarning = _py2h(PyExc_SyntaxWarning); + ctx->h_RuntimeWarning = _py2h(PyExc_RuntimeWarning); + ctx->h_FutureWarning = _py2h(PyExc_FutureWarning); + ctx->h_ImportWarning = _py2h(PyExc_ImportWarning); + ctx->h_UnicodeWarning = _py2h(PyExc_UnicodeWarning); + ctx->h_BytesWarning = _py2h(PyExc_BytesWarning); + ctx->h_ResourceWarning = _py2h(PyExc_ResourceWarning); + /* Types */ + ctx->h_BaseObjectType = _py2h((PyObject *)&PyBaseObject_Type); + ctx->h_TypeType = _py2h((PyObject *)&PyType_Type); + ctx->h_LongType = _py2h((PyObject *)&PyLong_Type); + ctx->h_UnicodeType = _py2h((PyObject *)&PyUnicode_Type); + ctx->h_TupleType = _py2h((PyObject *)&PyTuple_Type); + ctx->h_ListType = _py2h((PyObject *)&PyList_Type); +} + + PyMODINIT_FUNC PyInit_universal(void) { + init_universal_ctx(&g_universal_ctx); PyObject *mod = PyModuleDef_Init(&hpydef); return mod; } diff --git a/setup.py b/setup.py index ea2811da1..495eaae9e 100644 --- a/setup.py +++ b/setup.py @@ -48,7 +48,6 @@ def get_scm_config(): EXT_MODULES += [ Extension('hpy.universal', ['hpy/universal/src/hpymodule.c', - 'hpy/universal/src/handles.c', 'hpy/universal/src/ctx.c', 'hpy/universal/src/ctx_meth.c', 'hpy/universal/src/ctx_misc.c', From 59184b278b1fa322adef78d5928a588c9431736c Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 13:33:11 +0100 Subject: [PATCH 29/65] use +1/-1 instead of ~ for _py2h and _h2py: it's easier to look at them in gdb --- hpy/universal/src/handles.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hpy/universal/src/handles.h b/hpy/universal/src/handles.h index 96fd06dc6..cb722e9bc 100644 --- a/hpy/universal/src/handles.h +++ b/hpy/universal/src/handles.h @@ -4,19 +4,21 @@ #include #include "hpy.h" -// represent handles as ~address. The main reason is to make sure that if -// people casts HPy to PyObject* directly, things explode. +// The main reason for +1/-1 is to make sure that if people casts HPy to +// PyObject* directly, things explode. Moreover, with this we can easily +// distinguish normal and debug handles in gdb, by only looking at the last +// bit. static inline HPy _py2h(PyObject *obj) { if (obj == NULL) return HPy_NULL; - return (HPy){~(HPy_ssize_t)obj}; + return (HPy){(HPy_ssize_t)obj + 1}; } static inline PyObject *_h2py(HPy h) { if HPy_IsNull(h) return NULL; - return (PyObject *)~h._i; + return (PyObject *)(h._i - 1); } #endif /* HPY_HANDLES_H */ From 484e28da8e77f223259b4695300489a07a00d13b Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 14:33:14 +0100 Subject: [PATCH 30/65] Fix this XXX: and properly close the handle Differently than _h2py, HPy_AsPyObject does an incref, so we can safely close the handle and be sure that py_mod stays alive. Moreover, _h2py works only with the universal ctx, while HPy_AsPyObject will work even if we use the debug ctx --- hpy/universal/src/hpymodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index d64dc8a48..6a055b97b 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -116,11 +116,11 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path, int debug) } HPyContext ctx = get_context(debug); - HPy mod = ((InitFuncPtr)initfn)(ctx); - if (HPy_IsNull(mod)) + HPy h_mod = ((InitFuncPtr)initfn)(ctx); + if (HPy_IsNull(h_mod)) goto error; - PyObject *py_mod = _h2py(mod); - // XXX close the handle + PyObject *py_mod = HPy_AsPyObject(ctx, h_mod); + HPy_Close(ctx, h_mod); Py_XDECREF(name); Py_XDECREF(pathbytes); From 92216b1660899682fe4356bf66d0072d97517b8a Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 14:48:35 +0100 Subject: [PATCH 31/65] add a helper function to help gdb sessions --- hpy/debug/src/debug_ctx.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 3fa1cba1c..e7575f04c 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -73,3 +73,24 @@ HPyContext hpy_debug_get_ctx(HPyContext original_ctx) debug_ctx_init(original_ctx); return &g_debug_ctx; } + +// this function is supposed to be called from gdb: it tries to determine +// whether a handle is universal or debug by looking at the last bit +extern struct _HPyContext_s g_universal_ctx; +__attribute__((unused)) static void hpy_magic_dump(HPy h) +{ + int universal = h._i & 1; + if (universal) + fprintf(stderr, "Universal handle\n"); + else + fprintf(stderr, "Debug handle\n"); + + fprintf(stderr, "raw value: %lx (%ld)\n", h._i, h._i); + if (universal) + _HPy_Dump(&g_universal_ctx, h); + else { + DHPy dh = (DHPy)h._i; + fprintf(stderr, "dh->h: %lx\n", dh->h._i); + _HPy_Dump(&g_universal_ctx, dh->h); + } +} From 51bb8def997a6e17834c7d47ab921f746548c0fa Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 16:02:54 +0100 Subject: [PATCH 32/65] WIP: refactor everything again. The idea of making DHPy and HPy two different C types was nice in theory, but it was too complicated and confusing in practice. The new approach of using DHPy and UHPy is less type safe but probably easier to follow. See the comment inside debug_internal.h for more details --- hpy/debug/src/_debugmod.c | 8 + hpy/debug/src/autogen_debug_ctx.h | 1013 +++++------------------- hpy/debug/src/autogen_debug_wrappers.c | 220 ++--- hpy/debug/src/debug_ctx.c | 10 +- hpy/debug/src/debug_handles.c | 13 +- hpy/debug/src/debug_internal.h | 76 +- hpy/tools/autogen/debug.py | 63 +- 7 files changed, 375 insertions(+), 1028 deletions(-) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index 1f93633b5..e07dfcbca 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -10,16 +10,23 @@ HPyDef_METH(_test_DHPy_new, "_test_DHPy_new", _test_DHPy_new_impl, HPyFunc_O) static HPy _test_DHPy_new_impl(HPyContext ctx, HPy self, HPy arg) { + HPyErr_SetString(ctx, ctx->h_NotImplementedError, "TODO"); + return HPy_NULL; + /* HPyContext debug_ctx = hpy_debug_get_ctx(ctx); HPy h2 = HPy_Dup(ctx, arg); DHPy dh = DHPy_new(debug_ctx, h2); // return the numeric value of the pointer, although it's a bit useless return HPyLong_FromSsize_t(ctx, (HPy_ssize_t)dh); + */ } HPyDef_METH(_test_get_open_handles, "_test_get_open_handles", _test_get_open_handles_impl, HPyFunc_NOARGS) static HPy _test_get_open_handles_impl(HPyContext ctx, HPy self) { + HPyErr_SetString(ctx, ctx->h_NotImplementedError, "TODO"); + return HPy_NULL; + /* HPyContext debug_ctx = hpy_debug_get_ctx(ctx); HPyDebugInfo *info = get_info(debug_ctx); HPy hlist = HPyList_New(ctx, 0); @@ -29,6 +36,7 @@ static HPy _test_get_open_handles_impl(HPyContext ctx, HPy self) dh = dh->next; } return hlist; + */ } static HPyDef *module_defines[] = { diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h index d92baea7c..b8deedbe5 100644 --- a/hpy/debug/src/autogen_debug_ctx.h +++ b/hpy/debug/src/autogen_debug_ctx.h @@ -10,827 +10,204 @@ */ - -/* -The debug_ctx_* functions contain the actualy logic: they receive and -return handles of type DHPy. - -The _adapter_debug_* helpers cast DHPy into HPy and viceversa, to get -functions those signature is compatible to what is declared in the -HPyContext. Note that they are no-op, since the internal repr of DHPy -and HPy is the same (but the first is seen as a pointer to DHPy_s the -second as a small struct containining an integer), but the C standard -forbids casting function pointers whose arguments have nominally -different types, so we need to write the adapters manually. -*/ - DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def); -HPy _adapter_debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) -{ - return _d2h(debug_ctx_Module_Create(ctx, def)); -} - DHPy debug_ctx_Dup(HPyContext ctx, DHPy h); -HPy _adapter_debug_ctx_Dup(HPyContext ctx, HPy h) -{ - return _d2h(debug_ctx_Dup(ctx, _h2d(h))); -} - void debug_ctx_Close(HPyContext ctx, DHPy h); -void _adapter_debug_ctx_Close(HPyContext ctx, HPy h) -{ - debug_ctx_Close(ctx, _h2d(h)); -} - DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value); -HPy _adapter_debug_ctx_Long_FromLong(HPyContext ctx, long value) -{ - return _d2h(debug_ctx_Long_FromLong(ctx, value)); -} - DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value); -HPy _adapter_debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) -{ - return _d2h(debug_ctx_Long_FromUnsignedLong(ctx, value)); -} - DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v); -HPy _adapter_debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) -{ - return _d2h(debug_ctx_Long_FromLongLong(ctx, v)); -} - DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v); -HPy _adapter_debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) -{ - return _d2h(debug_ctx_Long_FromUnsignedLongLong(ctx, v)); -} - DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value); -HPy _adapter_debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) -{ - return _d2h(debug_ctx_Long_FromSize_t(ctx, value)); -} - DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value); -HPy _adapter_debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) -{ - return _d2h(debug_ctx_Long_FromSsize_t(ctx, value)); -} - long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h); -long _adapter_debug_ctx_Long_AsLong(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsLong(ctx, _h2d(h)); -} - unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h); -unsigned long _adapter_debug_ctx_Long_AsUnsignedLong(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsUnsignedLong(ctx, _h2d(h)); -} - unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h); -unsigned long _adapter_debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsUnsignedLongMask(ctx, _h2d(h)); -} - long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h); -long long _adapter_debug_ctx_Long_AsLongLong(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsLongLong(ctx, _h2d(h)); -} - unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h); -unsigned long long _adapter_debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsUnsignedLongLong(ctx, _h2d(h)); -} - unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h); -unsigned long long _adapter_debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsUnsignedLongLongMask(ctx, _h2d(h)); -} - size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h); -size_t _adapter_debug_ctx_Long_AsSize_t(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsSize_t(ctx, _h2d(h)); -} - HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h); -HPy_ssize_t _adapter_debug_ctx_Long_AsSsize_t(HPyContext ctx, HPy h) -{ - return debug_ctx_Long_AsSsize_t(ctx, _h2d(h)); -} - DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v); -HPy _adapter_debug_ctx_Float_FromDouble(HPyContext ctx, double v) -{ - return _d2h(debug_ctx_Float_FromDouble(ctx, v)); -} - double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h); -double _adapter_debug_ctx_Float_AsDouble(HPyContext ctx, HPy h) -{ - return debug_ctx_Float_AsDouble(ctx, _h2d(h)); -} - HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h); -HPy_ssize_t _adapter_debug_ctx_Length(HPyContext ctx, HPy h) -{ - return debug_ctx_Length(ctx, _h2d(h)); -} - int debug_ctx_Number_Check(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_Number_Check(HPyContext ctx, HPy h) -{ - return debug_ctx_Number_Check(ctx, _h2d(h)); -} - DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Add(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Add(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Subtract(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Subtract(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Multiply(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Multiply(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_MatrixMultiply(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_MatrixMultiply(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_FloorDivide(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_FloorDivide(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_TrueDivide(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_TrueDivide(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Remainder(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Remainder(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Divmod(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Divmod(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); -HPy _adapter_debug_ctx_Power(HPyContext ctx, HPy h1, HPy h2, HPy h3) -{ - return _d2h(debug_ctx_Power(ctx, _h2d(h1), _h2d(h2), _h2d(h3))); -} - DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1); -HPy _adapter_debug_ctx_Negative(HPyContext ctx, HPy h1) -{ - return _d2h(debug_ctx_Negative(ctx, _h2d(h1))); -} - DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1); -HPy _adapter_debug_ctx_Positive(HPyContext ctx, HPy h1) -{ - return _d2h(debug_ctx_Positive(ctx, _h2d(h1))); -} - DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1); -HPy _adapter_debug_ctx_Absolute(HPyContext ctx, HPy h1) -{ - return _d2h(debug_ctx_Absolute(ctx, _h2d(h1))); -} - DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1); -HPy _adapter_debug_ctx_Invert(HPyContext ctx, HPy h1) -{ - return _d2h(debug_ctx_Invert(ctx, _h2d(h1))); -} - DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Lshift(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Lshift(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Rshift(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Rshift(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_And(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_And(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Xor(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Xor(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_Or(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_Or(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_Index(HPyContext ctx, DHPy h1); -HPy _adapter_debug_ctx_Index(HPyContext ctx, HPy h1) -{ - return _d2h(debug_ctx_Index(ctx, _h2d(h1))); -} - DHPy debug_ctx_Long(HPyContext ctx, DHPy h1); -HPy _adapter_debug_ctx_Long(HPyContext ctx, HPy h1) -{ - return _d2h(debug_ctx_Long(ctx, _h2d(h1))); -} - DHPy debug_ctx_Float(HPyContext ctx, DHPy h1); -HPy _adapter_debug_ctx_Float(HPyContext ctx, HPy h1) -{ - return _d2h(debug_ctx_Float(ctx, _h2d(h1))); -} - DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceAdd(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceAdd(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceSubtract(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceSubtract(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceMultiply(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceMultiply(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceMatrixMultiply(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceFloorDivide(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceFloorDivide(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceTrueDivide(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceTrueDivide(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceRemainder(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceRemainder(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); -HPy _adapter_debug_ctx_InPlacePower(HPyContext ctx, HPy h1, HPy h2, HPy h3) -{ - return _d2h(debug_ctx_InPlacePower(ctx, _h2d(h1), _h2d(h2), _h2d(h3))); -} - DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceLshift(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceLshift(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceRshift(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceRshift(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceAnd(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceAnd(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceXor(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceXor(ctx, _h2d(h1), _h2d(h2))); -} - DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2); -HPy _adapter_debug_ctx_InPlaceOr(HPyContext ctx, HPy h1, HPy h2) -{ - return _d2h(debug_ctx_InPlaceOr(ctx, _h2d(h1), _h2d(h2))); -} - int debug_ctx_Callable_Check(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_Callable_Check(HPyContext ctx, HPy h) -{ - return debug_ctx_Callable_Check(ctx, _h2d(h)); -} - DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw); -HPy _adapter_debug_ctx_CallTupleDict(HPyContext ctx, HPy callable, HPy args, HPy kw) -{ - return _d2h(debug_ctx_CallTupleDict(ctx, _h2d(callable), _h2d(args), _h2d(kw))); -} - void debug_ctx_FatalError(HPyContext ctx, const char *message); -void _adapter_debug_ctx_FatalError(HPyContext ctx, const char *message) -{ - debug_ctx_FatalError(ctx, message); -} - void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message); -void _adapter_debug_ctx_Err_SetString(HPyContext ctx, HPy h_type, const char *message) -{ - debug_ctx_Err_SetString(ctx, _h2d(h_type), message); -} - void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value); -void _adapter_debug_ctx_Err_SetObject(HPyContext ctx, HPy h_type, HPy h_value) -{ - debug_ctx_Err_SetObject(ctx, _h2d(h_type), _h2d(h_value)); -} - int debug_ctx_Err_Occurred(HPyContext ctx); -int _adapter_debug_ctx_Err_Occurred(HPyContext ctx) -{ - return debug_ctx_Err_Occurred(ctx); -} - DHPy debug_ctx_Err_NoMemory(HPyContext ctx); -HPy _adapter_debug_ctx_Err_NoMemory(HPyContext ctx) -{ - return _d2h(debug_ctx_Err_NoMemory(ctx)); -} - void debug_ctx_Err_Clear(HPyContext ctx); -void _adapter_debug_ctx_Err_Clear(HPyContext ctx) -{ - debug_ctx_Err_Clear(ctx); -} - int debug_ctx_IsTrue(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_IsTrue(HPyContext ctx, HPy h) -{ - return debug_ctx_IsTrue(ctx, _h2d(h)); -} - DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params); -HPy _adapter_debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) -{ - return _d2h(debug_ctx_Type_FromSpec(ctx, spec, params)); -} - DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw); -HPy _adapter_debug_ctx_Type_GenericNew(HPyContext ctx, HPy type, HPy *args, HPy_ssize_t nargs, HPy kw) -{ - return _d2h(debug_ctx_Type_GenericNew(ctx, _h2d(type), (DHPy *)args, nargs, _h2d(kw))); -} - DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name); -HPy _adapter_debug_ctx_GetAttr(HPyContext ctx, HPy obj, HPy name) -{ - return _d2h(debug_ctx_GetAttr(ctx, _h2d(obj), _h2d(name))); -} - DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name); -HPy _adapter_debug_ctx_GetAttr_s(HPyContext ctx, HPy obj, const char *name) -{ - return _d2h(debug_ctx_GetAttr_s(ctx, _h2d(obj), name)); -} - int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name); -int _adapter_debug_ctx_HasAttr(HPyContext ctx, HPy obj, HPy name) -{ - return debug_ctx_HasAttr(ctx, _h2d(obj), _h2d(name)); -} - int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name); -int _adapter_debug_ctx_HasAttr_s(HPyContext ctx, HPy obj, const char *name) -{ - return debug_ctx_HasAttr_s(ctx, _h2d(obj), name); -} - int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value); -int _adapter_debug_ctx_SetAttr(HPyContext ctx, HPy obj, HPy name, HPy value) -{ - return debug_ctx_SetAttr(ctx, _h2d(obj), _h2d(name), _h2d(value)); -} - int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value); -int _adapter_debug_ctx_SetAttr_s(HPyContext ctx, HPy obj, const char *name, HPy value) -{ - return debug_ctx_SetAttr_s(ctx, _h2d(obj), name, _h2d(value)); -} - DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key); -HPy _adapter_debug_ctx_GetItem(HPyContext ctx, HPy obj, HPy key) -{ - return _d2h(debug_ctx_GetItem(ctx, _h2d(obj), _h2d(key))); -} - DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx); -HPy _adapter_debug_ctx_GetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx) -{ - return _d2h(debug_ctx_GetItem_i(ctx, _h2d(obj), idx)); -} - DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key); -HPy _adapter_debug_ctx_GetItem_s(HPyContext ctx, HPy obj, const char *key) -{ - return _d2h(debug_ctx_GetItem_s(ctx, _h2d(obj), key)); -} - int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value); -int _adapter_debug_ctx_SetItem(HPyContext ctx, HPy obj, HPy key, HPy value) -{ - return debug_ctx_SetItem(ctx, _h2d(obj), _h2d(key), _h2d(value)); -} - int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value); -int _adapter_debug_ctx_SetItem_i(HPyContext ctx, HPy obj, HPy_ssize_t idx, HPy value) -{ - return debug_ctx_SetItem_i(ctx, _h2d(obj), idx, _h2d(value)); -} - int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value); -int _adapter_debug_ctx_SetItem_s(HPyContext ctx, HPy obj, const char *key, HPy value) -{ - return debug_ctx_SetItem_s(ctx, _h2d(obj), key, _h2d(value)); -} - void *debug_ctx_Cast(HPyContext ctx, DHPy h); -void *_adapter_debug_ctx_Cast(HPyContext ctx, HPy h) -{ - return debug_ctx_Cast(ctx, _h2d(h)); -} - DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data); -HPy _adapter_debug_ctx_New(HPyContext ctx, HPy h_type, void **data) -{ - return _d2h(debug_ctx_New(ctx, _h2d(h_type), data)); -} - DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj); -HPy _adapter_debug_ctx_Repr(HPyContext ctx, HPy obj) -{ - return _d2h(debug_ctx_Repr(ctx, _h2d(obj))); -} - DHPy debug_ctx_Str(HPyContext ctx, DHPy obj); -HPy _adapter_debug_ctx_Str(HPyContext ctx, HPy obj) -{ - return _d2h(debug_ctx_Str(ctx, _h2d(obj))); -} - DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj); -HPy _adapter_debug_ctx_ASCII(HPyContext ctx, HPy obj) -{ - return _d2h(debug_ctx_ASCII(ctx, _h2d(obj))); -} - DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj); -HPy _adapter_debug_ctx_Bytes(HPyContext ctx, HPy obj) -{ - return _d2h(debug_ctx_Bytes(ctx, _h2d(obj))); -} - DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op); -HPy _adapter_debug_ctx_RichCompare(HPyContext ctx, HPy v, HPy w, int op) -{ - return _d2h(debug_ctx_RichCompare(ctx, _h2d(v), _h2d(w), op)); -} - int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op); -int _adapter_debug_ctx_RichCompareBool(HPyContext ctx, HPy v, HPy w, int op) -{ - return debug_ctx_RichCompareBool(ctx, _h2d(v), _h2d(w), op); -} - HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj); -HPy_hash_t _adapter_debug_ctx_Hash(HPyContext ctx, HPy obj) -{ - return debug_ctx_Hash(ctx, _h2d(obj)); -} - int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_Bytes_Check(HPyContext ctx, HPy h) -{ - return debug_ctx_Bytes_Check(ctx, _h2d(h)); -} - HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h); -HPy_ssize_t _adapter_debug_ctx_Bytes_Size(HPyContext ctx, HPy h) -{ - return debug_ctx_Bytes_Size(ctx, _h2d(h)); -} - HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h); -HPy_ssize_t _adapter_debug_ctx_Bytes_GET_SIZE(HPyContext ctx, HPy h) -{ - return debug_ctx_Bytes_GET_SIZE(ctx, _h2d(h)); -} - char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h); -char *_adapter_debug_ctx_Bytes_AsString(HPyContext ctx, HPy h) -{ - return debug_ctx_Bytes_AsString(ctx, _h2d(h)); -} - char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h); -char *_adapter_debug_ctx_Bytes_AS_STRING(HPyContext ctx, HPy h) -{ - return debug_ctx_Bytes_AS_STRING(ctx, _h2d(h)); -} - DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v); -HPy _adapter_debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) -{ - return _d2h(debug_ctx_Bytes_FromString(ctx, v)); -} - DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len); -HPy _adapter_debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) -{ - return _d2h(debug_ctx_Bytes_FromStringAndSize(ctx, v, len)); -} - DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8); -HPy _adapter_debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) -{ - return _d2h(debug_ctx_Unicode_FromString(ctx, utf8)); -} - int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_Unicode_Check(HPyContext ctx, HPy h) -{ - return debug_ctx_Unicode_Check(ctx, _h2d(h)); -} - DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h); -HPy _adapter_debug_ctx_Unicode_AsUTF8String(HPyContext ctx, HPy h) -{ - return _d2h(debug_ctx_Unicode_AsUTF8String(ctx, _h2d(h))); -} - DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size); -HPy _adapter_debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) -{ - return _d2h(debug_ctx_Unicode_FromWideChar(ctx, w, size)); -} - int debug_ctx_List_Check(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_List_Check(HPyContext ctx, HPy h) -{ - return debug_ctx_List_Check(ctx, _h2d(h)); -} - DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len); -HPy _adapter_debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) -{ - return _d2h(debug_ctx_List_New(ctx, len)); -} - int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item); -int _adapter_debug_ctx_List_Append(HPyContext ctx, HPy h_list, HPy h_item) -{ - return debug_ctx_List_Append(ctx, _h2d(h_list), _h2d(h_item)); -} - int debug_ctx_Dict_Check(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_Dict_Check(HPyContext ctx, HPy h) -{ - return debug_ctx_Dict_Check(ctx, _h2d(h)); -} - DHPy debug_ctx_Dict_New(HPyContext ctx); -HPy _adapter_debug_ctx_Dict_New(HPyContext ctx) -{ - return _d2h(debug_ctx_Dict_New(ctx)); -} - int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h); -int _adapter_debug_ctx_Tuple_Check(HPyContext ctx, HPy h) -{ - return debug_ctx_Tuple_Check(ctx, _h2d(h)); -} - DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n); -HPy _adapter_debug_ctx_Tuple_FromArray(HPyContext ctx, HPy items[], HPy_ssize_t n) -{ - return _d2h(debug_ctx_Tuple_FromArray(ctx, (DHPy *)items, n)); -} - DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj); -HPy _adapter_debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) -{ - return _d2h(debug_ctx_FromPyObject(ctx, obj)); -} - cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h); -cpy_PyObject *_adapter_debug_ctx_AsPyObject(HPyContext ctx, HPy h) -{ - return debug_ctx_AsPyObject(ctx, _h2d(h)); -} - void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args); -void _adapter_debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args) -{ - debug_ctx_CallRealFunctionFromTrampoline(ctx, sig, func, args); -} - void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self); -void _adapter_debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self) -{ - debug_ctx_CallDestroyAndThenDealloc(ctx, func, self); -} - HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -HPyListBuilder _adapter_debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) -{ - return debug_ctx_ListBuilder_New(ctx, initial_size); -} - void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item); -void _adapter_debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, HPy h_item) -{ - debug_ctx_ListBuilder_Set(ctx, builder, index, _h2d(h_item)); -} - DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder); -HPy _adapter_debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) -{ - return _d2h(debug_ctx_ListBuilder_Build(ctx, builder)); -} - void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder); -void _adapter_debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder) -{ - debug_ctx_ListBuilder_Cancel(ctx, builder); -} - HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -HPyTupleBuilder _adapter_debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) -{ - return debug_ctx_TupleBuilder_New(ctx, initial_size); -} - void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item); -void _adapter_debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, HPy h_item) -{ - debug_ctx_TupleBuilder_Set(ctx, builder, index, _h2d(h_item)); -} - DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder); -HPy _adapter_debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) -{ - return _d2h(debug_ctx_TupleBuilder_Build(ctx, builder)); -} - void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder); -void _adapter_debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder) -{ - debug_ctx_TupleBuilder_Cancel(ctx, builder); -} - HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size); -HPyTracker _adapter_debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size) -{ - return debug_ctx_Tracker_New(ctx, size); -} - int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h); -int _adapter_debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, HPy h) -{ - return debug_ctx_Tracker_Add(ctx, ht, _h2d(h)); -} - void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht); -void _adapter_debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht) -{ - debug_ctx_Tracker_ForgetAll(ctx, ht); -} - void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht); -void _adapter_debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) -{ - debug_ctx_Tracker_Close(ctx, ht); -} - void debug_ctx_Dump(HPyContext ctx, DHPy h); -void _adapter_debug_ctx_Dump(HPyContext ctx, HPy h) -{ - debug_ctx_Dump(ctx, _h2d(h)); -} static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext original_ctx) { - ctx->h_None = _d2h(DHPy_new(ctx, original_ctx->h_None)); - ctx->h_True = _d2h(DHPy_new(ctx, original_ctx->h_True)); - ctx->h_False = _d2h(DHPy_new(ctx, original_ctx->h_False)); - ctx->h_BaseException = _d2h(DHPy_new(ctx, original_ctx->h_BaseException)); - ctx->h_Exception = _d2h(DHPy_new(ctx, original_ctx->h_Exception)); - ctx->h_StopAsyncIteration = _d2h(DHPy_new(ctx, original_ctx->h_StopAsyncIteration)); - ctx->h_StopIteration = _d2h(DHPy_new(ctx, original_ctx->h_StopIteration)); - ctx->h_GeneratorExit = _d2h(DHPy_new(ctx, original_ctx->h_GeneratorExit)); - ctx->h_ArithmeticError = _d2h(DHPy_new(ctx, original_ctx->h_ArithmeticError)); - ctx->h_LookupError = _d2h(DHPy_new(ctx, original_ctx->h_LookupError)); - ctx->h_AssertionError = _d2h(DHPy_new(ctx, original_ctx->h_AssertionError)); - ctx->h_AttributeError = _d2h(DHPy_new(ctx, original_ctx->h_AttributeError)); - ctx->h_BufferError = _d2h(DHPy_new(ctx, original_ctx->h_BufferError)); - ctx->h_EOFError = _d2h(DHPy_new(ctx, original_ctx->h_EOFError)); - ctx->h_FloatingPointError = _d2h(DHPy_new(ctx, original_ctx->h_FloatingPointError)); - ctx->h_OSError = _d2h(DHPy_new(ctx, original_ctx->h_OSError)); - ctx->h_ImportError = _d2h(DHPy_new(ctx, original_ctx->h_ImportError)); - ctx->h_ModuleNotFoundError = _d2h(DHPy_new(ctx, original_ctx->h_ModuleNotFoundError)); - ctx->h_IndexError = _d2h(DHPy_new(ctx, original_ctx->h_IndexError)); - ctx->h_KeyError = _d2h(DHPy_new(ctx, original_ctx->h_KeyError)); - ctx->h_KeyboardInterrupt = _d2h(DHPy_new(ctx, original_ctx->h_KeyboardInterrupt)); - ctx->h_MemoryError = _d2h(DHPy_new(ctx, original_ctx->h_MemoryError)); - ctx->h_NameError = _d2h(DHPy_new(ctx, original_ctx->h_NameError)); - ctx->h_OverflowError = _d2h(DHPy_new(ctx, original_ctx->h_OverflowError)); - ctx->h_RuntimeError = _d2h(DHPy_new(ctx, original_ctx->h_RuntimeError)); - ctx->h_RecursionError = _d2h(DHPy_new(ctx, original_ctx->h_RecursionError)); - ctx->h_NotImplementedError = _d2h(DHPy_new(ctx, original_ctx->h_NotImplementedError)); - ctx->h_SyntaxError = _d2h(DHPy_new(ctx, original_ctx->h_SyntaxError)); - ctx->h_IndentationError = _d2h(DHPy_new(ctx, original_ctx->h_IndentationError)); - ctx->h_TabError = _d2h(DHPy_new(ctx, original_ctx->h_TabError)); - ctx->h_ReferenceError = _d2h(DHPy_new(ctx, original_ctx->h_ReferenceError)); - ctx->h_SystemError = _d2h(DHPy_new(ctx, original_ctx->h_SystemError)); - ctx->h_SystemExit = _d2h(DHPy_new(ctx, original_ctx->h_SystemExit)); - ctx->h_TypeError = _d2h(DHPy_new(ctx, original_ctx->h_TypeError)); - ctx->h_UnboundLocalError = _d2h(DHPy_new(ctx, original_ctx->h_UnboundLocalError)); - ctx->h_UnicodeError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeError)); - ctx->h_UnicodeEncodeError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeEncodeError)); - ctx->h_UnicodeDecodeError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeDecodeError)); - ctx->h_UnicodeTranslateError = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeTranslateError)); - ctx->h_ValueError = _d2h(DHPy_new(ctx, original_ctx->h_ValueError)); - ctx->h_ZeroDivisionError = _d2h(DHPy_new(ctx, original_ctx->h_ZeroDivisionError)); - ctx->h_BlockingIOError = _d2h(DHPy_new(ctx, original_ctx->h_BlockingIOError)); - ctx->h_BrokenPipeError = _d2h(DHPy_new(ctx, original_ctx->h_BrokenPipeError)); - ctx->h_ChildProcessError = _d2h(DHPy_new(ctx, original_ctx->h_ChildProcessError)); - ctx->h_ConnectionError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionError)); - ctx->h_ConnectionAbortedError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionAbortedError)); - ctx->h_ConnectionRefusedError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionRefusedError)); - ctx->h_ConnectionResetError = _d2h(DHPy_new(ctx, original_ctx->h_ConnectionResetError)); - ctx->h_FileExistsError = _d2h(DHPy_new(ctx, original_ctx->h_FileExistsError)); - ctx->h_FileNotFoundError = _d2h(DHPy_new(ctx, original_ctx->h_FileNotFoundError)); - ctx->h_InterruptedError = _d2h(DHPy_new(ctx, original_ctx->h_InterruptedError)); - ctx->h_IsADirectoryError = _d2h(DHPy_new(ctx, original_ctx->h_IsADirectoryError)); - ctx->h_NotADirectoryError = _d2h(DHPy_new(ctx, original_ctx->h_NotADirectoryError)); - ctx->h_PermissionError = _d2h(DHPy_new(ctx, original_ctx->h_PermissionError)); - ctx->h_ProcessLookupError = _d2h(DHPy_new(ctx, original_ctx->h_ProcessLookupError)); - ctx->h_TimeoutError = _d2h(DHPy_new(ctx, original_ctx->h_TimeoutError)); - ctx->h_Warning = _d2h(DHPy_new(ctx, original_ctx->h_Warning)); - ctx->h_UserWarning = _d2h(DHPy_new(ctx, original_ctx->h_UserWarning)); - ctx->h_DeprecationWarning = _d2h(DHPy_new(ctx, original_ctx->h_DeprecationWarning)); - ctx->h_PendingDeprecationWarning = _d2h(DHPy_new(ctx, original_ctx->h_PendingDeprecationWarning)); - ctx->h_SyntaxWarning = _d2h(DHPy_new(ctx, original_ctx->h_SyntaxWarning)); - ctx->h_RuntimeWarning = _d2h(DHPy_new(ctx, original_ctx->h_RuntimeWarning)); - ctx->h_FutureWarning = _d2h(DHPy_new(ctx, original_ctx->h_FutureWarning)); - ctx->h_ImportWarning = _d2h(DHPy_new(ctx, original_ctx->h_ImportWarning)); - ctx->h_UnicodeWarning = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeWarning)); - ctx->h_BytesWarning = _d2h(DHPy_new(ctx, original_ctx->h_BytesWarning)); - ctx->h_ResourceWarning = _d2h(DHPy_new(ctx, original_ctx->h_ResourceWarning)); - ctx->h_BaseObjectType = _d2h(DHPy_new(ctx, original_ctx->h_BaseObjectType)); - ctx->h_TypeType = _d2h(DHPy_new(ctx, original_ctx->h_TypeType)); - ctx->h_LongType = _d2h(DHPy_new(ctx, original_ctx->h_LongType)); - ctx->h_UnicodeType = _d2h(DHPy_new(ctx, original_ctx->h_UnicodeType)); - ctx->h_TupleType = _d2h(DHPy_new(ctx, original_ctx->h_TupleType)); - ctx->h_ListType = _d2h(DHPy_new(ctx, original_ctx->h_ListType)); + ctx->h_None = DHPy_wrap(ctx, original_ctx->h_None); + ctx->h_True = DHPy_wrap(ctx, original_ctx->h_True); + ctx->h_False = DHPy_wrap(ctx, original_ctx->h_False); + ctx->h_BaseException = DHPy_wrap(ctx, original_ctx->h_BaseException); + ctx->h_Exception = DHPy_wrap(ctx, original_ctx->h_Exception); + ctx->h_StopAsyncIteration = DHPy_wrap(ctx, original_ctx->h_StopAsyncIteration); + ctx->h_StopIteration = DHPy_wrap(ctx, original_ctx->h_StopIteration); + ctx->h_GeneratorExit = DHPy_wrap(ctx, original_ctx->h_GeneratorExit); + ctx->h_ArithmeticError = DHPy_wrap(ctx, original_ctx->h_ArithmeticError); + ctx->h_LookupError = DHPy_wrap(ctx, original_ctx->h_LookupError); + ctx->h_AssertionError = DHPy_wrap(ctx, original_ctx->h_AssertionError); + ctx->h_AttributeError = DHPy_wrap(ctx, original_ctx->h_AttributeError); + ctx->h_BufferError = DHPy_wrap(ctx, original_ctx->h_BufferError); + ctx->h_EOFError = DHPy_wrap(ctx, original_ctx->h_EOFError); + ctx->h_FloatingPointError = DHPy_wrap(ctx, original_ctx->h_FloatingPointError); + ctx->h_OSError = DHPy_wrap(ctx, original_ctx->h_OSError); + ctx->h_ImportError = DHPy_wrap(ctx, original_ctx->h_ImportError); + ctx->h_ModuleNotFoundError = DHPy_wrap(ctx, original_ctx->h_ModuleNotFoundError); + ctx->h_IndexError = DHPy_wrap(ctx, original_ctx->h_IndexError); + ctx->h_KeyError = DHPy_wrap(ctx, original_ctx->h_KeyError); + ctx->h_KeyboardInterrupt = DHPy_wrap(ctx, original_ctx->h_KeyboardInterrupt); + ctx->h_MemoryError = DHPy_wrap(ctx, original_ctx->h_MemoryError); + ctx->h_NameError = DHPy_wrap(ctx, original_ctx->h_NameError); + ctx->h_OverflowError = DHPy_wrap(ctx, original_ctx->h_OverflowError); + ctx->h_RuntimeError = DHPy_wrap(ctx, original_ctx->h_RuntimeError); + ctx->h_RecursionError = DHPy_wrap(ctx, original_ctx->h_RecursionError); + ctx->h_NotImplementedError = DHPy_wrap(ctx, original_ctx->h_NotImplementedError); + ctx->h_SyntaxError = DHPy_wrap(ctx, original_ctx->h_SyntaxError); + ctx->h_IndentationError = DHPy_wrap(ctx, original_ctx->h_IndentationError); + ctx->h_TabError = DHPy_wrap(ctx, original_ctx->h_TabError); + ctx->h_ReferenceError = DHPy_wrap(ctx, original_ctx->h_ReferenceError); + ctx->h_SystemError = DHPy_wrap(ctx, original_ctx->h_SystemError); + ctx->h_SystemExit = DHPy_wrap(ctx, original_ctx->h_SystemExit); + ctx->h_TypeError = DHPy_wrap(ctx, original_ctx->h_TypeError); + ctx->h_UnboundLocalError = DHPy_wrap(ctx, original_ctx->h_UnboundLocalError); + ctx->h_UnicodeError = DHPy_wrap(ctx, original_ctx->h_UnicodeError); + ctx->h_UnicodeEncodeError = DHPy_wrap(ctx, original_ctx->h_UnicodeEncodeError); + ctx->h_UnicodeDecodeError = DHPy_wrap(ctx, original_ctx->h_UnicodeDecodeError); + ctx->h_UnicodeTranslateError = DHPy_wrap(ctx, original_ctx->h_UnicodeTranslateError); + ctx->h_ValueError = DHPy_wrap(ctx, original_ctx->h_ValueError); + ctx->h_ZeroDivisionError = DHPy_wrap(ctx, original_ctx->h_ZeroDivisionError); + ctx->h_BlockingIOError = DHPy_wrap(ctx, original_ctx->h_BlockingIOError); + ctx->h_BrokenPipeError = DHPy_wrap(ctx, original_ctx->h_BrokenPipeError); + ctx->h_ChildProcessError = DHPy_wrap(ctx, original_ctx->h_ChildProcessError); + ctx->h_ConnectionError = DHPy_wrap(ctx, original_ctx->h_ConnectionError); + ctx->h_ConnectionAbortedError = DHPy_wrap(ctx, original_ctx->h_ConnectionAbortedError); + ctx->h_ConnectionRefusedError = DHPy_wrap(ctx, original_ctx->h_ConnectionRefusedError); + ctx->h_ConnectionResetError = DHPy_wrap(ctx, original_ctx->h_ConnectionResetError); + ctx->h_FileExistsError = DHPy_wrap(ctx, original_ctx->h_FileExistsError); + ctx->h_FileNotFoundError = DHPy_wrap(ctx, original_ctx->h_FileNotFoundError); + ctx->h_InterruptedError = DHPy_wrap(ctx, original_ctx->h_InterruptedError); + ctx->h_IsADirectoryError = DHPy_wrap(ctx, original_ctx->h_IsADirectoryError); + ctx->h_NotADirectoryError = DHPy_wrap(ctx, original_ctx->h_NotADirectoryError); + ctx->h_PermissionError = DHPy_wrap(ctx, original_ctx->h_PermissionError); + ctx->h_ProcessLookupError = DHPy_wrap(ctx, original_ctx->h_ProcessLookupError); + ctx->h_TimeoutError = DHPy_wrap(ctx, original_ctx->h_TimeoutError); + ctx->h_Warning = DHPy_wrap(ctx, original_ctx->h_Warning); + ctx->h_UserWarning = DHPy_wrap(ctx, original_ctx->h_UserWarning); + ctx->h_DeprecationWarning = DHPy_wrap(ctx, original_ctx->h_DeprecationWarning); + ctx->h_PendingDeprecationWarning = DHPy_wrap(ctx, original_ctx->h_PendingDeprecationWarning); + ctx->h_SyntaxWarning = DHPy_wrap(ctx, original_ctx->h_SyntaxWarning); + ctx->h_RuntimeWarning = DHPy_wrap(ctx, original_ctx->h_RuntimeWarning); + ctx->h_FutureWarning = DHPy_wrap(ctx, original_ctx->h_FutureWarning); + ctx->h_ImportWarning = DHPy_wrap(ctx, original_ctx->h_ImportWarning); + ctx->h_UnicodeWarning = DHPy_wrap(ctx, original_ctx->h_UnicodeWarning); + ctx->h_BytesWarning = DHPy_wrap(ctx, original_ctx->h_BytesWarning); + ctx->h_ResourceWarning = DHPy_wrap(ctx, original_ctx->h_ResourceWarning); + ctx->h_BaseObjectType = DHPy_wrap(ctx, original_ctx->h_BaseObjectType); + ctx->h_TypeType = DHPy_wrap(ctx, original_ctx->h_TypeType); + ctx->h_LongType = DHPy_wrap(ctx, original_ctx->h_LongType); + ctx->h_UnicodeType = DHPy_wrap(ctx, original_ctx->h_UnicodeType); + ctx->h_TupleType = DHPy_wrap(ctx, original_ctx->h_TupleType); + ctx->h_ListType = DHPy_wrap(ctx, original_ctx->h_ListType); } static struct _HPyContext_s g_debug_ctx = { @@ -910,126 +287,126 @@ static struct _HPyContext_s g_debug_ctx = { .h_UnicodeType = HPy_NULL, .h_TupleType = HPy_NULL, .h_ListType = HPy_NULL, - .ctx_Module_Create = &_adapter_debug_ctx_Module_Create, - .ctx_Dup = &_adapter_debug_ctx_Dup, - .ctx_Close = &_adapter_debug_ctx_Close, - .ctx_Long_FromLong = &_adapter_debug_ctx_Long_FromLong, - .ctx_Long_FromUnsignedLong = &_adapter_debug_ctx_Long_FromUnsignedLong, - .ctx_Long_FromLongLong = &_adapter_debug_ctx_Long_FromLongLong, - .ctx_Long_FromUnsignedLongLong = &_adapter_debug_ctx_Long_FromUnsignedLongLong, - .ctx_Long_FromSize_t = &_adapter_debug_ctx_Long_FromSize_t, - .ctx_Long_FromSsize_t = &_adapter_debug_ctx_Long_FromSsize_t, - .ctx_Long_AsLong = &_adapter_debug_ctx_Long_AsLong, - .ctx_Long_AsUnsignedLong = &_adapter_debug_ctx_Long_AsUnsignedLong, - .ctx_Long_AsUnsignedLongMask = &_adapter_debug_ctx_Long_AsUnsignedLongMask, - .ctx_Long_AsLongLong = &_adapter_debug_ctx_Long_AsLongLong, - .ctx_Long_AsUnsignedLongLong = &_adapter_debug_ctx_Long_AsUnsignedLongLong, - .ctx_Long_AsUnsignedLongLongMask = &_adapter_debug_ctx_Long_AsUnsignedLongLongMask, - .ctx_Long_AsSize_t = &_adapter_debug_ctx_Long_AsSize_t, - .ctx_Long_AsSsize_t = &_adapter_debug_ctx_Long_AsSsize_t, - .ctx_Float_FromDouble = &_adapter_debug_ctx_Float_FromDouble, - .ctx_Float_AsDouble = &_adapter_debug_ctx_Float_AsDouble, - .ctx_Length = &_adapter_debug_ctx_Length, - .ctx_Number_Check = &_adapter_debug_ctx_Number_Check, - .ctx_Add = &_adapter_debug_ctx_Add, - .ctx_Subtract = &_adapter_debug_ctx_Subtract, - .ctx_Multiply = &_adapter_debug_ctx_Multiply, - .ctx_MatrixMultiply = &_adapter_debug_ctx_MatrixMultiply, - .ctx_FloorDivide = &_adapter_debug_ctx_FloorDivide, - .ctx_TrueDivide = &_adapter_debug_ctx_TrueDivide, - .ctx_Remainder = &_adapter_debug_ctx_Remainder, - .ctx_Divmod = &_adapter_debug_ctx_Divmod, - .ctx_Power = &_adapter_debug_ctx_Power, - .ctx_Negative = &_adapter_debug_ctx_Negative, - .ctx_Positive = &_adapter_debug_ctx_Positive, - .ctx_Absolute = &_adapter_debug_ctx_Absolute, - .ctx_Invert = &_adapter_debug_ctx_Invert, - .ctx_Lshift = &_adapter_debug_ctx_Lshift, - .ctx_Rshift = &_adapter_debug_ctx_Rshift, - .ctx_And = &_adapter_debug_ctx_And, - .ctx_Xor = &_adapter_debug_ctx_Xor, - .ctx_Or = &_adapter_debug_ctx_Or, - .ctx_Index = &_adapter_debug_ctx_Index, - .ctx_Long = &_adapter_debug_ctx_Long, - .ctx_Float = &_adapter_debug_ctx_Float, - .ctx_InPlaceAdd = &_adapter_debug_ctx_InPlaceAdd, - .ctx_InPlaceSubtract = &_adapter_debug_ctx_InPlaceSubtract, - .ctx_InPlaceMultiply = &_adapter_debug_ctx_InPlaceMultiply, - .ctx_InPlaceMatrixMultiply = &_adapter_debug_ctx_InPlaceMatrixMultiply, - .ctx_InPlaceFloorDivide = &_adapter_debug_ctx_InPlaceFloorDivide, - .ctx_InPlaceTrueDivide = &_adapter_debug_ctx_InPlaceTrueDivide, - .ctx_InPlaceRemainder = &_adapter_debug_ctx_InPlaceRemainder, - .ctx_InPlacePower = &_adapter_debug_ctx_InPlacePower, - .ctx_InPlaceLshift = &_adapter_debug_ctx_InPlaceLshift, - .ctx_InPlaceRshift = &_adapter_debug_ctx_InPlaceRshift, - .ctx_InPlaceAnd = &_adapter_debug_ctx_InPlaceAnd, - .ctx_InPlaceXor = &_adapter_debug_ctx_InPlaceXor, - .ctx_InPlaceOr = &_adapter_debug_ctx_InPlaceOr, - .ctx_Callable_Check = &_adapter_debug_ctx_Callable_Check, - .ctx_CallTupleDict = &_adapter_debug_ctx_CallTupleDict, - .ctx_FatalError = &_adapter_debug_ctx_FatalError, - .ctx_Err_SetString = &_adapter_debug_ctx_Err_SetString, - .ctx_Err_SetObject = &_adapter_debug_ctx_Err_SetObject, - .ctx_Err_Occurred = &_adapter_debug_ctx_Err_Occurred, - .ctx_Err_NoMemory = &_adapter_debug_ctx_Err_NoMemory, - .ctx_Err_Clear = &_adapter_debug_ctx_Err_Clear, - .ctx_IsTrue = &_adapter_debug_ctx_IsTrue, - .ctx_Type_FromSpec = &_adapter_debug_ctx_Type_FromSpec, - .ctx_Type_GenericNew = &_adapter_debug_ctx_Type_GenericNew, - .ctx_GetAttr = &_adapter_debug_ctx_GetAttr, - .ctx_GetAttr_s = &_adapter_debug_ctx_GetAttr_s, - .ctx_HasAttr = &_adapter_debug_ctx_HasAttr, - .ctx_HasAttr_s = &_adapter_debug_ctx_HasAttr_s, - .ctx_SetAttr = &_adapter_debug_ctx_SetAttr, - .ctx_SetAttr_s = &_adapter_debug_ctx_SetAttr_s, - .ctx_GetItem = &_adapter_debug_ctx_GetItem, - .ctx_GetItem_i = &_adapter_debug_ctx_GetItem_i, - .ctx_GetItem_s = &_adapter_debug_ctx_GetItem_s, - .ctx_SetItem = &_adapter_debug_ctx_SetItem, - .ctx_SetItem_i = &_adapter_debug_ctx_SetItem_i, - .ctx_SetItem_s = &_adapter_debug_ctx_SetItem_s, - .ctx_Cast = &_adapter_debug_ctx_Cast, - .ctx_New = &_adapter_debug_ctx_New, - .ctx_Repr = &_adapter_debug_ctx_Repr, - .ctx_Str = &_adapter_debug_ctx_Str, - .ctx_ASCII = &_adapter_debug_ctx_ASCII, - .ctx_Bytes = &_adapter_debug_ctx_Bytes, - .ctx_RichCompare = &_adapter_debug_ctx_RichCompare, - .ctx_RichCompareBool = &_adapter_debug_ctx_RichCompareBool, - .ctx_Hash = &_adapter_debug_ctx_Hash, - .ctx_Bytes_Check = &_adapter_debug_ctx_Bytes_Check, - .ctx_Bytes_Size = &_adapter_debug_ctx_Bytes_Size, - .ctx_Bytes_GET_SIZE = &_adapter_debug_ctx_Bytes_GET_SIZE, - .ctx_Bytes_AsString = &_adapter_debug_ctx_Bytes_AsString, - .ctx_Bytes_AS_STRING = &_adapter_debug_ctx_Bytes_AS_STRING, - .ctx_Bytes_FromString = &_adapter_debug_ctx_Bytes_FromString, - .ctx_Bytes_FromStringAndSize = &_adapter_debug_ctx_Bytes_FromStringAndSize, - .ctx_Unicode_FromString = &_adapter_debug_ctx_Unicode_FromString, - .ctx_Unicode_Check = &_adapter_debug_ctx_Unicode_Check, - .ctx_Unicode_AsUTF8String = &_adapter_debug_ctx_Unicode_AsUTF8String, - .ctx_Unicode_FromWideChar = &_adapter_debug_ctx_Unicode_FromWideChar, - .ctx_List_Check = &_adapter_debug_ctx_List_Check, - .ctx_List_New = &_adapter_debug_ctx_List_New, - .ctx_List_Append = &_adapter_debug_ctx_List_Append, - .ctx_Dict_Check = &_adapter_debug_ctx_Dict_Check, - .ctx_Dict_New = &_adapter_debug_ctx_Dict_New, - .ctx_Tuple_Check = &_adapter_debug_ctx_Tuple_Check, - .ctx_Tuple_FromArray = &_adapter_debug_ctx_Tuple_FromArray, - .ctx_FromPyObject = &_adapter_debug_ctx_FromPyObject, - .ctx_AsPyObject = &_adapter_debug_ctx_AsPyObject, - .ctx_CallRealFunctionFromTrampoline = &_adapter_debug_ctx_CallRealFunctionFromTrampoline, - .ctx_CallDestroyAndThenDealloc = &_adapter_debug_ctx_CallDestroyAndThenDealloc, - .ctx_ListBuilder_New = &_adapter_debug_ctx_ListBuilder_New, - .ctx_ListBuilder_Set = &_adapter_debug_ctx_ListBuilder_Set, - .ctx_ListBuilder_Build = &_adapter_debug_ctx_ListBuilder_Build, - .ctx_ListBuilder_Cancel = &_adapter_debug_ctx_ListBuilder_Cancel, - .ctx_TupleBuilder_New = &_adapter_debug_ctx_TupleBuilder_New, - .ctx_TupleBuilder_Set = &_adapter_debug_ctx_TupleBuilder_Set, - .ctx_TupleBuilder_Build = &_adapter_debug_ctx_TupleBuilder_Build, - .ctx_TupleBuilder_Cancel = &_adapter_debug_ctx_TupleBuilder_Cancel, - .ctx_Tracker_New = &_adapter_debug_ctx_Tracker_New, - .ctx_Tracker_Add = &_adapter_debug_ctx_Tracker_Add, - .ctx_Tracker_ForgetAll = &_adapter_debug_ctx_Tracker_ForgetAll, - .ctx_Tracker_Close = &_adapter_debug_ctx_Tracker_Close, - .ctx_Dump = &_adapter_debug_ctx_Dump, + .ctx_Module_Create = &debug_ctx_Module_Create, + .ctx_Dup = &debug_ctx_Dup, + .ctx_Close = &debug_ctx_Close, + .ctx_Long_FromLong = &debug_ctx_Long_FromLong, + .ctx_Long_FromUnsignedLong = &debug_ctx_Long_FromUnsignedLong, + .ctx_Long_FromLongLong = &debug_ctx_Long_FromLongLong, + .ctx_Long_FromUnsignedLongLong = &debug_ctx_Long_FromUnsignedLongLong, + .ctx_Long_FromSize_t = &debug_ctx_Long_FromSize_t, + .ctx_Long_FromSsize_t = &debug_ctx_Long_FromSsize_t, + .ctx_Long_AsLong = &debug_ctx_Long_AsLong, + .ctx_Long_AsUnsignedLong = &debug_ctx_Long_AsUnsignedLong, + .ctx_Long_AsUnsignedLongMask = &debug_ctx_Long_AsUnsignedLongMask, + .ctx_Long_AsLongLong = &debug_ctx_Long_AsLongLong, + .ctx_Long_AsUnsignedLongLong = &debug_ctx_Long_AsUnsignedLongLong, + .ctx_Long_AsUnsignedLongLongMask = &debug_ctx_Long_AsUnsignedLongLongMask, + .ctx_Long_AsSize_t = &debug_ctx_Long_AsSize_t, + .ctx_Long_AsSsize_t = &debug_ctx_Long_AsSsize_t, + .ctx_Float_FromDouble = &debug_ctx_Float_FromDouble, + .ctx_Float_AsDouble = &debug_ctx_Float_AsDouble, + .ctx_Length = &debug_ctx_Length, + .ctx_Number_Check = &debug_ctx_Number_Check, + .ctx_Add = &debug_ctx_Add, + .ctx_Subtract = &debug_ctx_Subtract, + .ctx_Multiply = &debug_ctx_Multiply, + .ctx_MatrixMultiply = &debug_ctx_MatrixMultiply, + .ctx_FloorDivide = &debug_ctx_FloorDivide, + .ctx_TrueDivide = &debug_ctx_TrueDivide, + .ctx_Remainder = &debug_ctx_Remainder, + .ctx_Divmod = &debug_ctx_Divmod, + .ctx_Power = &debug_ctx_Power, + .ctx_Negative = &debug_ctx_Negative, + .ctx_Positive = &debug_ctx_Positive, + .ctx_Absolute = &debug_ctx_Absolute, + .ctx_Invert = &debug_ctx_Invert, + .ctx_Lshift = &debug_ctx_Lshift, + .ctx_Rshift = &debug_ctx_Rshift, + .ctx_And = &debug_ctx_And, + .ctx_Xor = &debug_ctx_Xor, + .ctx_Or = &debug_ctx_Or, + .ctx_Index = &debug_ctx_Index, + .ctx_Long = &debug_ctx_Long, + .ctx_Float = &debug_ctx_Float, + .ctx_InPlaceAdd = &debug_ctx_InPlaceAdd, + .ctx_InPlaceSubtract = &debug_ctx_InPlaceSubtract, + .ctx_InPlaceMultiply = &debug_ctx_InPlaceMultiply, + .ctx_InPlaceMatrixMultiply = &debug_ctx_InPlaceMatrixMultiply, + .ctx_InPlaceFloorDivide = &debug_ctx_InPlaceFloorDivide, + .ctx_InPlaceTrueDivide = &debug_ctx_InPlaceTrueDivide, + .ctx_InPlaceRemainder = &debug_ctx_InPlaceRemainder, + .ctx_InPlacePower = &debug_ctx_InPlacePower, + .ctx_InPlaceLshift = &debug_ctx_InPlaceLshift, + .ctx_InPlaceRshift = &debug_ctx_InPlaceRshift, + .ctx_InPlaceAnd = &debug_ctx_InPlaceAnd, + .ctx_InPlaceXor = &debug_ctx_InPlaceXor, + .ctx_InPlaceOr = &debug_ctx_InPlaceOr, + .ctx_Callable_Check = &debug_ctx_Callable_Check, + .ctx_CallTupleDict = &debug_ctx_CallTupleDict, + .ctx_FatalError = &debug_ctx_FatalError, + .ctx_Err_SetString = &debug_ctx_Err_SetString, + .ctx_Err_SetObject = &debug_ctx_Err_SetObject, + .ctx_Err_Occurred = &debug_ctx_Err_Occurred, + .ctx_Err_NoMemory = &debug_ctx_Err_NoMemory, + .ctx_Err_Clear = &debug_ctx_Err_Clear, + .ctx_IsTrue = &debug_ctx_IsTrue, + .ctx_Type_FromSpec = &debug_ctx_Type_FromSpec, + .ctx_Type_GenericNew = &debug_ctx_Type_GenericNew, + .ctx_GetAttr = &debug_ctx_GetAttr, + .ctx_GetAttr_s = &debug_ctx_GetAttr_s, + .ctx_HasAttr = &debug_ctx_HasAttr, + .ctx_HasAttr_s = &debug_ctx_HasAttr_s, + .ctx_SetAttr = &debug_ctx_SetAttr, + .ctx_SetAttr_s = &debug_ctx_SetAttr_s, + .ctx_GetItem = &debug_ctx_GetItem, + .ctx_GetItem_i = &debug_ctx_GetItem_i, + .ctx_GetItem_s = &debug_ctx_GetItem_s, + .ctx_SetItem = &debug_ctx_SetItem, + .ctx_SetItem_i = &debug_ctx_SetItem_i, + .ctx_SetItem_s = &debug_ctx_SetItem_s, + .ctx_Cast = &debug_ctx_Cast, + .ctx_New = &debug_ctx_New, + .ctx_Repr = &debug_ctx_Repr, + .ctx_Str = &debug_ctx_Str, + .ctx_ASCII = &debug_ctx_ASCII, + .ctx_Bytes = &debug_ctx_Bytes, + .ctx_RichCompare = &debug_ctx_RichCompare, + .ctx_RichCompareBool = &debug_ctx_RichCompareBool, + .ctx_Hash = &debug_ctx_Hash, + .ctx_Bytes_Check = &debug_ctx_Bytes_Check, + .ctx_Bytes_Size = &debug_ctx_Bytes_Size, + .ctx_Bytes_GET_SIZE = &debug_ctx_Bytes_GET_SIZE, + .ctx_Bytes_AsString = &debug_ctx_Bytes_AsString, + .ctx_Bytes_AS_STRING = &debug_ctx_Bytes_AS_STRING, + .ctx_Bytes_FromString = &debug_ctx_Bytes_FromString, + .ctx_Bytes_FromStringAndSize = &debug_ctx_Bytes_FromStringAndSize, + .ctx_Unicode_FromString = &debug_ctx_Unicode_FromString, + .ctx_Unicode_Check = &debug_ctx_Unicode_Check, + .ctx_Unicode_AsUTF8String = &debug_ctx_Unicode_AsUTF8String, + .ctx_Unicode_FromWideChar = &debug_ctx_Unicode_FromWideChar, + .ctx_List_Check = &debug_ctx_List_Check, + .ctx_List_New = &debug_ctx_List_New, + .ctx_List_Append = &debug_ctx_List_Append, + .ctx_Dict_Check = &debug_ctx_Dict_Check, + .ctx_Dict_New = &debug_ctx_Dict_New, + .ctx_Tuple_Check = &debug_ctx_Tuple_Check, + .ctx_Tuple_FromArray = &debug_ctx_Tuple_FromArray, + .ctx_FromPyObject = &debug_ctx_FromPyObject, + .ctx_AsPyObject = &debug_ctx_AsPyObject, + .ctx_CallRealFunctionFromTrampoline = &debug_ctx_CallRealFunctionFromTrampoline, + .ctx_CallDestroyAndThenDealloc = &debug_ctx_CallDestroyAndThenDealloc, + .ctx_ListBuilder_New = &debug_ctx_ListBuilder_New, + .ctx_ListBuilder_Set = &debug_ctx_ListBuilder_Set, + .ctx_ListBuilder_Build = &debug_ctx_ListBuilder_Build, + .ctx_ListBuilder_Cancel = &debug_ctx_ListBuilder_Cancel, + .ctx_TupleBuilder_New = &debug_ctx_TupleBuilder_New, + .ctx_TupleBuilder_Set = &debug_ctx_TupleBuilder_Set, + .ctx_TupleBuilder_Build = &debug_ctx_TupleBuilder_Build, + .ctx_TupleBuilder_Cancel = &debug_ctx_TupleBuilder_Cancel, + .ctx_Tracker_New = &debug_ctx_Tracker_New, + .ctx_Tracker_Add = &debug_ctx_Tracker_Add, + .ctx_Tracker_ForgetAll = &debug_ctx_Tracker_ForgetAll, + .ctx_Tracker_Close = &debug_ctx_Tracker_Close, + .ctx_Dump = &debug_ctx_Dump, }; diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index 113f0928e..a95cd7c41 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -14,287 +14,287 @@ DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) { - return _h2d(HPyModule_Create(get_info(ctx)->original_ctx, def)); + return DHPy_wrap(ctx, HPyModule_Create(get_info(ctx)->original_ctx, def)); } DHPy debug_ctx_Dup(HPyContext ctx, DHPy h) { - return _h2d(HPy_Dup(get_info(ctx)->original_ctx, h->h)); + return DHPy_wrap(ctx, HPy_Dup(get_info(ctx)->original_ctx, DHPy_unwrap(h))); } void debug_ctx_Close(HPyContext ctx, DHPy h) { - HPy_Close(get_info(ctx)->original_ctx, h->h); + HPy_Close(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value) { - return _h2d(HPyLong_FromLong(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromLong(get_info(ctx)->original_ctx, value)); } DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) { - return _h2d(HPyLong_FromUnsignedLong(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromUnsignedLong(get_info(ctx)->original_ctx, value)); } DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) { - return _h2d(HPyLong_FromLongLong(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyLong_FromLongLong(get_info(ctx)->original_ctx, v)); } DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) { - return _h2d(HPyLong_FromUnsignedLongLong(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyLong_FromUnsignedLongLong(get_info(ctx)->original_ctx, v)); } DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) { - return _h2d(HPyLong_FromSize_t(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromSize_t(get_info(ctx)->original_ctx, value)); } DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) { - return _h2d(HPyLong_FromSsize_t(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromSsize_t(get_info(ctx)->original_ctx, value)); } long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h) { - return HPyLong_AsLong(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLong(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsUnsignedLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongMask(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsUnsignedLongMask(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h) { - return HPyLong_AsLongLong(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsLongLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongLong(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsUnsignedLongLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h) { - return HPyLong_AsSize_t(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsSize_t(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h) { - return HPyLong_AsSsize_t(get_info(ctx)->original_ctx, h->h); + return HPyLong_AsSsize_t(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v) { - return _h2d(HPyFloat_FromDouble(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyFloat_FromDouble(get_info(ctx)->original_ctx, v)); } double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h) { - return HPyFloat_AsDouble(get_info(ctx)->original_ctx, h->h); + return HPyFloat_AsDouble(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h) { - return HPy_Length(get_info(ctx)->original_ctx, h->h); + return HPy_Length(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } int debug_ctx_Number_Check(HPyContext ctx, DHPy h) { - return HPyNumber_Check(get_info(ctx)->original_ctx, h->h); + return HPyNumber_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Add(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Add(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Subtract(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Subtract(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Multiply(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Multiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_MatrixMultiply(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_MatrixMultiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_FloorDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_FloorDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_TrueDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_TrueDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Remainder(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Remainder(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Divmod(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Divmod(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) { - return _h2d(HPy_Power(get_info(ctx)->original_ctx, h1->h, h2->h, h3->h)); + return DHPy_wrap(ctx, HPy_Power(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); } DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1) { - return _h2d(HPy_Negative(get_info(ctx)->original_ctx, h1->h)); + return DHPy_wrap(ctx, HPy_Negative(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1) { - return _h2d(HPy_Positive(get_info(ctx)->original_ctx, h1->h)); + return DHPy_wrap(ctx, HPy_Positive(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1) { - return _h2d(HPy_Absolute(get_info(ctx)->original_ctx, h1->h)); + return DHPy_wrap(ctx, HPy_Absolute(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1) { - return _h2d(HPy_Invert(get_info(ctx)->original_ctx, h1->h)); + return DHPy_wrap(ctx, HPy_Invert(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Lshift(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Lshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Rshift(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Rshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_And(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_And(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Xor(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Xor(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_Or(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_Or(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Index(HPyContext ctx, DHPy h1) { - return _h2d(HPy_Index(get_info(ctx)->original_ctx, h1->h)); + return DHPy_wrap(ctx, HPy_Index(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Long(HPyContext ctx, DHPy h1) { - return _h2d(HPy_Long(get_info(ctx)->original_ctx, h1->h)); + return DHPy_wrap(ctx, HPy_Long(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Float(HPyContext ctx, DHPy h1) { - return _h2d(HPy_Float(get_info(ctx)->original_ctx, h1->h)); + return DHPy_wrap(ctx, HPy_Float(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); } DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceAdd(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceAdd(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceSubtract(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceSubtract(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceMultiply(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceMultiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceMatrixMultiply(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceMatrixMultiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceFloorDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceFloorDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceTrueDivide(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceTrueDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceRemainder(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceRemainder(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) { - return _h2d(HPy_InPlacePower(get_info(ctx)->original_ctx, h1->h, h2->h, h3->h)); + return DHPy_wrap(ctx, HPy_InPlacePower(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); } DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceLshift(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceLshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceRshift(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceRshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceAnd(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceAnd(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceXor(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceXor(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2) { - return _h2d(HPy_InPlaceOr(get_info(ctx)->original_ctx, h1->h, h2->h)); + return DHPy_wrap(ctx, HPy_InPlaceOr(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } int debug_ctx_Callable_Check(HPyContext ctx, DHPy h) { - return HPyCallable_Check(get_info(ctx)->original_ctx, h->h); + return HPyCallable_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw) { - return _h2d(HPy_CallTupleDict(get_info(ctx)->original_ctx, callable->h, args->h, kw->h)); + return DHPy_wrap(ctx, HPy_CallTupleDict(get_info(ctx)->original_ctx, DHPy_unwrap(callable), DHPy_unwrap(args), DHPy_unwrap(kw))); } void debug_ctx_FatalError(HPyContext ctx, const char *message) @@ -304,12 +304,12 @@ void debug_ctx_FatalError(HPyContext ctx, const char *message) void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message) { - HPyErr_SetString(get_info(ctx)->original_ctx, h_type->h, message); + HPyErr_SetString(get_info(ctx)->original_ctx, DHPy_unwrap(h_type), message); } void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value) { - HPyErr_SetObject(get_info(ctx)->original_ctx, h_type->h, h_value->h); + HPyErr_SetObject(get_info(ctx)->original_ctx, DHPy_unwrap(h_type), DHPy_unwrap(h_value)); } int debug_ctx_Err_Occurred(HPyContext ctx) @@ -319,7 +319,7 @@ int debug_ctx_Err_Occurred(HPyContext ctx) DHPy debug_ctx_Err_NoMemory(HPyContext ctx) { - return _h2d(HPyErr_NoMemory(get_info(ctx)->original_ctx)); + return DHPy_wrap(ctx, HPyErr_NoMemory(get_info(ctx)->original_ctx)); } void debug_ctx_Err_Clear(HPyContext ctx) @@ -329,222 +329,222 @@ void debug_ctx_Err_Clear(HPyContext ctx) int debug_ctx_IsTrue(HPyContext ctx, DHPy h) { - return HPy_IsTrue(get_info(ctx)->original_ctx, h->h); + return HPy_IsTrue(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) { - return _h2d(HPyType_FromSpec(get_info(ctx)->original_ctx, spec, params)); + return DHPy_wrap(ctx, HPyType_FromSpec(get_info(ctx)->original_ctx, spec, params)); } DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw) { - return _h2d(HPyType_GenericNew(get_info(ctx)->original_ctx, type->h, (HPy *)args, nargs, kw->h)); + return DHPy_wrap(ctx, HPyType_GenericNew(get_info(ctx)->original_ctx, DHPy_unwrap(type), NULL /* TODO */, nargs, DHPy_unwrap(kw))); } DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name) { - return _h2d(HPy_GetAttr(get_info(ctx)->original_ctx, obj->h, name->h)); + return DHPy_wrap(ctx, HPy_GetAttr(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(name))); } DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name) { - return _h2d(HPy_GetAttr_s(get_info(ctx)->original_ctx, obj->h, name)); + return DHPy_wrap(ctx, HPy_GetAttr_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), name)); } int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name) { - return HPy_HasAttr(get_info(ctx)->original_ctx, obj->h, name->h); + return HPy_HasAttr(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(name)); } int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name) { - return HPy_HasAttr_s(get_info(ctx)->original_ctx, obj->h, name); + return HPy_HasAttr_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), name); } int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value) { - return HPy_SetAttr(get_info(ctx)->original_ctx, obj->h, name->h, value->h); + return HPy_SetAttr(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(name), DHPy_unwrap(value)); } int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value) { - return HPy_SetAttr_s(get_info(ctx)->original_ctx, obj->h, name, value->h); + return HPy_SetAttr_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), name, DHPy_unwrap(value)); } DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key) { - return _h2d(HPy_GetItem(get_info(ctx)->original_ctx, obj->h, key->h)); + return DHPy_wrap(ctx, HPy_GetItem(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(key))); } DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx) { - return _h2d(HPy_GetItem_i(get_info(ctx)->original_ctx, obj->h, idx)); + return DHPy_wrap(ctx, HPy_GetItem_i(get_info(ctx)->original_ctx, DHPy_unwrap(obj), idx)); } DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key) { - return _h2d(HPy_GetItem_s(get_info(ctx)->original_ctx, obj->h, key)); + return DHPy_wrap(ctx, HPy_GetItem_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), key)); } int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value) { - return HPy_SetItem(get_info(ctx)->original_ctx, obj->h, key->h, value->h); + return HPy_SetItem(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(key), DHPy_unwrap(value)); } int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value) { - return HPy_SetItem_i(get_info(ctx)->original_ctx, obj->h, idx, value->h); + return HPy_SetItem_i(get_info(ctx)->original_ctx, DHPy_unwrap(obj), idx, DHPy_unwrap(value)); } int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value) { - return HPy_SetItem_s(get_info(ctx)->original_ctx, obj->h, key, value->h); + return HPy_SetItem_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), key, DHPy_unwrap(value)); } void *debug_ctx_Cast(HPyContext ctx, DHPy h) { - return _HPy_Cast(get_info(ctx)->original_ctx, h->h); + return _HPy_Cast(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data) { - return _h2d(_HPy_New(get_info(ctx)->original_ctx, h_type->h, data)); + return DHPy_wrap(ctx, _HPy_New(get_info(ctx)->original_ctx, DHPy_unwrap(h_type), data)); } DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj) { - return _h2d(HPy_Repr(get_info(ctx)->original_ctx, obj->h)); + return DHPy_wrap(ctx, HPy_Repr(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); } DHPy debug_ctx_Str(HPyContext ctx, DHPy obj) { - return _h2d(HPy_Str(get_info(ctx)->original_ctx, obj->h)); + return DHPy_wrap(ctx, HPy_Str(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); } DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj) { - return _h2d(HPy_ASCII(get_info(ctx)->original_ctx, obj->h)); + return DHPy_wrap(ctx, HPy_ASCII(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); } DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj) { - return _h2d(HPy_Bytes(get_info(ctx)->original_ctx, obj->h)); + return DHPy_wrap(ctx, HPy_Bytes(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); } DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op) { - return _h2d(HPy_RichCompare(get_info(ctx)->original_ctx, v->h, w->h, op)); + return DHPy_wrap(ctx, HPy_RichCompare(get_info(ctx)->original_ctx, DHPy_unwrap(v), DHPy_unwrap(w), op)); } int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op) { - return HPy_RichCompareBool(get_info(ctx)->original_ctx, v->h, w->h, op); + return HPy_RichCompareBool(get_info(ctx)->original_ctx, DHPy_unwrap(v), DHPy_unwrap(w), op); } HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj) { - return HPy_Hash(get_info(ctx)->original_ctx, obj->h); + return HPy_Hash(get_info(ctx)->original_ctx, DHPy_unwrap(obj)); } int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h) { - return HPyBytes_Check(get_info(ctx)->original_ctx, h->h); + return HPyBytes_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h) { - return HPyBytes_Size(get_info(ctx)->original_ctx, h->h); + return HPyBytes_Size(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h) { - return HPyBytes_GET_SIZE(get_info(ctx)->original_ctx, h->h); + return HPyBytes_GET_SIZE(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h) { - return HPyBytes_AsString(get_info(ctx)->original_ctx, h->h); + return HPyBytes_AsString(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h) { - return HPyBytes_AS_STRING(get_info(ctx)->original_ctx, h->h); + return HPyBytes_AS_STRING(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) { - return _h2d(HPyBytes_FromString(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyBytes_FromString(get_info(ctx)->original_ctx, v)); } DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) { - return _h2d(HPyBytes_FromStringAndSize(get_info(ctx)->original_ctx, v, len)); + return DHPy_wrap(ctx, HPyBytes_FromStringAndSize(get_info(ctx)->original_ctx, v, len)); } DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) { - return _h2d(HPyUnicode_FromString(get_info(ctx)->original_ctx, utf8)); + return DHPy_wrap(ctx, HPyUnicode_FromString(get_info(ctx)->original_ctx, utf8)); } int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h) { - return HPyUnicode_Check(get_info(ctx)->original_ctx, h->h); + return HPyUnicode_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h) { - return _h2d(HPyUnicode_AsUTF8String(get_info(ctx)->original_ctx, h->h)); + return DHPy_wrap(ctx, HPyUnicode_AsUTF8String(get_info(ctx)->original_ctx, DHPy_unwrap(h))); } DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) { - return _h2d(HPyUnicode_FromWideChar(get_info(ctx)->original_ctx, w, size)); + return DHPy_wrap(ctx, HPyUnicode_FromWideChar(get_info(ctx)->original_ctx, w, size)); } int debug_ctx_List_Check(HPyContext ctx, DHPy h) { - return HPyList_Check(get_info(ctx)->original_ctx, h->h); + return HPyList_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) { - return _h2d(HPyList_New(get_info(ctx)->original_ctx, len)); + return DHPy_wrap(ctx, HPyList_New(get_info(ctx)->original_ctx, len)); } int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item) { - return HPyList_Append(get_info(ctx)->original_ctx, h_list->h, h_item->h); + return HPyList_Append(get_info(ctx)->original_ctx, DHPy_unwrap(h_list), DHPy_unwrap(h_item)); } int debug_ctx_Dict_Check(HPyContext ctx, DHPy h) { - return HPyDict_Check(get_info(ctx)->original_ctx, h->h); + return HPyDict_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Dict_New(HPyContext ctx) { - return _h2d(HPyDict_New(get_info(ctx)->original_ctx)); + return DHPy_wrap(ctx, HPyDict_New(get_info(ctx)->original_ctx)); } int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h) { - return HPyTuple_Check(get_info(ctx)->original_ctx, h->h); + return HPyTuple_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n) { - return _h2d(HPyTuple_FromArray(get_info(ctx)->original_ctx, (HPy *)items, n)); + return DHPy_wrap(ctx, HPyTuple_FromArray(get_info(ctx)->original_ctx, NULL /* TODO */, n)); } DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) { - return _h2d(HPy_FromPyObject(get_info(ctx)->original_ctx, obj)); + return DHPy_wrap(ctx, HPy_FromPyObject(get_info(ctx)->original_ctx, obj)); } cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h) { - return HPy_AsPyObject(get_info(ctx)->original_ctx, h->h); + return HPy_AsPyObject(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self) @@ -559,12 +559,12 @@ HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_siz void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyListBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item->h); + HPyListBuilder_Set(get_info(ctx)->original_ctx, builder, index, DHPy_unwrap(h_item)); } DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) { - return _h2d(HPyListBuilder_Build(get_info(ctx)->original_ctx, builder)); + return DHPy_wrap(ctx, HPyListBuilder_Build(get_info(ctx)->original_ctx, builder)); } void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder) @@ -579,12 +579,12 @@ HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_s void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyTupleBuilder_Set(get_info(ctx)->original_ctx, builder, index, h_item->h); + HPyTupleBuilder_Set(get_info(ctx)->original_ctx, builder, index, DHPy_unwrap(h_item)); } DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) { - return _h2d(HPyTupleBuilder_Build(get_info(ctx)->original_ctx, builder)); + return DHPy_wrap(ctx, HPyTupleBuilder_Build(get_info(ctx)->original_ctx, builder)); } void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder) @@ -599,7 +599,7 @@ HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size) int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h) { - return HPyTracker_Add(get_info(ctx)->original_ctx, ht, h->h); + return HPyTracker_Add(get_info(ctx)->original_ctx, ht, DHPy_unwrap(h)); } void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht) @@ -614,6 +614,6 @@ void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) void debug_ctx_Dump(HPyContext ctx, DHPy h) { - _HPy_Dump(get_info(ctx)->original_ctx, h->h); + _HPy_Dump(get_info(ctx)->original_ctx, DHPy_unwrap(h)); } diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index e7575f04c..8f1a91b49 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -81,16 +81,16 @@ __attribute__((unused)) static void hpy_magic_dump(HPy h) { int universal = h._i & 1; if (universal) - fprintf(stderr, "Universal handle\n"); + fprintf(stderr, "\nUniversal handle\n"); else - fprintf(stderr, "Debug handle\n"); + fprintf(stderr, "\nDebug handle\n"); fprintf(stderr, "raw value: %lx (%ld)\n", h._i, h._i); if (universal) _HPy_Dump(&g_universal_ctx, h); else { - DHPy dh = (DHPy)h._i; - fprintf(stderr, "dh->h: %lx\n", dh->h._i); - _HPy_Dump(&g_universal_ctx, dh->h); + DebugHandle *dh = as_DebugHandle(h); + fprintf(stderr, "dh->uh: %lx\n", dh->uh._i); + _HPy_Dump(&g_universal_ctx, dh->uh); } } diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index 4bf2b4aa4..16d5e1483 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -1,12 +1,11 @@ #include "debug_internal.h" -DHPy DHPy_new(HPyContext ctx, HPy h) +DHPy DHPy_wrap(HPyContext ctx, UHPy uh) { HPyDebugInfo *info = get_info(ctx); - DHPy dh = malloc(sizeof(struct DHPy_s)); - dh->h = h; - dh->next = info->open_handles; - info->open_handles = dh; - return dh; + DebugHandle *handle = malloc(sizeof(DebugHandle)); + handle->uh = uh; + handle->next = info->open_handles; + info->open_handles = handle; + return as_DHPy(handle); } - diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index 2b61c4742..d9474bc6e 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -11,53 +11,59 @@ #define HPY_DEBUG_MAGIC 0xDEB00FF /* The Debug context is a wrapper around an underlying context, which we will - call Universal. The signatures of API functions are the same, but the HPy - types represents very different things: - - * HPys belonging by the Universal ctx are opaque (from our point of view) - * HPys belonging by the Debug ctx are pointers to a struct called DHPy_s - - Every DHPy is a wrapper around an universal HPy. To get the underlying - universal HPy, you can use its ->h field. - - To wrap an universal HPy into a DHPy, you need to call DHPy_new: this - function should be called only ONCE for each handle, and only if it - "fresh": it will record the DHPy into a list of open handles so that it can - be checked later. - - To avoid confusion and to prevent passing wrong handles by mistake, all the - various debug_ctx_* functions take and return DHPys. Inside - autogen_ctx_def.h there are no-op adapters which converts the DHPys into - HPys to make the C compiler happy. See also the corresponding comment - there. _d2h and _h2d "cast" a DHPy into an HPy, and they should be used - ONLY by the adapters. + call Universal. Inside the debug mode we manipulate handles which belongs + to both contexts, so to make things easier we create two typedefs to make + it clear what kind of handle we expect: UHPy and DHPy: + + * UHPy are opaque from our point of view. + + * DHPy are actually DebugHandle* in disguise. DebugHandles are wrappers + around a UHPy, with a bunch of extra info. + + To cast between DHPy and DebugHandle*, use as_DebugHandle and as_DHPy: + these are just no-op casts. + + To wrap a UHPy, call DHPy_wrap: this contains some actual logic, because it + malloc()s a new DebugHandle, which will be released at some point in the + future after we call HPy_Close on it. Note that if you call DHPy_wrap + twice on the same UHPy, you get two different DHPy. + + To unwrap a DHPy and get the underyling UHPy, call DHPy_unwrap. If you call + DHPy_unwrap multiple times on the same DHPy, you always get the same UHPy. + + WARNING: both UHPy and DHPy are alias of HPy, so we need to take care of + not mixing them, because the compiler cannot help. */ -struct DHPy_s { - HPy h; - struct DHPy_s *next; -}; -typedef struct DHPy_s *DHPy; /* "Debug HPy" */ +typedef HPy UHPy; +typedef HPy DHPy; -DHPy DHPy_new(HPyContext ctx, HPy h); +typedef struct DebugHandle { + UHPy uh; + struct DebugHandle *next; +} DebugHandle; +static inline DebugHandle * as_DebugHandle(DHPy dh) { + return (DebugHandle *)dh._i; +} -/* ======================================================== */ -/* These two functions should be used ONLY be the adapters! */ -static inline HPy _d2h(DHPy dh) { - return (HPy){ ._i = (HPy_ssize_t)dh }; +static inline DHPy as_DHPy(DebugHandle *handle) { + return (DHPy){(HPy_ssize_t)handle}; } -static inline DHPy _h2d(HPy h) { - return (DHPy)h._i; + +DHPy DHPy_wrap(HPyContext ctx, UHPy uh); + +static inline UHPy DHPy_unwrap(DHPy dh) { + return as_DebugHandle(dh)->uh; } -/* ======================================================== */ +/* === HPyDebugInfo === */ typedef struct { long magic_number; // used just for sanity checks HPyContext original_ctx; - DHPy open_handles; // linked list - DHPy closed_handles; // linked list + DebugHandle *open_handles; // linked list + DebugHandle *closed_handles; // linked list } HPyDebugInfo; static inline HPyDebugInfo *get_info(HPyContext ctx) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index 4a88d6851..84212d19b 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -24,29 +24,17 @@ def get_debug_wrapper_node(func): visitor.visit(newnode) return newnode + class autogen_debug_ctx_h(AutoGenFile): PATH = 'hpy/debug/src/autogen_debug_ctx.h' def generate(self): lines = [] w = lines.append - w(textwrap.dedent(""" - /* - The debug_ctx_* functions contain the actualy logic: they receive and - return handles of type DHPy. - - The _adapter_debug_* helpers cast DHPy into HPy and viceversa, to get - functions those signature is compatible to what is declared in the - HPyContext. Note that they are no-op, since the internal repr of DHPy - and HPy is the same (but the first is seen as a pointer to DHPy_s the - second as a small struct containining an integer), but the C standard - forbids casting function pointers whose arguments have nominally - different types, so we need to write the adapters manually. - */ - """)) - # emit the declarations and adapters for all the debug_ctx_* functions + # emit the declarations for all the debug_ctx_* functions for func in self.api.functions: - self.generate_adapter(w, func) + w(toC(get_debug_wrapper_node(func)) + ';') + w('') self.generate_init_prebuilt_handles(w) # emit a static ctx which uses the various debug_ctx_* functions w('') @@ -57,48 +45,16 @@ def generate(self): for var in self.api.variables: w(' .%s = HPy_NULL,' % (var.name,)) for func in self.api.functions: - w(' .%s = &_adapter_debug_%s,' % (func.ctx_name(), func.ctx_name())) + w(' .%s = &debug_%s,' % (func.ctx_name(), func.ctx_name())) w('};') return '\n'.join(lines) - def generate_adapter(self, w, func): - name = 'debug_%s' % func.ctx_name() - wrapper_node = get_debug_wrapper_node(func) - w(toC(wrapper_node) + ';') # signature of the debug_ctx_* function - # - # emit the adapter - node = funcnode_with_new_name(func.node, '_adapter_%s' % name) - signature = toC(node) - rettype = toC(node.type.type) - def get_params(): - lst = [] - for p in node.type.args.params: - if toC(p.type) == 'HPy': - lst.append('_h2d(%s)' % p.name) - elif toC(p.type) in ('HPy *', 'HPy []'): - lst.append('(DHPy *)%s' % p.name) - else: - lst.append(p.name) - return ', '.join(lst) - params = get_params() - - w(signature) - w('{') - if rettype == 'void': - w(f' {name}({params});') - elif rettype == 'HPy': - w(f' return _d2h({name}({params}));') - else: - w(f' return {name}({params});') - w('}') - w('') - def generate_init_prebuilt_handles(self, w): w('static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext original_ctx)') w('{') for var in self.api.variables: name = var.name - w(f' ctx->{name} = _d2h(DHPy_new(ctx, original_ctx->{name}));') + w(f' ctx->{name} = DHPy_wrap(ctx, original_ctx->{name});') w('}') @@ -136,9 +92,10 @@ def get_params(): if p.name == 'ctx': lst.append('get_info(ctx)->original_ctx') elif toC(p.type) == 'DHPy': - lst.append('%s->h' % p.name) + lst.append('DHPy_unwrap(%s)' % p.name) elif toC(p.type) in ('DHPy *', 'DHPy []'): - lst.append('(HPy *)%s' % p.name) + #lst.append('(HPy *)%s' % p.name) + lst.append('NULL /* TODO */') else: lst.append(p.name) return ', '.join(lst) @@ -151,7 +108,7 @@ def get_params(): if rettype == 'void': w(f' {func.name}({params});') elif rettype == 'DHPy': - w(f' return _h2d({func.name}({params}));') + w(f' return DHPy_wrap(ctx, {func.name}({params}));') else: w(f' return {func.name}({params});') w('}') From 12b63118bca1e13c60c0b19d2311fd491a2d6b4a Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 16:15:46 +0100 Subject: [PATCH 33/65] rename original_ctx into uctx --- hpy/debug/src/autogen_debug_ctx.h | 148 +++++++-------- hpy/debug/src/autogen_debug_wrappers.c | 242 ++++++++++++------------- hpy/debug/src/debug_ctx.c | 20 +- hpy/debug/src/debug_internal.h | 2 +- hpy/tools/autogen/debug.py | 6 +- 5 files changed, 209 insertions(+), 209 deletions(-) diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h index b8deedbe5..c200f4dd7 100644 --- a/hpy/debug/src/autogen_debug_ctx.h +++ b/hpy/debug/src/autogen_debug_ctx.h @@ -133,81 +133,81 @@ void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht); void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht); void debug_ctx_Dump(HPyContext ctx, DHPy h); -static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext original_ctx) +static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext uctx) { - ctx->h_None = DHPy_wrap(ctx, original_ctx->h_None); - ctx->h_True = DHPy_wrap(ctx, original_ctx->h_True); - ctx->h_False = DHPy_wrap(ctx, original_ctx->h_False); - ctx->h_BaseException = DHPy_wrap(ctx, original_ctx->h_BaseException); - ctx->h_Exception = DHPy_wrap(ctx, original_ctx->h_Exception); - ctx->h_StopAsyncIteration = DHPy_wrap(ctx, original_ctx->h_StopAsyncIteration); - ctx->h_StopIteration = DHPy_wrap(ctx, original_ctx->h_StopIteration); - ctx->h_GeneratorExit = DHPy_wrap(ctx, original_ctx->h_GeneratorExit); - ctx->h_ArithmeticError = DHPy_wrap(ctx, original_ctx->h_ArithmeticError); - ctx->h_LookupError = DHPy_wrap(ctx, original_ctx->h_LookupError); - ctx->h_AssertionError = DHPy_wrap(ctx, original_ctx->h_AssertionError); - ctx->h_AttributeError = DHPy_wrap(ctx, original_ctx->h_AttributeError); - ctx->h_BufferError = DHPy_wrap(ctx, original_ctx->h_BufferError); - ctx->h_EOFError = DHPy_wrap(ctx, original_ctx->h_EOFError); - ctx->h_FloatingPointError = DHPy_wrap(ctx, original_ctx->h_FloatingPointError); - ctx->h_OSError = DHPy_wrap(ctx, original_ctx->h_OSError); - ctx->h_ImportError = DHPy_wrap(ctx, original_ctx->h_ImportError); - ctx->h_ModuleNotFoundError = DHPy_wrap(ctx, original_ctx->h_ModuleNotFoundError); - ctx->h_IndexError = DHPy_wrap(ctx, original_ctx->h_IndexError); - ctx->h_KeyError = DHPy_wrap(ctx, original_ctx->h_KeyError); - ctx->h_KeyboardInterrupt = DHPy_wrap(ctx, original_ctx->h_KeyboardInterrupt); - ctx->h_MemoryError = DHPy_wrap(ctx, original_ctx->h_MemoryError); - ctx->h_NameError = DHPy_wrap(ctx, original_ctx->h_NameError); - ctx->h_OverflowError = DHPy_wrap(ctx, original_ctx->h_OverflowError); - ctx->h_RuntimeError = DHPy_wrap(ctx, original_ctx->h_RuntimeError); - ctx->h_RecursionError = DHPy_wrap(ctx, original_ctx->h_RecursionError); - ctx->h_NotImplementedError = DHPy_wrap(ctx, original_ctx->h_NotImplementedError); - ctx->h_SyntaxError = DHPy_wrap(ctx, original_ctx->h_SyntaxError); - ctx->h_IndentationError = DHPy_wrap(ctx, original_ctx->h_IndentationError); - ctx->h_TabError = DHPy_wrap(ctx, original_ctx->h_TabError); - ctx->h_ReferenceError = DHPy_wrap(ctx, original_ctx->h_ReferenceError); - ctx->h_SystemError = DHPy_wrap(ctx, original_ctx->h_SystemError); - ctx->h_SystemExit = DHPy_wrap(ctx, original_ctx->h_SystemExit); - ctx->h_TypeError = DHPy_wrap(ctx, original_ctx->h_TypeError); - ctx->h_UnboundLocalError = DHPy_wrap(ctx, original_ctx->h_UnboundLocalError); - ctx->h_UnicodeError = DHPy_wrap(ctx, original_ctx->h_UnicodeError); - ctx->h_UnicodeEncodeError = DHPy_wrap(ctx, original_ctx->h_UnicodeEncodeError); - ctx->h_UnicodeDecodeError = DHPy_wrap(ctx, original_ctx->h_UnicodeDecodeError); - ctx->h_UnicodeTranslateError = DHPy_wrap(ctx, original_ctx->h_UnicodeTranslateError); - ctx->h_ValueError = DHPy_wrap(ctx, original_ctx->h_ValueError); - ctx->h_ZeroDivisionError = DHPy_wrap(ctx, original_ctx->h_ZeroDivisionError); - ctx->h_BlockingIOError = DHPy_wrap(ctx, original_ctx->h_BlockingIOError); - ctx->h_BrokenPipeError = DHPy_wrap(ctx, original_ctx->h_BrokenPipeError); - ctx->h_ChildProcessError = DHPy_wrap(ctx, original_ctx->h_ChildProcessError); - ctx->h_ConnectionError = DHPy_wrap(ctx, original_ctx->h_ConnectionError); - ctx->h_ConnectionAbortedError = DHPy_wrap(ctx, original_ctx->h_ConnectionAbortedError); - ctx->h_ConnectionRefusedError = DHPy_wrap(ctx, original_ctx->h_ConnectionRefusedError); - ctx->h_ConnectionResetError = DHPy_wrap(ctx, original_ctx->h_ConnectionResetError); - ctx->h_FileExistsError = DHPy_wrap(ctx, original_ctx->h_FileExistsError); - ctx->h_FileNotFoundError = DHPy_wrap(ctx, original_ctx->h_FileNotFoundError); - ctx->h_InterruptedError = DHPy_wrap(ctx, original_ctx->h_InterruptedError); - ctx->h_IsADirectoryError = DHPy_wrap(ctx, original_ctx->h_IsADirectoryError); - ctx->h_NotADirectoryError = DHPy_wrap(ctx, original_ctx->h_NotADirectoryError); - ctx->h_PermissionError = DHPy_wrap(ctx, original_ctx->h_PermissionError); - ctx->h_ProcessLookupError = DHPy_wrap(ctx, original_ctx->h_ProcessLookupError); - ctx->h_TimeoutError = DHPy_wrap(ctx, original_ctx->h_TimeoutError); - ctx->h_Warning = DHPy_wrap(ctx, original_ctx->h_Warning); - ctx->h_UserWarning = DHPy_wrap(ctx, original_ctx->h_UserWarning); - ctx->h_DeprecationWarning = DHPy_wrap(ctx, original_ctx->h_DeprecationWarning); - ctx->h_PendingDeprecationWarning = DHPy_wrap(ctx, original_ctx->h_PendingDeprecationWarning); - ctx->h_SyntaxWarning = DHPy_wrap(ctx, original_ctx->h_SyntaxWarning); - ctx->h_RuntimeWarning = DHPy_wrap(ctx, original_ctx->h_RuntimeWarning); - ctx->h_FutureWarning = DHPy_wrap(ctx, original_ctx->h_FutureWarning); - ctx->h_ImportWarning = DHPy_wrap(ctx, original_ctx->h_ImportWarning); - ctx->h_UnicodeWarning = DHPy_wrap(ctx, original_ctx->h_UnicodeWarning); - ctx->h_BytesWarning = DHPy_wrap(ctx, original_ctx->h_BytesWarning); - ctx->h_ResourceWarning = DHPy_wrap(ctx, original_ctx->h_ResourceWarning); - ctx->h_BaseObjectType = DHPy_wrap(ctx, original_ctx->h_BaseObjectType); - ctx->h_TypeType = DHPy_wrap(ctx, original_ctx->h_TypeType); - ctx->h_LongType = DHPy_wrap(ctx, original_ctx->h_LongType); - ctx->h_UnicodeType = DHPy_wrap(ctx, original_ctx->h_UnicodeType); - ctx->h_TupleType = DHPy_wrap(ctx, original_ctx->h_TupleType); - ctx->h_ListType = DHPy_wrap(ctx, original_ctx->h_ListType); + ctx->h_None = DHPy_wrap(ctx, uctx->h_None); + ctx->h_True = DHPy_wrap(ctx, uctx->h_True); + ctx->h_False = DHPy_wrap(ctx, uctx->h_False); + ctx->h_BaseException = DHPy_wrap(ctx, uctx->h_BaseException); + ctx->h_Exception = DHPy_wrap(ctx, uctx->h_Exception); + ctx->h_StopAsyncIteration = DHPy_wrap(ctx, uctx->h_StopAsyncIteration); + ctx->h_StopIteration = DHPy_wrap(ctx, uctx->h_StopIteration); + ctx->h_GeneratorExit = DHPy_wrap(ctx, uctx->h_GeneratorExit); + ctx->h_ArithmeticError = DHPy_wrap(ctx, uctx->h_ArithmeticError); + ctx->h_LookupError = DHPy_wrap(ctx, uctx->h_LookupError); + ctx->h_AssertionError = DHPy_wrap(ctx, uctx->h_AssertionError); + ctx->h_AttributeError = DHPy_wrap(ctx, uctx->h_AttributeError); + ctx->h_BufferError = DHPy_wrap(ctx, uctx->h_BufferError); + ctx->h_EOFError = DHPy_wrap(ctx, uctx->h_EOFError); + ctx->h_FloatingPointError = DHPy_wrap(ctx, uctx->h_FloatingPointError); + ctx->h_OSError = DHPy_wrap(ctx, uctx->h_OSError); + ctx->h_ImportError = DHPy_wrap(ctx, uctx->h_ImportError); + ctx->h_ModuleNotFoundError = DHPy_wrap(ctx, uctx->h_ModuleNotFoundError); + ctx->h_IndexError = DHPy_wrap(ctx, uctx->h_IndexError); + ctx->h_KeyError = DHPy_wrap(ctx, uctx->h_KeyError); + ctx->h_KeyboardInterrupt = DHPy_wrap(ctx, uctx->h_KeyboardInterrupt); + ctx->h_MemoryError = DHPy_wrap(ctx, uctx->h_MemoryError); + ctx->h_NameError = DHPy_wrap(ctx, uctx->h_NameError); + ctx->h_OverflowError = DHPy_wrap(ctx, uctx->h_OverflowError); + ctx->h_RuntimeError = DHPy_wrap(ctx, uctx->h_RuntimeError); + ctx->h_RecursionError = DHPy_wrap(ctx, uctx->h_RecursionError); + ctx->h_NotImplementedError = DHPy_wrap(ctx, uctx->h_NotImplementedError); + ctx->h_SyntaxError = DHPy_wrap(ctx, uctx->h_SyntaxError); + ctx->h_IndentationError = DHPy_wrap(ctx, uctx->h_IndentationError); + ctx->h_TabError = DHPy_wrap(ctx, uctx->h_TabError); + ctx->h_ReferenceError = DHPy_wrap(ctx, uctx->h_ReferenceError); + ctx->h_SystemError = DHPy_wrap(ctx, uctx->h_SystemError); + ctx->h_SystemExit = DHPy_wrap(ctx, uctx->h_SystemExit); + ctx->h_TypeError = DHPy_wrap(ctx, uctx->h_TypeError); + ctx->h_UnboundLocalError = DHPy_wrap(ctx, uctx->h_UnboundLocalError); + ctx->h_UnicodeError = DHPy_wrap(ctx, uctx->h_UnicodeError); + ctx->h_UnicodeEncodeError = DHPy_wrap(ctx, uctx->h_UnicodeEncodeError); + ctx->h_UnicodeDecodeError = DHPy_wrap(ctx, uctx->h_UnicodeDecodeError); + ctx->h_UnicodeTranslateError = DHPy_wrap(ctx, uctx->h_UnicodeTranslateError); + ctx->h_ValueError = DHPy_wrap(ctx, uctx->h_ValueError); + ctx->h_ZeroDivisionError = DHPy_wrap(ctx, uctx->h_ZeroDivisionError); + ctx->h_BlockingIOError = DHPy_wrap(ctx, uctx->h_BlockingIOError); + ctx->h_BrokenPipeError = DHPy_wrap(ctx, uctx->h_BrokenPipeError); + ctx->h_ChildProcessError = DHPy_wrap(ctx, uctx->h_ChildProcessError); + ctx->h_ConnectionError = DHPy_wrap(ctx, uctx->h_ConnectionError); + ctx->h_ConnectionAbortedError = DHPy_wrap(ctx, uctx->h_ConnectionAbortedError); + ctx->h_ConnectionRefusedError = DHPy_wrap(ctx, uctx->h_ConnectionRefusedError); + ctx->h_ConnectionResetError = DHPy_wrap(ctx, uctx->h_ConnectionResetError); + ctx->h_FileExistsError = DHPy_wrap(ctx, uctx->h_FileExistsError); + ctx->h_FileNotFoundError = DHPy_wrap(ctx, uctx->h_FileNotFoundError); + ctx->h_InterruptedError = DHPy_wrap(ctx, uctx->h_InterruptedError); + ctx->h_IsADirectoryError = DHPy_wrap(ctx, uctx->h_IsADirectoryError); + ctx->h_NotADirectoryError = DHPy_wrap(ctx, uctx->h_NotADirectoryError); + ctx->h_PermissionError = DHPy_wrap(ctx, uctx->h_PermissionError); + ctx->h_ProcessLookupError = DHPy_wrap(ctx, uctx->h_ProcessLookupError); + ctx->h_TimeoutError = DHPy_wrap(ctx, uctx->h_TimeoutError); + ctx->h_Warning = DHPy_wrap(ctx, uctx->h_Warning); + ctx->h_UserWarning = DHPy_wrap(ctx, uctx->h_UserWarning); + ctx->h_DeprecationWarning = DHPy_wrap(ctx, uctx->h_DeprecationWarning); + ctx->h_PendingDeprecationWarning = DHPy_wrap(ctx, uctx->h_PendingDeprecationWarning); + ctx->h_SyntaxWarning = DHPy_wrap(ctx, uctx->h_SyntaxWarning); + ctx->h_RuntimeWarning = DHPy_wrap(ctx, uctx->h_RuntimeWarning); + ctx->h_FutureWarning = DHPy_wrap(ctx, uctx->h_FutureWarning); + ctx->h_ImportWarning = DHPy_wrap(ctx, uctx->h_ImportWarning); + ctx->h_UnicodeWarning = DHPy_wrap(ctx, uctx->h_UnicodeWarning); + ctx->h_BytesWarning = DHPy_wrap(ctx, uctx->h_BytesWarning); + ctx->h_ResourceWarning = DHPy_wrap(ctx, uctx->h_ResourceWarning); + ctx->h_BaseObjectType = DHPy_wrap(ctx, uctx->h_BaseObjectType); + ctx->h_TypeType = DHPy_wrap(ctx, uctx->h_TypeType); + ctx->h_LongType = DHPy_wrap(ctx, uctx->h_LongType); + ctx->h_UnicodeType = DHPy_wrap(ctx, uctx->h_UnicodeType); + ctx->h_TupleType = DHPy_wrap(ctx, uctx->h_TupleType); + ctx->h_ListType = DHPy_wrap(ctx, uctx->h_ListType); } static struct _HPyContext_s g_debug_ctx = { diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index a95cd7c41..182665a9d 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -14,606 +14,606 @@ DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) { - return DHPy_wrap(ctx, HPyModule_Create(get_info(ctx)->original_ctx, def)); + return DHPy_wrap(ctx, HPyModule_Create(get_info(ctx)->uctx, def)); } DHPy debug_ctx_Dup(HPyContext ctx, DHPy h) { - return DHPy_wrap(ctx, HPy_Dup(get_info(ctx)->original_ctx, DHPy_unwrap(h))); + return DHPy_wrap(ctx, HPy_Dup(get_info(ctx)->uctx, DHPy_unwrap(h))); } void debug_ctx_Close(HPyContext ctx, DHPy h) { - HPy_Close(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + HPy_Close(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value) { - return DHPy_wrap(ctx, HPyLong_FromLong(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromLong(get_info(ctx)->uctx, value)); } DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) { - return DHPy_wrap(ctx, HPyLong_FromUnsignedLong(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromUnsignedLong(get_info(ctx)->uctx, value)); } DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) { - return DHPy_wrap(ctx, HPyLong_FromLongLong(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyLong_FromLongLong(get_info(ctx)->uctx, v)); } DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) { - return DHPy_wrap(ctx, HPyLong_FromUnsignedLongLong(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyLong_FromUnsignedLongLong(get_info(ctx)->uctx, v)); } DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) { - return DHPy_wrap(ctx, HPyLong_FromSize_t(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromSize_t(get_info(ctx)->uctx, value)); } DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) { - return DHPy_wrap(ctx, HPyLong_FromSsize_t(get_info(ctx)->original_ctx, value)); + return DHPy_wrap(ctx, HPyLong_FromSsize_t(get_info(ctx)->uctx, value)); } long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h) { - return HPyLong_AsLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsLong(get_info(ctx)->uctx, DHPy_unwrap(h)); } unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLong(get_info(ctx)->uctx, DHPy_unwrap(h)); } unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongMask(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLongMask(get_info(ctx)->uctx, DHPy_unwrap(h)); } long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h) { - return HPyLong_AsLongLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsLongLong(get_info(ctx)->uctx, DHPy_unwrap(h)); } unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongLong(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLongLong(get_info(ctx)->uctx, DHPy_unwrap(h)); } unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h) { - return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->uctx, DHPy_unwrap(h)); } size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h) { - return HPyLong_AsSize_t(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsSize_t(get_info(ctx)->uctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h) { - return HPyLong_AsSsize_t(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyLong_AsSsize_t(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v) { - return DHPy_wrap(ctx, HPyFloat_FromDouble(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyFloat_FromDouble(get_info(ctx)->uctx, v)); } double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h) { - return HPyFloat_AsDouble(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyFloat_AsDouble(get_info(ctx)->uctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h) { - return HPy_Length(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPy_Length(get_info(ctx)->uctx, DHPy_unwrap(h)); } int debug_ctx_Number_Check(HPyContext ctx, DHPy h) { - return HPyNumber_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyNumber_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Add(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Add(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Subtract(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Subtract(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Multiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Multiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_MatrixMultiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_MatrixMultiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_FloorDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_FloorDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_TrueDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_TrueDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Remainder(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Remainder(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Divmod(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Divmod(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) { - return DHPy_wrap(ctx, HPy_Power(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); + return DHPy_wrap(ctx, HPy_Power(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); } DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Negative(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); + return DHPy_wrap(ctx, HPy_Negative(get_info(ctx)->uctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Positive(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); + return DHPy_wrap(ctx, HPy_Positive(get_info(ctx)->uctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Absolute(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); + return DHPy_wrap(ctx, HPy_Absolute(get_info(ctx)->uctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Invert(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); + return DHPy_wrap(ctx, HPy_Invert(get_info(ctx)->uctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Lshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Lshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Rshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Rshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_And(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_And(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Xor(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Xor(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Or(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_Or(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_Index(HPyContext ctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Index(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); + return DHPy_wrap(ctx, HPy_Index(get_info(ctx)->uctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Long(HPyContext ctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Long(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); + return DHPy_wrap(ctx, HPy_Long(get_info(ctx)->uctx, DHPy_unwrap(h1))); } DHPy debug_ctx_Float(HPyContext ctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Float(get_info(ctx)->original_ctx, DHPy_unwrap(h1))); + return DHPy_wrap(ctx, HPy_Float(get_info(ctx)->uctx, DHPy_unwrap(h1))); } DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceAdd(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceAdd(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceSubtract(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceSubtract(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceMultiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceMultiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceMatrixMultiply(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceMatrixMultiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceFloorDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceFloorDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceTrueDivide(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceTrueDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceRemainder(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceRemainder(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) { - return DHPy_wrap(ctx, HPy_InPlacePower(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); + return DHPy_wrap(ctx, HPy_InPlacePower(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); } DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceLshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceLshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceRshift(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceRshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceAnd(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceAnd(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceXor(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceXor(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceOr(get_info(ctx)->original_ctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(ctx, HPy_InPlaceOr(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } int debug_ctx_Callable_Check(HPyContext ctx, DHPy h) { - return HPyCallable_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyCallable_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw) { - return DHPy_wrap(ctx, HPy_CallTupleDict(get_info(ctx)->original_ctx, DHPy_unwrap(callable), DHPy_unwrap(args), DHPy_unwrap(kw))); + return DHPy_wrap(ctx, HPy_CallTupleDict(get_info(ctx)->uctx, DHPy_unwrap(callable), DHPy_unwrap(args), DHPy_unwrap(kw))); } void debug_ctx_FatalError(HPyContext ctx, const char *message) { - HPy_FatalError(get_info(ctx)->original_ctx, message); + HPy_FatalError(get_info(ctx)->uctx, message); } void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message) { - HPyErr_SetString(get_info(ctx)->original_ctx, DHPy_unwrap(h_type), message); + HPyErr_SetString(get_info(ctx)->uctx, DHPy_unwrap(h_type), message); } void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value) { - HPyErr_SetObject(get_info(ctx)->original_ctx, DHPy_unwrap(h_type), DHPy_unwrap(h_value)); + HPyErr_SetObject(get_info(ctx)->uctx, DHPy_unwrap(h_type), DHPy_unwrap(h_value)); } int debug_ctx_Err_Occurred(HPyContext ctx) { - return HPyErr_Occurred(get_info(ctx)->original_ctx); + return HPyErr_Occurred(get_info(ctx)->uctx); } DHPy debug_ctx_Err_NoMemory(HPyContext ctx) { - return DHPy_wrap(ctx, HPyErr_NoMemory(get_info(ctx)->original_ctx)); + return DHPy_wrap(ctx, HPyErr_NoMemory(get_info(ctx)->uctx)); } void debug_ctx_Err_Clear(HPyContext ctx) { - HPyErr_Clear(get_info(ctx)->original_ctx); + HPyErr_Clear(get_info(ctx)->uctx); } int debug_ctx_IsTrue(HPyContext ctx, DHPy h) { - return HPy_IsTrue(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPy_IsTrue(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) { - return DHPy_wrap(ctx, HPyType_FromSpec(get_info(ctx)->original_ctx, spec, params)); + return DHPy_wrap(ctx, HPyType_FromSpec(get_info(ctx)->uctx, spec, params)); } DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw) { - return DHPy_wrap(ctx, HPyType_GenericNew(get_info(ctx)->original_ctx, DHPy_unwrap(type), NULL /* TODO */, nargs, DHPy_unwrap(kw))); + return DHPy_wrap(ctx, HPyType_GenericNew(get_info(ctx)->uctx, DHPy_unwrap(type), NULL /* TODO */, nargs, DHPy_unwrap(kw))); } DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name) { - return DHPy_wrap(ctx, HPy_GetAttr(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(name))); + return DHPy_wrap(ctx, HPy_GetAttr(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name))); } DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name) { - return DHPy_wrap(ctx, HPy_GetAttr_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), name)); + return DHPy_wrap(ctx, HPy_GetAttr_s(get_info(ctx)->uctx, DHPy_unwrap(obj), name)); } int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name) { - return HPy_HasAttr(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(name)); + return HPy_HasAttr(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name)); } int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name) { - return HPy_HasAttr_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), name); + return HPy_HasAttr_s(get_info(ctx)->uctx, DHPy_unwrap(obj), name); } int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value) { - return HPy_SetAttr(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(name), DHPy_unwrap(value)); + return HPy_SetAttr(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name), DHPy_unwrap(value)); } int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value) { - return HPy_SetAttr_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), name, DHPy_unwrap(value)); + return HPy_SetAttr_s(get_info(ctx)->uctx, DHPy_unwrap(obj), name, DHPy_unwrap(value)); } DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key) { - return DHPy_wrap(ctx, HPy_GetItem(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(key))); + return DHPy_wrap(ctx, HPy_GetItem(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(key))); } DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx) { - return DHPy_wrap(ctx, HPy_GetItem_i(get_info(ctx)->original_ctx, DHPy_unwrap(obj), idx)); + return DHPy_wrap(ctx, HPy_GetItem_i(get_info(ctx)->uctx, DHPy_unwrap(obj), idx)); } DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key) { - return DHPy_wrap(ctx, HPy_GetItem_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), key)); + return DHPy_wrap(ctx, HPy_GetItem_s(get_info(ctx)->uctx, DHPy_unwrap(obj), key)); } int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value) { - return HPy_SetItem(get_info(ctx)->original_ctx, DHPy_unwrap(obj), DHPy_unwrap(key), DHPy_unwrap(value)); + return HPy_SetItem(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(key), DHPy_unwrap(value)); } int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value) { - return HPy_SetItem_i(get_info(ctx)->original_ctx, DHPy_unwrap(obj), idx, DHPy_unwrap(value)); + return HPy_SetItem_i(get_info(ctx)->uctx, DHPy_unwrap(obj), idx, DHPy_unwrap(value)); } int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value) { - return HPy_SetItem_s(get_info(ctx)->original_ctx, DHPy_unwrap(obj), key, DHPy_unwrap(value)); + return HPy_SetItem_s(get_info(ctx)->uctx, DHPy_unwrap(obj), key, DHPy_unwrap(value)); } void *debug_ctx_Cast(HPyContext ctx, DHPy h) { - return _HPy_Cast(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return _HPy_Cast(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data) { - return DHPy_wrap(ctx, _HPy_New(get_info(ctx)->original_ctx, DHPy_unwrap(h_type), data)); + return DHPy_wrap(ctx, _HPy_New(get_info(ctx)->uctx, DHPy_unwrap(h_type), data)); } DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_Repr(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); + return DHPy_wrap(ctx, HPy_Repr(get_info(ctx)->uctx, DHPy_unwrap(obj))); } DHPy debug_ctx_Str(HPyContext ctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_Str(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); + return DHPy_wrap(ctx, HPy_Str(get_info(ctx)->uctx, DHPy_unwrap(obj))); } DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_ASCII(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); + return DHPy_wrap(ctx, HPy_ASCII(get_info(ctx)->uctx, DHPy_unwrap(obj))); } DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_Bytes(get_info(ctx)->original_ctx, DHPy_unwrap(obj))); + return DHPy_wrap(ctx, HPy_Bytes(get_info(ctx)->uctx, DHPy_unwrap(obj))); } DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op) { - return DHPy_wrap(ctx, HPy_RichCompare(get_info(ctx)->original_ctx, DHPy_unwrap(v), DHPy_unwrap(w), op)); + return DHPy_wrap(ctx, HPy_RichCompare(get_info(ctx)->uctx, DHPy_unwrap(v), DHPy_unwrap(w), op)); } int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op) { - return HPy_RichCompareBool(get_info(ctx)->original_ctx, DHPy_unwrap(v), DHPy_unwrap(w), op); + return HPy_RichCompareBool(get_info(ctx)->uctx, DHPy_unwrap(v), DHPy_unwrap(w), op); } HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj) { - return HPy_Hash(get_info(ctx)->original_ctx, DHPy_unwrap(obj)); + return HPy_Hash(get_info(ctx)->uctx, DHPy_unwrap(obj)); } int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h) { - return HPyBytes_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyBytes_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h) { - return HPyBytes_Size(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyBytes_Size(get_info(ctx)->uctx, DHPy_unwrap(h)); } HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h) { - return HPyBytes_GET_SIZE(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyBytes_GET_SIZE(get_info(ctx)->uctx, DHPy_unwrap(h)); } char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h) { - return HPyBytes_AsString(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyBytes_AsString(get_info(ctx)->uctx, DHPy_unwrap(h)); } char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h) { - return HPyBytes_AS_STRING(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyBytes_AS_STRING(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) { - return DHPy_wrap(ctx, HPyBytes_FromString(get_info(ctx)->original_ctx, v)); + return DHPy_wrap(ctx, HPyBytes_FromString(get_info(ctx)->uctx, v)); } DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) { - return DHPy_wrap(ctx, HPyBytes_FromStringAndSize(get_info(ctx)->original_ctx, v, len)); + return DHPy_wrap(ctx, HPyBytes_FromStringAndSize(get_info(ctx)->uctx, v, len)); } DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) { - return DHPy_wrap(ctx, HPyUnicode_FromString(get_info(ctx)->original_ctx, utf8)); + return DHPy_wrap(ctx, HPyUnicode_FromString(get_info(ctx)->uctx, utf8)); } int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h) { - return HPyUnicode_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyUnicode_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h) { - return DHPy_wrap(ctx, HPyUnicode_AsUTF8String(get_info(ctx)->original_ctx, DHPy_unwrap(h))); + return DHPy_wrap(ctx, HPyUnicode_AsUTF8String(get_info(ctx)->uctx, DHPy_unwrap(h))); } DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) { - return DHPy_wrap(ctx, HPyUnicode_FromWideChar(get_info(ctx)->original_ctx, w, size)); + return DHPy_wrap(ctx, HPyUnicode_FromWideChar(get_info(ctx)->uctx, w, size)); } int debug_ctx_List_Check(HPyContext ctx, DHPy h) { - return HPyList_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyList_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) { - return DHPy_wrap(ctx, HPyList_New(get_info(ctx)->original_ctx, len)); + return DHPy_wrap(ctx, HPyList_New(get_info(ctx)->uctx, len)); } int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item) { - return HPyList_Append(get_info(ctx)->original_ctx, DHPy_unwrap(h_list), DHPy_unwrap(h_item)); + return HPyList_Append(get_info(ctx)->uctx, DHPy_unwrap(h_list), DHPy_unwrap(h_item)); } int debug_ctx_Dict_Check(HPyContext ctx, DHPy h) { - return HPyDict_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyDict_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Dict_New(HPyContext ctx) { - return DHPy_wrap(ctx, HPyDict_New(get_info(ctx)->original_ctx)); + return DHPy_wrap(ctx, HPyDict_New(get_info(ctx)->uctx)); } int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h) { - return HPyTuple_Check(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPyTuple_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); } DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n) { - return DHPy_wrap(ctx, HPyTuple_FromArray(get_info(ctx)->original_ctx, NULL /* TODO */, n)); + return DHPy_wrap(ctx, HPyTuple_FromArray(get_info(ctx)->uctx, NULL /* TODO */, n)); } DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) { - return DHPy_wrap(ctx, HPy_FromPyObject(get_info(ctx)->original_ctx, obj)); + return DHPy_wrap(ctx, HPy_FromPyObject(get_info(ctx)->uctx, obj)); } cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h) { - return HPy_AsPyObject(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + return HPy_AsPyObject(get_info(ctx)->uctx, DHPy_unwrap(h)); } void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self) { - _HPy_CallDestroyAndThenDealloc(get_info(ctx)->original_ctx, func, self); + _HPy_CallDestroyAndThenDealloc(get_info(ctx)->uctx, func, self); } HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) { - return HPyListBuilder_New(get_info(ctx)->original_ctx, initial_size); + return HPyListBuilder_New(get_info(ctx)->uctx, initial_size); } void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyListBuilder_Set(get_info(ctx)->original_ctx, builder, index, DHPy_unwrap(h_item)); + HPyListBuilder_Set(get_info(ctx)->uctx, builder, index, DHPy_unwrap(h_item)); } DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) { - return DHPy_wrap(ctx, HPyListBuilder_Build(get_info(ctx)->original_ctx, builder)); + return DHPy_wrap(ctx, HPyListBuilder_Build(get_info(ctx)->uctx, builder)); } void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder) { - HPyListBuilder_Cancel(get_info(ctx)->original_ctx, builder); + HPyListBuilder_Cancel(get_info(ctx)->uctx, builder); } HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) { - return HPyTupleBuilder_New(get_info(ctx)->original_ctx, initial_size); + return HPyTupleBuilder_New(get_info(ctx)->uctx, initial_size); } void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyTupleBuilder_Set(get_info(ctx)->original_ctx, builder, index, DHPy_unwrap(h_item)); + HPyTupleBuilder_Set(get_info(ctx)->uctx, builder, index, DHPy_unwrap(h_item)); } DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) { - return DHPy_wrap(ctx, HPyTupleBuilder_Build(get_info(ctx)->original_ctx, builder)); + return DHPy_wrap(ctx, HPyTupleBuilder_Build(get_info(ctx)->uctx, builder)); } void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder) { - HPyTupleBuilder_Cancel(get_info(ctx)->original_ctx, builder); + HPyTupleBuilder_Cancel(get_info(ctx)->uctx, builder); } HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size) { - return HPyTracker_New(get_info(ctx)->original_ctx, size); + return HPyTracker_New(get_info(ctx)->uctx, size); } int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h) { - return HPyTracker_Add(get_info(ctx)->original_ctx, ht, DHPy_unwrap(h)); + return HPyTracker_Add(get_info(ctx)->uctx, ht, DHPy_unwrap(h)); } void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht) { - HPyTracker_ForgetAll(get_info(ctx)->original_ctx, ht); + HPyTracker_ForgetAll(get_info(ctx)->uctx, ht); } void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) { - HPyTracker_Close(get_info(ctx)->original_ctx, ht); + HPyTracker_Close(get_info(ctx)->uctx, ht); } void debug_ctx_Dump(HPyContext ctx, DHPy h) { - _HPy_Dump(get_info(ctx)->original_ctx, DHPy_unwrap(h)); + _HPy_Dump(get_info(ctx)->uctx, DHPy_unwrap(h)); } diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 8f1a91b49..a122e46cd 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -5,7 +5,7 @@ static HPyDebugInfo debug_info = { .magic_number = HPY_DEBUG_MAGIC, - .original_ctx = NULL, + .uctx = NULL, }; @@ -20,26 +20,26 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, abort(); } -// NOTE: at the moment this function assumes that original_ctx is always the +// NOTE: at the moment this function assumes that uctx is always the // same. If/when we migrate to a system in which we can have multiple // independent contexts, this function should ensure to create a different // debug wrapper for each of them. -static void debug_ctx_init(HPyContext original_ctx) +static void debug_ctx_init(HPyContext uctx) { if (g_debug_ctx._private != NULL) { // already initialized - assert(get_info(&g_debug_ctx)->original_ctx == original_ctx); // sanity check + assert(get_info(&g_debug_ctx)->uctx == uctx); // sanity check return; } // initialize debug_info - debug_info.original_ctx = original_ctx; + debug_info.uctx = uctx; debug_info.open_handles = NULL; debug_info.closed_handles = NULL; g_debug_ctx._private = &debug_info; // initialze ctx->h_None, etc. - debug_init_prebuilt_handles(&g_debug_ctx, original_ctx); + debug_init_prebuilt_handles(&g_debug_ctx, uctx); /* CallRealFunctionFromTrampoline is special, since it is responsible to retrieve and pass the appropriate context to the HPy functions on @@ -63,14 +63,14 @@ static void debug_ctx_init(HPyContext original_ctx) the HPy func. 5. So, the default implementation does exactly what we want! Let's just - copy it from original_ctx + copy it from uctx */ - g_debug_ctx.ctx_CallRealFunctionFromTrampoline = original_ctx->ctx_CallRealFunctionFromTrampoline; + g_debug_ctx.ctx_CallRealFunctionFromTrampoline = uctx->ctx_CallRealFunctionFromTrampoline; } -HPyContext hpy_debug_get_ctx(HPyContext original_ctx) +HPyContext hpy_debug_get_ctx(HPyContext uctx) { - debug_ctx_init(original_ctx); + debug_ctx_init(uctx); return &g_debug_ctx; } diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index d9474bc6e..e2160d59d 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -61,7 +61,7 @@ static inline UHPy DHPy_unwrap(DHPy dh) { typedef struct { long magic_number; // used just for sanity checks - HPyContext original_ctx; + HPyContext uctx; DebugHandle *open_handles; // linked list DebugHandle *closed_handles; // linked list } HPyDebugInfo; diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index 84212d19b..64d27e86e 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -50,11 +50,11 @@ def generate(self): return '\n'.join(lines) def generate_init_prebuilt_handles(self, w): - w('static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext original_ctx)') + w('static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext uctx)') w('{') for var in self.api.variables: name = var.name - w(f' ctx->{name} = DHPy_wrap(ctx, original_ctx->{name});') + w(f' ctx->{name} = DHPy_wrap(ctx, uctx->{name});') w('}') @@ -90,7 +90,7 @@ def get_params(): lst = [] for p in node.type.args.params: if p.name == 'ctx': - lst.append('get_info(ctx)->original_ctx') + lst.append('get_info(ctx)->uctx') elif toC(p.type) == 'DHPy': lst.append('DHPy_unwrap(%s)' % p.name) elif toC(p.type) in ('DHPy *', 'DHPy []'): From eadef67408f677e2524b6e4f9bc8a81bbd057c07 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 16:41:38 +0100 Subject: [PATCH 34/65] Start to write the debug mode version of ctx_CallRealFunctionFromTrampoline This is the last missing piece which was needed to actually call functions with the debug context. test_00_basic:test_noop passes. From here, it's just a matter of implementing the missing signatures --- hpy/debug/src/autogen_debug_ctx.h | 2 +- hpy/debug/src/debug_ctx.c | 38 ------------------ hpy/debug/src/debug_ctx_cpython.c | 56 +++++++++++++++++++++++++++ hpy/debug/src/debug_ctx_not_cpython.c | 16 ++++++++ setup.py | 1 + 5 files changed, 74 insertions(+), 39 deletions(-) create mode 100644 hpy/debug/src/debug_ctx_cpython.c create mode 100644 hpy/debug/src/debug_ctx_not_cpython.c diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h index c200f4dd7..d099f278a 100644 --- a/hpy/debug/src/autogen_debug_ctx.h +++ b/hpy/debug/src/autogen_debug_ctx.h @@ -210,7 +210,7 @@ static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext uctx) ctx->h_ListType = DHPy_wrap(ctx, uctx->h_ListType); } -static struct _HPyContext_s g_debug_ctx = { +struct _HPyContext_s g_debug_ctx = { .name = "HPy Debug Mode ABI", ._private = NULL, .ctx_version = 1, diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index a122e46cd..b6f65e449 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -8,18 +8,6 @@ static HPyDebugInfo debug_info = { .uctx = NULL, }; - -void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, - HPyFunc_Signature sig, - void *func, void *args) -{ - fprintf(stderr, - "FATAL ERROR! debug_ctx_CallRealFunctionFromTrampoline should never be " - "called! This probably means that the debug_ctx was not initialized " - "properly\n"); - abort(); -} - // NOTE: at the moment this function assumes that uctx is always the // same. If/when we migrate to a system in which we can have multiple // independent contexts, this function should ensure to create a different @@ -40,32 +28,6 @@ static void debug_ctx_init(HPyContext uctx) // initialze ctx->h_None, etc. debug_init_prebuilt_handles(&g_debug_ctx, uctx); - - /* CallRealFunctionFromTrampoline is special, since it is responsible to - retrieve and pass the appropriate context to the HPy functions on - CPython. Note that this is used ONLY on CPython, other implementations - should be able to call HPy functions natively without any need for - trampolines. - - Quick recap of what happens: - - 1. HPy_MODINIT defines a per-module _ctx_for_trampolines - - 2. universal.load(..., debug=True) passes g_debug_ctx to MODINIT, which - stores it in _ctx_for_trampolines - - 3. when CPython calls an HPy function, it goes through the trampoline - which calls CallRealFunctionFromTrampoline - - 4. the default implementation retrieves the ctx from - _ctx_for_trampolines (which will contain either g_universal_ctx or - g_debug_ctx depending on how the module was loaded) and passes it to - the HPy func. - - 5. So, the default implementation does exactly what we want! Let's just - copy it from uctx - */ - g_debug_ctx.ctx_CallRealFunctionFromTrampoline = uctx->ctx_CallRealFunctionFromTrampoline; } HPyContext hpy_debug_get_ctx(HPyContext uctx) diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c new file mode 100644 index 000000000..12b2418ed --- /dev/null +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -0,0 +1,56 @@ +/* =========== CPython-ONLY =========== + In the following code, we use _py2h and _h2py and we assumed they are the + ones defined by CPython's version of hpy.universal. + + DO NOT COMPILE THIS FILE UNLESS YOU ARE BUILDING CPython's hpy.universal. + + If you want to compile the debug mode into your own non-CPython version of + hpy.universal, you should include debug_ctx_not_cpython.c. + ==================================== + + In theory, the debug mode is completely generic and can wrap a generic + uctx. However, CPython is special because it does not have native support + for HPy, so uctx contains the logic to call HPy functions from CPython, by + using _HPy_CallRealFunctionFromTrampoline. + + uctx->ctx_CallRealFunctionFromTrampoline convers PyObject* into UHPy. So + for the debug mode we need to: + + 1. convert the PyObject* args into UHPys. + 2. wrap the UHPys into DHPys. + 3. unwrap the resulting DHPy and convert to PyObject*. +*/ + +#include +#include "debug_internal.h" +#include "handles.h" // for _py2h and _h2py + +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, + HPyFunc_Signature sig, + void *func, void *args) +{ + switch (sig) { + case HPyFunc_NOARGS: { + HPyFunc_noargs f = (HPyFunc_noargs)func; + _HPyFunc_args_NOARGS *a = (_HPyFunc_args_NOARGS*)args; + DHPy dh_self = DHPy_wrap(ctx, _py2h(a->self)); + DHPy dh_result = f(ctx, dh_self); + a->result = _h2py(DHPy_unwrap(dh_result)); + return; + } + case HPyFunc_O: { + abort(); + } + case HPyFunc_VARARGS: { + abort(); + } + case HPyFunc_KEYWORDS: { + abort(); + } + case HPyFunc_INITPROC: { + abort(); + } + default: + abort(); // XXX + } +} diff --git a/hpy/debug/src/debug_ctx_not_cpython.c b/hpy/debug/src/debug_ctx_not_cpython.c new file mode 100644 index 000000000..051801ada --- /dev/null +++ b/hpy/debug/src/debug_ctx_not_cpython.c @@ -0,0 +1,16 @@ +// This is for non-CPython implementations! +// +// If you want to bundle the debug mode into your own version of +// hpy.universal, make sure to compile this file and NOT debug_ctx_cpython.c + +#include "debug_internal.h" + +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, + HPyFunc_Signature sig, + void *func, void *args) +{ + HPyContext original_ctx = get_info(ctx)->original_ctx; + HPy_FatalError(original_ctx, + "Something is very wrong! _HPy_CallRealFunctionFromTrampoline() " + "should be used only by the CPython version of hpy.universal"); +} diff --git a/setup.py b/setup.py index 495eaae9e..66a81270f 100644 --- a/setup.py +++ b/setup.py @@ -61,6 +61,7 @@ def get_scm_config(): 'hpy/devel/src/runtime/ctx_tuple.c', 'hpy/devel/src/runtime/ctx_tuplebuilder.c', 'hpy/debug/src/debug_ctx.c', + 'hpy/debug/src/debug_ctx_cpython.c', 'hpy/debug/src/debug_handles.c', 'hpy/debug/src/_debugmod.c', 'hpy/debug/src/autogen_debug_wrappers.c', From d1818ffa21001b7f4f317f1f3778fc662f5555d0 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 16:56:22 +0100 Subject: [PATCH 35/65] implement HPyFunc_O --- hpy/debug/src/debug_ctx_cpython.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index 12b2418ed..098d56cc0 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -25,6 +25,16 @@ #include "debug_internal.h" #include "handles.h" // for _py2h and _h2py +static inline DHPy _py2dh(HPyContext ctx, PyObject *obj) +{ + return DHPy_wrap(ctx, _py2h(obj)); +} + +static inline PyObject *_dh2py(DHPy dh) +{ + return _h2py(DHPy_unwrap(dh)); +} + void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args) @@ -33,13 +43,20 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, case HPyFunc_NOARGS: { HPyFunc_noargs f = (HPyFunc_noargs)func; _HPyFunc_args_NOARGS *a = (_HPyFunc_args_NOARGS*)args; - DHPy dh_self = DHPy_wrap(ctx, _py2h(a->self)); + DHPy dh_self = _py2dh(ctx, a->self); DHPy dh_result = f(ctx, dh_self); - a->result = _h2py(DHPy_unwrap(dh_result)); + a->result = _dh2py(dh_result); + // XXX: close dh_self return; } case HPyFunc_O: { - abort(); + HPyFunc_o f = (HPyFunc_o)func; + _HPyFunc_args_O *a = (_HPyFunc_args_O*)args; + DHPy dh_self = _py2dh(ctx, a->self); + DHPy dh_arg = _py2dh(ctx, a->arg); + a->result = _dh2py(f(ctx, dh_self, dh_arg)); + // XXX: close dh_self and dh_arg + return; } case HPyFunc_VARARGS: { abort(); From d7709716aee17eb56787be19b1a4475a156dfe84 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 15 Jan 2021 18:53:42 +0100 Subject: [PATCH 36/65] initialize the debug context at runtime instead of compile time. This will make it easier to create thrown-away contexts for tests --- hpy/debug/src/autogen_debug_ctx.h | 412 ------------------------- hpy/debug/src/autogen_debug_ctx_init.h | 333 ++++++++++++++++++++ hpy/debug/src/debug_ctx.c | 36 ++- hpy/tools/autogen/__main__.py | 4 +- hpy/tools/autogen/debug.py | 28 +- 5 files changed, 364 insertions(+), 449 deletions(-) delete mode 100644 hpy/debug/src/autogen_debug_ctx.h create mode 100644 hpy/debug/src/autogen_debug_ctx_init.h diff --git a/hpy/debug/src/autogen_debug_ctx.h b/hpy/debug/src/autogen_debug_ctx.h deleted file mode 100644 index d099f278a..000000000 --- a/hpy/debug/src/autogen_debug_ctx.h +++ /dev/null @@ -1,412 +0,0 @@ - -/* - DO NOT EDIT THIS FILE! - - This file is automatically generated by hpy.tools.autogen.debug.autogen_debug_ctx_h - See also hpy.tools.autogen and hpy/tools/public_api.h - - Run this to regenerate: - make autogen - -*/ - -DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def); -DHPy debug_ctx_Dup(HPyContext ctx, DHPy h); -void debug_ctx_Close(HPyContext ctx, DHPy h); -DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value); -DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value); -DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v); -DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v); -DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value); -DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value); -long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h); -unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h); -unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h); -long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h); -unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h); -unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h); -size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h); -DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v); -double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h); -int debug_ctx_Number_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); -DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Index(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Long(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Float(HPyContext ctx, DHPy h1); -DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); -DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2); -int debug_ctx_Callable_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw); -void debug_ctx_FatalError(HPyContext ctx, const char *message); -void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message); -void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value); -int debug_ctx_Err_Occurred(HPyContext ctx); -DHPy debug_ctx_Err_NoMemory(HPyContext ctx); -void debug_ctx_Err_Clear(HPyContext ctx); -int debug_ctx_IsTrue(HPyContext ctx, DHPy h); -DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params); -DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw); -DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name); -DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name); -int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name); -int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name); -int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value); -int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value); -DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key); -DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx); -DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key); -int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value); -int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value); -int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value); -void *debug_ctx_Cast(HPyContext ctx, DHPy h); -DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data); -DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj); -DHPy debug_ctx_Str(HPyContext ctx, DHPy obj); -DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj); -DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj); -DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op); -int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op); -HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj); -int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h); -char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h); -char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h); -DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v); -DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len); -DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8); -int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h); -DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size); -int debug_ctx_List_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len); -int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item); -int debug_ctx_Dict_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Dict_New(HPyContext ctx); -int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n); -DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj); -cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h); -void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args); -void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self); -HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item); -DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder); -void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder); -HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item); -DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder); -void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder); -HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size); -int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h); -void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht); -void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht); -void debug_ctx_Dump(HPyContext ctx, DHPy h); - -static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext uctx) -{ - ctx->h_None = DHPy_wrap(ctx, uctx->h_None); - ctx->h_True = DHPy_wrap(ctx, uctx->h_True); - ctx->h_False = DHPy_wrap(ctx, uctx->h_False); - ctx->h_BaseException = DHPy_wrap(ctx, uctx->h_BaseException); - ctx->h_Exception = DHPy_wrap(ctx, uctx->h_Exception); - ctx->h_StopAsyncIteration = DHPy_wrap(ctx, uctx->h_StopAsyncIteration); - ctx->h_StopIteration = DHPy_wrap(ctx, uctx->h_StopIteration); - ctx->h_GeneratorExit = DHPy_wrap(ctx, uctx->h_GeneratorExit); - ctx->h_ArithmeticError = DHPy_wrap(ctx, uctx->h_ArithmeticError); - ctx->h_LookupError = DHPy_wrap(ctx, uctx->h_LookupError); - ctx->h_AssertionError = DHPy_wrap(ctx, uctx->h_AssertionError); - ctx->h_AttributeError = DHPy_wrap(ctx, uctx->h_AttributeError); - ctx->h_BufferError = DHPy_wrap(ctx, uctx->h_BufferError); - ctx->h_EOFError = DHPy_wrap(ctx, uctx->h_EOFError); - ctx->h_FloatingPointError = DHPy_wrap(ctx, uctx->h_FloatingPointError); - ctx->h_OSError = DHPy_wrap(ctx, uctx->h_OSError); - ctx->h_ImportError = DHPy_wrap(ctx, uctx->h_ImportError); - ctx->h_ModuleNotFoundError = DHPy_wrap(ctx, uctx->h_ModuleNotFoundError); - ctx->h_IndexError = DHPy_wrap(ctx, uctx->h_IndexError); - ctx->h_KeyError = DHPy_wrap(ctx, uctx->h_KeyError); - ctx->h_KeyboardInterrupt = DHPy_wrap(ctx, uctx->h_KeyboardInterrupt); - ctx->h_MemoryError = DHPy_wrap(ctx, uctx->h_MemoryError); - ctx->h_NameError = DHPy_wrap(ctx, uctx->h_NameError); - ctx->h_OverflowError = DHPy_wrap(ctx, uctx->h_OverflowError); - ctx->h_RuntimeError = DHPy_wrap(ctx, uctx->h_RuntimeError); - ctx->h_RecursionError = DHPy_wrap(ctx, uctx->h_RecursionError); - ctx->h_NotImplementedError = DHPy_wrap(ctx, uctx->h_NotImplementedError); - ctx->h_SyntaxError = DHPy_wrap(ctx, uctx->h_SyntaxError); - ctx->h_IndentationError = DHPy_wrap(ctx, uctx->h_IndentationError); - ctx->h_TabError = DHPy_wrap(ctx, uctx->h_TabError); - ctx->h_ReferenceError = DHPy_wrap(ctx, uctx->h_ReferenceError); - ctx->h_SystemError = DHPy_wrap(ctx, uctx->h_SystemError); - ctx->h_SystemExit = DHPy_wrap(ctx, uctx->h_SystemExit); - ctx->h_TypeError = DHPy_wrap(ctx, uctx->h_TypeError); - ctx->h_UnboundLocalError = DHPy_wrap(ctx, uctx->h_UnboundLocalError); - ctx->h_UnicodeError = DHPy_wrap(ctx, uctx->h_UnicodeError); - ctx->h_UnicodeEncodeError = DHPy_wrap(ctx, uctx->h_UnicodeEncodeError); - ctx->h_UnicodeDecodeError = DHPy_wrap(ctx, uctx->h_UnicodeDecodeError); - ctx->h_UnicodeTranslateError = DHPy_wrap(ctx, uctx->h_UnicodeTranslateError); - ctx->h_ValueError = DHPy_wrap(ctx, uctx->h_ValueError); - ctx->h_ZeroDivisionError = DHPy_wrap(ctx, uctx->h_ZeroDivisionError); - ctx->h_BlockingIOError = DHPy_wrap(ctx, uctx->h_BlockingIOError); - ctx->h_BrokenPipeError = DHPy_wrap(ctx, uctx->h_BrokenPipeError); - ctx->h_ChildProcessError = DHPy_wrap(ctx, uctx->h_ChildProcessError); - ctx->h_ConnectionError = DHPy_wrap(ctx, uctx->h_ConnectionError); - ctx->h_ConnectionAbortedError = DHPy_wrap(ctx, uctx->h_ConnectionAbortedError); - ctx->h_ConnectionRefusedError = DHPy_wrap(ctx, uctx->h_ConnectionRefusedError); - ctx->h_ConnectionResetError = DHPy_wrap(ctx, uctx->h_ConnectionResetError); - ctx->h_FileExistsError = DHPy_wrap(ctx, uctx->h_FileExistsError); - ctx->h_FileNotFoundError = DHPy_wrap(ctx, uctx->h_FileNotFoundError); - ctx->h_InterruptedError = DHPy_wrap(ctx, uctx->h_InterruptedError); - ctx->h_IsADirectoryError = DHPy_wrap(ctx, uctx->h_IsADirectoryError); - ctx->h_NotADirectoryError = DHPy_wrap(ctx, uctx->h_NotADirectoryError); - ctx->h_PermissionError = DHPy_wrap(ctx, uctx->h_PermissionError); - ctx->h_ProcessLookupError = DHPy_wrap(ctx, uctx->h_ProcessLookupError); - ctx->h_TimeoutError = DHPy_wrap(ctx, uctx->h_TimeoutError); - ctx->h_Warning = DHPy_wrap(ctx, uctx->h_Warning); - ctx->h_UserWarning = DHPy_wrap(ctx, uctx->h_UserWarning); - ctx->h_DeprecationWarning = DHPy_wrap(ctx, uctx->h_DeprecationWarning); - ctx->h_PendingDeprecationWarning = DHPy_wrap(ctx, uctx->h_PendingDeprecationWarning); - ctx->h_SyntaxWarning = DHPy_wrap(ctx, uctx->h_SyntaxWarning); - ctx->h_RuntimeWarning = DHPy_wrap(ctx, uctx->h_RuntimeWarning); - ctx->h_FutureWarning = DHPy_wrap(ctx, uctx->h_FutureWarning); - ctx->h_ImportWarning = DHPy_wrap(ctx, uctx->h_ImportWarning); - ctx->h_UnicodeWarning = DHPy_wrap(ctx, uctx->h_UnicodeWarning); - ctx->h_BytesWarning = DHPy_wrap(ctx, uctx->h_BytesWarning); - ctx->h_ResourceWarning = DHPy_wrap(ctx, uctx->h_ResourceWarning); - ctx->h_BaseObjectType = DHPy_wrap(ctx, uctx->h_BaseObjectType); - ctx->h_TypeType = DHPy_wrap(ctx, uctx->h_TypeType); - ctx->h_LongType = DHPy_wrap(ctx, uctx->h_LongType); - ctx->h_UnicodeType = DHPy_wrap(ctx, uctx->h_UnicodeType); - ctx->h_TupleType = DHPy_wrap(ctx, uctx->h_TupleType); - ctx->h_ListType = DHPy_wrap(ctx, uctx->h_ListType); -} - -struct _HPyContext_s g_debug_ctx = { - .name = "HPy Debug Mode ABI", - ._private = NULL, - .ctx_version = 1, - .h_None = HPy_NULL, - .h_True = HPy_NULL, - .h_False = HPy_NULL, - .h_BaseException = HPy_NULL, - .h_Exception = HPy_NULL, - .h_StopAsyncIteration = HPy_NULL, - .h_StopIteration = HPy_NULL, - .h_GeneratorExit = HPy_NULL, - .h_ArithmeticError = HPy_NULL, - .h_LookupError = HPy_NULL, - .h_AssertionError = HPy_NULL, - .h_AttributeError = HPy_NULL, - .h_BufferError = HPy_NULL, - .h_EOFError = HPy_NULL, - .h_FloatingPointError = HPy_NULL, - .h_OSError = HPy_NULL, - .h_ImportError = HPy_NULL, - .h_ModuleNotFoundError = HPy_NULL, - .h_IndexError = HPy_NULL, - .h_KeyError = HPy_NULL, - .h_KeyboardInterrupt = HPy_NULL, - .h_MemoryError = HPy_NULL, - .h_NameError = HPy_NULL, - .h_OverflowError = HPy_NULL, - .h_RuntimeError = HPy_NULL, - .h_RecursionError = HPy_NULL, - .h_NotImplementedError = HPy_NULL, - .h_SyntaxError = HPy_NULL, - .h_IndentationError = HPy_NULL, - .h_TabError = HPy_NULL, - .h_ReferenceError = HPy_NULL, - .h_SystemError = HPy_NULL, - .h_SystemExit = HPy_NULL, - .h_TypeError = HPy_NULL, - .h_UnboundLocalError = HPy_NULL, - .h_UnicodeError = HPy_NULL, - .h_UnicodeEncodeError = HPy_NULL, - .h_UnicodeDecodeError = HPy_NULL, - .h_UnicodeTranslateError = HPy_NULL, - .h_ValueError = HPy_NULL, - .h_ZeroDivisionError = HPy_NULL, - .h_BlockingIOError = HPy_NULL, - .h_BrokenPipeError = HPy_NULL, - .h_ChildProcessError = HPy_NULL, - .h_ConnectionError = HPy_NULL, - .h_ConnectionAbortedError = HPy_NULL, - .h_ConnectionRefusedError = HPy_NULL, - .h_ConnectionResetError = HPy_NULL, - .h_FileExistsError = HPy_NULL, - .h_FileNotFoundError = HPy_NULL, - .h_InterruptedError = HPy_NULL, - .h_IsADirectoryError = HPy_NULL, - .h_NotADirectoryError = HPy_NULL, - .h_PermissionError = HPy_NULL, - .h_ProcessLookupError = HPy_NULL, - .h_TimeoutError = HPy_NULL, - .h_Warning = HPy_NULL, - .h_UserWarning = HPy_NULL, - .h_DeprecationWarning = HPy_NULL, - .h_PendingDeprecationWarning = HPy_NULL, - .h_SyntaxWarning = HPy_NULL, - .h_RuntimeWarning = HPy_NULL, - .h_FutureWarning = HPy_NULL, - .h_ImportWarning = HPy_NULL, - .h_UnicodeWarning = HPy_NULL, - .h_BytesWarning = HPy_NULL, - .h_ResourceWarning = HPy_NULL, - .h_BaseObjectType = HPy_NULL, - .h_TypeType = HPy_NULL, - .h_LongType = HPy_NULL, - .h_UnicodeType = HPy_NULL, - .h_TupleType = HPy_NULL, - .h_ListType = HPy_NULL, - .ctx_Module_Create = &debug_ctx_Module_Create, - .ctx_Dup = &debug_ctx_Dup, - .ctx_Close = &debug_ctx_Close, - .ctx_Long_FromLong = &debug_ctx_Long_FromLong, - .ctx_Long_FromUnsignedLong = &debug_ctx_Long_FromUnsignedLong, - .ctx_Long_FromLongLong = &debug_ctx_Long_FromLongLong, - .ctx_Long_FromUnsignedLongLong = &debug_ctx_Long_FromUnsignedLongLong, - .ctx_Long_FromSize_t = &debug_ctx_Long_FromSize_t, - .ctx_Long_FromSsize_t = &debug_ctx_Long_FromSsize_t, - .ctx_Long_AsLong = &debug_ctx_Long_AsLong, - .ctx_Long_AsUnsignedLong = &debug_ctx_Long_AsUnsignedLong, - .ctx_Long_AsUnsignedLongMask = &debug_ctx_Long_AsUnsignedLongMask, - .ctx_Long_AsLongLong = &debug_ctx_Long_AsLongLong, - .ctx_Long_AsUnsignedLongLong = &debug_ctx_Long_AsUnsignedLongLong, - .ctx_Long_AsUnsignedLongLongMask = &debug_ctx_Long_AsUnsignedLongLongMask, - .ctx_Long_AsSize_t = &debug_ctx_Long_AsSize_t, - .ctx_Long_AsSsize_t = &debug_ctx_Long_AsSsize_t, - .ctx_Float_FromDouble = &debug_ctx_Float_FromDouble, - .ctx_Float_AsDouble = &debug_ctx_Float_AsDouble, - .ctx_Length = &debug_ctx_Length, - .ctx_Number_Check = &debug_ctx_Number_Check, - .ctx_Add = &debug_ctx_Add, - .ctx_Subtract = &debug_ctx_Subtract, - .ctx_Multiply = &debug_ctx_Multiply, - .ctx_MatrixMultiply = &debug_ctx_MatrixMultiply, - .ctx_FloorDivide = &debug_ctx_FloorDivide, - .ctx_TrueDivide = &debug_ctx_TrueDivide, - .ctx_Remainder = &debug_ctx_Remainder, - .ctx_Divmod = &debug_ctx_Divmod, - .ctx_Power = &debug_ctx_Power, - .ctx_Negative = &debug_ctx_Negative, - .ctx_Positive = &debug_ctx_Positive, - .ctx_Absolute = &debug_ctx_Absolute, - .ctx_Invert = &debug_ctx_Invert, - .ctx_Lshift = &debug_ctx_Lshift, - .ctx_Rshift = &debug_ctx_Rshift, - .ctx_And = &debug_ctx_And, - .ctx_Xor = &debug_ctx_Xor, - .ctx_Or = &debug_ctx_Or, - .ctx_Index = &debug_ctx_Index, - .ctx_Long = &debug_ctx_Long, - .ctx_Float = &debug_ctx_Float, - .ctx_InPlaceAdd = &debug_ctx_InPlaceAdd, - .ctx_InPlaceSubtract = &debug_ctx_InPlaceSubtract, - .ctx_InPlaceMultiply = &debug_ctx_InPlaceMultiply, - .ctx_InPlaceMatrixMultiply = &debug_ctx_InPlaceMatrixMultiply, - .ctx_InPlaceFloorDivide = &debug_ctx_InPlaceFloorDivide, - .ctx_InPlaceTrueDivide = &debug_ctx_InPlaceTrueDivide, - .ctx_InPlaceRemainder = &debug_ctx_InPlaceRemainder, - .ctx_InPlacePower = &debug_ctx_InPlacePower, - .ctx_InPlaceLshift = &debug_ctx_InPlaceLshift, - .ctx_InPlaceRshift = &debug_ctx_InPlaceRshift, - .ctx_InPlaceAnd = &debug_ctx_InPlaceAnd, - .ctx_InPlaceXor = &debug_ctx_InPlaceXor, - .ctx_InPlaceOr = &debug_ctx_InPlaceOr, - .ctx_Callable_Check = &debug_ctx_Callable_Check, - .ctx_CallTupleDict = &debug_ctx_CallTupleDict, - .ctx_FatalError = &debug_ctx_FatalError, - .ctx_Err_SetString = &debug_ctx_Err_SetString, - .ctx_Err_SetObject = &debug_ctx_Err_SetObject, - .ctx_Err_Occurred = &debug_ctx_Err_Occurred, - .ctx_Err_NoMemory = &debug_ctx_Err_NoMemory, - .ctx_Err_Clear = &debug_ctx_Err_Clear, - .ctx_IsTrue = &debug_ctx_IsTrue, - .ctx_Type_FromSpec = &debug_ctx_Type_FromSpec, - .ctx_Type_GenericNew = &debug_ctx_Type_GenericNew, - .ctx_GetAttr = &debug_ctx_GetAttr, - .ctx_GetAttr_s = &debug_ctx_GetAttr_s, - .ctx_HasAttr = &debug_ctx_HasAttr, - .ctx_HasAttr_s = &debug_ctx_HasAttr_s, - .ctx_SetAttr = &debug_ctx_SetAttr, - .ctx_SetAttr_s = &debug_ctx_SetAttr_s, - .ctx_GetItem = &debug_ctx_GetItem, - .ctx_GetItem_i = &debug_ctx_GetItem_i, - .ctx_GetItem_s = &debug_ctx_GetItem_s, - .ctx_SetItem = &debug_ctx_SetItem, - .ctx_SetItem_i = &debug_ctx_SetItem_i, - .ctx_SetItem_s = &debug_ctx_SetItem_s, - .ctx_Cast = &debug_ctx_Cast, - .ctx_New = &debug_ctx_New, - .ctx_Repr = &debug_ctx_Repr, - .ctx_Str = &debug_ctx_Str, - .ctx_ASCII = &debug_ctx_ASCII, - .ctx_Bytes = &debug_ctx_Bytes, - .ctx_RichCompare = &debug_ctx_RichCompare, - .ctx_RichCompareBool = &debug_ctx_RichCompareBool, - .ctx_Hash = &debug_ctx_Hash, - .ctx_Bytes_Check = &debug_ctx_Bytes_Check, - .ctx_Bytes_Size = &debug_ctx_Bytes_Size, - .ctx_Bytes_GET_SIZE = &debug_ctx_Bytes_GET_SIZE, - .ctx_Bytes_AsString = &debug_ctx_Bytes_AsString, - .ctx_Bytes_AS_STRING = &debug_ctx_Bytes_AS_STRING, - .ctx_Bytes_FromString = &debug_ctx_Bytes_FromString, - .ctx_Bytes_FromStringAndSize = &debug_ctx_Bytes_FromStringAndSize, - .ctx_Unicode_FromString = &debug_ctx_Unicode_FromString, - .ctx_Unicode_Check = &debug_ctx_Unicode_Check, - .ctx_Unicode_AsUTF8String = &debug_ctx_Unicode_AsUTF8String, - .ctx_Unicode_FromWideChar = &debug_ctx_Unicode_FromWideChar, - .ctx_List_Check = &debug_ctx_List_Check, - .ctx_List_New = &debug_ctx_List_New, - .ctx_List_Append = &debug_ctx_List_Append, - .ctx_Dict_Check = &debug_ctx_Dict_Check, - .ctx_Dict_New = &debug_ctx_Dict_New, - .ctx_Tuple_Check = &debug_ctx_Tuple_Check, - .ctx_Tuple_FromArray = &debug_ctx_Tuple_FromArray, - .ctx_FromPyObject = &debug_ctx_FromPyObject, - .ctx_AsPyObject = &debug_ctx_AsPyObject, - .ctx_CallRealFunctionFromTrampoline = &debug_ctx_CallRealFunctionFromTrampoline, - .ctx_CallDestroyAndThenDealloc = &debug_ctx_CallDestroyAndThenDealloc, - .ctx_ListBuilder_New = &debug_ctx_ListBuilder_New, - .ctx_ListBuilder_Set = &debug_ctx_ListBuilder_Set, - .ctx_ListBuilder_Build = &debug_ctx_ListBuilder_Build, - .ctx_ListBuilder_Cancel = &debug_ctx_ListBuilder_Cancel, - .ctx_TupleBuilder_New = &debug_ctx_TupleBuilder_New, - .ctx_TupleBuilder_Set = &debug_ctx_TupleBuilder_Set, - .ctx_TupleBuilder_Build = &debug_ctx_TupleBuilder_Build, - .ctx_TupleBuilder_Cancel = &debug_ctx_TupleBuilder_Cancel, - .ctx_Tracker_New = &debug_ctx_Tracker_New, - .ctx_Tracker_Add = &debug_ctx_Tracker_Add, - .ctx_Tracker_ForgetAll = &debug_ctx_Tracker_ForgetAll, - .ctx_Tracker_Close = &debug_ctx_Tracker_Close, - .ctx_Dump = &debug_ctx_Dump, -}; diff --git a/hpy/debug/src/autogen_debug_ctx_init.h b/hpy/debug/src/autogen_debug_ctx_init.h new file mode 100644 index 000000000..85dfd406e --- /dev/null +++ b/hpy/debug/src/autogen_debug_ctx_init.h @@ -0,0 +1,333 @@ + +/* + DO NOT EDIT THIS FILE! + + This file is automatically generated by hpy.tools.autogen.debug.autogen_debug_ctx_init_h + See also hpy.tools.autogen and hpy/tools/public_api.h + + Run this to regenerate: + make autogen + +*/ + +DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def); +DHPy debug_ctx_Dup(HPyContext ctx, DHPy h); +void debug_ctx_Close(HPyContext ctx, DHPy h); +DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value); +DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value); +DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v); +DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v); +DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value); +DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value); +long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h); +unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h); +unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h); +long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h); +unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h); +unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h); +size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h); +HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h); +DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v); +double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h); +HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h); +int debug_ctx_Number_Check(HPyContext ctx, DHPy h); +DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); +DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1); +DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1); +DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1); +DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1); +DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Index(HPyContext ctx, DHPy h1); +DHPy debug_ctx_Long(HPyContext ctx, DHPy h1); +DHPy debug_ctx_Float(HPyContext ctx, DHPy h1); +DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); +DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2); +int debug_ctx_Callable_Check(HPyContext ctx, DHPy h); +DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw); +void debug_ctx_FatalError(HPyContext ctx, const char *message); +void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message); +void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value); +int debug_ctx_Err_Occurred(HPyContext ctx); +DHPy debug_ctx_Err_NoMemory(HPyContext ctx); +void debug_ctx_Err_Clear(HPyContext ctx); +int debug_ctx_IsTrue(HPyContext ctx, DHPy h); +DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params); +DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw); +DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name); +DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name); +int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name); +int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name); +int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value); +int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value); +DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key); +DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx); +DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key); +int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value); +int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value); +int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value); +void *debug_ctx_Cast(HPyContext ctx, DHPy h); +DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data); +DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj); +DHPy debug_ctx_Str(HPyContext ctx, DHPy obj); +DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj); +DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj); +DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op); +int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op); +HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj); +int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h); +HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h); +HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h); +char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h); +char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h); +DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v); +DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len); +DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8); +int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h); +DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h); +DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size); +int debug_ctx_List_Check(HPyContext ctx, DHPy h); +DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len); +int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item); +int debug_ctx_Dict_Check(HPyContext ctx, DHPy h); +DHPy debug_ctx_Dict_New(HPyContext ctx); +int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h); +DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n); +DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj); +cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h); +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args); +void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self); +HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); +void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item); +DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder); +void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder); +HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); +void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item); +DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder); +void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder); +HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size); +int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h); +void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht); +void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht); +void debug_ctx_Dump(HPyContext ctx, DHPy h); + +static inline void debug_ctx_init_fields(HPyContext dctx, HPyContext uctx) +{ + dctx->h_None = DHPy_wrap(dctx, uctx->h_None); + dctx->h_True = DHPy_wrap(dctx, uctx->h_True); + dctx->h_False = DHPy_wrap(dctx, uctx->h_False); + dctx->h_BaseException = DHPy_wrap(dctx, uctx->h_BaseException); + dctx->h_Exception = DHPy_wrap(dctx, uctx->h_Exception); + dctx->h_StopAsyncIteration = DHPy_wrap(dctx, uctx->h_StopAsyncIteration); + dctx->h_StopIteration = DHPy_wrap(dctx, uctx->h_StopIteration); + dctx->h_GeneratorExit = DHPy_wrap(dctx, uctx->h_GeneratorExit); + dctx->h_ArithmeticError = DHPy_wrap(dctx, uctx->h_ArithmeticError); + dctx->h_LookupError = DHPy_wrap(dctx, uctx->h_LookupError); + dctx->h_AssertionError = DHPy_wrap(dctx, uctx->h_AssertionError); + dctx->h_AttributeError = DHPy_wrap(dctx, uctx->h_AttributeError); + dctx->h_BufferError = DHPy_wrap(dctx, uctx->h_BufferError); + dctx->h_EOFError = DHPy_wrap(dctx, uctx->h_EOFError); + dctx->h_FloatingPointError = DHPy_wrap(dctx, uctx->h_FloatingPointError); + dctx->h_OSError = DHPy_wrap(dctx, uctx->h_OSError); + dctx->h_ImportError = DHPy_wrap(dctx, uctx->h_ImportError); + dctx->h_ModuleNotFoundError = DHPy_wrap(dctx, uctx->h_ModuleNotFoundError); + dctx->h_IndexError = DHPy_wrap(dctx, uctx->h_IndexError); + dctx->h_KeyError = DHPy_wrap(dctx, uctx->h_KeyError); + dctx->h_KeyboardInterrupt = DHPy_wrap(dctx, uctx->h_KeyboardInterrupt); + dctx->h_MemoryError = DHPy_wrap(dctx, uctx->h_MemoryError); + dctx->h_NameError = DHPy_wrap(dctx, uctx->h_NameError); + dctx->h_OverflowError = DHPy_wrap(dctx, uctx->h_OverflowError); + dctx->h_RuntimeError = DHPy_wrap(dctx, uctx->h_RuntimeError); + dctx->h_RecursionError = DHPy_wrap(dctx, uctx->h_RecursionError); + dctx->h_NotImplementedError = DHPy_wrap(dctx, uctx->h_NotImplementedError); + dctx->h_SyntaxError = DHPy_wrap(dctx, uctx->h_SyntaxError); + dctx->h_IndentationError = DHPy_wrap(dctx, uctx->h_IndentationError); + dctx->h_TabError = DHPy_wrap(dctx, uctx->h_TabError); + dctx->h_ReferenceError = DHPy_wrap(dctx, uctx->h_ReferenceError); + dctx->h_SystemError = DHPy_wrap(dctx, uctx->h_SystemError); + dctx->h_SystemExit = DHPy_wrap(dctx, uctx->h_SystemExit); + dctx->h_TypeError = DHPy_wrap(dctx, uctx->h_TypeError); + dctx->h_UnboundLocalError = DHPy_wrap(dctx, uctx->h_UnboundLocalError); + dctx->h_UnicodeError = DHPy_wrap(dctx, uctx->h_UnicodeError); + dctx->h_UnicodeEncodeError = DHPy_wrap(dctx, uctx->h_UnicodeEncodeError); + dctx->h_UnicodeDecodeError = DHPy_wrap(dctx, uctx->h_UnicodeDecodeError); + dctx->h_UnicodeTranslateError = DHPy_wrap(dctx, uctx->h_UnicodeTranslateError); + dctx->h_ValueError = DHPy_wrap(dctx, uctx->h_ValueError); + dctx->h_ZeroDivisionError = DHPy_wrap(dctx, uctx->h_ZeroDivisionError); + dctx->h_BlockingIOError = DHPy_wrap(dctx, uctx->h_BlockingIOError); + dctx->h_BrokenPipeError = DHPy_wrap(dctx, uctx->h_BrokenPipeError); + dctx->h_ChildProcessError = DHPy_wrap(dctx, uctx->h_ChildProcessError); + dctx->h_ConnectionError = DHPy_wrap(dctx, uctx->h_ConnectionError); + dctx->h_ConnectionAbortedError = DHPy_wrap(dctx, uctx->h_ConnectionAbortedError); + dctx->h_ConnectionRefusedError = DHPy_wrap(dctx, uctx->h_ConnectionRefusedError); + dctx->h_ConnectionResetError = DHPy_wrap(dctx, uctx->h_ConnectionResetError); + dctx->h_FileExistsError = DHPy_wrap(dctx, uctx->h_FileExistsError); + dctx->h_FileNotFoundError = DHPy_wrap(dctx, uctx->h_FileNotFoundError); + dctx->h_InterruptedError = DHPy_wrap(dctx, uctx->h_InterruptedError); + dctx->h_IsADirectoryError = DHPy_wrap(dctx, uctx->h_IsADirectoryError); + dctx->h_NotADirectoryError = DHPy_wrap(dctx, uctx->h_NotADirectoryError); + dctx->h_PermissionError = DHPy_wrap(dctx, uctx->h_PermissionError); + dctx->h_ProcessLookupError = DHPy_wrap(dctx, uctx->h_ProcessLookupError); + dctx->h_TimeoutError = DHPy_wrap(dctx, uctx->h_TimeoutError); + dctx->h_Warning = DHPy_wrap(dctx, uctx->h_Warning); + dctx->h_UserWarning = DHPy_wrap(dctx, uctx->h_UserWarning); + dctx->h_DeprecationWarning = DHPy_wrap(dctx, uctx->h_DeprecationWarning); + dctx->h_PendingDeprecationWarning = DHPy_wrap(dctx, uctx->h_PendingDeprecationWarning); + dctx->h_SyntaxWarning = DHPy_wrap(dctx, uctx->h_SyntaxWarning); + dctx->h_RuntimeWarning = DHPy_wrap(dctx, uctx->h_RuntimeWarning); + dctx->h_FutureWarning = DHPy_wrap(dctx, uctx->h_FutureWarning); + dctx->h_ImportWarning = DHPy_wrap(dctx, uctx->h_ImportWarning); + dctx->h_UnicodeWarning = DHPy_wrap(dctx, uctx->h_UnicodeWarning); + dctx->h_BytesWarning = DHPy_wrap(dctx, uctx->h_BytesWarning); + dctx->h_ResourceWarning = DHPy_wrap(dctx, uctx->h_ResourceWarning); + dctx->h_BaseObjectType = DHPy_wrap(dctx, uctx->h_BaseObjectType); + dctx->h_TypeType = DHPy_wrap(dctx, uctx->h_TypeType); + dctx->h_LongType = DHPy_wrap(dctx, uctx->h_LongType); + dctx->h_UnicodeType = DHPy_wrap(dctx, uctx->h_UnicodeType); + dctx->h_TupleType = DHPy_wrap(dctx, uctx->h_TupleType); + dctx->h_ListType = DHPy_wrap(dctx, uctx->h_ListType); + dctx->ctx_Module_Create = &debug_ctx_Module_Create; + dctx->ctx_Dup = &debug_ctx_Dup; + dctx->ctx_Close = &debug_ctx_Close; + dctx->ctx_Long_FromLong = &debug_ctx_Long_FromLong; + dctx->ctx_Long_FromUnsignedLong = &debug_ctx_Long_FromUnsignedLong; + dctx->ctx_Long_FromLongLong = &debug_ctx_Long_FromLongLong; + dctx->ctx_Long_FromUnsignedLongLong = &debug_ctx_Long_FromUnsignedLongLong; + dctx->ctx_Long_FromSize_t = &debug_ctx_Long_FromSize_t; + dctx->ctx_Long_FromSsize_t = &debug_ctx_Long_FromSsize_t; + dctx->ctx_Long_AsLong = &debug_ctx_Long_AsLong; + dctx->ctx_Long_AsUnsignedLong = &debug_ctx_Long_AsUnsignedLong; + dctx->ctx_Long_AsUnsignedLongMask = &debug_ctx_Long_AsUnsignedLongMask; + dctx->ctx_Long_AsLongLong = &debug_ctx_Long_AsLongLong; + dctx->ctx_Long_AsUnsignedLongLong = &debug_ctx_Long_AsUnsignedLongLong; + dctx->ctx_Long_AsUnsignedLongLongMask = &debug_ctx_Long_AsUnsignedLongLongMask; + dctx->ctx_Long_AsSize_t = &debug_ctx_Long_AsSize_t; + dctx->ctx_Long_AsSsize_t = &debug_ctx_Long_AsSsize_t; + dctx->ctx_Float_FromDouble = &debug_ctx_Float_FromDouble; + dctx->ctx_Float_AsDouble = &debug_ctx_Float_AsDouble; + dctx->ctx_Length = &debug_ctx_Length; + dctx->ctx_Number_Check = &debug_ctx_Number_Check; + dctx->ctx_Add = &debug_ctx_Add; + dctx->ctx_Subtract = &debug_ctx_Subtract; + dctx->ctx_Multiply = &debug_ctx_Multiply; + dctx->ctx_MatrixMultiply = &debug_ctx_MatrixMultiply; + dctx->ctx_FloorDivide = &debug_ctx_FloorDivide; + dctx->ctx_TrueDivide = &debug_ctx_TrueDivide; + dctx->ctx_Remainder = &debug_ctx_Remainder; + dctx->ctx_Divmod = &debug_ctx_Divmod; + dctx->ctx_Power = &debug_ctx_Power; + dctx->ctx_Negative = &debug_ctx_Negative; + dctx->ctx_Positive = &debug_ctx_Positive; + dctx->ctx_Absolute = &debug_ctx_Absolute; + dctx->ctx_Invert = &debug_ctx_Invert; + dctx->ctx_Lshift = &debug_ctx_Lshift; + dctx->ctx_Rshift = &debug_ctx_Rshift; + dctx->ctx_And = &debug_ctx_And; + dctx->ctx_Xor = &debug_ctx_Xor; + dctx->ctx_Or = &debug_ctx_Or; + dctx->ctx_Index = &debug_ctx_Index; + dctx->ctx_Long = &debug_ctx_Long; + dctx->ctx_Float = &debug_ctx_Float; + dctx->ctx_InPlaceAdd = &debug_ctx_InPlaceAdd; + dctx->ctx_InPlaceSubtract = &debug_ctx_InPlaceSubtract; + dctx->ctx_InPlaceMultiply = &debug_ctx_InPlaceMultiply; + dctx->ctx_InPlaceMatrixMultiply = &debug_ctx_InPlaceMatrixMultiply; + dctx->ctx_InPlaceFloorDivide = &debug_ctx_InPlaceFloorDivide; + dctx->ctx_InPlaceTrueDivide = &debug_ctx_InPlaceTrueDivide; + dctx->ctx_InPlaceRemainder = &debug_ctx_InPlaceRemainder; + dctx->ctx_InPlacePower = &debug_ctx_InPlacePower; + dctx->ctx_InPlaceLshift = &debug_ctx_InPlaceLshift; + dctx->ctx_InPlaceRshift = &debug_ctx_InPlaceRshift; + dctx->ctx_InPlaceAnd = &debug_ctx_InPlaceAnd; + dctx->ctx_InPlaceXor = &debug_ctx_InPlaceXor; + dctx->ctx_InPlaceOr = &debug_ctx_InPlaceOr; + dctx->ctx_Callable_Check = &debug_ctx_Callable_Check; + dctx->ctx_CallTupleDict = &debug_ctx_CallTupleDict; + dctx->ctx_FatalError = &debug_ctx_FatalError; + dctx->ctx_Err_SetString = &debug_ctx_Err_SetString; + dctx->ctx_Err_SetObject = &debug_ctx_Err_SetObject; + dctx->ctx_Err_Occurred = &debug_ctx_Err_Occurred; + dctx->ctx_Err_NoMemory = &debug_ctx_Err_NoMemory; + dctx->ctx_Err_Clear = &debug_ctx_Err_Clear; + dctx->ctx_IsTrue = &debug_ctx_IsTrue; + dctx->ctx_Type_FromSpec = &debug_ctx_Type_FromSpec; + dctx->ctx_Type_GenericNew = &debug_ctx_Type_GenericNew; + dctx->ctx_GetAttr = &debug_ctx_GetAttr; + dctx->ctx_GetAttr_s = &debug_ctx_GetAttr_s; + dctx->ctx_HasAttr = &debug_ctx_HasAttr; + dctx->ctx_HasAttr_s = &debug_ctx_HasAttr_s; + dctx->ctx_SetAttr = &debug_ctx_SetAttr; + dctx->ctx_SetAttr_s = &debug_ctx_SetAttr_s; + dctx->ctx_GetItem = &debug_ctx_GetItem; + dctx->ctx_GetItem_i = &debug_ctx_GetItem_i; + dctx->ctx_GetItem_s = &debug_ctx_GetItem_s; + dctx->ctx_SetItem = &debug_ctx_SetItem; + dctx->ctx_SetItem_i = &debug_ctx_SetItem_i; + dctx->ctx_SetItem_s = &debug_ctx_SetItem_s; + dctx->ctx_Cast = &debug_ctx_Cast; + dctx->ctx_New = &debug_ctx_New; + dctx->ctx_Repr = &debug_ctx_Repr; + dctx->ctx_Str = &debug_ctx_Str; + dctx->ctx_ASCII = &debug_ctx_ASCII; + dctx->ctx_Bytes = &debug_ctx_Bytes; + dctx->ctx_RichCompare = &debug_ctx_RichCompare; + dctx->ctx_RichCompareBool = &debug_ctx_RichCompareBool; + dctx->ctx_Hash = &debug_ctx_Hash; + dctx->ctx_Bytes_Check = &debug_ctx_Bytes_Check; + dctx->ctx_Bytes_Size = &debug_ctx_Bytes_Size; + dctx->ctx_Bytes_GET_SIZE = &debug_ctx_Bytes_GET_SIZE; + dctx->ctx_Bytes_AsString = &debug_ctx_Bytes_AsString; + dctx->ctx_Bytes_AS_STRING = &debug_ctx_Bytes_AS_STRING; + dctx->ctx_Bytes_FromString = &debug_ctx_Bytes_FromString; + dctx->ctx_Bytes_FromStringAndSize = &debug_ctx_Bytes_FromStringAndSize; + dctx->ctx_Unicode_FromString = &debug_ctx_Unicode_FromString; + dctx->ctx_Unicode_Check = &debug_ctx_Unicode_Check; + dctx->ctx_Unicode_AsUTF8String = &debug_ctx_Unicode_AsUTF8String; + dctx->ctx_Unicode_FromWideChar = &debug_ctx_Unicode_FromWideChar; + dctx->ctx_List_Check = &debug_ctx_List_Check; + dctx->ctx_List_New = &debug_ctx_List_New; + dctx->ctx_List_Append = &debug_ctx_List_Append; + dctx->ctx_Dict_Check = &debug_ctx_Dict_Check; + dctx->ctx_Dict_New = &debug_ctx_Dict_New; + dctx->ctx_Tuple_Check = &debug_ctx_Tuple_Check; + dctx->ctx_Tuple_FromArray = &debug_ctx_Tuple_FromArray; + dctx->ctx_FromPyObject = &debug_ctx_FromPyObject; + dctx->ctx_AsPyObject = &debug_ctx_AsPyObject; + dctx->ctx_CallRealFunctionFromTrampoline = &debug_ctx_CallRealFunctionFromTrampoline; + dctx->ctx_CallDestroyAndThenDealloc = &debug_ctx_CallDestroyAndThenDealloc; + dctx->ctx_ListBuilder_New = &debug_ctx_ListBuilder_New; + dctx->ctx_ListBuilder_Set = &debug_ctx_ListBuilder_Set; + dctx->ctx_ListBuilder_Build = &debug_ctx_ListBuilder_Build; + dctx->ctx_ListBuilder_Cancel = &debug_ctx_ListBuilder_Cancel; + dctx->ctx_TupleBuilder_New = &debug_ctx_TupleBuilder_New; + dctx->ctx_TupleBuilder_Set = &debug_ctx_TupleBuilder_Set; + dctx->ctx_TupleBuilder_Build = &debug_ctx_TupleBuilder_Build; + dctx->ctx_TupleBuilder_Cancel = &debug_ctx_TupleBuilder_Cancel; + dctx->ctx_Tracker_New = &debug_ctx_Tracker_New; + dctx->ctx_Tracker_Add = &debug_ctx_Tracker_Add; + dctx->ctx_Tracker_ForgetAll = &debug_ctx_Tracker_ForgetAll; + dctx->ctx_Tracker_Close = &debug_ctx_Tracker_Close; + dctx->ctx_Dump = &debug_ctx_Dump; +} diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index b6f65e449..9d08106d3 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -1,39 +1,43 @@ #include #include #include "debug_internal.h" -#include "autogen_debug_ctx.h" +#include "autogen_debug_ctx_init.h" -static HPyDebugInfo debug_info = { - .magic_number = HPY_DEBUG_MAGIC, - .uctx = NULL, +static struct _HPyContext_s g_debug_ctx = { + .name = "HPy Debug Mode ABI", + ._private = NULL, + .ctx_version = 1, }; + // NOTE: at the moment this function assumes that uctx is always the // same. If/when we migrate to a system in which we can have multiple // independent contexts, this function should ensure to create a different // debug wrapper for each of them. -static void debug_ctx_init(HPyContext uctx) +static void debug_ctx_init(HPyContext dctx, HPyContext uctx) { - if (g_debug_ctx._private != NULL) { + if (dctx->_private != NULL) { // already initialized - assert(get_info(&g_debug_ctx)->uctx == uctx); // sanity check + assert(get_info(dctx)->uctx == uctx); // sanity check return; } - // initialize debug_info - debug_info.uctx = uctx; - debug_info.open_handles = NULL; - debug_info.closed_handles = NULL; - g_debug_ctx._private = &debug_info; + // XXX: currently we never free this malloc + HPyDebugInfo *info = malloc(sizeof(HPyDebugInfo)); + info->magic_number = HPY_DEBUG_MAGIC; + info->uctx = uctx; + info->open_handles = NULL; + info->closed_handles = NULL; + dctx->_private = info; - // initialze ctx->h_None, etc. - debug_init_prebuilt_handles(&g_debug_ctx, uctx); + debug_ctx_init_fields(dctx, uctx); } HPyContext hpy_debug_get_ctx(HPyContext uctx) { - debug_ctx_init(uctx); - return &g_debug_ctx; + HPyContext dctx = &g_debug_ctx; + debug_ctx_init(dctx, uctx); + return dctx; } // this function is supposed to be called from gdb: it tries to determine diff --git a/hpy/tools/autogen/__main__.py b/hpy/tools/autogen/__main__.py index aeec3899c..de5a5dc56 100644 --- a/hpy/tools/autogen/__main__.py +++ b/hpy/tools/autogen/__main__.py @@ -16,7 +16,7 @@ from .hpyfunc import autogen_ctx_call_i from .hpyfunc import autogen_cpython_hpyfunc_trampoline_h from .hpyslot import autogen_hpyslot_h -from .debug import autogen_debug_ctx_h, autogen_debug_wrappers +from .debug import autogen_debug_ctx_init_h, autogen_debug_wrappers from .pypy import autogen_pypy_txt def main(): @@ -38,7 +38,7 @@ def main(): autogen_ctx_call_i, autogen_cpython_hpyfunc_trampoline_h, autogen_hpyslot_h, - autogen_debug_ctx_h, + autogen_debug_ctx_init_h, autogen_debug_wrappers, autogen_pypy_txt): cls(api).write(outdir) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index 64d27e86e..25c3c7bad 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -25,8 +25,8 @@ def get_debug_wrapper_node(func): return newnode -class autogen_debug_ctx_h(AutoGenFile): - PATH = 'hpy/debug/src/autogen_debug_ctx.h' +class autogen_debug_ctx_init_h(AutoGenFile): + PATH = 'hpy/debug/src/autogen_debug_ctx_init.h' def generate(self): lines = [] @@ -35,27 +35,17 @@ def generate(self): for func in self.api.functions: w(toC(get_debug_wrapper_node(func)) + ';') w('') - self.generate_init_prebuilt_handles(w) - # emit a static ctx which uses the various debug_ctx_* functions - w('') - w('static struct _HPyContext_s g_debug_ctx = {') - w(' .name = "HPy Debug Mode ABI",') - w(' ._private = NULL,') - w(' .ctx_version = 1,') - for var in self.api.variables: - w(' .%s = HPy_NULL,' % (var.name,)) - for func in self.api.functions: - w(' .%s = &debug_%s,' % (func.ctx_name(), func.ctx_name())) - w('};') - return '\n'.join(lines) - - def generate_init_prebuilt_handles(self, w): - w('static inline void debug_init_prebuilt_handles(HPyContext ctx, HPyContext uctx)') + w('static inline void debug_ctx_init_fields(HPyContext dctx, HPyContext uctx)') w('{') for var in self.api.variables: name = var.name - w(f' ctx->{name} = DHPy_wrap(ctx, uctx->{name});') + w(f' dctx->{name} = DHPy_wrap(dctx, uctx->{name});') + for func in self.api.functions: + name = func.ctx_name() + w(f' dctx->{name} = &debug_{name};') + w('}') + return '\n'.join(lines) class autogen_debug_wrappers(AutoGenFile): From 6a481ea5ae0db7b9e19ccea24eec6ad91fe684df Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 11:18:59 +0100 Subject: [PATCH 37/65] implement the logic for HPy_Close, and add a python function to get the list of all open handles --- hpy/debug/src/_debugmod.c | 50 ++++++++++---------------- hpy/debug/src/autogen_debug_wrappers.c | 5 --- hpy/debug/src/debug_ctx.c | 7 ++++ hpy/debug/src/debug_ctx_cpython.c | 10 ++++-- hpy/debug/src/debug_handles.c | 30 ++++++++++++++++ hpy/debug/src/debug_internal.h | 4 ++- hpy/tools/autogen/debug.py | 1 + test/test_00_basic.py | 23 ++++++++++++ test/test_debug.py | 36 ++++++++++--------- 9 files changed, 109 insertions(+), 57 deletions(-) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index e07dfcbca..19224353e 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -1,47 +1,35 @@ // Python-level interface for the _debug module. Written in HPy itself, the // idea is that it should be reusable by other implementations +// NOTE: hpy.debug._debug is loaded using the UNIVERSAL ctx. To make it +// clearer, we will use "uctx" and "dctx" to distinguish them. + #include "hpy.h" #include "debug_internal.h" -/* WARNING: all the functions called _test_* are used only for testing. They - are not supposed to be used outside tests */ - -HPyDef_METH(_test_DHPy_new, "_test_DHPy_new", _test_DHPy_new_impl, HPyFunc_O) -static HPy _test_DHPy_new_impl(HPyContext ctx, HPy self, HPy arg) +HPyDef_METH(_get_open_handles, "_get_open_handles", _get_open_handles_impl, HPyFunc_NOARGS) +static HPy _get_open_handles_impl(HPyContext uctx, HPy self) { - HPyErr_SetString(ctx, ctx->h_NotImplementedError, "TODO"); - return HPy_NULL; - /* - HPyContext debug_ctx = hpy_debug_get_ctx(ctx); - HPy h2 = HPy_Dup(ctx, arg); - DHPy dh = DHPy_new(debug_ctx, h2); - // return the numeric value of the pointer, although it's a bit useless - return HPyLong_FromSsize_t(ctx, (HPy_ssize_t)dh); - */ -} + HPyContext dctx = hpy_debug_get_ctx(uctx); + HPyDebugInfo *info = get_info(dctx); -HPyDef_METH(_test_get_open_handles, "_test_get_open_handles", _test_get_open_handles_impl, HPyFunc_NOARGS) -static HPy _test_get_open_handles_impl(HPyContext ctx, HPy self) -{ - HPyErr_SetString(ctx, ctx->h_NotImplementedError, "TODO"); - return HPy_NULL; - /* - HPyContext debug_ctx = hpy_debug_get_ctx(ctx); - HPyDebugInfo *info = get_info(debug_ctx); - HPy hlist = HPyList_New(ctx, 0); - DHPy dh = info->open_handles; - while (dh != NULL) { - HPyList_Append(ctx, hlist, dh->h); + UHPy u_result = HPyList_New(uctx, 0); + if (HPy_IsNull(u_result)) + return HPy_NULL; + + DebugHandle *dh = info->open_handles; + while(dh != NULL) { + if (HPyList_Append(uctx, u_result, dh->uh) == -1) { + HPy_Close(uctx, u_result); + return HPy_NULL; + } dh = dh->next; } - return hlist; - */ + return u_result; } static HPyDef *module_defines[] = { - &_test_DHPy_new, - &_test_get_open_handles, + &_get_open_handles, NULL }; diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index 182665a9d..d4bd32be2 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -22,11 +22,6 @@ DHPy debug_ctx_Dup(HPyContext ctx, DHPy h) return DHPy_wrap(ctx, HPy_Dup(get_info(ctx)->uctx, DHPy_unwrap(h))); } -void debug_ctx_Close(HPyContext ctx, DHPy h) -{ - HPy_Close(get_info(ctx)->uctx, DHPy_unwrap(h)); -} - DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value) { return DHPy_wrap(ctx, HPyLong_FromLong(get_info(ctx)->uctx, value)); diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 9d08106d3..c123b11c5 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -9,6 +9,13 @@ static struct _HPyContext_s g_debug_ctx = { .ctx_version = 1, }; +void debug_ctx_Close(HPyContext ctx, DHPy dh) +{ + UHPy uh = DHPy_unwrap(dh); + DHPy_close(ctx, dh); + HPy_Close(get_info(ctx)->uctx, uh); +} + // NOTE: at the moment this function assumes that uctx is always the // same. If/when we migrate to a system in which we can have multiple diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index 098d56cc0..6ba12d6f0 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -46,7 +46,8 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, DHPy dh_self = _py2dh(ctx, a->self); DHPy dh_result = f(ctx, dh_self); a->result = _dh2py(dh_result); - // XXX: close dh_self + DHPy_close(ctx, dh_self); + DHPy_close(ctx, dh_result); return; } case HPyFunc_O: { @@ -54,8 +55,11 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, _HPyFunc_args_O *a = (_HPyFunc_args_O*)args; DHPy dh_self = _py2dh(ctx, a->self); DHPy dh_arg = _py2dh(ctx, a->arg); - a->result = _dh2py(f(ctx, dh_self, dh_arg)); - // XXX: close dh_self and dh_arg + DHPy dh_result = f(ctx, dh_self, dh_arg); + a->result = _dh2py(dh_result); + DHPy_close(ctx, dh_self); + DHPy_close(ctx, dh_arg); + DHPy_close(ctx, dh_result); return; } case HPyFunc_VARARGS: { diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index 16d5e1483..d6ccae3a6 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -5,7 +5,37 @@ DHPy DHPy_wrap(HPyContext ctx, UHPy uh) HPyDebugInfo *info = get_info(ctx); DebugHandle *handle = malloc(sizeof(DebugHandle)); handle->uh = uh; + handle->prev = NULL; handle->next = info->open_handles; + if (info->open_handles) + info->open_handles->prev = handle; info->open_handles = handle; return as_DHPy(handle); } + +void DHPy_close(HPyContext ctx, DHPy dh) +{ + HPyDebugInfo *info = get_info(ctx); + DebugHandle *handle = as_DebugHandle(dh); + + // remove the handle from the open_handles list + if (handle->prev) + handle->prev->next = handle->next; + if (handle->next) + handle->next->prev = handle->prev; + if (info->open_handles == handle) + info->open_handles = handle->next; + + // TODO: eventually, we want to keep a list of closed handles to be able + // to detect if you are still using them. + DHPy_free(dh); +} + +void DHPy_free(DHPy dh) +{ + DebugHandle *handle = as_DebugHandle(dh); + // this is not strictly necessary, but it increases the chances that you + // get a clear segfault if you use a freed handle + handle->uh = HPy_NULL; + free(handle); +} diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index e2160d59d..50f0c56e8 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -40,6 +40,7 @@ typedef HPy DHPy; typedef struct DebugHandle { UHPy uh; + struct DebugHandle *prev; struct DebugHandle *next; } DebugHandle; @@ -52,6 +53,7 @@ static inline DHPy as_DHPy(DebugHandle *handle) { } DHPy DHPy_wrap(HPyContext ctx, UHPy uh); +void DHPy_close(HPyContext ctx, DHPy dh); static inline UHPy DHPy_unwrap(DHPy dh) { return as_DebugHandle(dh)->uh; @@ -63,7 +65,7 @@ typedef struct { long magic_number; // used just for sanity checks HPyContext uctx; DebugHandle *open_handles; // linked list - DebugHandle *closed_handles; // linked list + //DebugHandle *closed_handles; // linked list } HPyDebugInfo; static inline HPyDebugInfo *get_info(HPyContext ctx) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index 25c3c7bad..39c15fb10 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -53,6 +53,7 @@ class autogen_debug_wrappers(AutoGenFile): NO_WRAPPER = set([ '_HPy_CallRealFunctionFromTrampoline', + 'HPy_Close', ]) def generate(self): diff --git a/test/test_00_basic.py b/test/test_00_basic.py index 1b639e50b..f73e182dd 100644 --- a/test/test_00_basic.py +++ b/test/test_00_basic.py @@ -376,3 +376,26 @@ def test_hash(self): """) x = object() assert mod.f(x) == hash(x) + + def test_ctx_name(self, hpy_abi): + mod = self.make_module(""" + HPyDef_METH(f, "f", f_impl, HPyFunc_NOARGS) + static HPy f_impl(HPyContext ctx, HPy self) + { + return HPyUnicode_FromString(ctx, ctx->name); + } + + @EXPORT(f) + @INIT + """) + ctx_name = mod.f() + if hpy_abi == 'cpython': + assert ctx_name == 'HPy CPython ABI' + elif hpy_abi == 'universal': + # this can be "HPy Universal ABI (CPython backend)" or + # "... (PyPy backend)", etc. + assert ctx_name.startswith('HPy Universal ABI') + elif hpy_abi == 'debug': + assert ctx_name.startswith('HPy Debug Mode ABI') + else: + assert False, 'unexpected hpy_abi: %s' % hpy_abi diff --git a/test/test_debug.py b/test/test_debug.py index bbbc822d6..b514b30d6 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -1,27 +1,29 @@ +import pytest from .support import HPyTest class TestDebug(HPyTest): - def test_ctx_name(self, hpy_abi): + # these tests are run only with hpy_abi=='debug'. We will probably need to + # tweak the approach to make it working with PyPy's apptests + @pytest.fixture(params=['debug']) + def hpy_abi(self, request): + return request.param + + def test_open_handles(self): + from hpy.universal import _debug mod = self.make_module(""" - HPyDef_METH(f, "f", f_impl, HPyFunc_NOARGS) - static HPy f_impl(HPyContext ctx, HPy self) + HPyDef_METH(leak, "leak", leak_impl, HPyFunc_NOARGS) + static HPy leak_impl(HPyContext ctx, HPy self) { - return HPyUnicode_FromString(ctx, ctx->name); + HPyUnicode_FromString(ctx, "hello"); + HPyUnicode_FromString(ctx, "world"); + return HPy_Dup(ctx, ctx->h_None); } - - @EXPORT(f) + @EXPORT(leak) @INIT """) - ctx_name = mod.f() - if hpy_abi == 'cpython': - assert ctx_name == 'HPy CPython ABI' - elif hpy_abi == 'universal': - # this can be "HPy Universal ABI (CPython backend)" or - # "... (PyPy backend)", etc. - assert ctx_name.startswith('HPy Universal ABI') - elif hpy_abi == 'debug': - assert ctx_name.startswith('HPy Debug Mode ABI') - else: - assert False, 'unexpected hpy_abi: %s' % hpy_abi + n = len(_debug._get_open_handles()) + mod.leak() + leaked_handles = _debug._get_open_handles()[:-n] + assert leaked_handles == ['world', 'hello'] From 221319168bb723a0a4b4f2cc44b9d1a3be4a5c6e Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 11:43:15 +0100 Subject: [PATCH 38/65] Associate a generation to each open handle, and make it possible to get the list of open handles which are newer than a certain generation --- hpy/debug/src/_debugmod.c | 35 ++++++++++++++++++++++++++++------ hpy/debug/src/debug_ctx.c | 3 ++- hpy/debug/src/debug_handles.c | 1 + hpy/debug/src/debug_internal.h | 6 ++++++ test/test_debug.py | 22 ++++++++++++--------- 5 files changed, 51 insertions(+), 16 deletions(-) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index 19224353e..d669ee532 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -7,11 +7,31 @@ #include "hpy.h" #include "debug_internal.h" -HPyDef_METH(_get_open_handles, "_get_open_handles", _get_open_handles_impl, HPyFunc_NOARGS) -static HPy _get_open_handles_impl(HPyContext uctx, HPy self) +HPyDef_METH(new_generation, "new_generation", new_generation_impl, HPyFunc_NOARGS) +static HPy new_generation_impl(HPyContext uctx, HPy self) { HPyContext dctx = hpy_debug_get_ctx(uctx); HPyDebugInfo *info = get_info(dctx); + info->current_generation++; + return HPyLong_FromLong(uctx, info->current_generation); +} + + +// TODO: eventually, we want to return Python-level views of DebugHandle, so +// that we can retrieve additional infos from applevel (e.g., the C backtrace +// at the moment of opening or so). For now, just return the Python objects +// pointed by the handles. +HPyDef_METH(get_open_handles, "get_open_handles", get_open_handles_impl, HPyFunc_O, .doc= + "Return a list containing all the open handles whose generation is >= " + "of the given arg") +static HPy get_open_handles_impl(HPyContext uctx, UHPy u_self, UHPy u_gen) +{ + HPyContext dctx = hpy_debug_get_ctx(uctx); + HPyDebugInfo *info = get_info(dctx); + + long gen = HPyLong_AsLong(uctx, u_gen); + if (HPyErr_Occurred(uctx)) + return HPy_NULL; UHPy u_result = HPyList_New(uctx, 0); if (HPy_IsNull(u_result)) @@ -19,9 +39,11 @@ static HPy _get_open_handles_impl(HPyContext uctx, HPy self) DebugHandle *dh = info->open_handles; while(dh != NULL) { - if (HPyList_Append(uctx, u_result, dh->uh) == -1) { - HPy_Close(uctx, u_result); - return HPy_NULL; + if (dh->generation >= gen) { + if (HPyList_Append(uctx, u_result, dh->uh) == -1) { + HPy_Close(uctx, u_result); + return HPy_NULL; + } } dh = dh->next; } @@ -29,7 +51,8 @@ static HPy _get_open_handles_impl(HPyContext uctx, HPy self) } static HPyDef *module_defines[] = { - &_get_open_handles, + &new_generation, + &get_open_handles, NULL }; diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index c123b11c5..72f433076 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -33,8 +33,9 @@ static void debug_ctx_init(HPyContext dctx, HPyContext uctx) HPyDebugInfo *info = malloc(sizeof(HPyDebugInfo)); info->magic_number = HPY_DEBUG_MAGIC; info->uctx = uctx; + info->current_generation = 0; info->open_handles = NULL; - info->closed_handles = NULL; + //info->closed_handles = NULL; dctx->_private = info; debug_ctx_init_fields(dctx, uctx); diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index d6ccae3a6..dda7bd4a6 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -5,6 +5,7 @@ DHPy DHPy_wrap(HPyContext ctx, UHPy uh) HPyDebugInfo *info = get_info(ctx); DebugHandle *handle = malloc(sizeof(DebugHandle)); handle->uh = uh; + handle->generation = info->current_generation; handle->prev = NULL; handle->next = info->open_handles; if (info->open_handles) diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index 50f0c56e8..29ed4156d 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -33,6 +33,9 @@ WARNING: both UHPy and DHPy are alias of HPy, so we need to take care of not mixing them, because the compiler cannot help. + + Each DebugHandle has a "generation", which is just a int to be able to get + only the handles which were created after a certain point. */ typedef HPy UHPy; @@ -40,6 +43,7 @@ typedef HPy DHPy; typedef struct DebugHandle { UHPy uh; + long generation; struct DebugHandle *prev; struct DebugHandle *next; } DebugHandle; @@ -54,6 +58,7 @@ static inline DHPy as_DHPy(DebugHandle *handle) { DHPy DHPy_wrap(HPyContext ctx, UHPy uh); void DHPy_close(HPyContext ctx, DHPy dh); +void DHPy_free(DHPy dh); static inline UHPy DHPy_unwrap(DHPy dh) { return as_DebugHandle(dh)->uh; @@ -64,6 +69,7 @@ static inline UHPy DHPy_unwrap(DHPy dh) { typedef struct { long magic_number; // used just for sanity checks HPyContext uctx; + long current_generation; DebugHandle *open_handles; // linked list //DebugHandle *closed_handles; // linked list } HPyDebugInfo; diff --git a/test/test_debug.py b/test/test_debug.py index b514b30d6..9eaa8624c 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -10,20 +10,24 @@ class TestDebug(HPyTest): def hpy_abi(self, request): return request.param - def test_open_handles(self): + def test_get_open_handles(self): from hpy.universal import _debug mod = self.make_module(""" - HPyDef_METH(leak, "leak", leak_impl, HPyFunc_NOARGS) - static HPy leak_impl(HPyContext ctx, HPy self) + HPyDef_METH(leak, "leak", leak_impl, HPyFunc_O) + static HPy leak_impl(HPyContext ctx, HPy self, HPy arg) { - HPyUnicode_FromString(ctx, "hello"); - HPyUnicode_FromString(ctx, "world"); + HPy_Dup(ctx, arg); // leak! return HPy_Dup(ctx, ctx->h_None); } @EXPORT(leak) @INIT """) - n = len(_debug._get_open_handles()) - mod.leak() - leaked_handles = _debug._get_open_handles()[:-n] - assert leaked_handles == ['world', 'hello'] + gen1 = _debug.new_generation() + mod.leak('hello') + mod.leak('world') + gen2 = _debug.new_generation() + mod.leak('a younger leak') + leaks1 = _debug.get_open_handles(gen1) + leaks2 = _debug.get_open_handles(gen2) + assert leaks1 == ['a younger leak', 'world', 'hello'] + assert leaks2 == ['a younger leak'] From 53b78ba2d7496dc77337173db5db909b3aabde59 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 11:49:47 +0100 Subject: [PATCH 39/65] NULL DHPys need a bit of special casing. This is enough to make test_00_basic:test_exception passing again --- hpy/debug/src/debug_handles.c | 2 ++ hpy/debug/src/debug_internal.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index dda7bd4a6..8f333cd1a 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -16,6 +16,8 @@ DHPy DHPy_wrap(HPyContext ctx, UHPy uh) void DHPy_close(HPyContext ctx, DHPy dh) { + if (HPy_IsNull(dh)) + return; HPyDebugInfo *info = get_info(ctx); DebugHandle *handle = as_DebugHandle(dh); diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index 29ed4156d..8513723fa 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -61,6 +61,8 @@ void DHPy_close(HPyContext ctx, DHPy dh); void DHPy_free(DHPy dh); static inline UHPy DHPy_unwrap(DHPy dh) { + if (HPy_IsNull(dh)) + return HPy_NULL; return as_DebugHandle(dh)->uh; } From 1a44f3d7422c63c77af1fa79609123b8c3252f70 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 11:59:18 +0100 Subject: [PATCH 40/65] implement the HPyFunc_VARARGS case inside debug_ctx_CallRealFunctionFromTrampoline --- hpy/debug/src/debug_ctx_cpython.c | 15 ++++++++++++++- test/test_00_basic.py | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index 6ba12d6f0..6ff35c20e 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -63,7 +63,20 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, return; } case HPyFunc_VARARGS: { - abort(); + HPyFunc_varargs f = (HPyFunc_varargs)func; + _HPyFunc_args_VARARGS *a = (_HPyFunc_args_VARARGS*)args; + DHPy dh_self = _py2dh(ctx, a->self); + Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); + DHPy dh_args[nargs * sizeof(DHPy)]; + for (Py_ssize_t i = 0; i < nargs; i++) { + dh_args[i] = _py2dh(ctx, PyTuple_GET_ITEM(a->args, i)); + } + a->result = _dh2py(f(ctx, dh_self, dh_args, nargs)); + DHPy_close(ctx, dh_self); + for (Py_ssize_t i = 0; i < nargs; i++) { + DHPy_close(ctx, dh_args[i]); + } + return; } case HPyFunc_KEYWORDS: { abort(); diff --git a/test/test_00_basic.py b/test/test_00_basic.py index f73e182dd..6ba9279da 100644 --- a/test/test_00_basic.py +++ b/test/test_00_basic.py @@ -164,6 +164,21 @@ def test_exception(self): mod.f(20) assert str(exc.value) == 'hello world' + def test_varargs(self): + mod = self.make_module(""" + HPyDef_METH(f, "f", f_impl, HPyFunc_VARARGS) + static HPy f_impl(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs) + { + long a, b; + if (!HPyArg_Parse(ctx, NULL, args, nargs, "ll", &a, &b)) + return HPy_NULL; + return HPyLong_FromLong(ctx, 10*a + b); + } + @EXPORT(f) + @INIT + """) + assert mod.f(4, 5) == 45 + def test_builtin_handles(self): mod = self.make_module(""" HPyDef_METH(f, "f", f_impl, HPyFunc_O) From f731b953d5dbdfacc226f51098af022af35de8be Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 16:21:55 +0100 Subject: [PATCH 41/65] implement HPyFunc_KEYWORDS --- hpy/debug/src/debug_ctx_cpython.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index 6ff35c20e..9efeeaa2e 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -79,7 +79,22 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, return; } case HPyFunc_KEYWORDS: { - abort(); + HPyFunc_keywords f = (HPyFunc_keywords)func; + _HPyFunc_args_KEYWORDS *a = (_HPyFunc_args_KEYWORDS*)args; + DHPy dh_self = _py2dh(ctx, a->self); + Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); + DHPy dh_args[nargs * sizeof(DHPy)]; + for (Py_ssize_t i = 0; i < nargs; i++) { + dh_args[i] = _py2dh(ctx, PyTuple_GET_ITEM(a->args, i)); + } + DHPy dh_kw = _py2dh(ctx, a->kw); + a->result = _dh2py(f(ctx, dh_self, dh_args, nargs, dh_kw)); + DHPy_close(ctx, dh_self); + for (Py_ssize_t i = 0; i < nargs; i++) { + DHPy_close(ctx, dh_args[i]); + } + DHPy_close(ctx, dh_kw); + return; } case HPyFunc_INITPROC: { abort(); From 00db14dacefc5e650e14a941d515120e07db1c3a Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 16:29:08 +0100 Subject: [PATCH 42/65] special case HPy_NULL also inside DHPy_wrap: this is needed to correctly propagate exceptions when wrapped functions return HPy_NULL --- hpy/debug/src/debug_handles.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index 8f333cd1a..e6c6832f2 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -2,6 +2,8 @@ DHPy DHPy_wrap(HPyContext ctx, UHPy uh) { + if (HPy_IsNull(uh)) + return HPy_NULL; HPyDebugInfo *info = get_info(ctx); DebugHandle *handle = malloc(sizeof(DebugHandle)); handle->uh = uh; From 37990460b0c92e9d88363cefbd87f60fbaa3035f Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Tue, 12 Jan 2021 18:11:30 +0100 Subject: [PATCH 43/65] add a note --- README-gdb.md | 4 ++++ gdb-py.test | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README-gdb.md b/README-gdb.md index 5a68c9203..c1bacca19 100644 --- a/README-gdb.md +++ b/README-gdb.md @@ -76,6 +76,10 @@ global 'i' = 9657683 Inspect `PyObject *` and `HPy` inside GDB ------------------------------------------ +**WARNING**: `py-dump` and `hpy-dump` prints to stderr, and this interacts +badly with pytest's capturing. Make sure to run `py.test -s`, else you might +not see the output. The included script `gdb-py.test` automatically pass `-s`. + `python-gdb.py` installs a GDB pretty-printer for `PyObject *` variables, which sometimes can be confusing: often, it prints the Python repr of the variable: diff --git a/gdb-py.test b/gdb-py.test index 165f037de..7412a0621 100755 --- a/gdb-py.test +++ b/gdb-py.test @@ -1,3 +1,3 @@ #!/bin/bash -gdb --eval-command run --args python3 -m pytest "$@" +gdb --eval-command run --args python3 -m pytest -s "$@" From 651aaaf4a660305c5bfbcd773254b5cb652a9fae Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 17:39:37 +0100 Subject: [PATCH 44/65] add some sanity check to ensure that we don't mix UHPy and DHPy wrongly --- hpy/debug/src/debug_handles.c | 3 +++ hpy/debug/src/debug_internal.h | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index e6c6832f2..c67e8f1e1 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -2,6 +2,7 @@ DHPy DHPy_wrap(HPyContext ctx, UHPy uh) { + UHPy_sanity_check(uh); if (HPy_IsNull(uh)) return HPy_NULL; HPyDebugInfo *info = get_info(ctx); @@ -18,6 +19,7 @@ DHPy DHPy_wrap(HPyContext ctx, UHPy uh) void DHPy_close(HPyContext ctx, DHPy dh) { + DHPy_sanity_check(dh); if (HPy_IsNull(dh)) return; HPyDebugInfo *info = get_info(ctx); @@ -38,6 +40,7 @@ void DHPy_close(HPyContext ctx, DHPy dh) void DHPy_free(DHPy dh) { + DHPy_sanity_check(dh); DebugHandle *handle = as_DebugHandle(dh); // this is not strictly necessary, but it increases the chances that you // get a clear segfault if you use a freed handle diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index 8513723fa..c453101da 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -41,6 +41,26 @@ typedef HPy UHPy; typedef HPy DHPy; +/* Under CPython: + - UHPy always end with 1 (see hpy.universal's _py2h and _h2py) + - DHPy are pointers, so they always end with 0 + + DHPy_sanity_check is a minimal check to ensure that we are not treating a + UHPy as a DHPy. Note that DHPy_sanity_check works fine also on HPy_NULL. + + NOTE: UHPy_sanity_check works ONLY with CPython's hpy.universal. If you + bundle the debug mode in an alternative Python implementation, you should + probably change/override UHPy_sanity_check, possibly with an #ifdef. +*/ +static inline void DHPy_sanity_check(DHPy dh) { + assert( (dh._i & 1) == 0 ); +} + +static inline void UHPy_sanity_check(UHPy uh) { + if (!HPy_IsNull(uh)) + assert( (uh._i & 1) == 1 ); +} + typedef struct DebugHandle { UHPy uh; long generation; @@ -49,6 +69,7 @@ typedef struct DebugHandle { } DebugHandle; static inline DebugHandle * as_DebugHandle(DHPy dh) { + DHPy_sanity_check(dh); return (DebugHandle *)dh._i; } From 2e50a135ee0b393f9faa3d8ce251fb27b12fe48d Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Sun, 17 Jan 2021 17:46:51 +0100 Subject: [PATCH 45/65] Use dctx and uctx everywhere, to make it clearer what is the ctx we expect in each place --- hpy/debug/src/_debugmod.c | 4 +- hpy/debug/src/autogen_debug_ctx_init.h | 244 ++++++------- hpy/debug/src/autogen_debug_wrappers.c | 480 ++++++++++++------------- hpy/debug/src/debug_ctx.c | 6 +- hpy/debug/src/debug_ctx_cpython.c | 50 +-- hpy/debug/src/debug_ctx_not_cpython.c | 6 +- hpy/debug/src/debug_handles.c | 8 +- hpy/debug/src/debug_internal.h | 8 +- hpy/debug/src/include/hpy_debug.h | 2 +- hpy/tools/autogen/debug.py | 9 +- 10 files changed, 411 insertions(+), 406 deletions(-) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index d669ee532..f7e0092c3 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -66,9 +66,9 @@ static HPyModuleDef moduledef = { HPy_MODINIT(_debug) -static HPy init__debug_impl(HPyContext ctx) +static HPy init__debug_impl(HPyContext uctx) { - HPy m = HPyModule_Create(ctx, &moduledef); + HPy m = HPyModule_Create(uctx, &moduledef); if (HPy_IsNull(m)) return HPy_NULL; return m; diff --git a/hpy/debug/src/autogen_debug_ctx_init.h b/hpy/debug/src/autogen_debug_ctx_init.h index 85dfd406e..85b81017b 100644 --- a/hpy/debug/src/autogen_debug_ctx_init.h +++ b/hpy/debug/src/autogen_debug_ctx_init.h @@ -10,128 +10,128 @@ */ -DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def); -DHPy debug_ctx_Dup(HPyContext ctx, DHPy h); -void debug_ctx_Close(HPyContext ctx, DHPy h); -DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value); -DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value); -DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v); -DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v); -DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value); -DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value); -long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h); -unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h); -unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h); -long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h); -unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h); -unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h); -size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h); -DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v); -double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h); -int debug_ctx_Number_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); -DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_Index(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Long(HPyContext ctx, DHPy h1); -DHPy debug_ctx_Float(HPyContext ctx, DHPy h1); -DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3); -DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2); -DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2); -int debug_ctx_Callable_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw); -void debug_ctx_FatalError(HPyContext ctx, const char *message); -void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message); -void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value); -int debug_ctx_Err_Occurred(HPyContext ctx); -DHPy debug_ctx_Err_NoMemory(HPyContext ctx); -void debug_ctx_Err_Clear(HPyContext ctx); -int debug_ctx_IsTrue(HPyContext ctx, DHPy h); -DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params); -DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw); -DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name); -DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name); -int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name); -int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name); -int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value); -int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value); -DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key); -DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx); -DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key); -int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value); -int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value); -int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value); -void *debug_ctx_Cast(HPyContext ctx, DHPy h); -DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data); -DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj); -DHPy debug_ctx_Str(HPyContext ctx, DHPy obj); -DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj); -DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj); -DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op); -int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op); -HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj); -int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h); -HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h); -char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h); -char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h); -DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v); -DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len); -DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8); -int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h); -DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size); -int debug_ctx_List_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len); -int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item); -int debug_ctx_Dict_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Dict_New(HPyContext ctx); -int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h); -DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n); -DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj); -cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h); -void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, HPyFunc_Signature sig, void *func, void *args); -void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self); -HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item); -DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder); -void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder); -HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size); -void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item); -DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder); -void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder); -HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size); -int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h); -void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht); -void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht); -void debug_ctx_Dump(HPyContext ctx, DHPy h); +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_FromLong(HPyContext dctx, long value); +DHPy debug_ctx_Long_FromUnsignedLong(HPyContext dctx, unsigned long value); +DHPy debug_ctx_Long_FromLongLong(HPyContext dctx, long long v); +DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext dctx, unsigned long long v); +DHPy debug_ctx_Long_FromSize_t(HPyContext dctx, size_t value); +DHPy debug_ctx_Long_FromSsize_t(HPyContext dctx, HPy_ssize_t value); +long debug_ctx_Long_AsLong(HPyContext dctx, DHPy h); +unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext dctx, DHPy h); +unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext dctx, DHPy h); +long long debug_ctx_Long_AsLongLong(HPyContext dctx, DHPy h); +unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext dctx, DHPy h); +unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext dctx, DHPy h); +size_t debug_ctx_Long_AsSize_t(HPyContext dctx, DHPy h); +HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext dctx, DHPy h); +DHPy debug_ctx_Float_FromDouble(HPyContext dctx, double v); +double debug_ctx_Float_AsDouble(HPyContext dctx, DHPy h); +HPy_ssize_t debug_ctx_Length(HPyContext dctx, DHPy h); +int debug_ctx_Number_Check(HPyContext dctx, DHPy h); +DHPy debug_ctx_Add(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Subtract(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Multiply(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_MatrixMultiply(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_FloorDivide(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_TrueDivide(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Remainder(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Divmod(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Power(HPyContext dctx, DHPy h1, DHPy h2, DHPy h3); +DHPy debug_ctx_Negative(HPyContext dctx, DHPy h1); +DHPy debug_ctx_Positive(HPyContext dctx, DHPy h1); +DHPy debug_ctx_Absolute(HPyContext dctx, DHPy h1); +DHPy debug_ctx_Invert(HPyContext dctx, DHPy h1); +DHPy debug_ctx_Lshift(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Rshift(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_And(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Xor(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Or(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_Index(HPyContext dctx, DHPy h1); +DHPy debug_ctx_Long(HPyContext dctx, DHPy h1); +DHPy debug_ctx_Float(HPyContext dctx, DHPy h1); +DHPy debug_ctx_InPlaceAdd(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceSubtract(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceMultiply(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceFloorDivide(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceTrueDivide(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceRemainder(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlacePower(HPyContext dctx, DHPy h1, DHPy h2, DHPy h3); +DHPy debug_ctx_InPlaceLshift(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceRshift(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceAnd(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceXor(HPyContext dctx, DHPy h1, DHPy h2); +DHPy debug_ctx_InPlaceOr(HPyContext dctx, DHPy h1, DHPy h2); +int debug_ctx_Callable_Check(HPyContext dctx, DHPy h); +DHPy debug_ctx_CallTupleDict(HPyContext dctx, DHPy callable, DHPy args, DHPy kw); +void debug_ctx_FatalError(HPyContext dctx, const char *message); +void debug_ctx_Err_SetString(HPyContext dctx, DHPy h_type, const char *message); +void debug_ctx_Err_SetObject(HPyContext dctx, DHPy h_type, DHPy h_value); +int debug_ctx_Err_Occurred(HPyContext dctx); +DHPy debug_ctx_Err_NoMemory(HPyContext dctx); +void debug_ctx_Err_Clear(HPyContext dctx); +int debug_ctx_IsTrue(HPyContext dctx, DHPy h); +DHPy debug_ctx_Type_FromSpec(HPyContext dctx, HPyType_Spec *spec, HPyType_SpecParam *params); +DHPy debug_ctx_Type_GenericNew(HPyContext dctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw); +DHPy debug_ctx_GetAttr(HPyContext dctx, DHPy obj, DHPy name); +DHPy debug_ctx_GetAttr_s(HPyContext dctx, DHPy obj, const char *name); +int debug_ctx_HasAttr(HPyContext dctx, DHPy obj, DHPy name); +int debug_ctx_HasAttr_s(HPyContext dctx, DHPy obj, const char *name); +int debug_ctx_SetAttr(HPyContext dctx, DHPy obj, DHPy name, DHPy value); +int debug_ctx_SetAttr_s(HPyContext dctx, DHPy obj, const char *name, DHPy value); +DHPy debug_ctx_GetItem(HPyContext dctx, DHPy obj, DHPy key); +DHPy debug_ctx_GetItem_i(HPyContext dctx, DHPy obj, HPy_ssize_t idx); +DHPy debug_ctx_GetItem_s(HPyContext dctx, DHPy obj, const char *key); +int debug_ctx_SetItem(HPyContext dctx, DHPy obj, DHPy key, DHPy value); +int debug_ctx_SetItem_i(HPyContext dctx, DHPy obj, HPy_ssize_t idx, DHPy value); +int debug_ctx_SetItem_s(HPyContext dctx, DHPy obj, const char *key, DHPy value); +void *debug_ctx_Cast(HPyContext dctx, DHPy h); +DHPy debug_ctx_New(HPyContext dctx, DHPy h_type, void **data); +DHPy debug_ctx_Repr(HPyContext dctx, DHPy obj); +DHPy debug_ctx_Str(HPyContext dctx, DHPy obj); +DHPy debug_ctx_ASCII(HPyContext dctx, DHPy obj); +DHPy debug_ctx_Bytes(HPyContext dctx, DHPy obj); +DHPy debug_ctx_RichCompare(HPyContext dctx, DHPy v, DHPy w, int op); +int debug_ctx_RichCompareBool(HPyContext dctx, DHPy v, DHPy w, int op); +HPy_hash_t debug_ctx_Hash(HPyContext dctx, DHPy obj); +int debug_ctx_Bytes_Check(HPyContext dctx, DHPy h); +HPy_ssize_t debug_ctx_Bytes_Size(HPyContext dctx, DHPy h); +HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext dctx, DHPy h); +char *debug_ctx_Bytes_AsString(HPyContext dctx, DHPy h); +char *debug_ctx_Bytes_AS_STRING(HPyContext dctx, DHPy h); +DHPy debug_ctx_Bytes_FromString(HPyContext dctx, const char *v); +DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext dctx, const char *v, HPy_ssize_t len); +DHPy debug_ctx_Unicode_FromString(HPyContext dctx, const char *utf8); +int debug_ctx_Unicode_Check(HPyContext dctx, DHPy h); +DHPy debug_ctx_Unicode_AsUTF8String(HPyContext dctx, DHPy h); +DHPy debug_ctx_Unicode_FromWideChar(HPyContext dctx, const wchar_t *w, HPy_ssize_t size); +int debug_ctx_List_Check(HPyContext dctx, DHPy h); +DHPy debug_ctx_List_New(HPyContext dctx, HPy_ssize_t len); +int debug_ctx_List_Append(HPyContext dctx, DHPy h_list, DHPy h_item); +int debug_ctx_Dict_Check(HPyContext dctx, DHPy h); +DHPy debug_ctx_Dict_New(HPyContext dctx); +int debug_ctx_Tuple_Check(HPyContext dctx, DHPy h); +DHPy debug_ctx_Tuple_FromArray(HPyContext dctx, DHPy items[], HPy_ssize_t n); +DHPy debug_ctx_FromPyObject(HPyContext dctx, cpy_PyObject *obj); +cpy_PyObject *debug_ctx_AsPyObject(HPyContext dctx, DHPy h); +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext dctx, HPyFunc_Signature sig, void *func, void *args); +void debug_ctx_CallDestroyAndThenDealloc(HPyContext dctx, void *func, cpy_PyObject *self); +HPyListBuilder debug_ctx_ListBuilder_New(HPyContext dctx, HPy_ssize_t initial_size); +void debug_ctx_ListBuilder_Set(HPyContext dctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item); +DHPy debug_ctx_ListBuilder_Build(HPyContext dctx, HPyListBuilder builder); +void debug_ctx_ListBuilder_Cancel(HPyContext dctx, HPyListBuilder builder); +HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext dctx, HPy_ssize_t initial_size); +void debug_ctx_TupleBuilder_Set(HPyContext dctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item); +DHPy debug_ctx_TupleBuilder_Build(HPyContext dctx, HPyTupleBuilder builder); +void debug_ctx_TupleBuilder_Cancel(HPyContext dctx, HPyTupleBuilder builder); +HPyTracker debug_ctx_Tracker_New(HPyContext dctx, HPy_ssize_t size); +int debug_ctx_Tracker_Add(HPyContext dctx, HPyTracker ht, DHPy h); +void debug_ctx_Tracker_ForgetAll(HPyContext dctx, HPyTracker ht); +void debug_ctx_Tracker_Close(HPyContext dctx, HPyTracker ht); +void debug_ctx_Dump(HPyContext dctx, DHPy h); static inline void debug_ctx_init_fields(HPyContext dctx, HPyContext uctx) { diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index d4bd32be2..d926998d9 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -12,603 +12,603 @@ #include "debug_internal.h" -DHPy debug_ctx_Module_Create(HPyContext ctx, HPyModuleDef *def) +DHPy debug_ctx_Module_Create(HPyContext dctx, HPyModuleDef *def) { - return DHPy_wrap(ctx, HPyModule_Create(get_info(ctx)->uctx, def)); + return DHPy_wrap(dctx, HPyModule_Create(get_info(dctx)->uctx, def)); } -DHPy debug_ctx_Dup(HPyContext ctx, DHPy h) +DHPy debug_ctx_Dup(HPyContext dctx, DHPy h) { - return DHPy_wrap(ctx, HPy_Dup(get_info(ctx)->uctx, DHPy_unwrap(h))); + return DHPy_wrap(dctx, HPy_Dup(get_info(dctx)->uctx, DHPy_unwrap(h))); } -DHPy debug_ctx_Long_FromLong(HPyContext ctx, long value) +DHPy debug_ctx_Long_FromLong(HPyContext dctx, long value) { - return DHPy_wrap(ctx, HPyLong_FromLong(get_info(ctx)->uctx, value)); + return DHPy_wrap(dctx, HPyLong_FromLong(get_info(dctx)->uctx, value)); } -DHPy debug_ctx_Long_FromUnsignedLong(HPyContext ctx, unsigned long value) +DHPy debug_ctx_Long_FromUnsignedLong(HPyContext dctx, unsigned long value) { - return DHPy_wrap(ctx, HPyLong_FromUnsignedLong(get_info(ctx)->uctx, value)); + return DHPy_wrap(dctx, HPyLong_FromUnsignedLong(get_info(dctx)->uctx, value)); } -DHPy debug_ctx_Long_FromLongLong(HPyContext ctx, long long v) +DHPy debug_ctx_Long_FromLongLong(HPyContext dctx, long long v) { - return DHPy_wrap(ctx, HPyLong_FromLongLong(get_info(ctx)->uctx, v)); + return DHPy_wrap(dctx, HPyLong_FromLongLong(get_info(dctx)->uctx, v)); } -DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext ctx, unsigned long long v) +DHPy debug_ctx_Long_FromUnsignedLongLong(HPyContext dctx, unsigned long long v) { - return DHPy_wrap(ctx, HPyLong_FromUnsignedLongLong(get_info(ctx)->uctx, v)); + return DHPy_wrap(dctx, HPyLong_FromUnsignedLongLong(get_info(dctx)->uctx, v)); } -DHPy debug_ctx_Long_FromSize_t(HPyContext ctx, size_t value) +DHPy debug_ctx_Long_FromSize_t(HPyContext dctx, size_t value) { - return DHPy_wrap(ctx, HPyLong_FromSize_t(get_info(ctx)->uctx, value)); + return DHPy_wrap(dctx, HPyLong_FromSize_t(get_info(dctx)->uctx, value)); } -DHPy debug_ctx_Long_FromSsize_t(HPyContext ctx, HPy_ssize_t value) +DHPy debug_ctx_Long_FromSsize_t(HPyContext dctx, HPy_ssize_t value) { - return DHPy_wrap(ctx, HPyLong_FromSsize_t(get_info(ctx)->uctx, value)); + return DHPy_wrap(dctx, HPyLong_FromSsize_t(get_info(dctx)->uctx, value)); } -long debug_ctx_Long_AsLong(HPyContext ctx, DHPy h) +long debug_ctx_Long_AsLong(HPyContext dctx, DHPy h) { - return HPyLong_AsLong(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsLong(get_info(dctx)->uctx, DHPy_unwrap(h)); } -unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext ctx, DHPy h) +unsigned long debug_ctx_Long_AsUnsignedLong(HPyContext dctx, DHPy h) { - return HPyLong_AsUnsignedLong(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLong(get_info(dctx)->uctx, DHPy_unwrap(h)); } -unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext ctx, DHPy h) +unsigned long debug_ctx_Long_AsUnsignedLongMask(HPyContext dctx, DHPy h) { - return HPyLong_AsUnsignedLongMask(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLongMask(get_info(dctx)->uctx, DHPy_unwrap(h)); } -long long debug_ctx_Long_AsLongLong(HPyContext ctx, DHPy h) +long long debug_ctx_Long_AsLongLong(HPyContext dctx, DHPy h) { - return HPyLong_AsLongLong(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsLongLong(get_info(dctx)->uctx, DHPy_unwrap(h)); } -unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext ctx, DHPy h) +unsigned long long debug_ctx_Long_AsUnsignedLongLong(HPyContext dctx, DHPy h) { - return HPyLong_AsUnsignedLongLong(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLongLong(get_info(dctx)->uctx, DHPy_unwrap(h)); } -unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext ctx, DHPy h) +unsigned long long debug_ctx_Long_AsUnsignedLongLongMask(HPyContext dctx, DHPy h) { - return HPyLong_AsUnsignedLongLongMask(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsUnsignedLongLongMask(get_info(dctx)->uctx, DHPy_unwrap(h)); } -size_t debug_ctx_Long_AsSize_t(HPyContext ctx, DHPy h) +size_t debug_ctx_Long_AsSize_t(HPyContext dctx, DHPy h) { - return HPyLong_AsSize_t(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsSize_t(get_info(dctx)->uctx, DHPy_unwrap(h)); } -HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext ctx, DHPy h) +HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext dctx, DHPy h) { - return HPyLong_AsSsize_t(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyLong_AsSsize_t(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Float_FromDouble(HPyContext ctx, double v) +DHPy debug_ctx_Float_FromDouble(HPyContext dctx, double v) { - return DHPy_wrap(ctx, HPyFloat_FromDouble(get_info(ctx)->uctx, v)); + return DHPy_wrap(dctx, HPyFloat_FromDouble(get_info(dctx)->uctx, v)); } -double debug_ctx_Float_AsDouble(HPyContext ctx, DHPy h) +double debug_ctx_Float_AsDouble(HPyContext dctx, DHPy h) { - return HPyFloat_AsDouble(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyFloat_AsDouble(get_info(dctx)->uctx, DHPy_unwrap(h)); } -HPy_ssize_t debug_ctx_Length(HPyContext ctx, DHPy h) +HPy_ssize_t debug_ctx_Length(HPyContext dctx, DHPy h) { - return HPy_Length(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPy_Length(get_info(dctx)->uctx, DHPy_unwrap(h)); } -int debug_ctx_Number_Check(HPyContext ctx, DHPy h) +int debug_ctx_Number_Check(HPyContext dctx, DHPy h) { - return HPyNumber_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyNumber_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Add(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Add(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Add(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Add(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Subtract(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Subtract(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Subtract(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Subtract(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Multiply(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Multiply(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Multiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Multiply(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_MatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_MatrixMultiply(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_MatrixMultiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_MatrixMultiply(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_FloorDivide(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_FloorDivide(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_FloorDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_FloorDivide(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_TrueDivide(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_TrueDivide(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_TrueDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_TrueDivide(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Remainder(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Remainder(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Remainder(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Remainder(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Divmod(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Divmod(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Divmod(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Divmod(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Power(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) +DHPy debug_ctx_Power(HPyContext dctx, DHPy h1, DHPy h2, DHPy h3) { - return DHPy_wrap(ctx, HPy_Power(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); + return DHPy_wrap(dctx, HPy_Power(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); } -DHPy debug_ctx_Negative(HPyContext ctx, DHPy h1) +DHPy debug_ctx_Negative(HPyContext dctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Negative(get_info(ctx)->uctx, DHPy_unwrap(h1))); + return DHPy_wrap(dctx, HPy_Negative(get_info(dctx)->uctx, DHPy_unwrap(h1))); } -DHPy debug_ctx_Positive(HPyContext ctx, DHPy h1) +DHPy debug_ctx_Positive(HPyContext dctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Positive(get_info(ctx)->uctx, DHPy_unwrap(h1))); + return DHPy_wrap(dctx, HPy_Positive(get_info(dctx)->uctx, DHPy_unwrap(h1))); } -DHPy debug_ctx_Absolute(HPyContext ctx, DHPy h1) +DHPy debug_ctx_Absolute(HPyContext dctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Absolute(get_info(ctx)->uctx, DHPy_unwrap(h1))); + return DHPy_wrap(dctx, HPy_Absolute(get_info(dctx)->uctx, DHPy_unwrap(h1))); } -DHPy debug_ctx_Invert(HPyContext ctx, DHPy h1) +DHPy debug_ctx_Invert(HPyContext dctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Invert(get_info(ctx)->uctx, DHPy_unwrap(h1))); + return DHPy_wrap(dctx, HPy_Invert(get_info(dctx)->uctx, DHPy_unwrap(h1))); } -DHPy debug_ctx_Lshift(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Lshift(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Lshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Lshift(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Rshift(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Rshift(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Rshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Rshift(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_And(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_And(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_And(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_And(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Xor(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Xor(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Xor(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Xor(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Or(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_Or(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_Or(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_Or(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_Index(HPyContext ctx, DHPy h1) +DHPy debug_ctx_Index(HPyContext dctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Index(get_info(ctx)->uctx, DHPy_unwrap(h1))); + return DHPy_wrap(dctx, HPy_Index(get_info(dctx)->uctx, DHPy_unwrap(h1))); } -DHPy debug_ctx_Long(HPyContext ctx, DHPy h1) +DHPy debug_ctx_Long(HPyContext dctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Long(get_info(ctx)->uctx, DHPy_unwrap(h1))); + return DHPy_wrap(dctx, HPy_Long(get_info(dctx)->uctx, DHPy_unwrap(h1))); } -DHPy debug_ctx_Float(HPyContext ctx, DHPy h1) +DHPy debug_ctx_Float(HPyContext dctx, DHPy h1) { - return DHPy_wrap(ctx, HPy_Float(get_info(ctx)->uctx, DHPy_unwrap(h1))); + return DHPy_wrap(dctx, HPy_Float(get_info(dctx)->uctx, DHPy_unwrap(h1))); } -DHPy debug_ctx_InPlaceAdd(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceAdd(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceAdd(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceAdd(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceSubtract(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceSubtract(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceSubtract(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceSubtract(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceMultiply(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceMultiply(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceMultiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceMultiply(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceMatrixMultiply(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceMatrixMultiply(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceMatrixMultiply(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceFloorDivide(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceFloorDivide(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceFloorDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceFloorDivide(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceTrueDivide(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceTrueDivide(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceTrueDivide(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceTrueDivide(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceRemainder(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceRemainder(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceRemainder(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceRemainder(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlacePower(HPyContext ctx, DHPy h1, DHPy h2, DHPy h3) +DHPy debug_ctx_InPlacePower(HPyContext dctx, DHPy h1, DHPy h2, DHPy h3) { - return DHPy_wrap(ctx, HPy_InPlacePower(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); + return DHPy_wrap(dctx, HPy_InPlacePower(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2), DHPy_unwrap(h3))); } -DHPy debug_ctx_InPlaceLshift(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceLshift(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceLshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceLshift(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceRshift(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceRshift(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceRshift(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceRshift(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceAnd(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceAnd(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceAnd(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceAnd(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceXor(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceXor(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceXor(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceXor(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -DHPy debug_ctx_InPlaceOr(HPyContext ctx, DHPy h1, DHPy h2) +DHPy debug_ctx_InPlaceOr(HPyContext dctx, DHPy h1, DHPy h2) { - return DHPy_wrap(ctx, HPy_InPlaceOr(get_info(ctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); + return DHPy_wrap(dctx, HPy_InPlaceOr(get_info(dctx)->uctx, DHPy_unwrap(h1), DHPy_unwrap(h2))); } -int debug_ctx_Callable_Check(HPyContext ctx, DHPy h) +int debug_ctx_Callable_Check(HPyContext dctx, DHPy h) { - return HPyCallable_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyCallable_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_CallTupleDict(HPyContext ctx, DHPy callable, DHPy args, DHPy kw) +DHPy debug_ctx_CallTupleDict(HPyContext dctx, DHPy callable, DHPy args, DHPy kw) { - return DHPy_wrap(ctx, HPy_CallTupleDict(get_info(ctx)->uctx, DHPy_unwrap(callable), DHPy_unwrap(args), DHPy_unwrap(kw))); + return DHPy_wrap(dctx, HPy_CallTupleDict(get_info(dctx)->uctx, DHPy_unwrap(callable), DHPy_unwrap(args), DHPy_unwrap(kw))); } -void debug_ctx_FatalError(HPyContext ctx, const char *message) +void debug_ctx_FatalError(HPyContext dctx, const char *message) { - HPy_FatalError(get_info(ctx)->uctx, message); + HPy_FatalError(get_info(dctx)->uctx, message); } -void debug_ctx_Err_SetString(HPyContext ctx, DHPy h_type, const char *message) +void debug_ctx_Err_SetString(HPyContext dctx, DHPy h_type, const char *message) { - HPyErr_SetString(get_info(ctx)->uctx, DHPy_unwrap(h_type), message); + HPyErr_SetString(get_info(dctx)->uctx, DHPy_unwrap(h_type), message); } -void debug_ctx_Err_SetObject(HPyContext ctx, DHPy h_type, DHPy h_value) +void debug_ctx_Err_SetObject(HPyContext dctx, DHPy h_type, DHPy h_value) { - HPyErr_SetObject(get_info(ctx)->uctx, DHPy_unwrap(h_type), DHPy_unwrap(h_value)); + HPyErr_SetObject(get_info(dctx)->uctx, DHPy_unwrap(h_type), DHPy_unwrap(h_value)); } -int debug_ctx_Err_Occurred(HPyContext ctx) +int debug_ctx_Err_Occurred(HPyContext dctx) { - return HPyErr_Occurred(get_info(ctx)->uctx); + return HPyErr_Occurred(get_info(dctx)->uctx); } -DHPy debug_ctx_Err_NoMemory(HPyContext ctx) +DHPy debug_ctx_Err_NoMemory(HPyContext dctx) { - return DHPy_wrap(ctx, HPyErr_NoMemory(get_info(ctx)->uctx)); + return DHPy_wrap(dctx, HPyErr_NoMemory(get_info(dctx)->uctx)); } -void debug_ctx_Err_Clear(HPyContext ctx) +void debug_ctx_Err_Clear(HPyContext dctx) { - HPyErr_Clear(get_info(ctx)->uctx); + HPyErr_Clear(get_info(dctx)->uctx); } -int debug_ctx_IsTrue(HPyContext ctx, DHPy h) +int debug_ctx_IsTrue(HPyContext dctx, DHPy h) { - return HPy_IsTrue(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPy_IsTrue(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Type_FromSpec(HPyContext ctx, HPyType_Spec *spec, HPyType_SpecParam *params) +DHPy debug_ctx_Type_FromSpec(HPyContext dctx, HPyType_Spec *spec, HPyType_SpecParam *params) { - return DHPy_wrap(ctx, HPyType_FromSpec(get_info(ctx)->uctx, spec, params)); + return DHPy_wrap(dctx, HPyType_FromSpec(get_info(dctx)->uctx, spec, params)); } -DHPy debug_ctx_Type_GenericNew(HPyContext ctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw) +DHPy debug_ctx_Type_GenericNew(HPyContext dctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw) { - return DHPy_wrap(ctx, HPyType_GenericNew(get_info(ctx)->uctx, DHPy_unwrap(type), NULL /* TODO */, nargs, DHPy_unwrap(kw))); + return DHPy_wrap(dctx, HPyType_GenericNew(get_info(dctx)->uctx, DHPy_unwrap(type), NULL /* TODO */, nargs, DHPy_unwrap(kw))); } -DHPy debug_ctx_GetAttr(HPyContext ctx, DHPy obj, DHPy name) +DHPy debug_ctx_GetAttr(HPyContext dctx, DHPy obj, DHPy name) { - return DHPy_wrap(ctx, HPy_GetAttr(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name))); + return DHPy_wrap(dctx, HPy_GetAttr(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name))); } -DHPy debug_ctx_GetAttr_s(HPyContext ctx, DHPy obj, const char *name) +DHPy debug_ctx_GetAttr_s(HPyContext dctx, DHPy obj, const char *name) { - return DHPy_wrap(ctx, HPy_GetAttr_s(get_info(ctx)->uctx, DHPy_unwrap(obj), name)); + return DHPy_wrap(dctx, HPy_GetAttr_s(get_info(dctx)->uctx, DHPy_unwrap(obj), name)); } -int debug_ctx_HasAttr(HPyContext ctx, DHPy obj, DHPy name) +int debug_ctx_HasAttr(HPyContext dctx, DHPy obj, DHPy name) { - return HPy_HasAttr(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name)); + return HPy_HasAttr(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name)); } -int debug_ctx_HasAttr_s(HPyContext ctx, DHPy obj, const char *name) +int debug_ctx_HasAttr_s(HPyContext dctx, DHPy obj, const char *name) { - return HPy_HasAttr_s(get_info(ctx)->uctx, DHPy_unwrap(obj), name); + return HPy_HasAttr_s(get_info(dctx)->uctx, DHPy_unwrap(obj), name); } -int debug_ctx_SetAttr(HPyContext ctx, DHPy obj, DHPy name, DHPy value) +int debug_ctx_SetAttr(HPyContext dctx, DHPy obj, DHPy name, DHPy value) { - return HPy_SetAttr(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name), DHPy_unwrap(value)); + return HPy_SetAttr(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name), DHPy_unwrap(value)); } -int debug_ctx_SetAttr_s(HPyContext ctx, DHPy obj, const char *name, DHPy value) +int debug_ctx_SetAttr_s(HPyContext dctx, DHPy obj, const char *name, DHPy value) { - return HPy_SetAttr_s(get_info(ctx)->uctx, DHPy_unwrap(obj), name, DHPy_unwrap(value)); + return HPy_SetAttr_s(get_info(dctx)->uctx, DHPy_unwrap(obj), name, DHPy_unwrap(value)); } -DHPy debug_ctx_GetItem(HPyContext ctx, DHPy obj, DHPy key) +DHPy debug_ctx_GetItem(HPyContext dctx, DHPy obj, DHPy key) { - return DHPy_wrap(ctx, HPy_GetItem(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(key))); + return DHPy_wrap(dctx, HPy_GetItem(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(key))); } -DHPy debug_ctx_GetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx) +DHPy debug_ctx_GetItem_i(HPyContext dctx, DHPy obj, HPy_ssize_t idx) { - return DHPy_wrap(ctx, HPy_GetItem_i(get_info(ctx)->uctx, DHPy_unwrap(obj), idx)); + return DHPy_wrap(dctx, HPy_GetItem_i(get_info(dctx)->uctx, DHPy_unwrap(obj), idx)); } -DHPy debug_ctx_GetItem_s(HPyContext ctx, DHPy obj, const char *key) +DHPy debug_ctx_GetItem_s(HPyContext dctx, DHPy obj, const char *key) { - return DHPy_wrap(ctx, HPy_GetItem_s(get_info(ctx)->uctx, DHPy_unwrap(obj), key)); + return DHPy_wrap(dctx, HPy_GetItem_s(get_info(dctx)->uctx, DHPy_unwrap(obj), key)); } -int debug_ctx_SetItem(HPyContext ctx, DHPy obj, DHPy key, DHPy value) +int debug_ctx_SetItem(HPyContext dctx, DHPy obj, DHPy key, DHPy value) { - return HPy_SetItem(get_info(ctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(key), DHPy_unwrap(value)); + return HPy_SetItem(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(key), DHPy_unwrap(value)); } -int debug_ctx_SetItem_i(HPyContext ctx, DHPy obj, HPy_ssize_t idx, DHPy value) +int debug_ctx_SetItem_i(HPyContext dctx, DHPy obj, HPy_ssize_t idx, DHPy value) { - return HPy_SetItem_i(get_info(ctx)->uctx, DHPy_unwrap(obj), idx, DHPy_unwrap(value)); + return HPy_SetItem_i(get_info(dctx)->uctx, DHPy_unwrap(obj), idx, DHPy_unwrap(value)); } -int debug_ctx_SetItem_s(HPyContext ctx, DHPy obj, const char *key, DHPy value) +int debug_ctx_SetItem_s(HPyContext dctx, DHPy obj, const char *key, DHPy value) { - return HPy_SetItem_s(get_info(ctx)->uctx, DHPy_unwrap(obj), key, DHPy_unwrap(value)); + return HPy_SetItem_s(get_info(dctx)->uctx, DHPy_unwrap(obj), key, DHPy_unwrap(value)); } -void *debug_ctx_Cast(HPyContext ctx, DHPy h) +void *debug_ctx_Cast(HPyContext dctx, DHPy h) { - return _HPy_Cast(get_info(ctx)->uctx, DHPy_unwrap(h)); + return _HPy_Cast(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_New(HPyContext ctx, DHPy h_type, void **data) +DHPy debug_ctx_New(HPyContext dctx, DHPy h_type, void **data) { - return DHPy_wrap(ctx, _HPy_New(get_info(ctx)->uctx, DHPy_unwrap(h_type), data)); + return DHPy_wrap(dctx, _HPy_New(get_info(dctx)->uctx, DHPy_unwrap(h_type), data)); } -DHPy debug_ctx_Repr(HPyContext ctx, DHPy obj) +DHPy debug_ctx_Repr(HPyContext dctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_Repr(get_info(ctx)->uctx, DHPy_unwrap(obj))); + return DHPy_wrap(dctx, HPy_Repr(get_info(dctx)->uctx, DHPy_unwrap(obj))); } -DHPy debug_ctx_Str(HPyContext ctx, DHPy obj) +DHPy debug_ctx_Str(HPyContext dctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_Str(get_info(ctx)->uctx, DHPy_unwrap(obj))); + return DHPy_wrap(dctx, HPy_Str(get_info(dctx)->uctx, DHPy_unwrap(obj))); } -DHPy debug_ctx_ASCII(HPyContext ctx, DHPy obj) +DHPy debug_ctx_ASCII(HPyContext dctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_ASCII(get_info(ctx)->uctx, DHPy_unwrap(obj))); + return DHPy_wrap(dctx, HPy_ASCII(get_info(dctx)->uctx, DHPy_unwrap(obj))); } -DHPy debug_ctx_Bytes(HPyContext ctx, DHPy obj) +DHPy debug_ctx_Bytes(HPyContext dctx, DHPy obj) { - return DHPy_wrap(ctx, HPy_Bytes(get_info(ctx)->uctx, DHPy_unwrap(obj))); + return DHPy_wrap(dctx, HPy_Bytes(get_info(dctx)->uctx, DHPy_unwrap(obj))); } -DHPy debug_ctx_RichCompare(HPyContext ctx, DHPy v, DHPy w, int op) +DHPy debug_ctx_RichCompare(HPyContext dctx, DHPy v, DHPy w, int op) { - return DHPy_wrap(ctx, HPy_RichCompare(get_info(ctx)->uctx, DHPy_unwrap(v), DHPy_unwrap(w), op)); + return DHPy_wrap(dctx, HPy_RichCompare(get_info(dctx)->uctx, DHPy_unwrap(v), DHPy_unwrap(w), op)); } -int debug_ctx_RichCompareBool(HPyContext ctx, DHPy v, DHPy w, int op) +int debug_ctx_RichCompareBool(HPyContext dctx, DHPy v, DHPy w, int op) { - return HPy_RichCompareBool(get_info(ctx)->uctx, DHPy_unwrap(v), DHPy_unwrap(w), op); + return HPy_RichCompareBool(get_info(dctx)->uctx, DHPy_unwrap(v), DHPy_unwrap(w), op); } -HPy_hash_t debug_ctx_Hash(HPyContext ctx, DHPy obj) +HPy_hash_t debug_ctx_Hash(HPyContext dctx, DHPy obj) { - return HPy_Hash(get_info(ctx)->uctx, DHPy_unwrap(obj)); + return HPy_Hash(get_info(dctx)->uctx, DHPy_unwrap(obj)); } -int debug_ctx_Bytes_Check(HPyContext ctx, DHPy h) +int debug_ctx_Bytes_Check(HPyContext dctx, DHPy h) { - return HPyBytes_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyBytes_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -HPy_ssize_t debug_ctx_Bytes_Size(HPyContext ctx, DHPy h) +HPy_ssize_t debug_ctx_Bytes_Size(HPyContext dctx, DHPy h) { - return HPyBytes_Size(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyBytes_Size(get_info(dctx)->uctx, DHPy_unwrap(h)); } -HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext ctx, DHPy h) +HPy_ssize_t debug_ctx_Bytes_GET_SIZE(HPyContext dctx, DHPy h) { - return HPyBytes_GET_SIZE(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyBytes_GET_SIZE(get_info(dctx)->uctx, DHPy_unwrap(h)); } -char *debug_ctx_Bytes_AsString(HPyContext ctx, DHPy h) +char *debug_ctx_Bytes_AsString(HPyContext dctx, DHPy h) { - return HPyBytes_AsString(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyBytes_AsString(get_info(dctx)->uctx, DHPy_unwrap(h)); } -char *debug_ctx_Bytes_AS_STRING(HPyContext ctx, DHPy h) +char *debug_ctx_Bytes_AS_STRING(HPyContext dctx, DHPy h) { - return HPyBytes_AS_STRING(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyBytes_AS_STRING(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Bytes_FromString(HPyContext ctx, const char *v) +DHPy debug_ctx_Bytes_FromString(HPyContext dctx, const char *v) { - return DHPy_wrap(ctx, HPyBytes_FromString(get_info(ctx)->uctx, v)); + return DHPy_wrap(dctx, HPyBytes_FromString(get_info(dctx)->uctx, v)); } -DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext ctx, const char *v, HPy_ssize_t len) +DHPy debug_ctx_Bytes_FromStringAndSize(HPyContext dctx, const char *v, HPy_ssize_t len) { - return DHPy_wrap(ctx, HPyBytes_FromStringAndSize(get_info(ctx)->uctx, v, len)); + return DHPy_wrap(dctx, HPyBytes_FromStringAndSize(get_info(dctx)->uctx, v, len)); } -DHPy debug_ctx_Unicode_FromString(HPyContext ctx, const char *utf8) +DHPy debug_ctx_Unicode_FromString(HPyContext dctx, const char *utf8) { - return DHPy_wrap(ctx, HPyUnicode_FromString(get_info(ctx)->uctx, utf8)); + return DHPy_wrap(dctx, HPyUnicode_FromString(get_info(dctx)->uctx, utf8)); } -int debug_ctx_Unicode_Check(HPyContext ctx, DHPy h) +int debug_ctx_Unicode_Check(HPyContext dctx, DHPy h) { - return HPyUnicode_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyUnicode_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Unicode_AsUTF8String(HPyContext ctx, DHPy h) +DHPy debug_ctx_Unicode_AsUTF8String(HPyContext dctx, DHPy h) { - return DHPy_wrap(ctx, HPyUnicode_AsUTF8String(get_info(ctx)->uctx, DHPy_unwrap(h))); + return DHPy_wrap(dctx, HPyUnicode_AsUTF8String(get_info(dctx)->uctx, DHPy_unwrap(h))); } -DHPy debug_ctx_Unicode_FromWideChar(HPyContext ctx, const wchar_t *w, HPy_ssize_t size) +DHPy debug_ctx_Unicode_FromWideChar(HPyContext dctx, const wchar_t *w, HPy_ssize_t size) { - return DHPy_wrap(ctx, HPyUnicode_FromWideChar(get_info(ctx)->uctx, w, size)); + return DHPy_wrap(dctx, HPyUnicode_FromWideChar(get_info(dctx)->uctx, w, size)); } -int debug_ctx_List_Check(HPyContext ctx, DHPy h) +int debug_ctx_List_Check(HPyContext dctx, DHPy h) { - return HPyList_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyList_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_List_New(HPyContext ctx, HPy_ssize_t len) +DHPy debug_ctx_List_New(HPyContext dctx, HPy_ssize_t len) { - return DHPy_wrap(ctx, HPyList_New(get_info(ctx)->uctx, len)); + return DHPy_wrap(dctx, HPyList_New(get_info(dctx)->uctx, len)); } -int debug_ctx_List_Append(HPyContext ctx, DHPy h_list, DHPy h_item) +int debug_ctx_List_Append(HPyContext dctx, DHPy h_list, DHPy h_item) { - return HPyList_Append(get_info(ctx)->uctx, DHPy_unwrap(h_list), DHPy_unwrap(h_item)); + return HPyList_Append(get_info(dctx)->uctx, DHPy_unwrap(h_list), DHPy_unwrap(h_item)); } -int debug_ctx_Dict_Check(HPyContext ctx, DHPy h) +int debug_ctx_Dict_Check(HPyContext dctx, DHPy h) { - return HPyDict_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyDict_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Dict_New(HPyContext ctx) +DHPy debug_ctx_Dict_New(HPyContext dctx) { - return DHPy_wrap(ctx, HPyDict_New(get_info(ctx)->uctx)); + return DHPy_wrap(dctx, HPyDict_New(get_info(dctx)->uctx)); } -int debug_ctx_Tuple_Check(HPyContext ctx, DHPy h) +int debug_ctx_Tuple_Check(HPyContext dctx, DHPy h) { - return HPyTuple_Check(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPyTuple_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Tuple_FromArray(HPyContext ctx, DHPy items[], HPy_ssize_t n) +DHPy debug_ctx_Tuple_FromArray(HPyContext dctx, DHPy items[], HPy_ssize_t n) { - return DHPy_wrap(ctx, HPyTuple_FromArray(get_info(ctx)->uctx, NULL /* TODO */, n)); + return DHPy_wrap(dctx, HPyTuple_FromArray(get_info(dctx)->uctx, NULL /* TODO */, n)); } -DHPy debug_ctx_FromPyObject(HPyContext ctx, cpy_PyObject *obj) +DHPy debug_ctx_FromPyObject(HPyContext dctx, cpy_PyObject *obj) { - return DHPy_wrap(ctx, HPy_FromPyObject(get_info(ctx)->uctx, obj)); + return DHPy_wrap(dctx, HPy_FromPyObject(get_info(dctx)->uctx, obj)); } -cpy_PyObject *debug_ctx_AsPyObject(HPyContext ctx, DHPy h) +cpy_PyObject *debug_ctx_AsPyObject(HPyContext dctx, DHPy h) { - return HPy_AsPyObject(get_info(ctx)->uctx, DHPy_unwrap(h)); + return HPy_AsPyObject(get_info(dctx)->uctx, DHPy_unwrap(h)); } -void debug_ctx_CallDestroyAndThenDealloc(HPyContext ctx, void *func, cpy_PyObject *self) +void debug_ctx_CallDestroyAndThenDealloc(HPyContext dctx, void *func, cpy_PyObject *self) { - _HPy_CallDestroyAndThenDealloc(get_info(ctx)->uctx, func, self); + _HPy_CallDestroyAndThenDealloc(get_info(dctx)->uctx, func, self); } -HPyListBuilder debug_ctx_ListBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) +HPyListBuilder debug_ctx_ListBuilder_New(HPyContext dctx, HPy_ssize_t initial_size) { - return HPyListBuilder_New(get_info(ctx)->uctx, initial_size); + return HPyListBuilder_New(get_info(dctx)->uctx, initial_size); } -void debug_ctx_ListBuilder_Set(HPyContext ctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item) +void debug_ctx_ListBuilder_Set(HPyContext dctx, HPyListBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyListBuilder_Set(get_info(ctx)->uctx, builder, index, DHPy_unwrap(h_item)); + HPyListBuilder_Set(get_info(dctx)->uctx, builder, index, DHPy_unwrap(h_item)); } -DHPy debug_ctx_ListBuilder_Build(HPyContext ctx, HPyListBuilder builder) +DHPy debug_ctx_ListBuilder_Build(HPyContext dctx, HPyListBuilder builder) { - return DHPy_wrap(ctx, HPyListBuilder_Build(get_info(ctx)->uctx, builder)); + return DHPy_wrap(dctx, HPyListBuilder_Build(get_info(dctx)->uctx, builder)); } -void debug_ctx_ListBuilder_Cancel(HPyContext ctx, HPyListBuilder builder) +void debug_ctx_ListBuilder_Cancel(HPyContext dctx, HPyListBuilder builder) { - HPyListBuilder_Cancel(get_info(ctx)->uctx, builder); + HPyListBuilder_Cancel(get_info(dctx)->uctx, builder); } -HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext ctx, HPy_ssize_t initial_size) +HPyTupleBuilder debug_ctx_TupleBuilder_New(HPyContext dctx, HPy_ssize_t initial_size) { - return HPyTupleBuilder_New(get_info(ctx)->uctx, initial_size); + return HPyTupleBuilder_New(get_info(dctx)->uctx, initial_size); } -void debug_ctx_TupleBuilder_Set(HPyContext ctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item) +void debug_ctx_TupleBuilder_Set(HPyContext dctx, HPyTupleBuilder builder, HPy_ssize_t index, DHPy h_item) { - HPyTupleBuilder_Set(get_info(ctx)->uctx, builder, index, DHPy_unwrap(h_item)); + HPyTupleBuilder_Set(get_info(dctx)->uctx, builder, index, DHPy_unwrap(h_item)); } -DHPy debug_ctx_TupleBuilder_Build(HPyContext ctx, HPyTupleBuilder builder) +DHPy debug_ctx_TupleBuilder_Build(HPyContext dctx, HPyTupleBuilder builder) { - return DHPy_wrap(ctx, HPyTupleBuilder_Build(get_info(ctx)->uctx, builder)); + return DHPy_wrap(dctx, HPyTupleBuilder_Build(get_info(dctx)->uctx, builder)); } -void debug_ctx_TupleBuilder_Cancel(HPyContext ctx, HPyTupleBuilder builder) +void debug_ctx_TupleBuilder_Cancel(HPyContext dctx, HPyTupleBuilder builder) { - HPyTupleBuilder_Cancel(get_info(ctx)->uctx, builder); + HPyTupleBuilder_Cancel(get_info(dctx)->uctx, builder); } -HPyTracker debug_ctx_Tracker_New(HPyContext ctx, HPy_ssize_t size) +HPyTracker debug_ctx_Tracker_New(HPyContext dctx, HPy_ssize_t size) { - return HPyTracker_New(get_info(ctx)->uctx, size); + return HPyTracker_New(get_info(dctx)->uctx, size); } -int debug_ctx_Tracker_Add(HPyContext ctx, HPyTracker ht, DHPy h) +int debug_ctx_Tracker_Add(HPyContext dctx, HPyTracker ht, DHPy h) { - return HPyTracker_Add(get_info(ctx)->uctx, ht, DHPy_unwrap(h)); + return HPyTracker_Add(get_info(dctx)->uctx, ht, DHPy_unwrap(h)); } -void debug_ctx_Tracker_ForgetAll(HPyContext ctx, HPyTracker ht) +void debug_ctx_Tracker_ForgetAll(HPyContext dctx, HPyTracker ht) { - HPyTracker_ForgetAll(get_info(ctx)->uctx, ht); + HPyTracker_ForgetAll(get_info(dctx)->uctx, ht); } -void debug_ctx_Tracker_Close(HPyContext ctx, HPyTracker ht) +void debug_ctx_Tracker_Close(HPyContext dctx, HPyTracker ht) { - HPyTracker_Close(get_info(ctx)->uctx, ht); + HPyTracker_Close(get_info(dctx)->uctx, ht); } -void debug_ctx_Dump(HPyContext ctx, DHPy h) +void debug_ctx_Dump(HPyContext dctx, DHPy h) { - _HPy_Dump(get_info(ctx)->uctx, DHPy_unwrap(h)); + _HPy_Dump(get_info(dctx)->uctx, DHPy_unwrap(h)); } diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 72f433076..dc25585e8 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -9,11 +9,11 @@ static struct _HPyContext_s g_debug_ctx = { .ctx_version = 1, }; -void debug_ctx_Close(HPyContext ctx, DHPy dh) +void debug_ctx_Close(HPyContext dctx, DHPy dh) { UHPy uh = DHPy_unwrap(dh); - DHPy_close(ctx, dh); - HPy_Close(get_info(ctx)->uctx, uh); + DHPy_close(dctx, dh); + HPy_Close(get_info(dctx)->uctx, uh); } diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index 9efeeaa2e..e1dee9787 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -25,9 +25,9 @@ #include "debug_internal.h" #include "handles.h" // for _py2h and _h2py -static inline DHPy _py2dh(HPyContext ctx, PyObject *obj) +static inline DHPy _py2dh(HPyContext dctx, PyObject *obj) { - return DHPy_wrap(ctx, _py2h(obj)); + return DHPy_wrap(dctx, _py2h(obj)); } static inline PyObject *_dh2py(DHPy dh) @@ -35,7 +35,7 @@ static inline PyObject *_dh2py(DHPy dh) return _h2py(DHPy_unwrap(dh)); } -void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext dctx, HPyFunc_Signature sig, void *func, void *args) { @@ -43,57 +43,57 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, case HPyFunc_NOARGS: { HPyFunc_noargs f = (HPyFunc_noargs)func; _HPyFunc_args_NOARGS *a = (_HPyFunc_args_NOARGS*)args; - DHPy dh_self = _py2dh(ctx, a->self); - DHPy dh_result = f(ctx, dh_self); + DHPy dh_self = _py2dh(dctx, a->self); + DHPy dh_result = f(dctx, dh_self); a->result = _dh2py(dh_result); - DHPy_close(ctx, dh_self); - DHPy_close(ctx, dh_result); + DHPy_close(dctx, dh_self); + DHPy_close(dctx, dh_result); return; } case HPyFunc_O: { HPyFunc_o f = (HPyFunc_o)func; _HPyFunc_args_O *a = (_HPyFunc_args_O*)args; - DHPy dh_self = _py2dh(ctx, a->self); - DHPy dh_arg = _py2dh(ctx, a->arg); - DHPy dh_result = f(ctx, dh_self, dh_arg); + DHPy dh_self = _py2dh(dctx, a->self); + DHPy dh_arg = _py2dh(dctx, a->arg); + DHPy dh_result = f(dctx, dh_self, dh_arg); a->result = _dh2py(dh_result); - DHPy_close(ctx, dh_self); - DHPy_close(ctx, dh_arg); - DHPy_close(ctx, dh_result); + DHPy_close(dctx, dh_self); + DHPy_close(dctx, dh_arg); + DHPy_close(dctx, dh_result); return; } case HPyFunc_VARARGS: { HPyFunc_varargs f = (HPyFunc_varargs)func; _HPyFunc_args_VARARGS *a = (_HPyFunc_args_VARARGS*)args; - DHPy dh_self = _py2dh(ctx, a->self); + DHPy dh_self = _py2dh(dctx, a->self); Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); DHPy dh_args[nargs * sizeof(DHPy)]; for (Py_ssize_t i = 0; i < nargs; i++) { - dh_args[i] = _py2dh(ctx, PyTuple_GET_ITEM(a->args, i)); + dh_args[i] = _py2dh(dctx, PyTuple_GET_ITEM(a->args, i)); } - a->result = _dh2py(f(ctx, dh_self, dh_args, nargs)); - DHPy_close(ctx, dh_self); + a->result = _dh2py(f(dctx, dh_self, dh_args, nargs)); + DHPy_close(dctx, dh_self); for (Py_ssize_t i = 0; i < nargs; i++) { - DHPy_close(ctx, dh_args[i]); + DHPy_close(dctx, dh_args[i]); } return; } case HPyFunc_KEYWORDS: { HPyFunc_keywords f = (HPyFunc_keywords)func; _HPyFunc_args_KEYWORDS *a = (_HPyFunc_args_KEYWORDS*)args; - DHPy dh_self = _py2dh(ctx, a->self); + DHPy dh_self = _py2dh(dctx, a->self); Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); DHPy dh_args[nargs * sizeof(DHPy)]; for (Py_ssize_t i = 0; i < nargs; i++) { - dh_args[i] = _py2dh(ctx, PyTuple_GET_ITEM(a->args, i)); + dh_args[i] = _py2dh(dctx, PyTuple_GET_ITEM(a->args, i)); } - DHPy dh_kw = _py2dh(ctx, a->kw); - a->result = _dh2py(f(ctx, dh_self, dh_args, nargs, dh_kw)); - DHPy_close(ctx, dh_self); + DHPy dh_kw = _py2dh(dctx, a->kw); + a->result = _dh2py(f(dctx, dh_self, dh_args, nargs, dh_kw)); + DHPy_close(dctx, dh_self); for (Py_ssize_t i = 0; i < nargs; i++) { - DHPy_close(ctx, dh_args[i]); + DHPy_close(dctx, dh_args[i]); } - DHPy_close(ctx, dh_kw); + DHPy_close(dctx, dh_kw); return; } case HPyFunc_INITPROC: { diff --git a/hpy/debug/src/debug_ctx_not_cpython.c b/hpy/debug/src/debug_ctx_not_cpython.c index 051801ada..16bc5c1fa 100644 --- a/hpy/debug/src/debug_ctx_not_cpython.c +++ b/hpy/debug/src/debug_ctx_not_cpython.c @@ -5,12 +5,12 @@ #include "debug_internal.h" -void debug_ctx_CallRealFunctionFromTrampoline(HPyContext ctx, +void debug_ctx_CallRealFunctionFromTrampoline(HPyContext dctx, HPyFunc_Signature sig, void *func, void *args) { - HPyContext original_ctx = get_info(ctx)->original_ctx; - HPy_FatalError(original_ctx, + HPyContext uctx = get_info(dctx)->uctx; + HPy_FatalError(uctx, "Something is very wrong! _HPy_CallRealFunctionFromTrampoline() " "should be used only by the CPython version of hpy.universal"); } diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index c67e8f1e1..832ad3d0d 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -1,11 +1,11 @@ #include "debug_internal.h" -DHPy DHPy_wrap(HPyContext ctx, UHPy uh) +DHPy DHPy_wrap(HPyContext dctx, UHPy uh) { UHPy_sanity_check(uh); if (HPy_IsNull(uh)) return HPy_NULL; - HPyDebugInfo *info = get_info(ctx); + HPyDebugInfo *info = get_info(dctx); DebugHandle *handle = malloc(sizeof(DebugHandle)); handle->uh = uh; handle->generation = info->current_generation; @@ -17,12 +17,12 @@ DHPy DHPy_wrap(HPyContext ctx, UHPy uh) return as_DHPy(handle); } -void DHPy_close(HPyContext ctx, DHPy dh) +void DHPy_close(HPyContext dctx, DHPy dh) { DHPy_sanity_check(dh); if (HPy_IsNull(dh)) return; - HPyDebugInfo *info = get_info(ctx); + HPyDebugInfo *info = get_info(dctx); DebugHandle *handle = as_DebugHandle(dh); // remove the handle from the open_handles list diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index c453101da..f6b589945 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -77,8 +77,8 @@ static inline DHPy as_DHPy(DebugHandle *handle) { return (DHPy){(HPy_ssize_t)handle}; } -DHPy DHPy_wrap(HPyContext ctx, UHPy uh); -void DHPy_close(HPyContext ctx, DHPy dh); +DHPy DHPy_wrap(HPyContext dctx, UHPy uh); +void DHPy_close(HPyContext dctx, DHPy dh); void DHPy_free(DHPy dh); static inline UHPy DHPy_unwrap(DHPy dh) { @@ -97,9 +97,9 @@ typedef struct { //DebugHandle *closed_handles; // linked list } HPyDebugInfo; -static inline HPyDebugInfo *get_info(HPyContext ctx) +static inline HPyDebugInfo *get_info(HPyContext dctx) { - HPyDebugInfo *info = (HPyDebugInfo*)ctx->_private; + HPyDebugInfo *info = (HPyDebugInfo*)dctx->_private; assert(info->magic_number == HPY_DEBUG_MAGIC); // sanity check return info; } diff --git a/hpy/debug/src/include/hpy_debug.h b/hpy/debug/src/include/hpy_debug.h index a49c28a08..f036299e3 100644 --- a/hpy/debug/src/include/hpy_debug.h +++ b/hpy/debug/src/include/hpy_debug.h @@ -9,6 +9,6 @@ HPyContext hpy_debug_get_ctx(HPyContext original_ctx); // of hpy.universal the code is embedded inside the extension, so we can call // this function directly instead of dlopen it. This is similar to what // CPython does for its own built-in modules -HPy HPyInit__debug(HPyContext ctx); +HPy HPyInit__debug(HPyContext uctx); #endif /* HPY_DEBUG_H */ diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index 39c15fb10..c20f3d451 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -11,6 +11,11 @@ def visit_IdentifierType(self, node): if node.names == ['HPy']: node.names = ['DHPy'] + def visit_TypeDecl(self, node): + if node.declname == 'ctx': + node.declname = 'dctx' + self.generic_visit(node) + def funcnode_with_new_name(node, name): newnode = deepcopy(node) typedecl = find_typedecl(newnode) @@ -81,7 +86,7 @@ def get_params(): lst = [] for p in node.type.args.params: if p.name == 'ctx': - lst.append('get_info(ctx)->uctx') + lst.append('get_info(dctx)->uctx') elif toC(p.type) == 'DHPy': lst.append('DHPy_unwrap(%s)' % p.name) elif toC(p.type) in ('DHPy *', 'DHPy []'): @@ -99,7 +104,7 @@ def get_params(): if rettype == 'void': w(f' {func.name}({params});') elif rettype == 'DHPy': - w(f' return DHPy_wrap(ctx, {func.name}({params}));') + w(f' return DHPy_wrap(dctx, {func.name}({params}));') else: w(f' return {func.name}({params});') w('}') From f94104c534a5e4e19fda450da450b04a22ff298f Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 25 Jan 2021 16:08:54 +0100 Subject: [PATCH 46/65] implement HPyFunct_INITPROC for the debug mode --- hpy/debug/src/debug_ctx_cpython.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index e1dee9787..ea1b9a7d2 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -97,7 +97,22 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext dctx, return; } case HPyFunc_INITPROC: { - abort(); + HPyFunc_initproc f = (HPyFunc_initproc)func; + _HPyFunc_args_INITPROC *a = (_HPyFunc_args_INITPROC*)args; + DHPy dh_self = _py2dh(dctx, a->self); + Py_ssize_t nargs = PyTuple_GET_SIZE(a->args); + DHPy dh_args[nargs * sizeof(DHPy)]; + for (Py_ssize_t i = 0; i < nargs; i++) { + dh_args[i] = _py2dh(dctx, PyTuple_GET_ITEM(a->args, i)); + } + DHPy dh_kw = _py2dh(dctx, a->kw); + a->result = f(dctx, dh_self, dh_args, nargs, dh_kw); + DHPy_close(dctx, dh_self); + for (Py_ssize_t i = 0; i < nargs; i++) { + DHPy_close(dctx, dh_args[i]); + } + DHPy_close(dctx, dh_kw); + return; } default: abort(); // XXX From 24e758822e9c084c7eed4656028c873ddd0e2144 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 25 Jan 2021 16:46:29 +0100 Subject: [PATCH 47/65] implement debug_ctx_Tuple_FromArray --- hpy/debug/src/autogen_debug_wrappers.c | 10 -------- hpy/debug/src/debug_ctx.c | 33 +++++++++++++++++++------- hpy/tools/autogen/debug.py | 6 +++-- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index d926998d9..f70d78ee7 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -332,11 +332,6 @@ DHPy debug_ctx_Type_FromSpec(HPyContext dctx, HPyType_Spec *spec, HPyType_SpecPa return DHPy_wrap(dctx, HPyType_FromSpec(get_info(dctx)->uctx, spec, params)); } -DHPy debug_ctx_Type_GenericNew(HPyContext dctx, DHPy type, DHPy *args, HPy_ssize_t nargs, DHPy kw) -{ - return DHPy_wrap(dctx, HPyType_GenericNew(get_info(dctx)->uctx, DHPy_unwrap(type), NULL /* TODO */, nargs, DHPy_unwrap(kw))); -} - DHPy debug_ctx_GetAttr(HPyContext dctx, DHPy obj, DHPy name) { return DHPy_wrap(dctx, HPy_GetAttr(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name))); @@ -527,11 +522,6 @@ int debug_ctx_Tuple_Check(HPyContext dctx, DHPy h) return HPyTuple_Check(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Tuple_FromArray(HPyContext dctx, DHPy items[], HPy_ssize_t n) -{ - return DHPy_wrap(dctx, HPyTuple_FromArray(get_info(dctx)->uctx, NULL /* TODO */, n)); -} - DHPy debug_ctx_FromPyObject(HPyContext dctx, cpy_PyObject *obj) { return DHPy_wrap(dctx, HPy_FromPyObject(get_info(dctx)->uctx, obj)); diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index dc25585e8..4d05dec83 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -9,14 +9,6 @@ static struct _HPyContext_s g_debug_ctx = { .ctx_version = 1, }; -void debug_ctx_Close(HPyContext dctx, DHPy dh) -{ - UHPy uh = DHPy_unwrap(dh); - DHPy_close(dctx, dh); - HPy_Close(get_info(dctx)->uctx, uh); -} - - // NOTE: at the moment this function assumes that uctx is always the // same. If/when we migrate to a system in which we can have multiple // independent contexts, this function should ensure to create a different @@ -68,3 +60,28 @@ __attribute__((unused)) static void hpy_magic_dump(HPy h) _HPy_Dump(&g_universal_ctx, dh->uh); } } + +/* ~~~~~~~~~~ manually written wrappers ~~~~~~~~~~ */ + +void debug_ctx_Close(HPyContext dctx, DHPy dh) +{ + UHPy uh = DHPy_unwrap(dh); + DHPy_close(dctx, dh); + HPy_Close(get_info(dctx)->uctx, uh); +} + +DHPy debug_ctx_Tuple_FromArray(HPyContext dctx, DHPy dh_items[], HPy_ssize_t n) +{ + // NOTE: replace VLAs with alloca() once issue #157 is fixed + UHPy uh_items[n]; + for(int i=0; iuctx, uh_items, n)); +} + +DHPy debug_ctx_Type_GenericNew(HPyContext dctx, DHPy type, DHPy *args, HPy_ssize_t nargs, + DHPy kw) +{ + abort(); +} diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index c20f3d451..addb1bf17 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -59,6 +59,8 @@ class autogen_debug_wrappers(AutoGenFile): NO_WRAPPER = set([ '_HPy_CallRealFunctionFromTrampoline', 'HPy_Close', + 'HPyTuple_FromArray', + 'HPyType_GenericNew', ]) def generate(self): @@ -90,8 +92,8 @@ def get_params(): elif toC(p.type) == 'DHPy': lst.append('DHPy_unwrap(%s)' % p.name) elif toC(p.type) in ('DHPy *', 'DHPy []'): - #lst.append('(HPy *)%s' % p.name) - lst.append('NULL /* TODO */') + assert False, ('C type %s not supported, please write the wrapper ' + 'for %s by hand' % (toC(p.type), func.name)) else: lst.append(p.name) return ', '.join(lst) From a186e66ce0e23628b629c7a6b68004e70f90b35c Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 25 Jan 2021 16:50:47 +0100 Subject: [PATCH 48/65] implement debug_ctx_Type_GenericNew --- hpy/debug/src/debug_ctx.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 4d05dec83..b490bb6ba 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -80,8 +80,16 @@ DHPy debug_ctx_Tuple_FromArray(HPyContext dctx, DHPy dh_items[], HPy_ssize_t n) return DHPy_wrap(dctx, HPyTuple_FromArray(get_info(dctx)->uctx, uh_items, n)); } -DHPy debug_ctx_Type_GenericNew(HPyContext dctx, DHPy type, DHPy *args, HPy_ssize_t nargs, - DHPy kw) +DHPy debug_ctx_Type_GenericNew(HPyContext dctx, DHPy dh_type, DHPy *dh_args, + HPy_ssize_t nargs, DHPy dh_kw) { - abort(); + UHPy uh_type = DHPy_unwrap(dh_type); + UHPy uh_kw = DHPy_unwrap(dh_kw); + // NOTE: replace VLAs with alloca() once issue #157 is fixed + UHPy uh_args[nargs]; + for(int i=0; iuctx, uh_type, uh_args, + nargs, uh_kw)); } From a670b73a31ed12cb777dc2a6f84c4a18af6da9f4 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 25 Jan 2021 17:01:09 +0100 Subject: [PATCH 49/65] autogen the rest of debug_ctx_CallRealFunctionFromTrampoline; test_slots.py fully passes --- hpy/debug/src/autogen_debug_ctx_call.i | 272 +++++++++++++++++++++++++ hpy/debug/src/debug_ctx_cpython.c | 1 + hpy/tools/autogen/__main__.py | 3 +- hpy/tools/autogen/debug.py | 50 +++++ 4 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 hpy/debug/src/autogen_debug_ctx_call.i diff --git a/hpy/debug/src/autogen_debug_ctx_call.i b/hpy/debug/src/autogen_debug_ctx_call.i new file mode 100644 index 000000000..fc93264f9 --- /dev/null +++ b/hpy/debug/src/autogen_debug_ctx_call.i @@ -0,0 +1,272 @@ + +/* + DO NOT EDIT THIS FILE! + + This file is automatically generated by hpy.tools.autogen.debug.autogen_debug_ctx_call_i + See also hpy.tools.autogen and hpy/tools/public_api.h + + Run this to regenerate: + make autogen + +*/ + + case HPyFunc_UNARYFUNC: { + 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); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_BINARYFUNC: { + HPyFunc_binaryfunc f = (HPyFunc_binaryfunc)func; + _HPyFunc_args_BINARYFUNC *a = (_HPyFunc_args_BINARYFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_result = f(dctx, dh_arg0, dh_arg1); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_TERNARYFUNC: { + HPyFunc_ternaryfunc f = (HPyFunc_ternaryfunc)func; + _HPyFunc_args_TERNARYFUNC *a = (_HPyFunc_args_TERNARYFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_arg2 = _py2dh(dctx, a->arg2); + DHPy dh_result = f(dctx, dh_arg0, dh_arg1, dh_arg2); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_arg2); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_INQUIRY: { + HPyFunc_inquiry f = (HPyFunc_inquiry)func; + _HPyFunc_args_INQUIRY *a = (_HPyFunc_args_INQUIRY*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + a->result = f(dctx, dh_arg0); + DHPy_close(dctx, dh_arg0); + return; + } + case HPyFunc_LENFUNC: { + HPyFunc_lenfunc f = (HPyFunc_lenfunc)func; + _HPyFunc_args_LENFUNC *a = (_HPyFunc_args_LENFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + a->result = f(dctx, dh_arg0); + DHPy_close(dctx, dh_arg0); + return; + } + case HPyFunc_SSIZEARGFUNC: { + HPyFunc_ssizeargfunc f = (HPyFunc_ssizeargfunc)func; + _HPyFunc_args_SSIZEARGFUNC *a = (_HPyFunc_args_SSIZEARGFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0, a->arg1); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_SSIZESSIZEARGFUNC: { + HPyFunc_ssizessizeargfunc f = (HPyFunc_ssizessizeargfunc)func; + _HPyFunc_args_SSIZESSIZEARGFUNC *a = (_HPyFunc_args_SSIZESSIZEARGFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0, a->arg1, a->arg2); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_SSIZEOBJARGPROC: { + HPyFunc_ssizeobjargproc f = (HPyFunc_ssizeobjargproc)func; + _HPyFunc_args_SSIZEOBJARGPROC *a = (_HPyFunc_args_SSIZEOBJARGPROC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg2 = _py2dh(dctx, a->arg2); + a->result = f(dctx, dh_arg0, a->arg1, dh_arg2); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg2); + return; + } + case HPyFunc_SSIZESSIZEOBJARGPROC: { + HPyFunc_ssizessizeobjargproc f = (HPyFunc_ssizessizeobjargproc)func; + _HPyFunc_args_SSIZESSIZEOBJARGPROC *a = (_HPyFunc_args_SSIZESSIZEOBJARGPROC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg3 = _py2dh(dctx, a->arg3); + a->result = f(dctx, dh_arg0, a->arg1, a->arg2, dh_arg3); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg3); + return; + } + case HPyFunc_OBJOBJARGPROC: { + HPyFunc_objobjargproc f = (HPyFunc_objobjargproc)func; + _HPyFunc_args_OBJOBJARGPROC *a = (_HPyFunc_args_OBJOBJARGPROC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_arg2 = _py2dh(dctx, a->arg2); + a->result = f(dctx, dh_arg0, dh_arg1, dh_arg2); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_arg2); + return; + } + case HPyFunc_FREEFUNC: { + HPyFunc_freefunc f = (HPyFunc_freefunc)func; + _HPyFunc_args_FREEFUNC *a = (_HPyFunc_args_FREEFUNC*)args; + f(dctx, a->arg0); + return; + } + case HPyFunc_GETATTRFUNC: { + HPyFunc_getattrfunc f = (HPyFunc_getattrfunc)func; + _HPyFunc_args_GETATTRFUNC *a = (_HPyFunc_args_GETATTRFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0, a->arg1); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_GETATTROFUNC: { + HPyFunc_getattrofunc f = (HPyFunc_getattrofunc)func; + _HPyFunc_args_GETATTROFUNC *a = (_HPyFunc_args_GETATTROFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_result = f(dctx, dh_arg0, dh_arg1); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_SETATTRFUNC: { + HPyFunc_setattrfunc f = (HPyFunc_setattrfunc)func; + _HPyFunc_args_SETATTRFUNC *a = (_HPyFunc_args_SETATTRFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg2 = _py2dh(dctx, a->arg2); + a->result = f(dctx, dh_arg0, a->arg1, dh_arg2); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg2); + return; + } + case HPyFunc_SETATTROFUNC: { + HPyFunc_setattrofunc f = (HPyFunc_setattrofunc)func; + _HPyFunc_args_SETATTROFUNC *a = (_HPyFunc_args_SETATTROFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_arg2 = _py2dh(dctx, a->arg2); + a->result = f(dctx, dh_arg0, dh_arg1, dh_arg2); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_arg2); + return; + } + case HPyFunc_REPRFUNC: { + HPyFunc_reprfunc f = (HPyFunc_reprfunc)func; + _HPyFunc_args_REPRFUNC *a = (_HPyFunc_args_REPRFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_HASHFUNC: { + HPyFunc_hashfunc f = (HPyFunc_hashfunc)func; + _HPyFunc_args_HASHFUNC *a = (_HPyFunc_args_HASHFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + a->result = f(dctx, dh_arg0); + DHPy_close(dctx, dh_arg0); + return; + } + case HPyFunc_RICHCMPFUNC: { + HPyFunc_richcmpfunc f = (HPyFunc_richcmpfunc)func; + _HPyFunc_args_RICHCMPFUNC *a = (_HPyFunc_args_RICHCMPFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_result = f(dctx, dh_arg0, dh_arg1, a->arg2); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_GETITERFUNC: { + HPyFunc_getiterfunc f = (HPyFunc_getiterfunc)func; + _HPyFunc_args_GETITERFUNC *a = (_HPyFunc_args_GETITERFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_ITERNEXTFUNC: { + HPyFunc_iternextfunc f = (HPyFunc_iternextfunc)func; + _HPyFunc_args_ITERNEXTFUNC *a = (_HPyFunc_args_ITERNEXTFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_DESCRGETFUNC: { + HPyFunc_descrgetfunc f = (HPyFunc_descrgetfunc)func; + _HPyFunc_args_DESCRGETFUNC *a = (_HPyFunc_args_DESCRGETFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_arg2 = _py2dh(dctx, a->arg2); + DHPy dh_result = f(dctx, dh_arg0, dh_arg1, dh_arg2); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_arg2); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_DESCRSETFUNC: { + HPyFunc_descrsetfunc f = (HPyFunc_descrsetfunc)func; + _HPyFunc_args_DESCRSETFUNC *a = (_HPyFunc_args_DESCRSETFUNC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + DHPy dh_arg2 = _py2dh(dctx, a->arg2); + a->result = f(dctx, dh_arg0, dh_arg1, dh_arg2); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + DHPy_close(dctx, dh_arg2); + return; + } + case HPyFunc_GETTER: { + HPyFunc_getter f = (HPyFunc_getter)func; + _HPyFunc_args_GETTER *a = (_HPyFunc_args_GETTER*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_result = f(dctx, dh_arg0, a->arg1); + a->result = _dh2py(dh_result); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_result); + return; + } + case HPyFunc_SETTER: { + HPyFunc_setter f = (HPyFunc_setter)func; + _HPyFunc_args_SETTER *a = (_HPyFunc_args_SETTER*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + a->result = f(dctx, dh_arg0, dh_arg1, a->arg2); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + return; + } + case HPyFunc_OBJOBJPROC: { + HPyFunc_objobjproc f = (HPyFunc_objobjproc)func; + _HPyFunc_args_OBJOBJPROC *a = (_HPyFunc_args_OBJOBJPROC*)args; + DHPy dh_arg0 = _py2dh(dctx, a->arg0); + DHPy dh_arg1 = _py2dh(dctx, a->arg1); + a->result = f(dctx, dh_arg0, dh_arg1); + DHPy_close(dctx, dh_arg0); + DHPy_close(dctx, dh_arg1); + return; + } diff --git a/hpy/debug/src/debug_ctx_cpython.c b/hpy/debug/src/debug_ctx_cpython.c index ea1b9a7d2..de902ad1b 100644 --- a/hpy/debug/src/debug_ctx_cpython.c +++ b/hpy/debug/src/debug_ctx_cpython.c @@ -114,6 +114,7 @@ void debug_ctx_CallRealFunctionFromTrampoline(HPyContext dctx, DHPy_close(dctx, dh_kw); return; } +#include "autogen_debug_ctx_call.i" default: abort(); // XXX } diff --git a/hpy/tools/autogen/__main__.py b/hpy/tools/autogen/__main__.py index de5a5dc56..8f983c625 100644 --- a/hpy/tools/autogen/__main__.py +++ b/hpy/tools/autogen/__main__.py @@ -16,7 +16,7 @@ from .hpyfunc import autogen_ctx_call_i from .hpyfunc import autogen_cpython_hpyfunc_trampoline_h from .hpyslot import autogen_hpyslot_h -from .debug import autogen_debug_ctx_init_h, autogen_debug_wrappers +from .debug import autogen_debug_ctx_init_h, autogen_debug_wrappers, autogen_debug_ctx_call_i from .pypy import autogen_pypy_txt def main(): @@ -40,6 +40,7 @@ def main(): autogen_hpyslot_h, autogen_debug_ctx_init_h, autogen_debug_wrappers, + autogen_debug_ctx_call_i, autogen_pypy_txt): cls(api).write(outdir) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index addb1bf17..48dd90f70 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -3,6 +3,7 @@ from pycparser import c_ast from .autogenfile import AutoGenFile from .parse import toC, find_typedecl +from .hpyfunc import SPECIAL_CASES class HPy_2_DHPy_Visitor(c_ast.NodeVisitor): "Visitor which renames all HPy types to DHPy" @@ -111,3 +112,52 @@ def get_params(): w(f' return {func.name}({params});') w('}') return '\n'.join(lines) + + +class autogen_debug_ctx_call_i(AutoGenFile): + PATH = 'hpy/debug/src/autogen_debug_ctx_call.i' + + def generate(self): + lines = [] + w = lines.append + for hpyfunc in self.api.hpyfunc_typedefs: + name = hpyfunc.base_name() + NAME = name.upper() + if NAME in SPECIAL_CASES: + continue + # + c_ret_type = toC(hpyfunc.return_type()) + args = ['dctx'] + dhpys = [] + for i, param in enumerate(hpyfunc.params()[1:]): + pname = param.name + if pname is None: + pname = 'arg%d' % i + if toC(param.type) == 'HPy': + dhpys.append(pname) + args.append(f'dh_{pname}') + else: + args.append(f'a->{pname}') + args = ', '.join(args) + # + w(f' case HPyFunc_{NAME}: {{') + w(f' HPyFunc_{name} f = (HPyFunc_{name})func;') + w(f' _HPyFunc_args_{NAME} *a = (_HPyFunc_args_{NAME}*)args;') + for pname in dhpys: + w(f' DHPy dh_{pname} = _py2dh(dctx, a->{pname});') + # + if c_ret_type == 'void': + w(f' f({args});') + elif c_ret_type == 'HPy': + w(f' DHPy dh_result = f({args});') + w(f' a->result = _dh2py(dh_result);') + dhpys.append('result') + else: + w(f' a->result = f({args});') + # + for pname in dhpys: + w(f' DHPy_close(dctx, dh_{pname});') + # + w(f' return;') + w(f' }}') + return '\n'.join(lines) From 0a660c34168a5fa468e4854f28520f3ecf1c1830 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 25 Jan 2021 19:21:44 +0100 Subject: [PATCH 50/65] implement debug_ctx_Type_FromSpec manually, since the autogenerated wrapper is not enough --- hpy/debug/src/autogen_debug_wrappers.c | 5 ----- hpy/debug/src/debug_ctx.c | 20 ++++++++++++++++++++ hpy/tools/autogen/debug.py | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index f70d78ee7..cdac74370 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -327,11 +327,6 @@ int debug_ctx_IsTrue(HPyContext dctx, DHPy h) return HPy_IsTrue(get_info(dctx)->uctx, DHPy_unwrap(h)); } -DHPy debug_ctx_Type_FromSpec(HPyContext dctx, HPyType_Spec *spec, HPyType_SpecParam *params) -{ - return DHPy_wrap(dctx, HPyType_FromSpec(get_info(dctx)->uctx, spec, params)); -} - DHPy debug_ctx_GetAttr(HPyContext dctx, DHPy obj, DHPy name) { return DHPy_wrap(dctx, HPy_GetAttr(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(name))); diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index b490bb6ba..c7cbeb59f 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -93,3 +93,23 @@ DHPy debug_ctx_Type_GenericNew(HPyContext dctx, DHPy dh_type, DHPy *dh_args, return DHPy_wrap(dctx, HPyType_GenericNew(get_info(dctx)->uctx, uh_type, uh_args, nargs, uh_kw)); } + +DHPy debug_ctx_Type_FromSpec(HPyContext dctx, HPyType_Spec *spec, HPyType_SpecParam *dparams) +{ + // dparams might contain some hidden DHPy: we need to manually unwrap them. + if (dparams != NULL) { + // count the params + HPy_ssize_t n = 1; + for (HPyType_SpecParam *p = dparams; p->kind != 0; p++) { + n++; + } + // NOTE: replace VLAs with alloca() once issue #157 is fixed + HPyType_SpecParam uparams[n]; + for (HPy_ssize_t i=0; iuctx, spec, uparams)); + } + return DHPy_wrap(dctx, HPyType_FromSpec(get_info(dctx)->uctx, spec, NULL)); +} diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index 48dd90f70..03a8ea02f 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -62,6 +62,7 @@ class autogen_debug_wrappers(AutoGenFile): 'HPy_Close', 'HPyTuple_FromArray', 'HPyType_GenericNew', + 'HPyType_FromSpec', ]) def generate(self): From 11974b828ccb3f1450be98961637357dfe7383e5 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 25 Jan 2021 20:29:06 +0100 Subject: [PATCH 51/65] add a note --- hpy/debug/src/debug_internal.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hpy/debug/src/debug_internal.h b/hpy/debug/src/debug_internal.h index f6b589945..9791c348e 100644 --- a/hpy/debug/src/debug_internal.h +++ b/hpy/debug/src/debug_internal.h @@ -61,6 +61,11 @@ static inline void UHPy_sanity_check(UHPy uh) { assert( (uh._i & 1) == 1 ); } +// NOTE: having a "generation" field is the easiest way to know when a handle +// was created, but we waste 8 bytes per handle. Since all handles of the same +// generation are stored sequentially in the open_handles list, a possible +// alternative implementation is to put special placeholders inside the list +// to mark the creation of a new generation typedef struct DebugHandle { UHPy uh; long generation; From 5b8d102ca58f9ad05a70e193cd9cd50998cf84b7 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Mon, 25 Jan 2021 23:44:18 +0100 Subject: [PATCH 52/65] introduce the applevel view of DebugHandle, and use it in _debug.get_open_handles() --- hpy/debug/src/_debugmod.c | 72 ++++++++++++++++++++++++++++++++++----- test/test_debug.py | 2 ++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index f7e0092c3..deba61e3c 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -7,8 +7,12 @@ #include "hpy.h" #include "debug_internal.h" +static UHPy new_DebugHandleObj(HPyContext uctx, UHPy u_DebugHandleType, + DebugHandle *handle); + + HPyDef_METH(new_generation, "new_generation", new_generation_impl, HPyFunc_NOARGS) -static HPy new_generation_impl(HPyContext uctx, HPy self) +static UHPy new_generation_impl(HPyContext uctx, UHPy self) { HPyContext dctx = hpy_debug_get_ctx(uctx); HPyDebugInfo *info = get_info(dctx); @@ -17,18 +21,18 @@ static HPy new_generation_impl(HPyContext uctx, HPy self) } -// TODO: eventually, we want to return Python-level views of DebugHandle, so -// that we can retrieve additional infos from applevel (e.g., the C backtrace -// at the moment of opening or so). For now, just return the Python objects -// pointed by the handles. HPyDef_METH(get_open_handles, "get_open_handles", get_open_handles_impl, HPyFunc_O, .doc= "Return a list containing all the open handles whose generation is >= " "of the given arg") -static HPy get_open_handles_impl(HPyContext uctx, UHPy u_self, UHPy u_gen) +static UHPy get_open_handles_impl(HPyContext uctx, UHPy u_self, UHPy u_gen) { HPyContext dctx = hpy_debug_get_ctx(uctx); HPyDebugInfo *info = get_info(dctx); + UHPy u_DebugHandleType = HPy_GetAttr_s(uctx, u_self, "DebugHandle"); + if (HPy_IsNull(u_DebugHandleType)) + return HPy_NULL; + long gen = HPyLong_AsLong(uctx, u_gen); if (HPyErr_Occurred(uctx)) return HPy_NULL; @@ -40,16 +44,60 @@ static HPy get_open_handles_impl(HPyContext uctx, UHPy u_self, UHPy u_gen) DebugHandle *dh = info->open_handles; while(dh != NULL) { if (dh->generation >= gen) { - if (HPyList_Append(uctx, u_result, dh->uh) == -1) { + UHPy u_item = new_DebugHandleObj(uctx, u_DebugHandleType, dh); + if (HPy_IsNull(u_item)) + return HPy_NULL; + if (HPyList_Append(uctx, u_result, u_item) == -1) { + HPy_Close(uctx, u_item); HPy_Close(uctx, u_result); return HPy_NULL; } + HPy_Close(uctx, u_item); } dh = dh->next; } return u_result; } +/* ~~~~~~ DebugHandleType and DebugHandleObject ~~~~~~~~ */ + +typedef struct { + HPyObject_HEAD + DebugHandle *handle; +} DebugHandleObject; + +HPyDef_GET(DebugHandle_obj, "obj", DebugHandle_obj_get) +static UHPy DebugHandle_obj_get(HPyContext uctx, UHPy self, void *closure) +{ + DebugHandleObject *dh = HPy_CAST(uctx, DebugHandleObject, self); + return HPy_Dup(uctx, dh->handle->uh); +} + +static HPyDef *DebugHandleType_defs[] = { + &DebugHandle_obj, + NULL +}; + +static HPyType_Spec DebugHandleType_spec = { + .name = "hpy.debug._debug.DebugHandle", + .basicsize = sizeof(DebugHandleObject), + .flags = HPy_TPFLAGS_DEFAULT, + .defines = DebugHandleType_defs, +}; + + +static UHPy new_DebugHandleObj(HPyContext uctx, UHPy u_DebugHandleType, + DebugHandle *handle) +{ + DebugHandleObject *dhobj; + UHPy u_result = HPy_New(uctx, u_DebugHandleType, &dhobj); + dhobj->handle = handle; + return u_result; +} + + +/* ~~~~~~ definition of the module hpy.debug._debug ~~~~~~~ */ + static HPyDef *module_defines[] = { &new_generation, &get_open_handles, @@ -66,10 +114,16 @@ static HPyModuleDef moduledef = { HPy_MODINIT(_debug) -static HPy init__debug_impl(HPyContext uctx) +static UHPy init__debug_impl(HPyContext uctx) { - HPy m = HPyModule_Create(uctx, &moduledef); + 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; } diff --git a/test/test_debug.py b/test/test_debug.py index 9eaa8624c..874a8d550 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -29,5 +29,7 @@ def test_get_open_handles(self): mod.leak('a younger leak') leaks1 = _debug.get_open_handles(gen1) leaks2 = _debug.get_open_handles(gen2) + leaks1 = [dh.obj for dh in leaks1] + leaks2 = [dh.obj for dh in leaks2] assert leaks1 == ['a younger leak', 'world', 'hello'] assert leaks2 == ['a younger leak'] From abe4cc4ce402dc22ac3d9faf6e65e6e2cbcea230 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 27 Jan 2021 00:57:42 +0100 Subject: [PATCH 53/65] check the result of these two mallocs --- hpy/debug/src/debug_ctx.c | 13 ++++++++++--- hpy/debug/src/debug_handles.c | 6 ++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index c7cbeb59f..935f4bc9b 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -13,16 +13,21 @@ static struct _HPyContext_s g_debug_ctx = { // same. If/when we migrate to a system in which we can have multiple // independent contexts, this function should ensure to create a different // debug wrapper for each of them. -static void debug_ctx_init(HPyContext dctx, HPyContext uctx) +static int debug_ctx_init(HPyContext dctx, HPyContext uctx) { if (dctx->_private != NULL) { // already initialized assert(get_info(dctx)->uctx == uctx); // sanity check - return; + return 0; } // initialize debug_info // XXX: currently we never free this malloc HPyDebugInfo *info = malloc(sizeof(HPyDebugInfo)); + if (info == NULL) { + HPyErr_SetString(uctx, uctx->h_MemoryError, + "Cannot allocate memory for HPyDebugInfo"); + return -1; + } info->magic_number = HPY_DEBUG_MAGIC; info->uctx = uctx; info->current_generation = 0; @@ -31,12 +36,14 @@ static void debug_ctx_init(HPyContext dctx, HPyContext uctx) dctx->_private = info; debug_ctx_init_fields(dctx, uctx); + return 0; } HPyContext hpy_debug_get_ctx(HPyContext uctx) { HPyContext dctx = &g_debug_ctx; - debug_ctx_init(dctx, uctx); + if (debug_ctx_init(dctx, uctx) < 0) + return NULL; return dctx; } diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index 832ad3d0d..c6ea908c6 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -7,6 +7,12 @@ DHPy DHPy_wrap(HPyContext dctx, UHPy uh) return HPy_NULL; HPyDebugInfo *info = get_info(dctx); DebugHandle *handle = malloc(sizeof(DebugHandle)); + if (handle == NULL) { + HPyContext uctx = info->uctx; + HPyErr_SetString(uctx, uctx->h_MemoryError, + "Cannot allocate memory for DebugHandle"); + return HPy_NULL; + } handle->uh = uh; handle->generation = info->current_generation; handle->prev = NULL; From b1df2ae0151b40b7f6d2705030dee235d274f98c Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 27 Jan 2021 10:37:44 +0100 Subject: [PATCH 54/65] use HPyErr_NoMemory and check whether get_context() fails --- hpy/debug/src/debug_ctx.c | 3 +-- hpy/debug/src/debug_handles.c | 5 +---- hpy/universal/src/hpymodule.c | 2 ++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/hpy/debug/src/debug_ctx.c b/hpy/debug/src/debug_ctx.c index 935f4bc9b..aab004c64 100644 --- a/hpy/debug/src/debug_ctx.c +++ b/hpy/debug/src/debug_ctx.c @@ -24,8 +24,7 @@ static int debug_ctx_init(HPyContext dctx, HPyContext uctx) // XXX: currently we never free this malloc HPyDebugInfo *info = malloc(sizeof(HPyDebugInfo)); if (info == NULL) { - HPyErr_SetString(uctx, uctx->h_MemoryError, - "Cannot allocate memory for HPyDebugInfo"); + HPyErr_NoMemory(uctx); return -1; } info->magic_number = HPY_DEBUG_MAGIC; diff --git a/hpy/debug/src/debug_handles.c b/hpy/debug/src/debug_handles.c index c6ea908c6..c3bcf8cdf 100644 --- a/hpy/debug/src/debug_handles.c +++ b/hpy/debug/src/debug_handles.c @@ -8,10 +8,7 @@ DHPy DHPy_wrap(HPyContext dctx, UHPy uh) HPyDebugInfo *info = get_info(dctx); DebugHandle *handle = malloc(sizeof(DebugHandle)); if (handle == NULL) { - HPyContext uctx = info->uctx; - HPyErr_SetString(uctx, uctx->h_MemoryError, - "Cannot allocate memory for DebugHandle"); - return HPy_NULL; + return HPyErr_NoMemory(info->uctx); } handle->uh = uh; handle->generation = info->current_generation; diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 6a055b97b..71c0df8db 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -116,6 +116,8 @@ static PyObject *do_load(PyObject *name_unicode, PyObject *path, int debug) } HPyContext ctx = get_context(debug); + if (ctx == NULL) + goto error; HPy h_mod = ((InitFuncPtr)initfn)(ctx); if (HPy_IsNull(h_mod)) goto error; From cd8cd6e9b0a8b05384c2e3acbfeab75bb3e84955 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 27 Jan 2021 11:14:17 +0100 Subject: [PATCH 55/65] Tell infer to ignore this file, as it reports a spurious memory leak. This is what it reports: hpy/debug/src/debug_ctx.c:37: error: MEMORY_LEAK memory dynamically allocated by call to `malloc()` at line 25, column 26 is not reachable after line 37, column 5. 35. dctx->_private = info; 36. 37. > debug_ctx_init_fields(dctx, uctx); 38. return 0; 39. } However, it is clear that "info" is stored inside dctx->_private and so still reachable. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bf1b9b0c9..23ae60ff5 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ cppcheck: cppcheck-build-dir infer: python3 setup.py build_ext -if -U NDEBUG | compiledb - @infer --fail-on-issue --compilation-database compile_commands.json + @infer --fail-on-issue --compilation-database compile_commands.json --report-blacklist-path-regex "hpy/debug/src/debug_ctx.c" valgrind: PYTHONMALLOC=malloc valgrind --suppressions=hpy/tools/valgrind/python.supp --suppressions=hpy/tools/valgrind/hpy.supp --leak-check=full --show-leak-kinds=definite,indirect --log-file=/tmp/valgrind-output python -m pytest --valgrind --valgrind-log=/tmp/valgrind-output test/ From 77fdaf8ee40f99f815ee2f161509c0ce92e8db2a Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 27 Jan 2021 12:03:52 +0100 Subject: [PATCH 56/65] introduce DebugHandle.id --- hpy/debug/src/_debugmod.c | 12 +++++++++++- test/test_debug.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index deba61e3c..e3937242d 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -66,15 +66,25 @@ typedef struct { DebugHandle *handle; } DebugHandleObject; -HPyDef_GET(DebugHandle_obj, "obj", DebugHandle_obj_get) +HPyDef_GET(DebugHandle_obj, "obj", DebugHandle_obj_get, + .doc="The object which the handle points to") static UHPy DebugHandle_obj_get(HPyContext uctx, UHPy self, void *closure) { DebugHandleObject *dh = HPy_CAST(uctx, DebugHandleObject, self); return HPy_Dup(uctx, dh->handle->uh); } +HPyDef_GET(DebugHandle_id, "id", DebugHandle_id_get, + .doc="A numeric identifier representing the underlying universal handle") +static UHPy DebugHandle_id_get(HPyContext uctx, UHPy self, void *closure) +{ + DebugHandleObject *dh = HPy_CAST(uctx, DebugHandleObject, self); + return HPyLong_FromSsize_t(uctx, dh->handle->uh._i); +} + static HPyDef *DebugHandleType_defs[] = { &DebugHandle_obj, + &DebugHandle_id, NULL }; diff --git a/test/test_debug.py b/test/test_debug.py index 874a8d550..e0f713427 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -33,3 +33,31 @@ def test_get_open_handles(self): leaks2 = [dh.obj for dh in leaks2] assert leaks1 == ['a younger leak', 'world', 'hello'] assert leaks2 == ['a younger leak'] + + def test_DebugHandle_id(self): + from hpy.universal import _debug + mod = self.make_module(""" + HPyDef_METH(leak, "leak", leak_impl, HPyFunc_O) + static HPy leak_impl(HPyContext ctx, HPy self, HPy arg) + { + HPy_Dup(ctx, arg); // leak! + return HPy_Dup(ctx, ctx->h_None); + } + @EXPORT(leak) + @INIT + """) + gen = _debug.new_generation() + mod.leak('a') + mod.leak('b') + b1, a1 = _debug.get_open_handles(gen) + b2, a2 = _debug.get_open_handles(gen) + assert a1.obj == a2.obj == 'a' + assert b1.obj == b2.obj == 'b' + # + assert a1 is not a2 + assert a1.id == a2.id + # + assert b1 is not b2 + assert b1.id == b2.id + # + assert a1.id != b1.id From 64f2e3607e49e5351e89719e3e9a3c8240dfe411 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Wed, 27 Jan 2021 15:00:47 +0100 Subject: [PATCH 57/65] fix autogen after the merge --- hpy/tools/autogen/debug.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hpy/tools/autogen/debug.py b/hpy/tools/autogen/debug.py index 03a8ea02f..3eb1bc096 100644 --- a/hpy/tools/autogen/debug.py +++ b/hpy/tools/autogen/debug.py @@ -3,7 +3,7 @@ from pycparser import c_ast from .autogenfile import AutoGenFile from .parse import toC, find_typedecl -from .hpyfunc import SPECIAL_CASES +from .hpyfunc import NO_CALL class HPy_2_DHPy_Visitor(c_ast.NodeVisitor): "Visitor which renames all HPy types to DHPy" @@ -124,7 +124,7 @@ def generate(self): for hpyfunc in self.api.hpyfunc_typedefs: name = hpyfunc.base_name() NAME = name.upper() - if NAME in SPECIAL_CASES: + if NAME in NO_CALL: continue # c_ret_type = toC(hpyfunc.return_type()) From 239885a36f25697333d3caa3d1fb6a630d0215c2 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 28 Jan 2021 14:31:07 +0100 Subject: [PATCH 58/65] explain what is a DebugHandleObject --- hpy/debug/src/_debugmod.c | 24 ++++++++++++++++++++++-- test/test_debug.py | 5 ++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index e3937242d..0bd17fb23 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -59,7 +59,27 @@ static UHPy get_open_handles_impl(HPyContext uctx, UHPy u_self, UHPy u_gen) return u_result; } -/* ~~~~~~ DebugHandleType and DebugHandleObject ~~~~~~~~ */ +/* ~~~~~~ DebugHandleType and DebugHandleObject ~~~~~~~~ + + This is the applevel view of a DebugHandle/DHPy. + + Note that there are two different ways to expose DebugHandle to applevel: + + 1. make DebugHandle itself a Python object: this is simple but means that + you have to pay the PyObject_HEAD overhead (16 bytes) for all of them + + 2. make DebugHandle a plain C struct, and expose them through a + Python-level wrapper. + + We choose to implement solution 2 because we expect to have many + DebugHandle around, but to expose only few of them to applevel, when you + call get_open_handles. This way, we save 16 bytes per DebugHandle. + + This means that you can have different DebugHandleObjects wrapping the same + DebugHandle. To make it easier to compare them, they expose the .id + attribute, which is the address of the wrapped DebugHandle. Also, + DebugHandleObjects compare equal if their .id is equal. +*/ typedef struct { HPyObject_HEAD @@ -79,7 +99,7 @@ HPyDef_GET(DebugHandle_id, "id", DebugHandle_id_get, static UHPy DebugHandle_id_get(HPyContext uctx, UHPy self, void *closure) { DebugHandleObject *dh = HPy_CAST(uctx, DebugHandleObject, self); - return HPyLong_FromSsize_t(uctx, dh->handle->uh._i); + return HPyLong_FromSsize_t(uctx, (HPy_ssize_t)dh->handle); } static HPyDef *DebugHandleType_defs[] = { diff --git a/test/test_debug.py b/test/test_debug.py index e0f713427..7ebee0351 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -55,9 +55,8 @@ def test_DebugHandle_id(self): assert b1.obj == b2.obj == 'b' # assert a1 is not a2 - assert a1.id == a2.id - # assert b1 is not b2 - assert b1.id == b2.id # + assert a1.id == a2.id + assert b1.id == b2.id assert a1.id != b1.id From c336f0264827559f6c1827fd42791a170149682e Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 28 Jan 2021 14:48:32 +0100 Subject: [PATCH 59/65] make autogen after the merge of the branch --- hpy/debug/src/autogen_debug_ctx_init.h | 6 ++++++ hpy/debug/src/autogen_debug_wrappers.c | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/hpy/debug/src/autogen_debug_ctx_init.h b/hpy/debug/src/autogen_debug_ctx_init.h index 85b81017b..aa706affd 100644 --- a/hpy/debug/src/autogen_debug_ctx_init.h +++ b/hpy/debug/src/autogen_debug_ctx_init.h @@ -29,6 +29,7 @@ size_t debug_ctx_Long_AsSize_t(HPyContext dctx, DHPy h); HPy_ssize_t debug_ctx_Long_AsSsize_t(HPyContext dctx, DHPy h); DHPy debug_ctx_Float_FromDouble(HPyContext dctx, double v); double debug_ctx_Float_AsDouble(HPyContext dctx, DHPy h); +DHPy debug_ctx_Bool_FromLong(HPyContext dctx, long v); HPy_ssize_t debug_ctx_Length(HPyContext dctx, DHPy h); int debug_ctx_Number_Check(HPyContext dctx, DHPy h); DHPy debug_ctx_Add(HPyContext dctx, DHPy h1, DHPy h2); @@ -88,6 +89,8 @@ DHPy debug_ctx_GetItem_s(HPyContext dctx, DHPy obj, const char *key); int debug_ctx_SetItem(HPyContext dctx, DHPy obj, DHPy key, DHPy value); int debug_ctx_SetItem_i(HPyContext dctx, DHPy obj, HPy_ssize_t idx, DHPy value); int debug_ctx_SetItem_s(HPyContext dctx, DHPy obj, const char *key, DHPy value); +DHPy debug_ctx_Type(HPyContext dctx, DHPy obj); +int debug_ctx_TypeCheck(HPyContext dctx, DHPy obj, DHPy type); void *debug_ctx_Cast(HPyContext dctx, DHPy h); DHPy debug_ctx_New(HPyContext dctx, DHPy h_type, void **data); DHPy debug_ctx_Repr(HPyContext dctx, DHPy obj); @@ -227,6 +230,7 @@ static inline void debug_ctx_init_fields(HPyContext dctx, HPyContext uctx) dctx->ctx_Long_AsSsize_t = &debug_ctx_Long_AsSsize_t; dctx->ctx_Float_FromDouble = &debug_ctx_Float_FromDouble; dctx->ctx_Float_AsDouble = &debug_ctx_Float_AsDouble; + dctx->ctx_Bool_FromLong = &debug_ctx_Bool_FromLong; dctx->ctx_Length = &debug_ctx_Length; dctx->ctx_Number_Check = &debug_ctx_Number_Check; dctx->ctx_Add = &debug_ctx_Add; @@ -286,6 +290,8 @@ static inline void debug_ctx_init_fields(HPyContext dctx, HPyContext uctx) dctx->ctx_SetItem = &debug_ctx_SetItem; dctx->ctx_SetItem_i = &debug_ctx_SetItem_i; dctx->ctx_SetItem_s = &debug_ctx_SetItem_s; + dctx->ctx_Type = &debug_ctx_Type; + dctx->ctx_TypeCheck = &debug_ctx_TypeCheck; dctx->ctx_Cast = &debug_ctx_Cast; dctx->ctx_New = &debug_ctx_New; dctx->ctx_Repr = &debug_ctx_Repr; diff --git a/hpy/debug/src/autogen_debug_wrappers.c b/hpy/debug/src/autogen_debug_wrappers.c index cdac74370..c9f5937fc 100644 --- a/hpy/debug/src/autogen_debug_wrappers.c +++ b/hpy/debug/src/autogen_debug_wrappers.c @@ -102,6 +102,11 @@ double debug_ctx_Float_AsDouble(HPyContext dctx, DHPy h) return HPyFloat_AsDouble(get_info(dctx)->uctx, DHPy_unwrap(h)); } +DHPy debug_ctx_Bool_FromLong(HPyContext dctx, long v) +{ + return DHPy_wrap(dctx, HPyBool_FromLong(get_info(dctx)->uctx, v)); +} + HPy_ssize_t debug_ctx_Length(HPyContext dctx, DHPy h) { return HPy_Length(get_info(dctx)->uctx, DHPy_unwrap(h)); @@ -387,6 +392,16 @@ int debug_ctx_SetItem_s(HPyContext dctx, DHPy obj, const char *key, DHPy value) return HPy_SetItem_s(get_info(dctx)->uctx, DHPy_unwrap(obj), key, DHPy_unwrap(value)); } +DHPy debug_ctx_Type(HPyContext dctx, DHPy obj) +{ + return DHPy_wrap(dctx, HPy_Type(get_info(dctx)->uctx, DHPy_unwrap(obj))); +} + +int debug_ctx_TypeCheck(HPyContext dctx, DHPy obj, DHPy type) +{ + return HPy_TypeCheck(get_info(dctx)->uctx, DHPy_unwrap(obj), DHPy_unwrap(type)); +} + void *debug_ctx_Cast(HPyContext dctx, DHPy h) { return _HPy_Cast(get_info(dctx)->uctx, DHPy_unwrap(h)); From cb13b9e127cd7d9251d421f6c28489d1d5a93fba Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 28 Jan 2021 14:55:52 +0100 Subject: [PATCH 60/65] add ctx->h_NotImplemented and ctx->h_Ellipsis --- hpy/debug/src/autogen_debug_ctx_init.h | 2 ++ hpy/devel/include/cpython/hpy.h | 4 ++++ hpy/devel/include/universal/autogen_ctx.h | 2 ++ hpy/tools/autogen/public_api.h | 2 ++ hpy/universal/src/hpymodule.c | 2 ++ test/test_00_basic.py | 4 +++- 6 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hpy/debug/src/autogen_debug_ctx_init.h b/hpy/debug/src/autogen_debug_ctx_init.h index aa706affd..2506e26a4 100644 --- a/hpy/debug/src/autogen_debug_ctx_init.h +++ b/hpy/debug/src/autogen_debug_ctx_init.h @@ -141,6 +141,8 @@ static inline void debug_ctx_init_fields(HPyContext dctx, HPyContext uctx) dctx->h_None = DHPy_wrap(dctx, uctx->h_None); dctx->h_True = DHPy_wrap(dctx, uctx->h_True); dctx->h_False = DHPy_wrap(dctx, uctx->h_False); + dctx->h_NotImplemented = DHPy_wrap(dctx, uctx->h_NotImplemented); + dctx->h_Ellipsis = DHPy_wrap(dctx, uctx->h_Ellipsis); dctx->h_BaseException = DHPy_wrap(dctx, uctx->h_BaseException); dctx->h_Exception = DHPy_wrap(dctx, uctx->h_Exception); dctx->h_StopAsyncIteration = DHPy_wrap(dctx, uctx->h_StopAsyncIteration); diff --git a/hpy/devel/include/cpython/hpy.h b/hpy/devel/include/cpython/hpy.h index fa4857216..c99403944 100644 --- a/hpy/devel/include/cpython/hpy.h +++ b/hpy/devel/include/cpython/hpy.h @@ -50,6 +50,8 @@ typedef struct _HPyContext_s { HPy h_None; HPy h_True; HPy h_False; + HPy h_NotImplemented; + HPy h_Ellipsis; /* Exceptions */ HPy h_BaseException; HPy h_Exception; @@ -147,6 +149,8 @@ _HPyGetContext(void) { ctx->h_None = _py2h(Py_None); ctx->h_True = _py2h(Py_True); ctx->h_False = _py2h(Py_False); + ctx->h_NotImplemented = _py2h(Py_NotImplemented); + ctx->h_Ellipsis = _py2h(Py_Ellipsis); /* Exceptions */ ctx->h_BaseException = _py2h(PyExc_BaseException); ctx->h_Exception = _py2h(PyExc_Exception); diff --git a/hpy/devel/include/universal/autogen_ctx.h b/hpy/devel/include/universal/autogen_ctx.h index 03fb41267..8adf4e5e4 100644 --- a/hpy/devel/include/universal/autogen_ctx.h +++ b/hpy/devel/include/universal/autogen_ctx.h @@ -17,6 +17,8 @@ struct _HPyContext_s { HPy h_None; HPy h_True; HPy h_False; + HPy h_NotImplemented; + HPy h_Ellipsis; HPy h_BaseException; HPy h_Exception; HPy h_StopAsyncIteration; diff --git a/hpy/tools/autogen/public_api.h b/hpy/tools/autogen/public_api.h index 3acbb1f26..40d8da002 100644 --- a/hpy/tools/autogen/public_api.h +++ b/hpy/tools/autogen/public_api.h @@ -23,6 +23,8 @@ typedef int HPy_RichCmpOp; HPy h_None; HPy h_True; HPy h_False; +HPy h_NotImplemented; +HPy h_Ellipsis; /* Exceptions */ HPy h_BaseException; diff --git a/hpy/universal/src/hpymodule.c b/hpy/universal/src/hpymodule.c index 71c0df8db..76ce96d18 100644 --- a/hpy/universal/src/hpymodule.c +++ b/hpy/universal/src/hpymodule.c @@ -201,6 +201,8 @@ static void init_universal_ctx(HPyContext ctx) ctx->h_None = _py2h(Py_None); ctx->h_True = _py2h(Py_True); ctx->h_False = _py2h(Py_False); + ctx->h_NotImplemented = _py2h(Py_NotImplemented); + ctx->h_Ellipsis = _py2h(Py_Ellipsis); /* Exceptions */ ctx->h_BaseException = _py2h(PyExc_BaseException); ctx->h_Exception = _py2h(PyExc_Exception); diff --git a/test/test_00_basic.py b/test/test_00_basic.py index 6ba9279da..c8f97b5f2 100644 --- a/test/test_00_basic.py +++ b/test/test_00_basic.py @@ -200,6 +200,8 @@ def test_builtin_handles(self): case 11: h = ctx->h_UnicodeType; break; case 12: h = ctx->h_TupleType; break; case 13: h = ctx->h_ListType; break; + case 14: h = ctx->h_NotImplemented; break; + case 15: h = ctx->h_Ellipsis; break; default: HPyErr_SetString(ctx, ctx->h_ValueError, "invalid choice"); return HPy_NULL; @@ -211,7 +213,7 @@ def test_builtin_handles(self): """) builtin_objs = ( '', None, False, True, ValueError, TypeError, IndexError, - SystemError, object, type, int, str, tuple, list, + SystemError, object, type, int, str, tuple, list, NotImplemented, ..., ) for i, obj in enumerate(builtin_objs): if i == 0: From c6174bedb0952e731506a7d1f57e9c55353e836b Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Thu, 28 Jan 2021 15:07:26 +0100 Subject: [PATCH 61/65] implement comparisons between DebugHandleObjects --- hpy/debug/src/_debugmod.c | 21 +++++++++++++++++++++ test/test_debug.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index 0bd17fb23..64fffef20 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -102,9 +102,30 @@ static UHPy DebugHandle_id_get(HPyContext uctx, UHPy self, void *closure) return HPyLong_FromSsize_t(uctx, (HPy_ssize_t)dh->handle); } +HPyDef_SLOT(DebugHandle_cmp, DebugHandle_cmp_impl, HPy_tp_richcompare) +static UHPy DebugHandle_cmp_impl(HPyContext uctx, UHPy self, UHPy o, HPy_RichCmpOp op) +{ + UHPy T = HPy_Type(uctx, self); + if (!HPy_TypeCheck(uctx, o, T)) + return HPy_Dup(uctx, uctx->h_NotImplemented); + DebugHandleObject *dh_self = HPy_CAST(uctx, DebugHandleObject, self); + DebugHandleObject *dh_o = HPy_CAST(uctx, DebugHandleObject, o); + + switch(op) { + case HPy_EQ: + return HPyBool_FromLong(uctx, dh_self->handle == dh_o->handle); + case HPy_NE: + return HPyBool_FromLong(uctx, dh_self->handle != dh_o->handle); + default: + return HPy_Dup(uctx, uctx->h_NotImplemented); + } +} + + static HPyDef *DebugHandleType_defs[] = { &DebugHandle_obj, &DebugHandle_id, + &DebugHandle_cmp, NULL }; diff --git a/test/test_debug.py b/test/test_debug.py index 7ebee0351..0bed508f5 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -60,3 +60,42 @@ def test_DebugHandle_id(self): assert a1.id == a2.id assert b1.id == b2.id assert a1.id != b1.id + + def test_DebugHandle_compare(self): + import pytest + from hpy.universal import _debug + mod = self.make_module(""" + HPyDef_METH(leak, "leak", leak_impl, HPyFunc_O) + static HPy leak_impl(HPyContext ctx, HPy self, HPy arg) + { + HPy_Dup(ctx, arg); // leak! + return HPy_Dup(ctx, ctx->h_None); + } + @EXPORT(leak) + @INIT + """) + gen = _debug.new_generation() + mod.leak('a') + mod.leak('a') + a2, a1 = _debug.get_open_handles(gen) + assert a1 != a2 # same underlying object, but different DebugHandle + # + a2_new, a1_new = _debug.get_open_handles(gen) + assert a1 is not a1_new # different objects... + assert a2 is not a2_new + assert a1 == a1_new # ...but same DebugHandle + assert a2 == a2_new + # + with pytest.raises(TypeError): + a1 < a2 + with pytest.raises(TypeError): + a1 <= a2 + with pytest.raises(TypeError): + a1 > a2 + with pytest.raises(TypeError): + a1 >= a2 + + assert not a1 == 'hello' + assert a1 != 'hello' + with pytest.raises(TypeError): + a1 < 'hello' From bbd00ac4a99dcf950bb8672c9623243012e498c0 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 29 Jan 2021 16:03:18 +0100 Subject: [PATCH 62/65] implement DebugHandle.repr --- hpy/debug/src/_debugmod.c | 32 ++++++++++++++++++++++++++++++++ test/test_debug.py | 18 ++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/hpy/debug/src/_debugmod.c b/hpy/debug/src/_debugmod.c index 64fffef20..4f59d734b 100644 --- a/hpy/debug/src/_debugmod.c +++ b/hpy/debug/src/_debugmod.c @@ -121,11 +121,43 @@ static UHPy DebugHandle_cmp_impl(HPyContext uctx, UHPy self, UHPy o, HPy_RichCmp } } +HPyDef_SLOT(DebugHandle_repr, DebugHandle_repr_impl, HPy_tp_repr) +static UHPy DebugHandle_repr_impl(HPyContext uctx, UHPy self) +{ + DebugHandleObject *dh = HPy_CAST(uctx, DebugHandleObject, self); + UHPy uh_fmt = HPy_NULL; + UHPy uh_id = HPy_NULL; + UHPy uh_args = HPy_NULL; + UHPy uh_result = HPy_NULL; + + uh_fmt = HPyUnicode_FromString(uctx, ""); + if (HPy_IsNull(uh_fmt)) + goto exit; + + uh_id = HPyLong_FromSsize_t(uctx, (HPy_ssize_t)dh->handle); + if (HPy_IsNull(uh_id)) + goto exit; + + uh_args = HPyTuple_FromArray(uctx, (UHPy[]){uh_id, dh->handle->uh}, 2); + if (HPy_IsNull(uh_args)) + goto exit; + + uh_result = HPy_Remainder(uctx, uh_fmt, uh_args); + + exit: + HPy_Close(uctx, uh_fmt); + HPy_Close(uctx, uh_id); + HPy_Close(uctx, uh_args); + return uh_result; +} + + static HPyDef *DebugHandleType_defs[] = { &DebugHandle_obj, &DebugHandle_id, &DebugHandle_cmp, + &DebugHandle_repr, NULL }; diff --git a/test/test_debug.py b/test/test_debug.py index 0bed508f5..c74888c48 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -99,3 +99,21 @@ def test_DebugHandle_compare(self): assert a1 != 'hello' with pytest.raises(TypeError): a1 < 'hello' + + def test_DebugHandle_repr(self): + import pytest + from hpy.universal import _debug + mod = self.make_module(""" + HPyDef_METH(leak, "leak", leak_impl, HPyFunc_O) + static HPy leak_impl(HPyContext ctx, HPy self, HPy arg) + { + HPy_Dup(ctx, arg); // leak! + return HPy_Dup(ctx, ctx->h_None); + } + @EXPORT(leak) + @INIT + """) + gen = _debug.new_generation() + mod.leak('hello') + h_hello, = _debug.get_open_handles(gen) + assert repr(h_hello) == "" % h_hello.id From ebf7c77e5affd336a8f3bed708676f3d5485d03d Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 29 Jan 2021 16:37:05 +0100 Subject: [PATCH 63/65] implement a simple LeakDetector on top of the low-level debug-mode primitives --- hpy/debug/__init__.py | 1 + hpy/debug/leakdetector.py | 37 +++++++++++++++++++++++++++++++++++++ test/test_debug.py | 21 +++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 hpy/debug/__init__.py create mode 100644 hpy/debug/leakdetector.py diff --git a/hpy/debug/__init__.py b/hpy/debug/__init__.py new file mode 100644 index 000000000..ae5bff69e --- /dev/null +++ b/hpy/debug/__init__.py @@ -0,0 +1 @@ +from .leakdetector import HPyError, HPyLeak, LeakDetector diff --git a/hpy/debug/leakdetector.py b/hpy/debug/leakdetector.py new file mode 100644 index 000000000..98e9af454 --- /dev/null +++ b/hpy/debug/leakdetector.py @@ -0,0 +1,37 @@ +from hpy.universal import _debug + +class HPyError(Exception): + pass + +class HPyLeak(HPyError): + def __init__(self, leaks): + super().__init__() + self.leaks = leaks + + def __str__(self): + lines = [] + lines.append('%s handles have not been closed properly:' % len(self.leaks)) + for dh in self.leaks: + lines.append(' %r' % dh) + return '\n'.join(lines) + + +class LeakDetector: + + def __init__(self): + self.generation = None + + def start(self): + if self.generation is not None: + raise ValueError('LeakDetector already started') + self.generation = _debug.new_generation() + + def stop(self): + if self.generation is None: + raise ValueError('LeakDetector not started yet') + leaks = _debug.get_open_handles(self.generation) + if leaks: + raise HPyLeak(leaks) + + + diff --git a/test/test_debug.py b/test/test_debug.py index c74888c48..3dd00a744 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -117,3 +117,24 @@ def test_DebugHandle_repr(self): mod.leak('hello') h_hello, = _debug.get_open_handles(gen) assert repr(h_hello) == "" % h_hello.id + + def test_LeakDetector(self): + import pytest + from hpy.debug import LeakDetector, HPyLeak + mod = self.make_module(""" + HPyDef_METH(leak, "leak", leak_impl, HPyFunc_O) + static HPy leak_impl(HPyContext ctx, HPy self, HPy arg) + { + HPy_Dup(ctx, arg); // leak! + return HPy_Dup(ctx, ctx->h_None); + } + @EXPORT(leak) + @INIT + """) + ld = LeakDetector() + ld.start() + mod.leak('hello') + mod.leak('world') + with pytest.raises(HPyLeak) as exc: + ld.stop() + assert str(exc.value).startswith('2 handles have not been closed properly:') From d18c016078786e63a2f7c2beec1229bdefce413d Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 29 Jan 2021 16:39:58 +0100 Subject: [PATCH 64/65] make it possible to use LeakDetector as a context manager --- hpy/debug/leakdetector.py | 6 +++++- test/test_debug.py | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hpy/debug/leakdetector.py b/hpy/debug/leakdetector.py index 98e9af454..38f521075 100644 --- a/hpy/debug/leakdetector.py +++ b/hpy/debug/leakdetector.py @@ -33,5 +33,9 @@ def stop(self): if leaks: raise HPyLeak(leaks) + def __enter__(self): + self.start() + return self - + def __exit__(self, etype, evalue, tb): + self.stop() diff --git a/test/test_debug.py b/test/test_debug.py index 3dd00a744..630077034 100644 --- a/test/test_debug.py +++ b/test/test_debug.py @@ -138,3 +138,16 @@ def test_LeakDetector(self): with pytest.raises(HPyLeak) as exc: ld.stop() assert str(exc.value).startswith('2 handles have not been closed properly:') + # + with pytest.raises(HPyLeak) as exc: + with LeakDetector(): + mod.leak('foo') + mod.leak('bar') + mod.leak('baz') + msg = str(exc.value) + assert msg.startswith('3 handles have not been closed properly:') + assert 'foo' in msg + assert 'bar' in msg + assert 'baz' in msg + assert 'hello' not in msg + assert 'world' not in msg From beb2d07b3866a824f2a74f6df399669592be4f56 Mon Sep 17 00:00:00 2001 From: Antonio Cuni Date: Fri, 29 Jan 2021 18:09:55 +0100 Subject: [PATCH 65/65] avoid the ... syntax, because this file needs to be importable also by py27 (because of pypy applevel tests) --- test/test_00_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_00_basic.py b/test/test_00_basic.py index c8f97b5f2..786673421 100644 --- a/test/test_00_basic.py +++ b/test/test_00_basic.py @@ -213,7 +213,7 @@ def test_builtin_handles(self): """) builtin_objs = ( '', None, False, True, ValueError, TypeError, IndexError, - SystemError, object, type, int, str, tuple, list, NotImplemented, ..., + SystemError, object, type, int, str, tuple, list, NotImplemented, Ellipsis, ) for i, obj in enumerate(builtin_objs): if i == 0: