3 Commits

Author SHA1 Message Date
vms
cb62ab800e fix sqlite3_bind_blob 2021-01-28 00:13:52 +03:00
vms
4179ccd6f9 fix blob/text setters and getters 2020-11-09 04:39:38 +03:00
vms
df5cbd0b0f make Dockerfile compatible with fce 0.1.11 2020-11-08 18:30:24 +03:00
6 changed files with 54 additions and 41 deletions

View File

@ -4,10 +4,13 @@ RUN apt-get update \
&& apt-get install -y ca-certificates \
curl \
git \
make
make \
cargo
RUN curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-11/wasi-sdk-11.0-linux.tar.gz | tar xz --strip-components=1 -C /
RUN cargo install fcli --version 0.1.12
VOLUME /code
WORKDIR /code
CMD make

View File

@ -160,6 +160,7 @@ all: default
$(TARGET): $(SQLITE_SRC) $(WRAPPER_SRC)
$(CC) -O3 --sysroot=$(SYSROOT) --target=$(TARGET_TRIPLE) $(SQLITE_FLAGS) $(CFLAGS) $(LDFLAGS) -Wl,$(EXPORT_FUNCS) $^ -o $@.wasm
/root/.cargo/bin/fce embed -i sqlite3.wasm -w sqlite3.wit
.PRECIOUS: $(TARGET)

View File

@ -1,5 +1,3 @@
;; Fluence SQLite fork Wasm Interface Types
;; Types
(@interface type (func
(param $size: i32)
@ -53,10 +51,10 @@
(result s32))) ;; 16
(@interface type (func
(param $filename: string $flags: s32 $vfs: string)
)) ;; 17
(result record 8))) ;; 17
(@interface type (func
(param $filename: string $flags: s32 $vfs: string)
)) ;; 18
(result record 8))) ;; 18
(@interface type (func
(param $db_handle: u32)
(result s32))) ;; 19
@ -113,27 +111,27 @@
(result s32))) ;; 36
(@interface type (func
(param $db_handle: u32 $sql: string)
)) ;; 37
(result record 7))) ;; 37
(@interface type (func
(param $db_handle: u32 $sql: string)
)) ;; 38
(result record 7))) ;; 38
(@interface type (func
(param $stmt_handle: u32 $pos: s32)
(param $stmt_handle: u32)
(result s32))) ;; 39
(@interface type (func
(param $stmt_handle: u32 $pos: s32)
(param $stmt_handle: u32)
(result s32))) ;; 40
(@interface type (func
(param $stmt_handle: u32)
(param $stmt_handle: u32 $pos: s32)
(result s32))) ;; 41
(@interface type (func
(param $stmt_handle: u32)
(param $stmt_handle: u32 $pos: s32)
(result s32))) ;; 42
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $blob: byte_array $xDel: s32)
(param $stmt_handle: u32 $pos: s32 $blob: array (u8) $xDel: s32)
(result s32))) ;; 43
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $blob: byte_array $xDel: s32)
(param $stmt_handle: u32 $pos: s32 $blob: array (u8) $xDel: s32)
(result s32))) ;; 44
(@interface type (func
(param $db_handle: u32)
@ -155,20 +153,20 @@
(result s32))) ;; 50
(@interface type (func
(param $db_handle: u32 $sql: string $callback_id: s32 $callback_arg: s32)
)) ;; 51
(result record 6))) ;; 51
(@interface type (func
(param $db_handle: u32 $sql: string $callback_id: s32 $callback_arg: s32)
)) ;; 52
(result record 6))) ;; 52
(@interface type (func
(result s32))) ;; 53
(@interface type (func
(result s32))) ;; 54
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result byte_array))) ;; 55
(result array (u8)))) ;; 55
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result byte_array))) ;; 56
(result array (u8)))) ;; 56
(@interface type (func
(param $stmt_handle: u32 $N: u32)
(result string))) ;; 57
@ -306,13 +304,13 @@
(@interface func (type 39)
arg.get 0
i32.from_u32
arg.get 1
i32.from_s32
call-core 21
s32.from_i32)
(@interface func (type 41)
arg.get 0
i32.from_u32
arg.get 1
i32.from_s32
call-core 22
s32.from_i32)
(@interface func (type 43)
@ -321,10 +319,7 @@
arg.get 1
i32.from_s32
arg.get 2
byte_array.size
call-core 0
arg.get 2
byte_array.lower_memory
array.lower_memory u8
arg.get 3
i32.from_s32
call-core 23
@ -379,10 +374,7 @@
call-core 29
call-core 3
call-core 2
byte_array.lift_memory
call-core 3
call-core 2
call-core 1)
array.lift_memory u8)
(@interface func (type 57)
arg.get 0
i32.from_u32
@ -425,8 +417,8 @@
(@interface export "sqlite3_bind_int64" (func 34))
(@interface export "sqlite3_finalize" (func 36))
(@interface export "sqlite3_prepare_v2" (func 38))
(@interface export "sqlite3_bind_null" (func 40))
(@interface export "sqlite3_column_count" (func 42))
(@interface export "sqlite3_column_count" (func 40))
(@interface export "sqlite3_bind_null" (func 42))
(@interface export "sqlite3_bind_blob" (func 44))
(@interface export "sqlite3_total_changes" (func 46))
(@interface export "sqlite3_bind_text" (func 48))

View File

@ -792,7 +792,7 @@ void sqlite3_prepare_v2_(
const char *pzTail;
const int ret_code = sqlite3_prepare_v2(db, zSql, nBytes, &ppStmt, &pzTail);
free(zSql);
free((void *)zSql);
int *result = (int *)malloc(3*8);
result[0] = ret_code;

View File

@ -1110,10 +1110,13 @@ static void columnMallocFailure(sqlite3_stmt *pStmt)
*/
void sqlite3_column_blob_(sqlite3_stmt *pStmt, int i) __EXPORT_NAME(sqlite3_column_blob) {
const char *result = sqlite3_column_blob(pStmt, i);
const char *blob = sqlite3_column_blob(pStmt, i);
int blob_len = sqlite3_column_bytes(pStmt, i);
set_result_ptr((char *)result);
unsigned char *copied_result = malloc(blob_len);
memcpy(copied_result, blob, blob_len);
set_result_ptr((char *)copied_result);
set_result_size(blob_len);
}
@ -1154,10 +1157,14 @@ sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
}
void sqlite3_column_text_(sqlite3_stmt *pStmt, int i) __EXPORT_NAME(sqlite3_column_text) {
const unsigned char *result = sqlite3_column_text(pStmt, i);
const unsigned char *text = sqlite3_column_text(pStmt, i);
const unsigned int text_len = sqlite3_column_bytes(pStmt, i);
set_result_ptr((char *)result);
set_result_size(strlen(result));
unsigned char *copied_text = malloc(text_len);
memcpy(copied_text, text, text_len);
set_result_ptr((char *)copied_text);
set_result_size(text_len);
}
const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
@ -1435,13 +1442,22 @@ static int bindText(
int sqlite3_bind_blob_(
sqlite3_stmt *pStmt,
int i,
const void *zData,
char *zData,
int nData,
void (*xDel)(void*)
) __EXPORT_NAME(sqlite3_bind_blob) {
const int copied_nData = nData / 8;
char *copied_zData = malloc(copied_nData);
const int result = sqlite3_bind_blob(pStmt, i, zData, nData, xDel);
free((void *)zData);
if (copied_zData == 0) {
return -1;
}
for (int char_id = 0; char_id < copied_nData; ++char_id) {
copied_zData[char_id] = zData[char_id * 8];
}
const int result = sqlite3_bind_blob(pStmt, i, copied_zData, copied_nData, 0);
return result;
}
@ -1530,8 +1546,10 @@ int sqlite3_bind_text_(
int nData,
void (*xDel)(void*)
) __EXPORT_NAME(sqlite3_bind_text) {
const int result = sqlite3_bind_text(pStmt, i, zData, nData, xDel);
free((char *)zData);
char *copied_zData = malloc(nData);
memcpy(copied_zData, zData, nData);
const int result = sqlite3_bind_text(pStmt, i, copied_zData, nData, xDel);
return result;
}

View File

@ -28,4 +28,3 @@ int get_result_size(void) {
const char *get_result_ptr() {
return RESULT_PTR;
}