ltests.h
Go to the documentation of this file.
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 
27 /* compiled with -O0, Lua uses a lot of C stack space... */
28 #undef LUAI_MAXCSTACK
29 #define LUAI_MAXCSTACK 400
30 
31 /* to avoid warnings, and to make sure value is really unused */
32 #define UNUSED(x) (x=0, (void)(x))
33 
34 
35 /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */
36 #undef l_sprintf
37 #if !defined(LUA_USE_C89)
38 #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i))
39 #else
40 #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i))
41 #endif
42 
43 
44 /* get a chance to test code without jump tables */
45 #define LUA_USE_JUMPTABLE 0
46 
47 
48 /* use 32-bit integers in random generator */
49 #define LUA_RAND32
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 
64 
65 
66 /*
67 ** generic variable for debug tricks
68 */
69 extern void *l_Trick;
70 
71 
72 
73 /*
74 ** Function to traverse and check all memory used by Lua
75 */
77 
78 /*
79 ** Function to print an object GC-friendly
80 */
81 struct GCObject;
82 LUAI_FUNC void lua_printobj (lua_State *L, struct GCObject *o);
83 
84 
85 /* test for lock/unlock */
86 
87 struct L_EXTRA { int lock; int *plock; };
88 #undef LUA_EXTRASPACE
89 #define LUA_EXTRASPACE sizeof(struct L_EXTRA)
90 #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l))
91 #define luai_userstateopen(l) \
92  (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
93 #define luai_userstateclose(l) \
94  lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock))
95 #define luai_userstatethread(l,l1) \
96  lua_assert(getlock(l1)->plock == getlock(l)->plock)
97 #define luai_userstatefree(l,l1) \
98  lua_assert(getlock(l)->plock == getlock(l1)->plock)
99 #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
100 #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
101 
102 
103 
105 
106 LUA_API void *debug_realloc (void *ud, void *block,
107  size_t osize, size_t nsize);
108 
109 #if defined(lua_c)
110 #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
111 #define luaL_openlibs(L) \
112  { (luaL_openlibs)(L); \
113  luaL_requiref(L, "T", luaB_opentests, 1); \
114  lua_pop(L, 1); }
115 #endif
116 
117 
118 
119 /* change some sizes to give some bugs a chance */
120 
121 #undef LUAL_BUFFERSIZE
122 #define LUAL_BUFFERSIZE 23
123 #define MINSTRTABSIZE 2
124 #define MAXIWTHABS 3
125 
126 #define STRCACHE_N 23
127 #define STRCACHE_M 5
128 
129 #undef LUAI_USER_ALIGNMENT_T
130 #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
131 
132 
133 /* make stack-overflow tests run faster */
134 #undef LUAI_MAXSTACK
135 #define LUAI_MAXSTACK 50000
136 
137 
138 /* force Lua to use its own implementations */
139 #undef lua_strx2number
140 #undef lua_number2strx
141 
142 
143 #endif
144 
void * l_Trick
unsigned long memlimit
Definition: ltests.h:58
#define LUAI_FUNC
Definition: luaconf.h:322
unsigned long total
Definition: ltests.h:56
int failnext
Definition: ltests.h:54
LUAI_FUNC int lua_checkmemory(lua_State *L)
LUAI_FUNC void lua_printobj(lua_State *L, struct GCObject *o)
unsigned long countlimit
Definition: ltests.h:59
LUA_API void * debug_realloc(void *ud, void *block, size_t osize, size_t nsize)
#define LUA_API
Definition: luaconf.h:292
static void block(LexState *ls)
Definition: lparser.c:1295
LUA_API int luaB_opentests(lua_State *L)
unsigned long numblocks
Definition: ltests.h:55
#define LUA_NUMTYPES
Definition: lua.h:75
struct Memcontrol Memcontrol
int * plock
Definition: ltests.h:87
unsigned long objcount[LUA_NUMTYPES]
Definition: ltests.h:60
Definition: ltests.h:87
LUA_API Memcontrol l_memcontrol
Definition: ltests.h:63
unsigned long maxmem
Definition: ltests.h:57


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:09