ltests.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ** $Id: ltests.h,v 2.9 2004/07/16 13:17:00 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. extern Memcontrol memcontrol;
  24. /*
  25. ** generic variable for debug tricks
  26. */
  27. extern 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. int lua_checkmemory (lua_State *L);
  33. /* test for lock/unlock */
  34. #undef lua_userstateopen
  35. #undef lua_lock
  36. #undef lua_unlock
  37. extern int islocked;
  38. #define LUA_USERSTATE int *
  39. #define getlock(l) (*(cast(LUA_USERSTATE *, l) - 1))
  40. #define lua_userstateopen(l) getlock(l) = &islocked;
  41. #define lua_lock(l) lua_assert((*getlock(l))++ == 0)
  42. #define lua_unlock(l) lua_assert(--(*getlock(l)) == 0)
  43. int luaB_opentests (lua_State *L);
  44. #undef lua_userinit
  45. #define lua_userinit(L) { luaopen_stdlibs(L); luaB_opentests(L); }
  46. /* real main will be defined at `ltests.c' */
  47. int l_main (int argc, char *argv[]);
  48. #define main l_main
  49. /* change some sizes to give some bugs a chance */
  50. #undef LUAL_BUFFERSIZE
  51. #define LUAL_BUFFERSIZE 27
  52. #define MINSTRTABSIZE 2
  53. #endif