Skip to content

Commit

Permalink
Merge pull request #432 from hpyproject/fa/fix_missing_structseq
Browse files Browse the repository at this point in the history
Add structseq.c to extra sources.
  • Loading branch information
fangerer authored May 11, 2023
2 parents 94aaada + fed10a4 commit 5ddcbc8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
8 changes: 6 additions & 2 deletions hpy/devel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -187,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)
Expand Down
32 changes: 18 additions & 14 deletions hpy/devel/src/runtime/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 5ddcbc8

Please sign in to comment.