SQLite Forum

[PATCH] Add SQLITE_ENABLE_CARRAY
Login

[PATCH] Add SQLITE_ENABLE_CARRAY

(1.1) By Arfrever Frehtes Taifersar Arahesis (Arfrever) on 2020-06-30 00:17:03 edited from 1.0 [source]

I maintain SQLite package in Gentoo and I would like to reduce amount of necessary patching.
I would like to enable some extensions in libsqlite3.so library (some of those which only add additional features (usually functions) and have no incompatible effect on behavior) (e.g. carray, csv, dbdata, eval, fileio, ieee754, regexp, sha1, shathree, totype, uint, uuid).

This can be done by supporting new SQLITE_ENABLE_* macros, which would be disabled by default.

Is there chance that any new proposed macros will be accepted?
(I can provide similar patches adding other macros.)

The following patch adds SQLITE_ENABLE_CARRAY macro, which enables carray extension with carray function.
(Patch written exclusively by me and provided in public domain.)


Index: Makefile.in
==================================================================
--- Makefile.in
+++ Makefile.in
@@ -363,10 +363,11 @@
   $(TOP)/ext/userauth/sqlite3userauth.h
 SRC += \
   $(TOP)/ext/rbu/sqlite3rbu.h \
   $(TOP)/ext/rbu/sqlite3rbu.c
 SRC += \
+  $(TOP)/ext/misc/carray.c \
   $(TOP)/ext/misc/json1.c \
   $(TOP)/ext/misc/stmt.c
 
 # Generated source code files
 #
@@ -438,11 +439,10 @@
 #
 TESTSRC += \
   $(TOP)/ext/expert/sqlite3expert.c \
   $(TOP)/ext/expert/test_expert.c \
   $(TOP)/ext/misc/amatch.c \
-  $(TOP)/ext/misc/carray.c \
   $(TOP)/ext/misc/closure.c \
   $(TOP)/ext/misc/csv.c \
   $(TOP)/ext/misc/decimal.c \
   $(TOP)/ext/misc/eval.c \
   $(TOP)/ext/misc/explain.c \

Index: Makefile.msc
==================================================================
--- Makefile.msc
+++ Makefile.msc
@@ -1440,10 +1440,11 @@
   $(TOP)\ext\fts3\fts3_write.c \
   $(TOP)\ext\icu\icu.c \
   $(TOP)\ext\rtree\rtree.c \
   $(TOP)\ext\session\sqlite3session.c \
   $(TOP)\ext\rbu\sqlite3rbu.c \
+  $(TOP)\ext\misc\carray.c \
   $(TOP)\ext\misc\json1.c \
   $(TOP)\ext\misc\stmt.c
 
 # Extension header files, part 1.
 #
@@ -1555,11 +1556,10 @@
 #
 TESTEXT = \
   $(TOP)\ext\expert\sqlite3expert.c \
   $(TOP)\ext\expert\test_expert.c \
   $(TOP)\ext\misc\amatch.c \
-  $(TOP)\ext\misc\carray.c \
   $(TOP)\ext\misc\closure.c \
   $(TOP)\ext\misc\csv.c \
   $(TOP)\ext\misc\decimal.c \
   $(TOP)\ext\misc\eval.c \
   $(TOP)\ext\misc\explain.c \

Index: ext/misc/carray.c
==================================================================
--- ext/misc/carray.c
+++ ext/misc/carray.c
@@ -50,10 +50,11 @@
 ** the virtual table has no rows.  Otherwise, the virtual table interprets
 ** the integer value of "pointer" as a pointer to the array and "count"
 ** as the number of elements in the array.  The virtual table steps through
 ** the array, element by element.
 */
+#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_CARRAY)
 #include "sqlite3ext.h"
 SQLITE_EXTENSION_INIT1
 #include <assert.h>
 #include <string.h>
 
@@ -381,20 +382,12 @@
 }
 #endif /* SQLITE_TEST */
 
 #endif /* SQLITE_OMIT_VIRTUALTABLE */
 
-#ifdef _WIN32
-__declspec(dllexport)
-#endif
-int sqlite3_carray_init(
-  sqlite3 *db, 
-  char **pzErrMsg, 
-  const sqlite3_api_routines *pApi
-){
+int sqlite3CarrayInit(sqlite3 *db){
   int rc = SQLITE_OK;
-  SQLITE_EXTENSION_INIT2(pApi);
 #ifndef SQLITE_OMIT_VIRTUALTABLE
   rc = sqlite3_create_module(db, "carray", &carrayModule, 0);
 #ifdef SQLITE_TEST
   if( rc==SQLITE_OK ){
     rc = sqlite3_create_function(db, "inttoptr", 1, SQLITE_UTF8, 0,
@@ -402,5 +395,21 @@
   }
 #endif /* SQLITE_TEST */
 #endif /* SQLITE_OMIT_VIRTUALTABLE */
   return rc;
 }
+
+#ifndef SQLITE_CORE
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int sqlite3_carray_init(
+  sqlite3 *db, 
+  char **pzErrMsg, 
+  const sqlite3_api_routines *pApi
+){
+  SQLITE_EXTENSION_INIT2(pApi);
+  (void)pzErrMsg;  /* Unused parameter */
+  return sqlite3CarrayInit(db);
+}
+#endif
+#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_CARRAY) */

Index: main.mk
==================================================================
--- main.mk
+++ main.mk
@@ -241,10 +241,11 @@
   $(TOP)/ext/userauth/sqlite3userauth.h
 SRC += \
   $(TOP)/ext/rbu/sqlite3rbu.c \
   $(TOP)/ext/rbu/sqlite3rbu.h
 SRC += \
+  $(TOP)/ext/misc/carray.c \
   $(TOP)/ext/misc/json1.c \
   $(TOP)/ext/misc/stmt.c
 
 
 # FTS5 things
@@ -358,11 +359,10 @@
 
 # Extensions to be statically loaded.
 #
 TESTSRC += \
   $(TOP)/ext/misc/amatch.c \
-  $(TOP)/ext/misc/carray.c \
   $(TOP)/ext/misc/closure.c \
   $(TOP)/ext/misc/csv.c \
   $(TOP)/ext/misc/decimal.c \
   $(TOP)/ext/misc/eval.c \
   $(TOP)/ext/misc/explain.c \

Index: src/ctime.c
==================================================================
--- src/ctime.c
+++ src/ctime.c
@@ -193,10 +193,13 @@
 #if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
   "ENABLE_BATCH_ATOMIC_WRITE",
 #endif
 #if SQLITE_ENABLE_BYTECODE_VTAB
   "ENABLE_BYTECODE_VTAB",
+#endif
+#if SQLITE_ENABLE_CARRAY
+  "ENABLE_CARRAY",
 #endif
 #if SQLITE_ENABLE_CEROD
   "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
 #endif
 #if SQLITE_ENABLE_COLUMN_METADATA

Index: src/main.c
==================================================================
--- src/main.c
+++ src/main.c
@@ -39,10 +39,13 @@
 
 /*
 ** Forward declarations of external module initializer functions
 ** for modules that need them.
 */
+#ifdef SQLITE_ENABLE_CARRAY
+int sqlite3CarrayInit(sqlite3*);
+#endif
 #ifdef SQLITE_ENABLE_FTS1
 int sqlite3Fts1Init(sqlite3*);
 #endif
 #ifdef SQLITE_ENABLE_FTS2
 int sqlite3Fts2Init(sqlite3*);
@@ -60,10 +63,13 @@
 /*
 ** An array of pointers to extension initializer functions for
 ** built-in extensions.
 */
 static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = {
+#ifdef SQLITE_ENABLE_CARRAY
+  sqlite3CarrayInit,
+#endif
 #ifdef SQLITE_ENABLE_FTS1
   sqlite3Fts1Init,
 #endif
 #ifdef SQLITE_ENABLE_FTS2
   sqlite3Fts2Init,

Index: tool/mksqlite3c.tcl
==================================================================
--- tool/mksqlite3c.tcl
+++ tool/mksqlite3c.tcl
@@ -392,10 +392,11 @@
    fts3_write.c
    fts3_snippet.c
    fts3_unicode.c
    fts3_unicode2.c
 
+   carray.c
    json1.c
    rtree.c
    icu.c
    fts3_icu.c
    sqlite3rbu.c