5 Commits

Author SHA1 Message Date
vms
f9a8e85da4 update wit file according to the record refactoring 2020-09-16 01:54:04 +03:00
vms
483c82e02c add IT support 2020-09-15 14:35:03 +03:00
vms
e39cf0d2ff fix off-by-one in returning OK string 2020-05-02 18:19:25 +03:00
vms
72e9311c97 getting rid of excess imports
since https://github.com/rust-lang/rust/issues/63562 fixed
2020-04-29 00:24:20 +03:00
vms
8960e72d3b update to the latest ABI 2020-04-28 21:58:11 +03:00
6 changed files with 84 additions and 32 deletions

3
.gitignore vendored
View File

@ -4,3 +4,6 @@
# Wasm files
*.wasm
*.wat
# REPL history
.repl_history

6
Config.toml Normal file
View File

@ -0,0 +1,6 @@
modules_dir = "./"
[[module]]
name = "sqlite3"
mem_pages_count = 100
logger_enabled = true

View File

@ -7,14 +7,11 @@ LDFLAGS = -Wl,--no-entry,--demangle,--allow-undefined
EXPORT_FUNCS = \
--export=allocate,$\
--export=deallocate,$\
--export=invoke,$\
--export=load,$\
--export=store,$\
--export=sqlite_allocate,$\
--export=sqlite_deallocate,$\
--export=sqlite_invoke,$\
--export=sqlite_load,$\
--export=sqlite_store
--export=set_result_size,$\
--export=set_result_ptr,$\
--export=get_result_size,$\
--export=get_result_ptr,$\
--export=invoke
SQLITE_SRC = \
src/alter.c\
src/analyze.c\
@ -128,8 +125,7 @@ SQLITE_FLAGS = \
-DSQLITE_ENABLE_OFFSET_SQL_FUNC\
-DSQLITE_ENABLE_DESERIALIZE\
-DSQLITE_INTROSPECTION_PRAGMAS\
-DSQLITE_OMIT_POPEN\
-DLOG_ENABLED
-DSQLITE_OMIT_POPEN
.PHONY: default all clean

View File

@ -2,7 +2,7 @@
#define FLUENCE_C_SDK_LOGGER_H
#define __LOGGER_IMPORT(name) \
__attribute__((__import_module__("logger"), __import_name__(#name)))
__attribute__((__import_module__("host"), __import_name__(#name)))
/**
* Writes provided utf8 string to Wasm VM logger.

43
sqlite3.wit Normal file
View File

@ -0,0 +1,43 @@
;; Fluence SQLite fork Wasm Interface Types
;; allocate
(@interface type (func (param $size: i32) (result i32))) ;; 0
;; deallocate
(@interface type (func (param $pointer: i32 $size: i32))) ;; 1
;; invoke
(@interface type (func (param $request: string) (result string))) ;; 2
;; get_result_ptr/get_result_size
(@interface type (func (result i32))) ;; 3
;; set_result_ptr/set_result_size
(@interface type (func (param $result: i32))) ;; 4
(@interface export "allocate" (func 0)) ;; 0
(@interface export "deallocate" (func 1)) ;; 1
(@interface export "invoke" (func 2)) ;; 2
(@interface export "get_result_size" (func 3)) ;; 3
(@interface export "get_result_ptr" (func 3)) ;; 4
(@interface export "set_result_size" (func 4)) ;; 5
(@interface export "set_result_ptr" (func 4)) ;; 6
;; adapter for export invoke function
(@interface func (type 2)
arg.get 0
string.size
call-core 0 ;; call allocate
arg.get 0
string.lower_memory
call-core 2 ;; call invoke
call-core 4 ;; call get_result_size
call-core 3 ;; call get_result_ptr
string.lift_memory
call-core 4 ;; call get_result_size
call-core 3 ;; call get_result_ptr
call-core 1 ;; call deallocate
)
;; Implementations
(@interface implement (func 2) (func 2))

View File

@ -3,6 +3,8 @@
#include "sqliteInt.h"
sqlite3 *state;
char *RESULT_PTR;
int RESULT_SIZE;
int init() {
const int rc = sqlite3_initialize();
@ -23,22 +25,27 @@ void deallocate(void *ptr, int size) {
free(ptr);
}
char *write_response(char *response, int response_size) {
char *result_response = allocate(response_size + 4);
void set_result_ptr(char *ptr) {
RESULT_PTR = ptr;
}
for(int i = 0; i < 4; ++i) {
result_response[i] = (response_size >> 8*i) & 0xFF;
}
void set_result_size(int size) {
RESULT_SIZE = size;
}
memcpy(result_response + 4, response, response_size);
return result_response;
int get_result_size(void) {
return RESULT_SIZE;
}
char *get_result_ptr() {
return RESULT_PTR;
}
typedef struct ShellText ShellText;
struct ShellText {
char *z;
int n;
int nAlloc;
char *z;
int n;
int nAlloc;
};
static void initText(ShellText *p){
@ -106,13 +113,13 @@ static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
return 0;
}
const char *invoke(char *request, int request_size) {
void invoke(char *request, int request_size) {
if(g_isInited == 0) {
// TODO: check the return code
init();
#if LOG_ENABLED
const char successInitMessage[] = "Sqlite has been initialized";
const char successInitMessage[] = "Sqlite has been initialized\n";
log_utf8_string(successInitMessage, sizeof(successInitMessage));
#endif
@ -133,20 +140,17 @@ const char *invoke(char *request, int request_size) {
char *response = 0;
if(rc || errorMessage) {
response = write_response(errorMessage, strlen(errorMessage));
RESULT_PTR = errorMessage;
RESULT_SIZE = strlen(errorMessage);
}
else {
if(str.n != 0) {
response = write_response(str.z, str.n);
RESULT_PTR = str.z;
RESULT_SIZE = str.n;
} else {
// if a request was successfull, sqlite doesn't return anything as the result string
const char success_result[] = "OK";
response = write_response((char *)success_result, sizeof(success_result));
RESULT_PTR = strdup("OK");
RESULT_SIZE = 2;
}
}
freeText(&str);
return response;
}