ltests.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ** $Id: ltests.h,v 2.33 2010/07/28 15:51:59 roberto Exp $
  3. ** Internal Header for Debugging of the Lua Implementation
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef ltests_h
  7. #define ltests_h
  8. #include <stdlib.h>
  9. /* do not use compatibility macros in Lua code */
  10. #undef LUA_COMPAT_API
  11. #define LUA_DEBUG
  12. #undef NDEBUG
  13. #include <assert.h>
  14. #define lua_assert(c) assert(c)
  15. /* to avoid warnings, and to make sure value is really unused */
  16. #define UNUSED(x) (x=0, (void)(x))
  17. /* memory allocator control variables */
  18. typedef struct Memcontrol {
  19. unsigned long numblocks;
  20. unsigned long total;
  21. unsigned long maxmem;
  22. unsigned long memlimit;
  23. unsigned long objcount[LUA_NUMTAGS];
  24. } Memcontrol;
  25. extern Memcontrol l_memcontrol;
  26. /*
  27. ** generic variable for debug tricks
  28. */
  29. extern void *l_Trick;
  30. void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize);
  31. typedef struct CallInfo *pCallInfo;
  32. int lua_checkmemory (lua_State *L);
  33. /* test for lock/unlock */
  34. #undef luai_userstateopen
  35. #undef luai_userstatethread
  36. #undef lua_lock
  37. #undef lua_unlock
  38. struct L_EXTRA { int lock; int *plock; };
  39. #define LUAI_EXTRASPACE sizeof(struct L_EXTRA)
  40. #define getlock(l) (cast(struct L_EXTRA *, l) - 1)
  41. #define luai_userstateopen(l) \
  42. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  43. #define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->plock)
  44. #define luai_userstatefree(l,l1) \
  45. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  46. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  47. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  48. int luaB_opentests (lua_State *L);
  49. #if defined(lua_c)
  50. #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
  51. #define luaL_openlibs(L) \
  52. { (luaL_openlibs)(L); luaL_requiref(L, "T", luaB_opentests, 1); }
  53. #endif
  54. /* change some sizes to give some bugs a chance */
  55. #undef LUAL_BUFFERSIZE
  56. #define LUAL_BUFFERSIZE 23
  57. #define MINSTRTABSIZE 2
  58. #undef LUAI_USER_ALIGNMENT_T
  59. #define LUAI_USER_ALIGNMENT_T union { char b[32]; }
  60. #endif