diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-03-23 14:12:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2016-03-23 14:12:17 -0300 |
| commit | acff3ad88db13bb6d74170a3db475a4e45ddb51f (patch) | |
| tree | 12ad34c5beebf8c29d0266007dd9a51192eec817 /lstrlib.c | |
| parent | e7b2e01d43d9c3ab6d223daa18eebb94a322e082 (diff) | |
| download | lua-acff3ad88db13bb6d74170a3db475a4e45ddb51f.tar.gz lua-acff3ad88db13bb6d74170a3db475a4e45ddb51f.tar.bz2 lua-acff3ad88db13bb6d74170a3db475a4e45ddb51f.zip | |
bug: 'gmatch' iterator fails when called from a coroutine different
from the one that created it
Diffstat (limited to 'lstrlib.c')
| -rw-r--r-- | lstrlib.c | 9 |
1 files changed, 4 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.239 2015/11/25 16:28:17 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.240 2016/02/25 19:42:55 roberto Exp roberto $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -688,14 +688,13 @@ typedef struct GMatchState { | |||
| 688 | static int gmatch_aux (lua_State *L) { | 688 | static int gmatch_aux (lua_State *L) { |
| 689 | GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3)); | 689 | GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3)); |
| 690 | const char *src; | 690 | const char *src; |
| 691 | gm->ms.L = L; | ||
| 691 | for (src = gm->src; src <= gm->ms.src_end; src++) { | 692 | for (src = gm->src; src <= gm->ms.src_end; src++) { |
| 692 | const char *e; | 693 | const char *e; |
| 693 | reprepstate(&gm->ms); | 694 | reprepstate(&gm->ms); |
| 694 | if ((e = match(&gm->ms, src, gm->p)) != NULL) { | 695 | if ((e = match(&gm->ms, src, gm->p)) != NULL) { |
| 695 | if (e == src) /* empty match? */ | 696 | /* in empty matches, advance at least one position */ |
| 696 | gm->src =src + 1; /* go at least one position */ | 697 | gm->src = (e == src) ? src + 1 : e; |
| 697 | else | ||
| 698 | gm->src = e; | ||
| 699 | return push_captures(&gm->ms, src, e); | 698 | return push_captures(&gm->ms, src, e); |
| 700 | } | 699 | } |
| 701 | } | 700 | } |
