diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-17 13:46:44 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-17 13:46:44 -0200 |
commit | 0bbdddc86b1353fec36ae886b4142986f3c4713f (patch) | |
tree | 9eb933c8123911f9477e8b8b55344035c8077c01 /lstring.c | |
parent | b3b8dfaaea2dba7e7b4b898a5f767a80f36319f1 (diff) | |
download | lua-0bbdddc86b1353fec36ae886b4142986f3c4713f.tar.gz lua-0bbdddc86b1353fec36ae886b4142986f3c4713f.tar.bz2 lua-0bbdddc86b1353fec36ae886b4142986f3c4713f.zip |
allocator function receives the tag of object being allocated in 'osize'
when 'ptr' is NULL.
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.14 2009/12/11 19:14:59 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.15 2009/12/11 21:31:14 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 | */ |
@@ -51,23 +51,22 @@ void luaS_resize (lua_State *L, int newsize) { | |||
51 | 51 | ||
52 | 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, |
53 | unsigned int h) { | 53 | unsigned int h) { |
54 | size_t totalsize; /* total size of TString object */ | ||
55 | GCObject **list; /* (pointer to) list where it will be inserted */ | ||
54 | TString *ts; | 56 | TString *ts; |
55 | stringtable *tb = &G(L)->strt; | 57 | stringtable *tb = &G(L)->strt; |
56 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) | 58 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) |
57 | luaM_toobig(L); | 59 | luaM_toobig(L); |
58 | if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) | 60 | if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) |
59 | luaS_resize(L, tb->size*2); /* too crowded */ | 61 | luaS_resize(L, tb->size*2); /* too crowded */ |
60 | ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); | 62 | totalsize = sizeof(TString) + ((l + 1) * sizeof(char)); |
63 | list = &tb->hash[lmod(h, tb->size)]; | ||
64 | ts = &luaC_newobj(L, LUA_TSTRING, totalsize, list, 0)->ts; | ||
61 | ts->tsv.len = l; | 65 | ts->tsv.len = l; |
62 | ts->tsv.hash = h; | 66 | ts->tsv.hash = h; |
63 | ts->tsv.marked = luaC_white(G(L)); | ||
64 | ts->tsv.tt = LUA_TSTRING; | ||
65 | ts->tsv.reserved = 0; | 67 | ts->tsv.reserved = 0; |
66 | memcpy(ts+1, str, l*sizeof(char)); | 68 | memcpy(ts+1, str, l*sizeof(char)); |
67 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ | 69 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ |
68 | h = lmod(h, tb->size); | ||
69 | ts->tsv.next = tb->hash[h]; /* chain new entry */ | ||
70 | tb->hash[h] = obj2gco(ts); | ||
71 | tb->nuse++; | 70 | tb->nuse++; |
72 | return ts; | 71 | return ts; |
73 | } | 72 | } |
@@ -99,8 +98,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { | |||
99 | Udata *u; | 98 | Udata *u; |
100 | if (s > MAX_SIZET - sizeof(Udata)) | 99 | if (s > MAX_SIZET - sizeof(Udata)) |
101 | luaM_toobig(L); | 100 | luaM_toobig(L); |
102 | u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); | 101 | u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u; |
103 | luaC_link(L, obj2gco(u), LUA_TUSERDATA); | ||
104 | u->uv.len = s; | 102 | u->uv.len = s; |
105 | u->uv.metatable = NULL; | 103 | u->uv.metatable = NULL; |
106 | u->uv.env = e; | 104 | u->uv.env = e; |