Skip to content

gobject: allocate parameter list for g_object_new_valist() entirely on stack

Thomas Haller requested to merge th/gobject-new-parameter-list into master

Quote:

    When parsing the argument list for g_object_new_valist() we need to
    build a temporary list.
    
    Note that already previously, all the GValue instances were allocate on the
    stack, with g_newa(). That means, previously we allocated on the stack
    (16 * sizeof (GObjectConstructParam) + n * sizeof (GValue)) bytes (which
    is (256 + n * 24), on 64 bit).
    
    Go one step further and allocate also the excess parameter list on the stack.
    Now we require O(n * 16 + n * 56) on the stack.
    
    Maybe it is a problem to allocate that much data on the stack. If that is
    a concern, we should limit the amount of bytes we allocate on the stack.
    On the other hand, n itself is the number of parameters of g_object_new_valist()
    and themself on the stack. That means, n itself is limited by an
    unknown amount of available stack and each parameter in the valist list
    probably requires 12 or 16 bytes (on 64 bit, for the aligned name pointer and
    the argument, depending on whether the type is int or a pointer).
    
    Also, previously the buffer was not grown exponentially during
    
      g_renew (GObjectConstructParam, params, n_params + 1)
    
    although I think it should be.

Merge request reports

Loading