ltests.h (3808B)
1 /* 2 ** $Id: ltests.h $ 3 ** Internal Header for Debugging of the Lua Implementation 4 ** See Copyright Notice in lua.h 5 */ 6 7 #ifndef ltests_h 8 #define ltests_h 9 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 14 /* test Lua with compatibility code */ 15 #define LUA_COMPAT_MATHLIB 16 #define LUA_COMPAT_LT_LE 17 18 19 #define LUA_DEBUG 20 21 22 /* turn on assertions */ 23 #define LUAI_ASSERT 24 25 26 /* to avoid warnings, and to make sure value is really unused */ 27 #define UNUSED(x) (x=0, (void)(x)) 28 29 30 /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */ 31 #undef l_sprintf 32 #if !defined(LUA_USE_C89) 33 #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i)) 34 #else 35 #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i)) 36 #endif 37 38 39 /* get a chance to test code without jump tables */ 40 #define LUA_USE_JUMPTABLE 0 41 42 43 /* use 32-bit integers in random generator */ 44 #define LUA_RAND32 45 46 47 /* test stack reallocation with strict address use */ 48 #define LUAI_STRICT_ADDRESS 1 49 50 51 /* memory-allocator control variables */ 52 typedef struct Memcontrol { 53 int failnext; 54 unsigned long numblocks; 55 unsigned long total; 56 unsigned long maxmem; 57 unsigned long memlimit; 58 unsigned long countlimit; 59 unsigned long objcount[LUA_NUMTYPES]; 60 } Memcontrol; 61 62 LUA_API Memcontrol l_memcontrol; 63 64 65 #define luai_tracegc(L,f) luai_tracegctest(L, f) 66 LUAI_FUNC void luai_tracegctest (lua_State *L, int first); 67 68 69 /* 70 ** generic variable for debug tricks 71 */ 72 extern void *l_Trick; 73 74 75 /* 76 ** Function to traverse and check all memory used by Lua 77 */ 78 LUAI_FUNC int lua_checkmemory (lua_State *L); 79 80 /* 81 ** Function to print an object GC-friendly 82 */ 83 struct GCObject; 84 LUAI_FUNC void lua_printobj (lua_State *L, struct GCObject *o); 85 86 87 /* 88 ** Function to print a value 89 */ 90 struct TValue; 91 LUAI_FUNC void lua_printvalue (struct TValue *v); 92 93 /* 94 ** Function to print the stack 95 */ 96 LUAI_FUNC void lua_printstack (lua_State *L); 97 98 99 /* test for lock/unlock */ 100 101 struct L_EXTRA { int lock; int *plock; }; 102 #undef LUA_EXTRASPACE 103 #define LUA_EXTRASPACE sizeof(struct L_EXTRA) 104 #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l)) 105 #define luai_userstateopen(l) \ 106 (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 107 #define luai_userstateclose(l) \ 108 lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock)) 109 #define luai_userstatethread(l,l1) \ 110 lua_assert(getlock(l1)->plock == getlock(l)->plock) 111 #define luai_userstatefree(l,l1) \ 112 lua_assert(getlock(l)->plock == getlock(l1)->plock) 113 #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 114 #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 115 116 117 118 LUA_API int luaB_opentests (lua_State *L); 119 120 LUA_API void *debug_realloc (void *ud, void *block, 121 size_t osize, size_t nsize); 122 123 #if defined(lua_c) 124 #define luaL_newstate() \ 125 lua_newstate(debug_realloc, &l_memcontrol, luaL_makeseed(NULL)) 126 #define luai_openlibs(L) \ 127 { luaL_openlibs(L); \ 128 luaL_requiref(L, "T", luaB_opentests, 1); \ 129 lua_pop(L, 1); } 130 #endif 131 132 133 134 /* change some sizes to give some bugs a chance */ 135 136 #undef LUAL_BUFFERSIZE 137 #define LUAL_BUFFERSIZE 23 138 #define MINSTRTABSIZE 2 139 #define MAXIWTHABS 3 140 141 #define STRCACHE_N 23 142 #define STRCACHE_M 5 143 144 #undef LUAI_USER_ALIGNMENT_T 145 #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; } 146 147 148 /* 149 ** This one is not compatible with tests for opcode optimizations, 150 ** as it blocks some optimizations 151 #define MAXINDEXRK 0 152 */ 153 154 155 /* 156 ** Reduce maximum stack size to make stack-overflow tests run faster. 157 ** (But value is still large enough to overflow smaller integers.) 158 */ 159 #undef LUAI_MAXSTACK 160 #define LUAI_MAXSTACK 68000 161 162 163 /* test mode uses more stack space */ 164 #undef LUAI_MAXCCALLS 165 #define LUAI_MAXCCALLS 180 166 167 168 /* force Lua to use its own implementations */ 169 #undef lua_strx2number 170 #undef lua_number2strx 171 172 173 #endif 174