Skip to content

Commit

Permalink
c31d6774ac7db4cfbc548ce507ae65ab6036f873
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Feb 25, 2024
1 parent f87aa2f commit 6fec183
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/lapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,9 +1380,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);
Expand Down
5 changes: 2 additions & 3 deletions src/lapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,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"))


/*
Expand Down
26 changes: 16 additions & 10 deletions src/lobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,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 */
Expand All @@ -102,12 +114,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;
}
}


Expand Down
7 changes: 3 additions & 4 deletions src/ltm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
Expand Down
2 changes: 2 additions & 0 deletions testes/sort.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6fec183

Please sign in to comment.