Skip to content

Ambiguous tests in test_hpytype_legacy.py #459

@mattip

Description

@mattip

The code in test_htype.py has tests like

    def test_simple_type(self):
        mod = self.make_module("""
            static HPyType_Spec Dummy_spec = {
                .name = "mytest.Dummy",
                .itemsize = 0,
                .flags = HPy_TPFLAGS_DEFAULT | HPy_TPFLAGS_BASETYPE,
                @DEFAULT_SHAPE
            };

            @EXPORT_TYPE("Dummy", Dummy_spec)
            @INIT
        """)

When run in test_hpytype.py then @DEFAULT_SHAPE is an empty comment "/* default object shape */" and everything is fine. But when these tests are rerun in test_hpytype_legacy.py, then @DEFAULT_SHAPE becomes .builtin_shape = HPyType_BuiltinShape_Legacy.

As I understand the intention of using the legacy shape is that the type can be used via the C-API, so it needs to become a heap type object. But the preamble to add #include <Python.h> is missing, and the basicsize is 0 (not declared). I guess I can work around the missing include file somehow, but it is not clear to me if a type spec can declare legacy shape without declaring a basicsize. Thoughts? Should this Just Work (i.e. when creating a type from the spec, note the legacy flag and allocate a heap type object as the storage)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions