~kvik/lu9-lua

4fc16e0ad0724a9237629cf95fcd1f8dc67da8a3 — kvik 3 years ago 04c3a13
mem: tag allocations for better profiling information
2 files changed, 6 insertions(+), 2 deletions(-)

M lauxlib.c
M lmem.c
M lauxlib.c => lauxlib.c +3 -2
@@ 1013,8 1013,9 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
    free(ptr);
    return NULL;
  }
  else
    return realloc(ptr, nsize);
  ptr = realloc(ptr, nsize);
  setmalloctag(ptr, getcallerpc(&ud));
  return ptr;
}



M lmem.c => lmem.c +3 -0
@@ 171,6 171,7 @@ void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
  }
  lua_assert((nsize == 0) == (newblock == NULL));
  g->GCdebt = (g->GCdebt + nsize) - osize;
  setmalloctag(newblock, getcallerpc(&L));
  return newblock;
}



@@ 180,6 181,7 @@ void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize,
  void *newblock = luaM_realloc_(L, block, osize, nsize);
  if (l_unlikely(newblock == NULL && nsize > 0))  /* allocation failed? */
    luaM_error(L);
  setmalloctag(newblock, getcallerpc(&L));
  return newblock;
}



@@ 196,6 198,7 @@ void *luaM_malloc_ (lua_State *L, size_t size, int tag) {
        luaM_error(L);
    }
    g->GCdebt += size;
  	setmalloctag(newblock, getcallerpc(&L));
    return newblock;
  }
}