ltests.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. ** $Id: ltests.h,v 2.46 2014/12/19 13:33:06 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. /* test Lua with no compatibility code */
  10. #undef LUA_COMPAT_MATHLIB
  11. #undef LUA_COMPAT_IPAIRS
  12. #undef LUA_COMPAT_BITLIB
  13. #undef LUA_COMPAT_APIINTCASTS
  14. #undef LUA_COMPAT_FLOATSTRING
  15. #undef LUA_COMPAT_UNPACK
  16. #undef LUA_COMPAT_LOADERS
  17. #undef LUA_COMPAT_LOG10
  18. #undef LUA_COMPAT_LOADSTRING
  19. #undef LUA_COMPAT_MAXN
  20. #undef LUA_COMPAT_MODULE
  21. #define LUA_DEBUG
  22. /* turn on assertions */
  23. #undef NDEBUG
  24. #include <assert.h>
  25. #define lua_assert(c) assert(c)
  26. /* to avoid warnings, and to make sure value is really unused */
  27. #define UNUSED(x) (x=0, (void)(x))
  28. /* memory-allocator control variables */
  29. typedef struct Memcontrol {
  30. unsigned long numblocks;
  31. unsigned long total;
  32. unsigned long maxmem;
  33. unsigned long memlimit;
  34. unsigned long objcount[LUA_NUMTAGS];
  35. } Memcontrol;
  36. LUA_API Memcontrol l_memcontrol;
  37. /*
  38. ** generic variable for debug tricks
  39. */
  40. extern void *l_Trick;
  41. /*
  42. ** Function to traverse and check all memory used by Lua
  43. */
  44. int lua_checkmemory (lua_State *L);
  45. /* test for lock/unlock */
  46. struct L_EXTRA { int lock; int *plock; };
  47. #undef LUA_EXTRASPACE
  48. #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
  49. #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
  50. #define luai_userstateopen(l) \
  51. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  52. #define luai_userstateclose(l) \
  53. lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
  54. #define luai_userstatethread(l,l1) \
  55. lua_assert(getlock(l1)->plock == getlock(l)->plock)
  56. #define luai_userstatefree(l,l1) \
  57. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  58. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  59. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  60. LUA_API int luaB_opentests (lua_State *L);
  61. LUA_API void *debug_realloc (void *ud, void *block,
  62. size_t osize, size_t nsize);
  63. #if defined(lua_c)
  64. #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
  65. #define luaL_openlibs(L) \
  66. { (luaL_openlibs)(L); luaL_requiref(L, "T", luaB_opentests, 1); }
  67. #endif
  68. /* change some sizes to give some bugs a chance */
  69. #undef LUAL_BUFFERSIZE
  70. #define LUAL_BUFFERSIZE 23
  71. #define MINSTRTABSIZE 2
  72. /* make stack-overflow tests run faster */
  73. #undef LUAI_MAXSTACK
  74. #define LUAI_MAXSTACK 50000
  75. #undef LUAI_USER_ALIGNMENT_T
  76. #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
  77. #endif