summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/llimits.h
diff options
context:
space:
mode:
authorRichard Quirk <richard.quirk@gmail.com>2014-03-19 19:31:31 +0100
committerMarcin Bukat <marcin.bukat@gmail.com>2014-04-02 20:31:54 +0200
commit36378988ad4059982742f05f5eb50580b456840a (patch)
treeee70be810d894566c5e351f21a1ebb79be742a85 /apps/plugins/lua/llimits.h
parent020f16a1c7d5bc9a302671cef03f56ac735e20c5 (diff)
downloadrockbox-36378988ad4059982742f05f5eb50580b456840a.tar.gz
rockbox-36378988ad4059982742f05f5eb50580b456840a.zip
Update lua plugin to 5.2.3
Prior to this patch the Lua plugin used version 5.1.4. This change reduces the number of modifications in the Lua source using some new defines and because the upstream source is now more flexible. Unless otherwise stated, l*.[ch] files are taken unmodified from the upstream lua-5.2.3. fscanf.c: file descriptors in rockbox are just ints, they are hidden behind a void* now so liolib requires less modifications. fscanf is updated to use void* too. getc.c: this is a new file required for getc implementation in lauxlib.c lauxlib.c: LoadF replaced FILE* with int, the rockbox file descriptor int are cast to FILE* (actually void* due to typedef). getc uses the PREFIX version. stdin is not used, as per 5.1.4. lbaselib.c: now uses strspn in the number parsing. print uses DEBUGF now rather than being commented out. lbitlib.c: use the built-in version from 5.2.3 rather than Reuben Thomas's external library. Backwards compatible and adds some new bit operations. ldo.c: the LUAI_THROW/TRY defines are now in the core lua code, so have been removed from rockconf.h liolib.c: here the implementation has changed to use the LStream from the original source, and cast the FILE* pointers to int. This has reduced the number of modifications from the upstream version. llex.c: the only change from upstream is to remove the locale include. lmathlib.c: updated from the 5.2.3 version and re-applied the changes that were made vs 5.1.4 for random numbers and to remove unsupported float functions. loadlib.c: upstream version, with the 5.1.4 changes for missing functions. lobject.c: upstream version, with ctype.h added and sprintf changed to snprintf. loslib.c: upstream version with locale.h removed and 5.1.4 changes for unsupportable functions. lstrlib.c: sprintf changed to snprintf. ltable.c: upstream with the hashnum function from 5.1.4 to avoid frexp in luai_hashnum. luaconf.h: updated to 5.2.3 version, restored relevant parts from the original 5.1.4 configuration. The COMPAT defines that are no longer available are not included. lundump.c: VERSION macro conflicts with the core Rockbox equivalent. rocklib.c: luaL_reg is no longer available, replaced by luaL_Reg equivalent. Moved checkboolean/optboolean functions to this file and out of core lua files. luaL_getn is no longer available, replaced by luaL_rawlen. luaL_register is deprecated, use the newlib/setfuncs replacements. rli_init has to be called before setting up the newlib to avoid overwriting the rb table. rocklib_aux.pl: use rli_checkboolean from rocklib.c. rocklua.c: new default bits library used, update the library loading code with idiomatic 5.2 code. strcspn.c: no longer needed, but strspn.c is required for strspn in lbaselib.c Change-Id: I0c7945c755f79083afe98ec117e1e8cf13de2651 Reviewed-on: http://gerrit.rockbox.org/774 Tested: Richard Quirk <richard.quirk@gmail.com> Reviewed-by: Marcin Bukat <marcin.bukat@gmail.com>
Diffstat (limited to 'apps/plugins/lua/llimits.h')
-rw-r--r--apps/plugins/lua/llimits.h221
1 files changed, 201 insertions, 20 deletions
diff --git a/apps/plugins/lua/llimits.h b/apps/plugins/lua/llimits.h
index a31ad160ad..152dd05515 100644
--- a/apps/plugins/lua/llimits.h
+++ b/apps/plugins/lua/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id$ 2** $Id: llimits.h,v 1.103.1.1 2013/04/12 18:48:47 roberto Exp $
3** Limits, basic types, and some other `installation-dependent' definitions 3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -15,7 +15,7 @@
15#include "lua.h" 15#include "lua.h"
16 16
17 17
18typedef LUAI_UINT32 lu_int32; 18typedef unsigned LUA_INT32 lu_int32;
19 19
20typedef LUAI_UMEM lu_mem; 20typedef LUAI_UMEM lu_mem;
21 21
@@ -31,6 +31,8 @@ typedef unsigned char lu_byte;
31 31
32#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 32#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
33 33
34#define MAX_LMEM ((l_mem) ((MAX_LUMEM >> 1) - 2))
35
34 36
35#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ 37#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
36 38
@@ -44,6 +46,10 @@ typedef unsigned char lu_byte;
44 46
45 47
46/* type to ensure maximum alignment */ 48/* type to ensure maximum alignment */
49#if !defined(LUAI_USER_ALIGNMENT_T)
50#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
51#endif
52
47typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 53typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
48 54
49 55
@@ -52,36 +58,75 @@ typedef LUAI_UACNUMBER l_uacNumber;
52 58
53 59
54/* internal assertions for in-house debugging */ 60/* internal assertions for in-house debugging */
55#ifdef lua_assert 61#if defined(lua_assert)
56
57#define check_exp(c,e) (lua_assert(c), (e)) 62#define check_exp(c,e) (lua_assert(c), (e))
58#define api_check(l,e) lua_assert(e) 63/* to avoid problems with conditions too long */
59 64#define lua_longassert(c) { if (!(c)) lua_assert(0); }
60#else 65#else
61
62#define lua_assert(c) ((void)0) 66#define lua_assert(c) ((void)0)
63#define check_exp(c,e) (e) 67#define check_exp(c,e) (e)
64#define api_check luai_apicheck 68#define lua_longassert(c) ((void)0)
69#endif
65 70
71/*
72** assertion for checking API calls
73*/
74#if !defined(luai_apicheck)
75
76#if defined(LUA_USE_APICHECK)
77#include <assert.h>
78#define luai_apicheck(L,e) assert(e)
79#else
80#define luai_apicheck(L,e) lua_assert(e)
66#endif 81#endif
67 82
83#endif
84
85#define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
86
68 87
69#ifndef UNUSED 88#if !defined(UNUSED)
70#define UNUSED(x) ((void)(x)) /* to avoid warnings */ 89#define UNUSED(x) ((void)(x)) /* to avoid warnings */
71#endif 90#endif
72 91
73 92
74#ifndef cast
75#define cast(t, exp) ((t)(exp)) 93#define cast(t, exp) ((t)(exp))
76#endif
77 94
78#define cast_byte(i) cast(lu_byte, (i)) 95#define cast_byte(i) cast(lu_byte, (i))
79#define cast_num(i) cast(lua_Number, (i)) 96#define cast_num(i) cast(lua_Number, (i))
80#define cast_int(i) cast(int, (i)) 97#define cast_int(i) cast(int, (i))
98#define cast_uchar(i) cast(unsigned char, (i))
99
100
101/*
102** non-return type
103*/
104#if defined(__GNUC__)
105#define l_noret void __attribute__((noreturn))
106#elif defined(_MSC_VER)
107#define l_noret void __declspec(noreturn)
108#else
109#define l_noret void
110#endif
81 111
82 112
83 113
84/* 114/*
115** maximum depth for nested C calls and syntactical nested non-terminals
116** in a program. (Value must fit in an unsigned short int.)
117*/
118#if !defined(LUAI_MAXCCALLS)
119#define LUAI_MAXCCALLS 200
120#endif
121
122/*
123** maximum number of upvalues in a closure (both C and Lua). (Value
124** must fit in an unsigned char.)
125*/
126#define MAXUPVAL UCHAR_MAX
127
128
129/*
85** type for virtual-machine instructions 130** type for virtual-machine instructions
86** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 131** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
87*/ 132*/
@@ -95,34 +140,170 @@ typedef lu_int32 Instruction;
95 140
96 141
97/* minimum size for the string table (must be power of 2) */ 142/* minimum size for the string table (must be power of 2) */
98#ifndef MINSTRTABSIZE 143#if !defined(MINSTRTABSIZE)
99#define MINSTRTABSIZE 32 144#define MINSTRTABSIZE 32
100#endif 145#endif
101 146
102 147
103/* minimum size for string buffer */ 148/* minimum size for string buffer */
104#ifndef LUA_MINBUFFER 149#if !defined(LUA_MINBUFFER)
105#define LUA_MINBUFFER 32 150#define LUA_MINBUFFER 32
106#endif 151#endif
107 152
108 153
109#ifndef lua_lock 154#if !defined(lua_lock)
110#define lua_lock(L) ((void) 0) 155#define lua_lock(L) ((void) 0)
111#define lua_unlock(L) ((void) 0) 156#define lua_unlock(L) ((void) 0)
112#endif 157#endif
113 158
114#ifndef luai_threadyield 159#if !defined(luai_threadyield)
115#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 160#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
116#endif 161#endif
117 162
118 163
119/* 164/*
165** these macros allow user-specific actions on threads when you defined
166** LUAI_EXTRASPACE and need to do something extra when a thread is
167** created/deleted/resumed/yielded.
168*/
169#if !defined(luai_userstateopen)
170#define luai_userstateopen(L) ((void)L)
171#endif
172
173#if !defined(luai_userstateclose)
174#define luai_userstateclose(L) ((void)L)
175#endif
176
177#if !defined(luai_userstatethread)
178#define luai_userstatethread(L,L1) ((void)L)
179#endif
180
181#if !defined(luai_userstatefree)
182#define luai_userstatefree(L,L1) ((void)L)
183#endif
184
185#if !defined(luai_userstateresume)
186#define luai_userstateresume(L,n) ((void)L)
187#endif
188
189#if !defined(luai_userstateyield)
190#define luai_userstateyield(L,n) ((void)L)
191#endif
192
193/*
194** lua_number2int is a macro to convert lua_Number to int.
195** lua_number2integer is a macro to convert lua_Number to lua_Integer.
196** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
197** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
198** luai_hashnum is a macro to hash a lua_Number value into an integer.
199** The hash must be deterministic and give reasonable values for
200** both small and large values (outside the range of integers).
201*/
202
203#if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */
204/* trick with Microsoft assembler for X86 */
205
206#define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
207#define lua_number2integer(i,n) lua_number2int(i, n)
208#define lua_number2unsigned(i,n) \
209 {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
210
211
212#elif defined(LUA_IEEE754TRICK) /* }{ */
213/* the next trick should work on any machine using IEEE754 with
214 a 32-bit int type */
215
216union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
217
218#if !defined(LUA_IEEEENDIAN) /* { */
219#define LUAI_EXTRAIEEE \
220 static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
221#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33)
222#else
223#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN
224#define LUAI_EXTRAIEEE /* empty */
225#endif /* } */
226
227#define lua_number2int32(i,n,t) \
228 { LUAI_EXTRAIEEE \
229 volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
230 (i) = (t)u.l_p[LUA_IEEEENDIANLOC]; }
231
232#define luai_hashnum(i,n) \
233 { volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
234 (i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */
235
236#define lua_number2int(i,n) lua_number2int32(i, n, int)
237#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
238
239/* the trick can be expanded to lua_Integer when it is a 32-bit value */
240#if defined(LUA_IEEELL)
241#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
242#endif
243
244#endif /* } */
245
246
247/* the following definitions always work, but may be slow */
248
249#if !defined(lua_number2int)
250#define lua_number2int(i,n) ((i)=(int)(n))
251#endif
252
253#if !defined(lua_number2integer)
254#define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
255#endif
256
257#if !defined(lua_number2unsigned) /* { */
258/* the following definition assures proper modulo behavior */
259#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_NUMBER_FLOAT)
260#include <math.h>
261#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
262#define lua_number2unsigned(i,n) \
263 ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
264#else
265#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
266#endif
267#endif /* } */
268
269
270#if !defined(lua_unsigned2number)
271/* on several machines, coercion from unsigned to double is slow,
272 so it may be worth to avoid */
273#define lua_unsigned2number(u) \
274 (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
275#endif
276
277
278
279#if defined(ltable_c) && !defined(luai_hashnum)
280
281#include <float.h>
282#include <math.h>
283
284#define luai_hashnum(i,n) { int e; \
285 n = l_mathop(frexp)(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
286 lua_number2int(i, n); i += e; }
287
288#endif
289
290
291
292/*
120** macro to control inclusion of some hard tests on stack reallocation 293** macro to control inclusion of some hard tests on stack reallocation
121*/ 294*/
122#ifndef HARDSTACKTESTS 295#if !defined(HARDSTACKTESTS)
123#define condhardstacktests(x) ((void)0) 296#define condmovestack(L) ((void)0)
297#else
298/* realloc stack keeping its size */
299#define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
300#endif
301
302#if !defined(HARDMEMTESTS)
303#define condchangemem(L) condmovestack(L)
124#else 304#else
125#define condhardstacktests(x) x 305#define condchangemem(L) \
306 ((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1)))
126#endif 307#endif
127 308
128#endif 309#endif