ltests.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. ** $Id: ltests.h,v 2.50.1.1 2017/04/19 17:20:42 roberto Exp $
  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. /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */
  29. #undef l_sprintf
  30. #if !defined(LUA_USE_C89)
  31. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i))
  32. #else
  33. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i))
  34. #endif
  35. /* memory-allocator control variables */
  36. typedef struct Memcontrol {
  37. unsigned long numblocks;
  38. unsigned long total;
  39. unsigned long maxmem;
  40. unsigned long memlimit;
  41. unsigned long objcount[LUA_NUMTAGS];
  42. } Memcontrol;
  43. LUA_API Memcontrol l_memcontrol;
  44. /*
  45. ** generic variable for debug tricks
  46. */
  47. extern void *l_Trick;
  48. /*
  49. ** Function to traverse and check all memory used by Lua
  50. */
  51. int lua_checkmemory (lua_State *L);
  52. /* test for lock/unlock */
  53. struct L_EXTRA { int lock; int *plock; };
  54. #undef LUA_EXTRASPACE
  55. #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
  56. #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
  57. #define luai_userstateopen(l) \
  58. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  59. #define luai_userstateclose(l) \
  60. lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
  61. #define luai_userstatethread(l,l1) \
  62. lua_assert(getlock(l1)->plock == getlock(l)->plock)
  63. #define luai_userstatefree(l,l1) \
  64. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  65. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  66. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  67. LUA_API int luaB_opentests (lua_State *L);
  68. LUA_API void *debug_realloc (void *ud, void *block,
  69. size_t osize, size_t nsize);
  70. #if defined(lua_c)
  71. #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
  72. #define luaL_openlibs(L) \
  73. { (luaL_openlibs)(L); \
  74. luaL_requiref(L, "T", luaB_opentests, 1); \
  75. lua_pop(L, 1); }
  76. #endif
  77. /* change some sizes to give some bugs a chance */
  78. #undef LUAL_BUFFERSIZE
  79. #define LUAL_BUFFERSIZE 23
  80. #define MINSTRTABSIZE 2
  81. #define MAXINDEXRK 1
  82. /* make stack-overflow tests run faster */
  83. #undef LUAI_MAXSTACK
  84. #define LUAI_MAXSTACK 50000
  85. #undef LUAI_USER_ALIGNMENT_T
  86. #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
  87. #define STRCACHE_N 23
  88. #define STRCACHE_M 5
  89. #endif