diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
commit | c787dccd9b5c3e55547a2c4bb598c0276de65034 (patch) | |
tree | c4cdf2f7319fee48e048472a2044119f541e8da2 /lstring.c | |
parent | b44e35b773bcaa9891d80a117392911ab5f656e5 (diff) | |
download | lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.gz lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.bz2 lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.zip |
"const" !!!
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.18 1999/02/08 16:28:48 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.19 1999/02/26 15:49:53 roberto Exp roberto $ |
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 | */ | 5 | */ |
@@ -38,7 +38,7 @@ void luaS_init (void) { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | 40 | ||
41 | static unsigned long hash_s (char *s, long l) { | 41 | static unsigned long hash_s (const char *s, long l) { |
42 | unsigned long h = 0; /* seed */ | 42 | unsigned long h = 0; /* seed */ |
43 | while (l--) | 43 | while (l--) |
44 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); | 44 | h = h ^ ((h<<5)+(h>>2)+(unsigned char)*(s++)); |
@@ -83,7 +83,7 @@ static void grow (stringtable *tb) { | |||
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | static TaggedString *newone_s (char *str, long l, unsigned long h) { | 86 | static TaggedString *newone_s (const char *str, long l, unsigned long h) { |
87 | TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l); | 87 | TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l); |
88 | memcpy(ts->str, str, l); | 88 | memcpy(ts->str, str, l); |
89 | ts->str[l] = 0; /* ending 0 */ | 89 | ts->str[l] = 0; /* ending 0 */ |
@@ -97,7 +97,7 @@ static TaggedString *newone_s (char *str, long l, unsigned long h) { | |||
97 | return ts; | 97 | return ts; |
98 | } | 98 | } |
99 | 99 | ||
100 | static TaggedString *newone_u (char *buff, int tag, unsigned long h) { | 100 | static TaggedString *newone_u (void *buff, int tag, unsigned long h) { |
101 | TaggedString *ts = luaM_new(TaggedString); | 101 | TaggedString *ts = luaM_new(TaggedString); |
102 | ts->u.d.v = buff; | 102 | ts->u.d.v = buff; |
103 | ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; | 103 | ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; |
@@ -109,7 +109,7 @@ static TaggedString *newone_u (char *buff, int tag, unsigned long h) { | |||
109 | return ts; | 109 | return ts; |
110 | } | 110 | } |
111 | 111 | ||
112 | static TaggedString *insert_s (char *str, long l, stringtable *tb) { | 112 | static TaggedString *insert_s (const char *str, long l, stringtable *tb) { |
113 | TaggedString *ts; | 113 | TaggedString *ts; |
114 | unsigned long h = hash_s(str, l); | 114 | unsigned long h = hash_s(str, l); |
115 | int size = tb->size; | 115 | int size = tb->size; |
@@ -172,16 +172,16 @@ TaggedString *luaS_createudata (void *udata, int tag) { | |||
172 | return insert_u(udata, tag, &L->string_root[t]); | 172 | return insert_u(udata, tag, &L->string_root[t]); |
173 | } | 173 | } |
174 | 174 | ||
175 | TaggedString *luaS_newlstr (char *str, long l) { | 175 | TaggedString *luaS_newlstr (const char *str, long l) { |
176 | int t = (l==0) ? 0 : ((int)((unsigned char)str[0]*l))%NUM_HASHSTR; | 176 | int t = (l==0) ? 0 : ((int)((unsigned char)str[0]*l))%NUM_HASHSTR; |
177 | return insert_s(str, l, &L->string_root[t]); | 177 | return insert_s(str, l, &L->string_root[t]); |
178 | } | 178 | } |
179 | 179 | ||
180 | TaggedString *luaS_new (char *str) { | 180 | TaggedString *luaS_new (const char *str) { |
181 | return luaS_newlstr(str, strlen(str)); | 181 | return luaS_newlstr(str, strlen(str)); |
182 | } | 182 | } |
183 | 183 | ||
184 | TaggedString *luaS_newfixedstring (char *str) { | 184 | TaggedString *luaS_newfixedstring (const char *str) { |
185 | TaggedString *ts = luaS_new(str); | 185 | TaggedString *ts = luaS_new(str); |
186 | if (ts->head.marked == 0) | 186 | if (ts->head.marked == 0) |
187 | ts->head.marked = 2; /* avoid GC */ | 187 | ts->head.marked = 2; /* avoid GC */ |
@@ -282,7 +282,7 @@ void luaS_rawsetglobal (TaggedString *ts, TObject *newval) { | |||
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | char *luaS_travsymbol (int (*fn)(TObject *)) { | 285 | const char *luaS_travsymbol (int (*fn)(TObject *)) { |
286 | TaggedString *g; | 286 | TaggedString *g; |
287 | for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next) | 287 | for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next) |
288 | if (fn(&g->u.s.globalval)) | 288 | if (fn(&g->u.s.globalval)) |
@@ -291,7 +291,7 @@ char *luaS_travsymbol (int (*fn)(TObject *)) { | |||
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | int luaS_globaldefined (char *name) { | 294 | int luaS_globaldefined (const char *name) { |
295 | TaggedString *ts = luaS_new(name); | 295 | TaggedString *ts = luaS_new(name); |
296 | return ts->u.s.globalval.ttype != LUA_T_NIL; | 296 | return ts->u.s.globalval.ttype != LUA_T_NIL; |
297 | } | 297 | } |