lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi.

This is a small patch for the macro op_bitwiseK in ./src/lvm.c (Lua 5.4.3).
This patch adds the type checking against K operand in op_bitwiseK as in op_arithK.
I wonder how much important the type checking against K operands is.
Please tell me if you have any opinion about this patch.

===
diff --git a/src/lvm.c b/src/lvm.c
index c9729bc..8036210 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -960,28 +960,31 @@ void luaV_finishOp (lua_State *L) {
 
 
 /*
-** Bitwise operations with constant operand.
+** Bitwise operations over numbers.
 */
-#define op_bitwiseK(L,op) {  \
-  TValue *v1 = vRB(i);  \
-  TValue *v2 = KC(i);  \
-  lua_Integer i1;  \
-  lua_Integer i2 = ivalue(v2);  \
-  if (tointegerns(v1, &i1)) {  \
+#define op_bitwise_aux(L,v1,v2,op) {  \
+  lua_Integer i1; lua_Integer i2;  \
+  if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) {  \
     pc++; setivalue(s2v(ra), op(i1, i2));  \
   }}
 
 
+/*
+** Bitwise operations with K operand.
+*/
+#define op_bitwiseK(L,op) {  \
+  TValue *v1 = vRB(i);  \
+  TValue *v2 = KC(i); lua_assert(ttisnumber(v2));  \
+  op_bitwise_aux(L, v1, v2, op); }
+
+
 /*
 ** Bitwise operations with register operands.
 */
 #define op_bitwise(L,op) {  \
   TValue *v1 = vRB(i);  \
   TValue *v2 = vRC(i);  \
-  lua_Integer i1; lua_Integer i2;  \
-  if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) {  \
-    pc++; setivalue(s2v(ra), op(i1, i2));  \
-  }}
+  op_bitwise_aux(L, v1, v2, op); }
 
 
 /*
===

Regards,

。:+* ゜ ゜゜ *+:。:+* ゜ ゜゜ *+:。:+* ゜ ゜゜ *+:。
Tatsuhiro Aoshima
NTT Secure Platform Laboratories
Phone: +81 422 59 3261 [JPN: (0422) 59 3261]