ltests.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. ** $Id: ltests.h,v 2.8 2004/07/09 14:29:29 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. #define check_exp(c,e) (lua_assert(c), (e))
  15. #undef api_check
  16. #define api_check(L, o) lua_assert(o)
  17. /* to avoid warnings, and to make sure value is really unused */
  18. #define UNUSED(x) (x=0, (void)(x))
  19. /* memory allocator control variables */
  20. typedef struct Memcontrol {
  21. unsigned long numblocks;
  22. unsigned long total;
  23. unsigned long maxmem;
  24. unsigned long memlimit;
  25. } Memcontrol;
  26. extern Memcontrol memcontrol;
  27. /*
  28. ** generic variable for debug tricks
  29. */
  30. extern int Trick;
  31. void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize);
  32. #ifdef lua_c
  33. #define luaL_newstate() lua_newstate(debug_realloc, &memcontrol)
  34. #endif
  35. int lua_checkmemory (lua_State *L);
  36. /* test for lock/unlock */
  37. #undef lua_userstateopen
  38. #undef lua_lock
  39. #undef lua_unlock
  40. extern int islocked;
  41. #define LUA_USERSTATE int *
  42. #define getlock(l) (*(cast(LUA_USERSTATE *, l) - 1))
  43. #define lua_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. #undef lua_userinit
  48. #define lua_userinit(L) { luaopen_stdlibs(L); luaB_opentests(L); }
  49. /* real main will be defined at `ltests.c' */
  50. int l_main (int argc, char *argv[]);
  51. #define main l_main
  52. /* change some sizes to give some bugs a chance */
  53. #undef LUAL_BUFFERSIZE
  54. #define LUAL_BUFFERSIZE 27
  55. #define MINSTRTABSIZE 2
  56. #endif