sqlite/src/wrapper.c

75 lines
1.6 KiB
C
Raw Normal View History

2019-07-19 15:12:49 +03:00
#include "sqliteInt.h"
2021-04-12 12:30:51 +03:00
#include "../cvector/cvector.h"
#include <stdlib.h>
2019-07-19 15:12:49 +03:00
2021-04-12 13:06:11 +03:00
void *RESULT_PTR;
2020-09-14 21:00:27 +03:00
int RESULT_SIZE;
2019-07-19 15:12:49 +03:00
2021-04-12 12:30:51 +03:00
cvector_vector_type(void *) OBJECTS_TO_RELEASE;
2021-09-03 13:49:23 +03:00
void* allocate(size_t size, size_t _type_tag) {
if (size == 0 || size + 1 == 0) {
return 0;
}
2021-04-12 12:30:51 +03:00
// this +1 is needed to append then zero byte to strings passing to this module.
2019-07-19 15:12:49 +03:00
return malloc(size + 1);
}
void release_objects() {
2021-04-12 12:30:51 +03:00
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);
2021-04-12 12:30:51 +03:00
cvector_pop_back(OBJECTS_TO_RELEASE);
}
}
2021-04-12 11:40:33 +03:00
void add_object_to_release(void *object) {
2021-04-12 12:30:51 +03:00
cvector_push_back(OBJECTS_TO_RELEASE, object);
2019-07-19 15:12:49 +03:00
}
2021-04-12 13:06:11 +03:00
void set_result_ptr(void *ptr) {
2020-09-14 21:00:27 +03:00
RESULT_PTR = ptr;
}
2019-07-19 15:12:49 +03:00
2020-09-14 21:00:27 +03:00
void set_result_size(int size) {
RESULT_SIZE = size;
}
int get_result_size(void) {
return RESULT_SIZE;
}
2019-07-19 15:12:49 +03:00
2021-04-12 13:06:11 +03:00
void *get_result_ptr() {
2020-09-14 21:00:27 +03:00
return RESULT_PTR;
2019-07-19 15:12:49 +03:00
}
2021-03-04 14:04:48 +03:00
2021-04-12 14:45:55 +03:00
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;
}
2021-04-22 19:48:39 +03:00
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;
}
extern void __wasm_call_ctors();
2021-03-04 14:04:48 +03:00
int main() {
__wasm_call_ctors(); // for more details see https://github.com/WebAssembly/WASI/issues/471
2021-03-04 14:04:48 +03:00
return 0;
2021-04-12 12:30:51 +03:00
}