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 /* memory-allocator control variables */ 48 typedef struct Memcontrol { 49 int failnext; 50 unsigned long numblocks; 51 unsigned long total; 52 unsigned long maxmem; 53 unsigned long memlimit; 54 unsigned long countlimit; 55 unsigned long objcount[LUA_NUMTYPES]; 56 } Memcontrol; 57 58 LUA_API Memcontrol l_memcontrol; 59 60 61 /* 62 ** generic variable for debug tricks 63 */ 64 extern void *l_Trick; 65 66 67 68 /* 69 ** Function to traverse and check all memory used by Lua 70 */ 71 LUAI_FUNC int lua_checkmemory (lua_State *L); 72 73 /* 74 ** Function to print an object GC-friendly 75 */ 76 struct GCObject; 77 LUAI_FUNC void lua_printobj (lua_State *L, struct GCObject *o); 78 79 80 /* test for lock/unlock */ 81 82 struct L_EXTRA { int lock; int *plock; }; 83 #undef LUA_EXTRASPACE 84 #define LUA_EXTRASPACE sizeof(struct L_EXTRA) 85 #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l)) 86 #define luai_userstateopen(l) \ 87 (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 88 #define luai_userstateclose(l) \ 89 lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock)) 90 #define luai_userstatethread(l,l1) \ 91 lua_assert(getlock(l1)->plock == getlock(l)->plock) 92 #define luai_userstatefree(l,l1) \ 93 lua_assert(getlock(l)->plock == getlock(l1)->plock) 94 #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 95 #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 96 97 98 99 LUA_API int luaB_opentests (lua_State *L); 100 101 LUA_API void *debug_realloc (void *ud, void *block, 102 size_t osize, size_t nsize); 103 104 #if defined(lua_c) 105 #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol) 106 #define luaL_openlibs(L) \ 107 { (luaL_openlibs)(L); \ 108 luaL_requiref(L, "T", luaB_opentests, 1); \ 109 lua_pop(L, 1); } 110 #endif 111 112 113 114 /* change some sizes to give some bugs a chance */ 115 116 #undef LUAL_BUFFERSIZE 117 #define LUAL_BUFFERSIZE 23 118 #define MINSTRTABSIZE 2 119 #define MAXIWTHABS 3 120 121 #define STRCACHE_N 23 122 #define STRCACHE_M 5 123 124 #undef LUAI_USER_ALIGNMENT_T 125 #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; } 126 127 128 /* 129 ** This one is not compatible with tests for opcode optimizations, 130 ** as it blocks some optimizations 131 #define MAXINDEXRK 0 132 */ 133 134 135 /* make stack-overflow tests run faster */ 136 #undef LUAI_MAXSTACK 137 #define LUAI_MAXSTACK 50000 138 139 140 /* test mode uses more stack space */ 141 #undef LUAI_MAXCCALLS 142 #define LUAI_MAXCCALLS 180 143 144 145 /* force Lua to use its own implementations */ 146 #undef lua_strx2number 147 #undef lua_number2strx 148 149 150 #endif 151 152