/script_binding/lua/lua/lmem.h

http://ftk.googlecode.com/ · C++ Header · 49 lines · 29 code · 15 blank · 5 comment · 1 complexity · 368761f75f040c81f9213c4e0e51192f MD5 · raw file

  1. /*
  2. ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 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 MEMERRMSG "not enough memory"
  12. #define luaM_reallocv(L,b,on,n,e) \
  13. ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
  14. luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
  15. luaM_toobig(L))
  16. #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
  17. #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
  18. #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t))
  19. #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t))
  20. #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
  21. #define luaM_newvector(L,n,t) \
  22. cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
  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 void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
  29. size_t size);
  30. LUAI_FUNC void *luaM_toobig (lua_State *L);
  31. LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
  32. size_t size_elem, int limit,
  33. const char *errormsg);
  34. #endif