diff options
Diffstat (limited to 'apps/plugins/lua/lstring.c')
-rw-r--r-- | apps/plugins/lua/lstring.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/apps/plugins/lua/lstring.c b/apps/plugins/lua/lstring.c index 49113151cc..bf0536e311 100644 --- a/apps/plugins/lua/lstring.c +++ b/apps/plugins/lua/lstring.c | |||
@@ -2,6 +2,8 @@ | |||
2 | ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ | 2 | ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | ** luaS_newllocstr is adapted from "elua -- pseudo RO strings" | ||
6 | ** by bogdanm, distributed under a MIT license. | ||
5 | */ | 7 | */ |
6 | 8 | ||
7 | 9 | ||
@@ -48,19 +50,26 @@ void luaS_resize (lua_State *L, int newsize) { | |||
48 | 50 | ||
49 | 51 | ||
50 | static TString *newlstr (lua_State *L, const char *str, size_t l, | 52 | static TString *newlstr (lua_State *L, const char *str, size_t l, |
51 | unsigned int h) { | 53 | unsigned int h, char type) { |
52 | TString *ts; | 54 | TString *ts; |
53 | stringtable *tb; | 55 | stringtable *tb; |
54 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) | 56 | if (l > ((MAX_SIZET - sizeof(TString))/sizeof(char)) - sizeof("")) |
55 | luaM_toobig(L); | 57 | luaM_toobig(L); |
56 | ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); | 58 | ts = cast(TString *, luaM_malloc(L, sizetstring(type, l))); |
57 | ts->tsv.len = l; | 59 | ts->tsv.len = l; |
58 | ts->tsv.hash = h; | 60 | ts->tsv.hash = h; |
59 | ts->tsv.marked = luaC_white(G(L)); | 61 | ts->tsv.marked = luaC_white(G(L)); |
62 | if (testbits(type, TSTR_FIXED)) | ||
63 | luaS_fix(ts); | ||
60 | ts->tsv.tt = LUA_TSTRING; | 64 | ts->tsv.tt = LUA_TSTRING; |
61 | ts->tsv.reserved = 0; | 65 | ts->tsv.reserved = 0; |
62 | memcpy(ts+1, str, l*sizeof(char)); | 66 | ts->tsv.type = cast_byte(type); |
63 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ | 67 | if (testbits(type, TSTR_INBIN)) /* ROCKLUA ADDED */ |
68 | *(const char **)(ts+1) = str; /* store a pointer to the string instead */ | ||
69 | else { | ||
70 | memcpy(ts+1, str, l*sizeof(char)); | ||
71 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ | ||
72 | } | ||
64 | tb = &G(L)->strt; | 73 | tb = &G(L)->strt; |
65 | h = lmod(h, tb->size); | 74 | h = lmod(h, tb->size); |
66 | ts->tsv.next = tb->hash[h]; /* chain new entry */ | 75 | ts->tsv.next = tb->hash[h]; /* chain new entry */ |
@@ -72,8 +81,16 @@ static TString *newlstr (lua_State *L, const char *str, size_t l, | |||
72 | } | 81 | } |
73 | 82 | ||
74 | 83 | ||
75 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 84 | TString *luaS_newllocstr (lua_State *L, const char *str, size_t l, char type) { |
76 | GCObject *o; | 85 | GCObject *o; |
86 | if (testbits(type, TSTR_CHKSZ)) | ||
87 | l = strlen(str); | ||
88 | #ifdef INBINARYSTRINGS | ||
89 | else if (!testbits(type, TSTR_ISLIT)) | ||
90 | #else | ||
91 | if (true) | ||
92 | #endif | ||
93 | resetbits(type, TSTR_INBIN); /* only whole strings can be used inbin */ | ||
77 | unsigned int h = cast(unsigned int, l); /* seed */ | 94 | unsigned int h = cast(unsigned int, l); /* seed */ |
78 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ | 95 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ |
79 | size_t l1; | 96 | size_t l1; |
@@ -86,10 +103,12 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
86 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { | 103 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { |
87 | /* string may be dead */ | 104 | /* string may be dead */ |
88 | if (isdead(G(L), o)) changewhite(o); | 105 | if (isdead(G(L), o)) changewhite(o); |
106 | if (testbits(type, TSTR_FIXED)) | ||
107 | luaS_fix(ts); | ||
89 | return ts; | 108 | return ts; |
90 | } | 109 | } |
91 | } | 110 | } |
92 | return newlstr(L, str, l, h); /* not found */ | 111 | return newlstr(L, str, l, h, type); /* not found */ |
93 | } | 112 | } |
94 | 113 | ||
95 | 114 | ||