Added lua (lua host bytecode-compiler) to tools/
[openwrt/svn-archive/archive.git] / tools / lua / patches / 030-archindependent-bytecode.patch
1 diff -ur lua-5.1.3-pt2/src/ldump.c lua-5.1.3-pt3/src/ldump.c
2 --- lua-5.1.3-pt2/src/ldump.c 2008-04-05 14:25:13.000000000 +0200
3 +++ lua-5.1.3-pt3/src/ldump.c 2008-04-05 14:28:27.000000000 +0200
4 @@ -67,12 +67,12 @@
5 {
6 if (s==NULL || getstr(s)==NULL)
7 {
8 - size_t size=0;
9 + unsigned int size=0;
10 DumpVar(size,D);
11 }
12 else
13 {
14 - size_t size=s->tsv.len+1; /* include trailing '\0' */
15 + unsigned int size=s->tsv.len+1; /* include trailing '\0' */
16 DumpVar(size,D);
17 DumpBlock(getstr(s),size,D);
18 }
19 diff -ur lua-5.1.3-pt2/src/lundump.c lua-5.1.3-pt3/src/lundump.c
20 --- lua-5.1.3-pt2/src/lundump.c 2008-04-05 14:25:13.000000000 +0200
21 +++ lua-5.1.3-pt3/src/lundump.c 2008-04-05 14:28:27.000000000 +0200
22 @@ -25,6 +25,7 @@
23 ZIO* Z;
24 Mbuffer* b;
25 const char* name;
26 + int swap;
27 } LoadState;
28
29 #ifdef LUAC_TRUST_BINARIES
30 @@ -40,7 +41,6 @@
31 }
32 #endif
33
34 -#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
35 #define LoadByte(S) (lu_byte)LoadChar(S)
36 #define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
37 #define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
38 @@ -52,6 +52,49 @@
39 IF (r!=0, "unexpected end");
40 }
41
42 +static void LoadMem (LoadState* S, void* b, int n, size_t size)
43 +{
44 + LoadBlock(S,b,n*size);
45 + if (S->swap)
46 + {
47 + char* p=(char*) b;
48 + char c;
49 + switch (size)
50 + {
51 + case 1:
52 + break;
53 + case 2:
54 + while (n--)
55 + {
56 + c=p[0]; p[0]=p[1]; p[1]=c;
57 + p+=2;
58 + }
59 + break;
60 + case 4:
61 + while (n--)
62 + {
63 + c=p[0]; p[0]=p[3]; p[3]=c;
64 + c=p[1]; p[1]=p[2]; p[2]=c;
65 + p+=4;
66 + }
67 + break;
68 + case 8:
69 + while (n--)
70 + {
71 + c=p[0]; p[0]=p[7]; p[7]=c;
72 + c=p[1]; p[1]=p[6]; p[6]=c;
73 + c=p[2]; p[2]=p[5]; p[5]=c;
74 + c=p[3]; p[3]=p[4]; p[4]=c;
75 + p+=8;
76 + }
77 + break;
78 + default:
79 + IF(1, "bad size");
80 + break;
81 + }
82 + }
83 +}
84 +
85 static int LoadChar(LoadState* S)
86 {
87 char x;
88 @@ -83,7 +126,7 @@
89
90 static TString* LoadString(LoadState* S)
91 {
92 - size_t size;
93 + unsigned int size;
94 LoadVar(S,size);
95 if (size==0)
96 return NULL;
97 @@ -194,6 +237,7 @@
98 char s[LUAC_HEADERSIZE];
99 luaU_header(h);
100 LoadBlock(S,s,LUAC_HEADERSIZE);
101 + S->swap=(s[6]!=h[6]); s[6]=h[6];
102 IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
103 }
104
105 @@ -228,7 +272,7 @@
106 *h++=(char)LUAC_FORMAT;
107 *h++=(char)*(char*)&x; /* endianness */
108 *h++=(char)sizeof(int);
109 - *h++=(char)sizeof(size_t);
110 + *h++=(char)sizeof(unsigned int);
111 *h++=(char)sizeof(Instruction);
112 *h++=(char)sizeof(lua_Number);
113