hpyproject / hpy

HPy: a better API for Python
https://hpyproject.org
MIT License
1.02k stars 52 forks source link

test_metaclass and `set_meta_data`: it seems to be operating on the wrong legacy class? #451

Closed mattip closed 11 months ago

mattip commented 11 months ago

In test_metaclass there is this code: https://github.com/hpyproject/hpy/blob/f6114734b4a5d03cfb9d24d3e8c71f77e8803881/test/test_hpytype.py#L1462

It calls into this function: https://github.com/hpyproject/hpy/blob/f6114734b4a5d03cfb9d24d3e8c71f77e8803881/test/test_hpytype.py#L244-L254

In legacy mode the macro DummyMeta_AsStruct is converted into

__attribute__((unused)) 
static inline DummyMeta * DummyMeta_AsStruct(HPyContext *ctx, HPy h) { 
    return (DummyMeta *) _HPy_AsStruct_Legacy(ctx, h); 
}

where _HPy_AsStruct_Legacy for CPython is _h2py(h). But the h in the test is the Dummy type object, not the DummyMeta type object, so doesn't _h2py(h) return the Dummy data struct (and not the DummyMeta struct the test is expecting? In universal mode, DummyMeta_AsStruct calls _HPy_AsStruct_Type, which I wrote as obj = handles.deref(h); type = type(obj); return dataptr(type) so that it will return the DummyMeta struct, but I don't know what to do for _HPy_AsStruct_Legacy.

mattip commented 11 months ago

I had a bug in the PyPy implementation, and now things work. I am still not sure how.