mirror of
https://github.com/fluencelabs/sqlite
synced 2025-07-30 14:51:58 +00:00
port SQLite fork to wasm
This commit is contained in:
13
sdk/allocator.c
Normal file
13
sdk/allocator.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "allocator.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
void *allocate(size_t size) {
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void deallocate(void *ptr, size_t size) {
|
||||
UNUSED(size);
|
||||
free(ptr);
|
||||
}
|
27
sdk/allocator.h
Normal file
27
sdk/allocator.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef C_SDK_ALLOCATOR_H
|
||||
#define C_SDK_ALLOCATOR_H
|
||||
|
||||
#include <stddef.h> // for size_t
|
||||
|
||||
/**
|
||||
* Allocates a memory region of given size.
|
||||
*
|
||||
* Used by Wasm VM for byte array passing. Should be exported from module.
|
||||
*
|
||||
* @param size a size of needed memory region.
|
||||
* @return a pointer to allocated memory region.
|
||||
*/
|
||||
void *allocate(size_t size);
|
||||
|
||||
/**
|
||||
* Frees a memory region.
|
||||
*
|
||||
* Used by Wasm VM for freeing previous memory allocated by `allocate` function.
|
||||
* Should be exported from module.
|
||||
*
|
||||
* @param ptr the pointer to the previously allocated memory region.
|
||||
* @param size the size of the previously allocated memory region.
|
||||
*/
|
||||
void deallocate(void *ptr, size_t size);
|
||||
|
||||
#endif //C_SDK_ALLOCATOR_H
|
15
sdk/logger.c
Normal file
15
sdk/logger.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "logger.h"
|
||||
|
||||
#define __LOGGER_IMPORT(name) \
|
||||
__attribute__((__import_module__("logger"), __import_name__(#name)))
|
||||
|
||||
void __write(char ch) __LOGGER_IMPORT(write);
|
||||
void __flush() __LOGGER_IMPORT(flush);
|
||||
|
||||
void wasm_log(const char *str, int len) {
|
||||
for(int byteId = 0; byteId < len; ++byteId) {
|
||||
__write(str[byteId]);
|
||||
}
|
||||
|
||||
__flush();
|
||||
}
|
11
sdk/logger.h
Normal file
11
sdk/logger.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef C_SDK_LOGGER_H
|
||||
#define C_SDK_LOGGER_H
|
||||
|
||||
/**
|
||||
* Writes provided string to Wasm VM logger.
|
||||
*
|
||||
* @param log_message a message that should be logged.
|
||||
*/
|
||||
void wasm_log(const char *str, int len);
|
||||
|
||||
#endif //C_SDK_LOGGER_H
|
Reference in New Issue
Block a user