On 11/29/2026 9:46 PM, Bonita Montero wrote:
> Am 30.11.2026 um 05:04 schrieb Dan Cross:
>
>> In article <11ei…@raubtier-asyl.eternal-september.org>,
>
>>> It is hard since a different class has a different object layout
>>> with different state.
>
>> Hence thunks.
> ???
>
Think of storing the original vtable pointer from something, oh, say like in my code:
https://pastebin.com/raw/f52a443b1
struct device {
struct device_vtable const* vtable;
};
You make another vtable that acts as a proxy for starters, just intercepts everything then sends along to the stored original vtable:
struct device_vtable* old = device->vtable;
device->vtable = &new;
Then in the new table we simply forward things to the old vtable.
Now, we have a man in the middle.
This can be thunked:
/* Interfaces
____________________________________________________________________*/
#include <stddef.h>
struct object_prv_vtable {
int (*fp_destroy) (void* const);
};
struct device_prv_vtable {
int (*fp_read) (void* const, void*, size_t);
int (*fp_write) (void* const, void const*, size_t);
};
struct device_vtable {
struct object_prv_vtable const object;
struct device_prv_vtable const device;
};
struct device {
struct device_vtable const* vtable;
};
#define object_destroy(mp_self) ( \
(mp_self)->vtable->object.fp_destroy((mp_self)) \
)
#define device_read(mp_self, mp_buf, mp_size) ( \
(mp_self)->vtable->device.fp_read((mp_self), (mp_buf), (mp_size)) \
)
#define device_write(mp_self, mp_buf, mp_size) ( \
(mp_self)->vtable->device.fp_write((mp_self), (mp_buf), (mp_size)) \
)