Implement easy SQL array access functions, and fix some bugs in spawning
new threads with arguments.
This commit is contained in:
@@ -52,4 +52,6 @@ int vm_intfn_cmdsocket_prefix(void);
|
|||||||
int vm_intfn_sql_query(void);
|
int vm_intfn_sql_query(void);
|
||||||
int vm_intfn_sql_query_1s(void);
|
int vm_intfn_sql_query_1s(void);
|
||||||
int vm_intfn_sql_getvar(void);
|
int vm_intfn_sql_getvar(void);
|
||||||
|
int vm_intfn_sql_getvar_array(void);
|
||||||
int vm_intfn_sql_setvar(void);
|
int vm_intfn_sql_setvar(void);
|
||||||
|
int vm_intfn_sql_setvar_array(void);
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ function cmdsocket_prefix
|
|||||||
function sql_query
|
function sql_query
|
||||||
function sql_query_1s
|
function sql_query_1s
|
||||||
function sql_getvar
|
function sql_getvar
|
||||||
|
function sql_getvar_array
|
||||||
function sql_setvar
|
function sql_setvar
|
||||||
|
function sql_setvar_array
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The ABI should be identified by a SHA1 hash of this file
|
* The ABI should be identified by a SHA1 hash of this file
|
||||||
|
|||||||
73
src/lsi/vm.c
73
src/lsi/vm.c
@@ -472,14 +472,18 @@ int vm_intfn_cmdsocket_write(void)
|
|||||||
char *buffer = stack_getstr(vm_current, len, 2);
|
char *buffer = stack_getstr(vm_current, len, 2);
|
||||||
int newoff;
|
int newoff;
|
||||||
|
|
||||||
|
printf("cmdsocket_write in vm\n");
|
||||||
|
|
||||||
newoff = cmdsocket_write(buffer, len, off);
|
newoff = cmdsocket_write(buffer, len, off);
|
||||||
stack_poke(vm_current, 1, newoff);
|
stack_poke(vm_current, 1, newoff);
|
||||||
|
|
||||||
if (newoff != len) {
|
if (newoff != len) {
|
||||||
|
printf("cmdsocket_write sleeping\n");
|
||||||
vm_queue(vm_current, VM_CMDWRITEQ);
|
vm_queue(vm_current, VM_CMDWRITEQ);
|
||||||
vm_current = NULL;
|
vm_current = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
printf("cmdsocket_write success\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,7 +618,34 @@ int vm_intfn_sql_getvar(void)
|
|||||||
snprintf(buf, len+1, stack_getstr(vm_current, len, 1));
|
snprintf(buf, len+1, stack_getstr(vm_current, len, 1));
|
||||||
snprintf(query, VM_STRING_MAX, "SELECT value FROM vars WHERE name=\"%s\"", buf);
|
snprintf(query, VM_STRING_MAX, "SELECT value FROM vars WHERE name=\"%s\"", buf);
|
||||||
|
|
||||||
sql_query(query, strlen(query), &result);
|
if (sql_query(query, strlen(query), &result) != 2)
|
||||||
|
result = -1;
|
||||||
|
|
||||||
|
/* XXX what to do with an error here? */
|
||||||
|
stack_poke(vm_current, 0, result); /* return value */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vm_intfn_sql_getvar_array(void)
|
||||||
|
{
|
||||||
|
int len, off;
|
||||||
|
char buf[VM_STRING_MAX];
|
||||||
|
char query[VM_STRING_MAX];
|
||||||
|
int result;
|
||||||
|
|
||||||
|
off = stack_get(vm_current, 1);
|
||||||
|
len = stack_get(vm_current, 2);
|
||||||
|
|
||||||
|
if (len >= VM_STRING_MAX) {
|
||||||
|
printf("Excessive string length - can't perform query\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, len+1, stack_getstr(vm_current, len, 2));
|
||||||
|
snprintf(query, VM_STRING_MAX, "SELECT value FROM vars WHERE name=\"%s[%d]\"", buf, off);
|
||||||
|
|
||||||
|
if (sql_query(query, strlen(query), &result) != 2)
|
||||||
|
result = -1;
|
||||||
|
|
||||||
/* XXX what to do with an error here? */
|
/* XXX what to do with an error here? */
|
||||||
stack_poke(vm_current, 0, result); /* return value */
|
stack_poke(vm_current, 0, result); /* return value */
|
||||||
@@ -645,6 +676,32 @@ int vm_intfn_sql_setvar(void)
|
|||||||
stack_poke(vm_current, 0, result); /* return value */
|
stack_poke(vm_current, 0, result); /* return value */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vm_intfn_sql_setvar_array(void)
|
||||||
|
{
|
||||||
|
int len, off, val;
|
||||||
|
char buf[VM_STRING_MAX];
|
||||||
|
char query[VM_STRING_MAX];
|
||||||
|
int result;
|
||||||
|
|
||||||
|
val = stack_get(vm_current, 1);
|
||||||
|
off = stack_get(vm_current, 2);
|
||||||
|
len = stack_get(vm_current, 3);
|
||||||
|
|
||||||
|
if (len >= VM_STRING_MAX) {
|
||||||
|
printf("Excessive string length - can't perform query\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, len+1, stack_getstr(vm_current, len, 3));
|
||||||
|
snprintf(query, VM_STRING_MAX, "INSERT OR REPLACE INTO vars VALUES(\"%s[%d]\", %d)", buf, off, val);
|
||||||
|
|
||||||
|
sql_query(query, strlen(query), &result);
|
||||||
|
|
||||||
|
/* XXX what to do with an error here? */
|
||||||
|
stack_poke(vm_current, 0, result); /* return value */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int vm_intfn_beatdetect_read(void)
|
int vm_intfn_beatdetect_read(void)
|
||||||
@@ -933,16 +990,20 @@ int vm_spawn_args(char *fn, int n, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
newt->sp = newt->stackbase;
|
newt->sp = newt->stackbase;
|
||||||
/* Push return address here, to point to some special thread exit
|
|
||||||
routine */
|
stack_push(newt, 0); /* Return value */
|
||||||
|
|
||||||
/* Push optional arguments */
|
/* Push optional arguments */
|
||||||
va_start(ap, n);
|
va_start(ap, n);
|
||||||
while (n--)
|
while (n--) {
|
||||||
stack_push(newt, va_arg(ap, int));
|
int a = va_arg(ap, int);
|
||||||
|
// printf("arg is %d\n", a);
|
||||||
|
stack_push(newt, a);
|
||||||
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
stack_push(newt, 0); /* Return value */
|
/* Push return address here, to point to some special thread exit
|
||||||
|
routine */
|
||||||
stack_push(newt, 0); /* Return address */
|
stack_push(newt, 0); /* Return address */
|
||||||
|
|
||||||
/* Insert into head of run queue */
|
/* Insert into head of run queue */
|
||||||
|
|||||||
Reference in New Issue
Block a user