vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.29k stars 145 forks source link

Add `void*` params to callbacks, for caller context #356

Open snej opened 1 year ago

snej commented 1 year ago

In general, most C APIs that register callbacks have a void* parameter in the callback, and in the function that registers it, for passing arbitrary client state. Otherwise the callback implementation can only access global state.

Mir’s API lacks this. So for example, I’ve found the function MIR_write_with_func almost unusable because my callback doesn’t know where to put the data given to it; I’d have to create a global/static variable pointing to my data buffer.

The functions that take such callbacks are: