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
3 changes: 2 additions & 1 deletion lua/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
if (!ttisstring(o)) {
/* COMDB2 MODIFICATION */
if (luabb_iscstring(L, idx)) {
const char *s = luabb_tolcstring(L, idx, len);
const char *s = luabb_tocstring(L, idx);
if (len) *len = strlen(s);
return s;
}
lua_lock(L); /* `luaV_tostring' may create a new string */
Expand Down
22 changes: 8 additions & 14 deletions lua/ltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -571,16 +571,16 @@ const char *luabb_tostring_noerr(Lua L, int idx)
static int luabb_toblob_int(Lua lua, int idx, blob_t *ret)
{
const char *c;
size_t s = 0;
size_t s;
int type = luabb_type(lua, idx);
if (type == DBTYPES_LSTRING) {
c = lua_tolstring(lua, idx, &s);
str: ret->data = strdup(c);
c = lua_tostring(lua, idx);
str: s = strlen(c);
ret->data = strdup(c);
ret->length = s;
return 0;
} else if (type == DBTYPES_CSTRING) {
c = ((lua_cstring_t*)lua_touserdata(lua, idx))->val;
s = ((lua_cstring_t*)lua_touserdata(lua, idx))->len;
goto str;
} else if (type == DBTYPES_BLOB) {
const lua_blob_t *blob = lua_topointer(lua, idx);
Expand Down Expand Up @@ -725,7 +725,6 @@ static int luabb_todatetime_int(lua_State *lua, int idx, datetime_t *ret)
dttz_t dt;
time_t temp_t;
const char *str;
size_t len;
cdb2_client_datetime_t cdtms;
cdb2_client_datetimeus_t cdtus;

Expand All @@ -735,8 +734,8 @@ static int luabb_todatetime_int(lua_State *lua, int idx, datetime_t *ret)

switch (luabb_dbtype(lua, idx)) {
case LUA_TSTRING:
str = lua_tolstring(lua, idx, &len);
if (str_to_dttz(str, len, tzname, &dt, precision) != 0)
str = lua_tostring(lua, idx);
if (str_to_dttz(str, strlen(str), tzname, &dt, precision) != 0)
goto err;
break;
case LUA_TNUMBER:
Expand Down Expand Up @@ -766,8 +765,7 @@ static int luabb_todatetime_int(lua_State *lua, int idx, datetime_t *ret)
return 0;
case DBTYPES_CSTRING:
str = ((lua_cstring_t*)lua_topointer(lua, idx))->val;
int len = ((lua_cstring_t*)lua_topointer(lua, idx))->len;
if (str_to_dttz(str, len, tzname, &dt, precision) != 0)
if (str_to_dttz(str, strlen(str), tzname, &dt, precision) != 0)
goto err;
break;
case DBTYPES_REAL:
Expand Down Expand Up @@ -1396,7 +1394,6 @@ int l_cstring_new(lua_State *lua) {
lua_cstring_t *s;
new_lua_t(s, lua_cstring_t, DBTYPES_CSTRING);
s->val = NULL;
s->len = 0;
return 1;
}

Expand All @@ -1420,7 +1417,7 @@ int l_cstring_free(Lua lua)
int l_cstring_length(lua_State *lua) {
const lua_cstring_t *s;
s = (const lua_cstring_t*) lua_topointer(lua, 1);
lua_pushnumber(lua, utf8_bytelen(s->val, s->len));
lua_pushnumber(lua, utf8_bytelen(s->val, strlen(s->val)));
return 1;
}

Expand Down Expand Up @@ -2116,15 +2113,13 @@ void luabb_pushcstring(lua_State *lua, const char* cstrval) {
l_cstring_new(lua);
lua_cstring_t *s = (lua_cstring_t *) lua_topointer(lua, -1);
s->val = strdup(cstrval);
s->len = strlen(cstrval);
}

void luabb_pushcstringlen(lua_State *lua, const char* cstrval, int len)
{
l_cstring_new(lua);
lua_cstring_t *s = (lua_cstring_t *) lua_topointer(lua, -1);
s->val = malloc(len + 1);
s->len = len;
memcpy(s->val, cstrval, len);
s->val[len] = '\0';
}
Expand All @@ -2135,7 +2130,6 @@ void luabb_pushcstring_dl(lua_State *lua, const char* cstrval)
l_cstring_new(lua);
lua_cstring_t *s = (lua_cstring_t *) lua_topointer(lua, -1);
s->val = (char *)cstrval;
s->len = (int)strlen(cstrval);
}

void luabb_pushblob(lua_State *lua, const blob_t *val)
Expand Down
1 change: 0 additions & 1 deletion lua/ltypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ typedef struct {
typedef struct {
DBTYPES_COMMON;
char* val;
int len;
} lua_cstring_t;

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion lua/luaglue.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int luabb_dbtype_from_tvalue(struct lua_TValue *);
int luabb_isnumber(struct lua_State *, int idx);
double luabb_tonumber(struct lua_State *, int idx);
int luabb_iscstring(struct lua_State *, int idx);
const char *luabb_tolcstring(struct lua_State *, int idx, size_t *);
const char *luabb_tocstring(struct lua_State *, int idx);
int luabb_isnull(struct lua_State *, int idx);
void luabb_tointeger(struct lua_State *, int idx, long long *val);

Expand Down
5 changes: 2 additions & 3 deletions lua/luautil.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ HashType luabb_hashinfo(void *udata, double *d, const char **c, size_t *l)
if (c != NULL && l != NULL) {
if (t->dbtype == DBTYPES_CSTRING) {
*c = ((lua_cstring_t *)t)->val;
*l = ((lua_cstring_t *)t)->len;
*l = strlen(*c);
} else {
*c = ((lua_blob_t *)t)->val.data;
*l = ((lua_blob_t *)t)->val.length;
Expand Down Expand Up @@ -582,13 +582,12 @@ int luabb_iscstring(Lua l, int idx)
}

/* assumes luabb_iscstring is true */
const char *luabb_tolcstring(Lua l, int idx, size_t *len)
const char *luabb_tocstring(Lua l, int idx)
{
const TValue *o = index2adr(l, idx);
lua_dbtypes_t *bb = luabb_todbpointer(o);
if (bb->dbtype != DBTYPES_CSTRING) abort();
lua_cstring_t *ptr = (lua_cstring_t *)bb;
if (len != NULL) *len = ptr->len;
return ptr->val;
}

Expand Down
15 changes: 5 additions & 10 deletions lua/sp.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ void *sp_column_ptr(struct response_data *arg, int col, int type, size_t *len)
case DBTYPES_CSTRING:
cs = lua_touserdata(L, idx);
c = cs->val;
*len = cs->len;
*len = strlen(c);
break;
default:
c = (char *)luabb_tostring_noerr(L, idx);
Expand Down Expand Up @@ -2201,7 +2201,6 @@ static int stmt_bind_int(Lua lua, sqlite3_stmt *stmt, int name, int value)
intv_t *i;
datetime_t *d;
int type;
size_t l;
if ((type = luabb_dbtype(lua, value)) > DBTYPES_MINTYPE) {
if (luabb_isnull(lua, value)) {
return sqlite3_bind_null(stmt, position);
Expand All @@ -2211,8 +2210,8 @@ static int stmt_bind_int(Lua lua, sqlite3_stmt *stmt, int name, int value)
switch (type) {
case DBTYPES_LNIL: return sqlite3_bind_null(stmt, position);
case DBTYPES_LSTRING:
c = lua_tolstring(lua, value, &l);
return sqlite3_bind_text(stmt, position, c, l, NULL);
c = lua_tostring(lua, value);
return sqlite3_bind_text(stmt, position, c, strlen(c), NULL);
case DBTYPES_LNUMBER:
return sqlite3_bind_double(stmt, position, lua_tonumber(lua, value));
case DBTYPES_INTEGER:
Expand All @@ -2221,8 +2220,7 @@ static int stmt_bind_int(Lua lua, sqlite3_stmt *stmt, int name, int value)
return sqlite3_bind_double(stmt, position, ((lua_real_t *)p)->val);
case DBTYPES_CSTRING:
c = ((lua_cstring_t *)p)->val;
l = ((lua_cstring_t *)p)->len;
return sqlite3_bind_text(stmt, position, c, l, NULL);
return sqlite3_bind_text(stmt, position, c, strlen(c), NULL);
case DBTYPES_BLOB:
b = &((lua_blob_t *)p)->val;
return sqlite3_bind_blob(stmt, position, b->data, b->length, NULL);
Expand Down Expand Up @@ -2963,10 +2961,8 @@ static void copy_comdb2_type(lua_State *lua1, lua_State *lua2, int index,
copy_type(dbtypes.cstring, lua_cstring_t);
if (f1->is_null) {
f2->val = NULL;
f2->len = 0;
} else {
f2->val = strdup(f1->val);
f2->len = f1->len;
}
} else if (luabb_istype(lua1, index, DBTYPES_BLOB)) {
copy_type(dbtypes.blob, lua_blob_t);
Expand Down Expand Up @@ -4518,7 +4514,6 @@ static int db_setnull(Lua lua)
c = (lua_cstring_t *)t;
free(c->val);
c->val = NULL;
c->len = 0;
break;
case DBTYPES_BLOB:
b = (lua_blob_t *)t;
Expand Down Expand Up @@ -5938,7 +5933,7 @@ static int push_param(Lua L, struct sqlclntstate *clnt, int64_t index)
case CLIENT_REAL: return push_real_array(L, &p);
}
return -1;
}
}
switch (p.type) {
case CLIENT_INT:
case CLIENT_UINT: luabb_pushinteger(L, p.u.i); break;
Expand Down
5 changes: 0 additions & 5 deletions tests/sp_perf.test/Makefile

This file was deleted.

27 changes: 0 additions & 27 deletions tests/sp_perf.test/alltypes.csc2

This file was deleted.

27 changes: 0 additions & 27 deletions tests/sp_perf.test/alltypes_cstr.csc2

This file was deleted.

22 changes: 0 additions & 22 deletions tests/sp_perf.test/cdb2api_types_map.json

This file was deleted.

5 changes: 0 additions & 5 deletions tests/sp_perf.test/consumer.exp

This file was deleted.

21 changes: 0 additions & 21 deletions tests/sp_perf.test/insert_bind

This file was deleted.

2 changes: 0 additions & 2 deletions tests/sp_perf.test/lrl.options

This file was deleted.

Loading