ltests.h 3.5 KB

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