-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrlua.h
More file actions
291 lines (243 loc) · 6.67 KB
/
thrlua.h
File metadata and controls
291 lines (243 loc) · 6.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
* Copyright (c) 2010-2011 Message Systems, Inc. All rights reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MESSAGE SYSTEMS
* The copyright notice above does not evidence any
* actual or intended publication of such source code.
*
* Redistribution of this material is strictly prohibited.
*
*/
#ifndef THRLUA_H
#define THRLUA_H
#define _GNU_SOURCE
#include "luaconf.h"
#define LUA_ASSERTIONS 0
#define USING_DRD 0
#define DEBUG_ALLOC 0
#if HAVE__OPT_MSYS_3RDPARTY_INCLUDE_VALGRIND_VALGRIND_H
#include </opt/msys/3rdParty/include/valgrind/memcheck.h>
#include </opt/msys/3rdParty/include/valgrind/valgrind.h>
#include </opt/msys/3rdParty/include/valgrind/drd.h>
#define HAVE_VALGRIND 1
#elif HAVE__USR_LOCAL_INCLUDE_VALGRIND_VALGRIND_H
#include <valgrind/memcheck.h>
#include <valgrind/valgrind.h>
#include <valgrind/drd.h>
#define HAVE_VALGRIND 1
#endif
#if LUA_ASSERTIONS && HAVE_VALGRIND
struct GCheader;
LUAI_FUNC void lua_assert_fail(const char *expr, struct GCheader *obj, const char *file, int line);
# define lua_assert_obj(expr, __obj) \
((expr) \
? (void) (0) \
: (lua_assert_fail (#expr, __obj, __FILE__, __LINE__), \
(void) (0)))
# define lua_assert(expr) lua_assert_obj(expr, 0)
#elif LUA_ASSERTIONS
# define lua_assert assert
# define lua_assert_obj(expr, __obj) assert(expr)
#else
# define lua_assert(expr) 0
# define lua_assert_obj(expr, __obj) 0
#endif
#ifndef MIN
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
#include <setjmp.h>
#include <locale.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#if defined(LUA_DL_DLOPEN)
#include <dlfcn.h>
#endif
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
struct global_State;
typedef struct global_State global_State;
#include "llimits.h"
#include "lobject.h"
#include "ltable.h"
#include "lzio.h"
#include "llex.h"
#include "lopcodes.h"
#include "lparser.h"
#include "lcode.h"
#include "ltm.h"
#include "lstate.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lstring.h"
#include "lundump.h"
#include "lvm.h"
/* Macros to set values */
static inline void setnilvalue(TValue *obj)
{
obj->tt = LUA_TNIL;
}
static inline void setnvalue(TValue *obj, lua_Number n)
{
obj->tt = LUA_TNUMBER;
obj->value.n = n;
}
static inline void setpvalue(TValue *obj, void *ud)
{
obj->tt = LUA_TLIGHTUSERDATA;
obj->value.p = ud;
}
static inline void setbvalue(TValue *obj, int b)
{
obj->tt = LUA_TBOOLEAN;
obj->value.b = b;
}
#if 0
static inline void setobj(lua_State *L, TValue *obj1, const TValue *obj2)
{
obj1->value = obj2->value;
obj1->tt = obj2->tt;
checkliveness(G(L), obj1);
}
#endif
static inline void setobj(lua_State *L, TValue *obj1, const TValue *obj2)
{
luaC_writebarriervv(L, &L->gch, obj1, obj2);
checkliveness(G(L), obj1);
}
static inline void setsvalue(lua_State *L, TValue *obj, TString *str)
{
luaC_writebarriervo(L, &L->gch, obj, &str->tsv.gch);
checkliveness(G(L), obj);
}
static inline void setuvalue(lua_State *L, TValue *obj, Udata *ud)
{
luaC_writebarriervo(L, &L->gch, obj, &ud->uv.gch);
checkliveness(G(L), obj);
}
static inline void setthvalue(lua_State *L, TValue *obj, lua_State *thr)
{
luaC_writebarriervo(L, &L->gch, obj, &thr->gch);
checkliveness(G(L), obj);
}
static inline void setclvalue(lua_State *L, TValue *obj, Closure *cl)
{
luaC_writebarriervo(L, &L->gch, obj, &cl->gch);
checkliveness(G(L), obj);
}
static inline void sethvalue(lua_State *L, TValue *obj, Table *t)
{
luaC_writebarriervo(L, &L->gch, obj, &t->gch);
checkliveness(G(L), obj);
}
static inline void setptvalue(lua_State *L, TValue *obj, Proto *p)
{
luaC_writebarriervo(L, &L->gch, obj, &p->gch);
checkliveness(G(L), obj);
}
/*
** different types of sets, according to destination
*/
/* from stack to (same) stack */
#define setobjs2s setobj
#define setobj2s setobj
#define setsvalue2s setsvalue
#define sethvalue2s sethvalue
#define setptvalue2s setptvalue
/* from table to same table */
#define setobjt2t setobj
/* to table */
#define setobj2t setobj
/* to new object */
#define setobj2n setobj
#define setsvalue2n setsvalue
static inline void setttype(TValue *obj, lu_byte tt)
{
#if HAVE_VALGRIND && 0
VALGRIND_PRINTF_BACKTRACE("changing type on value %p from %s to %s\n",
obj, lua_typename(NULL, ttype(obj)), lua_typename(NULL, tt));
#endif
ttype(obj) = tt;
}
#define getstr(ts) cast(const char *, ((TString*)ts) + 1)
#define svalue(o) getstr(rawtsvalue(o))
/* chain list of long jump buffers */
struct lua_longjmp {
struct lua_longjmp *previous;
luai_jmpbuf b;
volatile int status; /* error code */
const char *file;
unsigned int line;
};
#if LUA_OS_DARWIN
# define LUA_ASMNAME(x) x
#else
# define LUA_ASMNAME(x) _##x
#endif
#if LUA_ARCH_X86_64
# define lua_do_setjmp LUA_ASMNAME(lua_setjmp_amd64)
# define lua_do_longjmp LUA_ASMNAME(lua_longjmp_amd64)
#elif LUA_ARCH_I386
# define lua_do_setjmp LUA_ASMNAME(lua_setjmp_i386)
# define lua_do_longjmp LUA_ASMNAME(lua_longjmp_i386)
#elif LUA_ARCH_AARCH64
# define lua_do_setjmp LUA_ASMNAME(lua_setjmp_aarch64)
# define lua_do_longjmp LUA_ASMNAME(lua_longjmp_aarch64)
#endif
#ifdef lua_do_setjmp
extern int lua_do_setjmp(luai_jmpbuf env);
extern void lua_do_longjmp(luai_jmpbuf env, int val)
LUA_NORETURN;
#else
# define lua_do_setjmp setjmp
# define lua_do_longjmp longjmp
#endif
/* NOTE: undefined (certainly bad!) behavior will result if the function
* returns from within the TRY/FINALLY block handling */
#define LUAI_TRY_BLOCK(L) do { \
struct lua_longjmp lj; \
lj.status = 0; \
lj.previous = (L)->errorJmp; \
(L)->errorJmp = &lj; \
lj.file = __FILE__; \
lj.line = __LINE__; \
if (lua_do_setjmp(lj.b) == 0) {
#define LUAI_TRY_FINALLY(L) \
}
#define LUAI_TRY_END(L) \
(L)->errorJmp = lj.previous; \
if (lj.status) { \
/* Only log when there is NO outer handler -- that is the \
* dangerous path that hits luaD_throw's panic branch. \
* Normal error propagation (with an outer handler) is \
* high-frequency and must not be logged. */ \
if (!lj.previous) { \
thrlua_log((L), DCRITICAL, \
"LUAI_TRY_END: error status=%d in TRY block at %s:%d, " \
"re-throwing with NO outer handler, L=%p\n", \
lj.status, lj.file, lj.line, (void *)(L)); \
} \
luaD_throw((L), lj.status); \
} \
} while(0)
#define LUAI_TRY_CATCH(L) \
} \
if (lj.status -= lj.status)
#ifdef __cplusplus
extern "C" {
#endif
LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o);
LUAI_FUNC Table *luaA_getcurrenv (lua_State *L);
#ifdef __cplusplus
}
#endif
#endif
/* vim:ts=2:sw=2:et:
*/