immunio 1.1.13 → 1.1.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  /*
2
- ** $Id: lptree.h,v 1.2 2013/03/24 13:51:12 roberto Exp $
2
+ ** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $
3
3
  */
4
4
 
5
5
  #if !defined(lptree_h)
@@ -13,38 +13,43 @@
13
13
  ** types of trees
14
14
  */
15
15
  typedef enum TTag {
16
- TChar = 0, TSet, TAny, /* standard PEG elements */
17
- TTrue, TFalse,
18
- TRep,
19
- TSeq, TChoice,
20
- TNot, TAnd,
21
- TCall,
22
- TOpenCall,
23
- TRule, /* sib1 is rule's pattern, sib2 is 'next' rule */
24
- TGrammar, /* sib1 is initial (and first) rule */
25
- TBehind, /* match behind */
26
- TCapture, /* regular capture */
27
- TRunTime /* run-time capture */
16
+ TChar = 0, /* 'n' = char */
17
+ TSet, /* the set is stored in next CHARSETSIZE bytes */
18
+ TAny,
19
+ TTrue,
20
+ TFalse,
21
+ TRep, /* 'sib1'* */
22
+ TSeq, /* 'sib1' 'sib2' */
23
+ TChoice, /* 'sib1' / 'sib2' */
24
+ TNot, /* !'sib1' */
25
+ TAnd, /* &'sib1' */
26
+ TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */
27
+ TOpenCall, /* ktable[key] is rule's key */
28
+ TRule, /* ktable[key] is rule's key (but key == 0 for unused rules);
29
+ 'sib1' is rule's pattern;
30
+ 'sib2' is next rule; 'cap' is rule's sequential number */
31
+ TGrammar, /* 'sib1' is initial (and first) rule */
32
+ TBehind, /* 'sib1' is pattern, 'n' is how much to go back */
33
+ TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind');
34
+ ktable[key] is Lua value associated with capture;
35
+ 'sib1' is capture body */
36
+ TRunTime /* run-time capture: 'key' is Lua function;
37
+ 'sib1' is capture body */
28
38
  } TTag;
29
39
 
30
- /* number of siblings for each tree */
31
- extern const byte numsiblings[];
32
-
33
40
 
34
41
  /*
35
42
  ** Tree trees
36
- ** The first sibling of a tree (if there is one) is immediately after
37
- ** the tree. A reference to a second sibling (ps) is its position
38
- ** relative to the position of the tree itself. A key in ktable
39
- ** uses the (unique) address of the original tree that created that
40
- ** entry. NULL means no data.
43
+ ** The first child of a tree (if there is one) is immediately after
44
+ ** the tree. A reference to a second child (ps) is its position
45
+ ** relative to the position of the tree itself.
41
46
  */
42
47
  typedef struct TTree {
43
48
  byte tag;
44
49
  byte cap; /* kind of capture (if it is a capture) */
45
50
  unsigned short key; /* key in ktable for Lua data (0 if no key) */
46
51
  union {
47
- int ps; /* occasional second sibling */
52
+ int ps; /* occasional second child */
48
53
  int n; /* occasional counter */
49
54
  } u;
50
55
  } TTree;
@@ -55,16 +60,16 @@ typedef struct TTree {
55
60
  ** its corresponding code
56
61
  */
57
62
  typedef struct Pattern {
58
- union LpegInstruction *code;
63
+ union Instruction *code;
59
64
  int codesize;
60
65
  TTree tree[1];
61
66
  } Pattern;
62
67
 
63
68
 
64
- /* number of siblings for each tree */
69
+ /* number of children for each tree */
65
70
  extern const byte numsiblings[];
66
71
 
67
- /* access to siblings */
72
+ /* access to children */
68
73
  #define sib1(t) ((t) + 1)
69
74
  #define sib2(t) ((t) + (t)->u.ps)
70
75
 
@@ -1,7 +1,7 @@
1
1
  /*
2
- ** $Id: lptypes.h,v 1.10 2014/12/12 17:11:35 roberto Exp $
2
+ ** $Id: lptypes.h,v 1.16 2017/01/13 13:33:17 roberto Exp $
3
3
  ** LPeg - PEG pattern matching for Lua
4
- ** Copyright 2007-2014, Lua.org & PUC-Rio (see 'lpeg.html' for license)
4
+ ** Copyright 2007-2017, Lua.org & PUC-Rio (see 'lpeg.html' for license)
5
5
  ** written by Roberto Ierusalimschy
6
6
  */
7
7
 
@@ -19,7 +19,7 @@
19
19
  #include "lua.h"
20
20
 
21
21
 
22
- #define VERSION "0.12.1"
22
+ #define VERSION "1.0.1"
23
23
 
24
24
 
25
25
  #define PATTERN_T "lpeg-pattern"
@@ -27,37 +27,37 @@
27
27
 
28
28
 
29
29
  /*
30
- ** compatibility with Lua 5.2
30
+ ** compatibility with Lua 5.1
31
31
  */
32
- #if (LUA_VERSION_NUM >= 502)
32
+ #if (LUA_VERSION_NUM == 501)
33
33
 
34
- #undef lua_equal
35
- #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
34
+ #define lp_equal lua_equal
36
35
 
37
- #undef lua_getfenv
38
- #define lua_getfenv lua_getuservalue
39
- #undef lua_setfenv
40
- #define lua_setfenv lua_setuservalue
36
+ #define lua_getuservalue lua_getfenv
37
+ #define lua_setuservalue lua_setfenv
41
38
 
42
- #undef lua_objlen
43
- #define lua_objlen lua_rawlen
39
+ #define lua_rawlen lua_objlen
44
40
 
45
- #undef luaL_register
46
- #define luaL_register(L,n,f) \
47
- { if ((n) == NULL) luaL_setfuncs(L,f,0); else luaL_newlib(L,f); }
41
+ #define luaL_setfuncs(L,f,n) luaL_register(L,NULL,f)
42
+ #define luaL_newlib(L,f) luaL_register(L,"lpeg",f)
48
43
 
49
44
  #endif
50
45
 
51
46
 
47
+ #if !defined(lp_equal)
48
+ #define lp_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
49
+ #endif
50
+
51
+
52
52
  /* default maximum size for call/backtrack stack */
53
53
  #if !defined(MAXBACK)
54
- #define MAXBACK 100
54
+ #define MAXBACK 400
55
55
  #endif
56
56
 
57
57
 
58
- /* maximum number of rules in a grammar */
58
+ /* maximum number of rules in a grammar (limited by 'unsigned char') */
59
59
  #if !defined(MAXRULES)
60
- #define MAXRULES 1000
60
+ #define MAXRULES 250
61
61
  #endif
62
62
 
63
63
 
@@ -111,7 +111,7 @@ typedef struct Charset {
111
111
 
112
112
 
113
113
  /*
114
- ** in capture LpegInstructions, 'kind' of capture and its offset are
114
+ ** in capture instructions, 'kind' of capture and its offset are
115
115
  ** packed in field 'aux', 4 bits for each
116
116
  */
117
117
  #define getkind(op) ((op)->i.aux & 0xF)
@@ -130,14 +130,14 @@ typedef struct Charset {
130
130
  #define MAXPATTSIZE (SHRT_MAX - 10)
131
131
 
132
132
 
133
- /* size (in elements) for an LpegInstruction plus extra l bytes */
134
- #define instsize(l) (((l) + sizeof(LpegInstruction) - 1)/sizeof(LpegInstruction) + 1)
133
+ /* size (in elements) for an instruction plus extra l bytes */
134
+ #define instsize(l) (((l) + sizeof(Instruction) - 1)/sizeof(Instruction) + 1)
135
135
 
136
136
 
137
- /* size (in elements) for a ISet LpegInstruction */
137
+ /* size (in elements) for a ISet instruction */
138
138
  #define CHARSETINSTSIZE instsize(CHARSETSIZE)
139
139
 
140
- /* size (in elements) for a IFunc LpegInstruction */
140
+ /* size (in elements) for a IFunc instruction */
141
141
  #define funcinstsize(p) ((p)->i.aux + 2)
142
142
 
143
143
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- ** $Id: lpvm.c,v 1.5 2013/04/12 16:29:49 roberto Exp $
2
+ ** $Id: lpvm.c,v 1.9 2016/06/03 20:11:18 roberto Exp $
3
3
  ** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license)
4
4
  */
5
5
 
@@ -18,13 +18,13 @@
18
18
 
19
19
  /* initial size for call/backtrack stack */
20
20
  #if !defined(INITBACK)
21
- #define INITBACK 100
21
+ #define INITBACK MAXBACK
22
22
  #endif
23
23
 
24
24
 
25
25
  #define getoffset(p) (((p) + 1)->offset)
26
26
 
27
- static const LpegInstruction giveup = {{IGiveup, 0, 0}};
27
+ static const Instruction giveup = {{IGiveup, 0, 0}};
28
28
 
29
29
 
30
30
  /*
@@ -36,7 +36,7 @@ static const LpegInstruction giveup = {{IGiveup, 0, 0}};
36
36
 
37
37
  typedef struct Stack {
38
38
  const char *s; /* saved position (or NULL for calls) */
39
- const LpegInstruction *p; /* next LpegInstruction */
39
+ const Instruction *p; /* next instruction */
40
40
  int caplevel;
41
41
  } Stack;
42
42
 
@@ -45,14 +45,16 @@ typedef struct Stack {
45
45
 
46
46
 
47
47
  /*
48
- ** Double the size of the array of captures
48
+ ** Make the size of the array of captures 'cap' twice as large as needed
49
+ ** (which is 'captop'). ('n' is the number of new elements.)
49
50
  */
50
- static Capture *doublecap (lua_State *L, Capture *cap, int captop, int ptop) {
51
+ static Capture *doublecap (lua_State *L, Capture *cap, int captop,
52
+ int n, int ptop) {
51
53
  Capture *newc;
52
54
  if (captop >= INT_MAX/((int)sizeof(Capture) * 2))
53
55
  luaL_error(L, "too many captures");
54
56
  newc = (Capture *)lua_newuserdata(L, captop * 2 * sizeof(Capture));
55
- memcpy(newc, cap, captop * sizeof(Capture));
57
+ memcpy(newc, cap, (captop - n) * sizeof(Capture));
56
58
  lua_replace(L, caplistidx(ptop));
57
59
  return newc;
58
60
  }
@@ -70,7 +72,7 @@ static Stack *doublestack (lua_State *L, Stack **stacklimit, int ptop) {
70
72
  max = lua_tointeger(L, -1); /* maximum allowed size */
71
73
  lua_pop(L, 1);
72
74
  if (n >= max) /* already at maximum size? */
73
- luaL_error(L, "too many pending calls/choices");
75
+ luaL_error(L, "backtrack stack overflow (current limit is %d)", max);
74
76
  newn = 2 * n; /* new size */
75
77
  if (newn > max) newn = max;
76
78
  newstack = (Stack *)lua_newuserdata(L, newn * sizeof(Stack));
@@ -113,8 +115,8 @@ static int resdyncaptures (lua_State *L, int fr, int curr, int limit) {
113
115
  */
114
116
  static void adddyncaptures (const char *s, Capture *base, int n, int fd) {
115
117
  int i;
116
- /* Cgroup capture is already there */
117
- assert(base[0].kind == Cgroup && base[0].siz == 0);
118
+ base[0].kind = Cgroup; /* create group capture */
119
+ base[0].siz = 0;
118
120
  base[0].idx = 0; /* make it an anonymous group */
119
121
  for (i = 1; i <= n; i++) { /* add runtime captures */
120
122
  base[i].kind = Cruntime;
@@ -144,23 +146,24 @@ static int removedyncap (lua_State *L, Capture *capture,
144
146
  /*
145
147
  ** Opcode interpreter
146
148
  */
147
- const char *lpeg_match (lua_State *L, const char *o, const char *s, const char *e,
148
- LpegInstruction *op, Capture *capture, int ptop) {
149
+ const char *match (lua_State *L, const char *o, const char *s, const char *e,
150
+ Instruction *op, Capture *capture, int ptop) {
149
151
  Stack stackbase[INITBACK];
150
152
  Stack *stacklimit = stackbase + INITBACK;
151
153
  Stack *stack = stackbase; /* point to first empty slot in stack */
152
154
  int capsize = INITCAPSIZE;
153
155
  int captop = 0; /* point to first empty slot in captures */
154
156
  int ndyncap = 0; /* number of dynamic captures (in Lua stack) */
155
- const LpegInstruction *p = op; /* current LpegInstruction */
157
+ const Instruction *p = op; /* current instruction */
156
158
  stack->p = &giveup; stack->s = s; stack->caplevel = 0; stack++;
157
159
  lua_pushlightuserdata(L, stackbase);
158
160
  for (;;) {
159
161
  #if defined(DEBUG)
162
+ printf("-------------------------------------\n");
163
+ printcaplist(capture, capture + captop);
160
164
  printf("s: |%s| stck:%d, dyncaps:%d, caps:%d ",
161
- s, stack - getstackbase(L, ptop), ndyncap, captop);
165
+ s, (int)(stack - getstackbase(L, ptop)), ndyncap, captop);
162
166
  printinst(op, p);
163
- printcaplist(capture, capture + captop);
164
167
  #endif
165
168
  assert(stackidx(ptop) + ndyncap == lua_gettop(L) && ndyncap <= captop);
166
169
  switch ((Opcode)p->i.code) {
@@ -284,6 +287,9 @@ const char *lpeg_match (lua_State *L, const char *o, const char *s, const char *
284
287
  ndyncap -= removedyncap(L, capture, stack->caplevel, captop);
285
288
  captop = stack->caplevel;
286
289
  p = stack->p;
290
+ #if defined(DEBUG)
291
+ printf("**FAIL**\n");
292
+ #endif
287
293
  continue;
288
294
  }
289
295
  case ICloseRunTime: {
@@ -293,16 +299,19 @@ const char *lpeg_match (lua_State *L, const char *o, const char *s, const char *
293
299
  cs.s = o; cs.L = L; cs.ocap = capture; cs.ptop = ptop;
294
300
  n = runtimecap(&cs, capture + captop, s, &rem); /* call function */
295
301
  captop -= n; /* remove nested captures */
302
+ ndyncap -= rem; /* update number of dynamic captures */
296
303
  fr -= rem; /* 'rem' items were popped from Lua stack */
297
304
  res = resdyncaptures(L, fr, s - o, e - o); /* get result */
298
305
  if (res == -1) /* fail? */
299
306
  goto fail;
300
307
  s = o + res; /* else update current position */
301
308
  n = lua_gettop(L) - fr + 1; /* number of new captures */
302
- ndyncap += n - rem; /* update number of dynamic captures */
309
+ ndyncap += n; /* update number of dynamic captures */
303
310
  if (n > 0) { /* any new capture? */
311
+ if (fr + n >= SHRT_MAX)
312
+ luaL_error(L, "too many results in match-time capture");
304
313
  if ((captop += n + 2) >= capsize) {
305
- capture = doublecap(L, capture, captop, ptop);
314
+ capture = doublecap(L, capture, captop, n + 2, ptop);
306
315
  capsize = 2 * captop;
307
316
  }
308
317
  /* add new captures to 'capture' list */
@@ -339,7 +348,7 @@ const char *lpeg_match (lua_State *L, const char *o, const char *s, const char *
339
348
  capture[captop].idx = p->i.key;
340
349
  capture[captop].kind = getkind(p);
341
350
  if (++captop >= capsize) {
342
- capture = doublecap(L, capture, captop, ptop);
351
+ capture = doublecap(L, capture, captop, 0, ptop);
343
352
  capsize = 2 * captop;
344
353
  }
345
354
  p++;
@@ -8,7 +8,7 @@
8
8
  #include "lpcap.h"
9
9
 
10
10
 
11
- /* Virtual Machine's LpegInstructions */
11
+ /* Virtual Machine's instructions */
12
12
  typedef enum Opcode {
13
13
  IAny, /* if no char, fail */
14
14
  IChar, /* if char != aux, fail */
@@ -38,7 +38,7 @@ typedef enum Opcode {
38
38
 
39
39
 
40
40
 
41
- typedef union LpegInstruction {
41
+ typedef union Instruction {
42
42
  struct Inst {
43
43
  byte code;
44
44
  byte aux;
@@ -46,12 +46,12 @@ typedef union LpegInstruction {
46
46
  } i;
47
47
  int offset;
48
48
  byte buff[1];
49
- } LpegInstruction;
49
+ } Instruction;
50
50
 
51
51
 
52
- void printpatt (LpegInstruction *p, int n);
53
- const char *lpeg_match (lua_State *L, const char *o, const char *s, const char *e,
54
- LpegInstruction *op, Capture *capture, int ptop);
52
+ void printpatt (Instruction *p, int n);
53
+ const char *match (lua_State *L, const char *o, const char *s, const char *e,
54
+ Instruction *op, Capture *capture, int ptop);
55
55
 
56
56
 
57
57
  #endif
@@ -10,7 +10,7 @@
10
10
  </head>
11
11
  <body>
12
12
 
13
- <!-- $Id: re.html,v 1.21 2013/03/28 20:43:30 roberto Exp $ -->
13
+ <!-- $Id: re.html,v 1.24 2016/09/20 17:41:27 roberto Exp $ -->
14
14
 
15
15
  <div id="container">
16
16
 
@@ -296,7 +296,7 @@ it would be useful if each table had
296
296
  a <code>tag</code> field telling what non terminal
297
297
  that table represents.
298
298
  We can add such a tag using
299
- <a href="lpeg.html/#cap-g">named group captures</a>:
299
+ <a href="lpeg.html#cap-g">named group captures</a>:
300
300
  </p>
301
301
  <pre class="example">
302
302
  x = re.compile[[
@@ -406,7 +406,7 @@ of patterns accepted by <code>re</code>.
406
406
  p = [=[
407
407
 
408
408
  pattern &lt;- exp !.
409
- exp &lt;- S (alternative / grammar)
409
+ exp &lt;- S (grammar / alternative)
410
410
 
411
411
  alternative &lt;- seq ('/' S seq)*
412
412
  seq &lt;- prefix*
@@ -450,7 +450,7 @@ print(re.match(p, p)) -- a self description must match itself
450
450
  <h2><a name="license">License</a></h2>
451
451
 
452
452
  <p>
453
- Copyright &copy; 2008-2010 Lua.org, PUC-Rio.
453
+ Copyright &copy; 2008-2015 Lua.org, PUC-Rio.
454
454
  </p>
455
455
  <p>
456
456
  Permission is hereby granted, free of charge,
@@ -488,7 +488,7 @@ THE SOFTWARE.
488
488
 
489
489
  <div id="about">
490
490
  <p><small>
491
- $Id: re.html,v 1.21 2013/03/28 20:43:30 roberto Exp $
491
+ $Id: re.html,v 1.24 2016/09/20 17:41:27 roberto Exp $
492
492
  </small></p>
493
493
  </div> <!-- id="about" -->
494
494
 
@@ -9,6 +9,10 @@
9
9
  #define lib_init_c
10
10
  #define LUA_LIB
11
11
 
12
+ /*
13
+ luaL_openlibs is overridden in ext/all.c.
14
+ This file is commented to prevent duplicated symbols.
15
+
12
16
  #include "lua.h"
13
17
  #include "lauxlib.h"
14
18
  #include "lualib.h"
@@ -16,24 +20,24 @@
16
20
  #include "lj_arch.h"
17
21
 
18
22
  static const luaL_Reg lj_lib_load[] = {
19
- { "", luaopen_base },
20
- { LUA_LOADLIBNAME, luaopen_package },
21
- { LUA_TABLIBNAME, luaopen_table },
22
- { LUA_IOLIBNAME, luaopen_io },
23
- { LUA_OSLIBNAME, luaopen_os },
24
- { LUA_STRLIBNAME, luaopen_string },
25
- { LUA_MATHLIBNAME, luaopen_math },
26
- { LUA_DBLIBNAME, luaopen_debug },
27
- { LUA_BITLIBNAME, luaopen_bit },
28
- { LUA_JITLIBNAME, luaopen_jit },
29
- { NULL, NULL }
23
+ { "", luaopen_base },
24
+ { LUA_LOADLIBNAME, luaopen_package },
25
+ { LUA_TABLIBNAME, luaopen_table },
26
+ { LUA_IOLIBNAME, luaopen_io },
27
+ { LUA_OSLIBNAME, luaopen_os },
28
+ { LUA_STRLIBNAME, luaopen_string },
29
+ { LUA_MATHLIBNAME, luaopen_math },
30
+ { LUA_DBLIBNAME, luaopen_debug },
31
+ { LUA_BITLIBNAME, luaopen_bit },
32
+ { LUA_JITLIBNAME, luaopen_jit },
33
+ { NULL, NULL }
30
34
  };
31
35
 
32
36
  static const luaL_Reg lj_lib_preload[] = {
33
37
  #if LJ_HASFFI
34
- { LUA_FFILIBNAME, luaopen_ffi },
38
+ { LUA_FFILIBNAME, luaopen_ffi },
35
39
  #endif
36
- { NULL, NULL }
40
+ { NULL, NULL }
37
41
  };
38
42
 
39
43
  LUALIB_API void luaL_openlibs(lua_State *L)
@@ -45,11 +49,11 @@ LUALIB_API void luaL_openlibs(lua_State *L)
45
49
  lua_call(L, 1, 0);
46
50
  }
47
51
  luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD",
48
- sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);
52
+ sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1);
49
53
  for (lib = lj_lib_preload; lib->func; lib++) {
50
54
  lua_pushcfunction(L, lib->func);
51
55
  lua_setfield(L, -2, lib->name);
52
56
  }
53
57
  lua_pop(L, 1);
54
58
  }
55
-
59
+ */