The unified diff between revisions [a81fe555..] and [81f2a8bb..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'src/lsi/vm.c'

#
# old_revision [a81fe5550c21fa983b4e344e07c29b9cecdf75ea]
# new_revision [81f2a8bbe94638a22f5651ee07112ceabd50285c]
#
# patch "src/lsi/vm.c"
#  from [c29bc86ce0d4170f8a0229735384ea9eea76763f]
#    to [e2e905076968e53dd131de512d042191f64d91bf]
#
============================================================
--- src/lsi/vm.c	c29bc86ce0d4170f8a0229735384ea9eea76763f
+++ src/lsi/vm.c	e2e905076968e53dd131de512d042191f64d91bf
@@ -472,14 +472,18 @@ int vm_intfn_cmdsocket_write(void)
 	char *buffer = stack_getstr(vm_current, len, 2);
 	int newoff;
 
+	printf("cmdsocket_write in vm\n");
+
 	newoff = cmdsocket_write(buffer, len, off);
 	stack_poke(vm_current, 1, newoff);
 
 	if (newoff != len) {
+		printf("cmdsocket_write sleeping\n");
 		vm_queue(vm_current, VM_CMDWRITEQ);
 		vm_current = NULL;
 		return 0;
 	}
+	printf("cmdsocket_write success\n");
 	return 1;
 }
 
@@ -596,6 +600,108 @@ int vm_intfn_sql_query_1s(void)
 	stack_poke(vm_current, 0, result); /* return value */
 	return 1;
 }
+
+int vm_intfn_sql_getvar(void)
+{
+	int len;
+	char buf[VM_STRING_MAX];
+	char query[VM_STRING_MAX];
+	int result;
+
+	len = stack_get(vm_current, 1);
+
+	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, 1));
+	snprintf(query, VM_STRING_MAX, "SELECT value FROM vars WHERE name=\"%s\"", buf);
+
+	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? */
+	stack_poke(vm_current, 0, result); /* return value */
+	return 1;
+}
+
+int vm_intfn_sql_setvar(void)
+{
+	int len, val;
+	char buf[VM_STRING_MAX];
+	char query[VM_STRING_MAX];
+	int result;
+
+	val = 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, "INSERT OR REPLACE INTO vars VALUES(\"%s\", %d)", buf, 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;
+}
+
+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
 
 int vm_intfn_beatdetect_read(void)
@@ -884,16 +990,20 @@ int vm_spawn_args(char *fn, int n, ...)
 		return 0;
 	}
 	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 */
 	va_start(ap, n);
-	while (n--)
-	    stack_push(newt, va_arg(ap, int));
+	while (n--) {
+	    int a = va_arg(ap, int);
+//	    printf("arg is %d\n", a);
+	    stack_push(newt, a);
+	}
 	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 */
 
 	/* Insert into head of run queue */