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