commit c31d6774ac7db4cfbc548ce507ae65ab6036f873
parent 108e0bdc8495782544c351b17eaae1411a910e89
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 29 Jan 2024 14:28:57 -0300
Details
Diffstat:
7 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/config.lua b/config.lua
@@ -1,4 +0,0 @@
-collectgarbage("setparam", "minormul", 25)
--- collectgarbage("generational")
-
-
diff --git a/lapi.c b/lapi.c
@@ -1262,9 +1262,8 @@ LUA_API int lua_next (lua_State *L, int idx) {
api_checknelems(L, 1);
t = gettable(L, idx);
more = luaH_next(L, t, L->top.p - 1);
- if (more) {
+ if (more)
api_incr_top(L);
- }
else /* no more elements */
L->top.p -= 1; /* remove key */
lua_unlock(L);
diff --git a/lapi.h b/lapi.h
@@ -13,9 +13,8 @@
/* Increments 'L->top.p', checking for stack overflows */
-#define api_incr_top(L) {L->top.p++; \
- api_check(L, L->top.p <= L->ci->top.p, \
- "stack overflow");}
+#define api_incr_top(L) \
+ (L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow"))
/*
diff --git a/lobject.c b/lobject.c
@@ -73,17 +73,29 @@ unsigned int luaO_codeparam (unsigned int p) {
/*
-** Computes 'p' times 'x', where 'p' is a floating-point byte.
+** Computes 'p' times 'x', where 'p' is a floating-point byte. Roughly,
+** we have to multiply 'x' by the mantissa and then shift accordingly to
+** the exponent. If the exponent is positive, both the multiplication
+** and the shift increase 'x', so we have to care only about overflows.
+** For negative exponents, however, multiplying before the shift keeps
+** more significant bits, as long as the multiplication does not
+** overflow, so we check which order is best.
*/
l_obj luaO_applyparam (unsigned int p, l_obj x) {
unsigned int m = p & 0xF; /* mantissa */
int e = (p >> 4); /* exponent */
if (e > 0) { /* normalized? */
- e--;
- m += 0x10; /* maximum 'm' is 0x1F */
+ e--; /* correct exponent */
+ m += 0x10; /* correct mantissa; maximum value is 0x1F */
}
e -= 7; /* correct excess-7 */
- if (e < 0) {
+ if (e >= 0) {
+ if (x < (MAX_LOBJ / 0x1F) >> e) /* no overflow? */
+ return (x * m) << e; /* order doesn't matter here */
+ else /* real overflow */
+ return MAX_LOBJ;
+ }
+ else { /* negative exponent */
e = -e;
if (x < MAX_LOBJ / 0x1F) /* multiplication cannot overflow? */
return (x * m) >> e; /* multiplying first gives more precision */
@@ -92,12 +104,6 @@ l_obj luaO_applyparam (unsigned int p, l_obj x) {
else /* real overflow */
return MAX_LOBJ;
}
- else {
- if (x < (MAX_LOBJ / 0x1F) >> e) /* no overflow? */
- return (x * m) << e; /* order doesn't matter here */
- else /* real overflow */
- return MAX_LOBJ;
- }
}
diff --git a/ltm.c b/ltm.c
@@ -92,10 +92,9 @@ const char *luaT_objtypename (lua_State *L, const TValue *o) {
Table *mt;
if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) ||
(ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) {
- TValue name;
- int hres = luaH_getshortstr(mt, luaS_new(L, "__name"), &name);
- if (hres == HOK && ttisstring(&name)) /* is '__name' a string? */
- return getstr(tsvalue(&name)); /* use it as type name */
+ const TValue *name = luaH_Hgetshortstr(mt, luaS_new(L, "__name"));
+ if (ttisstring(name)) /* is '__name' a string? */
+ return getstr(tsvalue(name)); /* use it as type name */
}
return ttypename(ttype(o)); /* else use standard type name */
}
diff --git a/manual/manual.of b/manual/manual.of
@@ -6473,7 +6473,7 @@ Otherwise, returns the metatable of the given object.
@LibEntry{ipairs (t)|
-Returns three values (an iterator function, the table @id{t}, and 0)
+Returns three values (an iterator function, the value @id{t}, and 0)
so that the construction
@verbatim{
for i,v in ipairs(t) do @rep{body} end
diff --git a/testes/sort.lua b/testes/sort.lua
@@ -13,6 +13,8 @@ do print "testing 'table.create'"
assert(#t == i - 1)
t[i] = 0
end
+ for i = 1, 20 do t[#t + 1] = i * 10 end
+ assert(#t == 40 and t[39] == 190)
assert(not T or T.querytab(t) == 10000)
t = nil
collectgarbage()