ltests.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. ** $Id: ltests.h,v 2.14 2005/05/03 19:01:17 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 lua_lock
  38. #undef lua_unlock
  39. #undef LUAI_EXTRASPACE
  40. LUAI_DATA int islocked;
  41. #define LUAI_EXTRASPACE sizeof(double)
  42. #define getlock(l) (*(cast(int **, l) - 1))
  43. #define luai_userstateopen(l) getlock(l) = &islocked;
  44. #define lua_lock(l) lua_assert((*getlock(l))++ == 0)
  45. #define lua_unlock(l) lua_assert(--(*getlock(l)) == 0)
  46. int luaB_opentests (lua_State *L);
  47. #ifdef lua_c
  48. #define luaL_openlibs(L) { (luaL_openlibs)(L); luaB_opentests(L); }
  49. #endif
  50. /* real main will be defined at `ltests.c' */
  51. int l_main (int argc, char *argv[]);
  52. #define main l_main
  53. /* change some sizes to give some bugs a chance */
  54. #undef LUAL_BUFFERSIZE
  55. #define LUAL_BUFFERSIZE 27
  56. #define MINSTRTABSIZE 2
  57. #endif