14 Commits

Author SHA1 Message Date
19d85ba7a5 Merge pull request #5 from fluencelabs/fix_bwu
fix BWU compatibility
2021-09-03 17:43:33 +03:00
e7c772cfb6 Merge pull request #4 from fluencelabs/fix_xdel
Use hardcoded free instead of xDel
2021-09-03 17:13:59 +03:00
vms
807d6ff47d fix of fix 2021-09-03 13:50:33 +03:00
vms
5b9324916d fix BWU compatibility 2021-09-03 13:49:23 +03:00
vms
71080d772d fix 2021-09-03 13:43:58 +03:00
vms
f3a435616a use hardcoded free instead of xDel 2021-09-03 12:07:15 +03:00
vms
b07df8ab66 update to the latest sdk 2021-04-26 13:28:58 +03:00
vms
f23126d37e switch to BWU1 2021-04-22 19:48:39 +03:00
vms
107372813c Merge pull request #2 from fluencelabs/sdk_0.6.0
Move to sdk 0.6.0
2021-04-12 14:48:19 +03:00
vms
932bfb38a1 final preparation 2021-04-12 14:45:55 +03:00
vms
2150b81cf6 some updates 2021-04-12 13:06:14 +03:00
vms
0820036f56 use cvector 2021-04-12 12:30:51 +03:00
vms
af0ac14818 more changes 2021-04-12 11:40:33 +03:00
vms
38fb596f7c the first part of moving to the sdk 0.6.0 2021-04-12 00:15:26 +03:00
10 changed files with 842 additions and 610 deletions

View File

@ -7,7 +7,7 @@ SDK = sdk/logger.h
LDFLAGS = -Wl,--demangle,--allow-undefined
EXPORT_FUNCS = \
--export=allocate,$\
--export=deallocate,$\
--export=release_objects,$\
--export=set_result_size,$\
--export=set_result_ptr,$\
--export=get_result_size,$\
@ -26,15 +26,14 @@ EXPORT_FUNCS = \
--export=sqlite3_column_name_,$\
--export=sqlite3_step,$\
--export=sqlite3_reset,$\
--export=sqlite3_bind_blob_,$\
--export=sqlite3_bind_blob,$\
--export=sqlite3_bind_double,$\
--export=sqlite3_bind_int64,$\
--export=sqlite3_bind_text_,$\
--export=sqlite3_bind_text,$\
--export=sqlite3_bind_null,$\
--export=sqlite3_column_count,$\
--export=sqlite3_column_double,$\
--export=sqlite3_column_int64,$\
--export=sqlite3_column_text_,$\
--export=sqlite3_column_blob_,$\
--export=sqlite3_column_bytes,$\
--export=sqlite3_finalize
@ -154,7 +153,8 @@ SQLITE_FLAGS = \
-DSQLITE_ENABLE_OFFSET_SQL_FUNC\
-DSQLITE_ENABLE_DESERIALIZE\
-DSQLITE_INTROSPECTION_PRAGMAS\
-DSQLITE_OMIT_POPEN
-DSQLITE_OMIT_POPEN\
-DCVECTOR_LOGARITHMIC_GROWTH
.PHONY: default all clean
@ -163,7 +163,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
# /root/.cargo/bin/fce embed_it -i sqlite3.wasm -w sqlite3.wit
.PRECIOUS: $(TARGET)

197
cvector/cvector.h Normal file
View File

@ -0,0 +1,197 @@
#ifndef CVECTOR_H_
#define CVECTOR_H_
#include <assert.h> /* for assert */
#include <stdlib.h> /* for malloc/realloc/free */
/**
* @brief cvector_vector_type - The vector type used in this library
*/
#define cvector_vector_type(type) type *
/**
* @brief cvector_set_capacity - For internal use, sets the capacity variable of the vector
* @param vec - the vector
* @param size - the new capacity to set
* @return void
*/
#define cvector_set_capacity(vec, size) \
do { \
if (vec) { \
((size_t *)(vec))[-1] = (size); \
} \
} while (0)
/**
* @brief cvector_set_size - For internal use, sets the size variable of the vector
* @param vec - the vector
* @param size - the new capacity to set
* @return void
*/
#define cvector_set_size(vec, size) \
do { \
if (vec) { \
((size_t *)(vec))[-2] = (size); \
} \
} while (0)
/**
* @brief cvector_capacity - gets the current capacity of the vector
* @param vec - the vector
* @return the capacity as a size_t
*/
#define cvector_capacity(vec) \
((vec) ? ((size_t *)(vec))[-1] : (size_t)0)
/**
* @brief cvector_size - gets the current size of the vector
* @param vec - the vector
* @return the size as a size_t
*/
#define cvector_size(vec) \
((vec) ? ((size_t *)(vec))[-2] : (size_t)0)
/**
* @brief cvector_empty - returns non-zero if the vector is empty
* @param vec - the vector
* @return non-zero if empty, zero if non-empty
*/
#define cvector_empty(vec) \
(cvector_size(vec) == 0)
/**
* @brief cvector_grow - For internal use, ensures that the vector is at least <count> elements big
* @param vec - the vector
* @param count - the new capacity to set
* @return void
*/
#define cvector_grow(vec, count) \
do { \
const size_t cv_sz = (count) * sizeof(*(vec)) + (sizeof(size_t) * 2); \
if (!(vec)) { \
size_t *cv_p = malloc(cv_sz); \
assert(cv_p); \
(vec) = (void *)(&cv_p[2]); \
cvector_set_capacity((vec), (count)); \
cvector_set_size((vec), 0); \
} else { \
size_t *cv_p1 = &((size_t *)(vec))[-2]; \
size_t *cv_p2 = realloc(cv_p1, (cv_sz)); \
assert(cv_p2); \
(vec) = (void *)(&cv_p2[2]); \
cvector_set_capacity((vec), (count)); \
} \
} while (0)
/**
* @brief cvector_pop_back - removes the last element from the vector
* @param vec - the vector
* @return void
*/
#define cvector_pop_back(vec) \
do { \
cvector_set_size((vec), cvector_size(vec) - 1); \
} while (0)
/**
* @brief cvector_erase - removes the element at index i from the vector
* @param vec - the vector
* @param i - index of element to remove
* @return void
*/
#define cvector_erase(vec, i) \
do { \
if (vec) { \
const size_t cv_sz = cvector_size(vec); \
if ((i) < cv_sz) { \
cvector_set_size((vec), cv_sz - 1); \
size_t cv_x; \
for (cv_x = (i); cv_x < (cv_sz - 1); ++cv_x) { \
(vec)[cv_x] = (vec)[cv_x + 1]; \
} \
} \
} \
} while (0)
/**
* @brief cvector_free - frees all memory associated with the vector
* @param vec - the vector
* @return void
*/
#define cvector_free(vec) \
do { \
if (vec) { \
size_t *p1 = &((size_t *)(vec))[-2]; \
free(p1); \
} \
} while (0)
/**
* @brief cvector_begin - returns an iterator to first element of the vector
* @param vec - the vector
* @return a pointer to the first element (or NULL)
*/
#define cvector_begin(vec) \
(vec)
/**
* @brief cvector_end - returns an iterator to one past the last element of the vector
* @param vec - the vector
* @return a pointer to one past the last element (or NULL)
*/
#define cvector_end(vec) \
((vec) ? &((vec)[cvector_size(vec)]) : NULL)
/* user request to use logarithmic growth algorithm */
#ifdef CVECTOR_LOGARITHMIC_GROWTH
/**
* @brief cvector_push_back - adds an element to the end of the vector
* @param vec - the vector
* @param value - the value to add
* @return void
*/
#define cvector_push_back(vec, value) \
do { \
size_t cv_cap = cvector_capacity(vec); \
if (cv_cap <= cvector_size(vec)) { \
cvector_grow((vec), !cv_cap ? cv_cap + 1 : cv_cap * 2); \
} \
vec[cvector_size(vec)] = (value); \
cvector_set_size((vec), cvector_size(vec) + 1); \
} while (0)
#else
/**
* @brief cvector_push_back - adds an element to the end of the vector
* @param vec - the vector
* @param value - the value to add
* @return void
*/
#define cvector_push_back(vec, value) \
do { \
size_t cv_cap = cvector_capacity(vec); \
if (cv_cap <= cvector_size(vec)) { \
cvector_grow((vec), cv_cap + 1); \
} \
vec[cvector_size(vec)] = (value); \
cvector_set_size((vec), cvector_size(vec) + 1); \
} while (0)
#endif /* CVECTOR_LOGARITHMIC_GROWTH */
/**
* @brief cvector_copy - copy a vector
* @param from - the original vector
* @param to - destination to which the function copy to
* @return void
*/
#define cvector_copy(from, to) \
do { \
for(size_t i = 0; i < cvector_size(from); i++) { \
cvector_push_back(to, from[i]); \
} \
} while (0) \
#endif /* CVECTOR_H_ */

View File

@ -1,9 +1,10 @@
(@interface it_version "0.20.0")
;; Types
(@interface type (func
(param $size: i32)
(result i32))) ;; 0
(@interface type (func
(param $pointer: i32 $size: i32) )) ;; 1
(@interface type (func )) ;; 1
(@interface type (func
(result i32))) ;; 2
(@interface type (func
@ -25,102 +26,110 @@
field $ret_code: s32
field $db_handle: u32
))) ;; 8
(@interface type (record $SecurityTetraplet (
field $peer_pk: string
field $service_id: string
field $function_name: string
field $json_path: string
))) ;; 9
(@interface type (record $CallParameters (
field $init_peer_id: string
field $service_id: string
field $service_creator_peer_id: string
field $host_id: string
field $particle_id: string
field $tetraplets: array (array (record 9))
))) ;; 10
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result string))) ;; 9
(result string))) ;; 11
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result string))) ;; 10
(result string))) ;; 12
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s32))) ;; 11
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s32))) ;; 12
(@interface type (func
(param $db_handle: u32)
(result s32))) ;; 13
(@interface type (func
(param $db_handle: u32)
(param $stmt_handle: u32 $icol: u32)
(result s32))) ;; 14
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $value: f64)
(param $db_handle: u32)
(result s32))) ;; 15
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $value: f64)
(param $db_handle: u32)
(result s32))) ;; 16
(@interface type (func
(param $filename: string $flags: s32 $vfs: string)
(result record 8))) ;; 17
(param $stmt_handle: u32 $pos: s32 $value: f64)
(result s32))) ;; 17
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $value: f64)
(result s32))) ;; 18
(@interface type (func
(param $filename: string $flags: s32 $vfs: string)
(result record 8))) ;; 18
(result record 8))) ;; 19
(@interface type (func
(param $filename: string $flags: s32 $vfs: string)
(result record 8))) ;; 20
(@interface type (func
(param $db_handle: u32)
(result s32))) ;; 19
(@interface type (func
(param $db_handle: u32)
(result s32))) ;; 20
(@interface type (func
(param $stmt_handle: u32)
(result s32))) ;; 21
(@interface type (func
(param $stmt_handle: u32)
(param $db_handle: u32)
(result s32))) ;; 22
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s64))) ;; 23
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s64))) ;; 24
(@interface type (func
(param $db: u32)
(result s32))) ;; 25
(@interface type (func
(param $db: u32)
(result s32))) ;; 26
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result f64))) ;; 27
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result f64))) ;; 28
(@interface type (func
(param $db_handle: u32 $ms: u32)
(result s32))) ;; 29
(@interface type (func
(param $db_handle: u32 $ms: u32)
(result s32))) ;; 30
(@interface type (func
(param $db_handle: u32)
(result string))) ;; 31
(@interface type (func
(param $db_handle: u32)
(result string))) ;; 32
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $value: s64)
(result s32))) ;; 33
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $value: s64)
(result s32))) ;; 34
(param $stmt_handle: u32)
(result s32))) ;; 23
(@interface type (func
(param $stmt_handle: u32)
(result s32))) ;; 24
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s64))) ;; 25
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s64))) ;; 26
(@interface type (func
(param $db: u32)
(result s32))) ;; 27
(@interface type (func
(param $db: u32)
(result s32))) ;; 28
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result f64))) ;; 29
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result f64))) ;; 30
(@interface type (func
(param $db_handle: u32 $ms: u32)
(result s32))) ;; 31
(@interface type (func
(param $db_handle: u32 $ms: u32)
(result s32))) ;; 32
(@interface type (func
(param $db_handle: u32)
(result string))) ;; 33
(@interface type (func
(param $db_handle: u32)
(result string))) ;; 34
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $value: s64)
(result s32))) ;; 35
(@interface type (func
(param $stmt_handle: u32)
(param $stmt_handle: u32 $pos: s32 $value: s64)
(result s32))) ;; 36
(@interface type (func
(param $db_handle: u32 $sql: string)
(result record 7))) ;; 37
(@interface type (func
(param $db_handle: u32 $sql: string)
(result record 7))) ;; 38
(param $stmt_handle: u32)
(result s32))) ;; 37
(@interface type (func
(param $stmt_handle: u32)
(result s32))) ;; 39
(result s32))) ;; 38
(@interface type (func
(param $stmt_handle: u32)
(result s32))) ;; 40
(param $db_handle: u32 $sql: string)
(result record 7))) ;; 39
(@interface type (func
(param $db_handle: u32 $sql: string)
(result record 7))) ;; 40
(@interface type (func
(param $stmt_handle: u32 $pos: s32)
(result s32))) ;; 41
@ -128,62 +137,68 @@
(param $stmt_handle: u32 $pos: s32)
(result s32))) ;; 42
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $blob: array (u8) $xDel: s32)
(param $stmt_handle: u32)
(result s32))) ;; 43
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $blob: array (u8) $xDel: s32)
(param $stmt_handle: u32)
(result s32))) ;; 44
(@interface type (func
(param $db_handle: u32)
(param $stmt_handle: u32 $pos: s32 $blob: array (u8) $xDel: s32)
(result s32))) ;; 45
(@interface type (func
(param $db_handle: u32)
(param $stmt_handle: u32 $pos: s32 $blob: array (u8) $xDel: s32)
(result s32))) ;; 46
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $text: string $xDel: s32)
(param $db_handle: u32)
(result s32))) ;; 47
(@interface type (func
(param $stmt_handle: u32 $pos: s32 $text: string $xDel: s32)
(param $db_handle: u32)
(result s32))) ;; 48
(@interface type (func
(param $stmt_handle: u32)
(param $stmt_handle: u32 $pos: s32 $text: string $xDel: s32)
(result s32))) ;; 49
(@interface type (func
(param $stmt_handle: u32)
(param $stmt_handle: u32 $pos: s32 $text: string $xDel: s32)
(result s32))) ;; 50
(@interface type (func
(param $db_handle: u32 $sql: string $callback_id: s32 $callback_arg: s32)
(result record 6))) ;; 51
(param $stmt_handle: u32)
(result s32))) ;; 51
(@interface type (func
(param $stmt_handle: u32)
(result s32))) ;; 52
(@interface type (func
(param $db_handle: u32 $sql: string $callback_id: s32 $callback_arg: s32)
(result record 6))) ;; 52
(result record 6))) ;; 53
(@interface type (func
(result s32))) ;; 53
(param $db_handle: u32 $sql: string $callback_id: s32 $callback_arg: s32)
(result record 6))) ;; 54
(@interface type (func
(result s32))) ;; 54
(result s32))) ;; 55
(@interface type (func
(result s32))) ;; 56
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result array (u8)))) ;; 55
(result array (u8)))) ;; 57
(@interface type (func
(param $stmt_handle: u32 $icol: s32)
(result array (u8)))) ;; 56
(result array (u8)))) ;; 58
(@interface type (func
(param $stmt_handle: u32 $N: u32)
(result string))) ;; 57
(result string))) ;; 59
(@interface type (func
(param $stmt_handle: u32 $N: u32)
(result string))) ;; 58
(result string))) ;; 60
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s32))) ;; 59
(result s32))) ;; 61
(@interface type (func
(param $stmt_handle: u32 $icol: u32)
(result s32))) ;; 60
(result s32))) ;; 62
;; Adapters
(@interface func (type 9)
(@interface func (type 11)
arg.get 0
i32.from_u32
arg.get 1
@ -192,22 +207,20 @@
call-core 3
call-core 2
string.lift_memory
call-core 3
call-core 2
call-core 1)
(@interface func (type 11)
(@interface func (type 13)
arg.get 0
i32.from_u32
arg.get 1
i32.from_u32
call-core 7
s32.from_i32)
(@interface func (type 13)
(@interface func (type 15)
arg.get 0
i32.from_u32
call-core 8
s32.from_i32)
(@interface func (type 15)
(@interface func (type 17)
arg.get 0
i32.from_u32
arg.get 1
@ -215,9 +228,10 @@
arg.get 2
call-core 9
s32.from_i32)
(@interface func (type 17)
(@interface func (type 19)
arg.get 0
string.size
i32.push 1
call-core 0
arg.get 0
string.lower_memory
@ -225,58 +239,58 @@
i32.from_s32
arg.get 2
string.size
i32.push 1
call-core 0
arg.get 2
string.lower_memory
call-core 10
call-core 3
record.lift_memory 8)
(@interface func (type 19)
record.lift_memory 8
call-core 1)
(@interface func (type 21)
arg.get 0
i32.from_u32
call-core 11
s32.from_i32)
(@interface func (type 21)
(@interface func (type 23)
arg.get 0
i32.from_u32
call-core 12
s32.from_i32)
(@interface func (type 23)
(@interface func (type 25)
arg.get 0
i32.from_u32
arg.get 1
i32.from_u32
call-core 13
s64.from_i64)
(@interface func (type 25)
(@interface func (type 27)
arg.get 0
i32.from_u32
call-core 14
s32.from_i32)
(@interface func (type 27)
(@interface func (type 29)
arg.get 0
i32.from_u32
arg.get 1
i32.from_s32
call-core 15)
(@interface func (type 29)
(@interface func (type 31)
arg.get 0
i32.from_u32
arg.get 1
i32.from_u32
call-core 16
s32.from_i32)
(@interface func (type 31)
(@interface func (type 33)
arg.get 0
i32.from_u32
call-core 17
call-core 3
call-core 2
string.lift_memory
call-core 3
call-core 2
call-core 1)
(@interface func (type 33)
(@interface func (type 35)
arg.get 0
i32.from_u32
arg.get 1
@ -285,35 +299,37 @@
i64.from_s64
call-core 18
s32.from_i32)
(@interface func (type 35)
(@interface func (type 37)
arg.get 0
i32.from_u32
call-core 19
s32.from_i32)
(@interface func (type 37)
(@interface func (type 39)
arg.get 0
i32.from_u32
arg.get 1
string.size
i32.push 1
call-core 0
arg.get 1
string.lower_memory
call-core 20
call-core 3
record.lift_memory 7)
(@interface func (type 39)
arg.get 0
i32.from_u32
call-core 21
s32.from_i32)
record.lift_memory 7
call-core 1)
(@interface func (type 41)
arg.get 0
i32.from_u32
arg.get 1
i32.from_s32
call-core 22
call-core 21
s32.from_i32)
(@interface func (type 43)
arg.get 0
i32.from_u32
call-core 22
s32.from_i32)
(@interface func (type 45)
arg.get 0
i32.from_u32
arg.get 1
@ -324,18 +340,19 @@
i32.from_s32
call-core 23
s32.from_i32)
(@interface func (type 45)
(@interface func (type 47)
arg.get 0
i32.from_u32
call-core 24
s32.from_i32)
(@interface func (type 47)
(@interface func (type 49)
arg.get 0
i32.from_u32
arg.get 1
i32.from_s32
arg.get 2
string.size
i32.push 1
call-core 0
arg.get 2
string.lower_memory
@ -343,16 +360,17 @@
i32.from_s32
call-core 25
s32.from_i32)
(@interface func (type 49)
(@interface func (type 51)
arg.get 0
i32.from_u32
call-core 26
s32.from_i32)
(@interface func (type 51)
(@interface func (type 53)
arg.get 0
i32.from_u32
arg.get 1
string.size
i32.push 1
call-core 0
arg.get 1
string.lower_memory
@ -362,11 +380,12 @@
i32.from_s32
call-core 27
call-core 3
record.lift_memory 6)
(@interface func (type 53)
record.lift_memory 6
call-core 1)
(@interface func (type 55)
call-core 28
s32.from_i32)
(@interface func (type 55)
(@interface func (type 57)
arg.get 0
i32.from_u32
arg.get 1
@ -374,8 +393,9 @@
call-core 29
call-core 3
call-core 2
array.lift_memory u8)
(@interface func (type 57)
byte_array.lift_memory
call-core 1)
(@interface func (type 59)
arg.get 0
i32.from_u32
arg.get 1
@ -384,10 +404,8 @@
call-core 3
call-core 2
string.lift_memory
call-core 3
call-core 2
call-core 1)
(@interface func (type 59)
(@interface func (type 61)
arg.get 0
i32.from_u32
arg.get 1
@ -397,40 +415,39 @@
;; Exports
(@interface export "allocate" (func 0))
(@interface export "deallocate" (func 1))
(@interface export "release_objects" (func 1))
(@interface export "get_result_size" (func 2))
(@interface export "get_result_ptr" (func 3))
(@interface export "set_result_size" (func 4))
(@interface export "set_result_ptr" (func 5))
(@interface export "sqlite3_column_text" (func 10))
(@interface export "sqlite3_column_bytes" (func 12))
(@interface export "sqlite3_close" (func 14))
(@interface export "sqlite3_bind_double" (func 16))
(@interface export "sqlite3_open_v2" (func 18))
(@interface export "sqlite3_changes" (func 20))
(@interface export "sqlite3_step" (func 22))
(@interface export "sqlite3_column_int64" (func 24))
(@interface export "sqlite3_errcode" (func 26))
(@interface export "sqlite3_column_double" (func 28))
(@interface export "sqlite3_busy_timeout" (func 30))
(@interface export "sqlite3_errmsg" (func 32))
(@interface export "sqlite3_bind_int64" (func 34))
(@interface export "sqlite3_finalize" (func 36))
(@interface export "sqlite3_prepare_v2" (func 38))
(@interface export "sqlite3_column_count" (func 40))
(@interface export "sqlite3_column_text" (func 12))
(@interface export "sqlite3_column_bytes" (func 14))
(@interface export "sqlite3_close" (func 16))
(@interface export "sqlite3_bind_double" (func 18))
(@interface export "sqlite3_open_v2" (func 20))
(@interface export "sqlite3_changes" (func 22))
(@interface export "sqlite3_step" (func 24))
(@interface export "sqlite3_column_int64" (func 26))
(@interface export "sqlite3_errcode" (func 28))
(@interface export "sqlite3_column_double" (func 30))
(@interface export "sqlite3_busy_timeout" (func 32))
(@interface export "sqlite3_errmsg" (func 34))
(@interface export "sqlite3_bind_int64" (func 36))
(@interface export "sqlite3_finalize" (func 38))
(@interface export "sqlite3_prepare_v2" (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))
(@interface export "sqlite3_reset" (func 50))
(@interface export "sqlite3_exec" (func 52))
(@interface export "sqlite3_libversion_number" (func 54))
(@interface export "sqlite3_column_blob" (func 56))
(@interface export "sqlite3_column_name" (func 58))
(@interface export "sqlite3_column_type" (func 60))
(@interface export "sqlite3_column_count" (func 44))
(@interface export "sqlite3_bind_blob" (func 46))
(@interface export "sqlite3_total_changes" (func 48))
(@interface export "sqlite3_bind_text" (func 50))
(@interface export "sqlite3_reset" (func 52))
(@interface export "sqlite3_exec" (func 54))
(@interface export "sqlite3_libversion_number" (func 56))
(@interface export "sqlite3_column_blob" (func 58))
(@interface export "sqlite3_column_name" (func 60))
(@interface export "sqlite3_column_type" (func 62))
;; Implementations
(@interface implement (func 10) (func 9))
(@interface implement (func 12) (func 11))
(@interface implement (func 14) (func 13))
(@interface implement (func 16) (func 15))
@ -456,3 +473,4 @@
(@interface implement (func 56) (func 55))
(@interface implement (func 58) (func 57))
(@interface implement (func 60) (func 59))
(@interface implement (func 62) (func 61))

View File

@ -28,32 +28,33 @@
** argument to xCallback(). If xCallback=NULL then no callback
** is invoked, even for queries.
*/
#ifndef __sqlite_unmodified_upstream
void sqlite3_exec_(
sqlite3 *db, /* The database on which the SQL executes */
char *zSql, /* The SQL to be executed */
char *zSql, /* The SQL to be executed */
int zSql_len,
sqlite3_callback xCallback, /* Invoke this callback routine */
void *pArg /* First argument to xCallback() */
) __EXPORT_NAME(sqlite3_exec) {
char *new_zSql = (char *) malloc(zSql_len + 1);
memcpy(new_zSql, zSql, zSql_len);
new_zSql[zSql_len] = 0;
free((void *)zSql);
zSql = handle_input_string(zSql, zSql_len);
char *pzErrMsg = 0;
const int ret_code = sqlite3_exec(db, new_zSql, xCallback, pArg, &pzErrMsg);
const int ret_code = sqlite3_exec(db, zSql, xCallback, pArg, &pzErrMsg);
free(new_zSql);
int *result = malloc(3*8);
result[0] = ret_code;
result[1] = 0;
result[2] = (int) pzErrMsg;
result[3] = 0;
result[4] = strlen(pzErrMsg);
result[5] = 0;
// free the string passed from the IT side
free(zSql);
set_result_ptr((char *)result);
unsigned char *result = (unsigned char*)malloc(3*4);
write_le_int(result, 0, (unsigned int)ret_code);
write_le_int(result, 4, (unsigned int)pzErrMsg);
write_le_int(result, 8, (unsigned int)strlen(pzErrMsg));
// errmsg should be managed by user
add_object_to_release((void *) pzErrMsg);
add_object_to_release((void *) result);
set_result_ptr((void *) result);
}
#endif
int sqlite3_exec(
sqlite3 *db, /* The database on which the SQL executes */

File diff suppressed because it is too large Load Diff

View File

@ -783,25 +783,30 @@ int sqlite3_prepare(
return rc;
}
#ifndef __sqlite_unmodified_upstream
void sqlite3_prepare_v2_(
sqlite3 *db, /* Database handle. */
const char *zSql, /* UTF-8 encoded SQL statement. */
int nBytes /* Length of zSql in bytes. */
) __EXPORT_NAME(sqlite3_prepare_v2) {
sqlite3_stmt *ppStmt;
const char *pzTail;
sqlite3_stmt *ppStmt = NULL;
const char *pzTail = NULL;
const int ret_code = sqlite3_prepare_v2(db, zSql, nBytes, &ppStmt, &pzTail);
free((void *)zSql);
int *result = (int *)malloc(3*8);
result[0] = ret_code;
result[2] = (int)ppStmt;
result[4] = (int)pzTail;
result[5] = strlen(pzTail);
// free the string passed from the IT side
free((void *) zSql);
set_result_ptr((char *)result);
unsigned char *result = (unsigned char*)malloc(4 * 4);
write_le_int(result, 0, (unsigned int)ret_code);
write_le_int(result, 4, (unsigned int)ppStmt);
write_le_int(result, 8, (unsigned int)pzTail);
write_le_int(result, 12, (unsigned int)strlen(pzTail));
add_object_to_release((void *) result);
set_result_ptr((void *) result);
}
#endif
int sqlite3_prepare_v2(
sqlite3 *db, /* Database handle. */

View File

@ -37,9 +37,6 @@
#define __EXPORT_NAME(name) \
__attribute__((export_name(#name)))
void set_result_ptr(const char *ptr);
void set_result_size(int size);
/*
** Make sure we can call this stuff from C++.
*/

View File

@ -4908,4 +4908,14 @@ void sqlite3VectorErrorMsg(Parse*, Expr*);
const char **sqlite3CompileOptions(int *pnOpt);
#endif
#ifndef __sqlite_unmodified_upstream
void add_object_to_release(void *object);
void set_result_ptr(void *ptr);
void set_result_size(int size);
char *handle_input_string(char *str, int len);
void write_le_int(unsigned char *array, unsigned int offset, unsigned int value);
#endif
#endif /* SQLITEINT_H */

View File

@ -1113,10 +1113,8 @@ void sqlite3_column_blob_(sqlite3_stmt *pStmt, int i) __EXPORT_NAME(sqlite3_colu
const char *blob = sqlite3_column_blob(pStmt, i);
int blob_len = sqlite3_column_bytes(pStmt, i);
unsigned char *copied_result = malloc(blob_len);
memcpy(copied_result, blob, blob_len);
set_result_ptr((char *)copied_result);
// blob is managed by SQLite itself
set_result_ptr((void *)blob);
set_result_size(blob_len);
}
@ -1160,10 +1158,8 @@ void sqlite3_column_text_(sqlite3_stmt *pStmt, int i) __EXPORT_NAME(sqlite3_colu
const unsigned char *text = sqlite3_column_text(pStmt, i);
const unsigned int text_len = sqlite3_column_bytes(pStmt, i);
unsigned char *copied_text = malloc(text_len);
memcpy(copied_text, text, text_len);
set_result_ptr((char *)copied_text);
// test is managed by SQLite itself
set_result_ptr((void *) text);
set_result_size(text_len);
}
@ -1259,12 +1255,15 @@ static const void *columnName(
** Return the name of the Nth column of the result set returned by SQL
** statement pStmt.
*/
#ifndef __sqlite_unmodified_upstream
void sqlite3_column_name_(sqlite3_stmt *pStmt, int N) __EXPORT_NAME(sqlite3_column_name) {
const char *result = sqlite3_column_name(pStmt, N);
set_result_ptr((char *)result);
// result is managed by SQLite itself
set_result_ptr((void *)result);
set_result_size(strlen(result));
}
#endif
const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
return columnName(pStmt, N, 0, COLNAME_NAME);
@ -1438,30 +1437,6 @@ static int bindText(
/*
** Bind a blob value to an SQL statement variable.
*/
int sqlite3_bind_blob_(
sqlite3_stmt *pStmt,
int i,
char *zData,
int nData,
void (*xDel)(void*)
) __EXPORT_NAME(sqlite3_bind_blob) {
const int copied_nData = nData / 8;
char *copied_zData = malloc(copied_nData);
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;
}
int sqlite3_bind_blob(
sqlite3_stmt *pStmt,
int i,
@ -1472,7 +1447,13 @@ int sqlite3_bind_blob(
#ifdef SQLITE_ENABLE_API_ARMOR
if( nData<0 ) return SQLITE_MISUSE_BKPT;
#endif
#ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, 0);
#else
// xDel is a custom deallocator, due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData, free, 0);
#endif
}
int sqlite3_bind_blob64(
sqlite3_stmt *pStmt,
@ -1539,21 +1520,6 @@ int sqlite3_bind_pointer(
return rc;
}
int sqlite3_bind_text_(
sqlite3_stmt *pStmt,
int i,
const char *zData,
int nData,
void (*xDel)(void*)
) __EXPORT_NAME(sqlite3_bind_text) {
char *copied_zData = malloc(nData);
memcpy(copied_zData, zData, nData);
const int result = sqlite3_bind_text(pStmt, i, copied_zData, nData, xDel);
return result;
}
int sqlite3_bind_text(
sqlite3_stmt *pStmt,
int i,
@ -1561,7 +1527,12 @@ int sqlite3_bind_text(
int nData,
void (*xDel)(void*)
){
#ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
#else
// xDel is a custom deallocator, due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData, free, SQLITE_UTF8);
#endif
}
int sqlite3_bind_text64(
sqlite3_stmt *pStmt,

View File

@ -1,18 +1,37 @@
#include <stdlib.h>
#include "sqliteInt.h"
#include "../cvector/cvector.h"
const char *RESULT_PTR;
#include <stdlib.h>
void *RESULT_PTR;
int RESULT_SIZE;
void* allocate(size_t size) {
cvector_vector_type(void *) OBJECTS_TO_RELEASE;
void* allocate(size_t size, size_t _type_tag) {
if (size == 0 || size + 1 == 0) {
return 0;
}
// this +1 is needed to append then zero byte to strings passing to this module.
return malloc(size + 1);
}
void deallocate(void *ptr, int size) {
free(ptr);
void release_objects() {
const unsigned int objects_count = cvector_size(OBJECTS_TO_RELEASE);
for (unsigned int obj_id = objects_count; obj_id > 0; --obj_id) {
void *object = OBJECTS_TO_RELEASE[obj_id-1];
free(object);
cvector_pop_back(OBJECTS_TO_RELEASE);
}
}
void set_result_ptr(const char *ptr) {
void add_object_to_release(void *object) {
cvector_push_back(OBJECTS_TO_RELEASE, object);
}
void set_result_ptr(void *ptr) {
RESULT_PTR = ptr;
}
@ -24,11 +43,29 @@ int get_result_size(void) {
return RESULT_SIZE;
}
const char *get_result_ptr() {
void *get_result_ptr() {
return RESULT_PTR;
}
char *handle_input_string(char *str, int len) {
if (len == 0) {
free(str);
return NULL;
}
// this strings are supposed to be allocated by the allocate function, which allocates 1 byte more for null character
str[len] = '\x00';
return str;
}
void write_le_int(unsigned char *array, unsigned int offset, unsigned int value) {
array[offset] = value & 0xff;
array[offset + 1] = (value >> 8) & 0xff;
array[offset + 2] = (value >> 16) & 0xff;
array[offset + 3] = (value >> 24) & 0xff;
}
int main() {
// the main purpose of this empty main is to initialize WASi subsystem
// the main purpose of this empty main is to initialize WASI subsystem
return 0;
}
}