zval custom info

I wonder if it might be a good idea to allow zvals (if you don’t know what it is, you might want to read something about it before continuing) carry custom information – e.g. in a form of a pointer. This may allow various custom modules to tag zvals – e.g. security module to have zvals coming from users separated from zvals coming from engine. Or debugger could record where particular variable was created/modified.

Of course, that would need a protocol for coordinating this info between modules – so that two modules could store zval info without stepping on each other’s toes.


3 thoughts on “zval custom info

  1. I would imagine for things like debuggers and profilers you would want to re-populate the data on every zval copy to track when the copy was made and in which context. For security and other modules that may not be as important as they may not care about anything beyond creation and perhaps some specific usages that they are trying to protect.

    I think when to copy & free the data is a complex problem, probably the biggest complexity of this entire implementation. Given the overhead this may add, one idea make this “extra” zval info be set depending on a configure switch –with-extended-zval (or something like that) in a way it can be PHP’s frame-pointers 😉

  2. Yes, something along these lines, but some thinking needs to be done about freeing zvals and sharing info between zvals – i.e., we probably don’t want to copy all the stuff when zval is copied, if so – when this data is to be freed? We might need to refcount it.

  3. That’s a rather interesting idea, there are many ways this information could be useful, although adding anything to a zval may lead to increased memory usage, given how many zvals even small scripts tend to use.

    As far as multiple modules using this data something like this structure could be a solution

    typedef struct _extra {
    void *data;
    int module_number;
    struct _extra *next;
    } extra;

    The module can then using a loop to identify a free spot and mark it as its own via the module_number element.

    extra *zvale = zval->extra;
    while (zvale) {
    zvale = zvale->next;

Comments are closed.