diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-01-25 19:05:40 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2012-01-25 19:05:40 -0200 |
commit | a4b96ce9a3305ae3585c0bb143fa7342c140f20b (patch) | |
tree | fbb635282c4b72dde25e5c9ffb2bc6d314419d05 /lgc.c | |
parent | 291f564485d8968fc7b0d043dda5ff91a7ce604b (diff) | |
download | lua-a4b96ce9a3305ae3585c0bb143fa7342c140f20b.tar.gz lua-a4b96ce9a3305ae3585c0bb143fa7342c140f20b.tar.bz2 lua-a4b96ce9a3305ae3585c0bb143fa7342c140f20b.zip |
first implementation of long strings
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -65,7 +65,11 @@ | |||
65 | #define white2gray(x) resetbits(gch(x)->marked, WHITEBITS) | 65 | #define white2gray(x) resetbits(gch(x)->marked, WHITEBITS) |
66 | #define black2gray(x) resetbit(gch(x)->marked, BLACKBIT) | 66 | #define black2gray(x) resetbit(gch(x)->marked, BLACKBIT) |
67 | 67 | ||
68 | #define stringmark(s) ((void)((s) && resetbits((s)->tsv.marked, WHITEBITS))) | 68 | /* |
69 | ** dirty trick: we know that 'reallymarkobject' does not use 'g' when | ||
70 | ** object is a string | ||
71 | */ | ||
72 | #define stringmark(s) markobject(NULL, s) | ||
69 | 73 | ||
70 | 74 | ||
71 | #define isfinalized(x) testbit(gch(x)->marked, FINALIZEDBIT) | 75 | #define isfinalized(x) testbit(gch(x)->marked, FINALIZEDBIT) |
@@ -240,18 +244,18 @@ GCObject *luaC_newobj (lua_State *L, int tt, size_t sz, GCObject **list, | |||
240 | 244 | ||
241 | 245 | ||
242 | /* | 246 | /* |
243 | ** mark an object. Userdata and closed upvalues are visited and turned | 247 | ** mark an object. Userdata, strings, and closed upvalues are visited |
244 | ** black here. Strings remain gray (it is the same as making them | 248 | ** and turned black here. Other objects are marked gray and added |
245 | ** black). Other objects are marked gray and added to appropriate list | 249 | ** to appropriate list to be visited (and turned black) later. (Open |
246 | ** to be visited (and turned black) later. (Open upvalues are already | 250 | ** upvalues are already linked in 'headuv' list.) |
247 | ** linked in 'headuv' list.) | ||
248 | */ | 251 | */ |
249 | static void reallymarkobject (global_State *g, GCObject *o) { | 252 | static void reallymarkobject (global_State *g, GCObject *o) { |
250 | lua_assert(iswhite(o) && !isdead(g, o)); | ||
251 | white2gray(o); | 253 | white2gray(o); |
252 | switch (gch(o)->tt) { | 254 | switch (gch(o)->tt) { |
253 | case LUA_TSTRING: { | 255 | case LUA_TSHRSTR: |
254 | return; /* for strings, gray is as good as black */ | 256 | case LUA_TLNGSTR: { |
257 | gray2black(o); | ||
258 | return; /* nothing else to mark */ | ||
255 | } | 259 | } |
256 | case LUA_TUSERDATA: { | 260 | case LUA_TUSERDATA: { |
257 | Table *mt = gco2u(o)->metatable; | 261 | Table *mt = gco2u(o)->metatable; |
@@ -663,8 +667,10 @@ static void freeobj (lua_State *L, GCObject *o) { | |||
663 | case LUA_TTABLE: luaH_free(L, gco2t(o)); break; | 667 | case LUA_TTABLE: luaH_free(L, gco2t(o)); break; |
664 | case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break; | 668 | case LUA_TTHREAD: luaE_freethread(L, gco2th(o)); break; |
665 | case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break; | 669 | case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break; |
666 | case LUA_TSTRING: { | 670 | case LUA_TSHRSTR: |
667 | G(L)->strt.nuse--; | 671 | G(L)->strt.nuse--; |
672 | /* go through */ | ||
673 | case LUA_TLNGSTR: { | ||
668 | luaM_freemem(L, o, sizestring(gco2ts(o))); | 674 | luaM_freemem(L, o, sizestring(gco2ts(o))); |
669 | break; | 675 | break; |
670 | } | 676 | } |