[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A nasty, silent native-component gotcha (GB_BASE) - (follow-up on the uvicorn thread)
[Thread Prev] | [Thread Next]
- Subject: Re: A nasty, silent native-component gotcha (GB_BASE) - (follow-up on the uvicorn thread)
- From: Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
- Date: Thu, 10 Sep 2026 09:55:52 +0200
- To: user@xxxxxxxxxxxxxxxxxxxxxx
Le 09/09/2026 à 00:20, Alarch a écrit :
Dear Benoît, dear Claus, dear all, ... The mistake: my class' native struct did not have GB_BASE as its first field.typedef struct { llhttp_t parser; llhttp_settings_t settings; ... } CLLHTTPPARSER;instead oftypedef struct { GB_BASE ob; /* forgot this */ llhttp_t parser; llhttp_settings_t settings; ... } CLLHTTPPARSER;... Two things I wanted to ask/suggest, now that I've found it:1. Would a cheap sanity check be worth adding somewhere in CLASS_register_class (or right after a native _new call, in debug buildsonly) - e.g. checking that the class pointer embedded at the start of a freshly allocated object still matches what was written at allocation time? I don't know the internals well enough to judge the cost/ complexity, but even a debug-only assertion would have saved me a good few hours, since it would point straight at the object instead of crashing somewhere unrelated much later.
Sorry for your struggle with that bug, but I don't think it's possible to detect that mistake at compile time or at run time.
2. Would it be worth a short, explicit warning on the component- writing wiki page (with exactly this failure mode described), for anyone writing their first native class the way I did? I'm happy to draft that if it's welcome - it's exactly the kind of thing that's obvious in hindsight and invisible beforehand.
Feel free to add it on the wiki.Anyway, it's a very common programming pattern to have a common part at the beginning of a structure when you implement dynamic object with inheritance in C.
Regards, -- Benoît Minisini.
| A nasty, silent native-component gotcha (GB_BASE) - (follow-up on the uvicorn thread) | Alarch <alarch@xxxxxxxxx> |