aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-04-22 15:00:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-04-22 15:00:37 -0300
commit0ef5cf22891c9d34a88ccc5d89eb0ed82b004471 (patch)
tree1a095acefa978d5a41f32ff7d0fef58a642aa66c
parentfed9408ab51a4be5ff84450ad47d1e0cdaed97bc (diff)
downloadlua-0ef5cf22891c9d34a88ccc5d89eb0ed82b004471.tar.gz
lua-0ef5cf22891c9d34a88ccc5d89eb0ed82b004471.tar.bz2
lua-0ef5cf22891c9d34a88ccc5d89eb0ed82b004471.zip
lock mechanism seperseded by the REFERENCE mechanism.
-rw-r--r--fallback.c70
-rw-r--r--fallback.h8
-rw-r--r--lua.h21
-rw-r--r--luamem.h4
-rw-r--r--manual.tex75
-rw-r--r--mathlib.c8
-rw-r--r--opcode.c46
-rw-r--r--table.c21
-rw-r--r--table.h3
9 files changed, 163 insertions, 93 deletions
diff --git a/fallback.c b/fallback.c
index 8913797f..9d2db515 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_fallback="$Id: fallback.c,v 1.22 1996/03/19 22:28:37 roberto Exp roberto $"; 6char *rcs_fallback="$Id: fallback.c,v 1.23 1996/03/21 16:31:32 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -12,6 +12,7 @@ char *rcs_fallback="$Id: fallback.c,v 1.22 1996/03/19 22:28:37 roberto Exp rober
12#include "fallback.h" 12#include "fallback.h"
13#include "opcode.h" 13#include "opcode.h"
14#include "lua.h" 14#include "lua.h"
15#include "table.h"
15 16
16 17
17static void errorFB (void); 18static void errorFB (void);
@@ -112,59 +113,74 @@ static void funcFB (void)
112 113
113 114
114/* 115/*
115** Lock routines 116** Reference routines
116*/ 117*/
117 118
118static Object *lockArray = NULL; 119static struct ref {
119static int lockSize = 0; 120 Object o;
121 enum {LOCK, HOLD, FREE, COLLECTED} status;
122} *refArray = NULL;
123static int refSize = 0;
120 124
121int luaI_lock (Object *object) 125lua_Reference luaI_ref (Object *object, int lock)
122{ 126{
123 int i; 127 int i;
124 int oldSize; 128 int oldSize;
125 if (tag(object) == LUA_T_NIL) 129 if (tag(object) == LUA_T_NIL)
126 return -1; /* special lock ref for nil */ 130 return -1; /* special ref for nil */
127 for (i=0; i<lockSize; i++) 131 for (i=0; i<refSize; i++)
128 if (tag(&lockArray[i]) == LUA_T_NIL) 132 if (refArray[i].status == FREE)
129 { 133 goto found;
130 lockArray[i] = *object;
131 return i;
132 }
133 /* no more empty spaces */ 134 /* no more empty spaces */
134 oldSize = lockSize; 135 oldSize = refSize;
135 lockSize = growvector(&lockArray, lockSize, Object, lockEM, MAX_WORD); 136 refSize = growvector(&refArray, refSize, struct ref, refEM, MAX_WORD);
136 for (i=oldSize; i<lockSize; i++) 137 for (i=oldSize; i<refSize; i++)
137 tag(&lockArray[i]) = LUA_T_NIL; 138 refArray[i].status = FREE;
138 lockArray[oldSize] = *object; 139 i = oldSize;
139 return oldSize; 140 found:
141 refArray[i].o = *object;
142 refArray[i].status = lock ? LOCK : HOLD;
143 return i;
140} 144}
141 145
142 146
143void lua_unlock (int ref) 147void lua_unref (lua_Reference ref)
144{ 148{
145 if (ref >= 0 && ref < lockSize) 149 if (ref >= 0 && ref < refSize)
146 tag(&lockArray[ref]) = LUA_T_NIL; 150 refArray[ref].status = FREE;
147} 151}
148 152
149 153
150Object *luaI_getlocked (int ref) 154Object *luaI_getref (lua_Reference ref)
151{ 155{
152 static Object nul = {LUA_T_NIL, {0}}; 156 static Object nul = {LUA_T_NIL, {0}};
153 if (ref >= 0 && ref < lockSize) 157 if (ref == -1)
154 return &lockArray[ref];
155 else
156 return &nul; 158 return &nul;
159 if (ref >= 0 && ref < refSize &&
160 (refArray[ref].status == LOCK || refArray[ref].status == HOLD))
161 return &refArray[ref].o;
162 else
163 return NULL;
157} 164}
158 165
159 166
160void luaI_travlock (int (*fn)(Object *)) 167void luaI_travlock (int (*fn)(Object *))
161{ 168{
162 int i; 169 int i;
163 for (i=0; i<lockSize; i++) 170 for (i=0; i<refSize; i++)
164 fn(&lockArray[i]); 171 if (refArray[i].status == LOCK)
172 fn(&refArray[i].o);
165} 173}
166 174
167 175
176void luaI_invalidaterefs (void)
177{
178 int i;
179 for (i=0; i<refSize; i++)
180 if (refArray[i].status == HOLD && !luaI_ismarked(&refArray[i].o))
181 refArray[i].status = COLLECTED;
182}
183
168char *luaI_travfallbacks (int (*fn)(Object *)) 184char *luaI_travfallbacks (int (*fn)(Object *))
169{ 185{
170 int i; 186 int i;
diff --git a/fallback.h b/fallback.h
index 4ea72808..67620406 100644
--- a/fallback.h
+++ b/fallback.h
@@ -1,10 +1,11 @@
1/* 1/*
2** $Id: fallback.h,v 1.10 1995/10/17 11:52:38 roberto Exp roberto $ 2** $Id: fallback.h,v 1.11 1996/01/30 15:25:23 roberto Exp roberto $
3*/ 3*/
4 4
5#ifndef fallback_h 5#ifndef fallback_h
6#define fallback_h 6#define fallback_h
7 7
8#include "lua.h"
8#include "opcode.h" 9#include "opcode.h"
9 10
10extern struct FB { 11extern struct FB {
@@ -26,9 +27,10 @@ extern struct FB {
26#define FB_GETGLOBAL 9 27#define FB_GETGLOBAL 9
27 28
28void luaI_setfallback (void); 29void luaI_setfallback (void);
29int luaI_lock (Object *object); 30lua_Reference luaI_ref (Object *object, int lock);
30Object *luaI_getlocked (int ref); 31Object *luaI_getref (lua_Reference ref);
31void luaI_travlock (int (*fn)(Object *)); 32void luaI_travlock (int (*fn)(Object *));
33void luaI_invalidaterefs (void);
32char *luaI_travfallbacks (int (*fn)(Object *)); 34char *luaI_travfallbacks (int (*fn)(Object *));
33 35
34#endif 36#endif
diff --git a/lua.h b/lua.h
index 32cfac31..5738a619 100644
--- a/lua.h
+++ b/lua.h
@@ -2,7 +2,7 @@
2** LUA - Linguagem para Usuarios de Aplicacao 2** LUA - Linguagem para Usuarios de Aplicacao
3** Grupo de Tecnologia em Computacao Grafica 3** Grupo de Tecnologia em Computacao Grafica
4** TeCGraf - PUC-Rio 4** TeCGraf - PUC-Rio
5** $Id: lua.h,v 3.24 1996/03/19 22:28:37 roberto Exp roberto $ 5** $Id: lua.h,v 3.25 1996/03/21 21:30:29 roberto Exp roberto $
6*/ 6*/
7 7
8 8
@@ -80,17 +80,20 @@ lua_Object lua_getsubscript (void);
80 80
81int lua_type (lua_Object object); 81int lua_type (lua_Object object);
82 82
83int lua_lock (void); 83
84lua_Object lua_getlocked (int ref); 84typedef int lua_Reference;
85void lua_pushlocked (int ref); 85
86void lua_unlock (int ref); 86lua_Reference lua_ref (int lock);
87lua_Object lua_getref (lua_Reference ref);
88void lua_pushref (lua_Reference ref);
89void lua_unref (lua_Reference ref);
87 90
88lua_Object lua_createtable (void); 91lua_Object lua_createtable (void);
89 92
90 93
91/* some useful macros */ 94/* some useful macros */
92 95
93#define lua_lockobject(o) (lua_pushobject(o), lua_lock()) 96#define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l))
94 97
95#define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) 98#define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n))
96 99
@@ -99,6 +102,12 @@ lua_Object lua_createtable (void);
99 102
100/* for compatibility with old versions. Avoid using these macros */ 103/* for compatibility with old versions. Avoid using these macros */
101 104
105#define lua_lockobject(o) lua_refobject(o,1)
106#define lua_lock() lua_ref(1)
107#define lua_getlocked lua_getref
108#define lua_pushlocked lua_pushref
109#define lua_unlock lua_unref
110
102#define lua_pushliteral(o) lua_pushstring(o) 111#define lua_pushliteral(o) lua_pushstring(o)
103 112
104#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) 113#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript())
diff --git a/luamem.h b/luamem.h
index d22cc200..29d3a708 100644
--- a/luamem.h
+++ b/luamem.h
@@ -1,7 +1,7 @@
1/* 1/*
2** mem.c 2** mem.c
3** memory manager for lua 3** memory manager for lua
4** $Id: mem.h,v 1.5 1996/03/21 16:31:32 roberto Exp roberto $ 4** $Id: mem.h,v 1.6 1996/03/21 18:54:29 roberto Exp roberto $
5*/ 5*/
6 6
7#ifndef mem_h 7#ifndef mem_h
@@ -18,7 +18,7 @@
18#define constantEM "constant table overflow" 18#define constantEM "constant table overflow"
19#define stackEM "stack size overflow" 19#define stackEM "stack size overflow"
20#define lexEM "lex buffer overflow" 20#define lexEM "lex buffer overflow"
21#define lockEM "lock table overflow" 21#define refEM "reference table overflow"
22#define tableEM "table overflow" 22#define tableEM "table overflow"
23#define memEM "not enough memory" 23#define memEM "not enough memory"
24 24
diff --git a/manual.tex b/manual.tex
index 5a179cd0..539385a6 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.14 1996/03/20 18:44:02 roberto Exp roberto $ 1% $Id: manual.tex,v 1.15 1996/04/01 14:36:35 roberto Exp roberto $
2 2
3\documentstyle[fullpage,11pt,bnf]{article} 3\documentstyle[fullpage,11pt,bnf]{article}
4 4
@@ -34,7 +34,7 @@ Waldemar Celes Filho
34\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio 34\tecgraf\ --- Departamento de Inform\'atica --- PUC-Rio
35} 35}
36 36
37\date{\small \verb$Date: 1996/03/20 18:44:02 $} 37\date{\small \verb$Date: 1996/04/01 14:36:35 $}
38 38
39\maketitle 39\maketitle
40 40
@@ -739,7 +739,7 @@ The API functions can be classified in the following categories:
739\item manipulating (reading and writing) Lua objects; 739\item manipulating (reading and writing) Lua objects;
740\item calling Lua functions; 740\item calling Lua functions;
741\item C functions to be called by Lua; 741\item C functions to be called by Lua;
742\item locking Lua Objects. 742\item references to Lua Objects.
743\end{enumerate} 743\end{enumerate}
744All API functions are declared in the file \verb'lua.h'. 744All API functions are declared in the file \verb'lua.h'.
745 745
@@ -1069,30 +1069,39 @@ many results.
1069Section~\ref{exCFunction} presents an example of a CFunction. 1069Section~\ref{exCFunction} presents an example of a CFunction.
1070 1070
1071 1071
1072\subsection{Locking Lua Objects} 1072\subsection{References to Lua Objects}
1073 1073
1074As already noted, \verb'lua_Object's are volatile. 1074As already noted, \verb'lua_Object's are volatile.
1075If the C code needs to keep a \verb'lua_Object' 1075If the C code needs to keep a \verb'lua_Object'
1076outside block boundaries, 1076outside block boundaries,
1077it has to {\em lock} the object. 1077it must create a \Def{reference} to the object.
1078The routines to manipulate locking are the following: 1078The routines to manipulate references are the following:
1079\Deffunc{lua_lock}\Deffunc{lua_getlocked} 1079\Deffunc{lua_ref}\Deffunc{lua_getref}
1080\Deffunc{lua_pushlocked}\Deffunc{lua_unlock} 1080\Deffunc{lua_pushref}\Deffunc{lua_unref}
1081\begin{verbatim} 1081\begin{verbatim}
1082int lua_lock (void); 1082typedef int lua_Reference;
1083lua_Object lua_getlocked (int ref); 1083
1084void lua_pushlocked (int ref); 1084lua_Reference lua_ref (int lock);
1085void lua_unlock (int ref); 1085lua_Object lua_getref (lua_Reference ref);
1086\end{verbatim} 1086void lua_pushref (lua_Reference ref);
1087The function \verb'lua_lock' locks the object 1087void lua_unref (lua_Reference ref);
1088which is on the top of the stack, 1088\end{verbatim}
1089and returns a reference to it. 1089The function \verb'lua_ref' creates a reference
1090Whenever the locked object is needed, 1090to the object which is on the top of the stack,
1091a call to \verb'lua_getlocked' 1091and returns this reference.
1092If \verb'lock' is true, the object is {\em locked}:
1093that means the object will not be garbage collected.
1094Notice that an unlocked reference may be garbage collected.
1095Whenever the referenced object is needed,
1096a call to \verb'lua_getref'
1092returns a handle to it, 1097returns a handle to it,
1093while \verb'lua_pushlocked' pushes the handle on the stack. 1098while \verb'lua_pushref' pushes the object on the stack.
1094When a locked object is no longer needed, 1099If the object has been collected,
1095it can be unlocked with a call to \verb'lua_unlock'. 1100\verb'lua_getref' returns \verb'LUA_NOOBJECT',
1101and \verb'lua_pushobject' issues an error.
1102
1103When a reference is no longer needed,
1104it can be freed with a call to \verb'lua_unref'.
1096 1105
1097 1106
1098 1107
@@ -1839,12 +1848,14 @@ as illustrated in Figure~\ref{Cinher}.
1839\begin{figure} 1848\begin{figure}
1840\Line 1849\Line
1841\begin{verbatim} 1850\begin{verbatim}
1842int lockedParentName; /* stores the lock index for the string "parent" */ 1851#include "lua.h"
1843int lockedOldIndex; /* previous fallback function */ 1852
1853lua_Reference lockedParentName; /* lock index for the string "parent" */
1854lua_Reference lockedOldIndex; /* previous fallback function */
1844 1855
1845void callOldFallback (lua_Object table, lua_Object index) 1856void callOldFallback (lua_Object table, lua_Object index)
1846{ 1857{
1847 lua_Object oldIndex = lua_getlocked(lockedOldIndex); 1858 lua_Object oldIndex = lua_getref(lockedOldIndex);
1848 lua_pushobject(table); 1859 lua_pushobject(table);
1849 lua_pushobject(index); 1860 lua_pushobject(index);
1850 lua_callfunction(oldIndex); 1861 lua_callfunction(oldIndex);
@@ -1861,7 +1872,7 @@ void Index (void)
1861 return; 1872 return;
1862 } 1873 }
1863 lua_pushobject(table); 1874 lua_pushobject(table);
1864 lua_pushlocked(lockedParentName); 1875 lua_pushref(lockedParentName);
1865 parent = lua_getsubscript(); 1876 parent = lua_getsubscript();
1866 if (lua_istable(parent)) 1877 if (lua_istable(parent))
1867 { 1878 {
@@ -1880,9 +1891,9 @@ void Index (void)
1880This code must be registered with: 1891This code must be registered with:
1881\begin{verbatim} 1892\begin{verbatim}
1882 lua_pushstring("parent"); 1893 lua_pushstring("parent");
1883 lockedParentName = lua_lock(); 1894 lockedParentName = lua_ref(1);
1884 lua_pushobject(lua_setfallback("index", Index)); 1895 lua_pushobject(lua_setfallback("index", Index));
1885 lockedOldIndex = lua_lock(); 1896 lockedOldIndex = lua_ref(1);
1886\end{verbatim} 1897\end{verbatim}
1887Notice how the string \verb'"parent"' is kept 1898Notice how the string \verb'"parent"' is kept
1888locked in Lua for optimal performance. 1899locked in Lua for optimal performance.
@@ -1892,6 +1903,9 @@ There are many different ways to do object-oriented programming in Lua.
1892This section presents one possible way to 1903This section presents one possible way to
1893implement classes, 1904implement classes,
1894using the inheritance mechanism presented above. 1905using the inheritance mechanism presented above.
1906{\em Please notice: the following examples only work
1907with the index fallback redefined according to
1908Section~\ref{exfallback}}.
1895 1909
1896As one could expect, a good way to represent a class is 1910As one could expect, a good way to represent a class is
1897as a table. 1911as a table.
@@ -2079,9 +2093,12 @@ have been superseded by the new version of function \verb'date'.
2079Function \verb'int2str' (from \verb'strlib') has been superseded by new 2093Function \verb'int2str' (from \verb'strlib') has been superseded by new
2080function \verb'format', with parameter \verb'"%c"'. 2094function \verb'format', with parameter \verb'"%c"'.
2081\item 2095\item
2096The lock mechanism has been superseded by the reference mechanism.
2097However, \verb-lua.h- provides compatibility macros,
2098so there is no need to change programs.
2099\item
2082API function \verb'lua_pushliteral' now is just a macro to 2100API function \verb'lua_pushliteral' now is just a macro to
2083\verb'lua_pushstring'. 2101\verb'lua_pushstring'.
2084Programmers are encouraged not to use this macro.
2085\end{itemize} 2102\end{itemize}
2086 2103
2087\subsection*{Incompatibilities with \Index{version 2.1}} 2104\subsection*{Incompatibilities with \Index{version 2.1}}
diff --git a/mathlib.c b/mathlib.c
index cf5b6a8a..efc887b8 100644
--- a/mathlib.c
+++ b/mathlib.c
@@ -3,7 +3,7 @@
3** Mathematics library to LUA 3** Mathematics library to LUA
4*/ 4*/
5 5
6char *rcs_mathlib="$Id: mathlib.c,v 1.13 1995/11/10 17:54:31 roberto Exp roberto $"; 6char *rcs_mathlib="$Id: mathlib.c,v 1.14 1996/02/09 17:21:27 roberto Exp roberto $";
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <math.h> 9#include <math.h>
@@ -104,7 +104,7 @@ static void math_sqrt (void)
104 lua_pushnumber (sqrt(d)); 104 lua_pushnumber (sqrt(d));
105} 105}
106 106
107static int old_pow; 107static lua_Reference old_pow;
108 108
109static void math_pow (void) 109static void math_pow (void)
110{ 110{
@@ -113,7 +113,7 @@ static void math_pow (void)
113 lua_Object op = lua_getparam(3); 113 lua_Object op = lua_getparam(3);
114 if (!lua_isnumber(o1) || !lua_isnumber(o2) || *(lua_getstring(op)) != 'p') 114 if (!lua_isnumber(o1) || !lua_isnumber(o2) || *(lua_getstring(op)) != 'p')
115 { 115 {
116 lua_Object old = lua_getlocked(old_pow); 116 lua_Object old = lua_getref(old_pow);
117 lua_pushobject(o1); 117 lua_pushobject(o1);
118 lua_pushobject(o2); 118 lua_pushobject(o2);
119 lua_pushobject(op); 119 lua_pushobject(op);
@@ -223,5 +223,5 @@ void mathlib_open (void)
223 lua_register ("random", math_random); 223 lua_register ("random", math_random);
224 lua_register ("randomseed", math_randomseed); 224 lua_register ("randomseed", math_randomseed);
225 225
226 old_pow = lua_lockobject(lua_setfallback("arith", math_pow)); 226 old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1);
227} 227}
diff --git a/opcode.c b/opcode.c
index ffa1c844..c2437a56 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.65 1996/03/21 18:55:02 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.66 1996/03/22 19:12:15 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -717,27 +717,31 @@ void *lua_getuserdata (lua_Object object)
717} 717}
718 718
719 719
720lua_Object lua_getlocked (int ref) 720lua_Object lua_getref (lua_Reference ref)
721{ 721{
722 adjustC(0); 722 Object *o = luaI_getref(ref);
723 *top = *luaI_getlocked(ref); 723 if (o == NULL)
724 incr_top; 724 return LUA_NOOBJECT;
725 CBase++; /* incorporate object in the stack */ 725 adjustC(0);
726 return Ref(top-1); 726 luaI_pushobject(o);
727 CBase++; /* incorporate object in the stack */
728 return Ref(top-1);
727} 729}
728 730
729 731
730void lua_pushlocked (int ref) 732void lua_pushref (lua_Reference ref)
731{ 733{
732 *top = *luaI_getlocked(ref); 734 Object *o = luaI_getref(ref);
733 incr_top; 735 if (o == NULL)
736 lua_error("access to invalid (possibly garbage collected) reference");
737 luaI_pushobject(o);
734} 738}
735 739
736 740
737int lua_lock (void) 741lua_Reference lua_ref (int lock)
738{ 742{
739 adjustC(1); 743 adjustC(1);
740 return luaI_lock(--top); 744 return luaI_ref(--top, lock);
741} 745}
742 746
743 747
@@ -812,27 +816,29 @@ void lua_pushcfunction (lua_CFunction fn)
812*/ 816*/
813void lua_pushusertag (void *u, int tag) 817void lua_pushusertag (void *u, int tag)
814{ 818{
815 if (tag < LUA_T_USERDATA) return; 819 if (tag < LUA_T_USERDATA)
820 lua_error("invalid tag in `lua_pushusertag'");
816 tag(top) = tag; uvalue(top) = u; 821 tag(top) = tag; uvalue(top) = u;
817 incr_top; 822 incr_top;
818} 823}
819 824
820/* 825/*
821** Push a lua_Object to stack. 826** Push an object on the stack.
822*/ 827*/
823void lua_pushobject (lua_Object o) 828void luaI_pushobject (Object *o)
824{ 829{
825 *top = *Address(o); 830 *top = *o;
826 incr_top; 831 incr_top;
827} 832}
828 833
829/* 834/*
830** Push an object on the stack. 835** Push a lua_Object on stack.
831*/ 836*/
832void luaI_pushobject (Object *o) 837void lua_pushobject (lua_Object o)
833{ 838{
834 *top = *o; 839 if (o == LUA_NOOBJECT)
835 incr_top; 840 lua_error("attempt to push a NOOBJECT");
841 luaI_pushobject(Address(o));
836} 842}
837 843
838int lua_type (lua_Object o) 844int lua_type (lua_Object o)
diff --git a/table.c b/table.c
index 6c77d2e9..31ec0ac1 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.50 1996/03/21 16:31:32 roberto Exp roberto $"; 6char *rcs_table="$Id: table.c,v 2.51 1996/03/21 18:54:29 roberto Exp roberto $";
7 7
8#include "mem.h" 8#include "mem.h"
9#include "opcode.h" 9#include "opcode.h"
@@ -170,6 +170,24 @@ int lua_markobject (Object *o)
170 return 0; 170 return 0;
171} 171}
172 172
173/*
174* returns 0 if the object is going to be (garbage) collected
175*/
176int luaI_ismarked (Object *o)
177{
178 switch (o->tag)
179 {
180 case LUA_T_STRING:
181 return o->value.ts->marked;
182 case LUA_T_FUNCTION:
183 return o->value.tf->marked;
184 case LUA_T_ARRAY:
185 return o->value.a->mark;
186 default: /* nil, number, cfunction, or user data */
187 return 1;
188 }
189}
190
173 191
174/* 192/*
175** Garbage collection. 193** Garbage collection.
@@ -182,6 +200,7 @@ Long luaI_collectgarbage (void)
182 lua_travsymbol(lua_markobject); /* mark symbol table objects */ 200 lua_travsymbol(lua_markobject); /* mark symbol table objects */
183 luaI_travlock(lua_markobject); /* mark locked objects */ 201 luaI_travlock(lua_markobject); /* mark locked objects */
184 luaI_travfallbacks(lua_markobject); /* mark fallbacks */ 202 luaI_travfallbacks(lua_markobject); /* mark fallbacks */
203 luaI_invalidaterefs();
185 recovered += lua_strcollector(); 204 recovered += lua_strcollector();
186 recovered += lua_hashcollector(); 205 recovered += lua_hashcollector();
187 recovered += luaI_funccollector(); 206 recovered += luaI_funccollector();
diff --git a/table.h b/table.h
index de942458..bfe1a6be 100644
--- a/table.h
+++ b/table.h
@@ -1,7 +1,7 @@
1/* 1/*
2** Module to control static tables 2** Module to control static tables
3** TeCGraf - PUC-Rio 3** TeCGraf - PUC-Rio
4** $Id: table.h,v 2.19 1996/02/26 21:00:27 roberto Exp roberto $ 4** $Id: table.h,v 2.20 1996/03/14 15:57:19 roberto Exp roberto $
5*/ 5*/
6 6
7#ifndef table_h 7#ifndef table_h
@@ -30,6 +30,7 @@ Word luaI_findconstant (TaggedString *t);
30Word luaI_findconstantbyname (char *name); 30Word luaI_findconstantbyname (char *name);
31TaggedString *luaI_createfixedstring (char *str); 31TaggedString *luaI_createfixedstring (char *str);
32int lua_markobject (Object *o); 32int lua_markobject (Object *o);
33int luaI_ismarked (Object *o);
33Long luaI_collectgarbage (void); 34Long luaI_collectgarbage (void);
34void lua_pack (void); 35void lua_pack (void);
35 36