ltests.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. ** $Id: ltests.h,v 2.17 2005/12/27 17:12: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. #define lua_assert(c) assert(c)
  13. /* to avoid warnings, and to make sure value is really unused */
  14. #define UNUSED(x) (x=0, (void)(x))
  15. /* memory allocator control variables */
  16. typedef struct Memcontrol {
  17. unsigned long numblocks;
  18. unsigned long total;
  19. unsigned long maxmem;
  20. unsigned long memlimit;
  21. } Memcontrol;
  22. LUAI_DATA Memcontrol memcontrol;
  23. /*
  24. ** generic variable for debug tricks
  25. */
  26. LUAI_DATA int Trick;
  27. void *debug_realloc (void *ud, void *block, size_t osize, size_t nsize);
  28. #ifdef lua_c
  29. #define luaL_newstate() lua_newstate(debug_realloc, &memcontrol)
  30. #endif
  31. typedef struct CallInfo *pCallInfo;
  32. int lua_checkmemory (lua_State *L);
  33. int lua_checkpc (lua_State *L, pCallInfo ci);
  34. /* test for lock/unlock */
  35. #undef luai_userstateopen
  36. #undef luai_userstatethread
  37. #undef lua_lock
  38. #undef lua_unlock
  39. #undef LUAI_EXTRASPACE
  40. struct L_EXTRA { int lock; int *plock; };
  41. #define LUAI_EXTRASPACE sizeof(struct L_EXTRA)
  42. #define getlock(l) (cast(struct L_EXTRA *, l) - 1)
  43. #define luai_userstateopen(l) \
  44. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  45. #define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->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. #ifdef lua_c
  50. #define luaL_openlibs(L) { (luaL_openlibs)(L); luaB_opentests(L); }
  51. #endif
  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