diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-28 12:42:04 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-28 12:42:04 -0300 |
| commit | f180822fa6f99a27d3c01bb166af53788681d861 (patch) | |
| tree | b2c05104170cf944058621c229e28698906df572 | |
| parent | 594220c6242072529f27132034619bf0c6dd4474 (diff) | |
| download | lua-f180822fa6f99a27d3c01bb166af53788681d861.tar.gz lua-f180822fa6f99a27d3c01bb166af53788681d861.tar.bz2 lua-f180822fa6f99a27d3c01bb166af53788681d861.zip | |
back to internal table for 'ctype', no more locale manipulation
| -rw-r--r-- | ldo.c | 27 |
1 files changed, 4 insertions, 23 deletions
| @@ -1,11 +1,10 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.96 2011/06/18 17:08:58 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.97 2011/06/20 16:36:03 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | #include <locale.h> | ||
| 9 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 10 | #include <stdlib.h> | 9 | #include <stdlib.h> |
| 11 | #include <string.h> | 10 | #include <string.h> |
| @@ -613,22 +612,8 @@ struct SParser { /* data to `f_parser' */ | |||
| 613 | Mbuffer buff; /* dynamic structure used by the scanner */ | 612 | Mbuffer buff; /* dynamic structure used by the scanner */ |
| 614 | Dyndata dyd; /* dynamic structures used by the parser */ | 613 | Dyndata dyd; /* dynamic structures used by the parser */ |
| 615 | const char *name; | 614 | const char *name; |
| 616 | TString *savedlocale; | ||
| 617 | }; | 615 | }; |
| 618 | 616 | ||
| 619 | |||
| 620 | /* | ||
| 621 | ** save current locale and set locale to "C" for calling the parser | ||
| 622 | */ | ||
| 623 | static Proto *callparser (lua_State *L, struct SParser *p, int c) { | ||
| 624 | const char *oldloc = setlocale(LC_ALL, NULL); /* get current locale */ | ||
| 625 | p->savedlocale = luaS_new(L, oldloc); /* make a copy */ | ||
| 626 | setsvalue2s(L, L->top - 1, p->savedlocale); /* anchor it */ | ||
| 627 | (void)setlocale(LC_ALL, "C"); /* standard locale for parsing Lua files */ | ||
| 628 | return luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); | ||
| 629 | } | ||
| 630 | |||
| 631 | |||
| 632 | static void f_parser (lua_State *L, void *ud) { | 617 | static void f_parser (lua_State *L, void *ud) { |
| 633 | int i; | 618 | int i; |
| 634 | Proto *tf; | 619 | Proto *tf; |
| @@ -636,7 +621,8 @@ static void f_parser (lua_State *L, void *ud) { | |||
| 636 | struct SParser *p = cast(struct SParser *, ud); | 621 | struct SParser *p = cast(struct SParser *, ud); |
| 637 | int c = zgetc(p->z); /* read first character */ | 622 | int c = zgetc(p->z); /* read first character */ |
| 638 | tf = (c == LUA_SIGNATURE[0]) | 623 | tf = (c == LUA_SIGNATURE[0]) |
| 639 | ? luaU_undump(L, p->z, &p->buff, p->name) : callparser(L, p, c); | 624 | ? luaU_undump(L, p->z, &p->buff, p->name) |
| 625 | : luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); | ||
| 640 | setptvalue2s(L, L->top, tf); | 626 | setptvalue2s(L, L->top, tf); |
| 641 | incr_top(L); | 627 | incr_top(L); |
| 642 | cl = luaF_newLclosure(L, tf); | 628 | cl = luaF_newLclosure(L, tf); |
| @@ -649,9 +635,8 @@ static void f_parser (lua_State *L, void *ud) { | |||
| 649 | int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { | 635 | int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { |
| 650 | struct SParser p; | 636 | struct SParser p; |
| 651 | int status; | 637 | int status; |
| 652 | setnilvalue(L->top++); /* reserve space for anchoring locale */ | ||
| 653 | L->nny++; /* cannot yield during parsing */ | 638 | L->nny++; /* cannot yield during parsing */ |
| 654 | p.z = z; p.name = name; p.savedlocale = NULL; | 639 | p.z = z; p.name = name; |
| 655 | p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; | 640 | p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; |
| 656 | p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; | 641 | p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; |
| 657 | p.dyd.label.arr = NULL; p.dyd.label.size = 0; | 642 | p.dyd.label.arr = NULL; p.dyd.label.size = 0; |
| @@ -662,10 +647,6 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { | |||
| 662 | luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); | 647 | luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); |
| 663 | luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size); | 648 | luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size); |
| 664 | L->nny--; | 649 | L->nny--; |
| 665 | if (p.savedlocale) /* locale was changed? */ | ||
| 666 | (void)setlocale(LC_ALL, getstr(p.savedlocale)); /* restore old locale */ | ||
| 667 | setobjs2s(L, L->top - 2, L->top - 1); /* remove reserved space */ | ||
| 668 | --L->top; | ||
| 669 | return status; | 650 | return status; |
| 670 | } | 651 | } |
| 671 | 652 | ||
