ltests.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. ** $Id: ltests.h $
  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_LT_LE
  13. #undef LUA_COMPAT_GLOBAL
  14. #define LUA_DEBUG
  15. /* turn on assertions */
  16. #define LUAI_ASSERT
  17. /* to avoid warnings, and to make sure value is really unused */
  18. #define UNUSED(x) (x=0, (void)(x))
  19. /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */
  20. #undef l_sprintf
  21. #if !defined(LUA_USE_C89)
  22. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i))
  23. #else
  24. #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i))
  25. #endif
  26. /* get a chance to test code without jump tables */
  27. #define LUA_USE_JUMPTABLE 0
  28. /* use 32-bit integers in random generator */
  29. #define LUA_RAND32
  30. /* test stack reallocation without strict address use */
  31. #define LUAI_STRICT_ADDRESS 0
  32. /* memory-allocator control variables */
  33. typedef struct Memcontrol {
  34. int failnext;
  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_NUMTYPES];
  41. } Memcontrol;
  42. LUA_API Memcontrol l_memcontrol;
  43. #define luai_tracegc(L,f) luai_tracegctest(L, f)
  44. LUAI_FUNC void luai_tracegctest (lua_State *L, int first);
  45. /*
  46. ** generic variable for debug tricks
  47. */
  48. extern void *l_Trick;
  49. /*
  50. ** Function to traverse and check all memory used by Lua
  51. */
  52. LUAI_FUNC int lua_checkmemory (lua_State *L);
  53. /*
  54. ** Function to print an object GC-friendly
  55. */
  56. struct GCObject;
  57. LUAI_FUNC void lua_printobj (lua_State *L, struct GCObject *o);
  58. /*
  59. ** Function to print a value
  60. */
  61. struct TValue;
  62. LUAI_FUNC void lua_printvalue (struct TValue *v);
  63. /*
  64. ** Function to print the stack
  65. */
  66. LUAI_FUNC void lua_printstack (lua_State *L);
  67. LUAI_FUNC int lua_printallstack (lua_State *L);
  68. /* test for lock/unlock */
  69. struct L_EXTRA { int lock; int *plock; };
  70. #undef LUA_EXTRASPACE
  71. #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
  72. #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
  73. #define luai_userstateopen(l) \
  74. (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
  75. #define luai_userstateclose(l) \
  76. lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
  77. #define luai_userstatethread(l,l1) \
  78. lua_assert(getlock(l1)->plock == getlock(l)->plock)
  79. #define luai_userstatefree(l,l1) \
  80. lua_assert(getlock(l)->plock == getlock(l1)->plock)
  81. #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
  82. #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
  83. LUA_API int luaB_opentests (lua_State *L);
  84. LUA_API void *debug_realloc (void *ud, void *block,
  85. size_t osize, size_t nsize);
  86. #if defined(lua_c)
  87. #define luaL_newstate() \
  88. lua_newstate(debug_realloc, &l_memcontrol, luaL_makeseed(NULL))
  89. #define luai_openlibs(L) \
  90. { luaL_openlibs(L); \
  91. luaL_requiref(L, "T", luaB_opentests, 1); \
  92. lua_pop(L, 1); }
  93. #endif
  94. /* change some sizes to give some bugs a chance */
  95. #undef LUAL_BUFFERSIZE
  96. #define LUAL_BUFFERSIZE 23
  97. #define MINSTRTABSIZE 2
  98. #define MAXIWTHABS 3
  99. #define STRCACHE_N 23
  100. #define STRCACHE_M 5
  101. /*
  102. ** This one is not compatible with tests for opcode optimizations,
  103. ** as it blocks some optimizations
  104. #define MAXINDEXRK 0
  105. */
  106. /*
  107. ** Reduce maximum stack size to make stack-overflow tests run faster.
  108. ** (But value is still large enough to overflow smaller integers.)
  109. */
  110. #define LUAI_MAXSTACK 68000
  111. /* test mode uses more stack space */
  112. #undef LUAI_MAXCCALLS
  113. #define LUAI_MAXCCALLS 180
  114. /* force Lua to use its own implementations */
  115. #undef lua_strx2number
  116. #undef lua_number2strx
  117. #endif