Branch: Tag:

2019-08-19

2019-08-19 10:07:30 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Runtime: Reference-count malloced locals.

PIKE_FRAME_MALLOCED_LOCALS are now contained in a struct array,
this is in order to be able to reference count the storage and
share it beween multiple frames.

141: Inside #if defined(PIKE_DEBUG)
   gc_mark_external (f->current_program, " in current_program in frame on stack");    if (f->locals) { /* Check really needed? */    if (f->flags & PIKE_FRAME_MALLOCED_LOCALS) { -  gc_mark_external_svalues(f->locals, f->num_locals, +  gc_mark_external_svalues(f->locals - 1, 1,    " in malloced locals of trampoline frame on stack");    } else {    if (f->locals > stack_p || (stack_p - f->locals) >= 0x10000) {
2101:       if (num_new_locals)    { -  struct svalue *s = xcalloc(sizeof(struct svalue), num_new_locals); +  struct array *a = allocate_array(num_new_locals + 1);    struct svalue *locals = frame->locals;    unsigned INT16 bitmask = 0; -  +  struct svalue *s = ITEM(a) + 1;    -  +  /* Self-reference for reference-counting purposes. */ +  SET_SVAL(ITEM(a)[0], PIKE_T_ARRAY, 0, array, a); +  /* NB: Make sure that the self-reference is not counted as +  * part of the actual array contents for gc purposes. +  */ +  s = ++ITEM(a); +  a->size--; +     for (i = 0; i < num_new_locals; i++) {    unsigned INT16 bitmask = frame->save_locals_bitmask[i / 16];       if (bitmask & (1 << (i % 16))) {    assign_svalue_no_free(s + i, locals + i);    } - #ifdef PIKE_DEBUG -  else -  mark_free_svalue(s + i); - #endif +     }       frame->locals = s;
2164:   {    if(scope->flags & PIKE_FRAME_MALLOCED_LOCALS)    { -  free_mixed_svalues(scope->locals,scope->num_locals); -  free(scope->locals); +  struct array *a = scope->locals[-1].u.array; +  +  free_array(a); +  scope->locals = NULL; +    #ifdef PIKE_DEBUG    scope->flags&=~PIKE_FRAME_MALLOCED_LOCALS;   #endif