From 4cd1ce87e4d0108888c35e756b9a329366c9fd7c Mon Sep 17 00:00:00 2001 From: Florian Angerer Date: Thu, 11 May 2023 09:05:04 +0200 Subject: [PATCH 1/4] Add structseq.c to extra sources --- hpy/devel/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hpy/devel/__init__.py b/hpy/devel/__init__.py index e7414161..2c2ec71e 100644 --- a/hpy/devel/__init__.py +++ b/hpy/devel/__init__.py @@ -74,6 +74,7 @@ def get_extra_sources(self): self.src_dir.joinpath('buildvalue.c'), self.src_dir.joinpath('format.c'), self.src_dir.joinpath('helpers.c'), + self.src_dir.joinpath('structseq.c'), ])) def _scan_static_lib_dir(self): From de66fb906cc2b80ba0c62749e923bdf829ca9608 Mon Sep 17 00:00:00 2001 From: Florian Angerer Date: Thu, 11 May 2023 09:06:48 +0200 Subject: [PATCH 2/4] Use tag name for prerelease detection --- .github/workflows/release-pypi.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml index 6a2fe484..959a7791 100644 --- a/.github/workflows/release-pypi.yml +++ b/.github/workflows/release-pypi.yml @@ -126,16 +126,11 @@ jobs: name: artifact path: dist - - name: Checkout - uses: actions/checkout@v3 - with: - ref: ${{ inputs.tag }} - - name: Release uses: softprops/action-gh-release@v1 with: files: dist/* # consider tags in form '*.*.*rc*' to indicate a pre-release - prerelease: ${{ contains(github.ref, 'rc') }} + prerelease: ${{ contains(inputs.tag, 'rc') }} draft: ${{ !inputs.official }} tag_name: ${{ inputs.tag }} From b848622de2069f4ab3b4f26cdb2826fca50c690f Mon Sep 17 00:00:00 2001 From: Florian Angerer Date: Thu, 11 May 2023 09:44:54 +0200 Subject: [PATCH 3/4] Fix global option name --- hpy/devel/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hpy/devel/__init__.py b/hpy/devel/__init__.py index 2c2ec71e..e59dd027 100644 --- a/hpy/devel/__init__.py +++ b/hpy/devel/__init__.py @@ -188,8 +188,11 @@ def handle_hpy_ext_modules(dist, attr, hpy_ext_modules): dist.__class__.hpy_abi = DEFAULT_HPY_ABI dist.__class__.hpy_use_static_libs = False dist.__class__.global_options += [ - ('hpy-abi=', None, 'Specify the HPy ABI mode (default: %s)' % DEFAULT_HPY_ABI), - ('hpy-no-static-libs', None, 'Compile context and extra sources with extension (default: False)') + ('hpy-abi=', None, 'Specify the HPy ABI mode (default: %s)' + % DEFAULT_HPY_ABI), + ('hpy-use-static-libs', None, 'Use static library containing context ' + 'and helper functions for building ' + 'extensions (default: False)') ] hpydevel = HPyDevel() hpydevel.fix_distribution(dist) From fed10a4db630235725e403535e2b492681004666 Mon Sep 17 00:00:00 2001 From: Florian Angerer Date: Thu, 11 May 2023 10:59:23 +0200 Subject: [PATCH 4/4] Make structseq.c C++ ready --- hpy/devel/src/runtime/structseq.c | 32 +++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/hpy/devel/src/runtime/structseq.c b/hpy/devel/src/runtime/structseq.c index bec17e9c..8feb27d6 100644 --- a/hpy/devel/src/runtime/structseq.c +++ b/hpy/devel/src/runtime/structseq.c @@ -28,8 +28,10 @@ HPyStructSequence_NewType(HPyContext *ctx, HPyStructSequence_Desc *desc) #ifndef HPY_ABI_CPYTHON HPyTracker ht; - HPy fields, args, kwds, defs, docstring, n_fields; + HPy fields, args, kwds, defs, docstring, n_fields, h_field, h_modname; HPy result = HPy_NULL; + const char *name, *s; + char *modname; HPy collections = HPyImport_ImportModule(ctx, "collections"); if (HPy_IsNull(collections)) { @@ -56,8 +58,8 @@ HPyStructSequence_NewType(HPyContext *ctx, HPyStructSequence_Desc *desc) HPy_Close(ctx, h_name); i = 0; - for (const char* name = desc->fields[i].name; name != NULL; name = desc->fields[++i].name) { - HPy h_field = HPyUnicode_FromString(ctx, name); + for (name = desc->fields[i].name; name != NULL; name = desc->fields[++i].name) { + h_field = HPyUnicode_FromString(ctx, name); if (HPy_IsNull(h_field)) { HPyTupleBuilder_Cancel(ctx, argsBuilder); HPyTupleBuilder_Cancel(ctx, fieldsBuilder); @@ -130,8 +132,7 @@ HPyStructSequence_NewType(HPyContext *ctx, HPyStructSequence_Desc *desc) } /* Set the type name and qualname */ - const char *s = strrchr(desc->name, '.'); - char *modname; + s = strrchr(desc->name, '.'); if (s == NULL) { s = desc->name; modname = NULL; @@ -163,7 +164,7 @@ HPyStructSequence_NewType(HPyContext *ctx, HPyStructSequence_Desc *desc) } if (modname != NULL) { - HPy h_modname = HPyUnicode_FromString(ctx, modname); + h_modname = HPyUnicode_FromString(ctx, modname); free(modname); if (HPy_IsNull(h_modname)) { goto error; @@ -191,7 +192,7 @@ HPyStructSequence_NewType(HPyContext *ctx, HPyStructSequence_Desc *desc) .doc = desc->doc, #endif .fields = (PyStructSequence_Field *)desc->fields, - .n_in_sequence = i + .n_in_sequence = (int)i }; return _py2h((PyObject*) PyStructSequence_NewType(&d)); #endif @@ -216,16 +217,20 @@ HPyStructSequence_New(HPyContext *ctx, HPy type, HPy_ssize_t nargs, HPy *args) HPy_Close(ctx, tuple); return result; #else - PyTypeObject *tp = (PyTypeObject *)_h2py(type); + PyTypeObject *tp; + PyObject *name, *v, *seq, *item; + Py_ssize_t n_fields, i; + + tp = (PyTypeObject *)_h2py(type); + name = PyUnicode_FromStringAndSize(s_n_fields, sizeof(s_n_fields)); // CPython also accesses the dict directly - PyObject *name = PyUnicode_FromStringAndSize(s_n_fields, sizeof(s_n_fields)); - PyObject *v = PyDict_GetItemWithError(tp->tp_dict, name); + v = PyDict_GetItemWithError(tp->tp_dict, name); Py_DECREF(name); if (v == NULL && !PyErr_Occurred()) { goto type_error; } - Py_ssize_t n_fields = PyLong_AsSsize_t(v); - PyObject *seq = PyStructSequence_New(tp); + n_fields = PyLong_AsSsize_t(v); + seq = PyStructSequence_New(tp); if (seq == NULL) { goto type_error; } @@ -237,8 +242,7 @@ HPyStructSequence_New(HPyContext *ctx, HPy type, HPy_ssize_t nargs, HPy *args) goto error; } - PyObject *item; - for (Py_ssize_t i = 0; i < nargs; i++) { + for (i = 0; i < nargs; i++) { item = _h2py(args[i]); Py_INCREF(item); PyStructSequence_SetItem(seq, i, item);