hpyproject / hpy

HPy: a better API for Python

Home Page:https://hpyproject.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

mattip opened this issue · comments

In test_metaclass there is this code:

assert mod.set_meta_data(mod.Dummy) is None

It calls into this function:

hpy/test/test_hpytype.py

Lines 244 to 254 in f611473

HPyDef_METH(set_meta_data, "set_meta_data", HPyFunc_O)
static HPy set_meta_data_impl(HPyContext *ctx, HPy self, HPy arg)
{
DummyMeta *data = DummyMeta_AsStruct(ctx, arg);
data->meta_magic = 42;
data->meta_member = 11;
for (size_t i = 0; i < 64; ++i)
data->some_more[i] = (char) i;
return HPy_Dup(ctx, ctx->h_None);
}

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.

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