ltests.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ** $Id: ltests.h,v 2.15 2005/06/06 13:30:25 roberto Exp roberto $
  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. #define LUA_DEBUG
  10. #undef NDEBUG
  11. #include <assert.h>
  12. #undef lua_assert
  13. #define lua_assert(c) assert(c)
  14. /* to avoid warnings, and to make sure value is really unused */
  15. #define UNUSED(x) (x=0, (void)(x))
  16. /* memory allocator control variables */
  17. typedef struct Memcontrol {
  18. unsigned long numblocks;
  19. unsigned long total;
  20. unsigned long maxmem;
  21. unsigned long memlimit;
  22. } Memcontrol;
  23. LUAI_DATA Memcontrol memcontrol;
  24. /*
  25. ** generic variable for debug tricks
  26. */
  27. LUAI_DATA int Trick;
  28. void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize);
  29. #ifdef lua_c
  30. #define luaL_newstate() lua_newstate(debug_realloc, &memcontrol)
  31. #endif
  32. typedef struct CallInfo *pCallInfo;
  33. int lua_checkmemory (lua_State *L);
  34. int lua_checkpc (lua_State *L, pCallInfo ci);
  35. /* test for lock/unlock */
  36. #undef luai_userstateopen
  37. #undef luai_userstatethread
  38. #undef lua_lock
  39. #undef lua_unlock
  40. #undef LUAI_EXTRASPACE
  41. struct L_EXTRA { int lock; int *plock; };
  42. #define LUAI_EXTRASPACE sizeof(struct L_EXTRA)
  43. #define getlock(l) (cast(struct L_EXTRA *, l) - 1)
  44. #define luai_userstateopen(l) \
  45. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  46. #define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->plock)
  47. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  48. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  49. int luaB_opentests (lua_State *L);
  50. #ifdef lua_c
  51. #define luaL_openlibs(L) { (luaL_openlibs)(L); luaB_opentests(L); }
  52. #endif
  53. /* real main will be defined at `ltests.c' */
  54. int l_main (int argc, char *argv[]);
  55. #define main l_main
  56. /* change some sizes to give some bugs a chance */
  57. #undef LUAL_BUFFERSIZE
  58. #define LUAL_BUFFERSIZE 27
  59. #define MINSTRTABSIZE 2
  60. #endif