Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion db/comdb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ int gbl_return_long_column_names = 1;
int gbl_maxreclen;
int gbl_penaltyincpercent = 20;
int gbl_maxwthreadpenalty;
int gbl_spstrictassignments = 0;
int gbl_lock_conflict_trace = 0;
int gbl_move_deadlk_max_attempt = 500;

Expand Down
1 change: 0 additions & 1 deletion db/db_tunables.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ extern int gbl_debug_sleep_on_set_read_only;
extern int gbl_debug_wait_on_verify_off;
extern int gbl_debug_disttxn_trace;
extern int gbl_sparse_lockerid_map;
extern int gbl_spstrictassignments;
extern int gbl_early;
extern int gbl_exit_alarm_sec;
extern int gbl_fdb_default_ver;
Expand Down
3 changes: 0 additions & 3 deletions db/db_tunables.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,6 @@ REGISTER_TUNABLE("enable_sparse_lockerid_map",
"If set, allocates a sparse map of lockers for deadlock "
"resolution. (Default: on)",
TUNABLE_BOOLEAN, &gbl_sparse_lockerid_map, READONLY | NOARG, NULL, NULL, NULL, NULL);
REGISTER_TUNABLE("enable_sp_strict_assignments", NULL, TUNABLE_INTEGER,
&gbl_spstrictassignments, READONLY | NOARG, NULL, NULL, NULL,
NULL);
REGISTER_TUNABLE(
"enable_sq_flattening_optimization",
"Enable subquery flattening optimization for OUTER JOINS (Default: off)",
Expand Down
2 changes: 1 addition & 1 deletion lua/lopcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/
OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */

/* COMDB2 MODIFICATION */
OP_CAST, /* A B C R(A) := R(B).. := ..R(C) */
OP_CAST, /* A B C R(A) := RK(B) _cast RK(C) */

OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */
} OpCode;
Expand Down
47 changes: 0 additions & 47 deletions lua/ltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,12 +891,9 @@ void init_cmp(Lua lua)
lua_setfield(lua, -2, "__le");
}

static int l_typed_assignment(Lua);
static int l_concat(Lua);
void init_common(Lua lua)
{
lua_pushcfunction(lua, l_typed_assignment);
lua_setfield(lua, -2, "__type");
lua_pushcfunction(lua, l_column_cast);
lua_setfield(lua, -2, "__cast");
lua_pushcfunction(lua, l_concat);
Expand Down Expand Up @@ -2080,7 +2077,6 @@ static void init_blob(Lua L)
setup_method(L, "__lt", l_blob_lt);
setup_method(L, "__le", l_blob_le);
setup_method(L, "__cast", l_column_cast);
setup_method(L, "__type", l_typed_assignment);
setup_method(L, "__gc", l_blob_free);
setup_method(L, "__len", l_blob_length);

Expand Down Expand Up @@ -2179,16 +2175,6 @@ int luabb_isnull(lua_State *lua, int arg_index)
return 0;
}

int luabb_istyped(lua_State *lua, int arg_index)
{
int type = lua_type(lua, arg_index);
if (type == LUA_TUSERDATA) {
const lua_dbtypes_t *n = lua_topointer(lua, arg_index);
return n->is_typed;
}
return 0;
}

void luabb_pushnull(Lua lua, int dbtype)
{
switch (dbtype) {
Expand Down Expand Up @@ -2256,39 +2242,6 @@ char *luabb_newblob(Lua lua, int len, void **blob)
return (char *)b->val.data;
}

static int l_typed_assignment(lua_State *lua)
{
const char *name1 = NULL;
const char *name2 = NULL;
if ((lua_type(lua, 1) == LUA_TUSERDATA)) {
if (luabb_istyped(lua,1)) {
lua_getmetatable(lua, 1);
lua_pushstring(lua, "__metatable");
lua_gettable(lua, -2);
name1 = lua_tostring(lua, -1);
lua_getmetatable(lua, 2);
lua_pushstring(lua, "__metatable");
lua_gettable(lua, -2);
name2 = lua_tostring(lua, -1);
if (name1 && name2 && strcmp(name1, name2) == 0) {
lua_pop(lua,4);
lua_remove(lua,1);
} else {
/* Remove everything and push nil. */
lua_settop(lua, 0);
if (name1) {
luabb_error(lua, NULL, "Invalid assignment, invalid typed assignment for type %s", name1);
} else {
luabb_error(lua, NULL, "Invalid assignment, invalid typed assignment");
}
}
}
} else {
lua_remove(lua,1);
}
return 1;
}

int l_column_cast(Lua L)
{
if (lua_isnil(L, -2)) {
Expand Down
4 changes: 0 additions & 4 deletions lua/ltypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <lua.h>
#include <comdb2.h>

extern int gbl_spstrictassignments;

// one switch to rule them all
#define DBTYPES \
XMACRO_DBTYPES(DBTYPES_LNIL, "nil", t0, NULL)\
Expand Down Expand Up @@ -94,7 +92,6 @@ extern const char *dbtypes_str[];
#define DBTYPES_COMMON \
int magic; \
dbtypes_enum dbtype; \
int is_typed; \
int is_null

typedef struct {
Expand Down Expand Up @@ -150,7 +147,6 @@ typedef struct {
#define init_new_t(n, DBTYPE) \
(n)->magic = DBTYPES_MAGIC;\
(n)->is_null = 0;\
(n)->is_typed = gbl_spstrictassignments;\
(n)->dbtype = DBTYPE

#define new_lua_t_sz(L, n, DBTYPE, sz) \
Expand Down
2 changes: 0 additions & 2 deletions lua/luautil.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ void luabb_typeconvert(Lua l, int pos, int type)
lua_replace(l, pos);
}

#define luabb_todbpointer(x) ((lua_dbtypes_t *)(rawuvalue(x) + 1))

HashType luabb_hashinfo(void *udata, double *d, const char **c, size_t *l)
{
const lua_dbtypes_t *t = udata;
Expand Down
1 change: 1 addition & 0 deletions lua/luautil.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int luabb_istype(lua_State *lua, int index, dbtypes_enum);
int luabb_error(lua_State *lua, struct stored_proc *sp, const char *fmt, ...);
int luabb_issql_type(lua_State *lua, int index, int sql_type);
void luabb_typeconvert_int(struct lua_State *, int from_pos, dbtypes_enum to, const char *to_str);
#define luabb_todbpointer(x) ((lua_dbtypes_t *)(rawuvalue(x) + 1))
void lua_datetime_to_client(lua_datetime_t *ld, cdb2_client_datetime_t *val);
void client_datetime_to_lua(cdb2_client_datetime_t *val, lua_datetime_t *ld);
int precompile_lua(char *lua_buffer, void **compiled_data, int *size);
Expand Down
42 changes: 21 additions & 21 deletions lua/lvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,38 @@
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "ltypes.h"
#include "lvm.h"

#include "luaglue.h"
#include "luautil.h"


/* limit for table tag-method chains (to avoid loops) */
#define MAXTAGLOOP 100


const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
lua_Number num;
if (ttisnumber(obj)) return obj;
if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
setnvalue(n, num);
return n;
}
else
return NULL;

if (ttisuserdata(obj)) {
const lua_dbtypes_t *bb = luabb_todbpointer(obj);
if (bb->is_null) return NULL;
switch (bb->dbtype) {
case DBTYPES_INTEGER:
setnvalue(n, (lua_Number)(((lua_int_t *)bb)->val));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test for number close to max longlong?

return n;
case DBTYPES_REAL:
setnvalue(n, (lua_Number)(((lua_real_t *)bb)->val));
return n;
}
}

return NULL;
}


Expand Down Expand Up @@ -360,7 +374,8 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb,
const TValue *rc, TMS op) {
TValue tempb, tempc;
const TValue *b, *c;
if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
if (!ttisuserdata(rb) && !ttisuserdata(rc) &&
(b = luaV_tonumber(rb, &tempb)) != NULL &&
(c = luaV_tonumber(rc, &tempc)) != NULL) {
lua_Number nb = nvalue(b), nc = nvalue(c);
switch (op) {
Expand Down Expand Up @@ -402,15 +417,6 @@ static void Arith (lua_State *L, StkId ra, const TValue *rb,

#define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }

#define assign_op(op) { \
TValue *rb = RKB(i); \
TValue *rc = RKC(i); \
const TValue *tm = luaT_gettmbyobj(L, rc, TM_TYPE); \
if (ttisuserdata(rc) && !ttisnil(tm)) { \
Protect(Arith(L, ra, rc, rb, TM_TYPE)); \
} else \
setobjs2s(L, ra, RB(i));\
}

#define arith_op(op,tm) { \
TValue *rb = RKB(i); \
Expand Down Expand Up @@ -456,17 +462,11 @@ void luaV_execute (lua_State *L, int nexeccalls) {
lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
switch (GET_OPCODE(i)) {
case OP_MOVE: {
assign_op(GET_OPCODE(i));
setobjs2s(L, ra, RB(i));
continue;
}
case OP_LOADK: {
TValue *rb = RKB(i);
const TValue *tm = luaT_gettmbyobj(L, rb, TM_TYPE);
if (ttisuserdata(rb) && !ttisnil(tm)) {
Protect(Arith(L, ra, rb, KBx(i), TM_TYPE));
} else {
setobj2s(L, ra, KBx(i));
}
setobj2s(L, ra, KBx(i));
continue;
}
case OP_LOADBOOL: {
Expand Down
1 change: 1 addition & 0 deletions lua/lvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
/* Converts obj to a number: handles Lua number, numeric strings, and userdata numbers. */
LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
Expand Down
23 changes: 4 additions & 19 deletions lua/sp.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,13 @@ static int dbtype_to_client_type(lua_dbtypes_t *t)

static int lua_to_client_type(Lua lua, int idx)
{
if (lua_isnumber(lua, idx)) {
if (lua_type(lua, idx) == LUA_TUSERDATA) {
lua_dbtypes_t *t = lua_touserdata(lua, idx);
return dbtype_to_client_type(t);
} else if (lua_isnumber(lua, idx)) {
return SQLITE_FLOAT;
} else if (lua_isstring(lua, idx)) {
return SQLITE_TEXT;
} else if (lua_type(lua, idx) == LUA_TUSERDATA) {
lua_dbtypes_t *t = lua_touserdata(lua, idx);
return dbtype_to_client_type(t);
} else {
return -1;
}
Expand Down Expand Up @@ -4579,20 +4579,6 @@ static int db_setnull(Lua lua)
return 0;
}

static int db_settyped(Lua lua)
{
if (lua_type(lua, -1) != LUA_TUSERDATA) {
return luaL_error(lua, "bad argument to 'settyped'");
}

lua_dbtypes_t *t = (lua_dbtypes_t *)lua_topointer(lua, -1);
assert(t->magic == DBTYPES_MAGIC);
assert(t->dbtype > DBTYPES_MINTYPE);
assert(t->dbtype < DBTYPES_MAXTYPE);
t->is_typed = 1;
return 0;
}

static int db_setmaxinstructions(Lua L)
{
luaL_checkudata(L, 1, dbtypes.db);
Expand Down Expand Up @@ -5044,7 +5030,6 @@ static const luaL_Reg db_funcs[] = {
{"setmaxinstructions", db_setmaxinstructions},
{"setnull", db_setnull},
{"settimezone", db_settimezone},
{"settyped", db_settyped},
{"sp", db_sp},
{"sqlerror", db_error}, // every error isn't from SQL -- deprecate
{"table", db_table},
Expand Down
1 change: 0 additions & 1 deletion lua/sp_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ void luabb_pushnull(Lua, int dbtype);
void luabb_pushreal(Lua, double);

int luabb_isnull(Lua, int index);
int luabb_istyped(Lua, int index);

/* must be called before any exposed functionality is available in lua */
void init_dbtypes(Lua);
Expand Down
Loading