aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-wasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/api/sqlite3-wasm.c')
-rw-r--r--ext/wasm/api/sqlite3-wasm.c204
1 files changed, 96 insertions, 108 deletions
diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c
index 7f7e69689..ee8a10209 100644
--- a/ext/wasm/api/sqlite3-wasm.c
+++ b/ext/wasm/api/sqlite3-wasm.c
@@ -14,16 +14,17 @@
*/
#define SQLITE_WASM
#ifdef SQLITE_WASM_ENABLE_C_TESTS
+# undef SQLITE_WASM_ENABLE_C_TESTS
+# define SQLITE_WASM_ENABLE_C_TESTS 1
/*
-** Code blocked off by SQLITE_WASM_TESTS is intended solely for use in
-** unit/regression testing. They may be safely omitted from
+** Code blocked off by SQLITE_WASM_ENABLE_C_TESTS is intended solely
+** for use in unit/regression testing. They may be safely omitted from
** client-side builds. The main unit test script, tester1.js, will
** skip related tests if it doesn't find the corresponding functions
** in the WASM exports.
*/
-# define SQLITE_WASM_TESTS 1
#else
-# define SQLITE_WASM_TESTS 0
+# define SQLITE_WASM_ENABLE_C_TESTS 0
#endif
/*
@@ -92,60 +93,18 @@
#undef SQLITE_ENABLE_API_ARMOR
#define SQLITE_ENABLE_API_ARMOR 1
-#ifndef SQLITE_ENABLE_BYTECODE_VTAB
-# define SQLITE_ENABLE_BYTECODE_VTAB 1
-#endif
-#ifndef SQLITE_ENABLE_DBPAGE_VTAB
-# define SQLITE_ENABLE_DBPAGE_VTAB 1
-#endif
-#ifndef SQLITE_ENABLE_DBSTAT_VTAB
-# define SQLITE_ENABLE_DBSTAT_VTAB 1
-#endif
-#ifndef SQLITE_ENABLE_EXPLAIN_COMMENTS
-# define SQLITE_ENABLE_EXPLAIN_COMMENTS 1
-#endif
-#ifndef SQLITE_ENABLE_FTS5
-# define SQLITE_ENABLE_FTS5 1
-#endif
-#ifndef SQLITE_ENABLE_MATH_FUNCTIONS
-# define SQLITE_ENABLE_MATH_FUNCTIONS 1
-#endif
-#ifndef SQLITE_ENABLE_OFFSET_SQL_FUNC
-# define SQLITE_ENABLE_OFFSET_SQL_FUNC 1
-#endif
-#ifndef SQLITE_ENABLE_PREUPDATE_HOOK
-# define SQLITE_ENABLE_PREUPDATE_HOOK 1 /*required by session extension*/
-#endif
-#ifndef SQLITE_ENABLE_RTREE
-# define SQLITE_ENABLE_RTREE 1
-#endif
-#ifndef SQLITE_ENABLE_SESSION
-# define SQLITE_ENABLE_SESSION 1
-#endif
-#ifndef SQLITE_ENABLE_STMTVTAB
-# define SQLITE_ENABLE_STMTVTAB 1
-#endif
-#ifndef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
-# define SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
-#endif
-
/**********************************************************************/
/* SQLITE_O... */
-#ifndef SQLITE_OMIT_DEPRECATED
-# define SQLITE_OMIT_DEPRECATED 1
-#endif
-#ifndef SQLITE_OMIT_LOAD_EXTENSION
-# define SQLITE_OMIT_LOAD_EXTENSION 1
-#endif
-#ifndef SQLITE_OMIT_SHARED_CACHE
-# define SQLITE_OMIT_SHARED_CACHE 1
-#endif
-#ifndef SQLITE_OMIT_UTF16
-# define SQLITE_OMIT_UTF16 1
-#endif
-#ifndef SQLITE_OS_KV_OPTIONAL
-# define SQLITE_OS_KV_OPTIONAL 1
-#endif
+#undef SQLITE_OMIT_DEPRECATED
+#define SQLITE_OMIT_DEPRECATED 1
+#undef SQLITE_OMIT_LOAD_EXTENSION
+#define SQLITE_OMIT_LOAD_EXTENSION 1
+#undef SQLITE_OMIT_SHARED_CACHE
+#define SQLITE_OMIT_SHARED_CACHE 1
+#undef SQLITE_OMIT_UTF16
+#define SQLITE_OMIT_UTF16 1
+#undef SQLITE_OS_KV_OPTIONAL
+#define SQLITE_OS_KV_OPTIONAL 1
/**********************************************************************/
/* SQLITE_S... */
@@ -169,49 +128,73 @@
#endif
#ifdef SQLITE_WASM_EXTRA_INIT
-# define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init
+/* SQLITE_EXTRA_INIT vs SQLITE_EXTRA_INIT_MUTEXED:
+** see https://sqlite.org/forum/forumpost/14183b98fc0b1dea */
+# define SQLITE_EXTRA_INIT_MUTEXED sqlite3_wasm_extra_init
#endif
/*
-** If SQLITE_WASM_MINIMAL is defined, undefine most of the ENABLE
-** macros.
+** If SQLITE_WASM_BARE_BONES is defined, undefine most of the ENABLE
+** macros. This will, when using the canonical makefile, also elide
+** any C functions from the WASM exports which are listed in
+** ./EXPORT_FUNCTIONS.sqlite3-extras.
*/
-#ifdef SQLITE_WASM_MINIMAL
-# undef SQLITE_ENABLE_DBPAGE_VTAB
-# undef SQLITE_ENABLE_DBSTAT_VTAB
-# undef SQLITE_ENABLE_EXPLAIN_COMMENTS
-# undef SQLITE_ENABLE_FTS5
-# undef SQLITE_ENABLE_OFFSET_SQL_FUNC
-# undef SQLITE_ENABLE_PREUPDATE_HOOK
-# undef SQLITE_ENABLE_RTREE
-# undef SQLITE_ENABLE_SESSION
-# undef SQLITE_ENABLE_STMTVTAB
-# undef SQLITE_OMIT_AUTHORIZATION
+#ifdef SQLITE_WASM_BARE_BONES
+# undef SQLITE_ENABLE_COLUMN_METADATA
+# undef SQLITE_ENABLE_DBPAGE_VTAB
+# undef SQLITE_ENABLE_DBSTAT_VTAB
+# undef SQLITE_ENABLE_EXPLAIN_COMMENTS
+# undef SQLITE_ENABLE_FTS5
+# undef SQLITE_ENABLE_OFFSET_SQL_FUNC
+# undef SQLITE_ENABLE_PREUPDATE_HOOK
+# undef SQLITE_ENABLE_RTREE
+# undef SQLITE_ENABLE_SESSION
+# undef SQLITE_ENABLE_STMTVTAB
+# undef SQLITE_OMIT_AUTHORIZATION
# define SQLITE_OMIT_AUTHORIZATION
-/*Reminder re. custom sqlite3.c:
+# undef SQLITE_OMIT_GET_TABLE
+# define SQLITE_OMIT_GET_TABLE
+# undef SQLITE_OMIT_INCRBLOB
+# define SQLITE_OMIT_INCRBLOB
+# undef SQLITE_OMIT_INTROSPECTION_PRAGMAS
+# define SQLITE_OMIT_INTROSPECTION_PRAGMAS
+# undef SQLITE_OMIT_JSON
+# define SQLITE_OMIT_JSON
+# undef SQLITE_OMIT_PROGRESS_CALLBACK
+# define SQLITE_OMIT_PROGRESS_CALLBACK
+# undef SQLITE_OMIT_WAL
+# define SQLITE_OMIT_WAL
+/*
+ The following OMITs do not work with the standard amalgamation, so
+ require a custom build:
fossil clean -x
./configure
- OPTS='-DSQLITE_OMIT_VIRTUALTABLE -DSQLITE_OMIT_EXPLAIN -DSQLITE_OMIT_TRIGGER' make -e sqlite3
-*/
-/*Requires a custom sqlite3.c
-# undef SQLITE_OMIT_TRIGGER
-# define SQLITE_OMIT_TRIGGER
-*/
-/*TODO (requires build tweaks)
-# undef SQLITE_OMIT_WINDOWFUNC
-# define SQLITE_OMIT_WINDOWFUNC
-*/
-/*Requires a custom sqlite3.c
+ OPTS='...' make -e sqlite3
+
+ where ... has a -D... for each of the following OMIT flags:
+
# undef SQLITE_OMIT_EXPLAIN
# define SQLITE_OMIT_EXPLAIN
-*/
-/*Requires a custom sqlite3.c
+
+# undef SQLITE_OMIT_TRIGGER
+# define SQLITE_OMIT_TRIGGER
+
# undef SQLITE_OMIT_VIRTUALTABLE
# define SQLITE_OMIT_VIRTUALTABLE
+
+# undef SQLITE_OMIT_WINDOWFUNC
+# define SQLITE_OMIT_WINDOWFUNC
+
+ As of this writing (2024-07-25), such a build fails in various ways
+ for as-yet-unknown reasons.
*/
-# undef SQLITE_OMIT_JSON
-# define SQLITE_OMIT_JSON
+#endif
+
+#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_BARE_BONES)
+# define SQLITE_WASM_HAS_VTAB 1
+#else
+# define SQLITE_WASM_HAS_VTAB 0
#endif
#include <assert.h>
@@ -264,10 +247,6 @@
#undef INC__STRINGIFY
#undef SQLITE_C
-#if defined(__EMSCRIPTEN__)
-# include <emscripten/console.h>
-#endif
-
#if 0
/*
** An EXPERIMENT in implementing a stack-based allocator analog to
@@ -310,7 +289,7 @@ SQLITE_WASM_EXPORT void * sqlite3__wasm_stack_alloc(int n){
/*
** State for the "pseudo-stack" allocator implemented in
** sqlite3__wasm_pstack_xyz(). In order to avoid colliding with
-** Emscripten-controled stack space, it carves out a bit of stack
+** Emscripten-controlled stack space, it carves out a bit of stack
** memory to use for that purpose. This memory ends up in the
** WASM-managed memory, such that routines which manipulate the wasm
** heap can also be used to manipulate this memory.
@@ -337,7 +316,7 @@ SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_ptr(void){
return PStack.pPos;
}
/*
-** Sets the pstack position poitner to p. Results are undefined if the
+** Sets the pstack position pointer to p. Results are undefined if the
** given value did not come from sqlite3__wasm_pstack_ptr().
*/
SQLITE_WASM_EXPORT void sqlite3__wasm_pstack_restore(unsigned char * p){
@@ -357,7 +336,6 @@ SQLITE_WASM_EXPORT void sqlite3__wasm_pstack_restore(unsigned char * p){
*/
SQLITE_WASM_EXPORT void * sqlite3__wasm_pstack_alloc(int n){
if( n<=0 ) return 0;
- //if( n & 0x7 ) n += 8 - (n & 0x7) /* align to 8-byte boundary */;
n = (n + 7) & ~7 /* align to 8-byte boundary */;
if( PStack.pBegin + n > PStack.pPos /*not enough space left*/
|| PStack.pBegin + n <= PStack.pBegin /*overflow*/ ) return 0;
@@ -412,7 +390,7 @@ int sqlite3__wasm_db_error(sqlite3*db, int err_code, const char *zMsg){
return err_code;
}
-#if SQLITE_WASM_TESTS
+#if SQLITE_WASM_ENABLE_C_TESTS
struct WasmTestStruct {
int v4;
void * ppV;
@@ -432,7 +410,7 @@ void sqlite3__wasm_test_struct(WasmTestStruct * s){
}
return;
}
-#endif /* SQLITE_WASM_TESTS */
+#endif /* SQLITE_WASM_ENABLE_C_TESTS */
/*
** This function is NOT part of the sqlite3 public API. It is strictly
@@ -623,6 +601,9 @@ const char * sqlite3__wasm_enum_json(void){
DefInt(SQLITE_DBCONFIG_TRUSTED_SCHEMA);
DefInt(SQLITE_DBCONFIG_STMT_SCANSTATUS);
DefInt(SQLITE_DBCONFIG_REVERSE_SCANORDER);
+ DefInt(SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE);
+ DefInt(SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE);
+ DefInt(SQLITE_DBCONFIG_ENABLE_COMMENTS);
DefInt(SQLITE_DBCONFIG_MAX);
} _DefGroup;
@@ -967,7 +948,7 @@ const char * sqlite3__wasm_enum_json(void){
} _DefGroup;
DefGroup(vtab) {
-#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL)
+#if SQLITE_WASM_HAS_VTAB
DefInt(SQLITE_INDEX_SCAN_UNIQUE);
DefInt(SQLITE_INDEX_CONSTRAINT_EQ);
DefInt(SQLITE_INDEX_CONSTRAINT_GT);
@@ -995,7 +976,7 @@ const char * sqlite3__wasm_enum_json(void){
DefInt(SQLITE_FAIL);
//DefInt(SQLITE_ABORT); // Also an error code
DefInt(SQLITE_REPLACE);
-#endif /*!SQLITE_OMIT_VIRTUALTABLE*/
+#endif /*SQLITE_WASM_HAS_VTAB*/
} _DefGroup;
#undef DefGroup
@@ -1004,7 +985,7 @@ const char * sqlite3__wasm_enum_json(void){
#undef _DefGroup
/*
- ** Emit an array of "StructBinder" struct descripions, which look
+ ** Emit an array of "StructBinder" struct descriptions, which look
** like:
**
** {
@@ -1110,6 +1091,7 @@ const char * sqlite3__wasm_enum_json(void){
#undef CurrentStruct
+#if SQLITE_WASM_HAS_VTAB
#define CurrentStruct sqlite3_vtab
StructBinder {
M(pModule, "p");
@@ -1155,7 +1137,6 @@ const char * sqlite3__wasm_enum_json(void){
} _StructBinder;
#undef CurrentStruct
-#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL)
/**
** Workaround: in order to map the various inner structs from
** sqlite3_index_info, we have to uplift those into constructs we
@@ -1179,7 +1160,7 @@ const char * sqlite3__wasm_enum_json(void){
{ /* Validate that the above struct sizeof()s match
** expectations. We could improve upon this by
** checking the offsetof() for each member. */
- const sqlite3_index_info siiCheck;
+ const sqlite3_index_info siiCheck = {0};
#define IndexSzCheck(T,M) \
(sizeof(T) == sizeof(*siiCheck.M))
if(!IndexSzCheck(sqlite3_index_constraint,aConstraint)
@@ -1232,9 +1213,9 @@ const char * sqlite3__wasm_enum_json(void){
} _StructBinder;
#undef CurrentStruct
-#endif /*!SQLITE_OMIT_VIRTUALTABLE*/
+#endif /*SQLITE_WASM_HAS_VTAB*/
-#if SQLITE_WASM_TESTS
+#if SQLITE_WASM_ENABLE_C_TESTS
#define CurrentStruct WasmTestStruct
StructBinder {
M(v4, "i");
@@ -1244,7 +1225,7 @@ const char * sqlite3__wasm_enum_json(void){
M(xFunc, "v(p)");
} _StructBinder;
#undef CurrentStruct
-#endif
+#endif /*SQLITE_WASM_ENABLE_C_TESTS*/
} out( "]"/*structs*/);
@@ -1441,7 +1422,7 @@ int sqlite3__wasm_db_serialize( sqlite3 *pDb, const char *zSchema,
** NULL), or nData is negative, SQLITE_MISUSE are returned.
**
** On success, it creates a new file with the given name, populated
-** with the fist nData bytes of pData. If pData is NULL, the file is
+** with the first nData bytes of pData. If pData is NULL, the file is
** created and/or truncated to nData bytes.
**
** Whether or not directory components of zFilename are created
@@ -1603,7 +1584,7 @@ sqlite3_kvvfs_methods * sqlite3__wasm_kvvfs_methods(void){
return &sqlite3KvvfsMethods;
}
-#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL)
+#if SQLITE_WASM_HAS_VTAB
/*
** This function is NOT part of the sqlite3 public API. It is strictly
** for use by the sqlite project's own JS/WASM bindings.
@@ -1626,7 +1607,7 @@ int sqlite3__wasm_vtab_config(sqlite3 *pDb, int op, int arg){
return SQLITE_MISUSE;
}
}
-#endif /*!SQLITE_OMIT_VIRTUALTABLE*/
+#endif /*SQLITE_WASM_HAS_VTAB*/
/*
** This function is NOT part of the sqlite3 public API. It is strictly
@@ -1656,6 +1637,9 @@ int sqlite3__wasm_db_config_ip(sqlite3 *pDb, int op, int arg1, int* pArg2){
case SQLITE_DBCONFIG_TRUSTED_SCHEMA:
case SQLITE_DBCONFIG_STMT_SCANSTATUS:
case SQLITE_DBCONFIG_REVERSE_SCANORDER:
+ case SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE:
+ case SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE:
+ case SQLITE_DBCONFIG_ENABLE_COMMENTS:
return sqlite3_db_config(pDb, op, arg1, pArg2);
default: return SQLITE_MISUSE;
}
@@ -1750,6 +1734,7 @@ char * sqlite3__wasm_qfmt_token(char *z, int addQuotes){
}
#if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS)
+#include <emscripten/console.h>
#include <emscripten/wasmfs.h>
/*
@@ -1801,7 +1786,7 @@ int sqlite3__wasm_init_wasmfs(const char *zUnused){
}
#endif /* __EMSCRIPTEN__ && SQLITE_ENABLE_WASMFS */
-#if SQLITE_WASM_TESTS
+#if SQLITE_WASM_ENABLE_C_TESTS
SQLITE_WASM_EXPORT
int sqlite3__wasm_test_intptr(int * p){
@@ -1967,6 +1952,9 @@ int sqlite3__wasm_SQLTester_strglob(const char *zGlob, const char *z){
return !sqlite3__wasm_SQLTester_strnotglob(zGlob, z);
}
-#endif /* SQLITE_WASM_TESTS */
+#endif /* SQLITE_WASM_ENABLE_C_TESTS */
#undef SQLITE_WASM_EXPORT
+#undef SQLITE_WASM_HAS_VTAB
+#undef SQLITE_WASM_BARE_BONES
+#undef SQLITE_WASM_ENABLE_C_TESTS