ltests.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. ** $Id: ltests.h,v 2.54 2017/12/07 18:51:39 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 <stdio.h>
  9. #include <stdlib.h>
  10. /* test Lua with compatibility code */
  11. #define LUA_COMPAT_MATHLIB
  12. #define LUA_COMPAT_IPAIRS
  13. #define LUA_COMPAT_BITLIB
  14. #define LUA_COMPAT_APIINTCASTS
  15. #define LUA_COMPAT_FLOATSTRING
  16. #define LUA_COMPAT_UNPACK
  17. #define LUA_COMPAT_LOADERS
  18. #define LUA_COMPAT_LOG10
  19. #define LUA_COMPAT_LOADSTRING
  20. #define LUA_COMPAT_MAXN
  21. #define LUA_COMPAT_MODULE
  22. #define LUA_DEBUG
  23. /* turn on assertions */
  24. #undef NDEBUG
  25. #include <assert.h>
  26. #define lua_assert(c) assert(c)
  27. /* compiled with -O0, Lua uses a lot of C stack space... */
  28. #undef LUAI_MAXCCALLS
  29. #define LUAI_MAXCCALLS 200
  30. /* to avoid warnings, and to make sure value is really unused */
  31. #define UNUSED(x) (x=0, (void)(x))
  32. /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */
  33. #undef l_sprintf
  34. #if !defined(LUA_USE_C89)
  35. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i))
  36. #else
  37. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i))
  38. #endif
  39. /* memory-allocator control variables */
  40. typedef struct Memcontrol {
  41. unsigned long numblocks;
  42. unsigned long total;
  43. unsigned long maxmem;
  44. unsigned long memlimit;
  45. unsigned long countlimit;
  46. unsigned long objcount[LUA_NUMTAGS];
  47. } Memcontrol;
  48. LUA_API Memcontrol l_memcontrol;
  49. /*
  50. ** generic variable for debug tricks
  51. */
  52. extern void *l_Trick;
  53. /*
  54. ** Function to traverse and check all memory used by Lua
  55. */
  56. int lua_checkmemory (lua_State *L);
  57. /* test for lock/unlock */
  58. struct L_EXTRA { int lock; int *plock; };
  59. #undef LUA_EXTRASPACE
  60. #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
  61. #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
  62. #define luai_userstateopen(l) \
  63. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  64. #define luai_userstateclose(l) \
  65. lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
  66. #define luai_userstatethread(l,l1) \
  67. lua_assert(getlock(l1)->plock == getlock(l)->plock)
  68. #define luai_userstatefree(l,l1) \
  69. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  70. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  71. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  72. LUA_API int luaB_opentests (lua_State *L);
  73. LUA_API void *debug_realloc (void *ud, void *block,
  74. size_t osize, size_t nsize);
  75. #if defined(lua_c)
  76. #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
  77. #define luaL_openlibs(L) \
  78. { (luaL_openlibs)(L); \
  79. luaL_requiref(L, "T", luaB_opentests, 1); \
  80. lua_pop(L, 1); }
  81. #endif
  82. /* change some sizes to give some bugs a chance */
  83. #undef LUAL_BUFFERSIZE
  84. #define LUAL_BUFFERSIZE 23
  85. #define MINSTRTABSIZE 2
  86. #define MAXINDEXRK 1
  87. #define MAXIWTHABS 3
  88. /* make stack-overflow tests run faster */
  89. #undef LUAI_MAXSTACK
  90. #define LUAI_MAXSTACK 50000
  91. #undef LUAI_USER_ALIGNMENT_T
  92. #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
  93. #define STRCACHE_N 23
  94. #define STRCACHE_M 5
  95. #endif