summaryrefslogtreecommitdiff
path: root/community/luaexpat/lua52.patch
blob: 8b418e3a70b6644fcbd57bee369a2defd2483a55 (plain)
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
diff -wbBur luaexpat-1.2.0/config lua-expat-b4e6b167e020/config
--- luaexpat-1.2.0/config	2011-06-03 18:17:04.000000000 +0400
+++ lua-expat-b4e6b167e020/config	2012-07-28 04:59:45.000000000 +0400
@@ -17,8 +17,7 @@
 # (according to Lua 5.1 definition:
 # first version digit * 100 + second version digit
 # e.g. Lua 5.0.2 => 500, Lua 5.1 => 501, Lua 5.1.1 => 501)
-LUA_VERSION_NUM= 500
-COMPAT_DIR= ../compat/src
+LUA_VERSION_NUM= 502
 
 # Compilation parameters
 CWARNS = -Wall -pedantic \
@@ -31,6 +30,6 @@
         -Wshadow \
         -Wwrite-strings
 
-CFLAGS = $(CWARNS) -ansi -O2 -I$(LUA_INC) \
-   -I$(COMPAT_DIR) -I$(EXPAT_INC)
+CFLAGS = $(CWARNS) -ansi -O2 -fPIC -I$(LUA_INC) \
+   -I$(EXPAT_INC)
 CC = gcc
diff -wbBur luaexpat-1.2.0/.hg_archival.txt lua-expat-b4e6b167e020/.hg_archival.txt
--- luaexpat-1.2.0/.hg_archival.txt	2011-06-03 18:17:04.000000000 +0400
+++ lua-expat-b4e6b167e020/.hg_archival.txt	2012-07-28 04:59:45.000000000 +0400
@@ -1,4 +1,5 @@
 repo: 24d141cb2d1e66a1bb42b445f049fcc037972f2b
-node: 30c2491fe44a485caf2dd24643052670c91b91e3
+node: b4e6b167e020ba1bd9402acd0a142ef6e91d912a
 branch: default
-tag: 1.2.0
+latesttag: 1.2.0
+latesttagdistance: 7
diff -wbBur luaexpat-1.2.0/makefile lua-expat-b4e6b167e020/makefile
--- luaexpat-1.2.0/makefile	2011-06-03 18:17:04.000000000 +0400
+++ lua-expat-b4e6b167e020/makefile	2012-07-28 04:59:45.000000000 +0400
@@ -1,22 +1,15 @@
 T= lxp
-V= 1.2.0
+V= 1.3.0
 CONFIG= ./config
 
 include $(CONFIG)
 
-ifeq "$(LUA_VERSION_NUM)" "500"
-COMPAT_O= $(COMPAT_DIR)/compat-5.1.o
-endif
-
-OBJS= src/lxplib.o $(COMPAT_O)
+OBJS= src/lxplib.o
 lib: src/$(LIBNAME)
 
 src/$(LIBNAME) : $(OBJS)
 	export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) -o src/$(LIBNAME) $(LIB_OPTION) $(OBJS) -lexpat
 
-$(COMPAT_DIR)/compat-5.1.o: $(COMPAT_DIR)/compat-5.1.c
-	$(CC) -c $(CFLAGS) -o $@ $(COMPAT_DIR)/compat-5.1.c
-
 install:
 	mkdir -p $(LUA_LIBDIR)
 	cp src/$(LIBNAME) $(LUA_LIBDIR)
diff -wbBur luaexpat-1.2.0/README lua-expat-b4e6b167e020/README
--- luaexpat-1.2.0/README	2011-06-03 18:17:04.000000000 +0400
+++ lua-expat-b4e6b167e020/README	2012-07-28 04:59:45.000000000 +0400
@@ -47,11 +47,11 @@
 
 Credits
 
-Version 1.0 was designed by Roberto Ierusalimschy, André Carregal and Tomás Guisasola
+Version 1.0 was designed by Roberto Ierusalimschy, André Carregal and Tomás Guisasola
 as part of the Kepler Project which holds its copyright. The implementation was coded
 by Roberto Ierusalimschy, based on a previous design by Jay Carlson.
 
-LuaExpat development was sponsored by Fábrica Digital and FINEP.
+LuaExpat development was sponsored by Fábrica Digital and FINEP.
 
 Contact
 
diff -wbBur luaexpat-1.2.0/src/lxp/lom.lua lua-expat-b4e6b167e020/src/lxp/lom.lua
--- luaexpat-1.2.0/src/lxp/lom.lua	2011-06-03 18:17:04.000000000 +0400
+++ lua-expat-b4e6b167e020/src/lxp/lom.lua	2012-07-28 04:59:45.000000000 +0400
@@ -1,13 +1,11 @@
 -- See Copyright Notice in license.html
 -- $Id: lom.lua,v 1.6 2005/06/09 19:18:40 tuler Exp $
 
-require "lxp"
+local lxp = require "lxp"
 
-local tinsert, tremove, getn = table.insert, table.remove, table.getn
+local tinsert, tremove = table.insert, table.remove
 local assert, type, print = assert, type, print
-local lxp = lxp
 
-module ("lxp.lom")
 
 local function starttag (p, tag, attr)
   local stack = p:getcallbacks().stack
@@ -19,14 +17,14 @@
   local stack = p:getcallbacks().stack
   local element = tremove(stack)
   assert(element.tag == tag)
-  local level = getn(stack)
+  local level = #stack
   tinsert(stack[level], element)
 end
 
 local function text (p, txt)
   local stack = p:getcallbacks().stack
-  local element = stack[getn(stack)]
-  local n = getn(element)
+  local element = stack[#stack]
+  local n = #element
   if type(element[n]) == "string" then
     element[n] = element[n] .. txt
   else
@@ -34,7 +32,7 @@
   end
 end
 
-function  parse (o)
+local function parse (o)
   local c = { StartElement = starttag,
               EndElement = endtag,
               CharacterData = text,
@@ -47,7 +45,7 @@
     status, err = p:parse(o)
     if not status then return nil, err end
   else
-    for l in o do
+    for l in pairs(o) do
       status, err = p:parse(l)
       if not status then return nil, err end
     end
@@ -58,3 +56,4 @@
   return c.stack[1][1]
 end
 
+return { parse = parse }
diff -wbBur luaexpat-1.2.0/src/lxplib.c lua-expat-b4e6b167e020/src/lxplib.c
--- luaexpat-1.2.0/src/lxplib.c	2011-06-03 18:17:04.000000000 +0400
+++ lua-expat-b4e6b167e020/src/lxplib.c	2012-07-28 04:59:45.000000000 +0400
@@ -13,14 +13,16 @@
 
 #include "lua.h"
 #include "lauxlib.h"
-#if ! defined (LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
-#include "compat-5.1.h"
-#endif
 
 
 #include "lxplib.h"
 
 
+#if !defined(lua_pushliteral)
+#define lua_pushliteral(L, s)	\
+	lua_pushstring(L, "" s, (sizeof(s)/sizeof(char))-1)
+#endif
+
 
 enum XPState {
   XPSpre,  /* parser just initialized */
@@ -66,7 +68,7 @@
 
 
 static void lxpclose (lua_State *L, lxp_userdata *xpu) {
-  lua_unref(L, xpu->tableref);
+  luaL_unref(L, LUA_REGISTRYINDEX, xpu->tableref);
   xpu->tableref = LUA_REFNIL;
   if (xpu->parser)
     XML_ParserFree(xpu->parser);
@@ -225,7 +227,7 @@
   child->parser = XML_ExternalEntityParserCreate(p, context, NULL);
   if (!child->parser)
     luaL_error(L, "XML_ParserCreate failed");
-  lua_getref(L, xpu->tableref);  /* child uses the same table of its father */
+  lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /*lua_getref(L, xpu->tableref); */ /* child uses the same table of its father */
   child->tableref = luaL_ref(L, LUA_REGISTRYINDEX);
   lua_pushstring(L, base);
   lua_pushstring(L, systemId);
@@ -449,7 +451,7 @@
   xpu->state = XPSok;
   xpu->b = &b;
   lua_settop(L, 2);
-  lua_getref(L, xpu->tableref);  /* to be used by handlers */
+  lua_rawgeti(L, LUA_REGISTRYINDEX, xpu->tableref); /*lua_getref(L, xpu->tableref);*/  /* to be used by handlers */
   status = XML_Parse(xpu->parser, s, (int)len, s == NULL);
   if (xpu->state == XPSstring) dischargestring(xpu);
   if (xpu->state == XPSerror) {  /* callback error? */
@@ -517,7 +519,12 @@
   return 1;
 }
 
-static const struct luaL_reg lxp_meths[] = {
+#if !defined LUA_VERSION_NUM
+/* Lua 5.0 */
+#define luaL_Reg luaL_reg
+#endif
+
+static const struct luaL_Reg lxp_meths[] = {
   {"parse", lxp_parse},
   {"close", lxp_close},
   {"__gc", parser_gc},
@@ -530,7 +537,7 @@
   {NULL, NULL}
 };
 
-static const struct luaL_reg lxp_funcs[] = {
+static const struct luaL_Reg lxp_funcs[] = {
   {"new", lxp_make_parser},
   {NULL, NULL}
 };
@@ -541,19 +548,39 @@
 */
 static void set_info (lua_State *L) {
 	lua_pushliteral (L, "_COPYRIGHT");
-	lua_pushliteral (L, "Copyright (C) 2003-2007 Kepler Project");
+	lua_pushliteral (L, "Copyright (C) 2003-2012 Kepler Project");
 	lua_settable (L, -3);
 	lua_pushliteral (L, "_DESCRIPTION");
 	lua_pushliteral (L, "LuaExpat is a SAX XML parser based on the Expat library");
 	lua_settable (L, -3);
 	lua_pushliteral (L, "_VERSION");
-	lua_pushliteral (L, "LuaExpat 1.2.0");
+	lua_pushliteral (L, "LuaExpat 1.3.0");
 	lua_settable (L, -3);
 }
 
 
+#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
+/*
+** Adapted from Lua 5.2.0
+*/
+static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
+  luaL_checkstack(L, nup, "too many upvalues");
+  for (; l->name != NULL; l++) {  /* fill the table with given functions */
+    int i;
+    for (i = 0; i < nup; i++)  /* copy upvalues to the top */
+      lua_pushvalue(L, -nup);
+    lua_pushstring(L, l->name);
+    lua_pushcclosure(L, l->func, nup);  /* closure with those upvalues */
+    lua_settable(L, -(nup + 3));
+  }
+  lua_pop(L, nup);  /* remove upvalues */
+}
+#endif
+
+
 int luaopen_lxp (lua_State *L) {
   luaL_newmetatable(L, ParserType);
+
   lua_pushliteral(L, "__index");
   lua_pushvalue(L, -2);
   lua_rawset(L, -3);
@@ -557,9 +584,12 @@
   lua_pushliteral(L, "__index");
   lua_pushvalue(L, -2);
   lua_rawset(L, -3);
-  luaL_openlib (L, NULL, lxp_meths, 0);
-  luaL_openlib (L, "lxp", lxp_funcs, 0);
-  set_info (L);
 
+	luaL_setfuncs (L, lxp_meths, 0);
+	lua_pop (L, 1); /* remove metatable */
+
+	lua_newtable (L);
+	luaL_setfuncs (L, lxp_funcs, 0);
+	set_info (L);
   return 1;
 }
diff -wbBur luaexpat-1.2.0/tests/test.lua lua-expat-b4e6b167e020/tests/test.lua
--- luaexpat-1.2.0/tests/test.lua	2011-06-03 18:17:04.000000000 +0400
+++ lua-expat-b4e6b167e020/tests/test.lua	2012-07-28 04:59:45.000000000 +0400
@@ -2,8 +2,14 @@
 -- See Copyright Notice in license.html
 -- $Id: test.lua,v 1.6 2006/06/08 20:34:52 tomas Exp $
 
-require"lxp"
+if string.find(_VERSION, " 5.0") then
+	lxp = assert(loadlib("./lxp.so", "luaopen_lxp"))()
+else
+	lxp = require"lxp"
+	gcinfo = function () return collectgarbage"count" end
+end
 print (lxp._VERSION)
+assert(lxp.new, "Cannot find function lxp.new ("..tostring(lxp.new)..")")
 
 -- basic test with no preamble
 local p = lxp.new{}
@@ -35,9 +41,9 @@
 ]>
 ]]
 
-local X
+X = {}
+if string.find(_VERSION, " 5.0") then
 function getargs (...) X = arg end
-
 function xgetargs (c)
   return function (...)
     table.insert(arg, 1, c)
@@ -44,6 +50,35 @@
     table.insert(X, arg)
   end
 end
+else
+	(loadstring or load)[[
+	function getargs (...)
+		X = { ... }
+		X.n = select('#', ...)
+	end
+	function xgetargs (c)
+	  return function (...)
+	    local arg = { ... }
+	    arg.n = select('#', ...) + 1
+	    table.insert(arg, 1, c)
+	    table.insert(X, arg)
+	  end
+	end
+	table.getn = function (t)
+		if t.n then
+			return t.n
+		else
+			local n = 0
+			for i in pairs(t) do
+				if type(i) == "number" then
+					n = math.max(n, i)
+				end
+			end
+			return n
+		end
+	end]]()
+end
+
 
 
 -------------------------------
@@ -61,7 +96,7 @@
 assert(X.n == 3 and X[1] == p and X[2] == "to")
 x = X[3]
 assert(x.priority=="10" and x.xu=="hi" and x.method=="POST")
-assert(x[1] == "priority" and x[2] == "xu" and table.getn(x) == 2)
+assert(x[1] == "priority" and x[2] == "xu" and table.getn(x) == 2, "x[1] == "..tostring(x[1])..", x[2] == "..tostring(x[2])..", #x == "..tostring(table.getn(x)))
 assert(p:parse("</to>"))
 assert(p:parse())
 p:close()
@@ -95,7 +130,7 @@
 assert(p:parse"<to>")
 assert(p:parse"<![CDATA[hi]]>")
 assert(table.getn(X) == 3)
-assert(X[1][1] == "s" and X[1][2] == p)
+assert(X[1][1] == "s" and X[1][2] == p, "X[1][1] == "..tostring(X[1][1])..", X[1][2] == "..tostring(X[1][2])..", p == "..tostring(p))
 assert(X[2][1] == "c" and X[2][2] == p and X[2][3] == "hi")
 assert(X[3][1] == "e" and X[3][2] == p)
 assert(p:parse"</to>")
@@ -220,7 +255,7 @@
 ]])
 p:close()
 x = X[1]
-assert(x[1] == "sn" and x[3] == "space" and x[4] == "a/namespace" and table.getn(x) == 4)
+assert(x[1] == "sn" and x[3] == "space" and x[4] == "a/namespace" and table.getn(x) == 4, "x[1] == "..tostring(x[1])..", x[3] == "..tostring(x[3])..", x[4] == "..tostring(x[4])..", #x == "..tostring(table.getn(x)))
 x = X[3]
 assert(x[1] == "s" and x[3] == "a/namespace?a")
 x = X[4]
@@ -316,7 +351,7 @@
 local x = gcinfo()
 for i=1,100000 do
   -- due to a small bug in Lua...
-  if math.mod(i, 100) == 0 then collectgarbage() end
+  if (math.mod or math.fmod)(i, 100) == 0 then collectgarbage() end
   lxp.new({})
 end
 collectgarbage(); collectgarbage()