ltests.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. ** $Id: ltests.h,v 2.57 2018/04/11 16:49:36 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_DEBUG
  13. /* turn on assertions */
  14. #undef NDEBUG
  15. #include <assert.h>
  16. #define lua_assert(c) assert(c)
  17. /* include opcode names */
  18. #define LUAI_DEFOPNAMES
  19. /* compiled with -O0, Lua uses a lot of C stack space... */
  20. #undef LUAI_MAXCCALLS
  21. #define LUAI_MAXCCALLS 200
  22. /* to avoid warnings, and to make sure value is really unused */
  23. #define UNUSED(x) (x=0, (void)(x))
  24. /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */
  25. #undef l_sprintf
  26. #if !defined(LUA_USE_C89)
  27. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i))
  28. #else
  29. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i))
  30. #endif
  31. /* get a chance to test code without jump tables */
  32. #define LUA_USE_JUMPTABLE 0
  33. /* memory-allocator control variables */
  34. typedef struct Memcontrol {
  35. unsigned long numblocks;
  36. unsigned long total;
  37. unsigned long maxmem;
  38. unsigned long memlimit;
  39. unsigned long countlimit;
  40. unsigned long objcount[LUA_NUMTAGS];
  41. } Memcontrol;
  42. LUA_API Memcontrol l_memcontrol;
  43. /*
  44. ** generic variable for debug tricks
  45. */
  46. extern void *l_Trick;
  47. /*
  48. ** Function to traverse and check all memory used by Lua
  49. */
  50. int lua_checkmemory (lua_State *L);
  51. /* test for lock/unlock */
  52. struct L_EXTRA { int lock; int *plock; };
  53. #undef LUA_EXTRASPACE
  54. #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
  55. #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
  56. #define luai_userstateopen(l) \
  57. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  58. #define luai_userstateclose(l) \
  59. lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
  60. #define luai_userstatethread(l,l1) \
  61. lua_assert(getlock(l1)->plock == getlock(l)->plock)
  62. #define luai_userstatefree(l,l1) \
  63. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  64. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  65. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  66. LUA_API int luaB_opentests (lua_State *L);
  67. LUA_API void *debug_realloc (void *ud, void *block,
  68. size_t osize, size_t nsize);
  69. #if defined(lua_c)
  70. #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
  71. #define luaL_openlibs(L) \
  72. { (luaL_openlibs)(L); \
  73. luaL_requiref(L, "T", luaB_opentests, 1); \
  74. lua_pop(L, 1); }
  75. #endif
  76. /* change some sizes to give some bugs a chance */
  77. #undef LUAL_BUFFERSIZE
  78. #define LUAL_BUFFERSIZE 23
  79. #define MINSTRTABSIZE 2
  80. #define MAXINDEXRK 1
  81. #define MAXIWTHABS 3
  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