diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-02-19 15:55:09 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-02-19 15:55:09 -0300 |
| commit | e2b366c7601aeecda04f3b7ac5a2bd6eb80521bb (patch) | |
| tree | 580c94105007087a5029fcb02a0e3cb3be306b54 /lstring.c | |
| parent | fa19baab7ffd96cecb1defe4ad81084c612d2704 (diff) | |
| download | lua-e2b366c7601aeecda04f3b7ac5a2bd6eb80521bb.tar.gz lua-e2b366c7601aeecda04f3b7ac5a2bd6eb80521bb.tar.bz2 lua-e2b366c7601aeecda04f3b7ac5a2bd6eb80521bb.zip | |
userdata with finalizers are kept in a separated list
Diffstat (limited to 'lstring.c')
| -rw-r--r-- | lstring.c | 14 |
1 files changed, 5 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 2.9 2006/07/11 15:53:29 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.10 2007/11/09 18:55:07 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 | */ |
| @@ -32,11 +32,11 @@ void luaS_resize (lua_State *L, int newsize) { | |||
| 32 | for (i=0; i<tb->size; i++) { | 32 | for (i=0; i<tb->size; i++) { |
| 33 | GCObject *p = tb->hash[i]; | 33 | GCObject *p = tb->hash[i]; |
| 34 | while (p) { /* for each node in the list */ | 34 | while (p) { /* for each node in the list */ |
| 35 | GCObject *next = p->gch.next; /* save next */ | 35 | GCObject *next = gch(p)->next; /* save next */ |
| 36 | unsigned int h = gco2ts(p)->hash; | 36 | unsigned int h = gco2ts(p)->hash; |
| 37 | int h1 = lmod(h, newsize); /* new position */ | 37 | int h1 = lmod(h, newsize); /* new position */ |
| 38 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); | 38 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); |
| 39 | p->gch.next = newhash[h1]; /* chain it */ | 39 | gch(p)->next = newhash[h1]; /* chain it */ |
| 40 | newhash[h1] = p; | 40 | newhash[h1] = p; |
| 41 | p = next; | 41 | p = next; |
| 42 | } | 42 | } |
| @@ -80,7 +80,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
| 80 | h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); | 80 | h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); |
| 81 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; | 81 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; |
| 82 | o != NULL; | 82 | o != NULL; |
| 83 | o = o->gch.next) { | 83 | o = gch(o)->next) { |
| 84 | TString *ts = rawgco2ts(o); | 84 | TString *ts = rawgco2ts(o); |
| 85 | if (h == ts->tsv.hash && ts->tsv.len == l && | 85 | if (h == ts->tsv.hash && ts->tsv.len == l && |
| 86 | (memcmp(str, getstr(ts), l) == 0)) { | 86 | (memcmp(str, getstr(ts), l) == 0)) { |
| @@ -98,14 +98,10 @@ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { | |||
| 98 | if (s > MAX_SIZET - sizeof(Udata)) | 98 | if (s > MAX_SIZET - sizeof(Udata)) |
| 99 | luaM_toobig(L); | 99 | luaM_toobig(L); |
| 100 | u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); | 100 | u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); |
| 101 | u->uv.marked = luaC_white(G(L)); /* is not finalized */ | 101 | luaC_link(L, obj2gco(u), LUA_TUSERDATA); |
| 102 | u->uv.tt = LUA_TUSERDATA; | ||
| 103 | u->uv.len = s; | 102 | u->uv.len = s; |
| 104 | u->uv.metatable = NULL; | 103 | u->uv.metatable = NULL; |
| 105 | u->uv.env = e; | 104 | u->uv.env = e; |
| 106 | /* chain it on udata list (after main thread) */ | ||
| 107 | u->uv.next = G(L)->mainthread->next; | ||
| 108 | G(L)->mainthread->next = obj2gco(u); | ||
| 109 | return u; | 105 | return u; |
| 110 | } | 106 | } |
| 111 | 107 | ||
