You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 regels
1.5 KiB

  1. /*
  2. ** $Id: lmem.h,v 1.38 2011/12/02 13:26:54 roberto Exp $
  3. ** Interface to Memory Manager
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lmem_h
  7. #define lmem_h
  8. #include <stddef.h>
  9. #include "llimits.h"
  10. #include "lua.h"
  11. #define luaM_reallocv(L,b,on,n,e) \
  12. ((cast(size_t, (n)+1) > MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
  13. (luaM_toobig(L), (void *)0) : \
  14. luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
  15. #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
  16. #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
  17. #define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0]))
  18. #define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s))
  19. #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
  20. #define luaM_newvector(L,n,t) \
  21. cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
  22. #define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s))
  23. #define luaM_growvector(L,v,nelems,size,t,limit,e) \
  24. if ((nelems)+1 > (size)) \
  25. ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
  26. #define luaM_reallocvector(L, v,oldn,n,t) \
  27. ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
  28. LUAI_FUNC l_noret luaM_toobig (lua_State *L);
  29. /* not to be called directly */
  30. LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
  31. size_t size);
  32. LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
  33. size_t size_elem, int limit,
  34. const char *what);
  35. #endif