Eliminate LuaStack::rawgeti, it's not safe
This commit is contained in:
@@ -244,11 +244,11 @@ LuaDefine(deque_create, "c") {
|
||||
LuaStack LS(L, rdeque, classobj);
|
||||
const int imax = 4;
|
||||
LS.createtable(rdeque, DEQUE_BASE + imax - 1, 0);
|
||||
LS.rawseti(rdeque, DEQUE_LEFT, 0);
|
||||
LS.rawseti(rdeque, DEQUE_FILL, 0);
|
||||
LS.rawseti(rdeque, DEQUE_MAX, imax);
|
||||
LS.rawset(rdeque, DEQUE_LEFT, 0);
|
||||
LS.rawset(rdeque, DEQUE_FILL, 0);
|
||||
LS.rawset(rdeque, DEQUE_MAX, imax);
|
||||
for (int i = 0; i < imax; i++) {
|
||||
LS.rawseti(rdeque, DEQUE_BASE + i, 0);
|
||||
LS.rawset(rdeque, DEQUE_BASE + i, 0);
|
||||
}
|
||||
LS.makeclass(classobj, "deque");
|
||||
LS.setmetatable(rdeque, classobj);
|
||||
@@ -262,7 +262,7 @@ LuaDefine(deque_pushl, "c") {
|
||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||
max = deque_make_room(L, deque.index(), left, fill, max);
|
||||
int target = (left - 1) & (max-1);
|
||||
LS.rawseti(deque, DEQUE_BASE + target, elt);
|
||||
LS.rawset(deque, DEQUE_BASE + target, elt);
|
||||
fill += 1;
|
||||
left = (left - 1) & (max - 1);
|
||||
deque_put_info(L, deque.index(), &left, &fill, NULL);
|
||||
@@ -276,7 +276,7 @@ LuaDefine(deque_pushr, "c") {
|
||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||
max = deque_make_room(L, deque.index(), left, fill, max);
|
||||
int target = (left + fill) & (max-1);
|
||||
LS.rawseti(deque, DEQUE_BASE + target, elt);
|
||||
LS.rawset(deque, DEQUE_BASE + target, elt);
|
||||
fill += 1;
|
||||
deque_put_info(L, deque.index(), NULL, &fill, NULL);
|
||||
return LS.result();
|
||||
@@ -292,8 +292,8 @@ LuaDefine(deque_popl, "c") {
|
||||
LS.set(result, LuaNil);
|
||||
return LS.result();
|
||||
}
|
||||
LS.rawgeti(result, deque, DEQUE_BASE + left);
|
||||
LS.rawseti(deque, DEQUE_BASE + left, 0);
|
||||
LS.rawget(result, deque, DEQUE_BASE + left);
|
||||
LS.rawset(deque, DEQUE_BASE + left, 0);
|
||||
left = (left + 1) & (max - 1);
|
||||
fill -= 1;
|
||||
deque_put_info(L, deque.index(), &left, &fill, NULL);
|
||||
@@ -311,8 +311,8 @@ LuaDefine(deque_popr, "c") {
|
||||
return LS.result();
|
||||
}
|
||||
int target = (left + fill - 1) & (max - 1);
|
||||
LS.rawgeti(result, deque, DEQUE_BASE + target);
|
||||
LS.rawseti(deque, DEQUE_BASE + target, 0);
|
||||
LS.rawget(result, deque, DEQUE_BASE + target);
|
||||
LS.rawset(deque, DEQUE_BASE + target, 0);
|
||||
fill -= 1;
|
||||
deque_put_info(L, deque.index(), NULL, &fill, NULL);
|
||||
return LS.result();
|
||||
@@ -330,7 +330,7 @@ LuaDefine(deque_nthl, "c") {
|
||||
return LS.result();
|
||||
}
|
||||
int target = (left + n - 1) & (max - 1);
|
||||
LS.rawgeti(result, deque, DEQUE_BASE + target);
|
||||
LS.rawget(result, deque, DEQUE_BASE + target);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ LuaDefine(deque_nthr, "c") {
|
||||
return LS.result();
|
||||
}
|
||||
int target = (left + fill - n) & (max - 1);
|
||||
LS.rawgeti(result, deque, DEQUE_BASE + target);
|
||||
LS.rawget(result, deque, DEQUE_BASE + target);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ LuaDefine(deque_setl, "c") {
|
||||
return LS.result();
|
||||
}
|
||||
int target = (left + n - 1) & (max - 1);
|
||||
LS.rawseti(deque, DEQUE_BASE + target, val);
|
||||
LS.rawset(deque, DEQUE_BASE + target, val);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ LuaDefine(deque_setr, "c") {
|
||||
return LS.result();
|
||||
}
|
||||
int target = (left + fill - n) & (max - 1);
|
||||
LS.rawseti(deque, DEQUE_BASE + target, val);
|
||||
LS.rawset(deque, DEQUE_BASE + target, val);
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ LuaDefine(deque_findl, "c") {
|
||||
deque_get_info(L, deque.index(), &left, &fill, &max);
|
||||
for (int i = 0; i < fill; i++) {
|
||||
int index = (left + i) & (max - 1);
|
||||
LS.rawgeti(check, deque, DEQUE_BASE + index);
|
||||
LS.rawget(check, deque, DEQUE_BASE + index);
|
||||
if (LS.rawequal(check, val)) {
|
||||
LS.set(pos, i + 1);
|
||||
return LS.result();
|
||||
@@ -409,7 +409,7 @@ LuaDefine(deque_findr, "c") {
|
||||
int base = left + fill - 1;
|
||||
for (int i = 0; i < fill; i++) {
|
||||
int index = (base - i) & (max - 1);
|
||||
LS.rawgeti(check, deque, DEQUE_BASE + index);
|
||||
LS.rawget(check, deque, DEQUE_BASE + index);
|
||||
if (LS.rawequal(check, val)) {
|
||||
LS.set(pos, i + 1);
|
||||
return LS.result();
|
||||
@@ -424,7 +424,7 @@ LuaDefine(deque_size, "c") {
|
||||
LuaRet size;
|
||||
LuaStack LS(L, deque, size);
|
||||
LS.checktable(deque);
|
||||
LS.rawgeti(size, deque, DEQUE_FILL);
|
||||
LS.rawget(size, deque, DEQUE_FILL);
|
||||
LS.checknumber(size);
|
||||
return LS.result();
|
||||
}
|
||||
@@ -548,7 +548,7 @@ bool table_getpairs(LuaStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort) {
|
||||
// Create the table, store the initial 1.
|
||||
int total = lua_nkeys(L, tab.index());
|
||||
LS.createtable(pairs, total * 2 + 1, 0);
|
||||
LS.rawseti(pairs, 1, 1);
|
||||
LS.rawset(pairs, 1, 1);
|
||||
// Transfer the pairs into the sequence.
|
||||
lua_pushnil(L);
|
||||
int offset = 2;
|
||||
|
||||
Reference in New Issue
Block a user