From cc65612e35a677dc7252229dadaba92b6d3997b0 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 25 Jul 2024 10:50:45 +0000 Subject: [PATCH 01/50] Start work on an overhaul of the wasm build process, with an eye towards less over-engineering. FossilOrigin-Name: ed746b3dd3248b68cb91de50ac5ba5fd3a7c2fcbde76324e86b88edbfecd896b --- ext/wasm/GNUmakefile | 138 +++++------------- ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-auth | 1 - ...sion => EXPORTED_FUNCTIONS.sqlite3-extras} | 18 +++ .../api/EXPORTED_FUNCTIONS.sqlite3-preupdate | 6 - ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-vtab | 11 -- ext/wasm/api/sqlite3-api-glue.c-pp.js | 2 +- ext/wasm/make-make.sh | 84 +++++++++++ ext/wasm/tester1.c-pp.js | 12 +- ext/wasm/wasmfs.make | 7 - manifest | 27 ++-- manifest.uuid | 2 +- 11 files changed, 157 insertions(+), 151 deletions(-) delete mode 100644 ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-auth rename ext/wasm/api/{EXPORTED_FUNCTIONS.sqlite3-session => EXPORTED_FUNCTIONS.sqlite3-extras} (72%) delete mode 100644 ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-preupdate delete mode 100644 ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-vtab create mode 100755 ext/wasm/make-make.sh diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 51531627b9..2d5abebc46 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -54,6 +54,7 @@ MAKEFILE := $(lastword $(MAKEFILE_LIST)) CLEAN_FILES := DISTCLEAN_FILES := ./--dummy-- release: oz +MAKING_CLEAN := $(if $(filter %clean,$(MAKECMDGOALS)),1,0) ######################################################################## # JS_BUILD_NAMES exists for documentation purposes only. It enumerates @@ -86,46 +87,6 @@ JS_BUILD_NAMES := sqlite3 sqlite3-wasmfs # JS_BUILD_MODES := vanilla esm bunder-friendly node -######################################################################## -# Emscripten SDK home dir and related binaries... -EMSDK_HOME ?= $(word 1,$(wildcard $(HOME)/emsdk $(HOME)/src/emsdk)) -emcc.bin ?= $(word 1,$(wildcard $(EMSDK_HOME)/upstream/emscripten/emcc) $(shell which emcc)) -ifeq (,$(emcc.bin)) - $(error Cannot find emcc.) -endif -emcc.version := $(shell "$(emcc.bin)" --version | sed -n 1p \ - | sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;') -ifeq (,$(emcc.version)) - $(warning Cannot determine emcc version. This might unduly impact build flags.) -else - $(info using emcc version [$(emcc.version)]) -endif - -wasm-strip ?= $(shell which wasm-strip 2>/dev/null) -ifeq (,$(filter clean,$(MAKECMDGOALS))) -ifeq (,$(wasm-strip)) - $(info WARNING: *******************************************************************) - $(info WARNING: builds using -O2/-O3/-Os/-Oz will minify WASM-exported names,) - $(info WARNING: breaking _All The Things_. The workaround for that is to build) - $(info WARNING: with -g3 (which explodes the file size) and then strip the debug) - $(info WARNING: info after compilation, using wasm-strip, to shrink the wasm file.) - $(info WARNING: wasm-strip was not found in the PATH so we cannot strip those.) - $(info WARNING: If this build uses any optimization level higher than -O1 then) - $(info WARNING: the ***resulting JS code WILL NOT BE USABLE***.) - $(info WARNING: wasm-strip is part of the wabt package:) - $(info WARNING: https://github.com/WebAssembly/wabt) - $(info WARNING: on Ubuntu-like systems it can be installed with:) - $(info WARNING: sudo apt install wabt) - $(info WARNING: *******************************************************************) -endif -endif # 'make clean' check - -ifeq (,$(wasm-strip)) - maybe-wasm-strip = echo "not wasm-stripping" -else - maybe-wasm-strip = $(wasm-strip) -endif - ######################################################################## # dir.top = the top dir of the canonical build tree, where # sqlite3.[ch] live. @@ -141,41 +102,16 @@ dir.common := common dir.fiddle := fiddle dir.fiddle-debug := fiddle-debug dir.tool := $(dir.top)/tool -CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \ - $(dir.fiddle-debug)/* - -######################################################################## -# dir.dout = output dir for deliverables. +# Maintenance reminder: the names of $(dir.dout) and $(dir.tmp) must +# stay in sync with make-make.sh # -# MAINTENANCE REMINDER: the output .js and .wasm files of certain emcc -# buildables must be in _this_ dir, rather than a subdir, or else -# parts of the generated code get confused and cannot load -# property. Specifically, when X.js loads X.wasm, whether or not X.js -# uses the correct path for X.wasm depends on how it's loaded: an HTML -# script tag will resolve it intuitively, whereas a Worker's call to -# importScripts() will not. That's a fundamental incompatibility with -# how URL resolution in JS happens between those two contexts. See: -# -# https://zzz.buzz/2017/03/14/relative-uris-in-web-development/ -# -# We unfortunately have no way, from Worker-initiated code, to -# automatically resolve the path from X.js to X.wasm. -# -# We have an "only slightly unsightly" solution for our main builds -# but it does not work for the WASMFS builds, so those builds have to -# be built to _this_ directory and can only run when the client app is -# loaded from the same directory. -dir.dout := $(dir.wasm)/jswasm # dir.tmp = output dir for intermediary build files, as opposed to # end-user deliverables. +dir.dout := $(dir.wasm)/jswasm +# dir.dout = output dir for deliverables dir.tmp := $(dir.wasm)/bld -CLEAN_FILES += $(dir.tmp)/* $(dir.dout)/* -ifeq (,$(wildcard $(dir.dout))) - dir._tmp := $(shell mkdir -p $(dir.dout)) -endif -ifeq (,$(wildcard $(dir.tmp))) - dir._tmp := $(shell mkdir -p $(dir.tmp)) -endif +CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \ + $(dir.fiddle-debug)/* $(dir.dout)/* $(dir.tmp)/* ######################################################################## # Set up sqlite3.c and sqlite3.h... @@ -197,18 +133,33 @@ endif sqlite3.canonical.c := $(dir.top)/sqlite3.c sqlite3.c ?= $(firstword $(wildcard $(dir.top)/sqlite3-see.c) $(sqlite3.canonical.c)) sqlite3.h := $(dir.top)/sqlite3.h -ifeq (,$(shell grep sqlite3_activate_see $(sqlite3.c) 2>/dev/null)) - SQLITE_C_IS_SEE := 0 -else - SQLITE_C_IS_SEE := 1 - $(info This is an SEE build.) + +########################################################################@ +# It's important that sqlite3.h be built to completion before any +# other parts of the build run, thus we use .NOTPARALLEL to disable +# parallel build of that file and its dependants. +.NOTPARALLEL: $(sqlite3.h) +$(sqlite3.h): + $(MAKE) -C $(dir.top) sqlite3.c +$(sqlite3.c): $(sqlite3.h) + +# .cache.make is generated by a shell script and holds certain parts +# of the makefile, some of which are relatively expensive to calculate +# on each run (that is, they can take a human-visible amount of time). +ifeq (0,$(MAKING_CLEAN)) +.cache.make: $(sqlite3.c) $(sqlite3.canonical.c) $(MAKEFILE) make-make.sh + rm -f $@ + $(SHELL) make-make.sh "$(sqlite3.c)" > $@ + chmod -w $@ +-include .cache.make +.cache.make: $(emcc.bin) endif -# Most SQLITE_OPT flags are set in sqlite3-wasm.c but we need them -# made explicit here for building speedtest1.c. +CLEAN_FILES += .cache.make + +# Common options for building sqlite3-wasm.c and speedtest1.c. SQLITE_OPT = \ -DSQLITE_ENABLE_FTS5 \ -DSQLITE_ENABLE_RTREE \ - -DSQLITE_ENABLE_EXPLAIN_COMMENTS \ -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \ -DSQLITE_ENABLE_STMTVTAB \ -DSQLITE_ENABLE_DBPAGE_VTAB \ @@ -241,15 +192,6 @@ ifeq (1,$(minimal)) SQLITE_OPT += -DSQLITE_WASM_MINIMAL endif -########################################################################@ -# It's important that sqlite3.h be built to completion before any -# other parts of the build run, thus we use .NOTPARALLEL to disable -# parallel build of that file and its dependants. -.NOTPARALLEL: $(sqlite3.h) -$(sqlite3.h): - $(MAKE) -C $(dir.top) sqlite3.c -$(sqlite3.c): $(sqlite3.h) - .PHONY: clean distclean clean: -rm -f $(CLEAN_FILES) @@ -371,7 +313,7 @@ define C-PP.FILTER # $3 = optional c-pp -D... flags $(2): $(1) $$(MAKEFILE) $$(bin.c-pp) $$(bin.c-pp) -f $(1) -o $$@ $(3) $(C-PP.FILTER.global) -CLEAN_FILES += $(2) +#CLEAN_FILES += $(2) endef # /end C-PP.FILTER ######################################################################## @@ -421,17 +363,13 @@ emcc_opt_full := $(emcc_opt) -g3 ######################################################################## # EXPORTED_FUNCTIONS.* = files for use with Emscripten's # -sEXPORTED_FUNCTION flag. -EXPORTED_FUNCTIONS.api.core := $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core) +EXPORTED_FUNCTIONS.api.core := $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.core) ifeq (1,$(SQLITE_C_IS_SEE)) - EXPORTED_FUNCTIONS.api.in += $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see) + EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see endif ifeq (0,$(minimal)) - EXPORTED_FUNCTIONS.api.in += \ - $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-auth) \ - $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-preupdate) \ - $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-session) \ - $(abspath $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-vtab) + EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras else $(info ========================================) $(info This is a minimal-mode build) @@ -906,7 +844,7 @@ $(5): $(4) $$(MAKEFILE) $$(sqlite3-wasm.cfiles) $$(EXPORTED_FUNCTIONS.api) $$(pr ls -la $$$$dotwasm $$@ all: $(5) #quick: $(5) -CLEAN_FILES += $(4) $(5) +#CLEAN_FILES += $(4) $(5) endef # ^^^ /SETUP_LIB_BUILD_MODE ######################################################################## @@ -962,7 +900,7 @@ $(sqlite3.wasm): $(sqlite3.js) $(sqlite3.mjs): $(sqlite3.js) $(sqlite3-bundler-friendly.mjs): $(sqlite3.mjs) $(sqlite3-node.mjs): $(sqlite3.mjs) -CLEAN_FILES += $(sqlite3.wasm) +#CLEAN_FILES += $(sqlite3.wasm) ######################################################################## # We need separate copies of certain supplementary JS files for the @@ -1106,7 +1044,7 @@ $(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \ speedtest1: $(speedtest1.js) all: speedtest1 -CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm) +#CLEAN_FILES += $(speedtest1.js) $(speedtest1.wasm) # end speedtest1.js ######################################################################## @@ -1174,7 +1112,7 @@ wasmfs.enable ?= 1 else # Unconditionally enable wasmfs for [dist]clean so that the wasmfs # sub-make can clean up. -wasmfs.enable ?= $(if $(filter %clean,$(MAKECMDGOALS)),1,0) +wasmfs.enable ?= $(MAKING_CLEAN) endif ifeq (1,$(wasmfs.enable)) # wasmfs build disabled 2022-10-19 per /chat discussion. diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-auth b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-auth deleted file mode 100644 index 085090821b..0000000000 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-auth +++ /dev/null @@ -1 +0,0 @@ -_sqlite3_set_authorizer diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras similarity index 72% rename from ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session rename to ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras index 5b7b53f952..f8af685ed7 100644 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session +++ b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras @@ -1,3 +1,10 @@ +_sqlite3_set_authorizer +_sqlite3_preupdate_blobwrite +_sqlite3_preupdate_count +_sqlite3_preupdate_depth +_sqlite3_preupdate_hook +_sqlite3_preupdate_new +_sqlite3_preupdate_old _sqlite3changegroup_add _sqlite3changegroup_add_strm _sqlite3changegroup_delete @@ -40,3 +47,14 @@ _sqlite3session_object_config _sqlite3session_patchset _sqlite3session_patchset_strm _sqlite3session_table_filter +_sqlite3_create_module +_sqlite3_create_module_v2 +_sqlite3_declare_vtab +_sqlite3_vtab_collation +_sqlite3_vtab_distinct +_sqlite3_vtab_in +_sqlite3_vtab_in_first +_sqlite3_vtab_in_next +_sqlite3_vtab_nochange +_sqlite3_vtab_on_conflict +_sqlite3_vtab_rhs_value diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-preupdate b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-preupdate deleted file mode 100644 index 5c57a76b60..0000000000 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-preupdate +++ /dev/null @@ -1,6 +0,0 @@ -_sqlite3_preupdate_blobwrite -_sqlite3_preupdate_count -_sqlite3_preupdate_depth -_sqlite3_preupdate_hook -_sqlite3_preupdate_new -_sqlite3_preupdate_old diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-vtab b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-vtab deleted file mode 100644 index 1f6de96823..0000000000 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-vtab +++ /dev/null @@ -1,11 +0,0 @@ -_sqlite3_create_module -_sqlite3_create_module_v2 -_sqlite3_declare_vtab -_sqlite3_vtab_collation -_sqlite3_vtab_distinct -_sqlite3_vtab_in -_sqlite3_vtab_in_first -_sqlite3_vtab_in_next -_sqlite3_vtab_nochange -_sqlite3_vtab_on_conflict -_sqlite3_vtab_rhs_value diff --git a/ext/wasm/api/sqlite3-api-glue.c-pp.js b/ext/wasm/api/sqlite3-api-glue.c-pp.js index e5eb0cfeb6..55dd300d74 100644 --- a/ext/wasm/api/sqlite3-api-glue.c-pp.js +++ b/ext/wasm/api/sqlite3-api-glue.c-pp.js @@ -336,7 +336,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }/* sqlite3_set_authorizer() */ if(false && wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){ - /* ^^^ "the problem" is that this is an option feature and the + /* ^^^ "the problem" is that this is an optional feature and the build-time function-export list does not currently take optional features into account. */ wasm.bindingSignatures.push(["sqlite3_normalized_sql", "string", "sqlite3_stmt*"]); diff --git a/ext/wasm/make-make.sh b/ext/wasm/make-make.sh new file mode 100755 index 0000000000..e5b81b3d12 --- /dev/null +++ b/ext/wasm/make-make.sh @@ -0,0 +1,84 @@ +#!/usr/bin/bash +######################################################################## +# Emits the makefile code for .cache.make. Any makefile bits which are +# potentially expensive to calculate on every build but rarely change +# should be emitted from here. +# +# Arguments: +# +# $1 = path to sqlite3.c. Default: ../../sqlite3.c +# +######################################################################## + +function die(){ + local rc=$1 + shift + echo "\$(error $0 failed: $@)" + # ^^^ Ensure that if this output is being redirected, the + # resulting makefile will fail loudly instead of just being + # truncated. + echo "Error: $@" 1>&2 + exit $rc +} + +SQLITE3_C="${1-../../sqlite3.c}" + +echo "# GENERATED makefile code. DO NOT EDIT." + +if grep sqlite3_activate_see "$SQLITE3_C" &>/dev/null; then + echo 'SQLITE_C_IS_SEE := 1' + echo '$(info This is an SEE build)' +else + echo 'SQLITE_C_IS_SEE := 0' +fi + +######################################################################## +# Locate the emcc (Emscripten) binary... +EMCC_BIN=$(which emcc) +if [[ x = "x${EMCC_BIN}" ]]; then + if [[ x != "x${EMSDK_HOME}" ]]; then + EMCC_BIN="${EMSDK_HOME}/upstream/emscripten/emcc" + fi +fi +if [[ x = "x${EMCC_BIN}" ]]; then + die 1 "Cannot find emcc binary in PATH or EMSDK_HOME." +fi +[[ -x "${EMCC_BIN}" ]] || die 1 "emcc is not executable" +echo "emcc.bin := ${EMCC_BIN}" +echo "emcc.version :=" $("${EMCC_BIN}" --version | sed -n 1p \ + | sed -e 's/^.* \([3-9][^ ]*\) .*$/\1/;') +echo '$(info using emcc version [$(emcc.version)])' + +######################################################################### +# wasm-strip binary... +WASM_STRIP_BIN=$(which wasm-strip 2>/dev/null) +echo "wasm-strip ?= ${WASM_STRIP_BIN}" +if [[ x = "x${WASM_STRIP_BIN}" ]]; then +cat <wasm.compileOptionUsed('ENABLE_FTS5') || "FTS5 is not available", test: function(sqlite3){ // Testing https://sqlite.org/forum/forumpost/40ce55bdf5 // with the exception that that post uses "external content" diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index 71c0fe75a8..2bd7a0700b 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -14,11 +14,6 @@ sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm -CLEAN_FILES += $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.wasm) \ - $(subst .js,.worker.js,$(sqlite3-wasmfs.js)) \ - $(sqlite3-wasmfs.mjs) \ - $(subst .mjs,.worker.mjs,$(sqlite3-wasmfs.mjs)) - ######################################################################## # emcc flags for .c/.o. cflags.sqlite3-wasmfs := @@ -109,7 +104,5 @@ $(speedtest1-wasmfs.mjs): $(speedtest1.cfiles) $(sqlite3-wasmfs.js) \ ls -la $@ $(speedtest1-wasmfs.wasm) wasmfs: $(speedtest1-wasmfs.mjs) -CLEAN_FILES += $(speedtest1-wasmfs.mjs) $(speedtest1-wasmfs.wasm) \ - $(subst .js,.worker.js,$(speedtest1-wasmfs.mjs)) # end speedtest1.js ######################################################################## diff --git a/manifest b/manifest index 608c658c9e..f53748e088 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C wasm\sminimal\sbuild:\sstrip\sauthorizers\sand\sJSON\ssupport\s(saves\sapprox\s35kb).\sStrip\svtab\ssupport\sfrom\sthe\sJS\sbits\sbut\scannot\syet\sstrip\sit\sfrom\sthe\sC\sbits\sbecause\sthat\srequires\sa\scustom-configured\ssqlite3.c. -D 2024-07-24T23:58:28.415 +C Start\swork\son\san\soverhaul\sof\sthe\swasm\sbuild\sprocess,\swith\san\seye\stowards\sless\sover-engineering. +D 2024-07-25T10:50:45.547 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -593,7 +593,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile d4f6586d9a36ee2869a8c7f77227a8b7f42b6c4623f3be594beafb1554ab20d9 +F ext/wasm/GNUmakefile 2037399f1a33f8c0bab52e5aba78d4c6b6d9fb8d905ddf5fc3dd10f2a6fdb494 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -601,12 +601,9 @@ F ext/wasm/SQLTester/SQLTester.mjs ce765c0ad7d57f93553d12ef4dca574deb00300134a26 F ext/wasm/SQLTester/SQLTester.run.mjs c72b7fe2072d05992f7a3d8c6a1d34e95712513ceabe40849784e24e41c84638 F ext/wasm/SQLTester/index.html 3f8a016df0776be76605abf20e815ecaafbe055abac0e1fe5ea080e7846b760d F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f3038b96460fc5e5aa7e536 -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-auth 7ac80cc3b6a6d52e041bb295e85555ce797be78c15ef2008a64ae58815014080 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core 400213eb52a7e5ad5f448053d375cacf4dac2cf45d134f3edfe485ae4a49a183 -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-preupdate d1d62a2212099f2c0782d730beb8cb84a7a52d99c15ead2cb9b1411fff5fd6b1 +F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras e9a42a86d1e09cfd46fd22438e0cb9449e6eae2eff39597cdc834c183775286a w ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session 213b6c04267cb9bd760172db011eb1650732805fb3d01f9395478a8ceec18eb0 -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-vtab fd57af1f4502a052be27d8402df74be1dc60fcb6a687d372972abd90e424120a F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 34fe11466f9c1d81b10a0469e1114e5f1c5a6365c73d80a1a6ca639a1a358b73 F ext/wasm/api/extern-post-js.c-pp.js c4154a7f90c2d7e51fd6738273908152036c3457fdc0b6523f1be3ef51105aac @@ -615,7 +612,7 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.c-pp.js 54b32b5321105a72d6f3d3e8b77f28f162d0367b08c63184263d3f85f3d7dbed +F ext/wasm/api/sqlite3-api-glue.c-pp.js 30abfbb9ed4b6732e2fd78dbfedee5f8d7a395a6d38f140f8df19bd9c30b4191 F ext/wasm/api/sqlite3-api-oo1.c-pp.js f3a8e2004c6625d17946c11f2fb32008be78bc5207bf746fc77d59848813225f F ext/wasm/api/sqlite3-api-prologue.js 6f1257e04885632ed9f44d43aba200b86e0bc16709ffdba29abbbeb1bc8e8b76 F ext/wasm/api/sqlite3-api-worker1.c-pp.js 5cc22a3c0d52828cb32aad8691488719f47d27567e63e8bc8b832d74371c352d @@ -656,6 +653,7 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 +F ext/wasm/make-make.sh 93fa6d00f0ffa3481badd068b8da8ed5825cf74999d5e54b2a0c9b90579a3056 x F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -671,11 +669,11 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js a88b9c669715adc1c5e76750ca8c0994ae33d04572e3bf295b6f4f5870f3bdf3 +F ext/wasm/tester1.c-pp.js b5a126b7ae3f3b5628e74ca806f65394f309326dd518831b2186f88850439be2 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 -F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966f1bc16a +F ext/wasm/wasmfs.make e508db7fb82653a9c9d3c7f4e2c75010abfdefa5c413a9603a2c59547bec8709 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 @@ -2199,8 +2197,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ee2191f7302210100fa0b29ace8156531ad995bf61aa2642e526e0901d0c6862 -R 72e8c79f1e4399a95154f130ea5870d2 +P eb64d106551718467e0f6c6b53695410bf4c566901008e4cda8580d0f7efa7b0 +R 5dcb0158c3e9e326c7d4eacaa8552ecf +T *branch * wasm-build-rework +T *sym-wasm-build-rework * +T -sym-trunk * Cancelled\sby\sbranch. U stephan -Z 427f56307156eafbb2685aac023af7a2 +Z 6b2b2a8483fc393f764799aae3eb47aa # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 01abe9750d..9d68627d41 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eb64d106551718467e0f6c6b53695410bf4c566901008e4cda8580d0f7efa7b0 +ed746b3dd3248b68cb91de50ac5ba5fd3a7c2fcbde76324e86b88edbfecd896b From 520d1a84867fa59e063b66a276471cbfc9f6cef5 Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 25 Jul 2024 14:00:26 +0000 Subject: [PATCH 02/50] More work on the minimal-mode wasm build (now 603kb uncompressed). Remove the hard-coded feature-enable flags from sqlite3-wasm.c and rely on the build to provide them. Some wasm build cleanup, but attempts to completely overhaul it have been thwarted by my inability to make script-generated makefile code more legible/maintainable than the current eval spaghetti. FossilOrigin-Name: b029c4067943e366a9b25b8303136fab10822bd771ea4658ac4cd716ff4a0d8f --- ext/wasm/GNUmakefile | 93 +++++++++++-------- ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core | 1 - .../api/EXPORTED_FUNCTIONS.sqlite3-extras | 1 + ext/wasm/api/sqlite3-api-glue.c-pp.js | 2 +- ext/wasm/api/sqlite3-wasm.c | 79 ++++++---------- ext/wasm/make-make.sh | 26 ++++-- ext/wasm/tester1.c-pp.js | 6 +- manifest | 27 +++--- manifest.uuid | 2 +- 9 files changed, 120 insertions(+), 117 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 2d5abebc46..785d501f39 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -15,8 +15,9 @@ # by the target name. Rebuild is necessary for all components to get # the desired optimization level. # -# quick, q = do just a minimal build (sqlite3.js/wasm, tester1) for -# faster development-mode turnaround. +# quick, q = do just build the essentials for testing +# (sqlite3.js/wasm, tester1) for faster development-mode +# turnaround. # # dist = create end user deliverables. Add dist.build=oX to build # with a specific optimization level, where oX is one of the @@ -45,16 +46,24 @@ # related to each build variant $(JS_BUILD_MODES). (Update: an # external script was attempted but generating properly-escaped # makefile code from within a shell script is even less legible -# than the $(eval) indirection going on in this file.) +# than the $(eval) indirection going on in this file.) (Update 2: +# a second attempt at that make yet another mess of it.) # default: all #default: quick -SHELL := $(shell which bash 2>/dev/null) +SHELL := $(firstword $(wildcard /usr/local/bin/bash /usr/bin/bash /bin/bash)) +ifeq (,$(SHELL)) + $(error Cannot find the bash shell) +endif MAKEFILE := $(lastword $(MAKEFILE_LIST)) -CLEAN_FILES := +CLEAN_FILES := .gen.make DISTCLEAN_FILES := ./--dummy-- -release: oz MAKING_CLEAN := $(if $(filter %clean,$(MAKECMDGOALS)),1,0) +.PHONY: clean distclean +clean: + -rm -f $(CLEAN_FILES) +distclean: clean + -rm -f $(DISTCLEAN_FILES) ######################################################################## # JS_BUILD_NAMES exists for documentation purposes only. It enumerates @@ -143,33 +152,49 @@ $(sqlite3.h): $(MAKE) -C $(dir.top) sqlite3.c $(sqlite3.c): $(sqlite3.h) -# .cache.make is generated by a shell script and holds certain parts +######################################################################## +# .gen.make is generated by a shell script and holds certain parts # of the makefile, some of which are relatively expensive to calculate # on each run (that is, they can take a human-visible amount of time). +# +# .gen.make is also home to make-side vars which are needed for +# generating makefile code via shell code. ifeq (0,$(MAKING_CLEAN)) -.cache.make: $(sqlite3.c) $(sqlite3.canonical.c) $(MAKEFILE) make-make.sh +.gen.make: $(MAKEFILE) $(sqlite3.c) rm -f $@ - $(SHELL) make-make.sh "$(sqlite3.c)" > $@ + $(SHELL) make-make.sh $(sqlite3.c) > $@ chmod -w $@ --include .cache.make -.cache.make: $(emcc.bin) +-include .gen.make +endif + +ifeq (,$(filter release snapshot,$(MAKECMDGOALS))) + $(info Development build. Use 'release' or 'snapshot' target for a smaller release build.) endif -CLEAN_FILES += .cache.make # Common options for building sqlite3-wasm.c and speedtest1.c. +# Explicit ENABLEs... SQLITE_OPT = \ - -DSQLITE_ENABLE_FTS5 \ - -DSQLITE_ENABLE_RTREE \ - -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION \ - -DSQLITE_ENABLE_STMTVTAB \ + -DSQLITE_ENABLE_BYTECODE_VTAB \ -DSQLITE_ENABLE_DBPAGE_VTAB \ -DSQLITE_ENABLE_DBSTAT_VTAB \ - -DSQLITE_ENABLE_BYTECODE_VTAB \ + -DSQLITE_ENABLE_FTS5 \ + -DSQLITE_ENABLE_MATH_FUNCTIONS \ -DSQLITE_ENABLE_OFFSET_SQL_FUNC \ + -DSQLITE_ENABLE_PREUPDATE_HOOK \ + -DSQLITE_ENABLE_RTREE \ + -DSQLITE_ENABLE_SESSION \ + -DSQLITE_ENABLE_STMTVTAB \ + -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION + +# Explicit OMITs... +SQLITE_OPT += \ -DSQLITE_OMIT_LOAD_EXTENSION \ -DSQLITE_OMIT_DEPRECATED \ -DSQLITE_OMIT_UTF16 \ - -DSQLITE_OMIT_SHARED_CACHE \ + -DSQLITE_OMIT_SHARED_CACHE + +# Misc. build-time config options... +SQLITE_OPT += \ -DSQLITE_THREADSAFE=0 \ -DSQLITE_TEMP_STORE=2 \ -DSQLITE_OS_KV_OPTIONAL=1 \ @@ -177,6 +202,7 @@ SQLITE_OPT = \ -DSQLITE_USE_URI=1 \ -DSQLITE_WASM_ENABLE_C_TESTS \ -DSQLITE_C=$(sqlite3.c) + #SQLITE_OPT += -DSQLITE_DEBUG # Enabling SQLITE_DEBUG will break sqlite3_wasm_vfs_create_file() # (and thus sqlite3_js_vfs_create_file()). Those functions are @@ -187,25 +213,16 @@ SQLITE_OPT = \ ######################################################################## # minimal=1 disables all "extraneous" stuff from sqlite3-wasm.c, the # goal being to create a WASM file with only the core APIs. -minimal ?= 0 ifeq (1,$(minimal)) SQLITE_OPT += -DSQLITE_WASM_MINIMAL -endif - -.PHONY: clean distclean -clean: - -rm -f $(CLEAN_FILES) -distclean: clean - -rm -f $(DISTCLEAN_FILES) - -ifeq (release,$(filter release,$(MAKECMDGOALS))) - ifeq (,$(wasm-strip)) - $(error Cannot make release-quality binary because wasm-strip is not available. \ - See notes in the warning above) - endif + # SQLITE_WASM_MINIMAL tells sqlite3-wasm.c to explicitly omit + # a bunch of stuff, in the interest of keeping the wasm file size + # down. + wasm-minimal := 1 else - $(info Development build. Use '$(MAKE) release' for a smaller release build.) + wasm-minimal := 0 endif +undefine minimal ######################################################################## # Adding custom C code via sqlite3_wasm_extra_init.c: @@ -368,11 +385,11 @@ EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.core) ifeq (1,$(SQLITE_C_IS_SEE)) EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see endif -ifeq (0,$(minimal)) +ifeq (0,$(wasm-minimal)) EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras else $(info ========================================) - $(info This is a minimal-mode build) + $(info This is a minimal-mode build. It is missing many features.) $(info ========================================) endif EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api @@ -408,8 +425,10 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.c-pp.js sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.c-pp.js # sqlite3-vfs-helper = helper APIs for VFSes: sqlite3-api.jses += $(dir.api)/sqlite3-vfs-helper.c-pp.js -# sqlite3-vtab-helper = helper APIs for VTABLEs: -sqlite3-api.jses += $(dir.api)/sqlite3-vtab-helper.c-pp.js +ifeq (0,$(wasm-minimal)) + # sqlite3-vtab-helper = helper APIs for VTABLEs: + sqlite3-api.jses += $(dir.api)/sqlite3-vtab-helper.c-pp.js +endif # sqlite3-vfs-opfs = the first OPFS VFS: sqlite3-api.jses += $(dir.api)/sqlite3-vfs-opfs.c-pp.js # sqlite3-vfs-opfs-sahpool = the second OPFS VFS: diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core index db47ee7db1..263542bc94 100644 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core +++ b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core @@ -49,7 +49,6 @@ _sqlite3_db_name _sqlite3_db_readonly _sqlite3_db_status _sqlite3_deserialize -_sqlite3_drop_modules _sqlite3_errcode _sqlite3_errmsg _sqlite3_error_offset diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras index f8af685ed7..2e831447dd 100644 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras +++ b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras @@ -50,6 +50,7 @@ _sqlite3session_table_filter _sqlite3_create_module _sqlite3_create_module_v2 _sqlite3_declare_vtab +_sqlite3_drop_modules _sqlite3_vtab_collation _sqlite3_vtab_distinct _sqlite3_vtab_in diff --git a/ext/wasm/api/sqlite3-api-glue.c-pp.js b/ext/wasm/api/sqlite3-api-glue.c-pp.js index 55dd300d74..3c4bf582d1 100644 --- a/ext/wasm/api/sqlite3-api-glue.c-pp.js +++ b/ext/wasm/api/sqlite3-api-glue.c-pp.js @@ -385,7 +385,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ of this, the canonical builds of sqlite3.wasm/js guarantee that sqlite3.wasm.alloc() and friends use those allocators. Custom builds may not guarantee that, however. */, - ["sqlite3_drop_modules", "int", ["sqlite3*", "**"]], ["sqlite3_last_insert_rowid", "i64", ["sqlite3*"]], ["sqlite3_malloc64", "*","i64"], ["sqlite3_msize", "i64", "*"], @@ -422,6 +421,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_create_module_v2", "int", ["sqlite3*","string","sqlite3_module*","*","*"]], ["sqlite3_declare_vtab", "int", ["sqlite3*", "string:flexible"]], + ["sqlite3_drop_modules", "int", ["sqlite3*", "**"]], ["sqlite3_vtab_collation","string","sqlite3_index_info*","int"], ["sqlite3_vtab_distinct","int", "sqlite3_index_info*"], ["sqlite3_vtab_in","int", "sqlite3_index_info*", "int", "int"], diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 7f7e696899..c0da2c623d 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,43 +93,6 @@ #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 @@ -214,6 +178,12 @@ # define SQLITE_OMIT_JSON #endif +#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_MINIMAL) +# define SQLITE_WASM_HAS_VTAB 1 +#else +# define SQLITE_WASM_HAS_VTAB 0 +#endif + #include /* @@ -412,7 +382,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 +402,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 @@ -967,7 +937,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 +965,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 @@ -1110,6 +1080,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 +1126,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 @@ -1232,9 +1202,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 +1214,7 @@ const char * sqlite3__wasm_enum_json(void){ M(xFunc, "v(p)"); } _StructBinder; #undef CurrentStruct -#endif +#endif /*SQLITE_WASM_ENABLE_C_TESTS*/ } out( "]"/*structs*/); @@ -1603,7 +1573,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 +1596,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 @@ -1801,7 +1771,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 +1937,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_MINIMAL +#undef SQLITE_WASM_ENABLE_C_TESTS diff --git a/ext/wasm/make-make.sh b/ext/wasm/make-make.sh index e5b81b3d12..6f93d88835 100755 --- a/ext/wasm/make-make.sh +++ b/ext/wasm/make-make.sh @@ -23,7 +23,14 @@ function die(){ SQLITE3_C="${1-../../sqlite3.c}" -echo "# GENERATED makefile code. DO NOT EDIT." +separator='########################################################################' + +cat </dev/null; then echo 'SQLITE_C_IS_SEE := 1' @@ -34,6 +41,7 @@ fi ######################################################################## # Locate the emcc (Emscripten) binary... +echo $separator EMCC_BIN=$(which emcc) if [[ x = "x${EMCC_BIN}" ]]; then if [[ x != "x${EMSDK_HOME}" ]]; then @@ -51,6 +59,7 @@ echo '$(info using emcc version [$(emcc.version)])' ######################################################################### # wasm-strip binary... +echo $separator WASM_STRIP_BIN=$(which wasm-strip 2>/dev/null) echo "wasm-strip ?= ${WASM_STRIP_BIN}" if [[ x = "x${WASM_STRIP_BIN}" ]]; then @@ -71,14 +80,19 @@ ifeq (,\$(filter clean,\$(MAKECMDGOALS)))' \$(info WARNING: sudo apt install wabt) \$(info WARNING: *******************************************************************) endif +ifneq (,\$(filter release snapshot,\$(MAKECMDGOALS))) + \$(error Cannot make release-quality binary because wasm-strip is not available.) +endif EOF else - echo 'maybe-wasm-strip = $(wasm-strip)' +echo 'maybe-wasm-strip = $(wasm-strip)' fi +# /$(wasm-strip) +######################################################################## - -dir_dout=jswasm -dir_tmp=bld -for d in $dir_dout $dir_tmp; do +######################################################################## +# Make necessary dirs. Note that these need to align with their names +# in the main makefile. +for d in jswasm bld; do [ -d $d ] || mkdir -p $d done diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 3338bbb2a1..b8db1a59b2 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -2153,7 +2153,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //////////////////////////////////////////////////////////////////////// .t({ name: 'virtual table #1: eponymous w/ manual exception handling', - predicate: ()=>!!capi.sqlite3_create_module || "Missing vtab support", + predicate: (sqlite3)=>!!sqlite3.capi.sqlite3_vtab || "Missing vtab support", test: function(sqlite3){ const VT = sqlite3.vtab; const tmplCols = Object.assign(Object.create(null),{ @@ -2350,7 +2350,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //////////////////////////////////////////////////////////////////////// .t({ name: 'virtual table #2: non-eponymous w/ automated exception wrapping', - predicate: ()=>!!capi.sqlite3_create_module || "Missing vtab support", + predicate: (sqlite3)=>!!sqlite3.capi.sqlite3_vtab || "Missing vtab support", test: function(sqlite3){ const VT = sqlite3.vtab; const tmplCols = Object.assign(Object.create(null),{ @@ -3300,7 +3300,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.g('Bug Reports') .t({ name: 'Delete via bound parameter in subquery', - predicate: ()=>wasm.compileOptionUsed('ENABLE_FTS5') || "FTS5 is not available", + predicate: ()=>wasm.compileOptionUsed('ENABLE_FTS5') || "Missing FTS5", test: function(sqlite3){ // Testing https://sqlite.org/forum/forumpost/40ce55bdf5 // with the exception that that post uses "external content" diff --git a/manifest b/manifest index f53748e088..6b6d0243f4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Start\swork\son\san\soverhaul\sof\sthe\swasm\sbuild\sprocess,\swith\san\seye\stowards\sless\sover-engineering. -D 2024-07-25T10:50:45.547 +C More\swork\son\sthe\sminimal-mode\swasm\sbuild\s(now\s603kb\suncompressed).\sRemove\sthe\shard-coded\sfeature-enable\sflags\sfrom\ssqlite3-wasm.c\sand\srely\son\sthe\sbuild\sto\sprovide\sthem.\sSome\swasm\sbuild\scleanup,\sbut\sattempts\sto\scompletely\soverhaul\sit\shave\sbeen\sthwarted\sby\smy\sinability\sto\smake\sscript-generated\smakefile\scode\smore\slegible/maintainable\sthan\sthe\scurrent\seval\sspaghetti. +D 2024-07-25T14:00:26.899 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -593,7 +593,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 2037399f1a33f8c0bab52e5aba78d4c6b6d9fb8d905ddf5fc3dd10f2a6fdb494 +F ext/wasm/GNUmakefile c89b6d0e7f969de03cfcbd5d5f64985ee9ba823a7be6b150fb9c2976c7adb0d6 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -601,8 +601,8 @@ F ext/wasm/SQLTester/SQLTester.mjs ce765c0ad7d57f93553d12ef4dca574deb00300134a26 F ext/wasm/SQLTester/SQLTester.run.mjs c72b7fe2072d05992f7a3d8c6a1d34e95712513ceabe40849784e24e41c84638 F ext/wasm/SQLTester/index.html 3f8a016df0776be76605abf20e815ecaafbe055abac0e1fe5ea080e7846b760d F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f3038b96460fc5e5aa7e536 -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core 400213eb52a7e5ad5f448053d375cacf4dac2cf45d134f3edfe485ae4a49a183 -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras e9a42a86d1e09cfd46fd22438e0cb9449e6eae2eff39597cdc834c183775286a w ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session +F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core 38f85e6ec5f9c776087bc38aef9ef35eeb7e54942ddb1dd04e9ac0122958b741 +F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras 2a8c9f7d865cc6e5661b2cd40a45e963a1f8070a88def6ead4c40d4fa0c91998 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 34fe11466f9c1d81b10a0469e1114e5f1c5a6365c73d80a1a6ca639a1a358b73 @@ -612,7 +612,7 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.c-pp.js 30abfbb9ed4b6732e2fd78dbfedee5f8d7a395a6d38f140f8df19bd9c30b4191 +F ext/wasm/api/sqlite3-api-glue.c-pp.js 12f6f3840afdf8ff7a4374dc1a96a26bcc369e17853e0fe917c38f4d66c6e2d8 F ext/wasm/api/sqlite3-api-oo1.c-pp.js f3a8e2004c6625d17946c11f2fb32008be78bc5207bf746fc77d59848813225f F ext/wasm/api/sqlite3-api-prologue.js 6f1257e04885632ed9f44d43aba200b86e0bc16709ffdba29abbbeb1bc8e8b76 F ext/wasm/api/sqlite3-api-worker1.c-pp.js 5cc22a3c0d52828cb32aad8691488719f47d27567e63e8bc8b832d74371c352d @@ -622,7 +622,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js e529a99b7d5a088284821e2902b20d3404b561126969876997d5a73a656c9199 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js e99e3d99f736937914527070f00ab13e9391d3f1cef884ab99a64cbcbee8d675 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616 -F ext/wasm/api/sqlite3-wasm.c 09a938fc570f282e602acd111147c7b74b5332da72540c512a79b916ab57882a +F ext/wasm/api/sqlite3-wasm.c 79335b70d4d404b33fb485a4f65422a1ded0977c38e3b1a0cd8e26b49d3c9fba F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -653,7 +653,7 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/make-make.sh 93fa6d00f0ffa3481badd068b8da8ed5825cf74999d5e54b2a0c9b90579a3056 x +F ext/wasm/make-make.sh 3c1964f5ed80af79c21e583abb9adac2eb11141c98c1cf57eba7ebcb210f1025 x F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -669,7 +669,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js b5a126b7ae3f3b5628e74ca806f65394f309326dd518831b2186f88850439be2 +F ext/wasm/tester1.c-pp.js 7d0eba1496286338770133356488b4415de7970f4ee2c08f7f587bb18d8b6b0b F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2197,11 +2197,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P eb64d106551718467e0f6c6b53695410bf4c566901008e4cda8580d0f7efa7b0 -R 5dcb0158c3e9e326c7d4eacaa8552ecf -T *branch * wasm-build-rework -T *sym-wasm-build-rework * -T -sym-trunk * Cancelled\sby\sbranch. +P ed746b3dd3248b68cb91de50ac5ba5fd3a7c2fcbde76324e86b88edbfecd896b +R acaefae7f2493e8276236de40774aafc U stephan -Z 6b2b2a8483fc393f764799aae3eb47aa +Z 2f4bcd240a0ced338bed244e56f0f58c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9d68627d41..930c8e1a51 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed746b3dd3248b68cb91de50ac5ba5fd3a7c2fcbde76324e86b88edbfecd896b +b029c4067943e366a9b25b8303136fab10822bd771ea4658ac4cd716ff4a0d8f From e7840ce6810174625ae9ec116610bb987d252aef Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 25 Jul 2024 16:21:19 +0000 Subject: [PATCH 03/50] Strip progress handlers and window functions from the wasm bare-bones (formerly 'minimal') JS bits, noting that we can't yet use OMIT_WINDOWFUNC (for the C parts) without a custom amalgamation. Currently at 604kb. FossilOrigin-Name: ec02e9237e1ef81c4196fa630822cb109eab926143ad09593a24273eb0668601 --- ext/wasm/GNUmakefile | 120 +++-- ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core | 2 - .../api/EXPORTED_FUNCTIONS.sqlite3-extras | 2 + ext/wasm/api/sqlite3-api-glue.c-pp.js | 153 +++--- ext/wasm/api/sqlite3-wasm.c | 103 ++-- ext/wasm/fiddle.make | 10 +- ext/wasm/tester1.c-pp.js | 483 +++++++++--------- manifest | 24 +- manifest.uuid | 2 +- 9 files changed, 496 insertions(+), 403 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 785d501f39..18f8ffc22d 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -157,8 +157,9 @@ $(sqlite3.c): $(sqlite3.h) # of the makefile, some of which are relatively expensive to calculate # on each run (that is, they can take a human-visible amount of time). # -# .gen.make is also home to make-side vars which are needed for -# generating makefile code via shell code. +# Sidebar: three attempts have been made to move much of the +# $(eval)-generated makefile code into make-make.sh but the result is +# even less legible/maintainable than make-side $(eval). ifeq (0,$(MAKING_CLEAN)) .gen.make: $(MAKEFILE) $(sqlite3.c) rm -f $@ @@ -171,9 +172,39 @@ ifeq (,$(filter release snapshot,$(MAKECMDGOALS))) $(info Development build. Use 'release' or 'snapshot' target for a smaller release build.) endif +######################################################################## +# minimal=1 disables all "extraneous" stuff from sqlite3-wasm.c, the +# goal being to create a WASM file with only the core APIs. +ifeq (1,$(minimal)) + wasm-bare-bones := 1 +else + wasm-bare-bones := 0 +endif +undefine minimal + # Common options for building sqlite3-wasm.c and speedtest1.c. # Explicit ENABLEs... -SQLITE_OPT = \ +SQLITE_OPT.common := \ + -DSQLITE_THREADSAFE=0 \ + -DSQLITE_TEMP_STORE=2 \ + -DSQLITE_ENABLE_MATH_FUNCTIONS \ + -DSQLITE_OS_KV_OPTIONAL=1 \ + '-DSQLITE_DEFAULT_UNIX_VFS="unix-none"' \ + -DSQLITE_USE_URI=1 \ + -DSQLITE_C=$(sqlite3.c) \ + -DSQLITE_OMIT_DEPRECATED \ + -DSQLITE_OMIT_UTF16 \ + -DSQLITE_OMIT_LOAD_EXTENSION \ + -DSQLITE_OMIT_SHARED_CACHE +# ^^^ These particular OMITs are hard-coded in sqlite3-wasm.c and +# removing them from this list will serve only to break the speedtest1 +# builds. + +# Currently always needed but TODO is paring tester1.c-pp.js down +# to be able to run without this: +SQLITE_OPT.common += -DSQLITE_WASM_ENABLE_C_TESTS + +SQLITE_OPT.full-featured := \ -DSQLITE_ENABLE_BYTECODE_VTAB \ -DSQLITE_ENABLE_DBPAGE_VTAB \ -DSQLITE_ENABLE_DBSTAT_VTAB \ @@ -186,22 +217,45 @@ SQLITE_OPT = \ -DSQLITE_ENABLE_STMTVTAB \ -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION -# Explicit OMITs... -SQLITE_OPT += \ - -DSQLITE_OMIT_LOAD_EXTENSION \ - -DSQLITE_OMIT_DEPRECATED \ - -DSQLITE_OMIT_UTF16 \ - -DSQLITE_OMIT_SHARED_CACHE - -# Misc. build-time config options... -SQLITE_OPT += \ - -DSQLITE_THREADSAFE=0 \ - -DSQLITE_TEMP_STORE=2 \ - -DSQLITE_OS_KV_OPTIONAL=1 \ - '-DSQLITE_DEFAULT_UNIX_VFS="unix-none"' \ - -DSQLITE_USE_URI=1 \ - -DSQLITE_WASM_ENABLE_C_TESTS \ - -DSQLITE_C=$(sqlite3.c) +ifeq (0,$(wasm-bare-bones)) + # The so-called canonical build is full-featured: + SQLITE_OPT := \ + $(SQLITE_OPT.common) \ + $(SQLITE_OPT.full-featured) +else + # The so-called bare-bones build is exactly that: + SQLITE_OPT := \ + $(SQLITE_OPT.common) \ + -DSQLITE_WASM_BARE_BONES + # SQLITE_WASM_BARE_BONES tells sqlite3-wasm.c to explicitly omit + # a bunch of stuff, in the interest of keeping the wasm file size + # down. As of this writing it equates to: + # + # -USQLITE_ENABLE_DBPAGE_VTAB + # -USQLITE_ENABLE_DBSTAT_VTAB + # -USQLITE_ENABLE_EXPLAIN_COMMENTS + # -USQLITE_ENABLE_FTS5 + # -USQLITE_ENABLE_OFFSET_SQL_FUNC + # -USQLITE_ENABLE_PREUPDATE_HOOK + # -USQLITE_ENABLE_RTREE + # -USQLITE_ENABLE_SESSION + # -USQLITE_ENABLE_STMTVTAB + # -DSQLITE_OMIT_AUTHORIZATION + # -DSQLITE_OMIT_GET_TABLE + # -DSQLITE_OMIT_INCRBLOB + # -DSQLITE_OMIT_INTROSPECTION_PRAGMAS + # -DSQLITE_OMIT_JSON + # -DSQLITE_OMIT_PROGRESS_CALLBACK + # -DSQLITE_OMIT_WAL + # + # There are others we want here but which require explicit OMIT when + # creating their amalgamation, and that step is TODO: + # + # -DSQLITE_OMIT_EXPLAIN + # -DSQLITE_OMIT_TRIGGER + # -DSQLITE_OMIT_VIRTUALTABLE + # -DSQLITE_OMIT_WINDOWFUNC +endif #SQLITE_OPT += -DSQLITE_DEBUG # Enabling SQLITE_DEBUG will break sqlite3_wasm_vfs_create_file() @@ -211,18 +265,16 @@ SQLITE_OPT += \ # in client code. ######################################################################## -# minimal=1 disables all "extraneous" stuff from sqlite3-wasm.c, the -# goal being to create a WASM file with only the core APIs. -ifeq (1,$(minimal)) - SQLITE_OPT += -DSQLITE_WASM_MINIMAL - # SQLITE_WASM_MINIMAL tells sqlite3-wasm.c to explicitly omit - # a bunch of stuff, in the interest of keeping the wasm file size - # down. - wasm-minimal := 1 -else - wasm-minimal := 0 -endif -undefine minimal +# The following flags are hard-coded into sqlite3-wasm.c and cannot be +# modified via the build process: +# +# SQLITE_ENABLE_API_ARMOR +# SQLITE_OMIT_LOAD_EXTENSION +# SQLITE_OMIT_DEPRECATED +# SQLITE_OMIT_UTF16 +# SQLITE_OMIT_SHARED_CACHE +######################################################################## + ######################################################################## # Adding custom C code via sqlite3_wasm_extra_init.c: @@ -385,7 +437,7 @@ EXPORTED_FUNCTIONS.api.in := $(EXPORTED_FUNCTIONS.api.core) ifeq (1,$(SQLITE_C_IS_SEE)) EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-see endif -ifeq (0,$(wasm-minimal)) +ifeq (0,$(wasm-bare-bones)) EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras else $(info ========================================) @@ -425,7 +477,7 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-oo1.c-pp.js sqlite3-api.jses += $(dir.api)/sqlite3-api-worker1.c-pp.js # sqlite3-vfs-helper = helper APIs for VFSes: sqlite3-api.jses += $(dir.api)/sqlite3-vfs-helper.c-pp.js -ifeq (0,$(wasm-minimal)) +ifeq (0,$(wasm-bare-bones)) # sqlite3-vtab-helper = helper APIs for VTABLEs: sqlite3-api.jses += $(dir.api)/sqlite3-vtab-helper.c-pp.js endif @@ -1053,7 +1105,7 @@ $(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \ $(emcc.speedtest1.common) \ $(emcc.flags.speedtest1-vanilla) $(pre-post-speedtest1-vanilla.flags) \ $(SQLITE_OPT) \ - -USQLITE_WASM_MINIMAL \ + -USQLITE_WASM_BARE_BONES \ -USQLITE_C -DSQLITE_C=$(sqlite3.canonical.c) \ $(speedtest1.exit-runtime0) \ -o $@ $(speedtest1.cfiles) -lm diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core index 263542bc94..2578002ce4 100644 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core +++ b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core @@ -41,7 +41,6 @@ _sqlite3_create_collation _sqlite3_create_collation_v2 _sqlite3_create_function _sqlite3_create_function_v2 -_sqlite3_create_window_function _sqlite3_data_count _sqlite3_db_filename _sqlite3_db_handle @@ -80,7 +79,6 @@ _sqlite3_open_v2 _sqlite3_overload_function _sqlite3_prepare_v2 _sqlite3_prepare_v3 -_sqlite3_progress_handler _sqlite3_randomness _sqlite3_realloc _sqlite3_realloc64 diff --git a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras index 2e831447dd..e635d93b32 100644 --- a/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras +++ b/ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras @@ -1,3 +1,5 @@ +_sqlite3_create_window_function +_sqlite3_progress_handler _sqlite3_set_authorizer _sqlite3_preupdate_blobwrite _sqlite3_preupdate_count diff --git a/ext/wasm/api/sqlite3-api-glue.c-pp.js b/ext/wasm/api/sqlite3-api-glue.c-pp.js index 3c4bf582d1..680218370a 100644 --- a/ext/wasm/api/sqlite3-api-glue.c-pp.js +++ b/ext/wasm/api/sqlite3-api-glue.c-pp.js @@ -136,20 +136,12 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_compileoption_used", "int", "string"], ["sqlite3_complete", "int", "string:flexible"], ["sqlite3_context_db_handle", "sqlite3*", "sqlite3_context*"], - + /* sqlite3_create_collation() and sqlite3_create_collation_v2() + use hand-written bindings to simplify passing of the callback + function. */ /* sqlite3_create_function(), sqlite3_create_function_v2(), and sqlite3_create_window_function() use hand-written bindings to simplify handling of their function-type arguments. */ - /* sqlite3_create_collation() and sqlite3_create_collation_v2() - use hand-written bindings to simplify passing of the callback - function. - ["sqlite3_create_collation", "int", - "sqlite3*", "string", "int",//SQLITE_UTF8 is the only legal value - "*", "*"], - ["sqlite3_create_collation_v2", "int", - "sqlite3*", "string", "int",//SQLITE_UTF8 is the only legal value - "*", "*", "*"], - */ ["sqlite3_data_count", "int", "sqlite3_stmt*"], ["sqlite3_db_filename", "string", "sqlite3*", "string"], ["sqlite3_db_handle", "sqlite3*", "sqlite3_stmt*"], @@ -211,14 +203,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ for those, depending on how their SQL argument is provided. */ /* sqlite3_randomness() uses a hand-written wrapper to extend the range of supported argument types. */ - ["sqlite3_progress_handler", undefined, [ - "sqlite3*", "int", new wasm.xWrap.FuncPtrAdapter({ - name: 'xProgressHandler', - signature: 'i(p)', - bindScope: 'context', - contextKey: (argv,argIndex)=>argv[0/* sqlite3* */] - }), "*" - ]], ["sqlite3_realloc", "*","*","int"], ["sqlite3_reset", "int", "sqlite3_stmt*"], /* sqlite3_reset_auto_extension() has a hand-written binding. */ @@ -303,6 +287,19 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ["sqlite3_vfs_unregister", "int", "sqlite3_vfs*"] ]/*wasm.bindingSignatures*/; + if( !!wasm.exports.sqlite3_progress_handler ){ + wasm.bindingSignatures.push( + ["sqlite3_progress_handler", undefined, [ + "sqlite3*", "int", new wasm.xWrap.FuncPtrAdapter({ + name: 'xProgressHandler', + signature: 'i(p)', + bindScope: 'context', + contextKey: (argv,argIndex)=>argv[0/* sqlite3* */] + }), "*" + ]] + ); + } + if( !!wasm.exports.sqlite3_stmt_explain ){ wasm.bindingSignatures.push( ["sqlite3_stmt_explain", "int", "sqlite3_stmt*", "int"], @@ -950,7 +947,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /** Code duplication reducer for functions which take an encoding argument and require SQLITE_UTF8. Sets the db error code to - SQLITE_FORMAT and returns that code. */ + SQLITE_FORMAT, installs a descriptive error message, + and returns SQLITE_FORMAT. */ const __errEncoding = (pDb)=>{ return util.sqlite3__wasm_db_error( pDb, capi.SQLITE_FORMAT, "SQLITE_UTF8 is the only supported encoding." @@ -1000,11 +998,13 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ this._addUDF(pDb, name, arity, m.udf); }; - __dbCleanupMap.addWindowFunc = function(pDb, name, arity){ - const m = __dbCleanupMap(pDb, 1); - if(!m.wudf) m.wudf = new Map; - this._addUDF(pDb, name, arity, m.wudf); - }; + if( wasm.exports.sqlite3_create_window_function ){ + __dbCleanupMap.addWindowFunc = function(pDb, name, arity){ + const m = __dbCleanupMap(pDb, 1); + if(!m.wudf) m.wudf = new Map; + this._addUDF(pDb, name, arity, m.wudf); + }; + } /** Intended to be called _only_ from sqlite3_close_v2(), @@ -1273,17 +1273,20 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ] ); - const __sqlite3CreateWindowFunction = wasm.xWrap( - "sqlite3_create_window_function", "int", [ - "sqlite3*", "string"/*funcName*/, "int"/*nArg*/, - "int"/*eTextRep*/, "*"/*pApp*/, - new wasm.xWrap.FuncPtrAdapter({name: 'xStep', ...__cfProxy.xInverseAndStep}), - new wasm.xWrap.FuncPtrAdapter({name: 'xFinal', ...__cfProxy.xFinalAndValue}), - new wasm.xWrap.FuncPtrAdapter({name: 'xValue', ...__cfProxy.xFinalAndValue}), - new wasm.xWrap.FuncPtrAdapter({name: 'xInverse', ...__cfProxy.xInverseAndStep}), - new wasm.xWrap.FuncPtrAdapter({name: 'xDestroy', ...__cfProxy.xDestroy}) - ] - ); + const __sqlite3CreateWindowFunction = + wasm.exports.sqlite3_create_window_function + ? wasm.xWrap( + "sqlite3_create_window_function", "int", [ + "sqlite3*", "string"/*funcName*/, "int"/*nArg*/, + "int"/*eTextRep*/, "*"/*pApp*/, + new wasm.xWrap.FuncPtrAdapter({name: 'xStep', ...__cfProxy.xInverseAndStep}), + new wasm.xWrap.FuncPtrAdapter({name: 'xFinal', ...__cfProxy.xFinalAndValue}), + new wasm.xWrap.FuncPtrAdapter({name: 'xValue', ...__cfProxy.xFinalAndValue}), + new wasm.xWrap.FuncPtrAdapter({name: 'xInverse', ...__cfProxy.xInverseAndStep}), + new wasm.xWrap.FuncPtrAdapter({name: 'xDestroy', ...__cfProxy.xDestroy}) + ] + ) + : undefined; /* Documented in the api object's initializer. */ capi.sqlite3_create_function_v2 = function f( @@ -1328,61 +1331,71 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }; /* Documented in the api object's initializer. */ - capi.sqlite3_create_window_function = function f( - pDb, funcName, nArg, eTextRep, pApp, - xStep, //void (*xStep)(sqlite3_context*,int,sqlite3_value**) - xFinal, //void (*xFinal)(sqlite3_context*) - xValue, //void (*xValue)(sqlite3_context*) - xInverse,//void (*xInverse)(sqlite3_context*,int,sqlite3_value**) - xDestroy //void (*xDestroy)(void*) - ){ - if( f.length!==arguments.length ){ - return __dbArgcMismatch(pDb,"sqlite3_create_window_function",f.length); - }else if( 0 === (eTextRep & 0xf) ){ - eTextRep |= capi.SQLITE_UTF8; - }else if( capi.SQLITE_UTF8 !== (eTextRep & 0xf) ){ - return __errEncoding(pDb); - } - try{ - const rc = __sqlite3CreateWindowFunction(pDb, funcName, nArg, eTextRep, - pApp, xStep, xFinal, xValue, - xInverse, xDestroy); - if(0===rc && (xStep instanceof Function - || xFinal instanceof Function - || xValue instanceof Function - || xInverse instanceof Function - || xDestroy instanceof Function)){ - __dbCleanupMap.addWindowFunc(pDb, funcName, nArg); + if( __sqlite3CreateWindowFunction ){ + capi.sqlite3_create_window_function = function f( + pDb, funcName, nArg, eTextRep, pApp, + xStep, //void (*xStep)(sqlite3_context*,int,sqlite3_value**) + xFinal, //void (*xFinal)(sqlite3_context*) + xValue, //void (*xValue)(sqlite3_context*) + xInverse,//void (*xInverse)(sqlite3_context*,int,sqlite3_value**) + xDestroy //void (*xDestroy)(void*) + ){ + if( f.length!==arguments.length ){ + return __dbArgcMismatch(pDb,"sqlite3_create_window_function",f.length); + }else if( 0 === (eTextRep & 0xf) ){ + eTextRep |= capi.SQLITE_UTF8; + }else if( capi.SQLITE_UTF8 !== (eTextRep & 0xf) ){ + return __errEncoding(pDb); } - return rc; - }catch(e){ - console.error("sqlite3_create_window_function() setup threw:",e); - return util.sqlite3__wasm_db_error(pDb, e, "Creation of UDF threw: "+e); - } - }; + try{ + const rc = __sqlite3CreateWindowFunction(pDb, funcName, nArg, eTextRep, + pApp, xStep, xFinal, xValue, + xInverse, xDestroy); + if(0===rc && (xStep instanceof Function + || xFinal instanceof Function + || xValue instanceof Function + || xInverse instanceof Function + || xDestroy instanceof Function)){ + __dbCleanupMap.addWindowFunc(pDb, funcName, nArg); + } + return rc; + }catch(e){ + console.error("sqlite3_create_window_function() setup threw:",e); + return util.sqlite3__wasm_db_error(pDb, e, "Creation of UDF threw: "+e); + } + }; + }else{ + delete capi.sqlite3_create_window_function; + } /** A _deprecated_ alias for capi.sqlite3_result_js() which predates the addition of that function in the public API. */ capi.sqlite3_create_function_v2.udfSetResult = - capi.sqlite3_create_function.udfSetResult = + capi.sqlite3_create_function.udfSetResult = capi.sqlite3_result_js; + if(capi.sqlite3_create_window_function){ capi.sqlite3_create_window_function.udfSetResult = capi.sqlite3_result_js; + } /** A _deprecated_ alias for capi.sqlite3_values_to_js() which predates the addition of that function in the public API. */ capi.sqlite3_create_function_v2.udfConvertArgs = - capi.sqlite3_create_function.udfConvertArgs = + capi.sqlite3_create_function.udfConvertArgs = capi.sqlite3_values_to_js; + if(capi.sqlite3_create_window_function){ capi.sqlite3_create_window_function.udfConvertArgs = capi.sqlite3_values_to_js; + } /** A _deprecated_ alias for capi.sqlite3_result_error_js() which predates the addition of that function in the public API. */ capi.sqlite3_create_function_v2.udfSetError = - capi.sqlite3_create_function.udfSetError = + capi.sqlite3_create_function.udfSetError = capi.sqlite3_result_error_js; + if(capi.sqlite3_create_window_function){ capi.sqlite3_create_window_function.udfSetError = capi.sqlite3_result_error_js; + } }/*sqlite3_create_function_v2() and sqlite3_create_window_function() proxies*/; diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index c0da2c623d..c5dd495e54 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -95,21 +95,16 @@ /**********************************************************************/ /* 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... */ @@ -137,48 +132,61 @@ #endif /* -** If SQLITE_WASM_MINIMAL is defined, undefine most of the ENABLE +** If SQLITE_WASM_BARE_BONES is defined, undefine most of the ENABLE ** macros. */ -#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_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_MINIMAL) +#if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_WASM_BARE_BONES) # define SQLITE_WASM_HAS_VTAB 1 #else # define SQLITE_WASM_HAS_VTAB 0 @@ -234,10 +242,6 @@ #undef INC__STRINGIFY #undef SQLITE_C -#if defined(__EMSCRIPTEN__) -# include -#endif - #if 0 /* ** An EXPERIMENT in implementing a stack-based allocator analog to @@ -1720,6 +1724,7 @@ char * sqlite3__wasm_qfmt_token(char *z, int addQuotes){ } #if defined(__EMSCRIPTEN__) && defined(SQLITE_ENABLE_WASMFS) +#include #include /* @@ -1941,5 +1946,5 @@ int sqlite3__wasm_SQLTester_strglob(const char *zGlob, const char *z){ #undef SQLITE_WASM_EXPORT #undef SQLITE_WASM_HAS_VTAB -#undef SQLITE_WASM_MINIMAL +#undef SQLITE_WASM_BARE_BONES #undef SQLITE_WASM_ENABLE_C_TESTS diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index 1f0d9e2ad0..b081d25155 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -41,10 +41,11 @@ fiddle.emcc-flags = \ $(emcc.exportedRuntimeMethods) \ -sEXPORTED_FUNCTIONS=@$(abspath $(EXPORTED_FUNCTIONS.fiddle)) \ -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory \ - $(SQLITE_OPT) $(SHELL_OPT) \ - -USQLITE_WASM_MINIMAL \ + $(SQLITE_OPT.full-featured) \ + $(SQLITE_OPT.common) \ + $(SHELL_OPT) \ + -USQLITE_WASM_BARE_BONES \ -DSQLITE_SHELL_FIDDLE -# -D_POSIX_C_SOURCE is needed for strdup() with emcc # Flags specifically for debug builds of fiddle. Performance suffers # greatly in debug builds. @@ -55,7 +56,8 @@ fiddle.emcc-flags.debug := $(fiddle.emcc-flags) \ fiddle.EXPORTED_FUNCTIONS.in := \ EXPORTED_FUNCTIONS.fiddle.in \ - $(EXPORTED_FUNCTIONS.api) + $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core \ + $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras $(EXPORTED_FUNCTIONS.fiddle): $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle) sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@ diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index b8db1a59b2..6023069bc4 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -848,171 +848,176 @@ globalThis.sqlite3InitModule = sqlite3InitModule; }/*WhWasmUtil*/) //////////////////////////////////////////////////////////////////// - .t('sqlite3.StructBinder (jaccwabyt🐇)', function(sqlite3){ - const S = sqlite3, W = S.wasm; - const MyStructDef = { - sizeof: 16, - members: { - p4: {offset: 0, sizeof: 4, signature: "i"}, - pP: {offset: 4, sizeof: 4, signature: "P"}, - ro: {offset: 8, sizeof: 4, signature: "i", readOnly: true}, - cstr: {offset: 12, sizeof: 4, signature: "s"} - } - }; - if(W.bigIntEnabled){ - const m = MyStructDef; - m.members.p8 = {offset: m.sizeof, sizeof: 8, signature: "j"}; - m.sizeof += m.members.p8.sizeof; - } - const StructType = S.StructBinder.StructType; - const K = S.StructBinder('my_struct',MyStructDef); - T.mustThrowMatching(()=>K(), /via 'new'/). - mustThrowMatching(()=>new K('hi'), /^Invalid pointer/); - const k1 = new K(), k2 = new K(); - try { - T.assert(k1.constructor === K). - assert(K.isA(k1)). - assert(k1 instanceof K). - assert(K.prototype.lookupMember('p4').key === '$p4'). - assert(K.prototype.lookupMember('$p4').name === 'p4'). - mustThrowMatching(()=>K.prototype.lookupMember('nope'), /not a mapped/). - assert(undefined === K.prototype.lookupMember('nope',false)). - assert(k1 instanceof StructType). - assert(StructType.isA(k1)). - mustThrowMatching(()=>k1.$ro = 1, /read-only/); - Object.keys(MyStructDef.members).forEach(function(key){ - key = K.memberKey(key); - T.assert(0 == k1[key], - "Expecting allocation to zero the memory "+ - "for "+key+" but got: "+k1[key]+ - " from "+k1.memoryDump()); - }); - T.assert('number' === typeof k1.pointer). - mustThrowMatching(()=>k1.pointer = 1, /pointer/); - k1.$p4 = 1; k1.$pP = 2; - T.assert(1 === k1.$p4).assert(2 === k1.$pP); - if(MyStructDef.members.$p8){ - k1.$p8 = 1/*must not throw despite not being a BigInt*/; - k1.$p8 = BigInt(Number.MAX_SAFE_INTEGER * 2); - T.assert(BigInt(2 * Number.MAX_SAFE_INTEGER) === k1.$p8); - } - T.assert(!k1.ondispose); - k1.setMemberCString('cstr', "A C-string."); - T.assert(Array.isArray(k1.ondispose)). - assert(k1.ondispose[0] === k1.$cstr). - assert('number' === typeof k1.$cstr). - assert('A C-string.' === k1.memberToJsString('cstr')); - k1.$pP = k2; - T.assert(k1.$pP === k2.pointer); - k1.$pP = null/*null is special-cased to 0.*/; - T.assert(0===k1.$pP); - let ptr = k1.pointer; - k1.dispose(); - T.assert(undefined === k1.pointer). - mustThrowMatching(()=>{k1.$pP=1}, /disposed instance/); - }finally{ - k1.dispose(); - k2.dispose(); - } - - if(!W.bigIntEnabled){ - log("Skipping WasmTestStruct tests: BigInt not enabled."); - return; - } - - const WTStructDesc = - W.ctype.structs.filter((e)=>'WasmTestStruct'===e.name)[0]; - const autoResolvePtr = true /* EXPERIMENTAL */; - if(autoResolvePtr){ - WTStructDesc.members.ppV.signature = 'P'; - } - const WTStruct = S.StructBinder(WTStructDesc); - //log(WTStruct.structName, WTStruct.structInfo); - const wts = new WTStruct(); - //log("WTStruct.prototype keys:",Object.keys(WTStruct.prototype)); - try{ - T.assert(wts.constructor === WTStruct). - assert(WTStruct.memberKeys().indexOf('$ppV')>=0). - assert(wts.memberKeys().indexOf('$v8')>=0). - assert(!K.isA(wts)). - assert(WTStruct.isA(wts)). - assert(wts instanceof WTStruct). - assert(wts instanceof StructType). - assert(StructType.isA(wts)). - assert(wts.pointer>0).assert(0===wts.$v4).assert(0n===wts.$v8). - assert(0===wts.$ppV).assert(0===wts.$xFunc); - const testFunc = - W.xGet('sqlite3__wasm_test_struct'/*name gets mangled in -O3 builds!*/); - let counter = 0; - //log("wts.pointer =",wts.pointer); - const wtsFunc = function(arg){ - /*log("This from a JS function called from C, "+ - "which itself was called from JS. arg =",arg);*/ - ++counter; - if(3===counter){ - tossQuietly("Testing exception propagation."); + .t({ + name: 'sqlite3.StructBinder (jaccwabyt🐇)', + predicate: (sqlite3)=>!!sqlite3.wasm.exports.sqlite3__wasm_test_struct + || "Built without SQLITE_WASM_ENABLE_C_TESTS", + test: function(sqlite3){ + const S = sqlite3, W = S.wasm; + const MyStructDef = { + sizeof: 16, + members: { + p4: {offset: 0, sizeof: 4, signature: "i"}, + pP: {offset: 4, sizeof: 4, signature: "P"}, + ro: {offset: 8, sizeof: 4, signature: "i", readOnly: true}, + cstr: {offset: 12, sizeof: 4, signature: "s"} } + }; + if(W.bigIntEnabled){ + const m = MyStructDef; + m.members.p8 = {offset: m.sizeof, sizeof: 8, signature: "j"}; + m.sizeof += m.members.p8.sizeof; + } + const StructType = S.StructBinder.StructType; + const K = S.StructBinder('my_struct',MyStructDef); + T.mustThrowMatching(()=>K(), /via 'new'/). + mustThrowMatching(()=>new K('hi'), /^Invalid pointer/); + const k1 = new K(), k2 = new K(); + try { + T.assert(k1.constructor === K). + assert(K.isA(k1)). + assert(k1 instanceof K). + assert(K.prototype.lookupMember('p4').key === '$p4'). + assert(K.prototype.lookupMember('$p4').name === 'p4'). + mustThrowMatching(()=>K.prototype.lookupMember('nope'), /not a mapped/). + assert(undefined === K.prototype.lookupMember('nope',false)). + assert(k1 instanceof StructType). + assert(StructType.isA(k1)). + mustThrowMatching(()=>k1.$ro = 1, /read-only/); + Object.keys(MyStructDef.members).forEach(function(key){ + key = K.memberKey(key); + T.assert(0 == k1[key], + "Expecting allocation to zero the memory "+ + "for "+key+" but got: "+k1[key]+ + " from "+k1.memoryDump()); + }); + T.assert('number' === typeof k1.pointer). + mustThrowMatching(()=>k1.pointer = 1, /pointer/); + k1.$p4 = 1; k1.$pP = 2; + T.assert(1 === k1.$p4).assert(2 === k1.$pP); + if(MyStructDef.members.$p8){ + k1.$p8 = 1/*must not throw despite not being a BigInt*/; + k1.$p8 = BigInt(Number.MAX_SAFE_INTEGER * 2); + T.assert(BigInt(2 * Number.MAX_SAFE_INTEGER) === k1.$p8); + } + T.assert(!k1.ondispose); + k1.setMemberCString('cstr', "A C-string."); + T.assert(Array.isArray(k1.ondispose)). + assert(k1.ondispose[0] === k1.$cstr). + assert('number' === typeof k1.$cstr). + assert('A C-string.' === k1.memberToJsString('cstr')); + k1.$pP = k2; + T.assert(k1.$pP === k2.pointer); + k1.$pP = null/*null is special-cased to 0.*/; + T.assert(0===k1.$pP); + let ptr = k1.pointer; + k1.dispose(); + T.assert(undefined === k1.pointer). + mustThrowMatching(()=>{k1.$pP=1}, /disposed instance/); + }finally{ + k1.dispose(); + k2.dispose(); } - wts.$v4 = 10; wts.$v8 = 20; - wts.$xFunc = W.installFunction(wtsFunc, wts.memberSignature('xFunc')) - T.assert(0===counter).assert(10 === wts.$v4).assert(20n === wts.$v8) - .assert(0 === wts.$ppV).assert('number' === typeof wts.$xFunc) - .assert(0 === wts.$cstr) - .assert(wts.memberIsString('$cstr')) - .assert(!wts.memberIsString('$v4')) - .assert(null === wts.memberToJsString('$cstr')) - .assert(W.functionEntry(wts.$xFunc) instanceof Function); - /* It might seem silly to assert that the values match - what we just set, but recall that all of those property - reads and writes are, via property interceptors, - actually marshaling their data to/from a raw memory - buffer, so merely reading them back is actually part of - testing the struct-wrapping API. */ - testFunc(wts.pointer); - //log("wts.pointer, wts.$ppV",wts.pointer, wts.$ppV); - T.assert(1===counter).assert(20 === wts.$v4).assert(40n === wts.$v8) - .assert(wts.$ppV === wts.pointer) - .assert('string' === typeof wts.memberToJsString('cstr')) - .assert(wts.memberToJsString('cstr') === wts.memberToJsString('$cstr')) - .mustThrowMatching(()=>wts.memberToJsString('xFunc'), - /Invalid member type signature for C-string/) - ; - testFunc(wts.pointer); - T.assert(2===counter).assert(40 === wts.$v4).assert(80n === wts.$v8) - .assert(wts.$ppV === wts.pointer); - /** The 3rd call to wtsFunc throw from JS, which is called - from C, which is called from JS. Let's ensure that - that exception propagates back here... */ - T.mustThrowMatching(()=>testFunc(wts.pointer),/^Testing/); - W.uninstallFunction(wts.$xFunc); - wts.$xFunc = 0; - wts.$ppV = 0; - T.assert(!wts.$ppV); - //WTStruct.debugFlags(0x03); - wts.$ppV = wts; - T.assert(wts.pointer === wts.$ppV) - wts.setMemberCString('cstr', "A C-string."); - T.assert(Array.isArray(wts.ondispose)). - assert(wts.ondispose[0] === wts.$cstr). - assert('A C-string.' === wts.memberToJsString('cstr')); - const ptr = wts.pointer; - wts.dispose(); - T.assert(ptr).assert(undefined === wts.pointer); - }finally{ - wts.dispose(); - } + if(!W.bigIntEnabled){ + log("Skipping WasmTestStruct tests: BigInt not enabled."); + return; + } - if(1){ // ondispose of other struct instances - const s1 = new WTStruct, s2 = new WTStruct, s3 = new WTStruct; - T.assert(s1.lookupMember instanceof Function) - .assert(s1.addOnDispose instanceof Function); - s1.addOnDispose(s2,"testing variadic args"); - T.assert(2===s1.ondispose.length); - s2.addOnDispose(s3); - s1.dispose(); - T.assert(!s2.pointer,"Expecting s2 to be ondispose'd by s1."); - T.assert(!s3.pointer,"Expecting s3 to be ondispose'd by s2."); + const WTStructDesc = + W.ctype.structs.filter((e)=>'WasmTestStruct'===e.name)[0]; + const autoResolvePtr = true /* EXPERIMENTAL */; + if(autoResolvePtr){ + WTStructDesc.members.ppV.signature = 'P'; + } + const WTStruct = S.StructBinder(WTStructDesc); + //log(WTStruct.structName, WTStruct.structInfo); + const wts = new WTStruct(); + //log("WTStruct.prototype keys:",Object.keys(WTStruct.prototype)); + try{ + T.assert(wts.constructor === WTStruct). + assert(WTStruct.memberKeys().indexOf('$ppV')>=0). + assert(wts.memberKeys().indexOf('$v8')>=0). + assert(!K.isA(wts)). + assert(WTStruct.isA(wts)). + assert(wts instanceof WTStruct). + assert(wts instanceof StructType). + assert(StructType.isA(wts)). + assert(wts.pointer>0).assert(0===wts.$v4).assert(0n===wts.$v8). + assert(0===wts.$ppV).assert(0===wts.$xFunc); + const testFunc = + W.xGet('sqlite3__wasm_test_struct'/*name gets mangled in -O3 builds!*/); + let counter = 0; + //log("wts.pointer =",wts.pointer); + const wtsFunc = function(arg){ + /*log("This from a JS function called from C, "+ + "which itself was called from JS. arg =",arg);*/ + ++counter; + if(3===counter){ + tossQuietly("Testing exception propagation."); + } + } + wts.$v4 = 10; wts.$v8 = 20; + wts.$xFunc = W.installFunction(wtsFunc, wts.memberSignature('xFunc')) + T.assert(0===counter).assert(10 === wts.$v4).assert(20n === wts.$v8) + .assert(0 === wts.$ppV).assert('number' === typeof wts.$xFunc) + .assert(0 === wts.$cstr) + .assert(wts.memberIsString('$cstr')) + .assert(!wts.memberIsString('$v4')) + .assert(null === wts.memberToJsString('$cstr')) + .assert(W.functionEntry(wts.$xFunc) instanceof Function); + /* It might seem silly to assert that the values match + what we just set, but recall that all of those property + reads and writes are, via property interceptors, + actually marshaling their data to/from a raw memory + buffer, so merely reading them back is actually part of + testing the struct-wrapping API. */ + + testFunc(wts.pointer); + //log("wts.pointer, wts.$ppV",wts.pointer, wts.$ppV); + T.assert(1===counter).assert(20 === wts.$v4).assert(40n === wts.$v8) + .assert(wts.$ppV === wts.pointer) + .assert('string' === typeof wts.memberToJsString('cstr')) + .assert(wts.memberToJsString('cstr') === wts.memberToJsString('$cstr')) + .mustThrowMatching(()=>wts.memberToJsString('xFunc'), + /Invalid member type signature for C-string/) + ; + testFunc(wts.pointer); + T.assert(2===counter).assert(40 === wts.$v4).assert(80n === wts.$v8) + .assert(wts.$ppV === wts.pointer); + /** The 3rd call to wtsFunc throw from JS, which is called + from C, which is called from JS. Let's ensure that + that exception propagates back here... */ + T.mustThrowMatching(()=>testFunc(wts.pointer),/^Testing/); + W.uninstallFunction(wts.$xFunc); + wts.$xFunc = 0; + wts.$ppV = 0; + T.assert(!wts.$ppV); + //WTStruct.debugFlags(0x03); + wts.$ppV = wts; + T.assert(wts.pointer === wts.$ppV) + wts.setMemberCString('cstr', "A C-string."); + T.assert(Array.isArray(wts.ondispose)). + assert(wts.ondispose[0] === wts.$cstr). + assert('A C-string.' === wts.memberToJsString('cstr')); + const ptr = wts.pointer; + wts.dispose(); + T.assert(ptr).assert(undefined === wts.pointer); + }finally{ + wts.dispose(); + } + + if(1){ // ondispose of other struct instances + const s1 = new WTStruct, s2 = new WTStruct, s3 = new WTStruct; + T.assert(s1.lookupMember instanceof Function) + .assert(s1.addOnDispose instanceof Function); + s1.addOnDispose(s2,"testing variadic args"); + T.assert(2===s1.ondispose.length); + s2.addOnDispose(s3); + s1.dispose(); + T.assert(!s2.pointer,"Expecting s2 to be ondispose'd by s1."); + T.assert(!s3.pointer,"Expecting s3 to be ondispose'd by s2."); + } } }/*StructBinder*/) @@ -1126,75 +1131,84 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //////////////////////////////////////////////////////////////////////// T.g('sqlite3.oo1') - .t('Create db', function(sqlite3){ - const dbFile = '/tester1.db'; - sqlite3.util.sqlite3__wasm_vfs_unlink(0, dbFile); - const db = this.db = new sqlite3.oo1.DB(dbFile, 0 ? 'ct' : 'c'); - db.onclose = { - disposeAfter: [], - disposeBefore: [ - (db)=>{ - //console.debug("db.onclose.before dropping modules"); - //sqlite3.capi.sqlite3_drop_modules(db.pointer, 0); - } - ], - before: function(db){ - while(this.disposeBefore.length){ - const v = this.disposeBefore.shift(); - console.debug("db.onclose.before cleaning up:",v); - if(wasm.isPtr(v)) wasm.dealloc(v); - else if(v instanceof sqlite3.StructBinder.StructType){ - v.dispose(); - }else if(v instanceof Function){ - try{ v(db) } catch(e){ - console.warn("beforeDispose() callback threw:",e); + .t({ + name:'Create db', + //predicate: (sqlite3)=> + test: function(sqlite3){ + const dbFile = '/tester1.db'; + sqlite3.util.sqlite3__wasm_vfs_unlink(0, dbFile); + const db = this.db = new sqlite3.oo1.DB(dbFile, 0 ? 'ct' : 'c'); + db.onclose = { + disposeAfter: [], + disposeBefore: [ + (db)=>{ + //console.debug("db.onclose.before dropping modules"); + //sqlite3.capi.sqlite3_drop_modules(db.pointer, 0); + } + ], + before: function(db){ + while(this.disposeBefore.length){ + const v = this.disposeBefore.shift(); + console.debug("db.onclose.before cleaning up:",v); + if(wasm.isPtr(v)) wasm.dealloc(v); + else if(v instanceof sqlite3.StructBinder.StructType){ + v.dispose(); + }else if(v instanceof Function){ + try{ v(db) } catch(e){ + console.warn("beforeDispose() callback threw:",e); + } + } + } + }, + after: function(){ + while(this.disposeAfter.length){ + const v = this.disposeAfter.shift(); + console.debug("db.onclose.after cleaning up:",v); + if(wasm.isPtr(v)) wasm.dealloc(v); + else if(v instanceof sqlite3.StructBinder.StructType){ + v.dispose(); + }else if(v instanceof Function){ + try{v()} catch(e){/*ignored*/} } } } - }, - after: function(){ - while(this.disposeAfter.length){ - const v = this.disposeAfter.shift(); - console.debug("db.onclose.after cleaning up:",v); - if(wasm.isPtr(v)) wasm.dealloc(v); - else if(v instanceof sqlite3.StructBinder.StructType){ - v.dispose(); - }else if(v instanceof Function){ - try{v()} catch(e){/*ignored*/} - } - } + }; + + T.assert(wasm.isPtr(db.pointer)) + .mustThrowMatching(()=>db.pointer=1, /read-only/) + .assert(0===sqlite3.capi.sqlite3_extended_result_codes(db.pointer,1)) + .assert('main'===db.dbName(0)) + .assert('string' === typeof db.dbVfsName()) + .assert(db.pointer === wasm.xWrap.testConvertArg('sqlite3*',db)); + // Custom db error message handling via sqlite3_prepare_v2/v3() + let rc = capi.sqlite3_prepare_v3(db.pointer, {/*invalid*/}, -1, 0, null, null); + T.assert(capi.SQLITE_MISUSE === rc) + .assert(0 === capi.sqlite3_errmsg(db.pointer).indexOf("Invalid SQL")) + .assert(dbFile === db.dbFilename()) + .assert(!db.dbFilename('nope')); + //Sanity check DB.checkRc()... + let ex; + try{db.checkRc(rc)} + catch(e){ex = e} + T.assert(ex instanceof sqlite3.SQLite3Error) + .assert(capi.SQLITE_MISUSE===ex.resultCode) + .assert(0===ex.message.indexOf("SQLITE_MISUSE: sqlite3 result code")) + .assert(ex.message.indexOf("Invalid SQL")>0); + T.assert(db === db.checkRc(0)) + .assert(db === sqlite3.oo1.DB.checkRc(db,0)) + .assert(null === sqlite3.oo1.DB.checkRc(null,0)); + + this.progressHandlerCount = 0; + if( wasm.compileOptionUsed('OMIT_PROGRESS_CALLBACK') ){ + T.assert( !capi.sqlite3_progress_handler ); + }else{ + T.assert( capi.sqlite3_progress_handler ); + capi.sqlite3_progress_handler(db, 5, (p)=>{ + ++this.progressHandlerCount; + return 0; + }, 0); } - }; - - T.assert(wasm.isPtr(db.pointer)) - .mustThrowMatching(()=>db.pointer=1, /read-only/) - .assert(0===sqlite3.capi.sqlite3_extended_result_codes(db.pointer,1)) - .assert('main'===db.dbName(0)) - .assert('string' === typeof db.dbVfsName()) - .assert(db.pointer === wasm.xWrap.testConvertArg('sqlite3*',db)); - // Custom db error message handling via sqlite3_prepare_v2/v3() - let rc = capi.sqlite3_prepare_v3(db.pointer, {/*invalid*/}, -1, 0, null, null); - T.assert(capi.SQLITE_MISUSE === rc) - .assert(0 === capi.sqlite3_errmsg(db.pointer).indexOf("Invalid SQL")) - .assert(dbFile === db.dbFilename()) - .assert(!db.dbFilename('nope')); - //Sanity check DB.checkRc()... - let ex; - try{db.checkRc(rc)} - catch(e){ex = e} - T.assert(ex instanceof sqlite3.SQLite3Error) - .assert(capi.SQLITE_MISUSE===ex.resultCode) - .assert(0===ex.message.indexOf("SQLITE_MISUSE: sqlite3 result code")) - .assert(ex.message.indexOf("Invalid SQL")>0); - T.assert(db === db.checkRc(0)) - .assert(db === sqlite3.oo1.DB.checkRc(db,0)) - .assert(null === sqlite3.oo1.DB.checkRc(null,0)); - - this.progressHandlerCount = 0; - capi.sqlite3_progress_handler(db, 5, (p)=>{ - ++this.progressHandlerCount; - return 0; - }, 0); + } }) //////////////////////////////////////////////////////////////////// .t('sqlite3_db_config() and sqlite3_db_status()', function(sqlite3){ @@ -1236,7 +1250,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule; new TextEncoder('utf-8').encode("select 3 as a") ); //debug("statement =",st); - this.progressHandlerCount = 0; + T.assert( !this.progressHandlerCount ); let rc; try { T.assert(wasm.isPtr(st.pointer)) @@ -1278,7 +1292,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule; st, capi.SQLITE_STMTSTATUS_RUN, 0 ) > 0); - T.assert(this.progressHandlerCount > 0, + T.assert(this.progressHandlerCount>0 + || wasm.compileOptionUsed('OMIT_PROGRESS_CALLBACK'), "Expecting progress callback."). assert(0===capi.sqlite3_strglob("*.txt", "foo.txt")). assert(0!==capi.sqlite3_strglob("*.txt", "foo.xtx")). @@ -1363,7 +1378,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule; .assert(2 === list.length) .assert('string'===typeof list[1]) .assert(3===db.changes()) - .assert(this.progressHandlerCount > 0, + .assert(this.progressHandlerCount > 0 + || wasm.compileOptionUsed('OMIT_PROGRESS_CALLBACK'), "Expecting progress callback.") if(wasm.bigIntEnabled){ T.assert(3n===db.changes(false,true)); @@ -1904,7 +1920,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule; //////////////////////////////////////////////////////////////////// .t({ name: 'Window UDFs', - //predicate: ()=>false, + predicate: (sqlite3)=>!!sqlite3.wasm.exports.sqlite3_create_window_function + /*!sqlite3.wasm.compileOptionUsed('OMIT_WINDOWFUNC')*/ + || "Missing window functions", test: function(){ /* Example window function, table, and results taken from: https://sqlite.org/windowfunctions.html#udfwinfunc */ @@ -3132,7 +3150,10 @@ globalThis.sqlite3InitModule = sqlite3InitModule; ]); T.assert(2 === u1.getFileCount() /* one is the journal file */) .assert(3 === db.selectValue('select count(*) from t')) - .assert('wal'===db.selectValue('pragma journal_mode')); + .assert( + 'wal'===db.selectValue('pragma journal_mode') + || wasm.compileOptionUsed('OMIT_WAL') + ); db.close(); T.assert(1 === u1.getFileCount()); db = new u2.OpfsSAHPoolDb(dbName); diff --git a/manifest b/manifest index 6b6d0243f4..1df2fad795 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\swork\son\sthe\sminimal-mode\swasm\sbuild\s(now\s603kb\suncompressed).\sRemove\sthe\shard-coded\sfeature-enable\sflags\sfrom\ssqlite3-wasm.c\sand\srely\son\sthe\sbuild\sto\sprovide\sthem.\sSome\swasm\sbuild\scleanup,\sbut\sattempts\sto\scompletely\soverhaul\sit\shave\sbeen\sthwarted\sby\smy\sinability\sto\smake\sscript-generated\smakefile\scode\smore\slegible/maintainable\sthan\sthe\scurrent\seval\sspaghetti. -D 2024-07-25T14:00:26.899 +C Strip\sprogress\shandlers\sand\swindow\sfunctions\sfrom\sthe\swasm\sbare-bones\s(formerly\s'minimal')\sJS\sbits,\snoting\sthat\swe\scan't\syet\suse\sOMIT_WINDOWFUNC\s(for\sthe\sC\sparts)\swithout\sa\scustom\samalgamation.\sCurrently\sat\s604kb. +D 2024-07-25T16:21:19.087 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -593,7 +593,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile c89b6d0e7f969de03cfcbd5d5f64985ee9ba823a7be6b150fb9c2976c7adb0d6 +F ext/wasm/GNUmakefile 1857ad71bfdc780019639f49dc054fee491b4ddba2669898b8acfd4ffba50030 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -601,8 +601,8 @@ F ext/wasm/SQLTester/SQLTester.mjs ce765c0ad7d57f93553d12ef4dca574deb00300134a26 F ext/wasm/SQLTester/SQLTester.run.mjs c72b7fe2072d05992f7a3d8c6a1d34e95712513ceabe40849784e24e41c84638 F ext/wasm/SQLTester/index.html 3f8a016df0776be76605abf20e815ecaafbe055abac0e1fe5ea080e7846b760d F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f3038b96460fc5e5aa7e536 -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core 38f85e6ec5f9c776087bc38aef9ef35eeb7e54942ddb1dd04e9ac0122958b741 -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras 2a8c9f7d865cc6e5661b2cd40a45e963a1f8070a88def6ead4c40d4fa0c91998 +F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core 2bcbbfe3b95c043ed6037e2708a2ee078d212dd1612c364f93588d8dc97300fe +F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras fe40d6d758646e38f8b15f709044951e10884214f5453d35502100179c388c13 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 34fe11466f9c1d81b10a0469e1114e5f1c5a6365c73d80a1a6ca639a1a358b73 @@ -612,7 +612,7 @@ F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e -F ext/wasm/api/sqlite3-api-glue.c-pp.js 12f6f3840afdf8ff7a4374dc1a96a26bcc369e17853e0fe917c38f4d66c6e2d8 +F ext/wasm/api/sqlite3-api-glue.c-pp.js fb6dbfe692cc23000a65a4cd95a1a47ed5eb592dc9d8b55363b3c2952a787244 F ext/wasm/api/sqlite3-api-oo1.c-pp.js f3a8e2004c6625d17946c11f2fb32008be78bc5207bf746fc77d59848813225f F ext/wasm/api/sqlite3-api-prologue.js 6f1257e04885632ed9f44d43aba200b86e0bc16709ffdba29abbbeb1bc8e8b76 F ext/wasm/api/sqlite3-api-worker1.c-pp.js 5cc22a3c0d52828cb32aad8691488719f47d27567e63e8bc8b832d74371c352d @@ -622,7 +622,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js e529a99b7d5a088284821e2902b20d3404b561126969876997d5a73a656c9199 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js e99e3d99f736937914527070f00ab13e9391d3f1cef884ab99a64cbcbee8d675 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616 -F ext/wasm/api/sqlite3-wasm.c 79335b70d4d404b33fb485a4f65422a1ded0977c38e3b1a0cd8e26b49d3c9fba +F ext/wasm/api/sqlite3-wasm.c 83f5e9f998e9fa4261eb84e9f092210e3ffe03895119f5ded0429eb34ab9d2be F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -645,7 +645,7 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 653e212c1e84aa3be168d62a10616ccea45ee9585b0192745d2706707a5248ce F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make 2406b02473878a99fb6a2eaff0923277017adc45eb041b2afb2d7707bf7b375c +F ext/wasm/fiddle.make b3b118516ed581cdf2c16de8eb1672427320e67ff19d710a09c891e895883644 F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 F ext/wasm/fiddle/index.html 739e0b75bc592679665d25e2f7649d2b8b2db678f3b41a772a8720b609b8482d @@ -669,7 +669,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js 7d0eba1496286338770133356488b4415de7970f4ee2c08f7f587bb18d8b6b0b +F ext/wasm/tester1.c-pp.js eb56110cd1959fc72c4001decc066ac7978912304e08aa402ca76527007cea5a F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2197,8 +2197,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ed746b3dd3248b68cb91de50ac5ba5fd3a7c2fcbde76324e86b88edbfecd896b -R acaefae7f2493e8276236de40774aafc +P b029c4067943e366a9b25b8303136fab10822bd771ea4658ac4cd716ff4a0d8f +R 4aba6600c1b56bb40f0e32cfcacb9fbe U stephan -Z 2f4bcd240a0ced338bed244e56f0f58c +Z c6f1d9cf14c3543f4f2774a34de2bf76 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 930c8e1a51..6de85ff0e9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b029c4067943e366a9b25b8303136fab10822bd771ea4658ac4cd716ff4a0d8f +ec02e9237e1ef81c4196fa630822cb109eab926143ad09593a24273eb0668601 From d35a69a8da0a5a5c54823df540f0217c1601816b Mon Sep 17 00:00:00 2001 From: stephan Date: Thu, 25 Jul 2024 16:28:55 +0000 Subject: [PATCH 04/50] Fix a non-bare-bones-mode test case broken by the previous checkin. FossilOrigin-Name: 3be729493b76a8b51c19d81543dea2dcb1fc718f81d4f2d9c6e1381789217687 --- ext/wasm/tester1.c-pp.js | 3 +-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 6023069bc4..fd67dc01c3 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -1197,12 +1197,11 @@ globalThis.sqlite3InitModule = sqlite3InitModule; T.assert(db === db.checkRc(0)) .assert(db === sqlite3.oo1.DB.checkRc(db,0)) .assert(null === sqlite3.oo1.DB.checkRc(null,0)); - this.progressHandlerCount = 0; if( wasm.compileOptionUsed('OMIT_PROGRESS_CALLBACK') ){ T.assert( !capi.sqlite3_progress_handler ); }else{ - T.assert( capi.sqlite3_progress_handler ); + T.assert( !!capi.sqlite3_progress_handler ); capi.sqlite3_progress_handler(db, 5, (p)=>{ ++this.progressHandlerCount; return 0; diff --git a/manifest b/manifest index 1df2fad795..c392f70d94 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Strip\sprogress\shandlers\sand\swindow\sfunctions\sfrom\sthe\swasm\sbare-bones\s(formerly\s'minimal')\sJS\sbits,\snoting\sthat\swe\scan't\syet\suse\sOMIT_WINDOWFUNC\s(for\sthe\sC\sparts)\swithout\sa\scustom\samalgamation.\sCurrently\sat\s604kb. -D 2024-07-25T16:21:19.087 +C Fix\sa\snon-bare-bones-mode\stest\scase\sbroken\sby\sthe\sprevious\scheckin. +D 2024-07-25T16:28:55.294 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -669,7 +669,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.html ebc4b820a128963afce328ecf63ab200bd923309eb939f4110510ab449e9814c F ext/wasm/tester1.c-pp.html 1c1bc78b858af2019e663b1a31e76657b73dc24bede28ca92fbe917c3a972af2 -F ext/wasm/tester1.c-pp.js eb56110cd1959fc72c4001decc066ac7978912304e08aa402ca76527007cea5a +F ext/wasm/tester1.c-pp.js bb8c41a56ca0eabb945ca2e8f06324a7b63ad91630959d714b071bee88322019 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2197,8 +2197,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b029c4067943e366a9b25b8303136fab10822bd771ea4658ac4cd716ff4a0d8f -R 4aba6600c1b56bb40f0e32cfcacb9fbe +P ec02e9237e1ef81c4196fa630822cb109eab926143ad09593a24273eb0668601 +R 72c1b5abda53d89da6a43993db19cd53 U stephan -Z c6f1d9cf14c3543f4f2774a34de2bf76 +Z 8d08c3414a4f5b6a65c45fd3dc3ee076 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6de85ff0e9..5054a64027 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ec02e9237e1ef81c4196fa630822cb109eab926143ad09593a24273eb0668601 +3be729493b76a8b51c19d81543dea2dcb1fc718f81d4f2d9c6e1381789217687 From 1d9db01065d3d855d33c257711ef40486b122885 Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 23 Sep 2024 20:23:43 +0000 Subject: [PATCH 05/50] CLI uses only lib-c for I/O on Windows. No calls to Win32. Works on Win11, at least. Reads and writes unicode to/from the console and UTF-8 to/from files. Prototype code only - must testing and additional work required. FossilOrigin-Name: 5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da --- Makefile.in | 2 - Makefile.msc | 2 - main.mk | 2 - manifest | 21 +++--- manifest.uuid | 2 +- src/shell.c.in | 190 ++++++++++++++++++++++++++++--------------------- 6 files changed, 122 insertions(+), 97 deletions(-) diff --git a/Makefile.in b/Makefile.in index dba80d38fb..7b693b5225 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1187,8 +1187,6 @@ keywordhash.h: $(TOP)/tool/mkkeywordhash.c # Source and header files that shell.c depends on SHELL_DEP = \ $(TOP)/src/shell.c.in \ - $(TOP)/ext/consio/console_io.c \ - $(TOP)/ext/consio/console_io.h \ $(TOP)/ext/expert/sqlite3expert.c \ $(TOP)/ext/expert/sqlite3expert.h \ $(TOP)/ext/intck/sqlite3intck.c \ diff --git a/Makefile.msc b/Makefile.msc index 434c996608..bb63601518 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2316,8 +2316,6 @@ keywordhash.h: $(TOP)\tool\mkkeywordhash.c mkkeywordhash.exe # Source and header files that shell.c depends on SHELL_DEP = \ $(TOP)\src\shell.c.in \ - $(TOP)\ext\consio\console_io.c \ - $(TOP)\ext\consio\console_io.h \ $(TOP)\ext\expert\sqlite3expert.c \ $(TOP)\ext\expert\sqlite3expert.h \ $(TOP)\ext\intck\sqlite3intck.c \ diff --git a/main.mk b/main.mk index 79e345d1b8..8aaa7e7d06 100644 --- a/main.mk +++ b/main.mk @@ -763,8 +763,6 @@ keywordhash.h: $(TOP)/tool/mkkeywordhash.c # Source and header files that shell.c depends on SHELL_DEP = \ $(TOP)/src/shell.c.in \ - $(TOP)/ext/consio/console_io.c \ - $(TOP)/ext/consio/console_io.h \ $(TOP)/ext/expert/sqlite3expert.c \ $(TOP)/ext/expert/sqlite3expert.h \ $(TOP)/ext/intck/sqlite3intck.c \ diff --git a/manifest b/manifest index ca881335f6..8b26ee7843 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Add\sthe\srun-fuzzcheck\starget\sto\sthe\sMSVC\smakefile. -D 2024-09-21T17:27:47.017 +C CLI\suses\sonly\slib-c\sfor\sI/O\son\sWindows.\s\sNo\scalls\sto\sWin32.\s\sWorks\son\sWin11,\nat\sleast.\s\sReads\sand\swrites\sunicode\sto/from\sthe\sconsole\sand\sUTF-8\sto/from\sfiles.\nPrototype\scode\sonly\s-\smust\stesting\sand\sadditional\swork\srequired. +D 2024-09-23T20:23:43.341 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in fa448c4c0567623fd140efebecb570ab58d955d766a5ea0fd8a94e9b5697007c +F Makefile.in aa594119c3c7f699e87a767fca6598452f77d4c32c41a6486c40d4f156d4efc1 F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc e3c4723c27464acc31da4420b808c8d2690180ba2b915897bece0a9d5d2cecf6 +F Makefile.msc add7e29bae33ad5b8c464daf6de84a1a01e31e6337d79fb0c1062e53fa7657da F README.md c3c0f19532ce28f6297a71870f3c7b424729f0e6d9ab889616d3587dd2332159 F VERSION 0db40f92c04378404eb45bff93e9e42c148c7e54fd3da99469ed21e22411f5a6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -687,7 +687,7 @@ F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 -F main.mk 67e622f31d10fee8f0f62655b4f9b47cd97fe70a125674ca6754b3549d69cc0e +F main.mk b897586c0c7b77b7e39f0a0e9ed79fed7346b09af1ed35a08da745e02b795772 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 @@ -768,7 +768,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 375f8a183126be96ec73db4e42c57917ff10a0900846b1b722dd4f8cef537812 +F src/shell.c.in 265c877932142ee8ef05a6aa5a0a5bff92905ffef97dc6f566062a27814274a1 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2213,8 +2213,11 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 62e11a3a78edf9853b74d6495ccd8ae9ac1966c7d78eb3682cf2d5885e3740ec -R 44ce456c4e740a869984e636809287df +P 2e5194407a1b34dd0659c350ea8098bfef7b3f11aa5b2a07ecd2bce5582655a2 +R 7c20c2fd1880ef1b062b32c88da2e8e4 +T *branch * cli-stdlib +T *sym-cli-stdlib * +T -sym-trunk * U drh -Z fb345da7ed81e5875e018c3667e473a3 +Z cdf0bc25a30881c9fe4f62b1ff96af22 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c7adf060ec..7417271d4a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2e5194407a1b34dd0659c350ea8098bfef7b3f11aa5b2a07ecd2bce5582655a2 +5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da diff --git a/src/shell.c.in b/src/shell.c.in index 2b0e506ed8..a2b22845d6 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -237,6 +237,57 @@ extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR); extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText); #endif +#ifdef _WIN32 +/* On Windows, we normally run with output mode of TEXT so that \n characters +** are automatically translated into \r\n. However, this behavior needs +** to be disabled in some cases (ex: when generating CSV output and when +** rendering quoted strings that contain \n characters). The following +** routines take care of that. +*/ +static void setBinaryMode(FILE *file, int isOutput){ + if( isOutput ) fflush(file); + _setmode(_fileno(file), _O_BINARY); +} +static void setTextMode(FILE *file, int isOutput){ + if( isOutput ) fflush(file); + _setmode(_fileno(file), _O_TEXT); +} +#else + /* Unix equivalents to set*Mode() */ +# define setBinaryMode(X,Y) +# define setTextMode(X,Y) +#endif + +#ifdef _WIN32 +/* fgets() for windows */ +static char *cli_fgets(char *buf, int sz, FILE *in){ + if( isatty(_fileno(in)) ){ + /* When reading from the command-prompt in Windows, it is necessary + ** to use _O_WTEXT input mode to read UTF-16 characters, then translate + ** that into UTF-8. Otherwise, non-ASCII characters all get translated + ** into '?'. + */ + wchar_t *b1 = malloc( sz*sizeof(wchar_t) ); + if( b1==0 ) return 0; + _setmode(_fileno(in), _O_WTEXT); + if( fgetws(b1, sz/4, in)==0 ){ + sqlite3_free(b1); + return 0; + } + WideCharToMultiByte(CP_UTF8, 0, b1, -1, buf, sz, 0, 0); + sqlite3_free(b1); + return buf; + }else{ + /* Reading from a file or other input source, just read bytes without + ** any translation. */ + return fgets(buf, sz, in); + } +} +#else +/* library version works for everybody else */ +# define cli_fgets fgets +#endif + /* Use console I/O package as a direct INCLUDE. */ #define SQLITE_INTERNAL_LINKAGE static @@ -248,57 +299,15 @@ extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText); # define SQLITE_CIO_NO_SETMODE # define SQLITE_CIO_NO_FLUSH #endif -INCLUDE ../ext/consio/console_io.h -INCLUDE ../ext/consio/console_io.c -#ifndef SQLITE_SHELL_FIDDLE - -/* From here onward, fgets() is redirected to the console_io library. */ -# define fgets(b,n,f) fGetsUtf8(b,n,f) -/* - * Define macros for emitting output text in various ways: - * sputz(s, z) => emit 0-terminated string z to given stream s - * sputf(s, f, ...) => emit varargs per format f to given stream s - * oputz(z) => emit 0-terminated string z to default stream - * oputf(f, ...) => emit varargs per format f to default stream - * eputz(z) => emit 0-terminated string z to error stream - * eputf(f, ...) => emit varargs per format f to error stream - * oputb(b, n) => emit char buffer b[0..n-1] to default stream - * - * Note that the default stream is whatever has been last set via: - * setOutputStream(FILE *pf) - * This is normally the stream that CLI normal output goes to. - * For the stand-alone CLI, it is stdout with no .output redirect. - * - * The ?putz(z) forms are required for the Fiddle builds for string literal - * output, in aid of enforcing format string to argument correspondence. - */ -# define sputz(s,z) fPutsUtf8(z,s) -# define sputf fPrintfUtf8 -# define oputz(z) oPutsUtf8(z) -# define oputf oPrintfUtf8 -# define eputz(z) ePutsUtf8(z) -# define eputf ePrintfUtf8 -# define oputb(buf,na) oPutbUtf8(buf,na) -# define fflush(s) fFlushBuffer(s); - -#else -/* For Fiddle, all console handling and emit redirection is omitted. */ -/* These next 3 macros are for emitting formatted output. When complaints - * from the WASM build are issued for non-formatted output, when a mere - * string literal is to be emitted, the ?putz(z) forms should be used. - * (This permits compile-time checking of format string / argument mismatch.) - */ -# define oputf(fmt, ...) printf(fmt,__VA_ARGS__) -# define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__) -# define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__) +#define oputf(fmt, ...) printf(fmt,__VA_ARGS__) +#define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__) +#define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__) /* These next 3 macros are for emitting simple string literals. */ -# define oputz(z) fputs(z,stdout) -# define eputz(z) fputs(z,stderr) -# define sputz(fp,z) fputs(z,fp) -# define oputb(buf,na) fwrite(buf,1,na,stdout) -# undef fflush -#endif +#define oputz(z) fputs(z,stdout) +#define eputz(z) fputs(z,stderr) +#define sputz(fp,z) fputs(z,fp) +#define oputb(buf,na) fwrite(buf,1,na,stdout) /* True if the timer is enabled */ static int enableTimer = 0; @@ -344,6 +353,7 @@ struct rusage { #define getrusage(A,B) memset(B,0,sizeof(*B)) #endif + /* Saved resource information for the beginning of an operation */ static struct rusage sBegin; /* CPU time at start */ static sqlite3_int64 iBegin; /* Wall-clock time at start */ @@ -802,7 +812,7 @@ static char *local_getline(char *zLine, FILE *in){ zLine = realloc(zLine, nLine); shell_check_oom(zLine); } - if( fgets(&zLine[n], nLine - n, in)==0 ){ + if( cli_fgets(&zLine[n], nLine - n, in)==0 ){ if( n==0 ){ free(zLine); return 0; @@ -1766,10 +1776,7 @@ static const char *unused_string( static void output_quoted_string(const char *z){ int i; char c; -#ifndef SQLITE_SHELL_FIDDLE - FILE *pfO = setOutputStream(invalidFileStream); - setBinaryMode(pfO, 1); -#endif + setBinaryMode(stdout, 1); if( z==0 ) return; for(i=0; (c = z[i])!=0 && c!='\''; i++){} if( c==0 ){ @@ -1794,11 +1801,7 @@ static void output_quoted_string(const char *z){ } oputz("'"); } -#ifndef SQLITE_SHELL_FIDDLE - setTextMode(pfO, 1); -#else setTextMode(stdout, 1); -#endif } /* @@ -1813,10 +1816,7 @@ static void output_quoted_string(const char *z){ static void output_quoted_escaped_string(const char *z){ int i; char c; -#ifndef SQLITE_SHELL_FIDDLE - FILE *pfO = setOutputStream(invalidFileStream); - setBinaryMode(pfO, 1); -#endif + setBinaryMode(stdout, 1); for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){} if( c==0 ){ oputf("'%s'",z); @@ -1868,11 +1868,7 @@ static void output_quoted_escaped_string(const char *z){ oputf(",'%s',char(10))", zNL); } } -#ifndef SQLITE_SHELL_FIDDLE - setTextMode(pfO, 1); -#else setTextMode(stdout, 1); -#endif } /* @@ -1892,6 +1888,42 @@ static const char *anyOfInStr(const char *s, const char *zAny, size_t ns){ } return pcFirst; } + +/* Skip over as much z[] input char sequence as is valid UTF-8, +** limited per nAccept char's or whole characters and containing +** no char cn such that ((1<=0 => char count, nAccept<0 => character + */ +const char *zSkipValidUtf8(const char *z, int nAccept, long ccm){ + int ng = (nAccept<0)? -nAccept : 0; + const char *pcLimit = (nAccept>=0)? z+nAccept : 0; + assert(z!=0); + while( (pcLimit)? (z= pcLimit ) return z; + else{ + char ct = *zt++; + if( ct==0 || (zt-z)>4 || (ct & 0xC0)!=0x80 ){ + /* Trailing bytes are too few, too many, or invalid. */ + return z; + } + } + } while( ((c <<= 1) & 0x40) == 0x40 ); /* Eat lead byte's count. */ + z = zt; + } + } + return z; +} + + /* ** Output the given string as a quoted according to C or TCL quoting rules. */ @@ -3027,7 +3059,7 @@ static void displayLinuxIoStats(void){ sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid()); in = fopen(z, "rb"); if( in==0 ) return; - while( fgets(z, sizeof(z), in)!=0 ){ + while( cli_fgets(z, sizeof(z), in)!=0 ){ static const struct { const char *zPattern; const char *zDesc; @@ -5238,7 +5270,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){ } *pnData = 0; nLine++; - if( fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error; + if( cli_fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error; rc = sscanf(zLine, "| size %d pagesize %d", &n, &pgsz); if( rc!=2 ) goto readHexDb_error; if( n<0 ) goto readHexDb_error; @@ -5251,7 +5283,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){ eputz("invalid pagesize\n"); goto readHexDb_error; } - for(nLine++; fgets(zLine, sizeof(zLine), in)!=0; nLine++){ + for(nLine++; cli_fgets(zLine, sizeof(zLine), in)!=0; nLine++){ rc = sscanf(zLine, "| page %d offset %d", &j, &k); if( rc==2 ){ iOffset = k; @@ -5283,7 +5315,7 @@ readHexDb_error: if( in!=p->in ){ fclose(in); }else{ - while( fgets(zLine, sizeof(zLine), p->in)!=0 ){ + while( cli_fgets(zLine, sizeof(zLine), p->in)!=0 ){ nLine++; if(cli_strncmp(zLine, "| end ", 6)==0 ) break; } @@ -6177,10 +6209,10 @@ static void tryToClone(ShellState *p, const char *zNewDb){ ** Change the output stream (file or pipe or console) to something else. */ static void output_redir(ShellState *p, FILE *pfNew){ - if( p->out != stdout ) eputz("Output already redirected.\n"); - else{ + if( p->out != stdout ){ + eputz("Output already redirected.\n"); + }else{ p->out = pfNew; - setOutputStream(pfNew); } } @@ -6226,7 +6258,6 @@ static void output_reset(ShellState *p){ } p->outfile[0] = 0; p->out = stdout; - setOutputStream(stdout); } #else # define output_redir(SS,pfO) @@ -10719,9 +10750,9 @@ static int do_meta_command(char *zLine, ShellState *p){ zCmd = sqlite3_mprintf(strchr(azArg[i],' ')==0?"%z %s":"%z \"%s\"", zCmd, azArg[i]); } - consoleRestore(); + /*consoleRestore();*/ x = zCmd!=0 ? system(zCmd) : 1; - consoleRenewSetup(); + /*consoleRenewSetup();*/ sqlite3_free(zCmd); if( x ) eputf("System command returns %d\n", x); }else @@ -12374,7 +12405,6 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ # define data shellState #else ShellState data; - StreamsAreConsole consStreams = SAC_NoConsole; #endif const char *zInitFile = 0; int i; @@ -12397,10 +12427,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ stdout_is_console = 1; data.wasm.zDefaultDbName = "/fiddle.sqlite3"; #else - consStreams = consoleClassifySetup(stdin, stdout, stderr); - stdin_is_interactive = (consStreams & SAC_InConsole)!=0; - stdout_is_console = (consStreams & SAC_OutConsole)!=0; - atexit(consoleRestore); + stdin_is_interactive = isatty(0); + stdout_is_console = isatty(1); #endif atexit(sayAbnormalExit); #ifdef SQLITE_DEBUG From 69cce89425b19d8e41ddfaefbe6bbe042cf3f116 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 23 Sep 2024 21:22:09 +0000 Subject: [PATCH 06/50] wasm: replace much of the eval makefile spaghetti with equivalent code generated from a small C app. It turns out that's easier to read and write than doing the same thing from shell or tcl code, due entirely to C's lack of need for escaping dollar signs. FossilOrigin-Name: 5440de48903e94f91090e2df65702ec0c504e33dd5cbd50f684cf30988f20b02 --- ext/wasm/GNUmakefile | 244 +++++++++++---------------------- ext/wasm/c-pp.c | 3 +- ext/wasm/make-make.sh | 98 ------------- ext/wasm/mkwasmbuilds.c | 216 +++++++++++++++++++++++++++++ ext/wasm/speedtest1-wasmfs.mjs | 12 +- ext/wasm/wasmfs.make | 21 ++- manifest | 22 +-- manifest.uuid | 2 +- 8 files changed, 326 insertions(+), 292 deletions(-) delete mode 100755 ext/wasm/make-make.sh create mode 100644 ext/wasm/mkwasmbuilds.c diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 50fedfef71..e40db6a5f4 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -56,8 +56,8 @@ ifeq (,$(SHELL)) $(error Cannot find the bash shell) endif MAKEFILE := $(lastword $(MAKEFILE_LIST)) -CLEAN_FILES := .gen.make -DISTCLEAN_FILES := ./--dummy-- +CLEAN_FILES := +DISTCLEAN_FILES := MAKING_CLEAN := $(if $(filter %clean,$(MAKECMDGOALS)),1,0) .PHONY: clean distclean clean: @@ -111,14 +111,13 @@ dir.common := common dir.fiddle := fiddle dir.fiddle-debug := fiddle-debug dir.tool := $(dir.top)/tool -# Maintenance reminder: the names of $(dir.dout) and $(dir.tmp) must -# stay in sync with make-make.sh -# +# dir.dout = output dir for deliverables +dir.dout := $(dir.wasm)/jswasm # dir.tmp = output dir for intermediary build files, as opposed to # end-user deliverables. -dir.dout := $(dir.wasm)/jswasm -# dir.dout = output dir for deliverables dir.tmp := $(dir.wasm)/bld +dir.wasmfs := $(dir.dout) + CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \ $(dir.fiddle-debug)/* $(dir.dout)/* $(dir.tmp)/* @@ -143,6 +142,13 @@ sqlite3.canonical.c := $(dir.top)/sqlite3.c sqlite3.c ?= $(firstword $(wildcard $(dir.top)/sqlite3-see.c) $(sqlite3.canonical.c)) sqlite3.h := $(dir.top)/sqlite3.h +ifeq (,$(shell grep sqlite3_activate_see $(sqlite3.c))) + SQLITE_C_IS_SEE := 0 +else + SQLITE_C_IS_SEE := 1 + $(info This is an SEE build) +endif + ########################################################################@ # It's important that sqlite3.h be built to completion before any # other parts of the build run, thus we use .NOTPARALLEL to disable @@ -152,26 +158,50 @@ $(sqlite3.h): $(MAKE) -C $(dir.top) sqlite3.c $(sqlite3.c): $(sqlite3.h) -######################################################################## -# .gen.make is generated by a shell script and holds certain parts -# of the makefile, some of which are relatively expensive to calculate -# on each run (that is, they can take a human-visible amount of time). -# -# Sidebar: three attempts have been made to move much of the -# $(eval)-generated makefile code into make-make.sh but the result is -# even less legible/maintainable than make-side $(eval). -ifeq (0,$(MAKING_CLEAN)) -.gen.make: $(MAKEFILE) $(sqlite3.c) - rm -f $@ - $(SHELL) make-make.sh $(sqlite3.c) > $@ - chmod -w $@ --include .gen.make -endif - ifeq (,$(filter release snapshot,$(MAKECMDGOALS))) $(info Development build. Use 'release' or 'snapshot' target for a smaller release build.) endif +######################################################################## +# Find emcc (Emscripten compiler)... +emcc.bin := $(shell which emcc 2>/dev/null) +ifeq (,$(emcc.bin)) + ifneq (,$(EMSDK_HOME)) + emcc.bin := $(wildcard $(EMSDK_HOME)/upstream/emscripten/emcc) + endif + ifeq (,$(emcc.bin)) + $(error Cannot find emcc in path.) + endif +endif +emcc.version := $(shell $(emcc.bin) --version | sed -n 1p | sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;') +$(info using emcc version [$(emcc.version)]) +######################################################################### +# Find wasm-strip, which we need for release builds (see below for +# why) but not strictly for non-release builds. +wasm-strip.bin ?= $(shell which wasm-strip 2>/dev/null) +ifeq (,$(wasm-strip.bin)) + ifeq (,$(filter clean,$(MAKECMDGOALS))) + $(info WARNING: *******************************************************************) + $(info WARNING: builds using -O2/-O3/-Os/-Oz will minify WASM-exported names,) + $(info WARNING: breaking _All The Things_. The workaround for that is to build) + $(info WARNING: with -g3 (which explodes the file size) and then strip the debug) + $(info WARNING: info after compilation, using wasm-strip, to shrink the wasm file.) + $(info WARNING: wasm-strip was not found in the PATH so we cannot strip those.) + $(info WARNING: If this build uses any optimization level higher than -O1 then) + $(info WARNING: the ***resulting JS code WILL NOT BE USABLE***.) + $(info WARNING: wasm-strip is part of the wabt package:) + $(info WARNING: https://github.com/WebAssembly/wabt) + $(info WARNING: on Ubuntu-like systems it can be installed with:) + $(info WARNING: sudo apt install wabt) + $(info WARNING: *******************************************************************) + endif + ifneq (,$(filter release snapshot,$(MAKECMDGOALS))) + $(error Cannot make release-quality binary because wasm-strip is not available.) + endif + wasm-strip.bin := echo "not wasm-stripping" +endif +maybe-wasm-strip := $(wasm-strip.bin) + ######################################################################## # barebones=1 disables all "extraneous" stuff from sqlite3-wasm.c, the # goal being to create a WASM file with only the core APIs. @@ -332,6 +362,18 @@ $(bin.stripccomments): $(bin.stripccomments).c $(MAKEFILE) $(CC) -o $@ $< DISTCLEAN_FILES += $(bin.stripccomments) +######################################################################## +# bin.mkwb is used for generating some of the makefile code for the +# various build builds. It used to be generated in this makefile via a +# difficult-to-read/maintain block of $(eval)'d code. Attempts were +# made to generate it from tcl and bash (shell) but having to escape +# the $ references in those languages made it just as illegible as the +# native makefile code. Somewhat surprisingly, moving that code generation +# to C makes it slightly less illegible than the previousq 3 options. +bin.mkwb := ./mkwasmbuilds +$(bin.mkwb): $(bin.mkwb).c $(MAKEFILE) + $(CC) -o $@ $< +DISTCLEAN_FILES += $(bin.mkwb) ######################################################################## # C-PP.FILTER: a $(call)able to transform $(1) to $(2) via: @@ -749,55 +791,6 @@ $(post-js.js.in): $(post-jses.js) $(MAKEFILE) done > $@ -######################################################################## -# call-make-pre-post is a $(call)able which creates rules for -# pre-js.$(1)-$(2).js. $1 = the base name of the JS file on whose -# behalf this pre-js is for (one of: $(JS_BUILD_NAMES)). $2 is -# the build mode: one of $(JS_BUILD_MODES). This sets up -# --[extern-][pre/post]-js flags in $(pre-post-$(1)-$(2).flags) and -# dependencies in $(pre-post-$(1)-$(2).deps). The resulting files get -# filtered using $(C-PP.FILTER). Any flags necessary for such -# filtering need to be set in $(c-pp.D.$(1)-$(2)) before $(call)ing -# this. -# -# Maintenance note: a shell script was written to generate these rules -# with the hope that it would make them more legible and maintainable, -# but embedding makefile code in another language makes it even less -# legible than having the level of $(eval) indirection which we have -# here. -define call-make-pre-post -pre-post-$(1)-$(2).flags ?= -pre-js.js.$(1)-$(2).intermediary := $$(dir.tmp)/pre-js.$(1)-$(2).intermediary.js -pre-js.js.$(1)-$(2) := $$(dir.tmp)/pre-js.$(1)-$(2).js -#$$(error $$(pre-js.js.$(1)-$(2).intermediary) $$(pre-js.js.$(1)-$(2))) -$$(eval $$(call C-PP.FILTER,$$(pre-js.js.in),$$(pre-js.js.$(1)-$(2).intermediary),$$(c-pp.D.$(1)-$(2)))) -post-js.js.$(1)-$(2) := $$(dir.tmp)/post-js.$(1)-$(2).js -$$(eval $$(call C-PP.FILTER,$$(post-js.js.in),$$(post-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2)))) -extern-post-js.js.$(1)-$(2) := $$(dir.tmp)/extern-post-js.$(1)-$(2).js -$$(eval $$(call C-PP.FILTER,$$(extern-post-js.js.in),$$(extern-post-js.js.$(1)-$(2)),$$(c-pp.D.$(1)-$(2)))) -pre-post-common.flags.$(1)-$(2) := \ - $$(pre-post-common.flags) \ - --post-js=$$(post-js.js.$(1)-$(2)) \ - --extern-post-js=$$(extern-post-js.js.$(1)-$(2)) -pre-post-jses.$(1)-$(2).deps := $$(pre-post-jses.deps.common) \ - $$(post-js.js.$(1)-$(2)) $$(extern-post-js.js.$(1)-$(2)) -$$(pre-js.js.$(1)-$(2)): $$(pre-js.js.$(1)-$(2).intermediary) $$(MAKEFILE) - cp $$(pre-js.js.$(1)-$(2).intermediary) $$@ - @if [ sqlite3-wasmfs = $(1) ]; then \ - echo "delete Module[xNameOfInstantiateWasm] /*for WASMFS build*/;"; \ - elif [ sqlite3 != $(1) ]; then \ - echo "Module[xNameOfInstantiateWasm].uri = '$(1).wasm';"; \ - fi >> $$@ -pre-post-$(1)-$(2).deps := \ - $$(pre-post-jses.$(1)-$(2).deps) \ - $$(dir.tmp)/pre-js.$(1)-$(2).js -pre-post-$(1)-$(2).flags += \ - $$(pre-post-common.flags.$(1)-$(2)) \ - --pre-js=$$(dir.tmp)/pre-js.$(1)-$(2).js -endef -# /post-js and pre-js -######################################################################## - # Undocumented Emscripten feature: if the target file extension is # "mjs", it defaults to ES6 module builds: # https://github.com/emscripten-core/emscripten/issues/14383 @@ -811,11 +804,14 @@ sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles) # difference, so we build all binaries against sqlite3-wasm.c instead # of building a shared copy of sqlite3-wasm.o to link against. ######################################################################## -# SQLITE3.xJS.EXPORT-DEFAULT is part of SQLITE3-WASMFS.xJS.RECIPE and -# SETUP_LIB_BUILD_MODE, factored into a separate piece to avoid code -# duplication. $1 is 1 if the build mode needs this workaround (esm, -# bundler-friendly, node) and 0 if not (vanilla). $2 must be empty for -# all builds except sqlite3-wasmfs.mjs, in which case it must be 1. + +######################################################################## +# SQLITE3.xJS.ESM-EXPORT-DEFAULT is part of SQLITE3-WASMFS.xJS.RECIPE +# and SETUP_LIB_BUILD_MODE, factored into a separate piece to avoid +# code duplication. $1 is 1 if the build mode needs this workaround +# (esm, bundler-friendly, node) and 0 if not (vanilla). $2 must be +# 0 for all builds except sqlite3-wasmfs.mjs, in which case it +# must be 1. # # Reminder for ESM builds: even if we use -sEXPORT_ES6=0, emcc _still_ # adds: @@ -838,7 +834,7 @@ if [ x1 = x$(1) ]; then \ {\ awk '/^export default/ && !f{f=1; next} 1' $@ > $@.tmp && mv $@.tmp $@; \ } || exit $$?; \ - if [ x != x$(2) ]; then \ + if [ x1 = x$(2) ]; then \ if ! grep -q '^export default' $@; then \ echo "Cannot find export default." 1>&2; \ exit 1; \ @@ -847,78 +843,6 @@ if [ x1 = x$(1) ]; then \ fi endef -######################################################################## -# extern-post-js* and extern-pre-js* are files for use with -# Emscripten's --extern-pre-js and --extern-post-js flags. -extern-pre-js.js := $(dir.api)/extern-pre-js.js -extern-post-js.js.in := $(dir.api)/extern-post-js.c-pp.js -# Emscripten flags for --[extern-][pre|post]-js=... for the -# various builds. -pre-post-common.flags := \ - --extern-pre-js=$(sqlite3-license-version.js) -# pre-post-jses.deps.* = a list of dependencies for the -# --[extern-][pre/post]-js files. -pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js) - -######################################################################## -# SETUP_LIB_BUILD_MODE is a $(call)'able which sets up numerous pieces -# for one of the build modes. -# -# $1 = one of: $(JS_BUILD_NAMES) -# $2 = build mode name: one of $(JS_BUILD_MODES) -# $3 = 1 for ESM build mode, else 0 -# $4 = resulting sqlite-api JS/MJS file -# $5 = resulting JS/MJS file -# $6 = -D... flags for $(bin.c-pp) -# $7 = optional extra flags for emcc -# -# Maintenance reminder: be careful not to introduce spaces around args -# ($1, $2), otherwise string concatenation will malfunction. -# -# Before calling this, emcc.environment.$(2) must be set to a value -# for emcc's -sENVIRONMENT flag. -# -# $(cflags.$(1)) and $(cflags.$(1).$(2)) may be defined to append -# CFLAGS to a given build mode. -# -# $(emcc.flags.$(1)) and $(emcc.flags.$(1).$(2)) may be defined to -# append emcc-specific flags to a given build mode. -define SETUP_LIB_BUILD_MODE -$(info Setting up build [$(1)-$(2)]: $(5)) -c-pp.D.$(1)-$(2) := $(6) -$$(eval $$(call call-make-pre-post,$(1),$(2))) -emcc.flags.$(1).$(2) ?= -emcc.flags.$(1).$(2) += $(7) -$$(eval $$(call C-PP.FILTER, $$(sqlite3-api.js.in), $(4), $(6))) -$(5): $(4) $$(MAKEFILE) $$(sqlite3-wasm.cfiles) $$(EXPORTED_FUNCTIONS.api) $$(pre-post-$(1)-$(2).deps) - @echo "Building $$@ ..." - $$(emcc.bin) -o $$@ $$(emcc_opt_full) $$(emcc.flags) \ - $$(emcc.jsflags) \ - -sENVIRONMENT=$$(emcc.environment.$(2)) \ - $$(pre-post-$(1)-$(2).flags) \ - $$(emcc.flags.$(1)) $$(emcc.flags.$(1).$(2)) \ - $$(cflags.common) $$(SQLITE_OPT) \ - $$(cflags.$(1)) $$(cflags.$(1).$(2)) \ - $$(cflags.wasm_extra_init) $$(sqlite3-wasm.cfiles) - @$$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,$(3)) - @dotwasm=$$(basename $$@).wasm; \ - chmod -x $$$$dotwasm; \ - $(maybe-wasm-strip) $$$$dotwasm; \ - case $(2) in \ - bundler-friendly|node) \ - echo "Patching $$@ for $(1).wasm..."; \ - rm -f $$$$dotwasm; \ - dotwasm=; \ - sed -i -e 's/$(1)-$(2).wasm/$(1).wasm/g' $$@ || exit $$$$?; \ - ;; \ - esac; \ - ls -la $$$$dotwasm $$@ -all: $(5) -#quick: $(5) -#CLEAN_FILES += $(4) $(5) -endef -# ^^^ /SETUP_LIB_BUILD_MODE -######################################################################## sqlite3-api.js := $(dir.dout)/sqlite3-api.js sqlite3.js := $(dir.dout)/sqlite3.js sqlite3-api.mjs := $(dir.dout)/sqlite3-api.mjs @@ -927,17 +851,14 @@ sqlite3-api-bundler-friendly.mjs := $(dir.dout)/sqlite3-api-bundler-friendly.mjs sqlite3-bundler-friendly.mjs := $(dir.dout)/sqlite3-bundler-friendly.mjs sqlite3-api-node.mjs := $(dir.dout)/sqlite3-api-node.mjs sqlite3-node.mjs := $(dir.dout)/sqlite3-node.mjs -#$(info $(call SETUP_LIB_BUILD_MODE,sqlite3,vanilla,0, $(sqlite3-api.js), $(sqlite3.js))) -$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,vanilla,0,\ - $(sqlite3-api.js), $(sqlite3.js))) -$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,esm,1,\ - $(sqlite3-api.mjs), $(sqlite3.mjs), -Dtarget=es6-module)) -$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,bundler-friendly,1,\ - $(sqlite3-api-bundler-friendly.mjs),$(sqlite3-bundler-friendly.mjs),\ - $(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly)) -$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3,node,1,\ - $(sqlite3-api-node.mjs),$(sqlite3-node.mjs),\ - $(c-pp.D.sqlite3-bundler-friendly) -Dtarget=node)) +sqlite3-api-wasmfs.mjs := $(dir.tmp)/sqlite3-api-wasmfs.mjs +sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs +.wasmbuilds.make: $(bin.mkwb) + @rm -f $@ + $(bin.mkwb) > $@ + @chmod -w $@ +DISTCLEAN_FILES += .wasmbuilds.make +-include .wasmbuilds.make # The various -D... values used by *.c-pp.js include: # # -Dtarget=es6-module: for all ESM module builds @@ -1267,4 +1188,3 @@ endif # Run local web server for the test/demo pages. httpd: althttpd -max-age 1 -enable-sab 1 -page index.html - diff --git a/ext/wasm/c-pp.c b/ext/wasm/c-pp.c index c439a0d091..6815cb845b 100644 --- a/ext/wasm/c-pp.c +++ b/ext/wasm/c-pp.c @@ -1,7 +1,8 @@ /* ** 2022-11-12: ** -** In place of a legal notice, here is a blessing: +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** ** * May you do good and not evil. ** * May you find forgiveness for yourself and forgive others. diff --git a/ext/wasm/make-make.sh b/ext/wasm/make-make.sh deleted file mode 100755 index 6f93d88835..0000000000 --- a/ext/wasm/make-make.sh +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/bash -######################################################################## -# Emits the makefile code for .cache.make. Any makefile bits which are -# potentially expensive to calculate on every build but rarely change -# should be emitted from here. -# -# Arguments: -# -# $1 = path to sqlite3.c. Default: ../../sqlite3.c -# -######################################################################## - -function die(){ - local rc=$1 - shift - echo "\$(error $0 failed: $@)" - # ^^^ Ensure that if this output is being redirected, the - # resulting makefile will fail loudly instead of just being - # truncated. - echo "Error: $@" 1>&2 - exit $rc -} - -SQLITE3_C="${1-../../sqlite3.c}" - -separator='########################################################################' - -cat </dev/null; then - echo 'SQLITE_C_IS_SEE := 1' - echo '$(info This is an SEE build)' -else - echo 'SQLITE_C_IS_SEE := 0' -fi - -######################################################################## -# Locate the emcc (Emscripten) binary... -echo $separator -EMCC_BIN=$(which emcc) -if [[ x = "x${EMCC_BIN}" ]]; then - if [[ x != "x${EMSDK_HOME}" ]]; then - EMCC_BIN="${EMSDK_HOME}/upstream/emscripten/emcc" - fi -fi -if [[ x = "x${EMCC_BIN}" ]]; then - die 1 "Cannot find emcc binary in PATH or EMSDK_HOME." -fi -[[ -x "${EMCC_BIN}" ]] || die 1 "emcc is not executable" -echo "emcc.bin := ${EMCC_BIN}" -echo "emcc.version :=" $("${EMCC_BIN}" --version | sed -n 1p \ - | sed -e 's/^.* \([3-9][^ ]*\) .*$/\1/;') -echo '$(info using emcc version [$(emcc.version)])' - -######################################################################### -# wasm-strip binary... -echo $separator -WASM_STRIP_BIN=$(which wasm-strip 2>/dev/null) -echo "wasm-strip ?= ${WASM_STRIP_BIN}" -if [[ x = "x${WASM_STRIP_BIN}" ]]; then -cat < +#include +#include + +#define pf printf +#define ps puts +/* Very common printf() args combo. */ +#define zNM zName, zMode + +/* +** Valid names for the zName arguments. +*/ +#define JS_BUILD_NAMES sqlite3 sqlite3-wasmfs +/* +** Valid names for the zMode arguments. +*/ +#define JS_BUILD_MODES vanilla esm bundler-friendly node + +/* +** Emits common vars needed by the rest of the emitted code (but not +** needed by code outside of these generated pieces). +*/ +static void mk_prologue(void){ + ps("########################################################################"); + ps("# extern-post-js* and extern-pre-js* are files for use with"); + ps("# Emscripten's --extern-pre-js and --extern-post-js flags."); + ps("extern-pre-js.js := $(dir.api)/extern-pre-js.js"); + ps("extern-post-js.js.in := $(dir.api)/extern-post-js.c-pp.js"); + ps("# Emscripten flags for --[extern-][pre|post]-js=... for the"); + ps("# various builds."); + ps("pre-post-common.flags := --extern-pre-js=$(sqlite3-license-version.js)"); + ps("# pre-post-jses.deps.* = a list of dependencies for the"); + ps("# --[extern-][pre/post]-js files."); + ps("pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)"); +} + +/* +** Emits makefile code for setting up values for the --pre-js=FILE, +** --post-js=FILE, and --extern-post-js=FILE emcc flags, as well as +** populating those files. +*/ +static void mk_pre_post(const char *zName, const char *zMode){ + pf("pre-post-%s-%s.flags ?=\n", zNM); + + /* --pre-js=... */ + pf("pre-js.js.%s-%s.intermediary := $(dir.tmp)/pre-js.%s-%s.intermediary.js\n", + zNM, zNM); + pf("pre-js.js.%s-%s := $(dir.tmp)/pre-js.%s-%s.js\n", + zNM, zNM); + pf("$(eval $(call C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.%s-%s.intermediary)," + "$(c-pp.D.%s-%s)))\n", zNM, zNM); + + /* --post-js=... */ + pf("post-js.js.%s-%s := $(dir.tmp)/post-js.%s-%s.js\n", zNM, zNM); + pf("$(eval $(call C-PP.FILTER,$(post-js.js.in)," + "$(post-js.js.%s-%s),$(c-pp.D.%s-%s)))\n", zNM, zNM); + + /* --extern-post-js=... */ + pf("extern-post-js.js.%s-%s := $(dir.tmp)/extern-post-js.%s-%s.js\n", zNM, zNM); + pf("$(eval $(call C-PP.FILTER,$(extern-post-js.js.in),$(extern-post-js.js.%s-%s)," + "$(c-pp.D.%s-%s)))\n", zNM, zNM); + + /* Combine flags for use with emcc... */ + pf("pre-post-common.flags.%s-%s := " + "$(pre-post-common.flags) " + "--post-js=$(post-js.js.%s-%s) " + "--extern-post-js=$(extern-post-js.js.%s-%s)\n", zNM, zNM, zNM); + + pf("pre-post-%s-%s.flags += $(pre-post-common.flags.%s-%s) " + "--pre-js=$(pre-js.js.%s-%s)\n", zNM, zNM, zNM); + + pf("$(pre-js.js.%s-%s): $(pre-js.js.%s-%s.intermediary) $(MAKEFILE)\n", + zNM, zNM); + pf("\tcp $(pre-js.js.%s-%s.intermediary) $@\n", zNM); + /* Amend $(pre-js.js.zName-zMode) for all targets except the plain + "sqlite3" build... */ + if( 0==strcmp("sqlite3-wasmfs", zName) ){ + pf("\t@echo 'delete Module[xNameOfInstantiateWasm]; /" + "* for %s build *" "/' >> $@\n", zName); + }else if( 0!=strcmp("sqlite3", zName) ){ + pf("\t@echo 'Module[xNameOfInstantiateWasm].uri = \"$(1).wasm\";' >> $@\n"); + } + + /* Set up deps... */ + pf("pre-post-jses.%s-%s.deps := $(pre-post-jses.deps.common) " + "$(post-js.js.%s-%s) $(extern-post-js.js.%s-%s)\n", + zNM, zNM, zNM); + pf("pre-post-%s-%s.deps := $(pre-post-jses.%s-%s.deps) $(dir.tmp)/pre-js.%s-%s.js\n", + zNM, zNM, zNM); +} + +/* +** Emits makefile code for one build of the library, primarily defined +** by the combination of zName and zMode, each of which must be values +** from JS_BUILD_NAMES resp. JS_BUILD_MODES. +*/ +static void mk_lib_mode(const char *zName /* build name */, + const char *zMode /* build mode */, + int bIsEsm /* true only for ESM build */, + const char *zApiJsOut /* name of generated sqlite3-api.js/.mjs */, + const char *zJsOut /* name of generated sqlite3.js/.mjs */, + const char *zCmppD /* extra -D flags for c-pp */, + const char *zEmcc /* extra flags for emcc */){ + assert( zName ); + assert( zMode ); + assert( zApiJsOut ); + assert( zJsOut ); + if( !zCmppD ) zCmppD = ""; + if( !zEmcc ) zEmcc = ""; + + pf("#################### begin build [%s-%s]\n", zNM); + pf("$(info Setting up build [%s-%s]: %s)\n", zNM, zJsOut); + pf("c-pp.D.%s-%s := %s\n", zNM, zCmppD); + mk_pre_post(zNM); + pf("emcc.flags.%s.%s ?=\n", zNM); + if( zEmcc[0] ){ + pf("emcc.flags.%s.%s += %s\n", zNM, zEmcc); + } + pf("$(eval $(call C-PP.FILTER, $(sqlite3-api.js.in), %s, %s))\n", + zApiJsOut, zCmppD); + + /* target zJsOut */ + pf("%s: %s $(MAKEFILE) $(sqlite3-wasm.cfiles) $(EXPORTED_FUNCTIONS.api) " + "$(pre-post-%s-%s.deps)\n", + zJsOut, zApiJsOut, zNM); + pf("\t@echo \"Building $@ ...\"\n"); + pf("\t$(emcc.bin) -o $@ $(emcc_opt_full) $(emcc.flags) \\\n"); + pf("\t\t$(emcc.jsflags) -sENVIRONMENT=$(emcc.environment.%s) \\\n", zMode); + pf("\t\t$(pre-post-%s-%s.flags) \\\n", zNM); + pf("\t\t$(emcc.flags.%s) $(emcc.flags.%s.%s) \\\n", zName, zNM); + pf("\t\t$(cflags.common) $(SQLITE_OPT) \\\n" + "\t\t$(cflags.%s) $(cflags.%s.%s) \\\n" + "\t\t$(cflags.wasm_extra_init) $(sqlite3-wasm.cfiles)\n", zName, zNM); + if( bIsEsm ){ + /* TODO? Replace this CALL with the corresponding makefile code. + ** OTOH, we also use this $(call) in the speedtest1-wasmfs build, + ** which is not part of the rules emitted by this program. */ + pf("\t@$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,1,%d)\n", + 0==strcmp("sqlite3-wasmfs", zName) ? 1 : 0); + } + pf("\t@dotwasm=$(basename $@).wasm; \\\n" + "\tchmod -x $$dotwasm; \\\n" + "\t$(maybe-wasm-strip) $$dotwasm; \\\n"); + /* + ** The above $(emcc.bin) call will write zJsOut and will create a + ** like-named .wasm file. That .wasm file name gets hard-coded into + ** zJsOut so we need to, for some cases, patch zJsOut to use the + ** name sqlite3.wasm instead. Note that the resulting .wasm file is + ** identical for all builds for which zEmcc is empty. + */ + if( 0==strcmp("bundler-friendly", zMode) + || 0==strcmp("node", zMode) ) { + pf("\techo 'Patching $@ for %s.wasm...' \\\n", zName); + pf("\trm -f $$dotwasm; dotwasm=; \\\n" + "\tsed -i -e 's/%s-%s.wasm/%s.wasm/g' $@ || exit $$?; \\\n", + zNM, zName); + } + pf("\tls -la $$dotwasm $@\n"); + if( 0!=strcmp("sqlite3-wasmfs", zName) ){ + /* The sqlite3-wasmfs build is optional and needs to be invoked + ** conditionally using info we don't have here. */ + pf("all: %s\n", zJsOut); + } + pf("#################### end build [%s-%s]\n\n", zNM); +} + +int main(void){ + int rc = 0; + ps("# What follows was GENERATED by mkwasbuilds.c. Edit at your own risk."); + mk_prologue(); + mk_lib_mode("sqlite3", "vanilla", 0, + "$(sqlite3-api.js)", "$(sqlite3.js)", 0, 0); + mk_lib_mode("sqlite3", "esm", 1, + "$(sqlite3-api.mjs)", "$(sqlite3.mjs)", + "-Dtarget=es6-module", 0); + mk_lib_mode("sqlite3", "bundler-friendly", 1, + "$(sqlite3-api-bundler-friendly.mjs)", "$(sqlite3-bundler-friendly.mjs)", + "$(c-pp.D.sqlite3-esm) -Dtarget=es6-bundler-friendly", 0); + mk_lib_mode("sqlite3" , "node", 1, + "$(sqlite3-api-node.mjs)", "$(sqlite3-node.mjs)", + "$(c-pp.D.sqlite3-bundler-friendly) -Dtarget=node", 0); + mk_lib_mode("sqlite3-wasmfs", "esm" ,1, + "$(sqlite3-api-wasmfs.mjs)", "$(sqlite3-wasmfs.mjs)", + "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs", + "-sEXPORT_ES6 -sUSE_ES6_IMPORT_META"); + return rc; +} diff --git a/ext/wasm/speedtest1-wasmfs.mjs b/ext/wasm/speedtest1-wasmfs.mjs index 2d5ae322aa..aeb37dd7f9 100644 --- a/ext/wasm/speedtest1-wasmfs.mjs +++ b/ext/wasm/speedtest1-wasmfs.mjs @@ -10,14 +10,14 @@ wMsg('log',"speedtest1-wasmfs starting..."); */ const wasmfsDir = function f(wasmUtil,dirName="/opfs"){ if(undefined !== f._) return f._; - if( !self.FileSystemHandle - || !self.FileSystemDirectoryHandle - || !self.FileSystemFileHandle){ + if( !globalThis.FileSystemHandle + || !globalThis.FileSystemDirectoryHandle + || !globalThis.FileSystemFileHandle){ return f._ = ""; } try{ if(0===wasmUtil.xCallWrapped( - 'sqlite3_wasm_init_wasmfs', 'i32', ['string'], dirName + 'sqlite3__wasm_init_wasmfs', 'i32', ['string'], dirName )){ return f._ = dirName; }else{ @@ -36,7 +36,7 @@ const logErr = (...args)=>wMsg('logErr',...args); const runTests = function(sqlite3){ console.log("Module inited.",sqlite3); const wasm = sqlite3.wasm; - const __unlink = wasm.xWrap("sqlite3_wasm_vfs_unlink", "int", ["*","string"]); + const __unlink = wasm.xWrap("sqlite3__wasm_vfs_unlink", "int", ["*","string"]); const unlink = (fn)=>__unlink(0,fn); const pDir = wasmfsDir(wasm); if(pDir) log("Persistent storage:",pDir); @@ -46,7 +46,7 @@ const runTests = function(sqlite3){ } const scope = wasm.scopedAllocPush(); const dbFile = pDir+"/speedtest1.db"; - const urlParams = new URL(self.location.href).searchParams; + const urlParams = new URL(globalThis.location.href).searchParams; const argv = ["speedtest1"]; if(urlParams.has('flags')){ argv.push(...(urlParams.get('flags').split(','))); diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index 2bd7a0700b..59ec557568 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -6,12 +6,10 @@ # GNUMakefile. ######################################################################## MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST)) -$(warning The WASMFS build is currently incomplete.) +$(warning The WASMFS build is not well-supported. \ + WASMFS is a proverbial moving target, so what builds today might not tomorrow.) -#dir.wasmfs := $(dir.wasm) -dir.wasmfs := $(dir.dout) sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js -sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm ######################################################################## @@ -25,9 +23,11 @@ cflags.sqlite3-wasmfs += -DSQLITE_ENABLE_WASMFS # emcc flags specific to building the final .js/.wasm file... emcc.flags.sqlite3-wasmfs := emcc.flags.sqlite3-wasmfs += \ - -sEXPORTED_RUNTIME_METHODS=wasmMemory,allocateUTF8OnStack,stringToUTF8OnStack + -sEXPORTED_RUNTIME_METHODS=wasmMemory # wasmMemory ==> for -sIMPORTED_MEMORY - # *OnStack ==> wasmfs internals (leaky abstraction) +# Some version of emcc between 3.1.60-ish and 3.1.62 deprecated the use of +# (allocateUTF8OnStack,stringToUTF8OnStack). Earlier emcc versions will +# fail to build without those in EXPORTED_RUNTIME_METHODS. emcc.flags.sqlite3-wasmfs += -sUSE_CLOSURE_COMPILER=0 emcc.flags.sqlite3-wasmfs += -Wno-limited-postlink-optimizations # ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag. @@ -46,12 +46,7 @@ emcc.flags.sqlite3-wasmfs += -sALLOW_MEMORY_GROWTH=0 # And, indeed, it runs slowly if memory is permitted to grow. #emcc.flags.sqlite3-wasmfs.vanilla := #emcc.flags.sqlite3-wasmfs.esm := -sEXPORT_ES6 -sUSE_ES6_IMPORT_META -sqlite3-api.mjs.wasmfs := $(dir.tmp)/sqlite3-api-wasmfs.mjs -$(eval $(call SETUP_LIB_BUILD_MODE,sqlite3-wasmfs,esm,1,\ - $(sqlite3-api.mjs.wasmfs), $(sqlite3-wasmfs.mjs),\ - $(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs,\ - -sEXPORT_ES6 -sUSE_ES6_IMPORT_META\ -)) +all: $(sqlite3-wasmfs.mjs) $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(MAKEFILE.wasmfs) ######################################################################## # Build quirk: we cannot build BOTH .js and .mjs with our current @@ -98,7 +93,7 @@ $(speedtest1-wasmfs.mjs): $(speedtest1.cfiles) $(sqlite3-wasmfs.js) \ $(emcc.flags.sqlite3-wasmfs) \ $(emcc.flags.speedtest1-wasmfs) \ -o $@ $(speedtest1.cfiles) -lm - @$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,1) + @$(call SQLITE3.xJS.ESM-EXPORT-DEFAULT,1,1) $(maybe-wasm-strip) $(speedtest1-wasmfs.wasm) chmod -x $(speedtest1-wasmfs.wasm) ls -la $@ $(speedtest1-wasmfs.wasm) diff --git a/manifest b/manifest index 9683bfacfb..ff4fb6dcd1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\scurrent\strunk\sinto\sthis\sbranch. -D 2024-09-23T17:06:06.957 +C wasm:\sreplace\smuch\sof\sthe\seval\smakefile\sspaghetti\swith\sequivalent\scode\sgenerated\sfrom\sa\ssmall\sC\sapp.\sIt\sturns\sout\sthat's\seasier\sto\sread\sand\swrite\sthan\sdoing\sthe\ssame\sthing\sfrom\sshell\sor\stcl\scode,\sdue\sentirely\sto\sC's\slack\sof\sneed\sfor\sescaping\sdollar\ssigns. +D 2024-09-23T21:22:09.942 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -435,7 +435,7 @@ F ext/misc/urifuncs.c f71360d14fa9e7626b563f1f781c6148109462741c5235ac63ae0f8917 F ext/misc/uuid.c 5bb2264c1b64d163efa46509544fd7500cb8769cb7c16dd52052da8d961505cf F ext/misc/vfslog.c 3932ab932eeb2601dbc4447cb14d445aaa9fbe43b863ef5f014401c3420afd20 F ext/misc/vfsstat.c a85df08654743922a19410d7b1e3111de41bb7cd07d20dd16eda4e2b808d269d -F ext/misc/vfstrace.c ac76a4ac4d907774fd423cc2b61410c756f9d0782e27cf6032e058594accaaca w src/test_vfstrace.c +F ext/misc/vfstrace.c ac76a4ac4d907774fd423cc2b61410c756f9d0782e27cf6032e058594accaaca F ext/misc/vtablog.c 1100250ce8782db37c833e3a9a5c9a3ecf1af5e15b8325572b82e6e0a138ffb5 F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f65b4fc0668 @@ -601,7 +601,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 1bce318cef54073492b461bbad7d3d0ac5e535f48c514725222672925d9e79ff +F ext/wasm/GNUmakefile 9ad87c7b7cdbbf4b3d48ff8aad8b12ffca2f48cb0190d366efa1c25386601f99 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -637,7 +637,7 @@ F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8 F ext/wasm/batch-runner.js 05ec254f5dbfe605146d9640b3db17d6ef8c3fbef6aa8396051ca72bb5884e3f -F ext/wasm/c-pp.c 6d80d8569d85713effe8b0818a3cf51dc779e3f0bf8dc88771b8998552ee25b4 +F ext/wasm/c-pp.c e230a9f71a6179971a65d87e2d393a16c87285f6a3bbad232f494fbc5ab9f82f F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f @@ -661,12 +661,12 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/make-make.sh 3c1964f5ed80af79c21e583abb9adac2eb11141c98c1cf57eba7ebcb210f1025 x +F ext/wasm/mkwasmbuilds.c 958b5572d46a0d22ab1f85c9f47d7e9789532fbd8bb1ff5ce7bde1d2d369f063 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 F ext/wasm/speedtest1-wasmfs.html 0e9d335a9b5b5fafe6e1bc8dc0f0ca7e22e6eb916682a2d7c36218bb7d67379d -F ext/wasm/speedtest1-wasmfs.mjs ac5cadbf4ffe69e9eaac8b45e8523f030521e02bb67d654c6eb5236d9c456cbe +F ext/wasm/speedtest1-wasmfs.mjs c77c7231338ed5c0e1ce16aa29106df8e5b5cf11a48319c49433490a8d3ded30 F ext/wasm/speedtest1-worker.html 864b65ed78ce24847a348c180e7f267621a02ca027068a1863ec1c90187c1852 F ext/wasm/speedtest1-worker.js 95e549e13a4d35863a9a7fc66122b5f546c0130d3be7b06dfcc556eb66d24bde F ext/wasm/speedtest1.html ff048b4a623aa192e83e143e48f1ce2a899846dd42c023fdedc8772b6e3f07da @@ -681,7 +681,7 @@ F ext/wasm/tester1.c-pp.js bb8c41a56ca0eabb945ca2e8f06324a7b63ad91630959d714b071 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 -F ext/wasm/wasmfs.make e508db7fb82653a9c9d3c7f4e2c75010abfdefa5c413a9603a2c59547bec8709 +F ext/wasm/wasmfs.make fb12389969139fd379bb4aa8455bf110cf6856fc54c8901e7451fab23834a8ef F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 @@ -2211,8 +2211,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a1cf3095a87e101ff83ad64f20ae2e61858c7049181abfb18aece6f0a8451c15 2e5194407a1b34dd0659c350ea8098bfef7b3f11aa5b2a07ecd2bce5582655a2 -R df1e63607b5dc38491534a54bc1b4ba5 +P ed47d7f9a44b2af8ab7dd956495e71ea9a159cec438d1909f7022254a779e068 +R 5e878cdc4be0241d281da58d079e76d8 U stephan -Z 777957ea3a8879fa12050cc8a1414fec +Z 829f227b6ca9fd723c1b5f2aaff1937c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 22bb15e6be..bab3c10593 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ed47d7f9a44b2af8ab7dd956495e71ea9a159cec438d1909f7022254a779e068 +5440de48903e94f91090e2df65702ec0c504e33dd5cbd50f684cf30988f20b02 From 6ed21e8fd7597a80b8815e9c4eb8064264cd87a9 Mon Sep 17 00:00:00 2001 From: stephan Date: Mon, 23 Sep 2024 22:56:54 +0000 Subject: [PATCH 07/50] Typo fix in makefile comments. FossilOrigin-Name: a4a1287fe8205d7c24556ec2e7ae09cda37a36dbe405ea70cd756cf488549036 --- ext/wasm/mkwasmbuilds.c | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index 6f1488319f..8f9605a9ef 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -195,7 +195,7 @@ static void mk_lib_mode(const char *zName /* build name */, int main(void){ int rc = 0; - ps("# What follows was GENERATED by mkwasbuilds.c. Edit at your own risk."); + pf("# What follows was GENERATED by %s. Edit at your own risk.\n", __FILE__); mk_prologue(); mk_lib_mode("sqlite3", "vanilla", 0, "$(sqlite3-api.js)", "$(sqlite3.js)", 0, 0); diff --git a/manifest b/manifest index ff4fb6dcd1..dae84a70bf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C wasm:\sreplace\smuch\sof\sthe\seval\smakefile\sspaghetti\swith\sequivalent\scode\sgenerated\sfrom\sa\ssmall\sC\sapp.\sIt\sturns\sout\sthat's\seasier\sto\sread\sand\swrite\sthan\sdoing\sthe\ssame\sthing\sfrom\sshell\sor\stcl\scode,\sdue\sentirely\sto\sC's\slack\sof\sneed\sfor\sescaping\sdollar\ssigns. -D 2024-09-23T21:22:09.942 +C Typo\sfix\sin\smakefile\scomments. +D 2024-09-23T22:56:54.375 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -661,7 +661,7 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/mkwasmbuilds.c 958b5572d46a0d22ab1f85c9f47d7e9789532fbd8bb1ff5ce7bde1d2d369f063 +F ext/wasm/mkwasmbuilds.c 3bdf224f68038aaf16b9551ff95f72bda9aab122d047542ebb011a3108ea8e3c F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -2211,8 +2211,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ed47d7f9a44b2af8ab7dd956495e71ea9a159cec438d1909f7022254a779e068 -R 5e878cdc4be0241d281da58d079e76d8 +P 5440de48903e94f91090e2df65702ec0c504e33dd5cbd50f684cf30988f20b02 +R af6369038d36d387fd18581223ef3153 U stephan -Z 829f227b6ca9fd723c1b5f2aaff1937c +Z 842b2632fb8484faa7396f7355e6a0a1 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index bab3c10593..592ad46fc5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5440de48903e94f91090e2df65702ec0c504e33dd5cbd50f684cf30988f20b02 +a4a1287fe8205d7c24556ec2e7ae09cda37a36dbe405ea70cd756cf488549036 From 405ae974eeaa99114593bb49e2d4951892adcced Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 24 Sep 2024 00:31:08 +0000 Subject: [PATCH 08/50] Further wasm build cleanups and tweaks. No functional changes. FossilOrigin-Name: 3b72a143431537ec275aefae739e56330c1d445c9ea80885882a2b9aa2201179 --- ext/wasm/GNUmakefile | 56 ++++++++++++++++++++++++------------- ext/wasm/api/pre-js.c-pp.js | 13 ++++++++- ext/wasm/c-pp.c | 2 +- ext/wasm/mkwasmbuilds.c | 51 +++++++++++++++++++-------------- ext/wasm/wasmfs.make | 26 +++++++++++------ manifest | 20 ++++++------- manifest.uuid | 2 +- 7 files changed, 107 insertions(+), 63 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index e40db6a5f4..71978de48e 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -158,31 +158,43 @@ $(sqlite3.h): $(MAKE) -C $(dir.top) sqlite3.c $(sqlite3.c): $(sqlite3.h) -ifeq (,$(filter release snapshot,$(MAKECMDGOALS))) - $(info Development build. Use 'release' or 'snapshot' target for a smaller release build.) +ifneq (1,$(MAKING_CLEAN)) + ifeq (,$(filter release snapshot,$(MAKECMDGOALS))) + $(info ==============================================================) + $(info == Development build. Use 'release' or 'snapshot' target) + $(info == for a smaller release build.) + $(info ==============================================================) + endif endif ######################################################################## # Find emcc (Emscripten compiler)... -emcc.bin := $(shell which emcc 2>/dev/null) -ifeq (,$(emcc.bin)) - ifneq (,$(EMSDK_HOME)) - emcc.bin := $(wildcard $(EMSDK_HOME)/upstream/emscripten/emcc) - endif +ifeq (1,$(MAKING_CLEAN)) + emcc.bin := echo + emcc.version := unknown +else + emcc.bin := $(shell which emcc 2>/dev/null) ifeq (,$(emcc.bin)) - $(error Cannot find emcc in path.) + ifneq (,$(EMSDK_HOME)) + emcc.bin := $(wildcard $(EMSDK_HOME)/upstream/emscripten/emcc) + endif + ifeq (,$(emcc.bin)) + $(error Cannot find emcc in path.) + endif endif + emcc.version := $(shell $(emcc.bin) --version | sed -n 1p | sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;') + $(info using emcc version [$(emcc.version)]) endif -emcc.version := $(shell $(emcc.bin) --version | sed -n 1p | sed -e 's/^.* \([3-9][^ ]*\) .*$$/\1/;') -$(info using emcc version [$(emcc.version)]) ######################################################################### # Find wasm-strip, which we need for release builds (see below for # why) but not strictly for non-release builds. -wasm-strip.bin ?= $(shell which wasm-strip 2>/dev/null) -ifeq (,$(wasm-strip.bin)) - ifeq (,$(filter clean,$(MAKECMDGOALS))) +ifeq (1,$(MAKING_CLEAN)) + wasm-strip-bin := irrelevant +else + wasm-strip.bin ?= $(shell which wasm-strip 2>/dev/null) + ifeq (,$(wasm-strip.bin)) $(info WARNING: *******************************************************************) - $(info WARNING: builds using -O2/-O3/-Os/-Oz will minify WASM-exported names,) + $(info WARNING: Builds using -O2/-O3/-Os/-Oz will minify WASM-exported names,) $(info WARNING: breaking _All The Things_. The workaround for that is to build) $(info WARNING: with -g3 (which explodes the file size) and then strip the debug) $(info WARNING: info after compilation, using wasm-strip, to shrink the wasm file.) @@ -194,11 +206,11 @@ ifeq (,$(wasm-strip.bin)) $(info WARNING: on Ubuntu-like systems it can be installed with:) $(info WARNING: sudo apt install wabt) $(info WARNING: *******************************************************************) + wasm-strip.bin := echo "not wasm-stripping" endif ifneq (,$(filter release snapshot,$(MAKECMDGOALS))) $(error Cannot make release-quality binary because wasm-strip is not available.) endif - wasm-strip.bin := echo "not wasm-stripping" endif maybe-wasm-strip := $(wasm-strip.bin) @@ -207,6 +219,10 @@ maybe-wasm-strip := $(wasm-strip.bin) # goal being to create a WASM file with only the core APIs. ifeq (1,$(barebones)) wasm-bare-bones := 1 + $(info ==============================================================) + $(info == This is a bare-bones build. It trades away features for) + $(info == a smaller .wasm file.) + $(info ==============================================================) else wasm-bare-bones := 0 endif @@ -413,6 +429,7 @@ $(bin.c-pp): c-pp.c $(sqlite3.c) $(MAKEFILE) -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_UTF16 \ -DSQLITE_OMIT_SHARED_CACHE -DSQLITE_OMIT_WAL -DSQLITE_THREADSAFE=0 \ -DSQLITE_TEMP_STORE=3 +DISTCLEAN_FILES += $(bin.c-pp) C-PP.FILTER.global ?= ifeq (1,$(SQLITE_C_IS_SEE)) C-PP.FILTER.global += -Denable-see @@ -481,10 +498,6 @@ ifeq (1,$(SQLITE_C_IS_SEE)) endif ifeq (0,$(wasm-bare-bones)) EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras -else - $(info ============================================================) - $(info This is a bare-bones build. It is missing many features.) - $(info ============================================================) endif EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api $(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE) @@ -853,12 +866,15 @@ sqlite3-api-node.mjs := $(dir.dout)/sqlite3-api-node.mjs sqlite3-node.mjs := $(dir.dout)/sqlite3-node.mjs sqlite3-api-wasmfs.mjs := $(dir.tmp)/sqlite3-api-wasmfs.mjs sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs +ifneq (1,$(MAKING_CLEAN)) .wasmbuilds.make: $(bin.mkwb) @rm -f $@ $(bin.mkwb) > $@ @chmod -w $@ -DISTCLEAN_FILES += .wasmbuilds.make -include .wasmbuilds.make +endif +DISTCLEAN_FILES += .wasmbuilds.make + # The various -D... values used by *.c-pp.js include: # # -Dtarget=es6-module: for all ESM module builds diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index 878f3e0546..06d44a7a69 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -59,6 +59,7 @@ Module['locateFile'] = function(path, prefix) { }.bind(sqlite3InitModuleState); //#endif ifnot target=es6-bundler-friendly +//#if custom-Module.instantiateModule /** Bug warning: a custom Module.instantiateWasm() does not work in WASMFS builds: @@ -67,7 +68,15 @@ Module['locateFile'] = function(path, prefix) { In such builds we must disable this. */ -const xNameOfInstantiateWasm = false +const xNameOfInstantiateWasm = +//#if wasmfs + false +//#else + true /* This works, but it does not have the testing coverage in the + wild which Emscripten's default impl does, so we'll save + this option until we really need a custom + Module.instantiateWasm() */ +//#endif ? 'instantiateWasm' : 'emscripten-bug-17951'; Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ @@ -80,6 +89,7 @@ Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ sqlite3InitModuleState.debugModule( "instantiateWasm() uri =", uri ); + //console.warn("Custom instantiateModule",uri); const wfetch = ()=>fetch(uri, {credentials: 'same-origin'}); const loadWasm = WebAssembly.instantiateStreaming ? async ()=>{ @@ -105,6 +115,7 @@ Module[xNameOfInstantiateWasm] = function callee(imports,onSuccess){ scripts. */ Module[xNameOfInstantiateWasm].uri = 'sqlite3.wasm'; +//#endif custom-Module.instantiateModule /* END FILE: api/pre-js.js, noting that the build process may add a line after this one to change the above .uri to a build-specific one. */ diff --git a/ext/wasm/c-pp.c b/ext/wasm/c-pp.c index 6815cb845b..c67881dd3e 100644 --- a/ext/wasm/c-pp.c +++ b/ext/wasm/c-pp.c @@ -1508,7 +1508,7 @@ int main(int argc, char const * const * argv){ } ISFLAG("debug"){ ++g.doDebug; - }else if(!zInfile){ + }else if(!zInfile && '-'!=argv[i][0]){ goto do_infile; }else{ fatal("Unhandled flag: %s", argv[i]); diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index 8f9605a9ef..ae31a52ef2 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -13,12 +13,12 @@ ** This app's single purpose is to emit parts of the Makefile code for ** building sqlite3's WASM build. The main motivation is to generate ** code which "can" be created via GNU Make's eval command but is -** highly illegible when built that way. Attempts to write this app in -** Bash and TCL have failed because both require escaping $ symbols, -** making the resulting script code as illegible as the eval spaghetti -** we want to get away from. Writing it in C is, somewhat -** surprisingly, _slightly_ less illegible than writing it in bash, -** tcl, or native Make code. +** highly illegible when constructed that way. Attempts to write this +** app in Bash and TCL have suffered from the problem that both +** require escaping $ symbols, making the resulting script code as +** illegible as the eval spaghetti we want to get away from. Writing +** it in C is, somewhat surprisingly, _slightly_ less illegible than +** writing it in bash, tcl, or native Make code. ** ** The emitted makefile code is not standalone - it depends on ** variables and $(call)able functions from the main makefile. @@ -41,7 +41,8 @@ */ #define JS_BUILD_NAMES sqlite3 sqlite3-wasmfs /* -** Valid names for the zMode arguments. +** Valid names for the zMode arguments of the "sqlite3" build. For the +** "sqlite3-wasmfs" build, only "esm" (ES6 Module) is legal. */ #define JS_BUILD_MODES vanilla esm bundler-friendly node @@ -72,12 +73,30 @@ static void mk_pre_post(const char *zName, const char *zMode){ pf("pre-post-%s-%s.flags ?=\n", zNM); /* --pre-js=... */ - pf("pre-js.js.%s-%s.intermediary := $(dir.tmp)/pre-js.%s-%s.intermediary.js\n", - zNM, zNM); pf("pre-js.js.%s-%s := $(dir.tmp)/pre-js.%s-%s.js\n", zNM, zNM); + pf("$(pre-js.js.%s-%s): $(MAKEFILE)\n", zNM); +#if 1 + pf("$(eval $(call C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.%s-%s)," + "$(c-pp.D.%s-%s)))\n", zNM, zNM); +#else + /* This part is needed if/when we re-enable the custom + ** Module.instantiateModule() impl. */ + pf("pre-js.js.%s-%s.intermediary := $(dir.tmp)/pre-js.%s-%s.intermediary.js\n", + zNM, zNM); pf("$(eval $(call C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.%s-%s.intermediary)," "$(c-pp.D.%s-%s)))\n", zNM, zNM); + pf("$(pre-js.js.%s-%s): $(pre-js.js.%s-%s.intermediary)\n", zNM, zNM); + pf("\tcp $(pre-js.js.%s-%s.intermediary) $@\n", zNM); + + /* Amend $(pre-js.js.zName-zMode) for all targets except the plain + ** "sqlite3" build... */ + if( 0!=strcmp("sqlite3-wasmfs", zName) + && 0!=strcmp("sqlite3", zName) ){ + pf("\t@echo 'Module[xNameOfInstantiateWasm].uri = " + "\"%s.wasm\";' >> $@\n", zName); + } +#endif /* --post-js=... */ pf("post-js.js.%s-%s := $(dir.tmp)/post-js.%s-%s.js\n", zNM, zNM); @@ -98,18 +117,6 @@ static void mk_pre_post(const char *zName, const char *zMode){ pf("pre-post-%s-%s.flags += $(pre-post-common.flags.%s-%s) " "--pre-js=$(pre-js.js.%s-%s)\n", zNM, zNM, zNM); - pf("$(pre-js.js.%s-%s): $(pre-js.js.%s-%s.intermediary) $(MAKEFILE)\n", - zNM, zNM); - pf("\tcp $(pre-js.js.%s-%s.intermediary) $@\n", zNM); - /* Amend $(pre-js.js.zName-zMode) for all targets except the plain - "sqlite3" build... */ - if( 0==strcmp("sqlite3-wasmfs", zName) ){ - pf("\t@echo 'delete Module[xNameOfInstantiateWasm]; /" - "* for %s build *" "/' >> $@\n", zName); - }else if( 0!=strcmp("sqlite3", zName) ){ - pf("\t@echo 'Module[xNameOfInstantiateWasm].uri = \"$(1).wasm\";' >> $@\n"); - } - /* Set up deps... */ pf("pre-post-jses.%s-%s.deps := $(pre-post-jses.deps.common) " "$(post-js.js.%s-%s) $(extern-post-js.js.%s-%s)\n", @@ -138,6 +145,7 @@ static void mk_lib_mode(const char *zName /* build name */, if( !zEmcc ) zEmcc = ""; pf("#################### begin build [%s-%s]\n", zNM); + pf("ifneq (1,$(MAKING_CLEAN))\n"); pf("$(info Setting up build [%s-%s]: %s)\n", zNM, zJsOut); pf("c-pp.D.%s-%s := %s\n", zNM, zCmppD); mk_pre_post(zNM); @@ -190,6 +198,7 @@ static void mk_lib_mode(const char *zName /* build name */, ** conditionally using info we don't have here. */ pf("all: %s\n", zJsOut); } + ps("endif\n# ^^^ !$(MAKING_CLEAN)"); pf("#################### end build [%s-%s]\n\n", zNM); } diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index 59ec557568..4d34c42140 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -6,8 +6,16 @@ # GNUMakefile. ######################################################################## MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST)) -$(warning The WASMFS build is not well-supported. \ - WASMFS is a proverbial moving target, so what builds today might not tomorrow.) +# ensure that the following message starts on line 10 or higher for proper +# alignment! +ifneq (1,$(MAKING_CLEAN)) + $(warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!) + $(warning !! The WASMFS build is not well-supported. WASMFS is a proverbial) + $(warning !! moving target, sometimes changing in incompatible ways between) + $(warning !! Emscripten versions. This build is provided for adventurous folks) + $(warning !! and is not a supported deliverable of the SQLite project.) + $(warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!) +endif sqlite3-wasmfs.js := $(dir.wasmfs)/sqlite3-wasmfs.js sqlite3-wasmfs.wasm := $(dir.wasmfs)/sqlite3-wasmfs.wasm @@ -25,12 +33,13 @@ emcc.flags.sqlite3-wasmfs := emcc.flags.sqlite3-wasmfs += \ -sEXPORTED_RUNTIME_METHODS=wasmMemory # wasmMemory ==> for -sIMPORTED_MEMORY -# Some version of emcc between 3.1.60-ish and 3.1.62 deprecated the use of -# (allocateUTF8OnStack,stringToUTF8OnStack). Earlier emcc versions will -# fail to build without those in EXPORTED_RUNTIME_METHODS. +# Some version of emcc between 3.1.60-ish(?) and 3.1.62 deprecated the +# use of (allocateUTF8OnStack,stringToUTF8OnStack). Earlier emcc +# versions will fail to build without those in the +# EXPORTED_RUNTIME_METHODS list. emcc.flags.sqlite3-wasmfs += -sUSE_CLOSURE_COMPILER=0 emcc.flags.sqlite3-wasmfs += -Wno-limited-postlink-optimizations -# ^^^^^ it likes to warn when we have "limited optimizations" via the -g3 flag. +# ^^^^^ emcc likes to warn when we have "limited optimizations" via the -g3 flag. emcc.flags.sqlite3-wasmfs += -sMEMORY64=0 emcc.flags.sqlite3-wasmfs += -sINITIAL_MEMORY=$(emcc.INITIAL_MEMORY.128) # ^^^^ 64MB is not enough for WASMFS/OPFS test runs using batch-runner.js @@ -57,8 +66,8 @@ $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(MAKEFILE.wasmfs) # build both modes they would need to have distinct base names or # output directories. "The problem" with giving them distinct base # names is that it means that the corresponding .wasm file is also -# built/saved multiple times. -# +# built/saved multiple times. It is likely that anyone wanting to use +# WASMFS will want an ES6 module, so that's what we build here. wasmfs.build.ext := mjs $(sqlite3-wasmfs.js) $(sqlite3-wasmfs.mjs): $(SOAP.js.bld) ifeq (js,$(wasmfs.build.ext)) @@ -68,7 +77,6 @@ else $(sqlite3-wasmfs.wasm): $(sqlite3-wasmfs.mjs) wasmfs: $(sqlite3-wasmfs.mjs) endif -#all: wasmfs ######################################################################## # speedtest1 for wasmfs. diff --git a/manifest b/manifest index dae84a70bf..7442ebbc44 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Typo\sfix\sin\smakefile\scomments. -D 2024-09-23T22:56:54.375 +C Further\swasm\sbuild\scleanups\sand\stweaks.\sNo\sfunctional\schanges. +D 2024-09-24T00:31:08.220 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -601,7 +601,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 9ad87c7b7cdbbf4b3d48ff8aad8b12ffca2f48cb0190d366efa1c25386601f99 +F ext/wasm/GNUmakefile fdb89338c1c6ce71ce804ef1c3de8ac9aa0b68566e2ce3210ebe4951e88e3b52 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -618,7 +618,7 @@ F ext/wasm/api/extern-post-js.c-pp.js c4154a7f90c2d7e51fd6738273908152036c3457fd F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 -F ext/wasm/api/pre-js.c-pp.js ad906703f7429590f2fbf5e6498513bf727a1a4f0ebfa057afb08161d7511219 +F ext/wasm/api/pre-js.c-pp.js b10a41b749e86670d17c0937c95e60eefe33dfdea1c5fc6c95d5b62a7b2b1f2c F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.c-pp.js fb6dbfe692cc23000a65a4cd95a1a47ed5eb592dc9d8b55363b3c2952a787244 F ext/wasm/api/sqlite3-api-oo1.c-pp.js f3a8e2004c6625d17946c11f2fb32008be78bc5207bf746fc77d59848813225f @@ -637,7 +637,7 @@ F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0 F ext/wasm/batch-runner-sahpool.js 54a3ac228e6c4703fe72fb65c897e19156263a51fe9b7e21d2834a45e876aabd F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8 F ext/wasm/batch-runner.js 05ec254f5dbfe605146d9640b3db17d6ef8c3fbef6aa8396051ca72bb5884e3f -F ext/wasm/c-pp.c e230a9f71a6179971a65d87e2d393a16c87285f6a3bbad232f494fbc5ab9f82f +F ext/wasm/c-pp.c 6d131069644964223305582a80973477fa8b06b57306781690d7874ebd3a4f84 F ext/wasm/common/SqliteTestUtil.js 7adaeffef757d8708418dc9190f72df22367b531831775804b31598b44f6aa51 F ext/wasm/common/emscripten.css 11bd104b6c0d597c67d40cc8ecc0a60dae2b965151e3b6a37fa5708bac3acd15 F ext/wasm/common/testing.css e97549bab24126c24e0daabfe2de9bb478fb0a69fdb2ddd0a73a992c091aad6f @@ -661,7 +661,7 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/mkwasmbuilds.c 3bdf224f68038aaf16b9551ff95f72bda9aab122d047542ebb011a3108ea8e3c +F ext/wasm/mkwasmbuilds.c 1b7e970bcfbf4197cedc6e4da9e6939f869801c2d9fe70b4e844a8c598678359 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -681,7 +681,7 @@ F ext/wasm/tester1.c-pp.js bb8c41a56ca0eabb945ca2e8f06324a7b63ad91630959d714b071 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 -F ext/wasm/wasmfs.make fb12389969139fd379bb4aa8455bf110cf6856fc54c8901e7451fab23834a8ef +F ext/wasm/wasmfs.make 8067daf346482cdb91414c3f6b8f6ff110bfa874294f73e13479c755af67ec20 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 @@ -2211,8 +2211,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5440de48903e94f91090e2df65702ec0c504e33dd5cbd50f684cf30988f20b02 -R af6369038d36d387fd18581223ef3153 +P a4a1287fe8205d7c24556ec2e7ae09cda37a36dbe405ea70cd756cf488549036 +R 9f08f9acf686695c4b728c0d11a4b3f8 U stephan -Z 842b2632fb8484faa7396f7355e6a0a1 +Z 7db74120d28ad7360e1e90126cd6bb3c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 592ad46fc5..91085aa6fd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a4a1287fe8205d7c24556ec2e7ae09cda37a36dbe405ea70cd756cf488549036 +3b72a143431537ec275aefae739e56330c1d445c9ea80885882a2b9aa2201179 From 118ac6a7ad50378a18be2c8ba76a01ed2c696922 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 09:51:53 +0000 Subject: [PATCH 09/50] Always use fputws() for output to a Windows command-line prompt. FossilOrigin-Name: 33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b --- manifest | 15 +++++------ manifest.uuid | 2 +- src/shell.c.in | 68 +++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 8b26ee7843..f90dfa8f25 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C CLI\suses\sonly\slib-c\sfor\sI/O\son\sWindows.\s\sNo\scalls\sto\sWin32.\s\sWorks\son\sWin11,\nat\sleast.\s\sReads\sand\swrites\sunicode\sto/from\sthe\sconsole\sand\sUTF-8\sto/from\sfiles.\nPrototype\scode\sonly\s-\smust\stesting\sand\sadditional\swork\srequired. -D 2024-09-23T20:23:43.341 +C Always\suse\sfputws()\sfor\soutput\sto\sa\sWindows\scommand-line\sprompt. +D 2024-09-24T09:51:53.618 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -768,7 +768,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 265c877932142ee8ef05a6aa5a0a5bff92905ffef97dc6f566062a27814274a1 +F src/shell.c.in 6054892954e926a30a5b3d2994805477d38154692b5bb571d81db86791d0e58b F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2213,11 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2e5194407a1b34dd0659c350ea8098bfef7b3f11aa5b2a07ecd2bce5582655a2 -R 7c20c2fd1880ef1b062b32c88da2e8e4 -T *branch * cli-stdlib -T *sym-cli-stdlib * -T -sym-trunk * +P 5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da +R 39e94947c12065fc6ead20518785128b U drh -Z cdf0bc25a30881c9fe4f62b1ff96af22 +Z 9f7cd507ccaf6f6343bd8b5a2d5f1672 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7417271d4a..d6a1143c67 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da +33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b diff --git a/src/shell.c.in b/src/shell.c.in index a2b22845d6..c400073872 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -288,6 +288,62 @@ static char *cli_fgets(char *buf, int sz, FILE *in){ # define cli_fgets fgets #endif +#ifdef _WIN32 +/* fputs() for windows */ +static int cli_fputs(const char *z, FILE *out){ + if( isatty(_fileno(out)) ){ + /* When writing to the command-prompt in Windows, it is necessary + ** to use _O_WTEXT input mode and write UTF-16 characters. + */ + int sz = (int)strlen(z); + wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) ); + if( b1==0 ) return 0; + sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz); + b1[sz] = 0; + _setmode(_fileno(out), _O_WTEXT); + fputws(b1, out); + sqlite3_free(b1); + return 0; + }else{ + /* Writing to a file or other destination, just write bytes without + ** any translation. */ + return fputs(z, out); + } +} +#else +/* library version works for everybody else */ +# define cli_fputs fputs +#endif + +#ifdef _WIN32 +/* fprintf() for windows */ +static void cli_fprintf(FILE *out, const char *zFormat, ...){ + if( isatty(fileno(out)) ){ + /* When writing to the command-prompt in Windows, it is necessary + ** to use _O_WTEXT input mode and write UTF-16 characters. + */ + char *z; + va_list ap; + + va_start(ap, zFormat); + z = sqlite3_vmprintf(zFormat, ap); + va_end(ap); + cli_fputs(z, out); + sqlite3_free(z); + }else{ + /* Writing to a file or other destination, just write bytes without + ** any translation. */ + va_list ap; + va_start(ap, zFormat); + vfprintf(out, zFormat, ap); + va_end(ap); + } +} +#else +/* library version works for everybody else */ +# define cli_fprintf fprintf +#endif + /* Use console I/O package as a direct INCLUDE. */ #define SQLITE_INTERNAL_LINKAGE static @@ -300,13 +356,13 @@ static char *cli_fgets(char *buf, int sz, FILE *in){ # define SQLITE_CIO_NO_FLUSH #endif -#define oputf(fmt, ...) printf(fmt,__VA_ARGS__) -#define eputf(fmt, ...) fprintf(stderr,fmt,__VA_ARGS__) -#define sputf(fp,fmt, ...) fprintf(fp,fmt,__VA_ARGS__) +#define oputf(fmt, ...) cli_fprintf(stdout,fmt,__VA_ARGS__) +#define eputf(fmt, ...) cli_fprintf(stderr,fmt,__VA_ARGS__) +#define sputf(fp,fmt, ...) cli_fprintf(fp,fmt,__VA_ARGS__) /* These next 3 macros are for emitting simple string literals. */ -#define oputz(z) fputs(z,stdout) -#define eputz(z) fputs(z,stderr) -#define sputz(fp,z) fputs(z,fp) +#define oputz(z) cli_fputs(z,stdout) +#define eputz(z) cli_fputs(z,stderr) +#define sputz(fp,z) cli_fputs(z,fp) #define oputb(buf,na) fwrite(buf,1,na,stdout) /* True if the timer is enabled */ From 4e34558f1baf40bf628f8872f9bddf52f05c8c4f Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 10:30:07 +0000 Subject: [PATCH 10/50] Use _wfopen() instead of fopen() on Windows in the CLI. FossilOrigin-Name: 21a8cac5e9a0d5ead29ca1114be7520d182348f7e2e2e2416852b827d7e09f21 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 53 +++++++++++++++++++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/manifest b/manifest index f90dfa8f25..6c38834512 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Always\suse\sfputws()\sfor\soutput\sto\sa\sWindows\scommand-line\sprompt. -D 2024-09-24T09:51:53.618 +C Use\s_wfopen()\sinstead\sof\sfopen()\son\sWindows\sin\sthe\sCLI. +D 2024-09-24T10:30:07.376 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -768,7 +768,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 6054892954e926a30a5b3d2994805477d38154692b5bb571d81db86791d0e58b +F src/shell.c.in 95f1bdfb9b1d513c7d82ab04fbca746a9668fb02d3eb984cd1cfb3b4ffc413e0 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5c54530d5a0a4125a1ba44f22537c4f63d5e5708f347c43cbac3e1832c4335da -R 39e94947c12065fc6ead20518785128b +P 33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b +R 563de058a2a6970ab738b542c7a8c099 U drh -Z 9f7cd507ccaf6f6343bd8b5a2d5f1672 +Z 3b9fb03668dcca40431939db5346d2bc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d6a1143c67..a3d44399a6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b +21a8cac5e9a0d5ead29ca1114be7520d182348f7e2e2e2416852b827d7e09f21 diff --git a/src/shell.c.in b/src/shell.c.in index c400073872..5677e060f7 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -344,6 +344,33 @@ static void cli_fprintf(FILE *out, const char *zFormat, ...){ # define cli_fprintf fprintf #endif +#ifdef _WIN32 +/* fopen() for windows */ +static FILE *cli_fopen(const char *zFilename, const char *zMode){ + FILE *fp = 0; + wchar_t *b1, *b2; + int sz1, sz2; + + sz1 = (int)strlen(zFilename); + sz2 = (int)strlen(zMode); + b1 = malloc( (sz1+1)*sizeof(b1[0]) ); + b2 = malloc( (sz2+1)*sizeof(b1[0]) ); + if( b1 && b2 ){ + sz1 = MultiByteToWideChar(CP_UTF8, 0, zFilename, sz1, b1, sz1); + b1[sz1] = 0; + sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); + b2[sz2] = 0; + fp = _wfopen(b1, b2); + } + free(b1); + free(b2); + return fp; +} +#else +/* library version works for everybody else */ +# define cli_fopen fopen +#endif + /* Use console I/O package as a direct INCLUDE. */ #define SQLITE_INTERNAL_LINKAGE static @@ -827,7 +854,7 @@ static FILE * openChrSource(const char *zFile){ /* On Windows, open first, then check the stream nature. This order ** is necessary because _stat() and sibs, when checking a named pipe, ** effectively break the pipe as its supplier sees it. */ - FILE *rv = fopen(zFile, "rb"); + FILE *rv = cli_fopen(zFile, "rb"); if( rv==0 ) return 0; if( _fstat64(_fileno(rv), &x) != 0 || !STAT_CHR_SRC(x.st_mode)){ @@ -841,7 +868,7 @@ static FILE * openChrSource(const char *zFile){ # define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode)) if( rc!=0 ) return 0; if( STAT_CHR_SRC(x.st_mode) ){ - return fopen(zFile, "rb"); + return cli_fopen(zFile, "rb"); }else{ return 0; } @@ -1681,7 +1708,7 @@ static void editFunc( bBin = sqlite3_value_type(argv[0])==SQLITE_BLOB; /* When writing the file to be edited, do \n to \r\n conversions on systems ** that want \r\n line endings */ - f = fopen(zTempFile, bBin ? "wb" : "w"); + f = cli_fopen(zTempFile, bBin ? "wb" : "w"); if( f==0 ){ sqlite3_result_error(context, "edit() cannot open temp file", -1); goto edit_func_end; @@ -1712,7 +1739,7 @@ static void editFunc( sqlite3_result_error(context, "EDITOR returned non-zero", -1); goto edit_func_end; } - f = fopen(zTempFile, "rb"); + f = cli_fopen(zTempFile, "rb"); if( f==0 ){ sqlite3_result_error(context, "edit() cannot reopen temp file after edit", -1); @@ -3113,7 +3140,7 @@ static void displayLinuxIoStats(void){ FILE *in; char z[200]; sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid()); - in = fopen(z, "rb"); + in = cli_fopen(z, "rb"); if( in==0 ) return; while( cli_fgets(z, sizeof(z), in)!=0 ){ static const struct { @@ -5170,7 +5197,7 @@ static int process_input(ShellState *p); ** is undefined in this case. */ static char *readFile(const char *zName, int *pnByte){ - FILE *in = fopen(zName, "rb"); + FILE *in = cli_fopen(zName, "rb"); long nIn; size_t nRead; char *pBuf; @@ -5260,7 +5287,7 @@ static int session_filter(void *pCtx, const char *zTab){ ** the type cannot be determined from content. */ int deduceDatabaseType(const char *zName, int dfltZip){ - FILE *f = fopen(zName, "rb"); + FILE *f = cli_fopen(zName, "rb"); size_t n; int rc = SHELL_OPEN_UNSPEC; char zBuf[100]; @@ -5313,7 +5340,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){ unsigned int x[16]; char zLine[1000]; if( zDbFilename ){ - in = fopen(zDbFilename, "r"); + in = cli_fopen(zDbFilename, "r"); if( in==0 ){ eputf("cannot open \"%s\" for reading\n", zDbFilename); return 0; @@ -5800,7 +5827,7 @@ static FILE *output_file_open(const char *zFile, int bTextMode){ }else if( cli_strcmp(zFile, "off")==0 ){ f = 0; }else{ - f = fopen(zFile, bTextMode ? "w" : "wb"); + f = cli_fopen(zFile, bTextMode ? "w" : "wb"); if( f==0 ){ eputf("Error: cannot open \"%s\"\n", zFile); } @@ -9029,7 +9056,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sCtx.xCloser = pclose; #endif }else{ - sCtx.in = fopen(sCtx.zFile, "rb"); + sCtx.in = cli_fopen(sCtx.zFile, "rb"); sCtx.xCloser = fclose; } if( sCtx.in==0 ){ @@ -9358,7 +9385,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3IoTrace = iotracePrintf; iotrace = stdout; }else{ - iotrace = fopen(azArg[1], "w"); + iotrace = cli_fopen(azArg[1], "w"); if( iotrace==0 ){ eputf("Error: cannot open \"%s\"\n", azArg[1]); sqlite3IoTrace = 0; @@ -10327,7 +10354,7 @@ static int do_meta_command(char *zLine, ShellState *p){ failIfSafeMode(p, "cannot run \".session %s\" in safe mode", azCmd[0]); if( nCmd!=2 ) goto session_syntax_error; if( pSession->p==0 ) goto session_not_open; - out = fopen(azCmd[1], "wb"); + out = cli_fopen(azCmd[1], "wb"); if( out==0 ){ eputf("ERROR: cannot open \"%s\" for writing\n", azCmd[1]); @@ -12267,7 +12294,7 @@ static void process_sqliterc( shell_check_oom(zBuf); sqliterc = zBuf; } - p->in = fopen(sqliterc,"rb"); + p->in = cli_fopen(sqliterc,"rb"); if( p->in ){ if( stdin_is_interactive ){ eputf("-- Loading resources from %s\n", sqliterc); From 88c43ce1f6c40f4a3018829b831ab9b8a7d8dcbf Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 24 Sep 2024 12:16:05 +0000 Subject: [PATCH 11/50] Wasm build cleanups. Fix the wasm speedtest1 builds broken by yesterday's refactoring. FossilOrigin-Name: 5d4a090230d1d7609e70b9c28d662dc8b0f8dd4d70a254f3ce6e449c68a25897 --- ext/wasm/GNUmakefile | 15 +++++------ ext/wasm/api/pre-js.c-pp.js | 2 +- ext/wasm/fiddle.make | 2 +- ext/wasm/mkwasmbuilds.c | 52 +++++++++++++++++++++---------------- manifest | 18 ++++++------- manifest.uuid | 2 +- 6 files changed, 47 insertions(+), 44 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 71978de48e..bada548b45 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -819,12 +819,11 @@ sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles) ######################################################################## ######################################################################## -# SQLITE3.xJS.ESM-EXPORT-DEFAULT is part of SQLITE3-WASMFS.xJS.RECIPE -# and SETUP_LIB_BUILD_MODE, factored into a separate piece to avoid -# code duplication. $1 is 1 if the build mode needs this workaround -# (esm, bundler-friendly, node) and 0 if not (vanilla). $2 must be -# 0 for all builds except sqlite3-wasmfs.mjs, in which case it -# must be 1. +# SQLITE3.xJS.ESM-EXPORT-DEFAULT is used by mkwasmbuilds.c and the +# wasmfs build. $1 is 1 if the build mode needs this workaround +# (modes: esm, bundler-friendly, node) and 0 if not (vanilla). $2 must +# be 0 for all builds except sqlite3-wasmfs.mjs, in which case it must +# be 1. # # Reminder for ESM builds: even if we use -sEXPORT_ES6=0, emcc _still_ # adds: @@ -843,7 +842,7 @@ sqlite3-wasmfs.cfiles := $(sqlite3-wasm.cfiles) # use awk instead of sed for this. define SQLITE3.xJS.ESM-EXPORT-DEFAULT if [ x1 = x$(1) ]; then \ - echo "Fragile workaround for emscripten/issues/18237. See SQLITE3.xJS.RECIPE."; \ + echo "Fragile workaround for emscripten/issues/18237. See SQLITE3.xJS.ESM-EXPORT-DEFAULT."; \ {\ awk '/^export default/ && !f{f=1; next} 1' $@ > $@.tmp && mv $@.tmp $@; \ } || exit $$?; \ @@ -1030,9 +1029,7 @@ $(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api.core) speedtest1.js := $(dir.dout)/speedtest1.js speedtest1.wasm := $(dir.dout)/speedtest1.wasm emcc.flags.speedtest1-vanilla := $(cflags.common) -DSQLITE_SPEEDTEST1_WASM - speedtest1.cfiles := $(speedtest1.c) $(sqlite3-wasm.c) -$(eval $(call call-make-pre-post,speedtest1,vanilla)) $(speedtest1.js): $(MAKEFILE) $(speedtest1.cfiles) \ $(pre-post-speedtest1-vanilla.deps) \ $(EXPORTED_FUNCTIONS.speedtest1) diff --git a/ext/wasm/api/pre-js.c-pp.js b/ext/wasm/api/pre-js.c-pp.js index 06d44a7a69..4045fb11cd 100644 --- a/ext/wasm/api/pre-js.c-pp.js +++ b/ext/wasm/api/pre-js.c-pp.js @@ -48,7 +48,7 @@ Module['locateFile'] = function(path, prefix) { }else{ theFile = prefix + path; } - sqlite3InitModuleState.debugModule( + this.debugModule( "locateFile(",arguments[0], ',', arguments[1],")", 'sqlite3InitModuleState.scriptDir =',this.scriptDir, 'up.entries() =',Array.from(up.entries()), diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index b081d25155..c81379fbbd 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -20,7 +20,7 @@ endif ifeq (,$(SHELL_DEP)) $(error Could not parse SHELL_DEP from $(dir.top)/Makefile.) endif -$(dir.top)/shell.c: $(SHELL_DEP) $(dir.top)/tool/mkshellc.tcl $(sqlite3.c) +$(dir.top)/shell.c: $(SHELL_DEP) $(dir.tool)/mkshellc.tcl $(sqlite3.c) $(MAKE) -C $(dir.top) shell.c # /shell.c ######################################################################## diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index ae31a52ef2..f69cac3e6b 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -45,31 +45,15 @@ ** "sqlite3-wasmfs" build, only "esm" (ES6 Module) is legal. */ #define JS_BUILD_MODES vanilla esm bundler-friendly node - -/* -** Emits common vars needed by the rest of the emitted code (but not -** needed by code outside of these generated pieces). -*/ -static void mk_prologue(void){ - ps("########################################################################"); - ps("# extern-post-js* and extern-pre-js* are files for use with"); - ps("# Emscripten's --extern-pre-js and --extern-post-js flags."); - ps("extern-pre-js.js := $(dir.api)/extern-pre-js.js"); - ps("extern-post-js.js.in := $(dir.api)/extern-post-js.c-pp.js"); - ps("# Emscripten flags for --[extern-][pre|post]-js=... for the"); - ps("# various builds."); - ps("pre-post-common.flags := --extern-pre-js=$(sqlite3-license-version.js)"); - ps("# pre-post-jses.deps.* = a list of dependencies for the"); - ps("# --[extern-][pre/post]-js files."); - ps("pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)"); -} - +static const char * zBanner = + "\n########################################################################\n"; /* ** Emits makefile code for setting up values for the --pre-js=FILE, ** --post-js=FILE, and --extern-post-js=FILE emcc flags, as well as ** populating those files. */ static void mk_pre_post(const char *zName, const char *zMode){ + pf("%s# Begin --pre/--post flags for %s-%s\n", zBanner, zName, zMode); pf("pre-post-%s-%s.flags ?=\n", zNM); /* --pre-js=... */ @@ -81,7 +65,7 @@ static void mk_pre_post(const char *zName, const char *zMode){ "$(c-pp.D.%s-%s)))\n", zNM, zNM); #else /* This part is needed if/when we re-enable the custom - ** Module.instantiateModule() impl. */ + ** Module.instantiateModule() impl in api/pre-js.c-pp.js. */ pf("pre-js.js.%s-%s.intermediary := $(dir.tmp)/pre-js.%s-%s.intermediary.js\n", zNM, zNM); pf("$(eval $(call C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.%s-%s.intermediary)," @@ -123,6 +107,25 @@ static void mk_pre_post(const char *zName, const char *zMode){ zNM, zNM, zNM); pf("pre-post-%s-%s.deps := $(pre-post-jses.%s-%s.deps) $(dir.tmp)/pre-js.%s-%s.js\n", zNM, zNM, zNM); + pf("# End --pre/--post flags for %s-%s%s", zName, zMode, zBanner); +} + +/* +** Emits common vars needed by the rest of the emitted code (but not +** needed by code outside of these generated pieces). +*/ +static void mk_prologue(void){ + pf("%s", zBanner); + ps("# extern-post-js* and extern-pre-js* are files for use with"); + ps("# Emscripten's --extern-pre-js and --extern-post-js flags."); + ps("extern-pre-js.js := $(dir.api)/extern-pre-js.js"); + ps("extern-post-js.js.in := $(dir.api)/extern-post-js.c-pp.js"); + ps("# Emscripten flags for --[extern-][pre|post]-js=... for the"); + ps("# various builds."); + ps("pre-post-common.flags := --extern-pre-js=$(sqlite3-license-version.js)"); + ps("# pre-post-jses.deps.* = a list of dependencies for the"); + ps("# --[extern-][pre/post]-js files."); + ps("pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)"); } /* @@ -144,12 +147,12 @@ static void mk_lib_mode(const char *zName /* build name */, if( !zCmppD ) zCmppD = ""; if( !zEmcc ) zEmcc = ""; - pf("#################### begin build [%s-%s]\n", zNM); + pf("%s# Begin build [%s-%s]\n", zBanner, zNM); pf("ifneq (1,$(MAKING_CLEAN))\n"); pf("$(info Setting up build [%s-%s]: %s)\n", zNM, zJsOut); pf("c-pp.D.%s-%s := %s\n", zNM, zCmppD); mk_pre_post(zNM); - pf("emcc.flags.%s.%s ?=\n", zNM); + pf("\nemcc.flags.%s.%s ?=\n", zNM); if( zEmcc[0] ){ pf("emcc.flags.%s.%s += %s\n", zNM, zEmcc); } @@ -199,7 +202,7 @@ static void mk_lib_mode(const char *zName /* build name */, pf("all: %s\n", zJsOut); } ps("endif\n# ^^^ !$(MAKING_CLEAN)"); - pf("#################### end build [%s-%s]\n\n", zNM); + pf("# End build [%s-%s]%s", zNM, zBanner); } int main(void){ @@ -221,5 +224,8 @@ int main(void){ "$(sqlite3-api-wasmfs.mjs)", "$(sqlite3-wasmfs.mjs)", "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs", "-sEXPORT_ES6 -sUSE_ES6_IMPORT_META"); + + mk_pre_post("speedtest1","vanilla"); + mk_pre_post("speedtest1-wasmfs","esm"); return rc; } diff --git a/manifest b/manifest index 7442ebbc44..ff0300c95c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\swasm\sbuild\scleanups\sand\stweaks.\sNo\sfunctional\schanges. -D 2024-09-24T00:31:08.220 +C Wasm\sbuild\scleanups.\sFix\sthe\swasm\sspeedtest1\sbuilds\sbroken\sby\syesterday's\srefactoring. +D 2024-09-24T12:16:05.567 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -601,7 +601,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile fdb89338c1c6ce71ce804ef1c3de8ac9aa0b68566e2ce3210ebe4951e88e3b52 +F ext/wasm/GNUmakefile 4e2be9c8bed22922703f3ed6bb2444ff7c5b1053e466421e69a57c664d7a042d F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -618,7 +618,7 @@ F ext/wasm/api/extern-post-js.c-pp.js c4154a7f90c2d7e51fd6738273908152036c3457fd F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-header.js 04dc12c3edd666b64a1b4ef3b6690c88dcc653f26451fd4734472d8e29c1c122 -F ext/wasm/api/pre-js.c-pp.js b10a41b749e86670d17c0937c95e60eefe33dfdea1c5fc6c95d5b62a7b2b1f2c +F ext/wasm/api/pre-js.c-pp.js a614a2c82b12c4d96d8e3ba77330329efc53c4d56a8a7e60ade900f341866cfb F ext/wasm/api/sqlite3-api-cleanup.js d235ad237df6954145404305040991c72ef8b1881715d2a650dda7b3c2576d0e F ext/wasm/api/sqlite3-api-glue.c-pp.js fb6dbfe692cc23000a65a4cd95a1a47ed5eb592dc9d8b55363b3c2952a787244 F ext/wasm/api/sqlite3-api-oo1.c-pp.js f3a8e2004c6625d17946c11f2fb32008be78bc5207bf746fc77d59848813225f @@ -653,7 +653,7 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 653e212c1e84aa3be168d62a10616ccea45ee9585b0192745d2706707a5248ce F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make b3b118516ed581cdf2c16de8eb1672427320e67ff19d710a09c891e895883644 +F ext/wasm/fiddle.make 2a1a232157f6638bdcb4496cfc0014ca2ab723fe5d986989c9fd9ee3867e1be7 F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 F ext/wasm/fiddle/index.html 739e0b75bc592679665d25e2f7649d2b8b2db678f3b41a772a8720b609b8482d @@ -661,7 +661,7 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/mkwasmbuilds.c 1b7e970bcfbf4197cedc6e4da9e6939f869801c2d9fe70b4e844a8c598678359 +F ext/wasm/mkwasmbuilds.c c8906d4e54c605d8cddfce36f62723d6f0e89c3813ecebec9fec4a3fcb952003 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -2211,8 +2211,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a4a1287fe8205d7c24556ec2e7ae09cda37a36dbe405ea70cd756cf488549036 -R 9f08f9acf686695c4b728c0d11a4b3f8 +P 3b72a143431537ec275aefae739e56330c1d445c9ea80885882a2b9aa2201179 +R 04e34f9a24dc7d45d5d906b5bbfab195 U stephan -Z 7db74120d28ad7360e1e90126cd6bb3c +Z acb2af67fc0175d67098e0add512a294 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 91085aa6fd..9b4fe9265e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3b72a143431537ec275aefae739e56330c1d445c9ea80885882a2b9aa2201179 +5d4a090230d1d7609e70b9c28d662dc8b0f8dd4d70a254f3ce6e449c68a25897 From d2917d9f69c9007a8309a37046505323b9b32a4a Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 24 Sep 2024 13:00:21 +0000 Subject: [PATCH 12/50] Minor tweaks in mkwasmbuilds.c. FossilOrigin-Name: cee43280727435440b9e01b302a790a1a102aea930bc821ebc737ea519458cef --- ext/wasm/mkwasmbuilds.c | 50 ++++++++++++++++++++++------------------- manifest | 12 +++++----- manifest.uuid | 2 +- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index f69cac3e6b..80ea675a32 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -47,13 +47,36 @@ #define JS_BUILD_MODES vanilla esm bundler-friendly node static const char * zBanner = "\n########################################################################\n"; + +/* +** Emits common vars needed by the rest of the emitted code (but not +** needed by makefile code outside of these generated pieces). +*/ +static void mk_prologue(void){ + pf("%s", zBanner); + ps("# extern-post-js* and extern-pre-js* are files for use with"); + ps("# Emscripten's --extern-pre-js and --extern-post-js flags."); + ps("extern-pre-js.js := $(dir.api)/extern-pre-js.js"); + ps("extern-post-js.js.in := $(dir.api)/extern-post-js.c-pp.js"); + ps("# Emscripten flags for --[extern-][pre|post]-js=... for the"); + ps("# various builds."); + ps("pre-post-common.flags := --extern-pre-js=$(sqlite3-license-version.js)"); + ps("# pre-post-jses.deps.* = a list of dependencies for the"); + ps("# --[extern-][pre/post]-js files."); + ps("pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)"); +} + /* ** Emits makefile code for setting up values for the --pre-js=FILE, ** --post-js=FILE, and --extern-post-js=FILE emcc flags, as well as ** populating those files. */ -static void mk_pre_post(const char *zName, const char *zMode){ +static void mk_pre_post(const char *zName /* build name */, + const char *zMode /* build mode */, + const char *zCmppD /* optional -D flags for c-pp for the + ** --pre/--post-js files. */){ pf("%s# Begin --pre/--post flags for %s-%s\n", zBanner, zName, zMode); + pf("c-pp.D.%s-%s := %s\n", zNM, zCmppD ? zCmppD : ""); pf("pre-post-%s-%s.flags ?=\n", zNM); /* --pre-js=... */ @@ -110,24 +133,6 @@ static void mk_pre_post(const char *zName, const char *zMode){ pf("# End --pre/--post flags for %s-%s%s", zName, zMode, zBanner); } -/* -** Emits common vars needed by the rest of the emitted code (but not -** needed by code outside of these generated pieces). -*/ -static void mk_prologue(void){ - pf("%s", zBanner); - ps("# extern-post-js* and extern-pre-js* are files for use with"); - ps("# Emscripten's --extern-pre-js and --extern-post-js flags."); - ps("extern-pre-js.js := $(dir.api)/extern-pre-js.js"); - ps("extern-post-js.js.in := $(dir.api)/extern-post-js.c-pp.js"); - ps("# Emscripten flags for --[extern-][pre|post]-js=... for the"); - ps("# various builds."); - ps("pre-post-common.flags := --extern-pre-js=$(sqlite3-license-version.js)"); - ps("# pre-post-jses.deps.* = a list of dependencies for the"); - ps("# --[extern-][pre/post]-js files."); - ps("pre-post-jses.deps.common := $(extern-pre-js.js) $(sqlite3-license-version.js)"); -} - /* ** Emits makefile code for one build of the library, primarily defined ** by the combination of zName and zMode, each of which must be values @@ -150,8 +155,7 @@ static void mk_lib_mode(const char *zName /* build name */, pf("%s# Begin build [%s-%s]\n", zBanner, zNM); pf("ifneq (1,$(MAKING_CLEAN))\n"); pf("$(info Setting up build [%s-%s]: %s)\n", zNM, zJsOut); - pf("c-pp.D.%s-%s := %s\n", zNM, zCmppD); - mk_pre_post(zNM); + mk_pre_post(zNM, zCmppD); pf("\nemcc.flags.%s.%s ?=\n", zNM); if( zEmcc[0] ){ pf("emcc.flags.%s.%s += %s\n", zNM, zEmcc); @@ -225,7 +229,7 @@ int main(void){ "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs", "-sEXPORT_ES6 -sUSE_ES6_IMPORT_META"); - mk_pre_post("speedtest1","vanilla"); - mk_pre_post("speedtest1-wasmfs","esm"); + mk_pre_post("speedtest1","vanilla", 0); + mk_pre_post("speedtest1-wasmfs","esm", 0); return rc; } diff --git a/manifest b/manifest index ff0300c95c..f59d1f2c69 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Wasm\sbuild\scleanups.\sFix\sthe\swasm\sspeedtest1\sbuilds\sbroken\sby\syesterday's\srefactoring. -D 2024-09-24T12:16:05.567 +C Minor\stweaks\sin\smkwasmbuilds.c. +D 2024-09-24T13:00:21.657 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -661,7 +661,7 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/mkwasmbuilds.c c8906d4e54c605d8cddfce36f62723d6f0e89c3813ecebec9fec4a3fcb952003 +F ext/wasm/mkwasmbuilds.c cd280876e43fb7d9a1bd55c55af9428304227885016f94c45c50ea97d98c0c2a F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -2211,8 +2211,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3b72a143431537ec275aefae739e56330c1d445c9ea80885882a2b9aa2201179 -R 04e34f9a24dc7d45d5d906b5bbfab195 +P 5d4a090230d1d7609e70b9c28d662dc8b0f8dd4d70a254f3ce6e449c68a25897 +R a76d989228adf2ea2f12f585c2ad0411 U stephan -Z acb2af67fc0175d67098e0add512a294 +Z 9712f926f8fbe47c6917bc9e17888ee6 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9b4fe9265e..fcdc1c4022 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5d4a090230d1d7609e70b9c28d662dc8b0f8dd4d70a254f3ce6e449c68a25897 +cee43280727435440b9e01b302a790a1a102aea930bc821ebc737ea519458cef From 57b32ef924850824ce120987e7d9e2306bf254f1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 13:46:32 +0000 Subject: [PATCH 13/50] Add the sqlite3_stdio.h library for Windows console I/O. FossilOrigin-Name: fcd0ecffc9889f8c855ea340f075ec42cdca482df82d6e67dc9c32613e8d5846 --- Makefile.in | 2 + Makefile.msc | 2 + ext/misc/sqlite3_stdio.c | 157 +++++++++++++++++++++++++++++ ext/misc/sqlite3_stdio.h | 52 ++++++++++ main.mk | 2 + manifest | 20 ++-- manifest.uuid | 2 +- src/shell.c.in | 211 ++++++++------------------------------- 8 files changed, 266 insertions(+), 182 deletions(-) create mode 100644 ext/misc/sqlite3_stdio.c create mode 100644 ext/misc/sqlite3_stdio.h diff --git a/Makefile.in b/Makefile.in index 7b693b5225..5abe3bf6d3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1206,6 +1206,8 @@ SHELL_DEP = \ $(TOP)/ext/misc/sha1.c \ $(TOP)/ext/misc/shathree.c \ $(TOP)/ext/misc/sqlar.c \ + $(TOP)/ext/misc/sqlite3_stdio.c \ + $(TOP)/ext/misc/sqlite3_stdio.h \ $(TOP)/ext/misc/uint.c \ $(TOP)/ext/misc/vfstrace.c \ $(TOP)/ext/misc/zipfile.c \ diff --git a/Makefile.msc b/Makefile.msc index bb63601518..be6a771639 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2335,6 +2335,8 @@ SHELL_DEP = \ $(TOP)\ext\misc\sha1.c \ $(TOP)\ext\misc\shathree.c \ $(TOP)\ext\misc\sqlar.c \ + $(TOP)\ext\misc\sqlite3_stdio.c \ + $(TOP)\ext\misc\sqlite3_stdio.h \ $(TOP)\ext\misc\uint.c \ $(TOP)\ext\misc\vfstrace.c \ $(TOP)\ext\misc\zipfile.c \ diff --git a/ext/misc/sqlite3_stdio.c b/ext/misc/sqlite3_stdio.c new file mode 100644 index 0000000000..0cfa26673a --- /dev/null +++ b/ext/misc/sqlite3_stdio.c @@ -0,0 +1,157 @@ +/* +** 2024-09-24 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** Implementation of standard I/O interfaces for UTF-8 that are missing +** on Windows. +*/ +#ifdef _WIN32 /* This file is a no-op on all platforms except Windows */ + +/* +** Work-alike for the fopen() routine from the standard C library. +*/ +FILE *sqlite3_fopen(const char *zFilename, const char *zMode){ + FILE *fp = 0; + wchar_t *b1, *b2; + int sz1, sz2; + + sz1 = (int)strlen(zFilename); + sz2 = (int)strlen(zMode); + b1 = malloc( (sz1+1)*sizeof(b1[0]) ); + b2 = malloc( (sz2+1)*sizeof(b1[0]) ); + if( b1 && b2 ){ + sz1 = MultiByteToWideChar(CP_UTF8, 0, zFilename, sz1, b1, sz1); + b1[sz1] = 0; + sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); + b2[sz2] = 0; + fp = _wfopen(b1, b2); + } + free(b1); + free(b2); + return fp; +} + + +/* +** Work-alike for the popen() routine from the standard C library. +*/ +FILE *sqlite3_popen(const char *zCommand, const char *zMode){ + FILE *fp = 0; + wchar_t *b1, *b2; + int sz1, sz2; + + sz1 = (int)strlen(zCommand); + sz2 = (int)strlen(zMode); + b1 = malloc( (sz1+1)*sizeof(b1[0]) ); + b2 = malloc( (sz2+1)*sizeof(b1[0]) ); + if( b1 && b2 ){ + sz1 = MultiByteToWideChar(CP_UTF8, 0, zCommand, sz1, b1, sz1); + b1[sz1] = 0; + sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); + b2[sz2] = 0; + fp = _wpopen(b1, b2); + } + free(b1); + free(b2); + return fp; +} + +/* +** Work-alike for fgets() from the standard C library. +*/ +char *sqlite3_fgets(char *buf, int sz, FILE *in){ + if( isatty(_fileno(in)) ){ + /* When reading from the command-prompt in Windows, it is necessary + ** to use _O_WTEXT input mode to read UTF-16 characters, then translate + ** that into UTF-8. Otherwise, non-ASCII characters all get translated + ** into '?'. + */ + wchar_t *b1 = malloc( sz*sizeof(wchar_t) ); + if( b1==0 ) return 0; + _setmode(_fileno(in), _O_WTEXT); + if( fgetws(b1, sz/4, in)==0 ){ + sqlite3_free(b1); + return 0; + } + WideCharToMultiByte(CP_UTF8, 0, b1, -1, buf, sz, 0, 0); + sqlite3_free(b1); + return buf; + }else{ + /* Reading from a file or other input source, just read bytes without + ** any translation. */ + return fgets(buf, sz, in); + } +} + +/* +** Work-alike for fputs() from the standard C library. +*/ +int sqlite3_fputs(const char *z, FILE *out){ + if( isatty(_fileno(out)) ){ + /* When writing to the command-prompt in Windows, it is necessary + ** to use _O_WTEXT input mode and write UTF-16 characters. + */ + int sz = (int)strlen(z); + wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) ); + if( b1==0 ) return 0; + sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz); + b1[sz] = 0; + _setmode(_fileno(out), _O_WTEXT); + fputws(b1, out); + sqlite3_free(b1); + return 0; + }else{ + /* Writing to a file or other destination, just write bytes without + ** any translation. */ + return fputs(z, out); + } +} + + +/* +** Work-alike for fprintf() from the standard C library. +*/ +int sqlite3_fprintf(FILE *out, const char *zFormat, ...){ + int rc; + if( isatty(fileno(out)) ){ + /* When writing to the command-prompt in Windows, it is necessary + ** to use _O_WTEXT input mode and write UTF-16 characters. + */ + char *z; + va_list ap; + + va_start(ap, zFormat); + z = sqlite3_vmprintf(zFormat, ap); + va_end(ap); + sqlite3_fputs(z, out); + rc = (int)strlen(z); + sqlite3_free(z); + }else{ + /* Writing to a file or other destination, just write bytes without + ** any translation. */ + va_list ap; + va_start(ap, zFormat); + rc = vfprintf(out, zFormat, ap); + va_end(ap); + } + return rc; +} + +/* +** Set the mode for a stream. mode argument is typically _O_BINARY or +** _O_TEXT. +*/ +void sqlite3_fsetmode(FILE *fp, int mode){ + fflush(fp); + _setmode(_fileno(fp), mode); +} + +#endif /* defined(_WIN32) */ diff --git a/ext/misc/sqlite3_stdio.h b/ext/misc/sqlite3_stdio.h new file mode 100644 index 0000000000..3014c1b287 --- /dev/null +++ b/ext/misc/sqlite3_stdio.h @@ -0,0 +1,52 @@ +/* +** 2024-09-24 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** +** This header file contains definitions of interfaces that provide +** cross-platform I/O for UTF-8 content. +** +** On most platforms, the interfaces definitions in this file are +** just #defines. For example sqlite3_fopen() is a macro that resolves +** to the standard fopen() in the C-library. +** +** But Windows does not have a standard C-library, at least not one that +** can handle UTF-8. So for windows build, the interfaces resolve to new +** C-language routines contained in the separate sqlite3_stdio.c source file. +** +** So on all non-Windows platforms, simply #include this header file and +** use the interfaces defined herein. Then to run your application on Windows, +** also link in the accompanying sqlite3_stdio.c source file when compiling +** to get compatible interfaces. +*/ +#ifdef _WIN32 +/**** Definitions For Windows ****/ +#include +#include + +FILE *sqlite3_fopen(const char *zFilename, const char *zMode); +FILE *sqlite3_popen(const char *zCommand, const char *type); +char *sqlite3_fgets(char *s, int size, FILE *stream); +int sqlite3_fputs(const char *s, FILE *stream); +int sqlite3_fprintf(FILE *stream, const char *format, ...); +void sqlite3_fsetmode(FILE *stream, int mode); + + +#else +/**** Definitions For All Other Platforms ****/ +#include +#define sqlite3_fopen fopen +#define sqlite3_popen popen +#define sqlite3_fgets fgets +#define sqlite3_fputs fputs +#define sqlite3_fprintf fprintf +#define sqlite3_fsetmode(F,X) /*no-op*/ + +#endif diff --git a/main.mk b/main.mk index 8aaa7e7d06..2d616a6167 100644 --- a/main.mk +++ b/main.mk @@ -782,6 +782,8 @@ SHELL_DEP = \ $(TOP)/ext/misc/sha1.c \ $(TOP)/ext/misc/shathree.c \ $(TOP)/ext/misc/sqlar.c \ + $(TOP)/ext/misc/sqlite3_stdio.c \ + $(TOP)/ext/misc/sqlite3_stdio.h \ $(TOP)/ext/misc/uint.c \ $(TOP)/ext/misc/vfstrace.c \ $(TOP)/ext/misc/zipfile.c \ diff --git a/manifest b/manifest index 6c38834512..b88e6beea1 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Use\s_wfopen()\sinstead\sof\sfopen()\son\sWindows\sin\sthe\sCLI. -D 2024-09-24T10:30:07.376 +C Add\sthe\ssqlite3_stdio.h\slibrary\sfor\sWindows\sconsole\sI/O. +D 2024-09-24T13:46:32.112 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in aa594119c3c7f699e87a767fca6598452f77d4c32c41a6486c40d4f156d4efc1 +F Makefile.in a8e1d44a1166b6fb368effb19edc9adf7fede9225e9563352b9bb1989cd0150d F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc add7e29bae33ad5b8c464daf6de84a1a01e31e6337d79fb0c1062e53fa7657da +F Makefile.msc 1a5234794c9a5a71ba13fb47bcf031814d45b3ed6a56b4cb8e9f63fd32b4febe F README.md c3c0f19532ce28f6297a71870f3c7b424729f0e6d9ab889616d3587dd2332159 F VERSION 0db40f92c04378404eb45bff93e9e42c148c7e54fd3da99469ed21e22411f5a6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -425,6 +425,8 @@ F ext/misc/shathree.c 1821d90a0040c9accdbe3e3527d378d30569475d758aa70f6848924c0b F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c c0aa7b80d6df45f7da59d912b38752bcac1af53a5766966160e6c5cdd397dbea F ext/misc/sqlar.c a6175790482328171da47095f87608b48a476d4fac78d8a9ff18b03a2454f634 +F ext/misc/sqlite3_stdio.c 4d4190eac193a8ea8fc3f8259e0996cf8e54254b4f4925d71e456e88165401d8 +F ext/misc/sqlite3_stdio.h ddefddeb448eee7fe2d41a828356a0019f813a4ced4ea2e97faa1d6c3e803742 F ext/misc/stmt.c b090086cd6bd6281c21271d38d576eeffe662f0e6b67536352ce32bbaa438321 F ext/misc/stmtrand.c 59cffa5d8e158943ff1ce078956d8e208e8c04e67307e8f249dece2436dcb7fc F ext/misc/templatevtab.c 10f15b165b95423ddef593bc5dcb915ec4eb5e0f1066d585e5435a368b8bc22b @@ -687,7 +689,7 @@ F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 -F main.mk b897586c0c7b77b7e39f0a0e9ed79fed7346b09af1ed35a08da745e02b795772 +F main.mk dcb5cbba0ad64bd639b3e05d73d92e27c144a55bab9fca3460699602f4e9f4c2 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 @@ -768,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 95f1bdfb9b1d513c7d82ab04fbca746a9668fb02d3eb984cd1cfb3b4ffc413e0 +F src/shell.c.in a4dd977ee3c5a80793121979ec0adf5332a63c4b5314cf1816720b228389bc99 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2213,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 33950a8c3f3e48e5107fe56647da05147aa84f9c3eccbe7c8671f5b502ebb70b -R 563de058a2a6970ab738b542c7a8c099 +P 21a8cac5e9a0d5ead29ca1114be7520d182348f7e2e2e2416852b827d7e09f21 +R 5d809f396de7819d09230f46e082352b U drh -Z 3b9fb03668dcca40431939db5346d2bc +Z 615e3829254cd5f44a2bd3c1963a47dc # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a3d44399a6..11300e9220 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -21a8cac5e9a0d5ead29ca1114be7520d182348f7e2e2e2416852b827d7e09f21 +fcd0ecffc9889f8c855ea340f075ec42cdca482df82d6e67dc9c32613e8d5846 diff --git a/src/shell.c.in b/src/shell.c.in index 5677e060f7..e28bb4910f 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -192,8 +192,6 @@ typedef unsigned char u8; # ifndef strdup # define strdup _strdup # endif -# undef popen -# define popen _popen # undef pclose # define pclose _pclose # endif @@ -237,139 +235,8 @@ extern char *sqlite3_win32_unicode_to_utf8(LPCWSTR); extern LPWSTR sqlite3_win32_utf8_to_unicode(const char *zText); #endif -#ifdef _WIN32 -/* On Windows, we normally run with output mode of TEXT so that \n characters -** are automatically translated into \r\n. However, this behavior needs -** to be disabled in some cases (ex: when generating CSV output and when -** rendering quoted strings that contain \n characters). The following -** routines take care of that. -*/ -static void setBinaryMode(FILE *file, int isOutput){ - if( isOutput ) fflush(file); - _setmode(_fileno(file), _O_BINARY); -} -static void setTextMode(FILE *file, int isOutput){ - if( isOutput ) fflush(file); - _setmode(_fileno(file), _O_TEXT); -} -#else - /* Unix equivalents to set*Mode() */ -# define setBinaryMode(X,Y) -# define setTextMode(X,Y) -#endif - -#ifdef _WIN32 -/* fgets() for windows */ -static char *cli_fgets(char *buf, int sz, FILE *in){ - if( isatty(_fileno(in)) ){ - /* When reading from the command-prompt in Windows, it is necessary - ** to use _O_WTEXT input mode to read UTF-16 characters, then translate - ** that into UTF-8. Otherwise, non-ASCII characters all get translated - ** into '?'. - */ - wchar_t *b1 = malloc( sz*sizeof(wchar_t) ); - if( b1==0 ) return 0; - _setmode(_fileno(in), _O_WTEXT); - if( fgetws(b1, sz/4, in)==0 ){ - sqlite3_free(b1); - return 0; - } - WideCharToMultiByte(CP_UTF8, 0, b1, -1, buf, sz, 0, 0); - sqlite3_free(b1); - return buf; - }else{ - /* Reading from a file or other input source, just read bytes without - ** any translation. */ - return fgets(buf, sz, in); - } -} -#else -/* library version works for everybody else */ -# define cli_fgets fgets -#endif - -#ifdef _WIN32 -/* fputs() for windows */ -static int cli_fputs(const char *z, FILE *out){ - if( isatty(_fileno(out)) ){ - /* When writing to the command-prompt in Windows, it is necessary - ** to use _O_WTEXT input mode and write UTF-16 characters. - */ - int sz = (int)strlen(z); - wchar_t *b1 = malloc( (sz+1)*sizeof(wchar_t) ); - if( b1==0 ) return 0; - sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz); - b1[sz] = 0; - _setmode(_fileno(out), _O_WTEXT); - fputws(b1, out); - sqlite3_free(b1); - return 0; - }else{ - /* Writing to a file or other destination, just write bytes without - ** any translation. */ - return fputs(z, out); - } -} -#else -/* library version works for everybody else */ -# define cli_fputs fputs -#endif - -#ifdef _WIN32 -/* fprintf() for windows */ -static void cli_fprintf(FILE *out, const char *zFormat, ...){ - if( isatty(fileno(out)) ){ - /* When writing to the command-prompt in Windows, it is necessary - ** to use _O_WTEXT input mode and write UTF-16 characters. - */ - char *z; - va_list ap; - - va_start(ap, zFormat); - z = sqlite3_vmprintf(zFormat, ap); - va_end(ap); - cli_fputs(z, out); - sqlite3_free(z); - }else{ - /* Writing to a file or other destination, just write bytes without - ** any translation. */ - va_list ap; - va_start(ap, zFormat); - vfprintf(out, zFormat, ap); - va_end(ap); - } -} -#else -/* library version works for everybody else */ -# define cli_fprintf fprintf -#endif - -#ifdef _WIN32 -/* fopen() for windows */ -static FILE *cli_fopen(const char *zFilename, const char *zMode){ - FILE *fp = 0; - wchar_t *b1, *b2; - int sz1, sz2; - - sz1 = (int)strlen(zFilename); - sz2 = (int)strlen(zMode); - b1 = malloc( (sz1+1)*sizeof(b1[0]) ); - b2 = malloc( (sz2+1)*sizeof(b1[0]) ); - if( b1 && b2 ){ - sz1 = MultiByteToWideChar(CP_UTF8, 0, zFilename, sz1, b1, sz1); - b1[sz1] = 0; - sz2 = MultiByteToWideChar(CP_UTF8, 0, zMode, sz2, b2, sz2); - b2[sz2] = 0; - fp = _wfopen(b1, b2); - } - free(b1); - free(b2); - return fp; -} -#else -/* library version works for everybody else */ -# define cli_fopen fopen -#endif +INCLUDE ../ext/misc/sqlite3_stdio.h +INCLUDE ../ext/misc/sqlite3_stdio.c /* Use console I/O package as a direct INCLUDE. */ #define SQLITE_INTERNAL_LINKAGE static @@ -383,13 +250,13 @@ static FILE *cli_fopen(const char *zFilename, const char *zMode){ # define SQLITE_CIO_NO_FLUSH #endif -#define oputf(fmt, ...) cli_fprintf(stdout,fmt,__VA_ARGS__) -#define eputf(fmt, ...) cli_fprintf(stderr,fmt,__VA_ARGS__) -#define sputf(fp,fmt, ...) cli_fprintf(fp,fmt,__VA_ARGS__) +#define oputf(fmt, ...) sqlite3_fprintf(stdout,fmt,__VA_ARGS__) +#define eputf(fmt, ...) sqlite3_fprintf(stderr,fmt,__VA_ARGS__) +#define sputf(fp,fmt, ...) sqlite3_fprintf(fp,fmt,__VA_ARGS__) /* These next 3 macros are for emitting simple string literals. */ -#define oputz(z) cli_fputs(z,stdout) -#define eputz(z) cli_fputs(z,stderr) -#define sputz(fp,z) cli_fputs(z,fp) +#define oputz(z) sqlite3_fputs(z,stdout) +#define eputz(z) sqlite3_fputs(z,stderr) +#define sputz(fp,z) sqlite3_fputs(z,fp) #define oputb(buf,na) fwrite(buf,1,na,stdout) /* True if the timer is enabled */ @@ -854,7 +721,7 @@ static FILE * openChrSource(const char *zFile){ /* On Windows, open first, then check the stream nature. This order ** is necessary because _stat() and sibs, when checking a named pipe, ** effectively break the pipe as its supplier sees it. */ - FILE *rv = cli_fopen(zFile, "rb"); + FILE *rv = sqlite3_fopen(zFile, "rb"); if( rv==0 ) return 0; if( _fstat64(_fileno(rv), &x) != 0 || !STAT_CHR_SRC(x.st_mode)){ @@ -868,7 +735,7 @@ static FILE * openChrSource(const char *zFile){ # define STAT_CHR_SRC(mode) (S_ISREG(mode)||S_ISFIFO(mode)||S_ISCHR(mode)) if( rc!=0 ) return 0; if( STAT_CHR_SRC(x.st_mode) ){ - return cli_fopen(zFile, "rb"); + return sqlite3_fopen(zFile, "rb"); }else{ return 0; } @@ -895,7 +762,7 @@ static char *local_getline(char *zLine, FILE *in){ zLine = realloc(zLine, nLine); shell_check_oom(zLine); } - if( cli_fgets(&zLine[n], nLine - n, in)==0 ){ + if( sqlite3_fgets(&zLine[n], nLine - n, in)==0 ){ if( n==0 ){ free(zLine); return 0; @@ -1708,7 +1575,7 @@ static void editFunc( bBin = sqlite3_value_type(argv[0])==SQLITE_BLOB; /* When writing the file to be edited, do \n to \r\n conversions on systems ** that want \r\n line endings */ - f = cli_fopen(zTempFile, bBin ? "wb" : "w"); + f = sqlite3_fopen(zTempFile, bBin ? "wb" : "w"); if( f==0 ){ sqlite3_result_error(context, "edit() cannot open temp file", -1); goto edit_func_end; @@ -1739,7 +1606,7 @@ static void editFunc( sqlite3_result_error(context, "EDITOR returned non-zero", -1); goto edit_func_end; } - f = cli_fopen(zTempFile, "rb"); + f = sqlite3_fopen(zTempFile, "rb"); if( f==0 ){ sqlite3_result_error(context, "edit() cannot reopen temp file after edit", -1); @@ -1859,7 +1726,7 @@ static const char *unused_string( static void output_quoted_string(const char *z){ int i; char c; - setBinaryMode(stdout, 1); + sqlite3_fsetmode(stdout, _O_BINARY); if( z==0 ) return; for(i=0; (c = z[i])!=0 && c!='\''; i++){} if( c==0 ){ @@ -1884,7 +1751,7 @@ static void output_quoted_string(const char *z){ } oputz("'"); } - setTextMode(stdout, 1); + sqlite3_fsetmode(stdout, _O_TEXT); } /* @@ -1899,7 +1766,7 @@ static void output_quoted_string(const char *z){ static void output_quoted_escaped_string(const char *z){ int i; char c; - setBinaryMode(stdout, 1); + sqlite3_fsetmode(stdout, _O_BINARY); for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){} if( c==0 ){ oputf("'%s'",z); @@ -1951,7 +1818,7 @@ static void output_quoted_escaped_string(const char *z){ oputf(",'%s',char(10))", zNL); } } - setTextMode(stdout, 1); + sqlite3_fsetmode(stdout, _O_TEXT); } /* @@ -2722,7 +2589,7 @@ static int shell_callback( break; } case MODE_Csv: { - setBinaryMode(p->out, 1); + sqlite3_fsetmode(p->out, _O_BINARY); if( p->cnt++==0 && p->showHeader ){ for(i=0; irowSeparator); } - setTextMode(p->out, 1); + sqlite3_fsetmode(p->out, _O_TEXT); break; } case MODE_Insert: { @@ -3140,9 +3007,9 @@ static void displayLinuxIoStats(void){ FILE *in; char z[200]; sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid()); - in = cli_fopen(z, "rb"); + in = sqlite3_fopen(z, "rb"); if( in==0 ) return; - while( cli_fgets(z, sizeof(z), in)!=0 ){ + while( sqlite3_fgets(z, sizeof(z), in)!=0 ){ static const struct { const char *zPattern; const char *zDesc; @@ -5197,7 +5064,7 @@ static int process_input(ShellState *p); ** is undefined in this case. */ static char *readFile(const char *zName, int *pnByte){ - FILE *in = cli_fopen(zName, "rb"); + FILE *in = sqlite3_fopen(zName, "rb"); long nIn; size_t nRead; char *pBuf; @@ -5287,7 +5154,7 @@ static int session_filter(void *pCtx, const char *zTab){ ** the type cannot be determined from content. */ int deduceDatabaseType(const char *zName, int dfltZip){ - FILE *f = cli_fopen(zName, "rb"); + FILE *f = sqlite3_fopen(zName, "rb"); size_t n; int rc = SHELL_OPEN_UNSPEC; char zBuf[100]; @@ -5340,7 +5207,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){ unsigned int x[16]; char zLine[1000]; if( zDbFilename ){ - in = cli_fopen(zDbFilename, "r"); + in = sqlite3_fopen(zDbFilename, "r"); if( in==0 ){ eputf("cannot open \"%s\" for reading\n", zDbFilename); return 0; @@ -5353,7 +5220,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){ } *pnData = 0; nLine++; - if( cli_fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error; + if( sqlite3_fgets(zLine, sizeof(zLine), in)==0 ) goto readHexDb_error; rc = sscanf(zLine, "| size %d pagesize %d", &n, &pgsz); if( rc!=2 ) goto readHexDb_error; if( n<0 ) goto readHexDb_error; @@ -5366,7 +5233,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){ eputz("invalid pagesize\n"); goto readHexDb_error; } - for(nLine++; cli_fgets(zLine, sizeof(zLine), in)!=0; nLine++){ + for(nLine++; sqlite3_fgets(zLine, sizeof(zLine), in)!=0; nLine++){ rc = sscanf(zLine, "| page %d offset %d", &j, &k); if( rc==2 ){ iOffset = k; @@ -5398,7 +5265,7 @@ readHexDb_error: if( in!=p->in ){ fclose(in); }else{ - while( cli_fgets(zLine, sizeof(zLine), p->in)!=0 ){ + while( sqlite3_fgets(zLine, sizeof(zLine), p->in)!=0 ){ nLine++; if(cli_strncmp(zLine, "| end ", 6)==0 ) break; } @@ -5827,7 +5694,7 @@ static FILE *output_file_open(const char *zFile, int bTextMode){ }else if( cli_strcmp(zFile, "off")==0 ){ f = 0; }else{ - f = cli_fopen(zFile, bTextMode ? "w" : "wb"); + f = sqlite3_fopen(zFile, bTextMode ? "w" : "wb"); if( f==0 ){ eputf("Error: cannot open \"%s\"\n", zFile); } @@ -8287,9 +8154,9 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){ if( nArg==2 ){ if( booleanValue(azArg[1]) ){ - setBinaryMode(p->out, 1); + sqlite3_fsetmode(p->out, _O_BINARY); }else{ - setTextMode(p->out, 1); + sqlite3_fsetmode(p->out, _O_TEXT); } }else{ eputz("The \".binary\" command is deprecated. Use \".crnl\" instead.\n" @@ -8422,9 +8289,9 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){ if( nArg==2 ){ if( booleanValue(azArg[1]) ){ - setTextMode(p->out, 1); + sqlite3_fsetmode(p->out, _O_TEXT); }else{ - setBinaryMode(p->out, 1); + sqlite3_fsetmode(p->out, _O_BINARY); } }else{ #if !defined(_WIN32) && !defined(WIN32) @@ -9051,12 +8918,12 @@ static int do_meta_command(char *zLine, ShellState *p){ eputz("Error: pipes are not supported in this OS\n"); goto meta_command_exit; #else - sCtx.in = popen(sCtx.zFile+1, "r"); + sCtx.in = sqlite3_popen(sCtx.zFile+1, "r"); sCtx.zFile = ""; sCtx.xCloser = pclose; #endif }else{ - sCtx.in = cli_fopen(sCtx.zFile, "rb"); + sCtx.in = sqlite3_fopen(sCtx.zFile, "rb"); sCtx.xCloser = fclose; } if( sCtx.in==0 ){ @@ -9385,7 +9252,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3IoTrace = iotracePrintf; iotrace = stdout; }else{ - iotrace = cli_fopen(azArg[1], "w"); + iotrace = sqlite3_fopen(azArg[1], "w"); if( iotrace==0 ){ eputf("Error: cannot open \"%s\"\n", azArg[1]); sqlite3IoTrace = 0; @@ -9832,7 +9699,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; output_redir(p, stdout); #else - FILE *pfPipe = popen(zFile + 1, "w"); + FILE *pfPipe = sqlite3_popen(zFile + 1, "w"); if( pfPipe==0 ){ eputf("Error: cannot open pipe \"%s\"\n", zFile + 1); rc = 1; @@ -10049,7 +9916,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; p->out = stdout; #else - p->in = popen(azArg[1]+1, "r"); + p->in = sqlite3_popen(azArg[1]+1, "r"); if( p->in==0 ){ eputf("Error: cannot open \"%s\"\n", azArg[1]); rc = 1; @@ -10354,7 +10221,7 @@ static int do_meta_command(char *zLine, ShellState *p){ failIfSafeMode(p, "cannot run \".session %s\" in safe mode", azCmd[0]); if( nCmd!=2 ) goto session_syntax_error; if( pSession->p==0 ) goto session_not_open; - out = cli_fopen(azCmd[1], "wb"); + out = sqlite3_fopen(azCmd[1], "wb"); if( out==0 ){ eputf("ERROR: cannot open \"%s\" for writing\n", azCmd[1]); @@ -12294,7 +12161,7 @@ static void process_sqliterc( shell_check_oom(zBuf); sqliterc = zBuf; } - p->in = cli_fopen(sqliterc,"rb"); + p->in = sqlite3_fopen(sqliterc,"rb"); if( p->in ){ if( stdin_is_interactive ){ eputf("-- Loading resources from %s\n", sqliterc); From 0be2dd9a1bb0615661f8d7ef98805b52955e32de Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 16:09:50 +0000 Subject: [PATCH 14/50] Get output redirection working again in the CLI. FossilOrigin-Name: 086034c3508d95e4f620c5e0580fae770e85410b0c8bd94f600fc0fd25088947 --- manifest | 12 +- manifest.uuid | 2 +- src/shell.c.in | 934 ++++++++++++++++++++++++++----------------------- 3 files changed, 498 insertions(+), 450 deletions(-) diff --git a/manifest b/manifest index b88e6beea1..5e7518fc0c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\ssqlite3_stdio.h\slibrary\sfor\sWindows\sconsole\sI/O. -D 2024-09-24T13:46:32.112 +C Get\soutput\sredirection\sworking\sagain\sin\sthe\sCLI. +D 2024-09-24T16:09:50.466 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in a4dd977ee3c5a80793121979ec0adf5332a63c4b5314cf1816720b228389bc99 +F src/shell.c.in b3b0aed1b1050da8d70734b1a4bdc4a4679a73f37b2593f276e5a5f71a6fca2a F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 21a8cac5e9a0d5ead29ca1114be7520d182348f7e2e2e2416852b827d7e09f21 -R 5d809f396de7819d09230f46e082352b +P fcd0ecffc9889f8c855ea340f075ec42cdca482df82d6e67dc9c32613e8d5846 +R bfd2b7dbaf4f82e5e4b17d1ed0ea1a8f U drh -Z 615e3829254cd5f44a2bd3c1963a47dc +Z 5097f278634497c50b8747316810c634 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 11300e9220..ad785fcbcd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fcd0ecffc9889f8c855ea340f075ec42cdca482df82d6e67dc9c32613e8d5846 +086034c3508d95e4f620c5e0580fae770e85410b0c8bd94f600fc0fd25088947 diff --git a/src/shell.c.in b/src/shell.c.in index e28bb4910f..4c2ca65d83 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -250,14 +250,9 @@ INCLUDE ../ext/misc/sqlite3_stdio.c # define SQLITE_CIO_NO_FLUSH #endif -#define oputf(fmt, ...) sqlite3_fprintf(stdout,fmt,__VA_ARGS__) #define eputf(fmt, ...) sqlite3_fprintf(stderr,fmt,__VA_ARGS__) -#define sputf(fp,fmt, ...) sqlite3_fprintf(fp,fmt,__VA_ARGS__) -/* These next 3 macros are for emitting simple string literals. */ -#define oputz(z) sqlite3_fputs(z,stdout) #define eputz(z) sqlite3_fputs(z,stderr) #define sputz(fp,z) sqlite3_fputs(z,fp) -#define oputb(buf,na) fwrite(buf,1,na,stdout) /* True if the timer is enabled */ static int enableTimer = 0; @@ -332,7 +327,7 @@ static void endTimer(void){ sqlite3_int64 iEnd = timeOfDay(); struct rusage sEnd; getrusage(RUSAGE_SELF, &sEnd); - sputf(stdout, "Run Time: real %.3f user %f sys %f\n", + sqlite3_fprintf(stdout, "Run Time: real %.3f user %f sys %f\n", (iEnd - iBegin)*0.001, timeDiff(&sBegin.ru_utime, &sEnd.ru_utime), timeDiff(&sBegin.ru_stime, &sEnd.ru_stime)); @@ -411,7 +406,7 @@ static void endTimer(void){ FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd; sqlite3_int64 ftWallEnd = timeOfDay(); getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd); - sputf(stdout, "Run Time: real %.3f user %f sys %f\n", + sqlite3_fprintf(stdout, "Run Time: real %.3f user %f sys %f\n", (ftWallEnd - ftWallBegin)*0.001, timeDiff(&ftUserBegin, &ftUserEnd), timeDiff(&ftKernelBegin, &ftKernelEnd)); @@ -625,7 +620,7 @@ static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){ va_start(ap, zFormat); z = sqlite3_vmprintf(zFormat, ap); va_end(ap); - sputf(iotrace, "%s", z); + sqlite3_fprintf(iotrace, "%s", z); sqlite3_free(z); } #endif @@ -636,7 +631,7 @@ static void SQLITE_CDECL iotracePrintf(const char *zFormat, ...){ ** in bytes. This is different from the %*.*s specification in printf ** since with %*.*s the width is measured in bytes, not characters. */ -static void utf8_width_print(int w, const char *zUtf){ +static void utf8_width_print(FILE *out, int w, const char *zUtf){ int i; int n; int aw = w<0 ? -w : w; @@ -651,11 +646,11 @@ static void utf8_width_print(int w, const char *zUtf){ } } if( n>=aw ){ - oputf("%.*s", i, zUtf); + sqlite3_fprintf(out, "%.*s", i, zUtf); }else if( w<0 ){ - oputf("%*s%s", aw-n, "", zUtf); + sqlite3_fprintf(out, "%*s%s", aw-n, "", zUtf); }else{ - oputf("%s%*s", zUtf, aw-n, ""); + sqlite3_fprintf(out, "%s%*s", zUtf, aw-n, ""); } } @@ -1472,7 +1467,7 @@ static const char *modeDescr[] = { static void shellLog(void *pArg, int iErrCode, const char *zMsg){ ShellState *p = (ShellState*)pArg; if( p->pLog==0 ) return; - sputf(p->pLog, "(%d) %s\n", iErrCode, zMsg); + sqlite3_fprintf(p->pLog, "(%d) %s\n", iErrCode, zMsg); fflush(p->pLog); } @@ -1487,9 +1482,9 @@ static void shellPutsFunc( int nVal, sqlite3_value **apVal ){ - /* Unused: (ShellState*)sqlite3_user_data(pCtx); */ + ShellState *p = (ShellState*)sqlite3_user_data(pCtx); (void)nVal; - oputf("%s\n", sqlite3_value_text(apVal[0])); + sqlite3_fprintf(p->out, "%s\n", sqlite3_value_text(apVal[0])); sqlite3_result_value(pCtx, apVal[0]); } @@ -1676,7 +1671,7 @@ static void outputModePop(ShellState *p){ /* ** Output the given string as a hex-encoded blob (eg. X'1234' ) */ -static void output_hex_blob(const void *pBlob, int nBlob){ +static void output_hex_blob(FILE *out, const void *pBlob, int nBlob){ int i; unsigned char *aBlob = (unsigned char*)pBlob; @@ -1693,7 +1688,7 @@ static void output_hex_blob(const void *pBlob, int nBlob){ } zStr[i*2] = '\0'; - oputf("X'%s'", zStr); + sqlite3_fprintf(out, "X'%s'", zStr); sqlite3_free(zStr); } @@ -1723,25 +1718,25 @@ static const char *unused_string( ** ** See also: output_quoted_escaped_string() */ -static void output_quoted_string(const char *z){ +static void output_quoted_string(FILE *out, const char *z){ int i; char c; - sqlite3_fsetmode(stdout, _O_BINARY); + sqlite3_fsetmode(out, _O_BINARY); if( z==0 ) return; for(i=0; (c = z[i])!=0 && c!='\''; i++){} if( c==0 ){ - oputf("'%s'",z); + sqlite3_fprintf(out, "'%s'",z); }else{ - oputz("'"); + sqlite3_fputs("'", out); while( *z ){ for(i=0; (c = z[i])!=0 && c!='\''; i++){} if( c=='\'' ) i++; if( i ){ - oputf("%.*s", i, z); + sqlite3_fprintf(out, "%.*s", i, z); z += i; } if( c=='\'' ){ - oputz("'"); + sqlite3_fputs("'", out); continue; } if( c==0 ){ @@ -1749,9 +1744,9 @@ static void output_quoted_string(const char *z){ } z++; } - oputz("'"); + sqlite3_fputs("'", out); } - sqlite3_fsetmode(stdout, _O_TEXT); + sqlite3_fsetmode(out, _O_TEXT); } /* @@ -1763,13 +1758,13 @@ static void output_quoted_string(const char *z){ ** This is like output_quoted_string() but with the addition of the \r\n ** escape mechanism. */ -static void output_quoted_escaped_string(const char *z){ +static void output_quoted_escaped_string(FILE *out, const char *z){ int i; char c; - sqlite3_fsetmode(stdout, _O_BINARY); + sqlite3_fsetmode(out, _O_BINARY); for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){} if( c==0 ){ - oputf("'%s'",z); + sqlite3_fprintf(out, "'%s'",z); }else{ const char *zNL = 0; const char *zCR = 0; @@ -1781,23 +1776,23 @@ static void output_quoted_escaped_string(const char *z){ if( z[i]=='\r' ) nCR++; } if( nNL ){ - oputz("replace("); + sqlite3_fputs("replace(", out); zNL = unused_string(z, "\\n", "\\012", zBuf1); } if( nCR ){ - oputz("replace("); + sqlite3_fputs("replace(", out); zCR = unused_string(z, "\\r", "\\015", zBuf2); } - oputz("'"); + sqlite3_fputs("'", out); while( *z ){ for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){} if( c=='\'' ) i++; if( i ){ - oputf("%.*s", i, z); + sqlite3_fprintf(out, "%.*s", i, z); z += i; } if( c=='\'' ){ - oputz("'"); + sqlite3_fputs("'", out); continue; } if( c==0 ){ @@ -1805,17 +1800,17 @@ static void output_quoted_escaped_string(const char *z){ } z++; if( c=='\n' ){ - oputz(zNL); + sqlite3_fputs(zNL, out); continue; } - oputz(zCR); + sqlite3_fputs(zCR, out); } - oputz("'"); + sqlite3_fputs("'", out); if( nCR ){ - oputf(",'%s',char(13))", zCR); + sqlite3_fprintf(out, ",'%s',char(13))", zCR); } if( nNL ){ - oputf(",'%s',char(10))", zNL); + sqlite3_fprintf(out, ",'%s',char(10))", zNL); } } sqlite3_fsetmode(stdout, _O_TEXT); @@ -1877,19 +1872,21 @@ const char *zSkipValidUtf8(const char *z, int nAccept, long ccm){ /* ** Output the given string as a quoted according to C or TCL quoting rules. */ -static void output_c_string(const char *z){ +static void output_c_string(FILE *out, const char *z){ char c; static const char *zq = "\""; static long ctrlMask = ~0L; static const char *zDQBSRO = "\"\\\x7f"; /* double-quote, backslash, rubout */ char ace[3] = "\\?"; char cbsSay; - oputz(zq); + sqlite3_fputs(zq, out); while( *z!=0 ){ const char *pcDQBSRO = anyOfInStr(z, zDQBSRO, ~(size_t)0); const char *pcPast = zSkipValidUtf8(z, INT_MAX, ctrlMask); const char *pcEnd = (pcDQBSRO && pcDQBSRO < pcPast)? pcDQBSRO : pcPast; - if( pcEnd > z ) oputb(z, (int)(pcEnd-z)); + if( pcEnd > z ){ + sqlite3_fprintf(out, "%.*s", (int)(pcEnd-z), z); + } if( (c = *pcEnd)==0 ) break; ++pcEnd; switch( c ){ @@ -1904,22 +1901,22 @@ static void output_c_string(const char *z){ } if( cbsSay ){ ace[1] = cbsSay; - oputz(ace); + sqlite3_fputs(ace, out); }else if( !isprint(c&0xff) ){ - oputf("\\%03o", c&0xff); + sqlite3_fprintf(out, "\\%03o", c&0xff); }else{ ace[1] = (char)c; - oputz(ace+1); + sqlite3_fputs(ace+1, out); } z = pcEnd; } - oputz(zq); + sqlite3_fputs(zq, out); } /* ** Output the given string as a quoted according to JSON quoting rules. */ -static void output_json_string(const char *z, i64 n){ +static void output_json_string(FILE *out, const char *z, i64 n){ char c; static const char *zq = "\""; static long ctrlMask = ~0L; @@ -1930,13 +1927,13 @@ static void output_json_string(const char *z, i64 n){ if( z==0 ) z = ""; pcLimit = z + ((n<0)? strlen(z) : (size_t)n); - oputz(zq); + sqlite3_fputs(zq, out); while( z < pcLimit ){ const char *pcDQBS = anyOfInStr(z, zDQBS, pcLimit-z); const char *pcPast = zSkipValidUtf8(z, (int)(pcLimit-z), ctrlMask); const char *pcEnd = (pcDQBS && pcDQBS < pcPast)? pcDQBS : pcPast; if( pcEnd > z ){ - oputb(z, (int)(pcEnd-z)); + sqlite3_fprintf(out, "%.*s", (int)(pcEnd-z), z); z = pcEnd; } if( z >= pcLimit ) break; @@ -1954,22 +1951,22 @@ static void output_json_string(const char *z, i64 n){ } if( cbsSay ){ ace[1] = cbsSay; - oputz(ace); + sqlite3_fputs(ace, out); }else if( c<=0x1f ){ - oputf("u%04x", c); + sqlite3_fprintf(out, "u%04x", c); }else{ ace[1] = (char)c; - oputz(ace+1); + sqlite3_fputs(ace+1, out); } } - oputz(zq); + sqlite3_fputs(zq, out); } /* ** Output the given string with characters that are special to ** HTML escaped. */ -static void output_html_string(const char *z){ +static void output_html_string(FILE *out, const char *z){ int i; if( z==0 ) z = ""; while( *z ){ @@ -1981,18 +1978,18 @@ static void output_html_string(const char *z){ && z[i]!='\''; i++){} if( i>0 ){ - oputf("%.*s",i,z); + sqlite3_fprintf(out, "%.*s",i,z); } if( z[i]=='<' ){ - oputz("<"); + sqlite3_fputs("<", out); }else if( z[i]=='&' ){ - oputz("&"); + sqlite3_fputs("&", out); }else if( z[i]=='>' ){ - oputz(">"); + sqlite3_fputs(">", out); }else if( z[i]=='\"' ){ - oputz("""); + sqlite3_fputs(""", out); }else if( z[i]=='\'' ){ - oputz("'"); + sqlite3_fputs("'", out); }else{ break; } @@ -2031,7 +2028,7 @@ static const char needCsvQuote[] = { */ static void output_csv(ShellState *p, const char *z, int bSep){ if( z==0 ){ - oputf("%s",p->nullValue); + sqlite3_fprintf(p->out, "%s",p->nullValue); }else{ unsigned i; for(i=0; z[i]; i++){ @@ -2043,14 +2040,14 @@ static void output_csv(ShellState *p, const char *z, int bSep){ if( i==0 || strstr(z, p->colSeparator)!=0 ){ char *zQuoted = sqlite3_mprintf("\"%w\"", z); shell_check_oom(zQuoted); - oputz(zQuoted); + sqlite3_fputs(zQuoted, p->out); sqlite3_free(zQuoted); }else{ - oputz(z); + sqlite3_fputs(z, p->out); } } if( bSep ){ - oputz(p->colSeparator); + sqlite3_fputs(p->colSeparator, p->out); } } @@ -2158,16 +2155,16 @@ static int shellAuth( az[1] = zA2; az[2] = zA3; az[3] = zA4; - oputf("authorizer: %s", azAction[op]); + sqlite3_fprintf(p->out, "authorizer: %s", azAction[op]); for(i=0; i<4; i++){ - oputz(" "); + sqlite3_fputs(" ", p->out); if( az[i] ){ - output_c_string(az[i]); + output_c_string(p->out, az[i]); }else{ - oputz("NULL"); + sqlite3_fputs("NULL", p->out); } } - oputz("\n"); + sqlite3_fputs("\n", p->out); if( p->bSafeMode ) (void)safeModeAuth(pClientData, op, zA1, zA2, zA3, zA4); return SQLITE_OK; } @@ -2183,7 +2180,7 @@ static int shellAuth( ** sqlite3_complete() returns false, try to terminate the comment before ** printing the result. https://sqlite.org/forum/forumpost/d7be961c5c */ -static void printSchemaLine(const char *z, const char *zTail){ +static void printSchemaLine(FILE *out, const char *z, const char *zTail){ char *zToFree = 0; if( z==0 ) return; if( zTail==0 ) return; @@ -2205,16 +2202,16 @@ static void printSchemaLine(const char *z, const char *zTail){ } } if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){ - oputf("CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail); + sqlite3_fprintf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail); }else{ - oputf("%s%s", z, zTail); + sqlite3_fprintf(out, "%s%s", z, zTail); } sqlite3_free(zToFree); } -static void printSchemaLineN(char *z, int n, const char *zTail){ +static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){ char c = z[n]; z[n] = 0; - printSchemaLine(z, zTail); + printSchemaLine(out, z, zTail); z[n] = c; } @@ -2242,7 +2239,7 @@ static void eqp_append(ShellState *p, int iEqpId, int p2, const char *zText){ if( zText==0 ) return; nText = strlen(zText); if( p->autoEQPtest ){ - oputf("%d,%d,%s\n", iEqpId, p2, zText); + sqlite3_fprintf(p->out, "%d,%d,%s\n", iEqpId, p2, zText); } pNew = sqlite3_malloc64( sizeof(*pNew) + nText ); shell_check_oom(pNew); @@ -2290,7 +2287,8 @@ static void eqp_render_level(ShellState *p, int iEqpId){ for(pRow = eqp_next_row(p, iEqpId, 0); pRow; pRow = pNext){ pNext = eqp_next_row(p, iEqpId, pRow); z = pRow->zText; - oputf("%s%s%s\n", p->sGraph.zPrefix, pNext ? "|--" : "`--", z); + sqlite3_fprintf(p->out, "%s%s%s\n", p->sGraph.zPrefix, + pNext ? "|--" : "`--", z); if( n<(i64)sizeof(p->sGraph.zPrefix)-7 ){ memcpy(&p->sGraph.zPrefix[n], pNext ? "| " : " ", 4); eqp_render_level(p, pRow->iEqpId); @@ -2310,13 +2308,13 @@ static void eqp_render(ShellState *p, i64 nCycle){ eqp_reset(p); return; } - oputf("%s\n", pRow->zText+3); + sqlite3_fprintf(p->out, "%s\n", pRow->zText+3); p->sGraph.pRow = pRow->pNext; sqlite3_free(pRow); }else if( nCycle>0 ){ - oputf("QUERY PLAN (cycles=%lld [100%%])\n", nCycle); + sqlite3_fprintf(p->out, "QUERY PLAN (cycles=%lld [100%%])\n", nCycle); }else{ - oputz("QUERY PLAN\n"); + sqlite3_fputs("QUERY PLAN\n", p->out); } p->sGraph.zPrefix[0] = 0; eqp_render_level(p, 0); @@ -2332,13 +2330,13 @@ static int progress_handler(void *pClientData) { ShellState *p = (ShellState*)pClientData; p->nProgress++; if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){ - oputf("Progress limit reached (%u)\n", p->nProgress); + sqlite3_fprintf(p->out, "Progress limit reached (%u)\n", p->nProgress); if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; if( p->flgProgress & SHELL_PROGRESS_ONCE ) p->mxProgress = 0; return 1; } if( (p->flgProgress & SHELL_PROGRESS_QUIET)==0 ){ - oputf("Progress %u\n", p->nProgress); + sqlite3_fprintf(p->out, "Progress %u\n", p->nProgress); } return 0; } @@ -2347,14 +2345,14 @@ static int progress_handler(void *pClientData) { /* ** Print N dashes */ -static void print_dashes(int N){ +static void print_dashes(FILE *out, int N){ const char zDash[] = "--------------------------------------------------"; const int nDash = sizeof(zDash) - 1; while( N>nDash ){ - oputz(zDash); + sqlite3_fputs(zDash, out); N -= nDash; } - oputf("%.*s", N, zDash); + sqlite3_fprintf(out, "%.*s", N, zDash); } /* @@ -2367,15 +2365,15 @@ static void print_row_separator( ){ int i; if( nArg>0 ){ - oputz(zSep); - print_dashes(p->actualWidth[0]+2); + sqlite3_fputs(zSep, p->out); + print_dashes(p->out, p->actualWidth[0]+2); for(i=1; iactualWidth[i]+2); + sqlite3_fputs(zSep, p->out); + print_dashes(p->out, p->actualWidth[i]+2); } - oputz(zSep); + sqlite3_fputs(zSep, p->out); } - oputz("\n"); + sqlite3_fputs("\n", p->out); } /* @@ -2405,9 +2403,9 @@ static int shell_callback( int len = strlen30(azCol[i] ? azCol[i] : ""); if( len>w ) w = len; } - if( p->cnt++>0 ) oputz(p->rowSeparator); + if( p->cnt++>0 ) sqlite3_fputs(p->rowSeparator, p->out); for(i=0; iout, "%*s = %s%s", w, azCol[i], azArg[i] ? azArg[i] : p->nullValue, p->rowSeparator); } break; @@ -2435,12 +2433,12 @@ static int shell_callback( /* If this is the first row seen, print out the headers */ if( p->cnt++==0 ){ for(i=0; iout, aWidth[i], azCol[ aMap[i] ]); + sqlite3_fputs(i==nArg-1 ? "\n" : " ", p->out); } for(i=0; iout, aWidth[i]); + sqlite3_fputs(i==nArg-1 ? "\n" : " ", p->out); } } @@ -2458,17 +2456,17 @@ static int shell_callback( } if( i==iIndent && p->aiIndent && p->pStmt ){ if( p->iIndentnIndent ){ - oputf("%*.s", p->aiIndent[p->iIndent], ""); + sqlite3_fprintf(p->out, "%*.s", p->aiIndent[p->iIndent], ""); } p->iIndent++; } - utf8_width_print(w, zVal ? zVal : p->nullValue); - oputz(i==nArg-1 ? "\n" : zSep); + utf8_width_print(p->out, w, zVal ? zVal : p->nullValue); + sqlite3_fputs(i==nArg-1 ? "\n" : zSep, p->out); } break; } case MODE_Semi: { /* .schema and .fullschema output */ - printSchemaLine(azArg[0], ";\n"); + printSchemaLine(p->out, azArg[0], ";\n"); break; } case MODE_Pretty: { /* .schema and .fullschema with --indent */ @@ -2483,7 +2481,7 @@ static int shell_callback( if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0 || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0 ){ - oputf("%s;\n", azArg[0]); + sqlite3_fprintf(p->out, "%s;\n", azArg[0]); break; } z = sqlite3_mprintf("%s", azArg[0]); @@ -2516,7 +2514,7 @@ static int shell_callback( }else if( c==')' ){ nParen--; if( nLine>0 && nParen==0 && j>0 ){ - printSchemaLineN(z, j, "\n"); + printSchemaLineN(p->out, z, j, "\n"); j = 0; } } @@ -2525,7 +2523,7 @@ static int shell_callback( && (c=='(' || c=='\n' || (c==',' && !wsToEol(z+i+1))) ){ if( c=='\n' ) j--; - printSchemaLineN(z, j, "\n "); + printSchemaLineN(p->out, z, j, "\n "); j = 0; nLine++; while( IsSpace(z[i+1]) ){ i++; } @@ -2533,59 +2531,60 @@ static int shell_callback( } z[j] = 0; } - printSchemaLine(z, ";\n"); + printSchemaLine(p->out, z, ";\n"); sqlite3_free(z); break; } case MODE_List: { if( p->cnt++==0 && p->showHeader ){ for(i=0; irowSeparator : p->colSeparator); + sqlite3_fprintf(p->out, "%s%s", azCol[i], + i==nArg-1 ? p->rowSeparator : p->colSeparator); } } if( azArg==0 ) break; for(i=0; inullValue; - oputz(z); - oputz((icolSeparator : p->rowSeparator); + sqlite3_fputs(z, p->out); + sqlite3_fputs((icolSeparator : p->rowSeparator, p->out); } break; } case MODE_Html: { if( p->cnt++==0 && p->showHeader ){ - oputz(""); + sqlite3_fputs("", p->out); for(i=0; i"); - output_html_string(azCol[i]); - oputz("\n"); + sqlite3_fputs("", p->out); + output_html_string(p->out, azCol[i]); + sqlite3_fputs("\n", p->out); } - oputz("\n"); + sqlite3_fputs("\n", p->out); } if( azArg==0 ) break; - oputz(""); + sqlite3_fputs("", p->out); for(i=0; i"); - output_html_string(azArg[i] ? azArg[i] : p->nullValue); - oputz("\n"); + sqlite3_fputs("", p->out); + output_html_string(p->out, azArg[i] ? azArg[i] : p->nullValue); + sqlite3_fputs("\n", p->out); } - oputz("\n"); + sqlite3_fputs("\n", p->out); break; } case MODE_Tcl: { if( p->cnt++==0 && p->showHeader ){ for(i=0; icolSeparator); + output_c_string(p->out, azCol[i] ? azCol[i] : ""); + if(icolSeparator, p->out); } - oputz(p->rowSeparator); + sqlite3_fputs(p->rowSeparator, p->out); } if( azArg==0 ) break; for(i=0; inullValue); - if(icolSeparator); + output_c_string(p->out, azArg[i] ? azArg[i] : p->nullValue); + if(icolSeparator, p->out); } - oputz(p->rowSeparator); + sqlite3_fputs(p->rowSeparator, p->out); break; } case MODE_Csv: { @@ -2594,57 +2593,57 @@ static int shell_callback( for(i=0; irowSeparator); + sqlite3_fputs(p->rowSeparator, p->out); } if( nArg>0 ){ for(i=0; irowSeparator); + sqlite3_fputs(p->rowSeparator, p->out); } sqlite3_fsetmode(p->out, _O_TEXT); break; } case MODE_Insert: { if( azArg==0 ) break; - oputf("INSERT INTO %s",p->zDestTable); + sqlite3_fprintf(p->out, "INSERT INTO %s",p->zDestTable); if( p->showHeader ){ - oputz("("); + sqlite3_fputs("(", p->out); for(i=0; i0 ) oputz(","); + if( i>0 ) sqlite3_fputs(",", p->out); if( quoteChar(azCol[i]) ){ char *z = sqlite3_mprintf("\"%w\"", azCol[i]); shell_check_oom(z); - oputz(z); + sqlite3_fputs(z, p->out); sqlite3_free(z); }else{ - oputf("%s", azCol[i]); + sqlite3_fprintf(p->out, "%s", azCol[i]); } } - oputz(")"); + sqlite3_fputs(")", p->out); } p->cnt++; for(i=0; i0 ? "," : " VALUES("); + sqlite3_fputs(i>0 ? "," : " VALUES(", p->out); if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ - oputz("NULL"); + sqlite3_fputs("NULL", p->out); }else if( aiType && aiType[i]==SQLITE_TEXT ){ if( ShellHasFlag(p, SHFLG_Newlines) ){ - output_quoted_string(azArg[i]); + output_quoted_string(p->out, azArg[i]); }else{ - output_quoted_escaped_string(azArg[i]); + output_quoted_escaped_string(p->out, azArg[i]); } }else if( aiType && aiType[i]==SQLITE_INTEGER ){ - oputz(azArg[i]); + sqlite3_fputs(azArg[i], p->out); }else if( aiType && aiType[i]==SQLITE_FLOAT ){ char z[50]; double r = sqlite3_column_double(p->pStmt, i); sqlite3_uint64 ur; memcpy(&ur,&r,sizeof(r)); if( ur==0x7ff0000000000000LL ){ - oputz("9.0e+999"); + sqlite3_fputs("9.0e+999", p->out); }else if( ur==0xfff0000000000000LL ){ - oputz("-9.0e+999"); + sqlite3_fputs("-9.0e+999", p->out); }else{ sqlite3_int64 ir = (sqlite3_int64)r; if( r==(double)ir ){ @@ -2652,63 +2651,63 @@ static int shell_callback( }else{ sqlite3_snprintf(50,z,"%!.20g", r); } - oputz(z); + sqlite3_fputs(z, p->out); } }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ const void *pBlob = sqlite3_column_blob(p->pStmt, i); int nBlob = sqlite3_column_bytes(p->pStmt, i); - output_hex_blob(pBlob, nBlob); + output_hex_blob(p->out, pBlob, nBlob); }else if( isNumber(azArg[i], 0) ){ - oputz(azArg[i]); + sqlite3_fputs(azArg[i], p->out); }else if( ShellHasFlag(p, SHFLG_Newlines) ){ - output_quoted_string(azArg[i]); + output_quoted_string(p->out, azArg[i]); }else{ - output_quoted_escaped_string(azArg[i]); + output_quoted_escaped_string(p->out, azArg[i]); } } - oputz(");\n"); + sqlite3_fputs(");\n", p->out); break; } case MODE_Json: { if( azArg==0 ) break; if( p->cnt==0 ){ - fputs("[{", p->out); + sqlite3_fputs("[{", p->out); }else{ - fputs(",\n{", p->out); + sqlite3_fputs(",\n{", p->out); } p->cnt++; for(i=0; iout, azCol[i], -1); + sqlite3_fputs(":", p->out); if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ - oputz("null"); + sqlite3_fputs("null", p->out); }else if( aiType && aiType[i]==SQLITE_FLOAT ){ char z[50]; double r = sqlite3_column_double(p->pStmt, i); sqlite3_uint64 ur; memcpy(&ur,&r,sizeof(r)); if( ur==0x7ff0000000000000LL ){ - oputz("9.0e+999"); + sqlite3_fputs("9.0e+999", p->out); }else if( ur==0xfff0000000000000LL ){ - oputz("-9.0e+999"); + sqlite3_fputs("-9.0e+999", p->out); }else{ sqlite3_snprintf(50,z,"%!.20g", r); - oputz(z); + sqlite3_fputs(z, p->out); } }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ const void *pBlob = sqlite3_column_blob(p->pStmt, i); int nBlob = sqlite3_column_bytes(p->pStmt, i); - output_json_string(pBlob, nBlob); + output_json_string(p->out, pBlob, nBlob); }else if( aiType && aiType[i]==SQLITE_TEXT ){ - output_json_string(azArg[i], -1); + output_json_string(p->out, azArg[i], -1); }else{ - oputz(azArg[i]); + sqlite3_fputs(azArg[i], p->out); } if( iout); } } - oputz("}"); + sqlite3_fputs("}", p->out); break; } case MODE_Quote: { @@ -2716,7 +2715,7 @@ static int shell_callback( if( p->cnt==0 && p->showHeader ){ for(i=0; i0 ) fputs(p->colSeparator, p->out); - output_quoted_string(azCol[i]); + output_quoted_string(p->out, azCol[i]); } fputs(p->rowSeparator, p->out); } @@ -2724,24 +2723,24 @@ static int shell_callback( for(i=0; i0 ) fputs(p->colSeparator, p->out); if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ - oputz("NULL"); + sqlite3_fputs("NULL", p->out); }else if( aiType && aiType[i]==SQLITE_TEXT ){ - output_quoted_string(azArg[i]); + output_quoted_string(p->out, azArg[i]); }else if( aiType && aiType[i]==SQLITE_INTEGER ){ - oputz(azArg[i]); + sqlite3_fputs(azArg[i], p->out); }else if( aiType && aiType[i]==SQLITE_FLOAT ){ char z[50]; double r = sqlite3_column_double(p->pStmt, i); sqlite3_snprintf(50,z,"%!.20g", r); - oputz(z); + sqlite3_fputs(z, p->out); }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){ const void *pBlob = sqlite3_column_blob(p->pStmt, i); int nBlob = sqlite3_column_bytes(p->pStmt, i); - output_hex_blob(pBlob, nBlob); + output_hex_blob(p->out, pBlob, nBlob); }else if( isNumber(azArg[i], 0) ){ - oputz(azArg[i]); + sqlite3_fputs(azArg[i], p->out); }else{ - output_quoted_string(azArg[i]); + output_quoted_string(p->out, azArg[i]); } } fputs(p->rowSeparator, p->out); @@ -2750,17 +2749,17 @@ static int shell_callback( case MODE_Ascii: { if( p->cnt++==0 && p->showHeader ){ for(i=0; i0 ) oputz(p->colSeparator); - oputz(azCol[i] ? azCol[i] : ""); + if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); + sqlite3_fputs(azCol[i] ? azCol[i] : "", p->out); } - oputz(p->rowSeparator); + sqlite3_fputs(p->rowSeparator, p->out); } if( azArg==0 ) break; for(i=0; i0 ) oputz(p->colSeparator); - oputz(azArg[i] ? azArg[i] : p->nullValue); + if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); + sqlite3_fputs(azArg[i] ? azArg[i] : p->nullValue, p->out); } - oputz(p->rowSeparator); + sqlite3_fputs(p->rowSeparator, p->out); break; } case MODE_EQP: { @@ -2942,7 +2941,7 @@ static int run_table_dump_query( rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0); if( rc!=SQLITE_OK || !pSelect ){ char *zContext = shell_error_context(zSelect, p->db); - oputf("/**** ERROR: (%d) %s *****/\n%s", + sqlite3_fprintf(p->out, "/**** ERROR: (%d) %s *****/\n%s", rc, sqlite3_errmsg(p->db), zContext); sqlite3_free(zContext); if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; @@ -2952,22 +2951,23 @@ static int run_table_dump_query( nResult = sqlite3_column_count(pSelect); while( rc==SQLITE_ROW ){ z = (const char*)sqlite3_column_text(pSelect, 0); - oputf("%s", z); + sqlite3_fprintf(p->out, "%s", z); for(i=1; iout, ",%s", sqlite3_column_text(pSelect, i)); } if( z==0 ) z = ""; while( z[0] && (z[0]!='-' || z[1]!='-') ) z++; if( z[0] ){ - oputz("\n;\n"); + sqlite3_fputs("\n;\n", p->out); }else{ - oputz(";\n"); + sqlite3_fputs(";\n", p->out); } rc = sqlite3_step(pSelect); } rc = sqlite3_finalize(pSelect); if( rc!=SQLITE_OK ){ - oputf("/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db)); + sqlite3_fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", + rc, sqlite3_errmsg(p->db)); if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; } return rc; @@ -3003,7 +3003,7 @@ static char *save_err_msg( /* ** Attempt to display I/O stats on Linux using /proc/PID/io */ -static void displayLinuxIoStats(void){ +static void displayLinuxIoStats(FILE *out){ FILE *in; char z[200]; sqlite3_snprintf(sizeof(z), z, "/proc/%d/io", getpid()); @@ -3026,7 +3026,7 @@ static void displayLinuxIoStats(void){ for(i=0; iout==0 ) return 0; + out = pArg->out; if( pArg->pStmt && pArg->statsOn==2 ){ int nCol, i, x; sqlite3_stmt *pStmt = pArg->pStmt; char z[100]; nCol = sqlite3_column_count(pStmt); - oputf("%-36s %d\n", "Number of output columns:", nCol); + sqlite3_fprintf(out, "%-36s %d\n", "Number of output columns:", nCol); for(i=0; istatsOn==3 ){ if( pArg->pStmt ){ iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP,bReset); - oputf("VM-steps: %d\n", iCur); + sqlite3_fprintf(out, "VM-steps: %d\n", iCur); } return 0; } - displayStatLine("Memory Used:", + displayStatLine(out, "Memory Used:", "%lld (max %lld) bytes", SQLITE_STATUS_MEMORY_USED, bReset); - displayStatLine("Number of Outstanding Allocations:", + displayStatLine(out, "Number of Outstanding Allocations:", "%lld (max %lld)", SQLITE_STATUS_MALLOC_COUNT, bReset); if( pArg->shellFlgs & SHFLG_Pagecache ){ - displayStatLine("Number of Pcache Pages Used:", + displayStatLine(out, "Number of Pcache Pages Used:", "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset); } - displayStatLine("Number of Pcache Overflow Bytes:", + displayStatLine(out, "Number of Pcache Overflow Bytes:", "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset); - displayStatLine("Largest Allocation:", + displayStatLine(out, "Largest Allocation:", "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset); - displayStatLine("Largest Pcache Allocation:", + displayStatLine(out, "Largest Pcache Allocation:", "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset); #ifdef YYTRACKMAXSTACKDEPTH - displayStatLine("Deepest Parser Stack:", + displayStatLine(out, "Deepest Parser Stack:", "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset); #endif @@ -3128,68 +3132,87 @@ static int display_stats( iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, bReset); - oputf("Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr); + sqlite3_fprintf(out, + "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr); sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &iCur, &iHiwtr, bReset); - oputf("Successful lookaside attempts: %d\n", iHiwtr); + sqlite3_fprintf(out, + "Successful lookaside attempts: %d\n", iHiwtr); sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, &iCur, &iHiwtr, bReset); - oputf("Lookaside failures due to size: %d\n", iHiwtr); + sqlite3_fprintf(out, + "Lookaside failures due to size: %d\n", iHiwtr); sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, &iCur, &iHiwtr, bReset); - oputf("Lookaside failures due to OOM: %d\n", iHiwtr); + sqlite3_fprintf(out, + "Lookaside failures due to OOM: %d\n", iHiwtr); } iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &iCur, &iHiwtr, bReset); - oputf("Pager Heap Usage: %d bytes\n", iCur); + sqlite3_fprintf(out, + "Pager Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_HIT, &iCur, &iHiwtr, 1); - oputf("Page cache hits: %d\n", iCur); + sqlite3_fprintf(out, + "Page cache hits: %d\n", iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_MISS, &iCur, &iHiwtr, 1); - oputf("Page cache misses: %d\n", iCur); + sqlite3_fprintf(out, + "Page cache misses: %d\n", iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_WRITE, &iCur, &iHiwtr, 1); - oputf("Page cache writes: %d\n", iCur); + sqlite3_fprintf(out, + "Page cache writes: %d\n", iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_SPILL, &iCur, &iHiwtr, 1); - oputf("Page cache spills: %d\n", iCur); + sqlite3_fprintf(out, + "Page cache spills: %d\n", iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_SCHEMA_USED, &iCur, &iHiwtr, bReset); - oputf("Schema Heap Usage: %d bytes\n", iCur); + sqlite3_fprintf(out, + "Schema Heap Usage: %d bytes\n", iCur); iHiwtr = iCur = -1; sqlite3_db_status(db, SQLITE_DBSTATUS_STMT_USED, &iCur, &iHiwtr, bReset); - oputf("Statement Heap/Lookaside Usage: %d bytes\n", iCur); + sqlite3_fprintf(out, + "Statement Heap/Lookaside Usage: %d bytes\n", iCur); } if( pArg->pStmt ){ int iHit, iMiss; iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset); - oputf("Fullscan Steps: %d\n", iCur); + sqlite3_fprintf(out, + "Fullscan Steps: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_SORT, bReset); - oputf("Sort Operations: %d\n", iCur); + sqlite3_fprintf(out, + "Sort Operations: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_AUTOINDEX,bReset); - oputf("Autoindex Inserts: %d\n", iCur); + sqlite3_fprintf(out, + "Autoindex Inserts: %d\n", iCur); iHit = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_HIT, bReset); iMiss = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_FILTER_MISS, bReset); if( iHit || iMiss ){ - oputf("Bloom filter bypass taken: %d/%d\n", iHit, iHit+iMiss); + sqlite3_fprintf(out, + "Bloom filter bypass taken: %d/%d\n", iHit, iHit+iMiss); } iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_VM_STEP, bReset); - oputf("Virtual Machine Steps: %d\n", iCur); + sqlite3_fprintf(out, + "Virtual Machine Steps: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_REPREPARE,bReset); - oputf("Reprepare operations: %d\n", iCur); + sqlite3_fprintf(out, + "Reprepare operations: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_RUN, bReset); - oputf("Number of times run: %d\n", iCur); + sqlite3_fprintf(out, + "Number of times run: %d\n", iCur); iCur = sqlite3_stmt_status(pArg->pStmt, SQLITE_STMTSTATUS_MEMUSED, bReset); - oputf("Memory used by prepared stmt: %d\n", iCur); + sqlite3_fprintf(out, + "Memory used by prepared stmt: %d\n", iCur); } #ifdef __linux__ - displayLinuxIoStats(); + displayLinuxIoStats(pArg->out); #endif /* Do not remove this machine readable comment: extra-stats-output-here */ @@ -3585,17 +3608,17 @@ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){ /* Draw horizontal line N characters long using unicode box ** characters */ -static void print_box_line(int N){ +static void print_box_line(FILE *out, int N){ const char zDash[] = BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24 BOX_24; const int nDash = sizeof(zDash) - 1; N *= 3; while( N>nDash ){ - oputz(zDash); + sqlite3_fputs(zDash, out); N -= nDash; } - oputf("%.*s", N, zDash); + sqlite3_fprintf(out, "%.*s", N, zDash); } /* @@ -3610,15 +3633,15 @@ static void print_box_row_separator( ){ int i; if( nArg>0 ){ - oputz(zSep1); - print_box_line(p->actualWidth[0]+2); + sqlite3_fputs(zSep1, p->out); + print_box_line(p->out, p->actualWidth[0]+2); for(i=1; iactualWidth[i]+2); + sqlite3_fputs(zSep2, p->out); + print_box_line(p->out, p->actualWidth[i]+2); } - oputz(zSep3); + sqlite3_fputs(zSep3, p->out); } - oputz("\n"); + sqlite3_fputs("\n", p->out); } /* @@ -3881,11 +3904,11 @@ static void exec_prepared_stmt_columnar( for(i=0; iactualWidth[i]; if( p->colWidth[i]<0 ) w = -w; - utf8_width_print(w, azData[i]); - fputs(i==nColumn-1?"\n":" ", p->out); + utf8_width_print(p->out, w, azData[i]); + sqlite3_fputs(i==nColumn-1?"\n":" ", p->out); } for(i=0; iactualWidth[i]); + print_dashes(p->out, p->actualWidth[i]); fputs(i==nColumn-1?"\n":" ", p->out); } } @@ -3899,8 +3922,9 @@ static void exec_prepared_stmt_columnar( for(i=0; iactualWidth[i]; n = strlenChar(azData[i]); - oputf("%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); - oputz(i==nColumn-1?" |\n":" | "); + sqlite3_fprintf(p->out, "%*s%s%*s", (w-n)/2, "", + azData[i], (w-n+1)/2, ""); + sqlite3_fputs(i==nColumn-1?" |\n":" | ", p->out); } print_row_separator(p, nColumn, "+"); break; @@ -3912,8 +3936,9 @@ static void exec_prepared_stmt_columnar( for(i=0; iactualWidth[i]; n = strlenChar(azData[i]); - oputf("%*s%s%*s", (w-n)/2, "", azData[i], (w-n+1)/2, ""); - oputz(i==nColumn-1?" |\n":" | "); + sqlite3_fprintf(p->out, "%*s%s%*s", (w-n)/2, "", + azData[i], (w-n+1)/2, ""); + sqlite3_fputs(i==nColumn-1?" |\n":" | ", p->out); } print_row_separator(p, nColumn, "|"); break; @@ -3922,11 +3947,11 @@ static void exec_prepared_stmt_columnar( colSep = " " BOX_13 " "; rowSep = " " BOX_13 "\n"; print_box_row_separator(p, nColumn, BOX_23, BOX_234, BOX_34); - oputz(BOX_13 " "); + sqlite3_fputs(BOX_13 " ", p->out); for(i=0; iactualWidth[i]; n = strlenChar(azData[i]); - oputf("%*s%s%*s%s", + sqlite3_fprintf(p->out, "%*s%s%*s%s", (w-n)/2, "", azData[i], (w-n+1)/2, "", i==nColumn-1?" "BOX_13"\n":" "BOX_13" "); } @@ -3936,28 +3961,28 @@ static void exec_prepared_stmt_columnar( } for(i=nColumn, j=0; icMode!=MODE_Column ){ - oputz(p->cMode==MODE_Box?BOX_13" ":"| "); + sqlite3_fputs(p->cMode==MODE_Box?BOX_13" ":"| ", p->out); } z = azData[i]; if( z==0 ) z = p->nullValue; w = p->actualWidth[j]; if( p->colWidth[j]<0 ) w = -w; - utf8_width_print(w, z); + utf8_width_print(p->out, w, z); if( j==nColumn-1 ){ - oputz(rowSep); + sqlite3_fputs(rowSep, p->out); if( bMultiLineRowExists && abRowDiv[i/nColumn-1] && i+1cMode==MODE_Table ){ print_row_separator(p, nColumn, "+"); }else if( p->cMode==MODE_Box ){ print_box_row_separator(p, nColumn, BOX_123, BOX_1234, BOX_134); }else if( p->cMode==MODE_Column ){ - oputz("\n"); + sqlite3_fputs("\n", p->out); } } j = -1; if( seenInterrupt ) goto columnar_end; }else{ - oputz(colSep); + sqlite3_fputs(colSep, p->out); } } if( p->cMode==MODE_Table ){ @@ -3967,7 +3992,7 @@ static void exec_prepared_stmt_columnar( } columnar_end: if( seenInterrupt ){ - oputz("Interrupt\n"); + sqlite3_fputs("Interrupt\n", p->out); } nData = (nRow+1)*nColumn; for(i=0; iexpert.pExpert; + FILE *out = pState->out; assert( p ); assert( bCancel || pzErr==0 || *pzErr==0 ); if( bCancel==0 ){ @@ -4115,8 +4141,8 @@ static int expertFinish( if( bVerbose ){ const char *zCand = sqlite3_expert_report(p,0,EXPERT_REPORT_CANDIDATES); - oputz("-- Candidates -----------------------------\n"); - oputf("%s\n", zCand); + sqlite3_fputs("-- Candidates -----------------------------\n", out); + sqlite3_fprintf(out, "%s\n", zCand); } for(i=0; ishellFlgs & SHFLG_DumpNoSys)!=0; if( cli_strcmp(zTable, "sqlite_sequence")==0 && !noSys ){ - if( !dataOnly ) oputz("DELETE FROM sqlite_sequence;\n"); + if( !dataOnly ) sqlite3_fputs("DELETE FROM sqlite_sequence;\n", p->out); }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 && !noSys ){ - if( !dataOnly ) oputz("ANALYZE sqlite_schema;\n"); + if( !dataOnly ) sqlite3_fputs("ANALYZE sqlite_schema;\n", p->out); }else if( cli_strncmp(zTable, "sqlite_", 7)==0 ){ return 0; }else if( dataOnly ){ @@ -4521,7 +4548,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){ }else if( cli_strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){ char *zIns; if( !p->writableSchema ){ - oputz("PRAGMA writable_schema=ON;\n"); + sqlite3_fputs("PRAGMA writable_schema=ON;\n", p->out); p->writableSchema = 1; } zIns = sqlite3_mprintf( @@ -4529,11 +4556,11 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){ "VALUES('table','%q','%q',0,'%q');", zTable, zTable, zSql); shell_check_oom(zIns); - oputf("%s\n", zIns); + sqlite3_fprintf(p->out, "%s\n", zIns); sqlite3_free(zIns); return 0; }else{ - printSchemaLine(zSql, ";\n"); + printSchemaLine(p->out, zSql, ";\n"); } if( cli_strcmp(zType, "table")==0 ){ @@ -4591,7 +4618,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azNotUsed){ p->mode = p->cMode = MODE_Insert; rc = shell_exec(p, sSelect.z, 0); if( (rc&0xff)==SQLITE_CORRUPT ){ - oputz("/****** CORRUPTION ERROR *******/\n"); + sqlite3_fputs("/****** CORRUPTION ERROR *******/\n", p->out); toggleSelectOrder(p->db); shell_exec(p, sSelect.z, 0); toggleSelectOrder(p->db); @@ -4622,9 +4649,9 @@ static int run_schema_dump_query( if( rc==SQLITE_CORRUPT ){ char *zQ2; int len = strlen30(zQuery); - oputz("/****** CORRUPTION ERROR *******/\n"); + sqlite3_fputs("/****** CORRUPTION ERROR *******/\n", p->out); if( zErr ){ - oputf("/****** %s ******/\n", zErr); + sqlite3_fprintf(p->out, "/****** %s ******/\n", zErr); sqlite3_free(zErr); zErr = 0; } @@ -4633,7 +4660,7 @@ static int run_schema_dump_query( sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery); rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr); if( rc ){ - oputf("/****** ERROR: %s ******/\n", zErr); + sqlite3_fprintf(p->out, "/****** ERROR: %s ******/\n", zErr); }else{ rc = SQLITE_CORRUPT; } @@ -4990,10 +5017,10 @@ static int showHelp(FILE *out, const char *zPattern){ } if( ((hw^hh)&HH_Undoc)==0 ){ if( (hh&HH_Summary)!=0 ){ - sputf(out, ".%s\n", azHelp[i]+1); + sqlite3_fprintf(out, ".%s\n", azHelp[i]+1); ++n; }else if( (hw&HW_SummaryOnly)==0 ){ - sputf(out, "%s\n", azHelp[i]); + sqlite3_fprintf(out, "%s\n", azHelp[i]); } } } @@ -5003,7 +5030,7 @@ static int showHelp(FILE *out, const char *zPattern){ shell_check_oom(zPat); for(i=0; i65536 || (pgsz & (pgsz-1))!=0 ){ - eputz("invalid pagesize\n"); + sqlite3_fputs("invalid pagesize\n", stderr); goto readHexDb_error; } for(nLine++; sqlite3_fgets(zLine, sizeof(zLine), in)!=0; nLine++){ @@ -5355,7 +5382,8 @@ static void open_db(ShellState *p, int openFlags){ sqlite3_close(p->db); sqlite3_open(":memory:", &p->db); if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ - eputz("Also: unable to open substitute in-memory database.\n"); + sqlite3_fputs("Also: unable to open substitute in-memory database.\n", + stderr); exit(1); }else{ eputf("Notice: using substitute in-memory database instead of \"%s\"\n", @@ -5749,12 +5777,12 @@ static int sql_trace_callback( switch( mType ){ case SQLITE_TRACE_ROW: case SQLITE_TRACE_STMT: { - sputf(p->traceOut, "%.*s;\n", (int)nSql, zSql); + sqlite3_fprintf(p->traceOut, "%.*s;\n", (int)nSql, zSql); break; } case SQLITE_TRACE_PROFILE: { sqlite3_int64 nNanosec = pX ? *(sqlite3_int64*)pX : 0; - sputf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec); + sqlite3_fprintf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec); break; } } @@ -6080,7 +6108,7 @@ static void tryToCloneSchema( zSql = sqlite3_column_text(pQuery, 1); if( zName==0 || zSql==0 ) continue; if( sqlite3_stricmp((char*)zName, "sqlite_sequence")!=0 ){ - sputf(stdout, "%s... ", zName); fflush(stdout); + sqlite3_fprintf(stdout, "%s... ", zName); fflush(stdout); sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); if( zErrMsg ){ eputf("Error: %s\nSQL: [%s]\n", zErrMsg, zSql); @@ -6110,7 +6138,7 @@ static void tryToCloneSchema( zSql = sqlite3_column_text(pQuery, 1); if( zName==0 || zSql==0 ) continue; if( sqlite3_stricmp((char*)zName, "sqlite_sequence")==0 ) continue; - sputf(stdout, "%s... ", zName); fflush(stdout); + sqlite3_fprintf(stdout, "%s... ", zName); fflush(stdout); sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); if( zErrMsg ){ eputf("Error: %s\nSQL: [%s]\n", zErrMsg, zSql); @@ -6160,7 +6188,7 @@ static void tryToClone(ShellState *p, const char *zNewDb){ */ static void output_redir(ShellState *p, FILE *pfNew){ if( p->out != stdout ){ - eputz("Output already redirected.\n"); + sqlite3_fputs("Output already redirected.\n", stderr); }else{ p->out = pfNew; } @@ -6296,28 +6324,28 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ memcpy(aHdr, pb, 100); sqlite3_finalize(pStmt); }else{ - eputz("unable to read database header\n"); + sqlite3_fputs("unable to read database header\n", stderr); sqlite3_finalize(pStmt); return 1; } i = get2byteInt(aHdr+16); if( i==1 ) i = 65536; - oputf("%-20s %d\n", "database page size:", i); - oputf("%-20s %d\n", "write format:", aHdr[18]); - oputf("%-20s %d\n", "read format:", aHdr[19]); - oputf("%-20s %d\n", "reserved bytes:", aHdr[20]); + sqlite3_fprintf(p->out, "%-20s %d\n", "database page size:", i); + sqlite3_fprintf(p->out, "%-20s %d\n", "write format:", aHdr[18]); + sqlite3_fprintf(p->out, "%-20s %d\n", "read format:", aHdr[19]); + sqlite3_fprintf(p->out, "%-20s %d\n", "reserved bytes:", aHdr[20]); for(i=0; iout, "%-20s %u", aField[i].zName, val); switch( ofst ){ case 56: { - if( val==1 ) oputz(" (utf8)"); - if( val==2 ) oputz(" (utf16le)"); - if( val==3 ) oputz(" (utf16be)"); + if( val==1 ) sqlite3_fputs(" (utf8)", p->out); + if( val==2 ) sqlite3_fputs(" (utf16le)", p->out); + if( val==3 ) sqlite3_fputs(" (utf16be)", p->out); } } - oputz("\n"); + sqlite3_fputs("\n", p->out); } if( zDb==0 ){ zSchemaTab = sqlite3_mprintf("main.sqlite_schema"); @@ -6330,11 +6358,11 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab); int val = db_int(p->db, zSql); sqlite3_free(zSql); - oputf("%-20s %d\n", aQuery[i].zName, val); + sqlite3_fprintf(p->out, "%-20s %d\n", aQuery[i].zName, val); } sqlite3_free(zSchemaTab); sqlite3_file_control(p->db, zDb, SQLITE_FCNTL_DATA_VERSION, &iDataVersion); - oputf("%-20s %u\n", "data version", iDataVersion); + sqlite3_fprintf(p->out, "%-20s %u\n", "data version", iDataVersion); return 0; } #endif /* SQLITE_SHELL_HAVE_RECOVER */ @@ -6590,6 +6618,7 @@ static int lintFkeyIndexes( const char *zIndent = ""; /* How much to indent CREATE INDEX by */ int rc; /* Return code */ sqlite3_stmt *pSql = 0; /* Compiled version of SQL statement below */ + FILE *out = pState->out; /* Send output here */ /* ** This SELECT statement returns one row for each foreign key constraint @@ -6709,22 +6738,22 @@ static int lintFkeyIndexes( if( rc!=SQLITE_OK ) break; if( res<0 ){ - eputz("Error: internal error"); + sqlite3_fputs("Error: internal error", stderr); break; }else{ if( bGroupByParent && (bVerbose || res==0) && (zPrev==0 || sqlite3_stricmp(zParent, zPrev)) ){ - oputf("-- Parent table %s\n", zParent); + sqlite3_fprintf(out, "-- Parent table %s\n", zParent); sqlite3_free(zPrev); zPrev = sqlite3_mprintf("%s", zParent); } if( res==0 ){ - oputf("%s%s --> %s\n", zIndent, zCI, zTarget); + sqlite3_fprintf(out, "%s%s --> %s\n", zIndent, zCI, zTarget); }else if( bVerbose ){ - oputf("%s/* no extra indexes required for %s -> %s */\n", + sqlite3_fprintf(out, "%s/* no extra indexes required for %s -> %s */\n", zIndent, zFrom, zTarget ); } @@ -6762,9 +6791,9 @@ static int lintDotCommand( return lintFkeyIndexes(pState, azArg, nArg); usage: - eputf("Usage %s sub-command ?switches...?\n", azArg[0]); - eputz("Where sub-commands are:\n"); - eputz(" fkey-indexes\n"); + sqlite3_fprintf(stderr,"Usage %s sub-command ?switches...?\n", azArg[0]); + sqlite3_fprintf(stderr, "Where sub-commands are:\n"); + sqlite3_fprintf(stderr, " fkey-indexes\n"); return SQLITE_ERROR; } @@ -6873,6 +6902,7 @@ struct ArCommand { const char *zDir; /* --directory argument, or NULL */ char **azArg; /* Array of command arguments */ ShellState *p; /* Shell state */ + FILE *out; /* Output to this stream */ sqlite3 *db; /* Database containing the archive */ }; @@ -6896,9 +6926,9 @@ static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){ va_end(ap); shellEmitError(z); if( pAr->fromCmdLine ){ - eputz("Use \"-A\" for more help\n"); + sqlite3_fputs("Use \"-A\" for more help\n", stderr); }else{ - eputz("Use \".archive --help\" for more help\n"); + sqlite3_fputs("Use \".archive --help\" for more help\n", stderr); } sqlite3_free(z); return SQLITE_ERROR; @@ -6998,7 +7028,7 @@ static int arParseCommand( struct ArSwitch *pEnd = &aSwitch[nSwitch]; if( nArg<=1 ){ - eputz("Wrong number of arguments. Usage:\n"); + sqlite3_fprintf(stderr, "Wrong number of arguments. Usage:\n"); return arUsage(stderr); }else{ char *z = azArg[1]; @@ -7104,7 +7134,7 @@ static int arParseCommand( } } if( pAr->eCmd==0 ){ - eputz("Required argument missing. Usage:\n"); + sqlite3_fprintf(stderr, "Required argument missing. Usage:\n"); return arUsage(stderr); } return SQLITE_OK; @@ -7214,15 +7244,15 @@ static int arListCommand(ArCommand *pAr){ shellPreparePrintf(pAr->db, &rc, &pSql, zSql, azCols[pAr->bVerbose], pAr->zSrcTable, zWhere); if( pAr->bDryRun ){ - oputf("%s\n", sqlite3_sql(pSql)); + sqlite3_fprintf(pAr->out, "%s\n", sqlite3_sql(pSql)); }else{ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ if( pAr->bVerbose ){ - oputf("%s % 10d %s %s\n", + sqlite3_fprintf(pAr->out, "%s % 10d %s %s\n", sqlite3_column_text(pSql, 0), sqlite3_column_int(pSql, 1), sqlite3_column_text(pSql, 2),sqlite3_column_text(pSql, 3)); }else{ - oputf("%s\n", sqlite3_column_text(pSql, 0)); + sqlite3_fprintf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); } } } @@ -7249,7 +7279,7 @@ static int arRemoveCommand(ArCommand *pAr){ zSql = sqlite3_mprintf("DELETE FROM %s WHERE %s;", pAr->zSrcTable, zWhere); if( pAr->bDryRun ){ - oputf("%s\n", zSql); + sqlite3_fprintf(pAr->out, "%s\n", zSql); }else{ char *zErr = 0; rc = sqlite3_exec(pAr->db, "SAVEPOINT ar;", 0, 0, 0); @@ -7262,7 +7292,7 @@ static int arRemoveCommand(ArCommand *pAr){ } } if( zErr ){ - sputf(stdout, "ERROR: %s\n", zErr); /* stdout? */ + sqlite3_fprintf(stdout, "ERROR: %s\n", zErr); /* stdout? */ sqlite3_free(zErr); } } @@ -7326,11 +7356,11 @@ static int arExtractCommand(ArCommand *pAr){ j = sqlite3_bind_parameter_index(pSql, "$dirOnly"); sqlite3_bind_int(pSql, j, i); if( pAr->bDryRun ){ - oputf("%s\n", sqlite3_sql(pSql)); + sqlite3_fprintf(pAr->out, "%s\n", sqlite3_sql(pSql)); }else{ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ if( i==0 && pAr->bVerbose ){ - oputf("%s\n", sqlite3_column_text(pSql, 0)); + sqlite3_fprintf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); } } } @@ -7350,13 +7380,13 @@ static int arExtractCommand(ArCommand *pAr){ static int arExecSql(ArCommand *pAr, const char *zSql){ int rc; if( pAr->bDryRun ){ - oputf("%s\n", zSql); + sqlite3_fprintf(pAr->out, "%s\n", zSql); rc = SQLITE_OK; }else{ char *zErr = 0; rc = sqlite3_exec(pAr->db, zSql, 0, 0, &zErr); if( zErr ){ - sputf(stdout, "ERROR: %s\n", zErr); + sqlite3_fprintf(stdout, "ERROR: %s\n", zErr); sqlite3_free(zErr); } } @@ -7505,6 +7535,7 @@ static int arDotCommand( if( rc==SQLITE_OK ){ int eDbType = SHELL_OPEN_UNSPEC; cmd.p = pState; + cmd.out = pState->out; cmd.db = pState->db; if( cmd.zFile ){ eDbType = deduceDatabaseType(cmd.zFile, 1); @@ -7531,13 +7562,14 @@ static int arDotCommand( } cmd.db = 0; if( cmd.bDryRun ){ - oputf("-- open database '%s'%s\n", cmd.zFile, + sqlite3_fprintf(cmd.out, "-- open database '%s'%s\n", cmd.zFile, eDbType==SHELL_OPEN_APPENDVFS ? " using 'apndvfs'" : ""); } rc = sqlite3_open_v2(cmd.zFile, &cmd.db, flags, eDbType==SHELL_OPEN_APPENDVFS ? "apndvfs" : 0); if( rc!=SQLITE_OK ){ - eputf("cannot open file: %s (%s)\n", cmd.zFile, sqlite3_errmsg(cmd.db)); + sqlite3_fprintf(stderr, "cannot open file: %s (%s)\n", + cmd.zFile, sqlite3_errmsg(cmd.db)); goto end_ar_command; } sqlite3_fileio_init(cmd.db, 0, 0); @@ -7550,7 +7582,7 @@ static int arDotCommand( if( cmd.eCmd!=AR_CMD_CREATE && sqlite3_table_column_metadata(cmd.db,0,"sqlar","name",0,0,0,0,0) ){ - eputz("database does not contain an 'sqlar' table\n"); + sqlite3_fprintf(stderr, "database does not contain an 'sqlar' table\n"); rc = SQLITE_ERROR; goto end_ar_command; } @@ -7608,7 +7640,7 @@ end_ar_command: */ static int recoverSqlCb(void *pCtx, const char *zSql){ ShellState *pState = (ShellState*)pCtx; - sputf(pState->out, "%s;\n", zSql); + sqlite3_fprintf(pState->out, "%s;\n", zSql); return SQLITE_OK; } @@ -7692,7 +7724,7 @@ static int intckDatabaseCmd(ShellState *pState, i64 nStepPerUnlock){ while( SQLITE_OK==sqlite3_intck_step(p) ){ const char *zMsg = sqlite3_intck_message(p); if( zMsg ){ - oputf("%s\n", zMsg); + sqlite3_fprintf(pState->out, "%s\n", zMsg); nError++; } nStep++; @@ -7706,7 +7738,7 @@ static int intckDatabaseCmd(ShellState *pState, i64 nStepPerUnlock){ } sqlite3_intck_close(p); - oputf("%lld steps, %lld errors\n", nStep, nError); + sqlite3_fprintf(pState->out, "%lld steps, %lld errors\n", nStep, nError); } return rc; @@ -7946,8 +7978,9 @@ static int outputDumpWarning(ShellState *p, const char *zLike){ "sql LIKE 'CREATE VIRTUAL TABLE%%' AND %s", zLike ? zLike : "true" ); if( rc==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){ - oputz("/* WARNING: " - "Script requires that SQLITE_DBCONFIG_DEFENSIVE be disabled */\n" + sqlite3_fputs("/* WARNING: " + "Script requires that SQLITE_DBCONFIG_DEFENSIVE be disabled */\n", + p->out ); } shellFinalize(&rc, pStmt); @@ -7978,12 +8011,14 @@ static int faultsim_callback(int iArg){ if( faultsim_state.iCnt ){ if( faultsim_state.iCnt>0 ) faultsim_state.iCnt--; if( faultsim_state.eVerbose>=2 ){ - oputf("FAULT-SIM id=%d no-fault (cnt=%d)\n", iArg, faultsim_state.iCnt); + sqlite3_fprintf(stdout, + "FAULT-SIM id=%d no-fault (cnt=%d)\n", iArg, faultsim_state.iCnt); } return SQLITE_OK; } if( faultsim_state.eVerbose>=1 ){ - oputf("FAULT-SIM id=%d returns %d\n", iArg, faultsim_state.iErr); + sqlite3_fprintf(stdout, + "FAULT-SIM id=%d returns %d\n", iArg, faultsim_state.iErr); } faultsim_state.iCnt = faultsim_state.iInterval; faultsim_state.nHit++; @@ -8046,7 +8081,7 @@ static int do_meta_command(char *zLine, ShellState *p){ #ifndef SQLITE_OMIT_AUTHORIZATION if( c=='a' && cli_strncmp(azArg[0], "auth", n)==0 ){ if( nArg!=2 ){ - eputz("Usage: .auth ON|OFF\n"); + sqlite3_fprintf(stderr, "Usage: .auth ON|OFF\n"); rc = 1; goto meta_command_exit; } @@ -8102,12 +8137,12 @@ static int do_meta_command(char *zLine, ShellState *p){ zDb = zDestFile; zDestFile = azArg[j]; }else{ - eputz("Usage: .backup ?DB? ?OPTIONS? FILENAME\n"); + sqlite3_fprintf(stderr, "Usage: .backup ?DB? ?OPTIONS? FILENAME\n"); return 1; } } if( zDestFile==0 ){ - eputz("missing FILENAME argument on .backup\n"); + sqlite3_fprintf(stderr, "missing FILENAME argument on .backup\n"); return 1; } if( zDb==0 ) zDb = "main"; @@ -8221,7 +8256,7 @@ static int do_meta_command(char *zLine, ShellState *p){ p->zTestcase, azArg[1], zRes); rc = 1; }else{ - oputf("testcase-%s ok\n", p->zTestcase); + sqlite3_fprintf(p->out, "testcase-%s ok\n", p->zTestcase); p->nCheck++; } sqlite3_free(zRes); @@ -8254,9 +8289,9 @@ static int do_meta_command(char *zLine, ShellState *p){ zFile = "(temporary-file)"; } if( p->pAuxDb == &p->aAuxDb[i] ){ - sputf(stdout, "ACTIVE %d: %s\n", i, zFile); + sqlite3_fprintf(stdout, "ACTIVE %d: %s\n", i, zFile); }else if( p->aAuxDb[i].db!=0 ){ - sputf(stdout, " %d: %s\n", i, zFile); + sqlite3_fprintf(stdout, " %d: %s\n", i, zFile); } } }else if( nArg==2 && IsDigit(azArg[1][0]) && azArg[1][1]==0 ){ @@ -8329,7 +8364,7 @@ static int do_meta_command(char *zLine, ShellState *p){ int eTxn = sqlite3_txn_state(p->db, azName[i*2]); int bRdonly = sqlite3_db_readonly(p->db, azName[i*2]); const char *z = azName[i*2+1]; - oputf("%s: %s %s%s\n", + sqlite3_fprintf(p->out, "%s: %s %s%s\n", azName[i*2], z && z[0] ? z : "\"\"", bRdonly ? "r/o" : "r/w", eTxn==SQLITE_TXN_NONE ? "" : eTxn==SQLITE_TXN_READ ? " read-txn" : " write-txn"); @@ -8371,7 +8406,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0); } sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v); - oputf("%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off"); + sqlite3_fprintf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off"); if( nArg>1 ) break; } if( nArg>1 && ii==ArraySize(aDbConfig) ){ @@ -8460,8 +8495,8 @@ static int do_meta_command(char *zLine, ShellState *p){ /* When playing back a "dump", the content might appear in an order ** which causes immediate foreign key constraints to be violated. ** So disable foreign-key constraint enforcement to prevent problems. */ - oputz("PRAGMA foreign_keys=OFF;\n"); - oputz("BEGIN TRANSACTION;\n"); + sqlite3_fputs("PRAGMA foreign_keys=OFF;\n", p->out); + sqlite3_fputs("BEGIN TRANSACTION;\n", p->out); } p->writableSchema = 0; p->showHeader = 0; @@ -8493,13 +8528,13 @@ static int do_meta_command(char *zLine, ShellState *p){ } sqlite3_free(zLike); if( p->writableSchema ){ - oputz("PRAGMA writable_schema=OFF;\n"); + sqlite3_fputs("PRAGMA writable_schema=OFF;\n", p->out); p->writableSchema = 0; } sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0); sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0); if( (p->shellFlgs & SHFLG_DumpDataOnly)==0 ){ - oputz(p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n"); + sqlite3_fputs(p->nErr?"ROLLBACK; -- due to errors\n":"COMMIT;\n", p->out); } p->showHeader = savedShowHeader; p->shellFlgs = savedShellFlags; @@ -8636,9 +8671,9 @@ static int do_meta_command(char *zLine, ShellState *p){ /* --help lists all file-controls */ if( cli_strcmp(zCmd,"help")==0 ){ - oputz("Available file-controls:\n"); + sqlite3_fputs("Available file-controls:\n", p->out); for(i=0; iout, " .filectrl %s %s\n", aCtrl[i].zCtrlName, aCtrl[i].zUsage); } rc = 1; goto meta_command_exit; @@ -8705,7 +8740,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( nArg!=2 ) break; sqlite3_file_control(p->db, zSchema, filectrl, &z); if( z ){ - oputf("%s\n", z); + sqlite3_fprintf(p->out, "%s\n", z); sqlite3_free(z); } isOk = 2; @@ -8719,19 +8754,20 @@ static int do_meta_command(char *zLine, ShellState *p){ } x = -1; sqlite3_file_control(p->db, zSchema, filectrl, &x); - oputf("%d\n", x); + sqlite3_fprintf(p->out, "%d\n", x); isOk = 2; break; } } } if( isOk==0 && iCtrl>=0 ){ - oputf("Usage: .filectrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); + sqlite3_fprintf(p->out, "Usage: .filectrl %s %s\n", + zCmd, aCtrl[iCtrl].zUsage); rc = 1; }else if( isOk==1 ){ char zBuf[100]; sqlite3_snprintf(sizeof(zBuf), zBuf, "%lld", iRes); - oputf("%s\n", zBuf); + sqlite3_fprintf(p->out, "%s\n", zBuf); } }else @@ -8772,15 +8808,15 @@ static int do_meta_command(char *zLine, ShellState *p){ } } if( doStats==0 ){ - oputz("/* No STAT tables available */\n"); + sqlite3_fputs("/* No STAT tables available */\n", p->out); }else{ - oputz("ANALYZE sqlite_schema;\n"); + sqlite3_fputs("ANALYZE sqlite_schema;\n", p->out); data.cMode = data.mode = MODE_Insert; data.zDestTable = "sqlite_stat1"; shell_exec(&data, "SELECT * FROM sqlite_stat1", 0); data.zDestTable = "sqlite_stat4"; shell_exec(&data, "SELECT * FROM sqlite_stat4", 0); - oputz("ANALYZE sqlite_schema;\n"); + sqlite3_fputs("ANALYZE sqlite_schema;\n", p->out); } }else @@ -8798,7 +8834,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( nArg>=2 ){ n = showHelp(p->out, azArg[1]); if( n==0 ){ - oputf("Nothing matches '%s'\n", azArg[1]); + sqlite3_fprintf(p->out, "Nothing matches '%s'\n", azArg[1]); } }else{ showHelp(p->out, 0); @@ -8841,7 +8877,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( zTable==0 ){ zTable = z; }else{ - oputf("ERROR: extra argument: \"%s\". Usage:\n", z); + sqlite3_fprintf(p->out, "ERROR: extra argument: \"%s\". Usage:\n",z); showHelp(p->out, "import"); goto meta_command_exit; } @@ -8862,13 +8898,13 @@ static int do_meta_command(char *zLine, ShellState *p){ xRead = csv_read_one_field; useOutputMode = 0; }else{ - oputf("ERROR: unknown option: \"%s\". Usage:\n", z); + sqlite3_fprintf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", z); showHelp(p->out, "import"); goto meta_command_exit; } } if( zTable==0 ){ - oputf("ERROR: missing %s argument. Usage:\n", + sqlite3_fprintf(p->out, "ERROR: missing %s argument. Usage:\n", zFile==0 ? "FILE" : "TABLE"); showHelp(p->out, "import"); goto meta_command_exit; @@ -8934,12 +8970,12 @@ static int do_meta_command(char *zLine, ShellState *p){ char zSep[2]; zSep[1] = 0; zSep[0] = sCtx.cColSep; - oputz("Column separator "); - output_c_string(zSep); - oputz(", row separator "); + sqlite3_fputs("Column separator ", p->out); + output_c_string(p->out, zSep); + sqlite3_fputs(", row separator ", p->out); zSep[0] = sCtx.cRowSep; - output_c_string(zSep); - oputz("\n"); + output_c_string(p->out, zSep); + sqlite3_fputs("\n", p->out); } sCtx.z = sqlite3_malloc64(120); if( sCtx.z==0 ){ @@ -8964,7 +9000,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } zColDefs = zAutoColumn(0, &dbCols, &zRenames); if( zRenames!=0 ){ - sputf((stdin_is_interactive && p->in==stdin)? p->out : stderr, + sqlite3_fprintf((stdin_is_interactive && p->in==stdin)? p->out : stderr, "Columns renamed during .import %s due to duplicates:\n" "%s\n", sCtx.zFile, zRenames); sqlite3_free(zRenames); @@ -8983,7 +9019,7 @@ static int do_meta_command(char *zLine, ShellState *p){ shell_out_of_memory(); } if( eVerbose>=1 ){ - oputf("%s\n", zCreate); + sqlite3_fprintf(p->out, "%s\n", zCreate); } rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); sqlite3_free(zCreate); @@ -9044,7 +9080,7 @@ static int do_meta_command(char *zLine, ShellState *p){ zSql[j] = 0; assert( j=2 ){ - oputf("Insert using: %s\n", zSql); + sqlite3_fprintf(p->out, "Insert using: %s\n", zSql); } rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); @@ -9115,7 +9151,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_finalize(pStmt); if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); if( eVerbose>0 ){ - oputf("Added %d rows with %d errors using %d lines of input\n", + sqlite3_fprintf(p->out, "Added %d rows with %d errors using %d lines of input\n", sCtx.nRow, sCtx.nErr, sCtx.nLine-1); } }else @@ -9214,8 +9250,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( rc ){ eputf("Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); }else{ - sputf(stdout, "%s;\n", zSql); - sputf(stdout, "WARNING: writing to an imposter table will corrupt" + sqlite3_fprintf(stdout, "%s;\n", zSql); + sqlite3_fprintf(stdout, "WARNING: writing to an imposter table will corrupt" " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index"); } }else{ @@ -9286,7 +9322,7 @@ static int do_meta_command(char *zLine, ShellState *p){ open_db(p, 0); if( nArg==1 ){ for(i=0; idb, aLimit[i].limitCode, -1)); } }else if( nArg>3 ){ @@ -9318,7 +9354,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_limit(p->db, aLimit[iLimit].limitCode, (int)integerValue(azArg[2])); } - sputf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName, + sqlite3_fprintf(stdout, "%20s %d\n", aLimit[iLimit].zLimitName, sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1)); } }else @@ -9420,12 +9456,13 @@ static int do_meta_command(char *zLine, ShellState *p){ if( p->mode==MODE_Column || (p->mode>=MODE_Markdown && p->mode<=MODE_Box) ){ - oputf("current output mode: %s --wrap %d --wordwrap %s --%squote\n", + sqlite3_fprintf(p->out, + "current output mode: %s --wrap %d --wordwrap %s --%squote\n", modeDescr[p->mode], p->cmOpts.iWrap, p->cmOpts.bWordWrap ? "on" : "off", p->cmOpts.bQuote ? "" : "no"); }else{ - oputf("current output mode: %s\n", modeDescr[p->mode]); + sqlite3_fprintf(p->out, "current output mode: %s\n", modeDescr[p->mode]); } zMode = modeDescr[p->mode]; } @@ -9644,7 +9681,8 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( c!='e' && cli_strcmp(z,"-e")==0 ){ eMode = 'e'; /* text editor */ }else{ - oputf("ERROR: unknown option: \"%s\". Usage:\n", azArg[i]); + sqlite3_fprintf(p->out, + "ERROR: unknown option: \"%s\". Usage:\n", azArg[i]); showHelp(p->out, azArg[0]); rc = 1; goto meta_command_exit; @@ -9656,7 +9694,7 @@ static int do_meta_command(char *zLine, ShellState *p){ break; } }else{ - oputf("ERROR: extra parameter: \"%s\". Usage:\n", azArg[i]); + sqlite3_fprintf(p->out, "ERROR: extra parameter: \"%s\". Usage:\n", azArg[i]); showHelp(p->out, azArg[0]); rc = 1; sqlite3_free(zFile); @@ -9705,7 +9743,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; }else{ output_redir(p, pfPipe); - if( zBom ) oputz(zBom); + if( zBom ) sqlite3_fputs(zBom, pfPipe); sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); } #endif @@ -9718,7 +9756,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; } else { output_redir(p, pfFile); - if( zBom ) oputz(zBom); + if( zBom ) sqlite3_fputs(zBom, pfFile); sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); } } @@ -9759,7 +9797,7 @@ static int do_meta_command(char *zLine, ShellState *p){ "SELECT key, quote(value) " "FROM temp.sqlite_parameters;", -1, &pStmt, 0); while( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){ - oputf("%-*s %s\n", len, sqlite3_column_text(pStmt,0), + sqlite3_fprintf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0), sqlite3_column_text(pStmt,1)); } sqlite3_finalize(pStmt); @@ -9804,7 +9842,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); if( rx!=SQLITE_OK ){ - oputf("Error: %s\n", sqlite3_errmsg(p->db)); + sqlite3_fprintf(p->out, "Error: %s\n", sqlite3_errmsg(p->db)); sqlite3_finalize(pStmt); pStmt = 0; rc = 1; @@ -9833,10 +9871,10 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='p' && n>=3 && cli_strncmp(azArg[0], "print", n)==0 ){ int i; for(i=1; i1 ) oputz(" "); - oputz(azArg[i]); + if( i>1 ) sqlite3_fputs(" ", p->out); + sqlite3_fputs(azArg[i], p->out); } - oputz("\n"); + sqlite3_fputs("\n", p->out); }else #ifndef SQLITE_OMIT_PROGRESS_CALLBACK @@ -10143,7 +10181,7 @@ static int do_meta_command(char *zLine, ShellState *p){ appendText(&sSelect, "sql IS NOT NULL" " ORDER BY snum, rowid", 0); if( bDebug ){ - oputf("SQL: %s;\n", sSelect.z); + sqlite3_fprintf(p->out, "SQL: %s;\n", sSelect.z); }else{ rc = sqlite3_exec(p->db, sSelect.z, callback, &data, &zErrMsg); } @@ -10234,7 +10272,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3session_patchset(pSession->p, &szChng, &pChng); } if( rc ){ - sputf(stdout, "Error: error code %d\n", rc); + sqlite3_fprintf(stdout, "Error: error code %d\n", rc); rc = 0; } if( pChng @@ -10266,7 +10304,7 @@ static int do_meta_command(char *zLine, ShellState *p){ ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); if( pAuxDb->nSession ){ ii = sqlite3session_enable(pSession->p, ii); - oputf("session %s enable flag = %d\n", pSession->zName, ii); + sqlite3_fprintf(p->out, "session %s enable flag = %d\n", pSession->zName, ii); } }else @@ -10301,7 +10339,7 @@ static int do_meta_command(char *zLine, ShellState *p){ ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); if( pAuxDb->nSession ){ ii = sqlite3session_indirect(pSession->p, ii); - oputf("session %s indirect flag = %d\n", pSession->zName, ii); + sqlite3_fprintf(p->out, "session %s indirect flag = %d\n", pSession->zName, ii); } }else @@ -10313,7 +10351,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( nCmd!=1 ) goto session_syntax_error; if( pAuxDb->nSession ){ ii = sqlite3session_isempty(pSession->p); - oputf("session %s isempty flag = %d\n", pSession->zName, ii); + sqlite3_fprintf(p->out, "session %s isempty flag = %d\n", pSession->zName, ii); } }else @@ -10322,7 +10360,7 @@ static int do_meta_command(char *zLine, ShellState *p){ */ if( cli_strcmp(azCmd[0],"list")==0 ){ for(i=0; inSession; i++){ - oputf("%d %s\n", i, pAuxDb->aSession[i].zName); + sqlite3_fprintf(p->out, "%d %s\n", i, pAuxDb->aSession[i].zName); } }else @@ -10372,7 +10410,7 @@ static int do_meta_command(char *zLine, ShellState *p){ int i, v; for(i=1; iout, "%s: %d 0x%x\n", azArg[i], v, v); } } if( cli_strncmp(azArg[0]+9, "integer", n-9)==0 ){ @@ -10381,7 +10419,7 @@ static int do_meta_command(char *zLine, ShellState *p){ char zBuf[200]; v = integerValue(azArg[i]); sqlite3_snprintf(sizeof(zBuf),zBuf,"%s: %lld 0x%llx\n", azArg[i],v,v); - oputz(zBuf); + sqlite3_fputs(zBuf, p->out); } } }else @@ -10454,10 +10492,10 @@ static int do_meta_command(char *zLine, ShellState *p){ if( zAns==0 ) continue; k = 0; if( bVerbose>0 ){ - sputf(stdout, "%d: %s %s\n", tno, zOp, zSql); + sqlite3_fprintf(stdout, "%d: %s %s\n", tno, zOp, zSql); } if( cli_strcmp(zOp,"memo")==0 ){ - oputf("%s\n", zSql); + sqlite3_fprintf(p->out, "%s\n", zSql); }else if( cli_strcmp(zOp,"run")==0 ){ char *zErrMsg = 0; @@ -10466,18 +10504,18 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_exec(p->db, zSql, captureOutputCallback, &str, &zErrMsg); nTest++; if( bVerbose ){ - oputf("Result: %s\n", str.z); + sqlite3_fprintf(p->out, "Result: %s\n", str.z); } if( rc || zErrMsg ){ nErr++; rc = 1; - oputf("%d: error-code-%d: %s\n", tno, rc, zErrMsg); + sqlite3_fprintf(p->out, "%d: error-code-%d: %s\n", tno, rc, zErrMsg); sqlite3_free(zErrMsg); }else if( cli_strcmp(zAns,str.z)!=0 ){ nErr++; rc = 1; - oputf("%d: Expected: [%s]\n", tno, zAns); - oputf("%d: Got: [%s]\n", tno, str.z); + sqlite3_fprintf(p->out, "%d: Expected: [%s]\n", tno, zAns); + sqlite3_fprintf(p->out, "%d: Got: [%s]\n", tno, str.z); } } else{ @@ -10489,7 +10527,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_finalize(pStmt); } /* End loop over k */ freeText(&str); - oputf("%d errors out of %d tests\n", nErr, nTest); + sqlite3_fprintf(p->out, "%d errors out of %d tests\n", nErr, nTest); }else if( c=='s' && cli_strncmp(azArg[0], "separator", n)==0 ){ @@ -10615,7 +10653,7 @@ static int do_meta_command(char *zLine, ShellState *p){ freeText(&sQuery); freeText(&sSql); if( bDebug ){ - oputf("%s\n", zSql); + sqlite3_fprintf(p->out, "%s\n", zSql); }else{ shell_exec(p, zSql, 0); } @@ -10645,7 +10683,7 @@ static int do_meta_command(char *zLine, ShellState *p){ "' OR ') as query, tname from tabcols group by tname)" , zRevText); shell_check_oom(zRevText); - if( bDebug ) oputf("%s\n", zRevText); + if( bDebug ) sqlite3_fprintf(p->out, "%s\n", zRevText); lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0); if( lrc!=SQLITE_OK ){ /* assert(lrc==SQLITE_NOMEM); // might also be SQLITE_ERROR if the @@ -10658,7 +10696,7 @@ static int do_meta_command(char *zLine, ShellState *p){ const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0); sqlite3_stmt *pCheckStmt; lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0); - if( bDebug ) oputf("%s\n", zGenQuery); + if( bDebug ) sqlite3_fprintf(p->out, "%s\n", zGenQuery); if( lrc!=SQLITE_OK ){ rc = 1; }else{ @@ -10717,46 +10755,46 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; goto meta_command_exit; } - oputf("%12.12s: %s\n","echo", + sqlite3_fprintf(p->out, "%12.12s: %s\n","echo", azBool[ShellHasFlag(p, SHFLG_Echo)]); - oputf("%12.12s: %s\n","eqp", azBool[p->autoEQP&3]); - oputf("%12.12s: %s\n","explain", + sqlite3_fprintf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]); + sqlite3_fprintf(p->out, "%12.12s: %s\n","explain", p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off"); - oputf("%12.12s: %s\n","headers", azBool[p->showHeader!=0]); + sqlite3_fprintf(p->out, "%12.12s: %s\n","headers", azBool[p->showHeader!=0]); if( p->mode==MODE_Column || (p->mode>=MODE_Markdown && p->mode<=MODE_Box) ){ - oputf("%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode", + sqlite3_fprintf(p->out, "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode", modeDescr[p->mode], p->cmOpts.iWrap, p->cmOpts.bWordWrap ? "on" : "off", p->cmOpts.bQuote ? "" : "no"); }else{ - oputf("%12.12s: %s\n","mode", modeDescr[p->mode]); + sqlite3_fprintf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]); } - oputf("%12.12s: ", "nullvalue"); - output_c_string(p->nullValue); - oputz("\n"); - oputf("%12.12s: %s\n","output", + sqlite3_fprintf(p->out, "%12.12s: ", "nullvalue"); + output_c_string(p->out, p->nullValue); + sqlite3_fputs("\n", p->out); + sqlite3_fprintf(p->out, "%12.12s: %s\n","output", strlen30(p->outfile) ? p->outfile : "stdout"); - oputf("%12.12s: ", "colseparator"); - output_c_string(p->colSeparator); - oputz("\n"); - oputf("%12.12s: ", "rowseparator"); - output_c_string(p->rowSeparator); - oputz("\n"); + sqlite3_fprintf(p->out, "%12.12s: ", "colseparator"); + output_c_string(p->out, p->colSeparator); + sqlite3_fputs("\n", p->out); + sqlite3_fprintf(p->out, "%12.12s: ", "rowseparator"); + output_c_string(p->out, p->rowSeparator); + sqlite3_fputs("\n", p->out); switch( p->statsOn ){ case 0: zOut = "off"; break; default: zOut = "on"; break; case 2: zOut = "stmt"; break; case 3: zOut = "vmstep"; break; } - oputf("%12.12s: %s\n","stats", zOut); - oputf("%12.12s: ", "width"); + sqlite3_fprintf(p->out, "%12.12s: %s\n","stats", zOut); + sqlite3_fprintf(p->out, "%12.12s: ", "width"); for (i=0;inWidth;i++) { - oputf("%d ", p->colWidth[i]); + sqlite3_fprintf(p->out, "%d ", p->colWidth[i]); } - oputz("\n"); - oputf("%12.12s: %s\n", "filename", + sqlite3_fputs("\n", p->out); + sqlite3_fprintf(p->out, "%12.12s: %s\n", "filename", p->pAuxDb->zDbFilename ? p->pAuxDb->zDbFilename : ""); }else @@ -10874,9 +10912,9 @@ static int do_meta_command(char *zLine, ShellState *p){ for(i=0; iout, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:""); } - oputz("\n"); + sqlite3_fputs("\n", p->out); } } @@ -10952,10 +10990,10 @@ static int do_meta_command(char *zLine, ShellState *p){ /* --help lists all test-controls */ if( cli_strcmp(zCmd,"help")==0 ){ - oputz("Available test-controls:\n"); + sqlite3_fputs("Available test-controls:\n", p->out); for(i=0; iout, " .testctrl %s %s\n", aCtrl[i].zCtrlName, aCtrl[i].zUsage); } rc = 1; @@ -11078,16 +11116,16 @@ static int do_meta_command(char *zLine, ShellState *p){ curOpt = ~newOpt; } if( newOpt==0 ){ - oputz("+All\n"); + sqlite3_fputs("+All\n", p->out); }else if( newOpt==0xffffffff ){ - oputz("-All\n"); + sqlite3_fputs("-All\n", p->out); }else{ int jj; for(jj=0; jjout, "%c%s\n", (newOpt & m)==0 ? '+' : '-', aLabel[jj].zLabel); } } @@ -11131,7 +11169,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3 *db; if( ii==0 && cli_strcmp(azArg[2],"random")==0 ){ sqlite3_randomness(sizeof(ii),&ii); - sputf(stdout, "-- random seed: %d\n", ii); + sqlite3_fprintf(stdout, "-- random seed: %d\n", ii); } if( nArg==3 ){ db = 0; @@ -11199,7 +11237,7 @@ static int do_meta_command(char *zLine, ShellState *p){ case SQLITE_TESTCTRL_SEEK_COUNT: { u64 x = 0; rc2 = sqlite3_test_control(testctrl, p->db, &x); - oputf("%llu\n", x); + sqlite3_fprintf(p->out, "%llu\n", x); isOk = 3; break; } @@ -11230,11 +11268,11 @@ static int do_meta_command(char *zLine, ShellState *p){ int val = 0; rc2 = sqlite3_test_control(testctrl, -id, &val); if( rc2!=SQLITE_OK ) break; - if( id>1 ) oputz(" "); - oputf("%d: %d", id, val); + if( id>1 ) sqlite3_fputs(" ", p->out); + sqlite3_fprintf(p->out, "%d: %d", id, val); id++; } - if( id>1 ) oputz("\n"); + if( id>1 ) sqlite3_fputs("\n", p->out); isOk = 3; } break; @@ -11276,14 +11314,22 @@ static int do_meta_command(char *zLine, ShellState *p){ faultsim_state.nHit = 0; sqlite3_test_control(testctrl, faultsim_callback); }else if( cli_strcmp(z,"status")==0 ){ - oputf("faultsim.iId: %d\n", faultsim_state.iId); - oputf("faultsim.iErr: %d\n", faultsim_state.iErr); - oputf("faultsim.iCnt: %d\n", faultsim_state.iCnt); - oputf("faultsim.nHit: %d\n", faultsim_state.nHit); - oputf("faultsim.iInterval: %d\n", faultsim_state.iInterval); - oputf("faultsim.eVerbose: %d\n", faultsim_state.eVerbose); - oputf("faultsim.nRepeat: %d\n", faultsim_state.nRepeat); - oputf("faultsim.nSkip: %d\n", faultsim_state.nSkip); + sqlite3_fprintf(p->out, "faultsim.iId: %d\n", + faultsim_state.iId); + sqlite3_fprintf(p->out, "faultsim.iErr: %d\n", + faultsim_state.iErr); + sqlite3_fprintf(p->out, "faultsim.iCnt: %d\n", + faultsim_state.iCnt); + sqlite3_fprintf(p->out, "faultsim.nHit: %d\n", + faultsim_state.nHit); + sqlite3_fprintf(p->out, "faultsim.iInterval: %d\n", + faultsim_state.iInterval); + sqlite3_fprintf(p->out, "faultsim.eVerbose: %d\n", + faultsim_state.eVerbose); + sqlite3_fprintf(p->out, "faultsim.nRepeat: %d\n", + faultsim_state.nRepeat); + sqlite3_fprintf(p->out, "faultsim.nSkip: %d\n", + faultsim_state.nSkip); }else if( cli_strcmp(z,"-v")==0 ){ if( faultsim_state.eVerbose<2 ) faultsim_state.eVerbose++; }else if( cli_strcmp(z,"-q")==0 ){ @@ -11309,7 +11355,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } } if( bShowHelp ){ - oputz( + sqlite3_fputs( "Usage: .testctrl fault_install ARGS\n" "Possible arguments:\n" " off Disable faultsim\n" @@ -11323,6 +11369,7 @@ static int do_meta_command(char *zLine, ShellState *p){ " --interval N Trigger only after every N-th call\n" " --repeat N Turn off after N hits. 0 means never\n" " --skip N Skip the first N encounters\n" + ,p->out ); } break; @@ -11330,12 +11377,13 @@ static int do_meta_command(char *zLine, ShellState *p){ } } if( isOk==0 && iCtrl>=0 ){ - oputf("Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); + sqlite3_fprintf(p->out, + "Usage: .testctrl %s %s\n", zCmd,aCtrl[iCtrl].zUsage); rc = 1; }else if( isOk==1 ){ - oputf("%d\n", rc2); + sqlite3_fprintf(p->out, "%d\n", rc2); }else if( isOk==2 ){ - oputf("0x%08x\n", rc2); + sqlite3_fprintf(p->out, "0x%08x\n", rc2); } }else #endif /* !defined(SQLITE_UNTESTABLE) */ @@ -11498,21 +11546,21 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='v' && cli_strncmp(azArg[0], "version", n)==0 ){ char *zPtrSz = sizeof(void*)==8 ? "64-bit" : "32-bit"; - oputf("SQLite %s %s\n" /*extra-version-info*/, + sqlite3_fprintf(p->out, "SQLite %s %s\n" /*extra-version-info*/, sqlite3_libversion(), sqlite3_sourceid()); #if SQLITE_HAVE_ZLIB - oputf("zlib version %s\n", zlibVersion()); + sqlite3_fprintf(p->out, "zlib version %s\n", zlibVersion()); #endif #define CTIMEOPT_VAL_(opt) #opt #define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt) #if defined(__clang__) && defined(__clang_major__) - oputf("clang-" CTIMEOPT_VAL(__clang_major__) "." + sqlite3_fprintf(p->out, "clang-" CTIMEOPT_VAL(__clang_major__) "." CTIMEOPT_VAL(__clang_minor__) "." CTIMEOPT_VAL(__clang_patchlevel__) " (%s)\n", zPtrSz); #elif defined(_MSC_VER) - oputf("msvc-" CTIMEOPT_VAL(_MSC_VER) " (%s)\n", zPtrSz); + sqlite3_fprintf(p->out, "msvc-" CTIMEOPT_VAL(_MSC_VER) " (%s)\n", zPtrSz); #elif defined(__GNUC__) && defined(__VERSION__) - oputf("gcc-" __VERSION__ " (%s)\n", zPtrSz); + sqlite3_fprintf(p->out, "gcc-" __VERSION__ " (%s)\n", zPtrSz); #endif }else @@ -11522,10 +11570,10 @@ static int do_meta_command(char *zLine, ShellState *p){ if( p->db ){ sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFS_POINTER, &pVfs); if( pVfs ){ - oputf("vfs.zName = \"%s\"\n", pVfs->zName); - oputf("vfs.iVersion = %d\n", pVfs->iVersion); - oputf("vfs.szOsFile = %d\n", pVfs->szOsFile); - oputf("vfs.mxPathname = %d\n", pVfs->mxPathname); + sqlite3_fprintf(p->out, "vfs.zName = \"%s\"\n", pVfs->zName); + sqlite3_fprintf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion); + sqlite3_fprintf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile); + sqlite3_fprintf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname); } } }else @@ -11537,13 +11585,13 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_file_control(p->db, "main", SQLITE_FCNTL_VFS_POINTER, &pCurrent); } for(pVfs=sqlite3_vfs_find(0); pVfs; pVfs=pVfs->pNext){ - oputf("vfs.zName = \"%s\"%s\n", pVfs->zName, + sqlite3_fprintf(p->out, "vfs.zName = \"%s\"%s\n", pVfs->zName, pVfs==pCurrent ? " <--- CURRENT" : ""); - oputf("vfs.iVersion = %d\n", pVfs->iVersion); - oputf("vfs.szOsFile = %d\n", pVfs->szOsFile); - oputf("vfs.mxPathname = %d\n", pVfs->mxPathname); + sqlite3_fprintf(p->out, "vfs.iVersion = %d\n", pVfs->iVersion); + sqlite3_fprintf(p->out, "vfs.szOsFile = %d\n", pVfs->szOsFile); + sqlite3_fprintf(p->out, "vfs.mxPathname = %d\n", pVfs->mxPathname); if( pVfs->pNext ){ - oputz("-----------------------------------\n"); + sqlite3_fputs("-----------------------------------\n", p->out); } } }else @@ -11554,7 +11602,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( p->db ){ sqlite3_file_control(p->db, zDbName, SQLITE_FCNTL_VFSNAME, &zVfsName); if( zVfsName ){ - oputf("%s\n", zVfsName); + sqlite3_fprintf(p->out, "%s\n", zVfsName); sqlite3_free(zVfsName); } } @@ -11863,7 +11911,7 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ sqlite3_snprintf(sizeof(zLineBuf), zLineBuf, "changes: %lld total_changes: %lld", sqlite3_changes64(p->db), sqlite3_total_changes64(p->db)); - oputf("%s\n", zLineBuf); + sqlite3_fprintf(p->out, "%s\n", zLineBuf); } if( doAutoDetectRestore(p, zSql) ) return 1; @@ -11871,7 +11919,7 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ } static void echo_group_input(ShellState *p, const char *zDo){ - if( ShellHasFlag(p, SHFLG_Echo) ) oputf("%s\n", zDo); + if( ShellHasFlag(p, SHFLG_Echo) ) sqlite3_fprintf(p->out, "%s\n", zDo); } #ifdef SQLITE_SHELL_FIDDLE @@ -11941,7 +11989,7 @@ static int process_input(ShellState *p){ zLine = one_input_line(p->in, zLine, nSql>0); if( zLine==0 ){ /* End of input */ - if( p->in==0 && stdin_is_interactive ) oputz("\n"); + if( p->in==0 && stdin_is_interactive ) sqlite3_fputs("\n", p->out); break; } if( seenInterrupt ){ @@ -12308,7 +12356,7 @@ static void printBold(const char *zText){ } #else static void printBold(const char *zText){ - sputf(stdout, "\033[1m%s\033[0m", zText); + sqlite3_fprintf(stdout, "\033[1m%s\033[0m", zText); } #endif @@ -12765,7 +12813,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ }else if( cli_strcmp(z,"-bail")==0 ){ /* No-op. The bail_on_error flag should already be set. */ }else if( cli_strcmp(z,"-version")==0 ){ - sputf(stdout, "%s %s (%d-bit)\n", + sqlite3_fprintf(stdout, "%s %s (%d-bit)\n", sqlite3_libversion(), sqlite3_sourceid(), 8*(int)sizeof(char*)); return 0; }else if( cli_strcmp(z,"-interactive")==0 ){ @@ -12901,7 +12949,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #else # define SHELL_CIO_CHAR_SET "" #endif - sputf(stdout, "SQLite version %s %.19s%s\n" /*extra-version-info*/ + sqlite3_fprintf(stdout, "SQLite version %s %.19s%s\n" /*extra-version-info*/ "Enter \".help\" for usage hints.\n", sqlite3_libversion(), sqlite3_sourceid(), SHELL_CIO_CHAR_SET); if( warnInmemoryDb ){ @@ -13017,7 +13065,7 @@ sqlite3_vfs * fiddle_db_vfs(const char *zDbName){ /* Only for emcc experimentation purposes. */ sqlite3 * fiddle_db_arg(sqlite3 *arg){ - oputf("fiddle_db_arg(%p)\n", (const void*)arg); + sqlite3_fprintf(p->out, "fiddle_db_arg(%p)\n", (const void*)arg); return arg; } @@ -13054,7 +13102,7 @@ void fiddle_reset_db(void){ ** Resolve problem reported in ** https://sqlite.org/forum/forumpost/0b41a25d65 */ - oputz("Rolling back in-progress transaction.\n"); + sqlite3_fputs("Rolling back in-progress transaction.\n", stdout); sqlite3_exec(globalDb,"ROLLBACK", 0, 0, 0); } rc = sqlite3_db_config(globalDb, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0); From a55901a27cf3de084c906466f0e126e76be0de64 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 17:40:54 +0000 Subject: [PATCH 15/50] Port sqldiff over to use sqlite3_stdio. FossilOrigin-Name: 18f784c47d4252bc3696a7e084a1afb9f51f006cf2021292f2103531b8235226 --- Makefile.in | 4 +- Makefile.msc | 4 +- ext/misc/sqlite3_stdio.c | 19 ++++- ext/misc/sqlite3_stdio.h | 3 + main.mk | 4 +- manifest | 22 +++--- manifest.uuid | 2 +- tool/sqldiff.c | 150 ++++++++++++++++++--------------------- 8 files changed, 106 insertions(+), 102 deletions(-) diff --git a/Makefile.in b/Makefile.in index 5abe3bf6d3..6fc821da23 100644 --- a/Makefile.in +++ b/Makefile.in @@ -694,8 +694,8 @@ sqlite3$(TEXE): shell.c sqlite3.c shell.c sqlite3.c \ $(LIBREADLINE) $(TLIBS) -rpath "$(libdir)" -sqldiff$(TEXE): $(TOP)/tool/sqldiff.c sqlite3.lo sqlite3.h - $(LTLINK) -o $@ $(TOP)/tool/sqldiff.c sqlite3.lo $(TLIBS) +sqldiff$(TEXE): $(TOP)/tool/sqldiff.c $(TOP)/ext/misc/sqlite3_stdio.h sqlite3.lo sqlite3.h + $(LTLINK) -I$(TOP)/ext/misc -o $@ $(TOP)/tool/sqldiff.c sqlite3.lo $(TLIBS) dbhash$(TEXE): $(TOP)/tool/dbhash.c sqlite3.lo sqlite3.h $(LTLINK) -o $@ $(TOP)/tool/dbhash.c sqlite3.lo $(TLIBS) diff --git a/Makefile.msc b/Makefile.msc index be6a771639..cc0285bb2c 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -1861,8 +1861,8 @@ $(SQLITE3EXE): shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLIT /link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS) # <> -sqldiff.exe: $(TOP)\tool\sqldiff.c $(TOP)\ext\consio\console_io.h $(TOP)\ext\consio\console_io.c $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS) - $(LTLINK) $(NO_WARN) -I$(TOP)\ext\consio $(TOP)\tool\sqldiff.c $(TOP)\ext\consio\console_io.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) $(LIBRESOBJS) +sqldiff.exe: $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.h $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE3C) $(SQLITE3H) $(LIBRESOBJS) + $(LTLINK) $(NO_WARN) -I$(TOP)\ext\misc $(TOP)\tool\sqldiff.c $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) $(LIBRESOBJS) dbhash.exe: $(TOP)\tool\dbhash.c $(SQLITE3C) $(SQLITE3H) $(LTLINK) $(NO_WARN) $(TOP)\tool\dbhash.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS) diff --git a/ext/misc/sqlite3_stdio.c b/ext/misc/sqlite3_stdio.c index 0cfa26673a..6b7beff4e6 100644 --- a/ext/misc/sqlite3_stdio.c +++ b/ext/misc/sqlite3_stdio.c @@ -14,6 +14,19 @@ ** on Windows. */ #ifdef _WIN32 /* This file is a no-op on all platforms except Windows */ +#include "sqlite3_stdio.h" +#undef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include +#include "sqlite3.h" +#include +#include +#include +#include /* ** Work-alike for the fopen() routine from the standard C library. @@ -68,7 +81,7 @@ FILE *sqlite3_popen(const char *zCommand, const char *zMode){ ** Work-alike for fgets() from the standard C library. */ char *sqlite3_fgets(char *buf, int sz, FILE *in){ - if( isatty(_fileno(in)) ){ + if( _isatty(_fileno(in)) ){ /* When reading from the command-prompt in Windows, it is necessary ** to use _O_WTEXT input mode to read UTF-16 characters, then translate ** that into UTF-8. Otherwise, non-ASCII characters all get translated @@ -95,7 +108,7 @@ char *sqlite3_fgets(char *buf, int sz, FILE *in){ ** Work-alike for fputs() from the standard C library. */ int sqlite3_fputs(const char *z, FILE *out){ - if( isatty(_fileno(out)) ){ + if( _isatty(_fileno(out)) ){ /* When writing to the command-prompt in Windows, it is necessary ** to use _O_WTEXT input mode and write UTF-16 characters. */ @@ -121,7 +134,7 @@ int sqlite3_fputs(const char *z, FILE *out){ */ int sqlite3_fprintf(FILE *out, const char *zFormat, ...){ int rc; - if( isatty(fileno(out)) ){ + if( _isatty(fileno(out)) ){ /* When writing to the command-prompt in Windows, it is necessary ** to use _O_WTEXT input mode and write UTF-16 characters. */ diff --git a/ext/misc/sqlite3_stdio.h b/ext/misc/sqlite3_stdio.h index 3014c1b287..dd0eefad04 100644 --- a/ext/misc/sqlite3_stdio.h +++ b/ext/misc/sqlite3_stdio.h @@ -26,6 +26,8 @@ ** also link in the accompanying sqlite3_stdio.c source file when compiling ** to get compatible interfaces. */ +#ifndef _SQLITE3_STDIO_H_ +#define _SQLITE3_STDIO_H_ 1 #ifdef _WIN32 /**** Definitions For Windows ****/ #include @@ -50,3 +52,4 @@ void sqlite3_fsetmode(FILE *stream, int mode); #define sqlite3_fsetmode(F,X) /*no-op*/ #endif +#endif /* _SQLITE3_STDIO_H_ */ diff --git a/main.mk b/main.mk index 2d616a6167..f0f41736d1 100644 --- a/main.mk +++ b/main.mk @@ -560,8 +560,8 @@ sqlite3$(EXE): sqlite3.h libsqlite3.a shell.c $(TCCX) $(READLINE_FLAGS) -o sqlite3$(EXE) $(SHELL_OPT) \ shell.c libsqlite3.a $(LIBREADLINE) $(TLIBS) $(THREADLIB) -sqldiff$(EXE): $(TOP)/tool/sqldiff.c sqlite3.c sqlite3.h - $(TCCX) -o sqldiff$(EXE) -DSQLITE_THREADSAFE=0 \ +sqldiff$(EXE): $(TOP)/tool/sqldiff.c $(TOP)/ext/misc/sqlite3_stdio.h sqlite3.c sqlite3.h + $(TCCX) -I$(TOP)/ext/misc -o sqldiff$(EXE) -DSQLITE_THREADSAFE=0 \ $(TOP)/tool/sqldiff.c sqlite3.c $(TLIBS) $(THREADLIB) dbhash$(EXE): $(TOP)/tool/dbhash.c sqlite3.c sqlite3.h diff --git a/manifest b/manifest index 5e7518fc0c..728db2c94e 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Get\soutput\sredirection\sworking\sagain\sin\sthe\sCLI. -D 2024-09-24T16:09:50.466 +C Port\ssqldiff\sover\sto\suse\ssqlite3_stdio. +D 2024-09-24T17:40:54.086 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 -F Makefile.in a8e1d44a1166b6fb368effb19edc9adf7fede9225e9563352b9bb1989cd0150d +F Makefile.in 6a826facc78c3c8ad38bf00ed588f6aa3665ccd7a9749b891d20582fc290c77e F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc 1a5234794c9a5a71ba13fb47bcf031814d45b3ed6a56b4cb8e9f63fd32b4febe +F Makefile.msc 10fcf3b1eff1859846878469ffad1ebcd168fa0bd9e8a81f76ce65465b79e35d F README.md c3c0f19532ce28f6297a71870f3c7b424729f0e6d9ab889616d3587dd2332159 F VERSION 0db40f92c04378404eb45bff93e9e42c148c7e54fd3da99469ed21e22411f5a6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -425,8 +425,8 @@ F ext/misc/shathree.c 1821d90a0040c9accdbe3e3527d378d30569475d758aa70f6848924c0b F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c c0aa7b80d6df45f7da59d912b38752bcac1af53a5766966160e6c5cdd397dbea F ext/misc/sqlar.c a6175790482328171da47095f87608b48a476d4fac78d8a9ff18b03a2454f634 -F ext/misc/sqlite3_stdio.c 4d4190eac193a8ea8fc3f8259e0996cf8e54254b4f4925d71e456e88165401d8 -F ext/misc/sqlite3_stdio.h ddefddeb448eee7fe2d41a828356a0019f813a4ced4ea2e97faa1d6c3e803742 +F ext/misc/sqlite3_stdio.c d9c7b3883788ef6e15134323783d6a3c69d2b453545a2aa60d8a3503bfeadcb7 +F ext/misc/sqlite3_stdio.h f05eaf5e0258f0573910324a789a9586fc360a57678c57a6d63cfaa2245b6176 F ext/misc/stmt.c b090086cd6bd6281c21271d38d576eeffe662f0e6b67536352ce32bbaa438321 F ext/misc/stmtrand.c 59cffa5d8e158943ff1ce078956d8e208e8c04e67307e8f249dece2436dcb7fc F ext/misc/templatevtab.c 10f15b165b95423ddef593bc5dcb915ec4eb5e0f1066d585e5435a368b8bc22b @@ -689,7 +689,7 @@ F ext/wasm/wasmfs.make 8a4955882aaa0783b3f60a9484a1f0f3d8b6f775c0fcd17c082f31966 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 -F main.mk dcb5cbba0ad64bd639b3e05d73d92e27c144a55bab9fca3460699602f4e9f4c2 +F main.mk 0a55ebec3508ca1bdb593d86f3aa19d7fa42a2ddd3220703e6dc0a65f1338a43 F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271 F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504 F mptest/crash01.test 61e61469e257df0850df4293d7d4d6c2af301421 @@ -2175,7 +2175,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 7ce07da76b5e745783e703a834417d725b7d45fd F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d40618 x F tool/split-sqlite3c.tcl 5aa60643afca558bc732b1444ae81a522326f91e1dc5665b369c54f09e20de60 -F tool/sqldiff.c 847fc8fcfddf5ce4797b7394cad6372f2f5dc17d8186e2ef8fb44d50fae4f44a +F tool/sqldiff.c 2a0987d183027c795ced13d6749061c1d2f38e24eddb428f56fa64c3a8f51e4b F tool/sqlite3-rsync.c 187b262035c1159b047dbfa1959c168b87b5a153b63465e8c8bd1b54fabf4460 F tool/sqlite3_analyzer.c.in 8da2b08f56eeac331a715036cf707cc20f879f231362be0c22efd682e2b89b4f F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fcd0ecffc9889f8c855ea340f075ec42cdca482df82d6e67dc9c32613e8d5846 -R bfd2b7dbaf4f82e5e4b17d1ed0ea1a8f +P 086034c3508d95e4f620c5e0580fae770e85410b0c8bd94f600fc0fd25088947 +R d688762d4b1334b98cdf41bc1c1c4c96 U drh -Z 5097f278634497c50b8747316810c634 +Z 9855069890c5f74ec21934036ad0fa9f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ad785fcbcd..f7119b107e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -086034c3508d95e4f620c5e0580fae770e85410b0c8bd94f600fc0fd25088947 +18f784c47d4252bc3696a7e084a1afb9f51f006cf2021292f2103531b8235226 diff --git a/tool/sqldiff.c b/tool/sqldiff.c index 8b2293cafd..bb26daf139 100644 --- a/tool/sqldiff.c +++ b/tool/sqldiff.c @@ -14,7 +14,7 @@ ** between two SQLite databases. ** ** To compile, simply link against SQLite. (Windows builds must also link -** against ext/consio/console_io.c.) +** against ext/misc/sqlite3_stdio.c.) ** ** See the showHelp() routine below for a brief description of how to ** run the utility. @@ -26,19 +26,7 @@ #include #include #include "sqlite3.h" - -/* Output function substitutions that cause UTF8 characters to be rendered -** correctly on Windows: -** -** fprintf() -> Wfprintf() -** -*/ -#if defined(_WIN32) -# include "console_io.h" -# define Wfprintf fPrintfUtf8 -#else -# define Wfprintf fprintf -#endif +#include "sqlite3_stdio.h" /* ** All global variables are gathered into the "g" singleton. @@ -76,9 +64,9 @@ static void cmdlineError(const char *zFormat, ...){ va_start(ap, zFormat); sqlite3_str_vappendf(pOut, zFormat, ap); va_end(ap); - Wfprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut)); + sqlite3_fprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut)); strFree(pOut); - Wfprintf(stderr, "\"%s --help\" for more help\n", g.zArgv0); + sqlite3_fprintf(stderr, "\"%s --help\" for more help\n", g.zArgv0); exit(1); } @@ -92,7 +80,7 @@ static void runtimeError(const char *zFormat, ...){ va_start(ap, zFormat); sqlite3_str_vappendf(pOut, zFormat, ap); va_end(ap); - Wfprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut)); + sqlite3_fprintf(stderr, "%s: %s\n", g.zArgv0, sqlite3_str_value(pOut)); strFree(pOut); exit(1); } @@ -349,11 +337,11 @@ static void printQuoted(FILE *out, sqlite3_value *X){ char zBuf[50]; r1 = sqlite3_value_double(X); sqlite3_snprintf(sizeof(zBuf), zBuf, "%!.15g", r1); - fprintf(out, "%s", zBuf); + sqlite3_fprintf(out, "%s", zBuf); break; } case SQLITE_INTEGER: { - fprintf(out, "%lld", sqlite3_value_int64(X)); + sqlite3_fprintf(out, "%lld", sqlite3_value_int64(X)); break; } case SQLITE_BLOB: { @@ -361,14 +349,14 @@ static void printQuoted(FILE *out, sqlite3_value *X){ int nBlob = sqlite3_value_bytes(X); if( zBlob ){ int i; - fprintf(out, "x'"); + sqlite3_fprintf(out, "x'"); for(i=0; iinctl ){ inctl = ctl; - fprintf(out, "%.*s'||X'%02x", i-j, &zArg[j], c); + sqlite3_fprintf(out, "%.*s'||X'%02x", i-j, &zArg[j], c); j = i+1; }else if( ctl ){ - fprintf(out, "%02x", c); + sqlite3_fprintf(out, "%02x", c); j = i+1; }else{ if( inctl ){ inctl = 0; - fprintf(out, "'\n||'"); + sqlite3_fprintf(out, "'\n||'"); } if( c=='\'' ){ - fprintf(out, "%.*s'", i-j+1, &zArg[j]); + sqlite3_fprintf(out, "%.*s'", i-j+1, &zArg[j]); j = i+1; } } } - fprintf(out, "%s'", &zArg[j]); + sqlite3_fprintf(out, "%s'", &zArg[j]); } break; } case SQLITE_NULL: { - fprintf(out, "NULL"); + sqlite3_fprintf(out, "NULL"); break; } } @@ -428,7 +416,7 @@ static void dump_table(const char *zTab, FILE *out){ pStmt = db_prepare("SELECT sql FROM aux.sqlite_schema WHERE name=%Q", zTab); if( SQLITE_ROW==sqlite3_step(pStmt) ){ - fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0)); + sqlite3_fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0)); } sqlite3_finalize(pStmt); if( !g.bSchemaOnly ){ @@ -463,14 +451,14 @@ static void dump_table(const char *zTab, FILE *out){ } nCol = sqlite3_column_count(pStmt); while( SQLITE_ROW==sqlite3_step(pStmt) ){ - Wfprintf(out, "%s",sqlite3_str_value(pIns)); + sqlite3_fprintf(out, "%s",sqlite3_str_value(pIns)); zSep = "("; for(i=0; i0 ) fprintf(out, ", "); + if( i>0 ) sqlite3_fprintf(out, ", "); printQuoted(out, sqlite3_column_value(pStmt, i)); } }else{ @@ -1320,9 +1308,9 @@ static void rbudiff_one_table(const char *zTab, FILE *out){ nDelta = rbuDeltaCreate(aSrc, nSrc, aFinal, nFinal, aDelta); if( nDelta Date: Tue, 24 Sep 2024 17:49:06 +0000 Subject: [PATCH 16/50] Port sqlite3_analyzer.exe to use sqlite3_stdio. FossilOrigin-Name: 7c1c1226d803dbaf8e75085b1cc2aad88aef4c3168288e587c8c736633d09054 --- Makefile.msc | 2 +- ext/misc/sqlite3_stdio.c | 2 ++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- tool/sqlite3_analyzer.c.in | 8 ++++---- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Makefile.msc b/Makefile.msc index cc0285bb2c..60669993c1 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -2624,7 +2624,7 @@ smoketest: $(TESTPROGS) shelltest: $(TESTPROGS) .\testfixture.exe $(TOP)\test\permutations.test shell -sqlite3_analyzer.c: $(SQLITE3C) $(SQLITE3H) $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl $(TOP)\tool\mkccode.tcl $(TOP)\tool\sqlite3_analyzer.c.in $(TOP)\ext\consio\console_io.h $(TOP)\ext\consio\console_io.c $(SQLITE_TCL_DEP) +sqlite3_analyzer.c: $(SQLITE3C) $(SQLITE3H) $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl $(TOP)\tool\mkccode.tcl $(TOP)\tool\sqlite3_analyzer.c.in $(TOP)\ext\misc\sqlite3_stdio.h $(TOP)\ext\misc\sqlite3_stdio.c $(SQLITE_TCL_DEP) $(TCLSH_CMD) $(TOP)\tool\mkccode.tcl $(TOP)\tool\sqlite3_analyzer.c.in > $@ sqlite3_analyzer.exe: sqlite3_analyzer.c $(LIBRESOBJS) diff --git a/ext/misc/sqlite3_stdio.c b/ext/misc/sqlite3_stdio.c index 6b7beff4e6..5447faadf7 100644 --- a/ext/misc/sqlite3_stdio.c +++ b/ext/misc/sqlite3_stdio.c @@ -14,7 +14,9 @@ ** on Windows. */ #ifdef _WIN32 /* This file is a no-op on all platforms except Windows */ +#ifndef _SQLITE3_STDIO_H_ #include "sqlite3_stdio.h" +#endif #undef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #include diff --git a/manifest b/manifest index 728db2c94e..4679c11a96 100644 --- a/manifest +++ b/manifest @@ -1,11 +1,11 @@ -C Port\ssqldiff\sover\sto\suse\ssqlite3_stdio. -D 2024-09-24T17:40:54.086 +C Port\ssqlite3_analyzer.exe\sto\suse\ssqlite3_stdio. +D 2024-09-24T17:49:06.245 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F Makefile.in 6a826facc78c3c8ad38bf00ed588f6aa3665ccd7a9749b891d20582fc290c77e F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6 -F Makefile.msc 10fcf3b1eff1859846878469ffad1ebcd168fa0bd9e8a81f76ce65465b79e35d +F Makefile.msc 9c6d80d9d103fa42e931f4c464884a5e577fae8563acc7589bff4e43fbe8f864 F README.md c3c0f19532ce28f6297a71870f3c7b424729f0e6d9ab889616d3587dd2332159 F VERSION 0db40f92c04378404eb45bff93e9e42c148c7e54fd3da99469ed21e22411f5a6 F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50 @@ -425,7 +425,7 @@ F ext/misc/shathree.c 1821d90a0040c9accdbe3e3527d378d30569475d758aa70f6848924c0b F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c c0aa7b80d6df45f7da59d912b38752bcac1af53a5766966160e6c5cdd397dbea F ext/misc/sqlar.c a6175790482328171da47095f87608b48a476d4fac78d8a9ff18b03a2454f634 -F ext/misc/sqlite3_stdio.c d9c7b3883788ef6e15134323783d6a3c69d2b453545a2aa60d8a3503bfeadcb7 +F ext/misc/sqlite3_stdio.c aefcfaeefdee26eae2c0d94e41d3720d86b1dc5c96e70132366ab1e204f9ef92 F ext/misc/sqlite3_stdio.h f05eaf5e0258f0573910324a789a9586fc360a57678c57a6d63cfaa2245b6176 F ext/misc/stmt.c b090086cd6bd6281c21271d38d576eeffe662f0e6b67536352ce32bbaa438321 F ext/misc/stmtrand.c 59cffa5d8e158943ff1ce078956d8e208e8c04e67307e8f249dece2436dcb7fc @@ -2177,7 +2177,7 @@ F tool/spellsift.tcl 52b4b04dc4333c7ab024f09d9d66ed6b6f7c6eb00b38497a09f338fa55d F tool/split-sqlite3c.tcl 5aa60643afca558bc732b1444ae81a522326f91e1dc5665b369c54f09e20de60 F tool/sqldiff.c 2a0987d183027c795ced13d6749061c1d2f38e24eddb428f56fa64c3a8f51e4b F tool/sqlite3-rsync.c 187b262035c1159b047dbfa1959c168b87b5a153b63465e8c8bd1b54fabf4460 -F tool/sqlite3_analyzer.c.in 8da2b08f56eeac331a715036cf707cc20f879f231362be0c22efd682e2b89b4f +F tool/sqlite3_analyzer.c.in 348ba349bbdc93c9866439f9f935d7284866a2a4e6898bc906ae1204ade56918 F tool/sqltclsh.c.in 1bcc2e9da58fadf17b0bf6a50e68c1159e602ce057210b655d50bad5aaaef898 F tool/sqltclsh.tcl 862f4cf1418df5e1315b5db3b5ebe88969e2a784525af5fbf9596592f14ed848 F tool/src-verify.c 41c586dee84d0b190ad13e0282ed83d4a65ec9fefde9adf4943efdf6558eea7f @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 086034c3508d95e4f620c5e0580fae770e85410b0c8bd94f600fc0fd25088947 -R d688762d4b1334b98cdf41bc1c1c4c96 +P 18f784c47d4252bc3696a7e084a1afb9f51f006cf2021292f2103531b8235226 +R f37703682204a6532c10f65be42e5cd4 U drh -Z 9855069890c5f74ec21934036ad0fa9f +Z 64787aa4f9a8932f50b4106ef4d8ed62 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f7119b107e..c8fe7fce57 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -18f784c47d4252bc3696a7e084a1afb9f51f006cf2021292f2103531b8235226 +7c1c1226d803dbaf8e75085b1cc2aad88aef4c3168288e587c8c736633d09054 diff --git a/tool/sqlite3_analyzer.c.in b/tool/sqlite3_analyzer.c.in index 2d799ed250..1c9fc836a1 100644 --- a/tool/sqlite3_analyzer.c.in +++ b/tool/sqlite3_analyzer.c.in @@ -20,8 +20,8 @@ INCLUDE sqlite3.c INCLUDE $ROOT/src/tclsqlite.c #if defined(_WIN32) -INCLUDE $ROOT/ext/consio/console_io.h -INCLUDE $ROOT/ext/consio/console_io.c +INCLUDE $ROOT/ext/misc/sqlite3_stdio.h +INCLUDE $ROOT/ext/misc/sqlite3_stdio.c /* Substitute "puts" command. Only these forms recognized: ** @@ -56,8 +56,8 @@ static int subst_puts( return TCL_ERROR; } } - fPutsUtf8(zOut, pOut); - if( addNewLine ) fPutsUtf8("\n", pOut); + sqlite3_fputs(zOut, pOut); + if( addNewLine ) sqlite3_fputs("\n", pOut); return TCL_OK; } #endif /* defined(_WIN32) */ From 63558eae548343ad9990b48f4f0874404dc7d101 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 18:01:50 +0000 Subject: [PATCH 17/50] Get fiddle working again on this branch. FossilOrigin-Name: 0f228317c6ea1388d82df46f44c166b2aa9be63361ff9b81569ebee63c930f2e --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 4679c11a96..47bc7a854d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Port\ssqlite3_analyzer.exe\sto\suse\ssqlite3_stdio. -D 2024-09-24T17:49:06.245 +C Get\sfiddle\sworking\sagain\son\sthis\sbranch. +D 2024-09-24T18:01:50.659 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in b3b0aed1b1050da8d70734b1a4bdc4a4679a73f37b2593f276e5a5f71a6fca2a +F src/shell.c.in 2774f5af2edc468b272a14b3aec7f3c3c63bfe977f4db8c69a900433ec2b1e4f F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 18f784c47d4252bc3696a7e084a1afb9f51f006cf2021292f2103531b8235226 -R f37703682204a6532c10f65be42e5cd4 +P 7c1c1226d803dbaf8e75085b1cc2aad88aef4c3168288e587c8c736633d09054 +R c097c41ad97afac2d584ca3114783cc7 U drh -Z 64787aa4f9a8932f50b4106ef4d8ed62 +Z de72510160f83f54a6026486570e81b8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c8fe7fce57..a6d9dfda23 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c1c1226d803dbaf8e75085b1cc2aad88aef4c3168288e587c8c736633d09054 +0f228317c6ea1388d82df46f44c166b2aa9be63361ff9b81569ebee63c930f2e diff --git a/src/shell.c.in b/src/shell.c.in index 4c2ca65d83..4b799838da 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -13065,7 +13065,7 @@ sqlite3_vfs * fiddle_db_vfs(const char *zDbName){ /* Only for emcc experimentation purposes. */ sqlite3 * fiddle_db_arg(sqlite3 *arg){ - sqlite3_fprintf(p->out, "fiddle_db_arg(%p)\n", (const void*)arg); + sqlite3_fprintf(stdout, "fiddle_db_arg(%p)\n", (const void*)arg); return arg; } From 697c3fb25b521dd3b57de253b98cd17ca4dd4351 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 19:19:53 +0000 Subject: [PATCH 18/50] Fix error messages in the shell. FossilOrigin-Name: aeef82e974c24071e3211588001a92c7f122fbaf02d9dcf7fa5aaf30d2729f64 --- manifest | 12 +-- manifest.uuid | 2 +- src/shell.c.in | 238 +++++++++++++++++++++++++------------------------ 3 files changed, 127 insertions(+), 125 deletions(-) diff --git a/manifest b/manifest index 47bc7a854d..f7a7dc5ef4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Get\sfiddle\sworking\sagain\son\sthis\sbranch. -D 2024-09-24T18:01:50.659 +C Fix\serror\smessages\sin\sthe\sshell. +D 2024-09-24T19:19:53.992 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 2774f5af2edc468b272a14b3aec7f3c3c63bfe977f4db8c69a900433ec2b1e4f +F src/shell.c.in 38a38100356134f962b3f72e1e3a44da014dee4f044b81438273aa5b0b5e7469 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7c1c1226d803dbaf8e75085b1cc2aad88aef4c3168288e587c8c736633d09054 -R c097c41ad97afac2d584ca3114783cc7 +P 0f228317c6ea1388d82df46f44c166b2aa9be63361ff9b81569ebee63c930f2e +R d40ea38d7142da3f67c791f2921da224 U drh -Z de72510160f83f54a6026486570e81b8 +Z 6cd8755ee2455e78de1e4ba9f17c392f # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a6d9dfda23..66bec0a036 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0f228317c6ea1388d82df46f44c166b2aa9be63361ff9b81569ebee63c930f2e +aeef82e974c24071e3211588001a92c7f122fbaf02d9dcf7fa5aaf30d2729f64 diff --git a/src/shell.c.in b/src/shell.c.in index 4b799838da..48234b7d31 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -250,7 +250,6 @@ INCLUDE ../ext/misc/sqlite3_stdio.c # define SQLITE_CIO_NO_FLUSH #endif -#define eputf(fmt, ...) sqlite3_fprintf(stderr,fmt,__VA_ARGS__) #define eputz(z) sqlite3_fputs(z,stderr) #define sputz(fp,z) sqlite3_fputs(z,fp) @@ -1503,7 +1502,7 @@ static void failIfSafeMode( va_start(ap, zErrMsg); zMsg = sqlite3_vmprintf(zErrMsg, ap); va_end(ap); - eputf("line %d: %s\n", p->lineno, zMsg); + sqlite3_fprintf(stderr, "line %d: %s\n", p->lineno, zMsg); exit(1); } } @@ -2838,7 +2837,7 @@ static void createSelftestTable(ShellState *p){ "DROP TABLE [_shell$self];" ,0,0,&zErrMsg); if( zErrMsg ){ - eputf("SELFTEST initialization failure: %s\n", zErrMsg); + sqlite3_fprintf(stderr, "SELFTEST initialization failure: %s\n", zErrMsg); sqlite3_free(zErrMsg); } sqlite3_exec(p->db, "RELEASE selftest_init",0,0,0); @@ -4190,18 +4189,18 @@ static int expertDotCommand( } else if( n>=2 && 0==cli_strncmp(z, "-sample", n) ){ if( i==(nArg-1) ){ - eputf("option requires an argument: %s\n", z); + sqlite3_fprintf(stderr, "option requires an argument: %s\n", z); rc = SQLITE_ERROR; }else{ iSample = (int)integerValue(azArg[++i]); if( iSample<0 || iSample>100 ){ - eputf("value out of range: %s\n", azArg[i]); + sqlite3_fprintf(stderr,"value out of range: %s\n", azArg[i]); rc = SQLITE_ERROR; } } } else{ - eputf("unknown option: %s\n", z); + sqlite3_fprintf(stderr,"unknown option: %s\n", z); rc = SQLITE_ERROR; } } @@ -4209,7 +4208,7 @@ static int expertDotCommand( if( rc==SQLITE_OK ){ pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr); if( pState->expert.pExpert==0 ){ - eputf("sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory"); + sqlite3_fprintf(stderr,"sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory"); rc = SQLITE_ERROR; }else{ sqlite3_expert_config( @@ -5099,7 +5098,7 @@ static char *readFile(const char *zName, int *pnByte){ if( in==0 ) return 0; rc = fseek(in, 0, SEEK_END); if( rc!=0 ){ - eputf("Error: '%s' not seekable\n", zName); + sqlite3_fprintf(stderr,"Error: '%s' not seekable\n", zName); fclose(in); return 0; } @@ -5115,7 +5114,7 @@ static char *readFile(const char *zName, int *pnByte){ fclose(in); if( nRead!=1 ){ sqlite3_free(pBuf); - eputf("Error: cannot read '%s'\n", zName); + sqlite3_fprintf(stderr,"Error: cannot read '%s'\n", zName); return 0; } pBuf[nIn] = 0; @@ -5236,7 +5235,7 @@ static unsigned char *readHexDb(ShellState *p, int *pnData){ if( zDbFilename ){ in = sqlite3_fopen(zDbFilename, "r"); if( in==0 ){ - eputf("cannot open \"%s\" for reading\n", zDbFilename); + sqlite3_fprintf(stderr,"cannot open \"%s\" for reading\n", zDbFilename); return 0; } nLine = 0; @@ -5299,7 +5298,7 @@ readHexDb_error: p->lineno = nLine; } sqlite3_free(a); - eputf("Error on line %d of --hexdb input\n", nLine); + sqlite3_fprintf(stderr,"Error on line %d of --hexdb input\n", nLine); return 0; } #endif /* SQLITE_OMIT_DESERIALIZE */ @@ -5374,7 +5373,7 @@ static void open_db(ShellState *p, int openFlags){ } } if( p->db==0 || SQLITE_OK!=sqlite3_errcode(p->db) ){ - eputf("Error: unable to open database \"%s\": %s\n", + sqlite3_fprintf(stderr,"Error: unable to open database \"%s\": %s\n", zDbFilename, sqlite3_errmsg(p->db)); if( (openFlags & OPEN_DB_KEEPALIVE)==0 ){ exit(1); @@ -5386,7 +5385,7 @@ static void open_db(ShellState *p, int openFlags){ stderr); exit(1); }else{ - eputf("Notice: using substitute in-memory database instead of \"%s\"\n", + sqlite3_fprintf(stderr,"Notice: using substitute in-memory database instead of \"%s\"\n", zDbFilename); } } @@ -5498,7 +5497,7 @@ static void open_db(ShellState *p, int openFlags){ SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE); if( rc ){ - eputf("Error: sqlite3_deserialize() returns %d\n", rc); + sqlite3_fprintf(stderr,"Error: sqlite3_deserialize() returns %d\n", rc); } if( p->szMax>0 ){ sqlite3_file_control(p->db, "main", SQLITE_FCNTL_SIZE_LIMIT, &p->szMax); @@ -5522,7 +5521,7 @@ static void open_db(ShellState *p, int openFlags){ void close_db(sqlite3 *db){ int rc = sqlite3_close(db); if( rc ){ - eputf("Error: sqlite3_close() returns %d: %s\n", rc, sqlite3_errmsg(db)); + sqlite3_fprintf(stderr,"Error: sqlite3_close() returns %d: %s\n", rc, sqlite3_errmsg(db)); } } @@ -5686,7 +5685,7 @@ static int booleanValue(const char *zArg){ if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){ return 0; } - eputf("ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg); + sqlite3_fprintf(stderr,"ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg); return 0; } @@ -5724,7 +5723,7 @@ static FILE *output_file_open(const char *zFile, int bTextMode){ }else{ f = sqlite3_fopen(zFile, bTextMode ? "w" : "wb"); if( f==0 ){ - eputf("Error: cannot open \"%s\"\n", zFile); + sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile); } } return f; @@ -5889,10 +5888,11 @@ static char *SQLITE_CDECL csv_read_one_field(ImportCtx *p){ break; } if( pc==cQuote && c!='\r' ){ - eputf("%s:%d: unescaped %c character\n", p->zFile, p->nLine, cQuote); + sqlite3_fprintf(stderr,"%s:%d: unescaped %c character\n", + p->zFile, p->nLine, cQuote); } if( c==EOF ){ - eputf("%s:%d: unterminated %c-quoted field\n", + sqlite3_fprintf(stderr,"%s:%d: unterminated %c-quoted field\n", p->zFile, startLine, cQuote); p->cTerm = c; break; @@ -5991,7 +5991,7 @@ static void tryToCloneData( shell_check_oom(zQuery); rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); if( rc ){ - eputf("Error %d: %s on [%s]\n", + sqlite3_fprintf(stderr,"Error %d: %s on [%s]\n", sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery); goto end_data_xfer; } @@ -6008,7 +6008,7 @@ static void tryToCloneData( memcpy(zInsert+i, ");", 3); rc = sqlite3_prepare_v2(newDb, zInsert, -1, &pInsert, 0); if( rc ){ - eputf("Error %d: %s on [%s]\n", + sqlite3_fprintf(stderr,"Error %d: %s on [%s]\n", sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb), zInsert); goto end_data_xfer; } @@ -6044,7 +6044,7 @@ static void tryToCloneData( } /* End for */ rc = sqlite3_step(pInsert); if( rc!=SQLITE_OK && rc!=SQLITE_ROW && rc!=SQLITE_DONE ){ - eputf("Error %d: %s\n", + sqlite3_fprintf(stderr,"Error %d: %s\n", sqlite3_extended_errcode(newDb), sqlite3_errmsg(newDb)); } sqlite3_reset(pInsert); @@ -6062,7 +6062,7 @@ static void tryToCloneData( shell_check_oom(zQuery); rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); if( rc ){ - eputf("Warning: cannot step \"%s\" backwards", zTable); + sqlite3_fprintf(stderr,"Warning: cannot step \"%s\" backwards", zTable); break; } } /* End for(k=0...) */ @@ -6099,7 +6099,7 @@ static void tryToCloneSchema( shell_check_oom(zQuery); rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); if( rc ){ - eputf("Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db), + sqlite3_fprintf(stderr,"Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery); goto end_schema_xfer; } @@ -6111,7 +6111,7 @@ static void tryToCloneSchema( sqlite3_fprintf(stdout, "%s... ", zName); fflush(stdout); sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); if( zErrMsg ){ - eputf("Error: %s\nSQL: [%s]\n", zErrMsg, zSql); + sqlite3_fprintf(stderr,"Error: %s\nSQL: [%s]\n", zErrMsg, zSql); sqlite3_free(zErrMsg); zErrMsg = 0; } @@ -6129,7 +6129,7 @@ static void tryToCloneSchema( shell_check_oom(zQuery); rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); if( rc ){ - eputf("Error: (%d) %s on [%s]\n", + sqlite3_fprintf(stderr,"Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery); goto end_schema_xfer; } @@ -6141,7 +6141,7 @@ static void tryToCloneSchema( sqlite3_fprintf(stdout, "%s... ", zName); fflush(stdout); sqlite3_exec(newDb, (const char*)zSql, 0, 0, &zErrMsg); if( zErrMsg ){ - eputf("Error: %s\nSQL: [%s]\n", zErrMsg, zSql); + sqlite3_fprintf(stderr,"Error: %s\nSQL: [%s]\n", zErrMsg, zSql); sqlite3_free(zErrMsg); zErrMsg = 0; } @@ -6165,12 +6165,12 @@ static void tryToClone(ShellState *p, const char *zNewDb){ int rc; sqlite3 *newDb = 0; if( access(zNewDb,0)==0 ){ - eputf("File \"%s\" already exists.\n", zNewDb); + sqlite3_fprintf(stderr,"File \"%s\" already exists.\n", zNewDb); return; } rc = sqlite3_open(zNewDb, &newDb); if( rc ){ - eputf("Cannot create output database: %s\n", sqlite3_errmsg(newDb)); + sqlite3_fprintf(stderr,"Cannot create output database: %s\n", sqlite3_errmsg(newDb)); }else{ sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0); sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0); @@ -6221,7 +6221,7 @@ static void output_reset(ShellState *p){ char *zCmd; zCmd = sqlite3_mprintf("%s %s", zXdgOpenCmd, p->zTempFile); if( system(zCmd) ){ - eputf("Failed: [%s]\n", zCmd); + sqlite3_fprintf(stderr,"Failed: [%s]\n", zCmd); }else{ /* Give the start/open/xdg-open command some time to get ** going before we continue, and potential delete the @@ -6311,7 +6311,7 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1", -1, &pStmt, 0); if( rc ){ - eputf("error: %s\n", sqlite3_errmsg(p->db)); + sqlite3_fprintf(stderr,"error: %s\n", sqlite3_errmsg(p->db)); sqlite3_finalize(pStmt); return 1; } @@ -6371,7 +6371,7 @@ static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){ ** Print the given string as an error message. */ static void shellEmitError(const char *zErr){ - eputf("Error: %s\n", zErr); + sqlite3_fprintf(stderr,"Error: %s\n", zErr); } /* ** Print the current sqlite3_errmsg() value to stderr and return 1. @@ -6694,7 +6694,7 @@ static int lintFkeyIndexes( zIndent = " "; } else{ - eputf("Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]); + sqlite3_fprintf(stderr,"Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]); return SQLITE_ERROR; } } @@ -6762,16 +6762,16 @@ static int lintFkeyIndexes( sqlite3_free(zPrev); if( rc!=SQLITE_OK ){ - eputf("%s\n", sqlite3_errmsg(db)); + sqlite3_fprintf(stderr,"%s\n", sqlite3_errmsg(db)); } rc2 = sqlite3_finalize(pSql); if( rc==SQLITE_OK && rc2!=SQLITE_OK ){ rc = rc2; - eputf("%s\n", sqlite3_errmsg(db)); + sqlite3_fprintf(stderr,"%s\n", sqlite3_errmsg(db)); } }else{ - eputf("%s\n", sqlite3_errmsg(db)); + sqlite3_fprintf(stderr,"%s\n", sqlite3_errmsg(db)); } return rc; @@ -6807,7 +6807,7 @@ static void shellPrepare( if( *pRc==SQLITE_OK ){ int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0); if( rc!=SQLITE_OK ){ - eputf("sql error: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); + sqlite3_fprintf(stderr,"sql error: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); *pRc = rc; } } @@ -6851,7 +6851,7 @@ static void shellFinalize( int rc = sqlite3_finalize(pStmt); if( *pRc==SQLITE_OK ){ if( rc!=SQLITE_OK ){ - eputf("SQL error: %s\n", sqlite3_errmsg(db)); + sqlite3_fprintf(stderr,"SQL error: %s\n", sqlite3_errmsg(db)); } *pRc = rc; } @@ -6873,7 +6873,7 @@ void shellReset( if( *pRc==SQLITE_OK ){ if( rc!=SQLITE_OK ){ sqlite3 *db = sqlite3_db_handle(pStmt); - eputf("SQL error: %s\n", sqlite3_errmsg(db)); + sqlite3_fprintf(stderr,"SQL error: %s\n", sqlite3_errmsg(db)); } *pRc = rc; } @@ -7177,7 +7177,7 @@ static int arCheckEntries(ArCommand *pAr){ } shellReset(&rc, pTest); if( rc==SQLITE_OK && bOk==0 ){ - eputf("not found in archive: %s\n", z); + sqlite3_fprintf(stderr,"not found in archive: %s\n", z); rc = SQLITE_ERROR; } } @@ -7683,7 +7683,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){ bRowids = 0; } else{ - eputf("unexpected option: %s\n", azArg[i]); + sqlite3_fprintf(stderr,"unexpected option: %s\n", azArg[i]); showHelp(pState->out, azArg[0]); return 1; } @@ -7702,7 +7702,7 @@ static int recoverDatabaseCmd(ShellState *pState, int nArg, char **azArg){ if( sqlite3_recover_errcode(p)!=SQLITE_OK ){ const char *zErr = sqlite3_recover_errmsg(p); int errCode = sqlite3_recover_errcode(p); - eputf("sql error: %s (%d)\n", zErr, errCode); + sqlite3_fprintf(stderr,"sql error: %s (%d)\n", zErr, errCode); } rc = sqlite3_recover_finish(p); return rc; @@ -7734,7 +7734,7 @@ static int intckDatabaseCmd(ShellState *pState, i64 nStepPerUnlock){ } rc = sqlite3_intck_error(p, &zErr); if( zErr ){ - eputf("%s\n", zErr); + sqlite3_fprintf(stderr,"%s\n", zErr); } sqlite3_intck_close(p); @@ -7761,7 +7761,7 @@ static int intckDatabaseCmd(ShellState *pState, i64 nStepPerUnlock){ #define rc_err_oom_die(rc) \ if( rc==SQLITE_NOMEM ) shell_check_oom(0); \ else if(!(rc==SQLITE_OK||rc==SQLITE_DONE)) \ - eputf("E:%d\n",rc), assert(0) + sqlite3_fprintf(stderr,"E:%d\n",rc), assert(0) #else static void rc_err_oom_die(int rc){ if( rc==SQLITE_NOMEM ) shell_check_oom(0); @@ -8128,7 +8128,7 @@ static int do_meta_command(char *zLine, ShellState *p){ bAsync = 1; }else { - eputf("unknown option: %s\n", azArg[j]); + sqlite3_fprintf(stderr,"unknown option: %s\n", azArg[j]); return 1; } }else if( zDestFile==0 ){ @@ -8149,7 +8149,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_open_v2(zDestFile, &pDest, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs); if( rc!=SQLITE_OK ){ - eputf("Error: cannot open \"%s\"\n", zDestFile); + sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zDestFile); close_db(pDest); return 1; } @@ -8219,7 +8219,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = chdir(azArg[1]); #endif if( rc ){ - eputf("Cannot change to directory \"%s\"\n", azArg[1]); + sqlite3_fprintf(stderr,"Cannot change to directory \"%s\"\n", azArg[1]); rc = 1; } }else{ @@ -8252,7 +8252,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){ rc = 2; }else if( testcase_glob(azArg[1],zRes)==0 ){ - eputf("testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n", + sqlite3_fprintf(stderr,"testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n", p->zTestcase, azArg[1], zRes); rc = 1; }else{ @@ -8410,7 +8410,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( nArg>1 ) break; } if( nArg>1 && ii==ArraySize(aDbConfig) ){ - eputf("Error: unknown dbconfig \"%s\"\n", azArg[1]); + sqlite3_fprintf(stderr,"Error: unknown dbconfig \"%s\"\n", azArg[1]); eputz("Enter \".dbconfig\" with no arguments for a list\n"); } }else @@ -8460,7 +8460,7 @@ static int do_meta_command(char *zLine, ShellState *p){ ShellSetFlag(p, SHFLG_DumpNoSys); }else { - eputf("Unknown option \"%s\" on \".dump\"\n", azArg[i]); + sqlite3_fprintf(stderr,"Unknown option \"%s\" on \".dump\"\n", azArg[i]); rc = 1; sqlite3_free(zLike); goto meta_command_exit; @@ -8614,7 +8614,7 @@ static int do_meta_command(char *zLine, ShellState *p){ #ifndef SQLITE_OMIT_VIRTUALTABLE if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){ if( p->bSafeMode ){ - eputf("Cannot run experimental commands such as \"%s\" in safe mode\n", + sqlite3_fprintf(stderr,"Cannot run experimental commands such as \"%s\" in safe mode\n", azArg[0]); rc = 1; }else{ @@ -8688,7 +8688,7 @@ static int do_meta_command(char *zLine, ShellState *p){ filectrl = aCtrl[i].ctrlCode; iCtrl = i; }else{ - eputf("Error: ambiguous file-control: \"%s\"\n" + sqlite3_fprintf(stderr,"Error: ambiguous file-control: \"%s\"\n" "Use \".filectrl --help\" for help\n", zCmd); rc = 1; goto meta_command_exit; @@ -8696,7 +8696,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } } if( filectrl<0 ){ - eputf("Error: unknown file-control: %s\n" + sqlite3_fprintf(stderr,"Error: unknown file-control: %s\n" "Use \".filectrl --help\" for help\n", zCmd); }else{ switch(filectrl){ @@ -8963,7 +8963,7 @@ static int do_meta_command(char *zLine, ShellState *p){ sCtx.xCloser = fclose; } if( sCtx.in==0 ){ - eputf("Error: cannot open \"%s\"\n", zFile); + sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zFile); goto meta_command_exit; } if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){ @@ -9007,7 +9007,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } assert(dbCols==0); if( zColDefs==0 ){ - eputf("%s: empty file\n", sCtx.zFile); + sqlite3_fprintf(stderr,"%s: empty file\n", sCtx.zFile); import_cleanup(&sCtx); rc = 1; sqlite3_free(zCreate); @@ -9022,10 +9022,12 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_fprintf(p->out, "%s\n", zCreate); } rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); + if( rc ){ + sqlite3_fprintf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); + } sqlite3_free(zCreate); zCreate = 0; if( rc ){ - eputf("%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); import_cleanup(&sCtx); rc = 1; goto meta_command_exit; @@ -9119,7 +9121,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT); if( i=nCol ){ sqlite3_step(pStmt); rc = sqlite3_reset(pStmt); if( rc!=SQLITE_OK ){ - eputf("%s:%d: INSERT failed: %s\n", + sqlite3_fprintf(stderr,"%s:%d: INSERT failed: %s\n", sCtx.zFile, startLine, sqlite3_errmsg(p->db)); sCtx.nErr++; }else{ @@ -9167,7 +9169,7 @@ static int do_meta_command(char *zLine, ShellState *p){ int lenPK = 0; /* Length of the PRIMARY KEY string for isWO tables */ int i; if( !ShellHasFlag(p,SHFLG_TestingMode) ){ - eputf(".%s unavailable without --unsafe-testing\n", + sqlite3_fprintf(stderr,".%s unavailable without --unsafe-testing\n", "imposter"); rc = 1; goto meta_command_exit; @@ -9233,7 +9235,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } sqlite3_finalize(pStmt); if( i==0 || tnum==0 ){ - eputf("no such index: \"%s\"\n", azArg[1]); + sqlite3_fprintf(stderr,"no such index: \"%s\"\n", azArg[1]); rc = 1; sqlite3_free(zCollist); goto meta_command_exit; @@ -9248,14 +9250,14 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_exec(p->db, zSql, 0, 0, 0); sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0); if( rc ){ - eputf("Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); + sqlite3_fprintf(stderr,"Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); }else{ sqlite3_fprintf(stdout, "%s;\n", zSql); sqlite3_fprintf(stdout, "WARNING: writing to an imposter table will corrupt" " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index"); } }else{ - eputf("SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc); + sqlite3_fprintf(stderr,"SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc); rc = 1; } sqlite3_free(zSql); @@ -9269,7 +9271,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( iArg==0 ) iArg = -1; } if( (nArg!=1 && nArg!=2) || iArg<0 ){ - eputf("%s","Usage: .intck STEPS_PER_UNLOCK\n"); + sqlite3_fprintf(stderr,"%s","Usage: .intck STEPS_PER_UNLOCK\n"); rc = 1; goto meta_command_exit; } @@ -9290,7 +9292,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else{ iotrace = sqlite3_fopen(azArg[1], "w"); if( iotrace==0 ){ - eputf("Error: cannot open \"%s\"\n", azArg[1]); + sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); sqlite3IoTrace = 0; rc = 1; }else{ @@ -9337,14 +9339,14 @@ static int do_meta_command(char *zLine, ShellState *p){ if( iLimit<0 ){ iLimit = i; }else{ - eputf("ambiguous limit: \"%s\"\n", azArg[1]); + sqlite3_fprintf(stderr,"ambiguous limit: \"%s\"\n", azArg[1]); rc = 1; goto meta_command_exit; } } } if( iLimit<0 ){ - eputf("unknown limit: \"%s\"\n" + sqlite3_fprintf(stderr,"unknown limit: \"%s\"\n" "enter \".limits\" with no arguments for a list.\n", azArg[1]); rc = 1; @@ -9437,7 +9439,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( zTabname==0 ){ zTabname = z; }else if( z[0]=='-' ){ - eputf("unknown option: %s\n", z); + sqlite3_fprintf(stderr,"unknown option: %s\n", z); eputz("options:\n" " --noquote\n" " --quote\n" @@ -9447,7 +9449,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; goto meta_command_exit; }else{ - eputf("extra argument: \"%s\"\n", z); + sqlite3_fprintf(stderr,"extra argument: \"%s\"\n", z); rc = 1; goto meta_command_exit; } @@ -9535,7 +9537,7 @@ static int do_meta_command(char *zLine, ShellState *p){ eputz("Usage: .nonce NONCE\n"); rc = 1; }else if( p->zNonce==0 || cli_strcmp(azArg[1],p->zNonce)!=0 ){ - eputf("line %d: incorrect nonce: \"%s\"\n", + sqlite3_fprintf(stderr,"line %d: incorrect nonce: \"%s\"\n", p->lineno, azArg[1]); exit(1); }else{ @@ -9590,11 +9592,11 @@ static int do_meta_command(char *zLine, ShellState *p){ }else #endif /* !SQLITE_SHELL_FIDDLE */ if( z[0]=='-' ){ - eputf("unknown option: %s\n", z); + sqlite3_fprintf(stderr,"unknown option: %s\n", z); rc = 1; goto meta_command_exit; }else if( zFN ){ - eputf("extra argument: \"%s\"\n", z); + sqlite3_fprintf(stderr,"extra argument: \"%s\"\n", z); rc = 1; goto meta_command_exit; }else{ @@ -9636,7 +9638,7 @@ static int do_meta_command(char *zLine, ShellState *p){ p->pAuxDb->zDbFilename = zNewFilename; open_db(p, OPEN_DB_KEEPALIVE); if( p->db==0 ){ - eputf("Error: cannot open '%s'\n", zNewFilename); + sqlite3_fprintf(stderr,"Error: cannot open '%s'\n", zNewFilename); sqlite3_free(zNewFilename); }else{ p->pAuxDb->zFreeOnClose = zNewFilename; @@ -9739,7 +9741,7 @@ static int do_meta_command(char *zLine, ShellState *p){ #else FILE *pfPipe = sqlite3_popen(zFile + 1, "w"); if( pfPipe==0 ){ - eputf("Error: cannot open pipe \"%s\"\n", zFile + 1); + sqlite3_fprintf(stderr,"Error: cannot open pipe \"%s\"\n", zFile + 1); rc = 1; }else{ output_redir(p, pfPipe); @@ -9751,7 +9753,7 @@ static int do_meta_command(char *zLine, ShellState *p){ FILE *pfFile = output_file_open(zFile, bTxtMode); if( pfFile==0 ){ if( cli_strcmp(zFile,"off")!=0 ){ - eputf("Error: cannot write to \"%s\"\n", zFile); + sqlite3_fprintf(stderr,"Error: cannot write to \"%s\"\n", zFile); } rc = 1; } else { @@ -9911,7 +9913,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } continue; } - eputf("Error: unknown option: \"%s\"\n", azArg[i]); + sqlite3_fprintf(stderr,"Error: unknown option: \"%s\"\n", azArg[i]); rc = 1; goto meta_command_exit; }else{ @@ -9956,7 +9958,7 @@ static int do_meta_command(char *zLine, ShellState *p){ #else p->in = sqlite3_popen(azArg[1]+1, "r"); if( p->in==0 ){ - eputf("Error: cannot open \"%s\"\n", azArg[1]); + sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); rc = 1; }else{ rc = process_input(p); @@ -9964,7 +9966,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } #endif }else if( (p->in = openChrSource(azArg[1]))==0 ){ - eputf("Error: cannot open \"%s\"\n", azArg[1]); + sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", azArg[1]); rc = 1; }else{ rc = process_input(p); @@ -9997,7 +9999,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } rc = sqlite3_open(zSrcFile, &pSrc); if( rc!=SQLITE_OK ){ - eputf("Error: cannot open \"%s\"\n", zSrcFile); + sqlite3_fprintf(stderr,"Error: cannot open \"%s\"\n", zSrcFile); close_db(pSrc); return 1; } @@ -10080,7 +10082,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( optionMatch(azArg[ii],"nosys") ){ bNoSystemTabs = 1; }else if( azArg[ii][0]=='-' ){ - eputf("Unknown option: \"%s\"\n", azArg[ii]); + sqlite3_fprintf(stderr,"Unknown option: \"%s\"\n", azArg[ii]); rc = 1; goto meta_command_exit; }else if( zName==0 ){ @@ -10242,7 +10244,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else{ rc = sqlite3session_attach(pSession->p, azCmd[1]); if( rc ){ - eputf("ERROR: sqlite3session_attach() returns %d\n",rc); + sqlite3_fprintf(stderr,"ERROR: sqlite3session_attach() returns %d\n",rc); rc = 0; } } @@ -10261,7 +10263,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( pSession->p==0 ) goto session_not_open; out = sqlite3_fopen(azCmd[1], "wb"); if( out==0 ){ - eputf("ERROR: cannot open \"%s\" for writing\n", + sqlite3_fprintf(stderr,"ERROR: cannot open \"%s\" for writing\n", azCmd[1]); }else{ int szChng; @@ -10277,7 +10279,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } if( pChng && fwrite(pChng, szChng, 1, out)!=1 ){ - eputf("ERROR: Failed to write entire %d-byte output\n", szChng); + sqlite3_fprintf(stderr,"ERROR: Failed to write entire %d-byte output\n", szChng); } sqlite3_free(pChng); fclose(out); @@ -10375,18 +10377,18 @@ static int do_meta_command(char *zLine, ShellState *p){ if( zName[0]==0 ) goto session_syntax_error; for(i=0; inSession; i++){ if( cli_strcmp(pAuxDb->aSession[i].zName,zName)==0 ){ - eputf("Session \"%s\" already exists\n", zName); + sqlite3_fprintf(stderr,"Session \"%s\" already exists\n", zName); goto meta_command_exit; } } if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){ - eputf("Maximum of %d sessions\n", ArraySize(pAuxDb->aSession)); + sqlite3_fprintf(stderr,"Maximum of %d sessions\n", ArraySize(pAuxDb->aSession)); goto meta_command_exit; } pSession = &pAuxDb->aSession[pAuxDb->nSession]; rc = sqlite3session_create(p->db, azCmd[1], &pSession->p); if( rc ){ - eputf("Cannot open session: error code=%d\n", rc); + sqlite3_fprintf(stderr,"Cannot open session: error code=%d\n", rc); rc = 0; goto meta_command_exit; } @@ -10446,7 +10448,7 @@ static int do_meta_command(char *zLine, ShellState *p){ bVerbose++; }else { - eputf("Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); + sqlite3_fprintf(stderr,"Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); eputz("Should be one of: --init -v\n"); rc = 1; goto meta_command_exit; @@ -10519,7 +10521,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } } else{ - eputf("Unknown operation \"%s\" on selftest line %d\n", zOp, tno); + sqlite3_fprintf(stderr,"Unknown operation \"%s\" on selftest line %d\n", zOp, tno); rc = 1; break; } @@ -10575,7 +10577,7 @@ static int do_meta_command(char *zLine, ShellState *p){ bDebug = 1; }else { - eputf("Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); + sqlite3_fprintf(stderr,"Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); showHelp(p->out, azArg[0]); rc = 1; goto meta_command_exit; @@ -10704,7 +10706,7 @@ static int do_meta_command(char *zLine, ShellState *p){ double countIrreversible = sqlite3_column_double(pCheckStmt, 0); if( countIrreversible>0 ){ int sz = (int)(countIrreversible + 0.5); - eputf("Digest includes %d invalidly encoded text field%s.\n", + sqlite3_fprintf(stderr,"Digest includes %d invalidly encoded text field%s.\n", sz, (sz>1)? "s": ""); } } @@ -10742,7 +10744,7 @@ static int do_meta_command(char *zLine, ShellState *p){ x = zCmd!=0 ? system(zCmd) : 1; /*consoleRenewSetup();*/ sqlite3_free(zCmd); - if( x ) eputf("System command returns %d\n", x); + if( x ) sqlite3_fprintf(stderr,"System command returns %d\n", x); }else #endif /* !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE) */ @@ -11010,7 +11012,7 @@ static int do_meta_command(char *zLine, ShellState *p){ testctrl = aCtrl[i].ctrlCode; iCtrl = i; }else{ - eputf("Error: ambiguous test-control: \"%s\"\n" + sqlite3_fprintf(stderr,"Error: ambiguous test-control: \"%s\"\n" "Use \".testctrl --help\" for help\n", zCmd); rc = 1; goto meta_command_exit; @@ -11018,7 +11020,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } } if( testctrl<0 ){ - eputf("Error: unknown test-control: %s\n" + sqlite3_fprintf(stderr,"Error: unknown test-control: %s\n" "Use \".testctrl --help\" for help\n", zCmd); }else{ switch(testctrl){ @@ -11094,10 +11096,10 @@ static int do_meta_command(char *zLine, ShellState *p){ if( sqlite3_stricmp(zLabel, aLabel[jj].zLabel)==0 ) break; } if( jj>=ArraySize(aLabel) ){ - eputf("Error: no such optimization: \"%s\"\n", zLabel); + sqlite3_fprintf(stderr,"Error: no such optimization: \"%s\"\n", zLabel); eputz("Should be one of:"); for(jj=0; jjdb, azArg[2], azArg[3], strlen30(azArg[3])); if( rc ){ - eputf("Authentication failed for user %s\n", azArg[2]); + sqlite3_fprintf(stderr,"Authentication failed for user %s\n", azArg[2]); rc = 1; } }else if( cli_strcmp(azArg[1],"add")==0 ){ @@ -11510,7 +11512,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_user_add(p->db, azArg[2], azArg[3], strlen30(azArg[3]), booleanValue(azArg[4])); if( rc ){ - eputf("User-Add failed: %d\n", rc); + sqlite3_fprintf(stderr,"User-Add failed: %d\n", rc); rc = 1; } }else if( cli_strcmp(azArg[1],"edit")==0 ){ @@ -11522,7 +11524,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_user_change(p->db, azArg[2], azArg[3], strlen30(azArg[3]), booleanValue(azArg[4])); if( rc ){ - eputf("User-Edit failed: %d\n", rc); + sqlite3_fprintf(stderr,"User-Edit failed: %d\n", rc); rc = 1; } }else if( cli_strcmp(azArg[1],"delete")==0 ){ @@ -11533,7 +11535,7 @@ static int do_meta_command(char *zLine, ShellState *p){ } rc = sqlite3_user_delete(p->db, azArg[2]); if( rc ){ - eputf("User-Delete failed: %d\n", rc); + sqlite3_fprintf(stderr,"User-Delete failed: %d\n", rc); rc = 1; } }else{ @@ -11626,7 +11628,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else { - eputf("Error: unknown command or invalid arguments: " + sqlite3_fprintf(stderr,"Error: unknown command or invalid arguments: " " \"%s\". Enter \".help\" for help\n", azArg[0]); rc = 1; } @@ -11902,7 +11904,7 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ }else{ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType); } - eputf("%s %s\n", zPrefix, zErrorTail); + sqlite3_fprintf(stderr,"%s %s\n", zPrefix, zErrorTail); sqlite3_free(zErrMsg); zErrMsg = 0; return 1; @@ -11977,7 +11979,7 @@ static int process_input(ShellState *p){ if( p->inputNesting==MAX_INPUT_NESTING ){ /* This will be more informative in a later version. */ - eputf("Input nesting limit (%d) reached at line %d." + sqlite3_fprintf(stderr,"Input nesting limit (%d) reached at line %d." " Check recursion.\n", MAX_INPUT_NESTING, p->lineno); return 1; } @@ -12212,12 +12214,12 @@ static void process_sqliterc( p->in = sqlite3_fopen(sqliterc,"rb"); if( p->in ){ if( stdin_is_interactive ){ - eputf("-- Loading resources from %s\n", sqliterc); + sqlite3_fprintf(stderr,"-- Loading resources from %s\n", sqliterc); } if( process_input(p) && bail_on_error ) exit(1); fclose(p->in); }else if( sqliterc_override!=0 ){ - eputf("cannot open: \"%s\"\n", sqliterc); + sqlite3_fprintf(stderr,"cannot open: \"%s\"\n", sqliterc); if( bail_on_error ) exit(1); } p->in = inSaved; @@ -12292,11 +12294,11 @@ static const char zOptions[] = #endif ; static void usage(int showDetail){ - eputf("Usage: %s [OPTIONS] [FILENAME [SQL]]\n" + sqlite3_fprintf(stderr,"Usage: %s [OPTIONS] [FILENAME [SQL]]\n" "FILENAME is the name of an SQLite database. A new database is created\n" "if the file does not previously exist. Defaults to :memory:.\n", Argv0); if( showDetail ){ - eputf("OPTIONS include:\n%s", zOptions); + sqlite3_fprintf(stderr,"OPTIONS include:\n%s", zOptions); }else{ eputz("Use the -help option for additional information\n"); } @@ -12366,7 +12368,7 @@ static void printBold(const char *zText){ */ static char *cmdline_option_value(int argc, char **argv, int i){ if( i==argc ){ - eputf("%s: Error: missing argument to %s\n", argv[0], argv[argc-1]); + sqlite3_fprintf(stderr,"%s: Error: missing argument to %s\n", argv[0], argv[argc-1]); exit(1); } return argv[i]; @@ -12435,7 +12437,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #if !defined(_WIN32_WCE) if( getenv("SQLITE_DEBUG_BREAK") ){ if( isatty(0) && isatty(2) ){ - eputf("attach debugger to process %d and press any key to continue.\n", + sqlite3_fprintf(stderr,"attach debugger to process %d and press any key to continue.\n", GETPID()); fgetc(stdin); }else{ @@ -12462,7 +12464,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #if USE_SYSTEM_SQLITE+0!=1 if( cli_strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){ - eputf("SQLite header and source version mismatch\n%s\n%s\n", + sqlite3_fprintf(stderr,"SQLite header and source version mismatch\n%s\n%s\n", sqlite3_sourceid(), SQLITE_SOURCE_ID); exit(1); } @@ -12686,7 +12688,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( pVfs ){ sqlite3_vfs_register(pVfs, 1); }else{ - eputf("no such VFS: \"%s\"\n", zVfs); + sqlite3_fprintf(stderr,"no such VFS: \"%s\"\n", zVfs); exit(1); } } @@ -12696,7 +12698,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ data.pAuxDb->zDbFilename = ":memory:"; warnInmemoryDb = argc==1; #else - eputf("%s: Error: no database filename specified\n", Argv0); + sqlite3_fprintf(stderr,"%s: Error: no database filename specified\n", Argv0); return 1; #endif } @@ -12876,14 +12878,14 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ shellEmitError(zErrMsg); if( bail_on_error ) return rc!=0 ? rc : 1; }else if( rc!=0 ){ - eputf("Error: unable to process SQL \"%s\"\n", z); + sqlite3_fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z); if( bail_on_error ) return rc; } } #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) }else if( cli_strncmp(z, "-A", 2)==0 ){ if( nCmd>0 ){ - eputf("Error: cannot mix regular SQL or dot-commands" + sqlite3_fprintf(stderr,"Error: cannot mix regular SQL or dot-commands" " with \"%s\"\n", z); return 1; } @@ -12902,7 +12904,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ }else if( cli_strcmp(z,"-unsafe-testing")==0 ){ /* Acted upon in first pass. */ }else{ - eputf("%s: Error: unknown option: %s\n", Argv0, z); + sqlite3_fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z); eputz("Use -help for a list of options.\n"); return 1; } @@ -12929,7 +12931,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( zErrMsg!=0 ){ shellEmitError(zErrMsg); }else{ - eputf("Error: unable to process SQL: %s\n", azCmd[i]); + sqlite3_fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]); } sqlite3_free(zErrMsg); if( rc==0 ) rc = 1; @@ -13025,7 +13027,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ } #ifdef SQLITE_DEBUG if( sqlite3_memory_used()>mem_main_enter ){ - eputf("Memory leaked: %u bytes\n", + sqlite3_fprintf(stderr,"Memory leaked: %u bytes\n", (unsigned int)(sqlite3_memory_used()-mem_main_enter)); } #endif From 18e2ace4681c6b1d4950811a6123c014ba0fbab0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 24 Sep 2024 19:47:12 +0000 Subject: [PATCH 19/50] Fix over-length lines in the shell source code. FossilOrigin-Name: f3fdf76a0d3abeb5202f2b6f26318815396da7df680073955bde60b13f84e797 --- manifest | 12 ++--- manifest.uuid | 2 +- src/shell.c.in | 140 ++++++++++++++++++++++++++++++++----------------- 3 files changed, 99 insertions(+), 55 deletions(-) diff --git a/manifest b/manifest index f7a7dc5ef4..42bba29152 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\serror\smessages\sin\sthe\sshell. -D 2024-09-24T19:19:53.992 +C Fix\sover-length\slines\sin\sthe\sshell\ssource\scode. +D 2024-09-24T19:47:12.272 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c b2cd748488012312824508639b6af908461e45403037d5c4e19d9b0e8195507f F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 38a38100356134f962b3f72e1e3a44da014dee4f044b81438273aa5b0b5e7469 +F src/shell.c.in 59d96ef5df9ba2f1f1982267385486b0a3fe5d9c04bcf00db8341064a6aaf72f F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0f228317c6ea1388d82df46f44c166b2aa9be63361ff9b81569ebee63c930f2e -R d40ea38d7142da3f67c791f2921da224 +P aeef82e974c24071e3211588001a92c7f122fbaf02d9dcf7fa5aaf30d2729f64 +R e0249c26fc1dbc90ee636c7d58ded95a U drh -Z 6cd8755ee2455e78de1e4ba9f17c392f +Z d330d508deb5561f036eaedfc6533764 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 66bec0a036..fd858c80cf 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -aeef82e974c24071e3211588001a92c7f122fbaf02d9dcf7fa5aaf30d2729f64 +f3fdf76a0d3abeb5202f2b6f26318815396da7df680073955bde60b13f84e797 diff --git a/src/shell.c.in b/src/shell.c.in index 48234b7d31..6454c2d935 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -4208,7 +4208,8 @@ static int expertDotCommand( if( rc==SQLITE_OK ){ pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr); if( pState->expert.pExpert==0 ){ - sqlite3_fprintf(stderr,"sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory"); + sqlite3_fprintf(stderr, + "sqlite3_expert_new: %s\n", zErr ? zErr : "out of memory"); rc = SQLITE_ERROR; }else{ sqlite3_expert_config( @@ -5385,7 +5386,8 @@ static void open_db(ShellState *p, int openFlags){ stderr); exit(1); }else{ - sqlite3_fprintf(stderr,"Notice: using substitute in-memory database instead of \"%s\"\n", + sqlite3_fprintf(stderr, + "Notice: using substitute in-memory database instead of \"%s\"\n", zDbFilename); } } @@ -5521,7 +5523,8 @@ static void open_db(ShellState *p, int openFlags){ void close_db(sqlite3 *db){ int rc = sqlite3_close(db); if( rc ){ - sqlite3_fprintf(stderr,"Error: sqlite3_close() returns %d: %s\n", rc, sqlite3_errmsg(db)); + sqlite3_fprintf(stderr, + "Error: sqlite3_close() returns %d: %s\n", rc, sqlite3_errmsg(db)); } } @@ -5685,7 +5688,8 @@ static int booleanValue(const char *zArg){ if( sqlite3_stricmp(zArg, "off")==0 || sqlite3_stricmp(zArg,"no")==0 ){ return 0; } - sqlite3_fprintf(stderr,"ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg); + sqlite3_fprintf(stderr, + "ERROR: Not a boolean value: \"%s\". Assuming \"no\".\n", zArg); return 0; } @@ -5781,7 +5785,8 @@ static int sql_trace_callback( } case SQLITE_TRACE_PROFILE: { sqlite3_int64 nNanosec = pX ? *(sqlite3_int64*)pX : 0; - sqlite3_fprintf(p->traceOut, "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec); + sqlite3_fprintf(p->traceOut, + "%.*s; -- %lld ns\n", (int)nSql, zSql, nNanosec); break; } } @@ -6099,7 +6104,8 @@ static void tryToCloneSchema( shell_check_oom(zQuery); rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0); if( rc ){ - sqlite3_fprintf(stderr,"Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db), + sqlite3_fprintf(stderr, + "Error: (%d) %s on [%s]\n", sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db), zQuery); goto end_schema_xfer; } @@ -6170,7 +6176,8 @@ static void tryToClone(ShellState *p, const char *zNewDb){ } rc = sqlite3_open(zNewDb, &newDb); if( rc ){ - sqlite3_fprintf(stderr,"Cannot create output database: %s\n", sqlite3_errmsg(newDb)); + sqlite3_fprintf(stderr, + "Cannot create output database: %s\n", sqlite3_errmsg(newDb)); }else{ sqlite3_exec(p->db, "PRAGMA writable_schema=ON;", 0, 0, 0); sqlite3_exec(newDb, "BEGIN EXCLUSIVE;", 0, 0, 0); @@ -6694,7 +6701,8 @@ static int lintFkeyIndexes( zIndent = " "; } else{ - sqlite3_fprintf(stderr,"Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]); + sqlite3_fprintf(stderr, + "Usage: %s %s ?-verbose? ?-groupbyparent?\n", azArg[0], azArg[1]); return SQLITE_ERROR; } } @@ -6753,7 +6761,8 @@ static int lintFkeyIndexes( if( res==0 ){ sqlite3_fprintf(out, "%s%s --> %s\n", zIndent, zCI, zTarget); }else if( bVerbose ){ - sqlite3_fprintf(out, "%s/* no extra indexes required for %s -> %s */\n", + sqlite3_fprintf(out, + "%s/* no extra indexes required for %s -> %s */\n", zIndent, zFrom, zTarget ); } @@ -6807,7 +6816,8 @@ static void shellPrepare( if( *pRc==SQLITE_OK ){ int rc = sqlite3_prepare_v2(db, zSql, -1, ppStmt, 0); if( rc!=SQLITE_OK ){ - sqlite3_fprintf(stderr,"sql error: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); + sqlite3_fprintf(stderr, + "sql error: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); *pRc = rc; } } @@ -8252,7 +8262,8 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){ rc = 2; }else if( testcase_glob(azArg[1],zRes)==0 ){ - sqlite3_fprintf(stderr,"testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n", + sqlite3_fprintf(stderr, + "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n", p->zTestcase, azArg[1], zRes); rc = 1; }else{ @@ -8406,7 +8417,8 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0); } sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v); - sqlite3_fprintf(p->out, "%19s %s\n", aDbConfig[ii].zName, v ? "on" : "off"); + sqlite3_fprintf(p->out, "%19s %s\n", + aDbConfig[ii].zName, v ? "on" : "off"); if( nArg>1 ) break; } if( nArg>1 && ii==ArraySize(aDbConfig) ){ @@ -8460,7 +8472,8 @@ static int do_meta_command(char *zLine, ShellState *p){ ShellSetFlag(p, SHFLG_DumpNoSys); }else { - sqlite3_fprintf(stderr,"Unknown option \"%s\" on \".dump\"\n", azArg[i]); + sqlite3_fprintf(stderr, + "Unknown option \"%s\" on \".dump\"\n", azArg[i]); rc = 1; sqlite3_free(zLike); goto meta_command_exit; @@ -8614,7 +8627,8 @@ static int do_meta_command(char *zLine, ShellState *p){ #ifndef SQLITE_OMIT_VIRTUALTABLE if( c=='e' && cli_strncmp(azArg[0], "expert", n)==0 ){ if( p->bSafeMode ){ - sqlite3_fprintf(stderr,"Cannot run experimental commands such as \"%s\" in safe mode\n", + sqlite3_fprintf(stderr, + "Cannot run experimental commands such as \"%s\" in safe mode\n", azArg[0]); rc = 1; }else{ @@ -8673,7 +8687,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( cli_strcmp(zCmd,"help")==0 ){ sqlite3_fputs("Available file-controls:\n", p->out); for(i=0; iout, " .filectrl %s %s\n", aCtrl[i].zCtrlName, aCtrl[i].zUsage); + sqlite3_fprintf(p->out, + " .filectrl %s %s\n", aCtrl[i].zCtrlName, aCtrl[i].zUsage); } rc = 1; goto meta_command_exit; @@ -9023,7 +9038,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } rc = sqlite3_exec(p->db, zCreate, 0, 0, 0); if( rc ){ - sqlite3_fprintf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); + sqlite3_fprintf(stderr, + "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db)); } sqlite3_free(zCreate); zCreate = 0; @@ -9133,7 +9149,8 @@ static int do_meta_command(char *zLine, ShellState *p){ xRead(&sCtx); i++; }while( sCtx.cTerm==sCtx.cColSep ); - sqlite3_fprintf(stderr,"%s:%d: expected %d columns but found %d - extras ignored\n", + sqlite3_fprintf(stderr, + "%s:%d: expected %d columns but found %d - extras ignored\n", sCtx.zFile, startLine, nCol, i); } if( i>=nCol ){ @@ -9153,7 +9170,8 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_finalize(pStmt); if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0); if( eVerbose>0 ){ - sqlite3_fprintf(p->out, "Added %d rows with %d errors using %d lines of input\n", + sqlite3_fprintf(p->out, + "Added %d rows with %d errors using %d lines of input\n", sCtx.nRow, sCtx.nErr, sCtx.nLine-1); } }else @@ -9250,10 +9268,12 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = sqlite3_exec(p->db, zSql, 0, 0, 0); sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0); if( rc ){ - sqlite3_fprintf(stderr,"Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); + sqlite3_fprintf(stderr, + "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db)); }else{ sqlite3_fprintf(stdout, "%s;\n", zSql); - sqlite3_fprintf(stdout, "WARNING: writing to an imposter table will corrupt" + sqlite3_fprintf(stdout, + "WARNING: writing to an imposter table will corrupt" " the \"%s\" %s!\n", azArg[1], isWO ? "table" : "index"); } }else{ @@ -9464,7 +9484,8 @@ static int do_meta_command(char *zLine, ShellState *p){ p->cmOpts.bWordWrap ? "on" : "off", p->cmOpts.bQuote ? "" : "no"); }else{ - sqlite3_fprintf(p->out, "current output mode: %s\n", modeDescr[p->mode]); + sqlite3_fprintf(p->out, + "current output mode: %s\n", modeDescr[p->mode]); } zMode = modeDescr[p->mode]; } @@ -9696,7 +9717,8 @@ static int do_meta_command(char *zLine, ShellState *p){ break; } }else{ - sqlite3_fprintf(p->out, "ERROR: extra parameter: \"%s\". Usage:\n", azArg[i]); + sqlite3_fprintf(p->out, + "ERROR: extra parameter: \"%s\". Usage:\n", azArg[i]); showHelp(p->out, azArg[0]); rc = 1; sqlite3_free(zFile); @@ -9799,7 +9821,8 @@ static int do_meta_command(char *zLine, ShellState *p){ "SELECT key, quote(value) " "FROM temp.sqlite_parameters;", -1, &pStmt, 0); while( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){ - sqlite3_fprintf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0), + sqlite3_fprintf(p->out, + "%-*s %s\n", len, sqlite3_column_text(pStmt,0), sqlite3_column_text(pStmt,1)); } sqlite3_finalize(pStmt); @@ -10244,7 +10267,8 @@ static int do_meta_command(char *zLine, ShellState *p){ }else{ rc = sqlite3session_attach(pSession->p, azCmd[1]); if( rc ){ - sqlite3_fprintf(stderr,"ERROR: sqlite3session_attach() returns %d\n",rc); + sqlite3_fprintf(stderr, + "ERROR: sqlite3session_attach() returns %d\n",rc); rc = 0; } } @@ -10279,7 +10303,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } if( pChng && fwrite(pChng, szChng, 1, out)!=1 ){ - sqlite3_fprintf(stderr,"ERROR: Failed to write entire %d-byte output\n", szChng); + sqlite3_fprintf(stderr, + "ERROR: Failed to write entire %d-byte output\n", szChng); } sqlite3_free(pChng); fclose(out); @@ -10306,7 +10331,8 @@ static int do_meta_command(char *zLine, ShellState *p){ ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); if( pAuxDb->nSession ){ ii = sqlite3session_enable(pSession->p, ii); - sqlite3_fprintf(p->out, "session %s enable flag = %d\n", pSession->zName, ii); + sqlite3_fprintf(p->out, + "session %s enable flag = %d\n", pSession->zName, ii); } }else @@ -10341,7 +10367,8 @@ static int do_meta_command(char *zLine, ShellState *p){ ii = nCmd==1 ? -1 : booleanValue(azCmd[1]); if( pAuxDb->nSession ){ ii = sqlite3session_indirect(pSession->p, ii); - sqlite3_fprintf(p->out, "session %s indirect flag = %d\n", pSession->zName, ii); + sqlite3_fprintf(p->out, + "session %s indirect flag = %d\n", pSession->zName, ii); } }else @@ -10353,7 +10380,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( nCmd!=1 ) goto session_syntax_error; if( pAuxDb->nSession ){ ii = sqlite3session_isempty(pSession->p); - sqlite3_fprintf(p->out, "session %s isempty flag = %d\n", pSession->zName, ii); + sqlite3_fprintf(p->out, + "session %s isempty flag = %d\n", pSession->zName, ii); } }else @@ -10382,7 +10410,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } } if( pAuxDb->nSession>=ArraySize(pAuxDb->aSession) ){ - sqlite3_fprintf(stderr,"Maximum of %d sessions\n", ArraySize(pAuxDb->aSession)); + sqlite3_fprintf(stderr, + "Maximum of %d sessions\n", ArraySize(pAuxDb->aSession)); goto meta_command_exit; } pSession = &pAuxDb->aSession[pAuxDb->nSession]; @@ -10448,8 +10477,9 @@ static int do_meta_command(char *zLine, ShellState *p){ bVerbose++; }else { - sqlite3_fprintf(stderr,"Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); - eputz("Should be one of: --init -v\n"); + sqlite3_fprintf(stderr, + "Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); + sqlite3_fputs("Should be one of: --init -v\n", stderr); rc = 1; goto meta_command_exit; } @@ -10511,7 +10541,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( rc || zErrMsg ){ nErr++; rc = 1; - sqlite3_fprintf(p->out, "%d: error-code-%d: %s\n", tno, rc, zErrMsg); + sqlite3_fprintf(p->out, "%d: error-code-%d: %s\n", tno, rc,zErrMsg); sqlite3_free(zErrMsg); }else if( cli_strcmp(zAns,str.z)!=0 ){ nErr++; @@ -10521,7 +10551,8 @@ static int do_meta_command(char *zLine, ShellState *p){ } } else{ - sqlite3_fprintf(stderr,"Unknown operation \"%s\" on selftest line %d\n", zOp, tno); + sqlite3_fprintf(stderr, + "Unknown operation \"%s\" on selftest line %d\n", zOp, tno); rc = 1; break; } @@ -10577,7 +10608,8 @@ static int do_meta_command(char *zLine, ShellState *p){ bDebug = 1; }else { - sqlite3_fprintf(stderr,"Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); + sqlite3_fprintf(stderr, + "Unknown option \"%s\" on \"%s\"\n", azArg[i], azArg[0]); showHelp(p->out, azArg[0]); rc = 1; goto meta_command_exit; @@ -10706,7 +10738,8 @@ static int do_meta_command(char *zLine, ShellState *p){ double countIrreversible = sqlite3_column_double(pCheckStmt, 0); if( countIrreversible>0 ){ int sz = (int)(countIrreversible + 0.5); - sqlite3_fprintf(stderr,"Digest includes %d invalidly encoded text field%s.\n", + sqlite3_fprintf(stderr, + "Digest includes %d invalidly encoded text field%s.\n", sz, (sz>1)? "s": ""); } } @@ -10762,11 +10795,13 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_fprintf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]); sqlite3_fprintf(p->out, "%12.12s: %s\n","explain", p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off"); - sqlite3_fprintf(p->out, "%12.12s: %s\n","headers", azBool[p->showHeader!=0]); + sqlite3_fprintf(p->out, "%12.12s: %s\n","headers", + azBool[p->showHeader!=0]); if( p->mode==MODE_Column || (p->mode>=MODE_Markdown && p->mode<=MODE_Box) ){ - sqlite3_fprintf(p->out, "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode", + sqlite3_fprintf(p->out, + "%12.12s: %s --wrap %d --wordwrap %s --%squote\n", "mode", modeDescr[p->mode], p->cmOpts.iWrap, p->cmOpts.bWordWrap ? "on" : "off", p->cmOpts.bQuote ? "" : "no"); @@ -10914,7 +10949,8 @@ static int do_meta_command(char *zLine, ShellState *p){ for(i=0; iout, "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:""); + sqlite3_fprintf(p->out, + "%s%-*s", zSp, maxlen, azResult[j] ? azResult[j]:""); } sqlite3_fputs("\n", p->out); } @@ -11096,12 +11132,13 @@ static int do_meta_command(char *zLine, ShellState *p){ if( sqlite3_stricmp(zLabel, aLabel[jj].zLabel)==0 ) break; } if( jj>=ArraySize(aLabel) ){ - sqlite3_fprintf(stderr,"Error: no such optimization: \"%s\"\n", zLabel); - eputz("Should be one of:"); + sqlite3_fprintf(stderr, + "Error: no such optimization: \"%s\"\n", zLabel); + sqlite3_fputs("Should be one of:", stderr); for(jj=0; jjzDbFilename = ":memory:"; warnInmemoryDb = argc==1; #else - sqlite3_fprintf(stderr,"%s: Error: no database filename specified\n", Argv0); + sqlite3_fprintf(stderr, + "%s: Error: no database filename specified\n", Argv0); return 1; #endif } @@ -12931,7 +12973,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ if( zErrMsg!=0 ){ shellEmitError(zErrMsg); }else{ - sqlite3_fprintf(stderr,"Error: unable to process SQL: %s\n", azCmd[i]); + sqlite3_fprintf(stderr, + "Error: unable to process SQL: %s\n", azCmd[i]); } sqlite3_free(zErrMsg); if( rc==0 ) rc = 1; @@ -12951,7 +12994,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #else # define SHELL_CIO_CHAR_SET "" #endif - sqlite3_fprintf(stdout, "SQLite version %s %.19s%s\n" /*extra-version-info*/ + sqlite3_fprintf(stdout, + "SQLite version %s %.19s%s\n" /*extra-version-info*/ "Enter \".help\" for usage hints.\n", sqlite3_libversion(), sqlite3_sourceid(), SHELL_CIO_CHAR_SET); if( warnInmemoryDb ){ From 613c2ee21f7f497b6b3107e5804755d7dd268ffa Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 24 Sep 2024 21:54:37 +0000 Subject: [PATCH 20/50] Minor wasmfs speedtest1 build tweaks. Disable one wasmfs demo which was broken by Emscripten-side changes. FossilOrigin-Name: 5ccc85d8f5809d961602dff557dca1ed34f5db61203912387272034e4da02614 --- ext/wasm/index.html | 6 +++--- ext/wasm/mkwasmbuilds.c | 4 ++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/wasm/index.html b/ext/wasm/index.html index d12a3aa03f..a3d41f1a9c 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -125,10 +125,10 @@ the WASMFS build is available on this server (it is not by default) and that this server emits the COOP/COEP headers.
    -
  • scratchpad-wasmfs: + +
  • speedtest1-wasmfs: a variant of speedtest1 built solely for the wasmfs/opfs feature.
  • diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index 80ea675a32..0da005eeb7 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -92,7 +92,7 @@ static void mk_pre_post(const char *zName /* build name */, pf("pre-js.js.%s-%s.intermediary := $(dir.tmp)/pre-js.%s-%s.intermediary.js\n", zNM, zNM); pf("$(eval $(call C-PP.FILTER,$(pre-js.js.in),$(pre-js.js.%s-%s.intermediary)," - "$(c-pp.D.%s-%s)))\n", zNM, zNM); + "$(c-pp.D.%s-%s) -Dcustom-Module.instantiateModule))\n", zNM, zNM); pf("$(pre-js.js.%s-%s): $(pre-js.js.%s-%s.intermediary)\n", zNM, zNM); pf("\tcp $(pre-js.js.%s-%s.intermediary) $@\n", zNM); @@ -230,6 +230,6 @@ int main(void){ "-sEXPORT_ES6 -sUSE_ES6_IMPORT_META"); mk_pre_post("speedtest1","vanilla", 0); - mk_pre_post("speedtest1-wasmfs","esm", 0); + mk_pre_post("speedtest1-wasmfs","esm", "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs"); return rc; } diff --git a/manifest b/manifest index f59d1f2c69..47e74610ab 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\stweaks\sin\smkwasmbuilds.c. -D 2024-09-24T13:00:21.657 +C Minor\swasmfs\sspeedtest1\sbuild\stweaks.\sDisable\sone\swasmfs\sdemo\swhich\swas\sbroken\sby\sEmscripten-side\schanges. +D 2024-09-24T21:54:37.941 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -658,10 +658,10 @@ F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 F ext/wasm/fiddle/index.html 739e0b75bc592679665d25e2f7649d2b8b2db678f3b41a772a8720b609b8482d F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29aeff8507511f -F ext/wasm/index.html 4337f495416756802669f69f9f9f3df9f87ee4c1918e6718719b4b5718e4713a +F ext/wasm/index.html e4bbffdb3d40eff12b3f9c7abedef91787e2935620b7f8d40f2c774b80ad8fa9 F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/mkwasmbuilds.c cd280876e43fb7d9a1bd55c55af9428304227885016f94c45c50ea97d98c0c2a +F ext/wasm/mkwasmbuilds.c 0619a960ae36a62dffe5be4781266a8f8b3d5bb9159e3bbbce1120cbe7665f2d F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -2211,8 +2211,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 5d4a090230d1d7609e70b9c28d662dc8b0f8dd4d70a254f3ce6e449c68a25897 -R a76d989228adf2ea2f12f585c2ad0411 +P cee43280727435440b9e01b302a790a1a102aea930bc821ebc737ea519458cef +R 3ad4aa454386a8a2c5afddc12db2471b U stephan -Z 9712f926f8fbe47c6917bc9e17888ee6 +Z 5b453b3ba6239edcf196a762c7d96ef5 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fcdc1c4022..eb3623a412 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cee43280727435440b9e01b302a790a1a102aea930bc821ebc737ea519458cef +5ccc85d8f5809d961602dff557dca1ed34f5db61203912387272034e4da02614 From 38b4158abae426f2efc610e4c7916931d8e03da1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 11:27:59 +0000 Subject: [PATCH 21/50] Use sqlite3_fgets() instead of fgetc() to end the startup debugging pause in the CLI. FossilOrigin-Name: 869b3c05e852a797b5801a81d30a1f7955c31afad0274327f7af2284b555f23a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 97936fe65a..590b028e17 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\strunk\senhancements,\sand\sespecially\sthe\szero-\sand\sdouble-width\scharacter\nprocessing\sfor\scolumnar\soutputs\sinto\sthe\scli-stdlib\sbranch. -D 2024-09-25T09:43:05.208 +C Use\ssqlite3_fgets()\sinstead\sof\sfgetc()\sto\send\sthe\sstartup\sdebugging\spause\nin\sthe\sCLI. +D 2024-09-25T11:27:59.291 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 3eb4e28de9e629adba14f2314c0051ea462770fdc04972f15a3922810fec5959 +F src/shell.c.in 4ff7790dc89c0ca7f7a0f1921b34ed01d78c70e1c8d080659ebaecdca298411f F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f3fdf76a0d3abeb5202f2b6f26318815396da7df680073955bde60b13f84e797 9592b9ba3ad7a842cdd4c4010da278485a6fdec7e811bda01ebe640162a8c3b6 -R cb8cb8b7debcfd75af761c484fdbc0a1 +P d6262a4bcd7b0334b23ae4d194ca2bce7c6554ee6c678666b24c830e4c14a467 +R d977d49e5dea1a4e01fec0c001abe012 U drh -Z e3c77b1ca9fc0efcd7f2507f7b7e048d +Z 0a28ca13fa93e1f632f49b48601d4127 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 8afc0d5af4..1375b7c7d3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d6262a4bcd7b0334b23ae4d194ca2bce7c6554ee6c678666b24c830e4c14a467 +869b3c05e852a797b5801a81d30a1f7955c31afad0274327f7af2284b555f23a diff --git a/src/shell.c.in b/src/shell.c.in index cdcba084da..667f3e2d1f 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12672,10 +12672,11 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ #if !defined(_WIN32_WCE) if( getenv("SQLITE_DEBUG_BREAK") ){ if( isatty(0) && isatty(2) ){ + char zLine[100]; sqlite3_fprintf(stderr, - "attach debugger to process %d and press any key to continue.\n", + "attach debugger to process %d and press ENTER to continue...", GETPID()); - fgetc(stdin); + sqlite3_fgets(zLine, sizeof(zLine), stdin); }else{ #if defined(_WIN32) || defined(WIN32) #if SQLITE_OS_WINRT From 853520ddbf85b29db418cc283648e4eac0f62a83 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 11:38:00 +0000 Subject: [PATCH 22/50] Fix stray fputs() calls in the CLI. FossilOrigin-Name: 1ee3fa0f0e87a61b5700abd56547c4acefe999317b0d53d66d890d9e09d8b7d9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 19 ++++++++++--------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 590b028e17..9b7a96878f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\ssqlite3_fgets()\sinstead\sof\sfgetc()\sto\send\sthe\sstartup\sdebugging\spause\nin\sthe\sCLI. -D 2024-09-25T11:27:59.291 +C Fix\sstray\sfputs()\scalls\sin\sthe\sCLI. +D 2024-09-25T11:38:00.160 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 4ff7790dc89c0ca7f7a0f1921b34ed01d78c70e1c8d080659ebaecdca298411f +F src/shell.c.in d91ad1c7b7c00cfe2d5f0577016fa31411b238b0a8eba232087265c89ed134e2 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d6262a4bcd7b0334b23ae4d194ca2bce7c6554ee6c678666b24c830e4c14a467 -R d977d49e5dea1a4e01fec0c001abe012 +P 869b3c05e852a797b5801a81d30a1f7955c31afad0274327f7af2284b555f23a +R 65de7bdaddb9c81ab30a8bc4f548eed2 U drh -Z 0a28ca13fa93e1f632f49b48601d4127 +Z fec9edb9be260bf1b825cec9b6314a72 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1375b7c7d3..19e0615510 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -869b3c05e852a797b5801a81d30a1f7955c31afad0274327f7af2284b555f23a +1ee3fa0f0e87a61b5700abd56547c4acefe999317b0d53d66d890d9e09d8b7d9 diff --git a/src/shell.c.in b/src/shell.c.in index 667f3e2d1f..6dba6e8c33 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2891,14 +2891,14 @@ static int shell_callback( if( azArg==0 ) break; if( p->cnt==0 && p->showHeader ){ for(i=0; i0 ) fputs(p->colSeparator, p->out); + if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); output_quoted_string(p->out, azCol[i]); } - fputs(p->rowSeparator, p->out); + sqlite3_fputs(p->rowSeparator, p->out); } p->cnt++; for(i=0; i0 ) fputs(p->colSeparator, p->out); + if( i>0 ) sqlite3_fputs(p->colSeparator, p->out); if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){ sqlite3_fputs("NULL", p->out); }else if( aiType && aiType[i]==SQLITE_TEXT ){ @@ -2920,7 +2920,7 @@ static int shell_callback( output_quoted_string(p->out, azArg[i]); } } - fputs(p->rowSeparator, p->out); + sqlite3_fputs(p->rowSeparator, p->out); break; } case MODE_Ascii: { @@ -4104,7 +4104,7 @@ static void exec_prepared_stmt_columnar( } for(i=0; iout, p->actualWidth[i]); - fputs(i==nColumn-1?"\n":" ", p->out); + sqlite3_fputs(i==nColumn-1?"\n":" ", p->out); } } break; @@ -4113,7 +4113,7 @@ static void exec_prepared_stmt_columnar( colSep = " | "; rowSep = " |\n"; print_row_separator(p, nColumn, "+"); - fputs("| ", p->out); + sqlite3_fputs("| ", p->out); for(i=0; iactualWidth[i]; n = strlenChar(azData[i]); @@ -4127,7 +4127,7 @@ static void exec_prepared_stmt_columnar( case MODE_Markdown: { colSep = " | "; rowSep = " |\n"; - fputs("| ", p->out); + sqlite3_fputs("| ", p->out); for(i=0; iactualWidth[i]; n = strlenChar(azData[i]); @@ -4274,7 +4274,7 @@ static void exec_prepared_stmt( } while( SQLITE_ROW == rc ); sqlite3_free(pData); if( pArg->cMode==MODE_Json ){ - fputs("]\n", pArg->out); + sqlite3_fputs("]\n", pArg->out); }else if( pArg->cMode==MODE_Count ){ char zBuf[200]; sqlite3_snprintf(sizeof(zBuf), zBuf, "%llu row%s\n", @@ -12845,7 +12845,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ default: sqlite3_config(SQLITE_CONFIG_SERIALIZED); break; } }else if( cli_strcmp(z,"-vfstrace")==0 ){ - vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1); + vfstrace_register("trace",0,(int(*)(const char*,void*))sqlite3_fputs, + stderr,1); bEnableVfstrace = 1; #ifdef SQLITE_ENABLE_MULTIPLEX }else if( cli_strcmp(z,"-multiplex")==0 ){ From 9e59c06fb1644fed1499b65cbe547b1eb07bc6ea Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 12:56:44 +0000 Subject: [PATCH 23/50] Always include a UTF-8 BOM at the beginning of the output CSV when using the ".excel" command on Windows, as the actual Excel program requires the BOM in order to work correctly. FossilOrigin-Name: 04727fc00207325a76a5d5f20549c00232810ac727dedb70bc9e8112e60b3f56 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 9b7a96878f..1494e6c021 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sstray\sfputs()\scalls\sin\sthe\sCLI. -D 2024-09-25T11:38:00.160 +C Always\sinclude\sa\sUTF-8\sBOM\sat\sthe\sbeginning\sof\sthe\soutput\sCSV\swhen\susing\nthe\s".excel"\scommand\son\sWindows,\sas\sthe\sactual\sExcel\sprogram\srequires\sthe\nBOM\sin\sorder\sto\swork\scorrectly. +D 2024-09-25T12:56:44.564 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in d91ad1c7b7c00cfe2d5f0577016fa31411b238b0a8eba232087265c89ed134e2 +F src/shell.c.in be499bb6bcd951a7fa9480588a824a03cef863c334f1843a2f4b76bcf31bd616 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 869b3c05e852a797b5801a81d30a1f7955c31afad0274327f7af2284b555f23a -R 65de7bdaddb9c81ab30a8bc4f548eed2 +P 1ee3fa0f0e87a61b5700abd56547c4acefe999317b0d53d66d890d9e09d8b7d9 +R aa31813957ce0d0538591043958b4e17 U drh -Z fec9edb9be260bf1b825cec9b6314a72 +Z 487c96328e404c2d5a7c68c4fa573337 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 19e0615510..31a0367380 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ee3fa0f0e87a61b5700abd56547c4acefe999317b0d53d66d890d9e09d8b7d9 +04727fc00207325a76a5d5f20549c00232810ac727dedb70bc9e8112e60b3f56 diff --git a/src/shell.c.in b/src/shell.c.in index 6dba6e8c33..c6beeee0da 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -9941,6 +9941,10 @@ static int do_meta_command(char *zLine, ShellState *p){ p->mode = MODE_Csv; sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma); sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_CrLf); +#ifdef _WIN32 + zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does + ** not work without it. */ +#endif }else{ /* text editor mode */ newTempFile(p, "txt"); From 2a9254cf2c9412da3994d6e11f556ba507dd66c2 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 13:29:03 +0000 Subject: [PATCH 24/50] Add the "www" output mode that include <table> in the HTML output. Add the ".www" command and the "-w" option to ".once". FossilOrigin-Name: b06fd9e6bcce09f12c994dc34f329a8d267ea0601bb07c9b00903c5017d55d42 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 44 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 1494e6c021..c421c9dd6a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Always\sinclude\sa\sUTF-8\sBOM\sat\sthe\sbeginning\sof\sthe\soutput\sCSV\swhen\susing\nthe\s".excel"\scommand\son\sWindows,\sas\sthe\sactual\sExcel\sprogram\srequires\sthe\nBOM\sin\sorder\sto\swork\scorrectly. -D 2024-09-25T12:56:44.564 +C Add\sthe\s"www"\soutput\smode\sthat\sinclude\s<table>\sin\sthe\sHTML\soutput.\nAdd\sthe\s".www"\scommand\sand\sthe\s"-w"\soption\sto\s".once". +D 2024-09-25T13:29:03.338 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in be499bb6bcd951a7fa9480588a824a03cef863c334f1843a2f4b76bcf31bd616 +F src/shell.c.in 9781ab726a108a10f8722d0d5e10c548d6f797ceef8d1a257a4e2cdc107bffc0 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1ee3fa0f0e87a61b5700abd56547c4acefe999317b0d53d66d890d9e09d8b7d9 -R aa31813957ce0d0538591043958b4e17 +P 04727fc00207325a76a5d5f20549c00232810ac727dedb70bc9e8112e60b3f56 +R a9ce986cea2b862753a371f08d91ab92 U drh -Z 487c96328e404c2d5a7c68c4fa573337 +Z cd53dd6e20071a9c7b2de3e7e318715b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 31a0367380..2fedfa4050 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -04727fc00207325a76a5d5f20549c00232810ac727dedb70bc9e8112e60b3f56 +b06fd9e6bcce09f12c994dc34f329a8d267ea0601bb07c9b00903c5017d55d42 diff --git a/src/shell.c.in b/src/shell.c.in index c6beeee0da..9581c5c3cb 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1596,6 +1596,7 @@ static ShellState shellState; #define MODE_Count 17 /* Output only a count of the rows of output */ #define MODE_Off 18 /* No query output shown */ #define MODE_ScanExp 19 /* Like MODE_Explain, but for ".scanstats vm" */ +#define MODE_Www 20 /* Full web-page output */ static const char *modeDescr[] = { "line", @@ -1616,7 +1617,9 @@ static const char *modeDescr[] = { "table", "box", "count", - "off" + "off", + "scanexp", + "www", }; /* @@ -2728,8 +2731,13 @@ static int shell_callback( } break; } + case MODE_Www: case MODE_Html: { - if( p->cnt++==0 && p->showHeader ){ + if( p->cnt==0 && p->cMode==MODE_Www ){ + sqlite3_fputs( + "\n",p->out); + } + if( p->cnt==0 && p->showHeader ){ sqlite3_fputs("", p->out); for(i=0; i", p->out); @@ -2738,6 +2746,7 @@ static int shell_callback( } sqlite3_fputs("\n", p->out); } + p->cnt++; if( azArg==0 ) break; sqlite3_fputs("", p->out); for(i=0; icMode==MODE_Json ){ sqlite3_fputs("]\n", pArg->out); + }else if( pArg->cMode==MODE_Www ){ + sqlite3_fputs("
    \n", pArg->out); }else if( pArg->cMode==MODE_Count ){ char zBuf[200]; sqlite3_snprintf(sizeof(zBuf), zBuf, "%llu row%s\n", @@ -5029,6 +5040,7 @@ static const char *(azHelp[]) = { " If FILE begins with '|' then open as a pipe", " --bom Put a UTF8 byte-order mark at the beginning", " -e Send output to the system text editor", + " -w Send output as HTML to a web browser (same as \".www\")", " -x Send output as CSV to a spreadsheet (same as \".excel\")", /* Note that .open is (partially) available in WASM builds but is ** currently only intended to be used by the fiddle tool, not @@ -5165,6 +5177,9 @@ static const char *(azHelp[]) = { ".vfsname ?AUX? Print the name of the VFS stack", ".width NUM1 NUM2 ... Set minimum column widths for columnar output", " Negative values right-justify", +#ifndef SQLITE_SHELL_FIDDLE + ".www Display output of the next command in web browser", +#endif }; /* @@ -9702,6 +9717,8 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); }else if( cli_strncmp(zMode,"html",n2)==0 ){ p->mode = MODE_Html; + }else if( cli_strncmp(zMode,"www",n2)==0 ){ + p->mode = MODE_Www; }else if( cli_strncmp(zMode,"tcl",n2)==0 ){ p->mode = MODE_Tcl; sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space); @@ -9873,12 +9890,13 @@ static int do_meta_command(char *zLine, ShellState *p){ && (cli_strncmp(azArg[0], "output", n)==0 || cli_strncmp(azArg[0], "once", n)==0)) || (c=='e' && n==5 && cli_strcmp(azArg[0],"excel")==0) + || (c=='w' && n==3 && cli_strcmp(azArg[0],"www")==0) ){ char *zFile = 0; int bTxtMode = 0; int i; int eMode = 0; - int bOnce = 0; /* 0: .output, 1: .once, 2: .excel */ + int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */ static const char *zBomUtf8 = "\xef\xbb\xbf"; const char *zBom = 0; @@ -9886,6 +9904,9 @@ static int do_meta_command(char *zLine, ShellState *p){ if( c=='e' ){ eMode = 'x'; bOnce = 2; + }else if( c=='w' ){ + eMode = 'w'; + bOnce = 2; }else if( cli_strncmp(azArg[0],"once",n)==0 ){ bOnce = 1; } @@ -9895,10 +9916,12 @@ static int do_meta_command(char *zLine, ShellState *p){ if( z[1]=='-' ) z++; if( cli_strcmp(z,"-bom")==0 ){ zBom = zBomUtf8; - }else if( c!='e' && cli_strcmp(z,"-x")==0 ){ + }else if( c=='o' && cli_strcmp(z,"-x")==0 ){ eMode = 'x'; /* spreadsheet */ - }else if( c!='e' && cli_strcmp(z,"-e")==0 ){ + }else if( c=='o' && cli_strcmp(z,"-e")==0 ){ eMode = 'e'; /* text editor */ + }else if( c=='o' && cli_strcmp(z,"-w")==0 ){ + eMode = 'w'; /* Web browser */ }else{ sqlite3_fprintf(p->out, "ERROR: unknown option: \"%s\". Usage:\n", azArg[i]); @@ -9906,7 +9929,7 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; goto meta_command_exit; } - }else if( zFile==0 && eMode!='e' && eMode!='x' ){ + }else if( zFile==0 && eMode==0 ){ zFile = sqlite3_mprintf("%s", z); if( zFile && zFile[0]=='|' ){ while( i+1doXdgOpen = 1; outputModePush(p); if( eMode=='x' ){ @@ -9945,6 +9968,11 @@ static int do_meta_command(char *zLine, ShellState *p){ zBom = zBomUtf8; /* Always include the BOM on Windows, as Excel does ** not work without it. */ #endif + }else if( eMode=='w' ){ + /* web-browser mode. */ + newTempFile(p, "html"); + p->mode = MODE_Www; + bTxtMode = 1; }else{ /* text editor mode */ newTempFile(p, "txt"); @@ -12979,6 +13007,8 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ i++; }else if( cli_strcmp(z,"-html")==0 ){ data.mode = MODE_Html; + }else if( cli_strcmp(z,"-www")==0 ){ + data.mode = MODE_Www; }else if( cli_strcmp(z,"-list")==0 ){ data.mode = MODE_List; }else if( cli_strcmp(z,"-quote")==0 ){ From 62d96919f6dfc42f441311b000d2726e5077f8c1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 13:56:05 +0000 Subject: [PATCH 25/50] Improvements to ".www" and ".output -w" so that text that is not part of query output is shown using <pre>. FossilOrigin-Name: f8ef65c52305b2180ec56760f5762ac5638584cd504c79d57e86f61736901aa4 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 21 +++++++++++++++------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index c421c9dd6a..e7cdcc4770 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"www"\soutput\smode\sthat\sinclude\s<table>\sin\sthe\sHTML\soutput.\nAdd\sthe\s".www"\scommand\sand\sthe\s"-w"\soption\sto\s".once". -D 2024-09-25T13:29:03.338 +C Improvements\sto\s".www"\sand\s".output\s-w"\sso\sthat\stext\sthat\sis\snot\spart\sof\nquery\soutput\sis\sshown\susing\s<pre>. +D 2024-09-25T13:56:05.407 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 9781ab726a108a10f8722d0d5e10c548d6f797ceef8d1a257a4e2cdc107bffc0 +F src/shell.c.in 053df097aad75a1ecdff3f71c8452efffc889cc3b88907c93325360340d8b977 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 04727fc00207325a76a5d5f20549c00232810ac727dedb70bc9e8112e60b3f56 -R a9ce986cea2b862753a371f08d91ab92 +P b06fd9e6bcce09f12c994dc34f329a8d267ea0601bb07c9b00903c5017d55d42 +R 322d10259a92b6303d31355dabde0d96 U drh -Z cd53dd6e20071a9c7b2de3e7e318715b +Z 8156bb15fa45205c46d5412fa2ec3c8c # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 2fedfa4050..07c5b4e27c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b06fd9e6bcce09f12c994dc34f329a8d267ea0601bb07c9b00903c5017d55d42 +f8ef65c52305b2180ec56760f5762ac5638584cd504c79d57e86f61736901aa4 diff --git a/src/shell.c.in b/src/shell.c.in index 9581c5c3cb..3bba26c7dd 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2735,7 +2735,10 @@ static int shell_callback( case MODE_Html: { if( p->cnt==0 && p->cMode==MODE_Www ){ sqlite3_fputs( - "\n",p->out); + "\n" + "
    \n" + ,p->out + ); } if( p->cnt==0 && p->showHeader ){ sqlite3_fputs("", p->out); @@ -4285,7 +4288,7 @@ static void exec_prepared_stmt( if( pArg->cMode==MODE_Json ){ sqlite3_fputs("]\n", pArg->out); }else if( pArg->cMode==MODE_Www ){ - sqlite3_fputs("
    \n", pArg->out); + sqlite3_fputs("\n
    \n", pArg->out);
           }else if( pArg->cMode==MODE_Count ){
             char zBuf[200];
             sqlite3_snprintf(sizeof(zBuf), zBuf, "%llu row%s\n",
    @@ -6409,6 +6412,13 @@ static void output_redir(ShellState *p, FILE *pfNew){
         sqlite3_fputs("Output already redirected.\n", stderr);
       }else{
         p->out = pfNew;
    +    if( p->mode==MODE_Www ){
    +      sqlite3_fputs(
    +        "\n"
    +        "
    \n",
    +        p->out
    +      );
    +    }
       }
     }
     
    @@ -6425,6 +6435,9 @@ static void output_reset(ShellState *p){
         pclose(p->out);
     #endif
       }else{
    +    if( p->mode==MODE_Www ){
    +      sqlite3_fputs("
    \n", p->out); + } output_file_close(p->out); #ifndef SQLITE_NOHAVE_SYSTEM if( p->doXdgOpen ){ @@ -9717,8 +9730,6 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_snprintf(sizeof(p->rowSeparator), p->rowSeparator, SEP_Row); }else if( cli_strncmp(zMode,"html",n2)==0 ){ p->mode = MODE_Html; - }else if( cli_strncmp(zMode,"www",n2)==0 ){ - p->mode = MODE_Www; }else if( cli_strncmp(zMode,"tcl",n2)==0 ){ p->mode = MODE_Tcl; sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Space); @@ -13007,8 +13018,6 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ i++; }else if( cli_strcmp(z,"-html")==0 ){ data.mode = MODE_Html; - }else if( cli_strcmp(z,"-www")==0 ){ - data.mode = MODE_Www; }else if( cli_strcmp(z,"-list")==0 ){ data.mode = MODE_List; }else if( cli_strcmp(z,"-quote")==0 ){ From 95f35b64da4e4507c3fd117f91f7ee2069c65723 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 14:09:47 +0000 Subject: [PATCH 26/50] Redirect timer output just like any other text. FossilOrigin-Name: 3b5ae21074958788b23ccf449e52fbbad1f81779e07a6ca62ad8395f88a37286 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/manifest b/manifest index e7cdcc4770..affcaf289a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\s".www"\sand\s".output\s-w"\sso\sthat\stext\sthat\sis\snot\spart\sof\nquery\soutput\sis\sshown\susing\s<pre>. -D 2024-09-25T13:56:05.407 +C Redirect\stimer\soutput\sjust\slike\sany\sother\stext. +D 2024-09-25T14:09:47.920 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 053df097aad75a1ecdff3f71c8452efffc889cc3b88907c93325360340d8b977 +F src/shell.c.in 9e32f35af780b0369cac93730d6c7e4440c7ec8a7382525da913e406491a1e46 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b06fd9e6bcce09f12c994dc34f329a8d267ea0601bb07c9b00903c5017d55d42 -R 322d10259a92b6303d31355dabde0d96 +P f8ef65c52305b2180ec56760f5762ac5638584cd504c79d57e86f61736901aa4 +R ac074bfeea03930c231c06a9d210f518 U drh -Z 8156bb15fa45205c46d5412fa2ec3c8c +Z 51901a5607650ec168b6e659dbb210c8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 07c5b4e27c..464094fc1b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f8ef65c52305b2180ec56760f5762ac5638584cd504c79d57e86f61736901aa4 +3b5ae21074958788b23ccf449e52fbbad1f81779e07a6ca62ad8395f88a37286 diff --git a/src/shell.c.in b/src/shell.c.in index 3bba26c7dd..1c81a0bbab 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -321,12 +321,12 @@ static double timeDiff(struct timeval *pStart, struct timeval *pEnd){ /* ** Print the timing results. */ -static void endTimer(void){ +static void endTimer(FILE *out){ if( enableTimer ){ sqlite3_int64 iEnd = timeOfDay(); struct rusage sEnd; getrusage(RUSAGE_SELF, &sEnd); - sqlite3_fprintf(stdout, "Run Time: real %.3f user %f sys %f\n", + sqlite3_fprintf(out, "Run Time: real %.3f user %f sys %f\n", (iEnd - iBegin)*0.001, timeDiff(&sBegin.ru_utime, &sEnd.ru_utime), timeDiff(&sBegin.ru_stime, &sEnd.ru_stime)); @@ -334,7 +334,7 @@ static void endTimer(void){ } #define BEGIN_TIMER beginTimer() -#define END_TIMER endTimer() +#define END_TIMER(X) endTimer(X) #define HAS_TIMER 1 #elif (defined(_WIN32) || defined(WIN32)) @@ -400,12 +400,12 @@ static double timeDiff(FILETIME *pStart, FILETIME *pEnd){ /* ** Print the timing results. */ -static void endTimer(void){ +static void endTimer(FILE *out){ if( enableTimer && getProcessTimesAddr){ FILETIME ftCreation, ftExit, ftKernelEnd, ftUserEnd; sqlite3_int64 ftWallEnd = timeOfDay(); getProcessTimesAddr(hProcess,&ftCreation,&ftExit,&ftKernelEnd,&ftUserEnd); - sqlite3_fprintf(stdout, "Run Time: real %.3f user %f sys %f\n", + sqlite3_fprintf(out, "Run Time: real %.3f user %f sys %f\n", (ftWallEnd - ftWallBegin)*0.001, timeDiff(&ftUserBegin, &ftUserEnd), timeDiff(&ftKernelBegin, &ftKernelEnd)); @@ -413,12 +413,12 @@ static void endTimer(void){ } #define BEGIN_TIMER beginTimer() -#define END_TIMER endTimer() +#define END_TIMER(X) endTimer(X) #define HAS_TIMER hasTimer() #else #define BEGIN_TIMER -#define END_TIMER +#define END_TIMER(X) /*no-op*/ #define HAS_TIMER 0 #endif @@ -12157,7 +12157,7 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ if( p->flgProgress & SHELL_PROGRESS_RESET ) p->nProgress = 0; BEGIN_TIMER; rc = shell_exec(p, zSql, &zErrMsg); - END_TIMER; + END_TIMER(p->out); if( rc || zErrMsg ){ char zPrefix[100]; const char *zErrorTail; From 7119a6c16b046a35b690fc8c56c8ee26a35cbad9 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 15:26:37 +0000 Subject: [PATCH 27/50] Have the zipfile and fileio extensions use sqlite3_stdio.c when it is available - such as when those extensions are preloaded into the CLI. FossilOrigin-Name: 74bbb2b2b4507d9acbd91209a2ce341968e9ff64f3aebe9e817bfe488d39ae03 --- ext/misc/fileio.c | 11 +++++++++-- ext/misc/zipfile.c | 12 ++++++++++-- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c index c2ecab0b25..483ef0187f 100644 --- a/ext/misc/fileio.c +++ b/ext/misc/fileio.c @@ -110,6 +110,13 @@ SQLITE_EXTENSION_INIT1 #include #include +/* When used as part of the CLI, the sqlite3_stdio.h module will have +** been included before this one. In that case use the sqlite3_stdio.h +** #defines. If not, create our own for fopen(). +*/ +#ifndef _SQLITE3_STDIO_H_ +# define sqlite3_fopen fopen +#endif /* ** Structure of the fsdir() table-valued function @@ -142,7 +149,7 @@ static void readFileContents(sqlite3_context *ctx, const char *zName){ sqlite3 *db; int mxBlob; - in = fopen(zName, "rb"); + in = sqlite3_fopen(zName, "rb"); if( in==0 ){ /* File does not exist or is unreadable. Leave the result set to NULL. */ return; @@ -397,7 +404,7 @@ static int writeFile( sqlite3_int64 nWrite = 0; const char *z; int rc = 0; - FILE *out = fopen(zFile, "wb"); + FILE *out = sqlite3_fopen(zFile, "wb"); if( out==0 ) return 1; z = (const char*)sqlite3_value_blob(pData); if( z ){ diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index fd6d13bc38..2377457dfb 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -35,6 +35,14 @@ SQLITE_EXTENSION_INIT1 #include +/* When used as part of the CLI, the sqlite3_stdio.h module will have +** been included before this one. In that case use the sqlite3_stdio.h +** #defines. If not, create our own for fopen(). +*/ +#ifndef _SQLITE3_STDIO_H_ +# define sqlite3_fopen fopen +#endif + #ifndef SQLITE_OMIT_VIRTUALTABLE #ifndef SQLITE_AMALGAMATION @@ -1291,7 +1299,7 @@ static int zipfileFilter( } if( 0==pTab->pWriteFd && 0==bInMemory ){ - pCsr->pFile = zFile ? fopen(zFile, "rb") : 0; + pCsr->pFile = zFile ? sqlite3_fopen(zFile, "rb") : 0; if( pCsr->pFile==0 ){ zipfileCursorErr(pCsr, "cannot open file: %s", zFile); rc = SQLITE_ERROR; @@ -1481,7 +1489,7 @@ static int zipfileBegin(sqlite3_vtab *pVtab){ ** structure into memory. During the transaction any new file data is ** appended to the archive file, but the central directory is accumulated ** in main-memory until the transaction is committed. */ - pTab->pWriteFd = fopen(pTab->zFile, "ab+"); + pTab->pWriteFd = sqlite3_fopen(pTab->zFile, "ab+"); if( pTab->pWriteFd==0 ){ pTab->base.zErrMsg = sqlite3_mprintf( "zipfile: failed to open file %s for writing", pTab->zFile diff --git a/manifest b/manifest index affcaf289a..76054939a5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Redirect\stimer\soutput\sjust\slike\sany\sother\stext. -D 2024-09-25T14:09:47.920 +C Have\sthe\szipfile\sand\sfileio\sextensions\suse\ssqlite3_stdio.c\swhen\sit\sis\navailable\s-\ssuch\sas\swhen\sthose\sextensions\sare\spreloaded\sinto\sthe\sCLI. +D 2024-09-25T15:26:37.435 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -399,7 +399,7 @@ F ext/misc/dbdump.c b8592f6f2da292c62991a13864a60d6c573c47a9cc58362131b9e6a64f82 F ext/misc/decimal.c 172cf81a8634e6a0f0bedaf71a8372fee63348cf5a3c4e1b78bb233c35889fdc F ext/misc/eval.c 04bc9aada78c888394204b4ed996ab834b99726fb59603b0ee3ed6e049755dc1 F ext/misc/explain.c 606100185fb90d6a1eade1ed0414d53503c86820d8956a06e3b0a56291894f2b -F ext/misc/fileio.c 001179b29735639c607586c9e9398c92505c0833de06eefc27e13acf60dd1577 +F ext/misc/fileio.c e6b34db4df4b55b96265086c0010264e257b6eab1644e665697a6da587659403 F ext/misc/fossildelta.c 8c026e086e406e2b69947f1856fa3b848fff5379962276430d10085b8756b05a F ext/misc/fuzzer.c 8b28acf1a7e95d50e332bdd47e792ff27054ad99d3f9bc2e91273814d4b31a5a F ext/misc/ieee754.c 62a90978204d2c956d5036eb89e548e736ca5fac0e965912867ddd7bb833256d @@ -441,7 +441,7 @@ F ext/misc/vfstrace.c ac76a4ac4d907774fd423cc2b61410c756f9d0782e27cf6032e058594a F ext/misc/vtablog.c 1100250ce8782db37c833e3a9a5c9a3ecf1af5e15b8325572b82e6e0a138ffb5 F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f65b4fc0668 -F ext/misc/zipfile.c 5a3bf1b9cccb8e0da2389fe9e39e9c7f2b1351474b7e5090635f817d495eee3f +F ext/misc/zipfile.c b62147ac4985eaac4e368d529b1f4f43ad6bc9ac13d6805d907fff3afdac64d3 F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c 801450b24eaf14440d8fd20385aacc751d5c9d6123398df41b1b5aa804bf4ce8 F ext/rbu/rbu1.test 25870dd7db7eb5597e2b4d6e29e7a7e095abf332660f67d89959552ce8f8f255 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f8ef65c52305b2180ec56760f5762ac5638584cd504c79d57e86f61736901aa4 -R ac074bfeea03930c231c06a9d210f518 +P 3b5ae21074958788b23ccf449e52fbbad1f81779e07a6ca62ad8395f88a37286 +R 5afd3bdce6fbcc9f56c686c2625824c5 U drh -Z 51901a5607650ec168b6e659dbb210c8 +Z a729cfecd90e8d587c0a925f42031223 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 464094fc1b..9f435ff8f9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3b5ae21074958788b23ccf449e52fbbad1f81779e07a6ca62ad8395f88a37286 +74bbb2b2b4507d9acbd91209a2ce341968e9ff64f3aebe9e817bfe488d39ae03 From 878db7b099ed8928ec18a584a2efa7d9d3ff4f45 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 15:55:52 +0000 Subject: [PATCH 28/50] Add the --plain option to the ".www" dot-command. FossilOrigin-Name: a9209519f612e66cfe11c89e70efd8285a0185ac0d3e5795846aafbd05d7a21f --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 23 ++++++++++++++++++----- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 76054939a5..85c44e231b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\sthe\szipfile\sand\sfileio\sextensions\suse\ssqlite3_stdio.c\swhen\sit\sis\navailable\s-\ssuch\sas\swhen\sthose\sextensions\sare\spreloaded\sinto\sthe\sCLI. -D 2024-09-25T15:26:37.435 +C Add\sthe\s--plain\soption\sto\sthe\s".www"\sdot-command. +D 2024-09-25T15:55:52.425 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 9e32f35af780b0369cac93730d6c7e4440c7ec8a7382525da913e406491a1e46 +F src/shell.c.in 405e15e6a57a224af0f6ff014cb45cbb8123178fa1a6e5cfb39d3540389d9207 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3b5ae21074958788b23ccf449e52fbbad1f81779e07a6ca62ad8395f88a37286 -R 5afd3bdce6fbcc9f56c686c2625824c5 +P 74bbb2b2b4507d9acbd91209a2ce341968e9ff64f3aebe9e817bfe488d39ae03 +R 9584e7093ca35da79a25d5e2b514ac01 U drh -Z a729cfecd90e8d587c0a925f42031223 +Z 9a391f06b77de429a8a012b5954b01a2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 9f435ff8f9..24a6899959 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -74bbb2b2b4507d9acbd91209a2ce341968e9ff64f3aebe9e817bfe488d39ae03 +a9209519f612e66cfe11c89e70efd8285a0185ac0d3e5795846aafbd05d7a21f diff --git a/src/shell.c.in b/src/shell.c.in index 1c81a0bbab..25e3aad519 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -5041,10 +5041,11 @@ static const char *(azHelp[]) = { #ifndef SQLITE_SHELL_FIDDLE ".once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE", " If FILE begins with '|' then open as a pipe", - " --bom Put a UTF8 byte-order mark at the beginning", - " -e Send output to the system text editor", - " -w Send output as HTML to a web browser (same as \".www\")", - " -x Send output as CSV to a spreadsheet (same as \".excel\")", + " --bom Put a UTF8 byte-order mark at the beginning", + " -e Send output to the system text editor", + " --plain Use text/plain output instead of HTML for -w option", + " -w Send output as HTML to a web browser (same as \".www\")", + " -x Send output as CSV to a spreadsheet (same as \".excel\")", /* Note that .open is (partially) available in WASM builds but is ** currently only intended to be used by the fiddle tool, not ** end users, so is "undocumented." */ @@ -5067,6 +5068,8 @@ static const char *(azHelp[]) = { " Options:", " --bom Prefix output with a UTF8 byte-order mark", " -e Send output to the system text editor", + " --plain Use text/plain for -w option", + " -w Send output to a web browser", " -x Send output as CSV to a spreadsheet", #endif ".parameter CMD ... Manage SQL parameter bindings", @@ -5182,6 +5185,7 @@ static const char *(azHelp[]) = { " Negative values right-justify", #ifndef SQLITE_SHELL_FIDDLE ".www Display output of the next command in web browser", + " --plain Show results as text/plain, not as HTML", #endif }; @@ -9908,6 +9912,7 @@ static int do_meta_command(char *zLine, ShellState *p){ int i; int eMode = 0; int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */ + int bPlain = 0; /* --plain option */ static const char *zBomUtf8 = "\xef\xbb\xbf"; const char *zBom = 0; @@ -9927,6 +9932,8 @@ static int do_meta_command(char *zLine, ShellState *p){ if( z[1]=='-' ) z++; if( cli_strcmp(z,"-bom")==0 ){ zBom = zBomUtf8; + }else if( cli_strcmp(z,"-plain")==0 ){ + bPlain = 1; }else if( c=='o' && cli_strcmp(z,"-x")==0 ){ eMode = 'x'; /* spreadsheet */ }else if( c=='o' && cli_strcmp(z,"-e")==0 ){ @@ -9982,7 +9989,7 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( eMode=='w' ){ /* web-browser mode. */ newTempFile(p, "html"); - p->mode = MODE_Www; + if( !bPlain ) p->mode = MODE_Www; bTxtMode = 1; }else{ /* text editor mode */ @@ -10019,6 +10026,12 @@ static int do_meta_command(char *zLine, ShellState *p){ rc = 1; } else { output_redir(p, pfFile); + if( bPlain && eMode=='w' ){ + sqlite3_fputs( + "\n\n\n", + pfFile + ); + } if( zBom ) sqlite3_fputs(zBom, pfFile); sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile); } From 66b3ed318b89d41a3484eb38bad43ccc255034a1 Mon Sep 17 00:00:00 2001 From: drh <> Date: Wed, 25 Sep 2024 16:11:27 +0000 Subject: [PATCH 29/50] Always show HTML table headers in ".www" output mode. FossilOrigin-Name: 660ca5ce6600d897cc2b00b9d39e5d993c1c0e71ec0d5dc706246c053a163281 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c.in | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 85c44e231b..1e84cd981f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--plain\soption\sto\sthe\s".www"\sdot-command. -D 2024-09-25T15:55:52.425 +C Always\sshow\sHTML\stable\sheaders\sin\s".www"\soutput\smode. +D 2024-09-25T16:11:27.958 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 405e15e6a57a224af0f6ff014cb45cbb8123178fa1a6e5cfb39d3540389d9207 +F src/shell.c.in 5a5881cbe128962b431bfd466ff408db6bf05b971db67200615be38745f0ceef F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 74bbb2b2b4507d9acbd91209a2ce341968e9ff64f3aebe9e817bfe488d39ae03 -R 9584e7093ca35da79a25d5e2b514ac01 +P a9209519f612e66cfe11c89e70efd8285a0185ac0d3e5795846aafbd05d7a21f +R 5a9e599155b273bd1e8c309df5248f6e U drh -Z 9a391f06b77de429a8a012b5954b01a2 +Z 4b89dbbffeeb17eaffa0b5d5ca63c4c0 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 24a6899959..53d2b13f11 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a9209519f612e66cfe11c89e70efd8285a0185ac0d3e5795846aafbd05d7a21f +660ca5ce6600d897cc2b00b9d39e5d993c1c0e71ec0d5dc706246c053a163281 diff --git a/src/shell.c.in b/src/shell.c.in index 25e3aad519..c848c4c235 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -2740,7 +2740,7 @@ static int shell_callback( ,p->out ); } - if( p->cnt==0 && p->showHeader ){ + if( p->cnt==0 && (p->showHeader || p->cMode==MODE_Www) ){ sqlite3_fputs("<TR>", p->out); for(i=0; i<nArg; i++){ sqlite3_fputs("<TH>", p->out); From b7ceffdadff6826711e2bbaba866821afcd99a22 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 26 Sep 2024 01:29:22 +0000 Subject: [PATCH 30/50] Fix shell test cases to account for recent additions to the ".help" output. FossilOrigin-Name: 54c22bc6165affbea0d1166a0912d19939300ccc4ae33a6b2ed8c510ab61c574 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/shell1.test | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 1e84cd981f..ea40af4ac6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Always\sshow\sHTML\stable\sheaders\sin\s".www"\soutput\smode. -D 2024-09-25T16:11:27.958 +C Fix\sshell\stest\scases\sto\saccount\sfor\srecent\sadditions\sto\sthe\s".help"\soutput. +D 2024-09-26T01:29:22.012 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -1628,7 +1628,7 @@ F test/sharedA.test 64bdd21216dda2c6a3bd3475348ccdc108160f34682c97f2f51c19fc0e21 F test/sharedB.test 1a84863d7a2204e0d42f2e1606577c5e92e4473fa37ea0f5bdf829e4bf8ee707 F test/shared_err.test 32634e404a3317eeb94abc7a099c556a346fdb8fb3858dbe222a4cbb8926a939 F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304 -F test/shell1.test 490bf9d0c7c9564fea318c46d49369f4690b825b584c9a544dbdccf61bc0babc +F test/shell1.test b02d628494fa284cdb2b7b2fecdadea96913796afd623f340a79d68f055dcb7e F test/shell2.test 01a01f76ed98088ce598794fbf5b359e148271541a8ddbf79d21cc353cc67a24 F test/shell3.test db1953a8e59d08e9240b7cc5948878e184f7eb2623591587f8fd1f1a5bd536d8 F test/shell4.test 522fdc628c55eff697b061504fb0a9e4e6dfc5d9087a633ab0f3dd11bcc4f807 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P a9209519f612e66cfe11c89e70efd8285a0185ac0d3e5795846aafbd05d7a21f -R 5a9e599155b273bd1e8c309df5248f6e +P 660ca5ce6600d897cc2b00b9d39e5d993c1c0e71ec0d5dc706246c053a163281 +R 3b1b1ac1efd2caefa25e8d6c9bf0ff2f U drh -Z 4b89dbbffeeb17eaffa0b5d5ca63c4c0 +Z 1e00c19e9c0388401e635e4bb988cbfe # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 53d2b13f11..fac43782cc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -660ca5ce6600d897cc2b00b9d39e5d993c1c0e71ec0d5dc706246c053a163281 +54c22bc6165affbea0d1166a0912d19939300ccc4ae33a6b2ed8c510ab61c574 diff --git a/test/shell1.test b/test/shell1.test index f355989c31..b4883e3521 100644 --- a/test/shell1.test +++ b/test/shell1.test @@ -516,6 +516,8 @@ do_test shell1-3.15.3 { Options: --bom Prefix output with a UTF8 byte-order mark -e Send output to the system text editor + --plain Use text/plain for -w option + -w Send output to a web browser -x Send output as CSV to a spreadsheet child process exited abnormally}} @@ -532,6 +534,8 @@ do_test shell1-3.16.2 { Options: --bom Prefix output with a UTF8 byte-order mark -e Send output to the system text editor + --plain Use text/plain for -w option + -w Send output to a web browser -x Send output as CSV to a spreadsheet child process exited abnormally}} From 2fb055366dfb68b20d313f628f180fe52801c20d Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 26 Sep 2024 13:12:19 +0000 Subject: [PATCH 31/50] Clarification of the meaning of the nByte parameter to sqlite3_prepare(). Comment and documentation change only - no changes to the code. FossilOrigin-Name: 92d71eee4f3a5edb3877c108d14972d80654982b0de3e635d9d008e9d3b6591f --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/sqlite.h.in | 8 ++++++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index e74bcacf3c..04cb434a6f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\sCLI,\sfor\scolumnar\soutput\sformats,\stry\sto\saccount\sfor\sthe\spresence\sof\nzero-width\sand\sdouble-width\scharacters\sin\sthe\soutput\sand\sadjust\scolumn\swidths\naccordingly. -D 2024-09-25T09:39:11.501 +C Clarification\sof\sthe\smeaning\sof\sthe\snByte\sparameter\sto\ssqlite3_prepare().\nComment\sand\sdocumentation\schange\sonly\s-\sno\schanges\sto\sthe\scode. +D 2024-09-26T13:12:19.952 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -769,7 +769,7 @@ F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe F src/shell.c.in 9b68a945f3aafc78eac1a256a4a588a9310dbc61a0cd60378c5b7a78f789af50 -F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c +F src/sqlite.h.in b20547021d20ba016c2fd0500f14f08a21ff23e64a0ed93e72ca0fecb9e1d0a0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 F src/sqliteInt.h 5978cbb11becc3ce6471015d770d95f694ece06336c496f691df1b02460e9cd5 @@ -2213,9 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 42bb941584a1ac922ee6b0b6ecadce71c9259555563cf49913a6f820f3f9b887 b217e3004b58af0e777726bdd652b999ad41815261299ef4ce8f8d2f6b0afe8d -R 5fcf6775e686fdd76943c66cce860cb0 -T +closed b217e3004b58af0e777726bdd652b999ad41815261299ef4ce8f8d2f6b0afe8d +P 9592b9ba3ad7a842cdd4c4010da278485a6fdec7e811bda01ebe640162a8c3b6 +R 0bed48c612190c1339a39e58e27e8cbd U drh -Z af457fc67e3efab459ef7260d9a5da46 +Z 38a364760cd51d772a2b987e6988323a # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 5d05a8c7ec..e3d4847c8a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9592b9ba3ad7a842cdd4c4010da278485a6fdec7e811bda01ebe640162a8c3b6 +92d71eee4f3a5edb3877c108d14972d80654982b0de3e635d9d008e9d3b6591f diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 5546793c94..72190beec5 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -4222,13 +4222,17 @@ int sqlite3_limit(sqlite3*, int id, int newVal); ** and sqlite3_prepare16_v3() use UTF-16. ** ** ^If the nByte argument is negative, then zSql is read up to the -** first zero terminator. ^If nByte is positive, then it is the -** number of bytes read from zSql. ^If nByte is zero, then no prepared +** first zero terminator. ^If nByte is positive, then it is the maximum +** number of bytes read from zSql. When nByte is positive, zSql is read +** up to the first zero terminator or until the nByte bytes have been read, +** whichever comes first. ^If nByte is zero, then no prepared ** statement is generated. ** If the caller knows that the supplied string is nul-terminated, then ** there is a small performance advantage to passing an nByte parameter that ** is the number of bytes in the input string <i>including</i> ** the nul-terminator. +** Note that nByte measure the length of the input in bytes, not +** characters, even for the UTF-16 inferfaces. ** ** ^If pzTail is not NULL then *pzTail is made to point to the first byte ** past the end of the first SQL statement in zSql. These routines only From 2c77d51dfe206fad8caf39a9788482cd96875e5b Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Thu, 26 Sep 2024 18:13:10 +0000 Subject: [PATCH 32/50] Resolve a harmless compiler warning in QNX builds. FossilOrigin-Name: 2916460179c6089375188c6e4e3cff1fca5bbbbb7280a10c919e09e75d1f11f8 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 04cb434a6f..bb39343c96 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Clarification\sof\sthe\smeaning\sof\sthe\snByte\sparameter\sto\ssqlite3_prepare().\nComment\sand\sdocumentation\schange\sonly\s-\sno\schanges\sto\sthe\scode. -D 2024-09-26T13:12:19.952 +C Resolve\sa\sharmless\scompiler\swarning\sin\sQNX\sbuilds. +D 2024-09-26T18:13:10.425 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -751,7 +751,7 @@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b8f8e448169304d83a7ed9db66a65732f3e63 F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06 F src/os_kv.c 4d39e1f1c180b11162c6dc4aa8ad34053873a639bac6baae23272fc03349986a F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d872107 -F src/os_unix.c 6e3e4fc75904ff85184091dbab996e6e35c1799e771788961cc3b4fcbe8f852c +F src/os_unix.c 779e83666ecd535f6725497ba6da069c1d15138ff6a4ee123edad1ae0cdfbe83 F src/os_win.c 6ff43bac175bd9ed79e7c0f96840b139f2f51d01689a638fd05128becf94908a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c b08600ebf0db90b6d1e9b8b6577c6fa3877cbe1a100bd0b2899e4c6e9adad4b3 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 9592b9ba3ad7a842cdd4c4010da278485a6fdec7e811bda01ebe640162a8c3b6 -R 0bed48c612190c1339a39e58e27e8cbd -U drh -Z 38a364760cd51d772a2b987e6988323a +P 92d71eee4f3a5edb3877c108d14972d80654982b0de3e635d9d008e9d3b6591f +R 695a2a8c9ed9206bd31e5393e29d1395 +U stephan +Z 46b5546a8d1e43d063c19803f97215ff # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index e3d4847c8a..24900fc1d3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -92d71eee4f3a5edb3877c108d14972d80654982b0de3e635d9d008e9d3b6591f +2916460179c6089375188c6e4e3cff1fca5bbbbb7280a10c919e09e75d1f11f8 diff --git a/src/os_unix.c b/src/os_unix.c index 5d1dc9ac6b..92ad9d8607 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4159,7 +4159,7 @@ static void setDeviceCharacteristics(unixFile *pFd){ static void setDeviceCharacteristics(unixFile *pFile){ if( pFile->sectorSize == 0 ){ struct statvfs fsInfo; - + /* Set defaults for non-supported filesystems */ pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE; pFile->deviceCharacteristics = 0; @@ -4199,7 +4199,7 @@ static void setDeviceCharacteristics(unixFile *pFile){ pFile->sectorSize = fsInfo.f_bsize; pFile->deviceCharacteristics = /* full bitset of atomics from max sector size and smaller */ - ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 | + (((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2) | SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind ** so it is ordered */ 0; @@ -4207,7 +4207,7 @@ static void setDeviceCharacteristics(unixFile *pFile){ pFile->sectorSize = fsInfo.f_bsize; pFile->deviceCharacteristics = /* full bitset of atomics from max sector size and smaller */ - ((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2 | + (((pFile->sectorSize / 512 * SQLITE_IOCAP_ATOMIC512) << 1) - 2) | SQLITE_IOCAP_SEQUENTIAL | /* The ram filesystem has no write behind ** so it is ordered */ 0; From 2b041fb97a8a821d15e5d40184a0a724cce549e0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 26 Sep 2024 19:16:20 +0000 Subject: [PATCH 33/50] Provide SQLITE_U8TEXT_ONLY and SQLITE_U8TEXT_STDIO compile-time options to the sqlite3_stdio.c module. FossilOrigin-Name: f31588520e3f45b50dcaa9eecab17f52ebb56bb53d0f9bdb88cc596d1a156353 --- ext/misc/sqlite3_stdio.c | 55 ++++++++++++++++++++++++++++++++++------ manifest | 14 +++++----- manifest.uuid | 2 +- src/shell.c.in | 34 ++++++++++++------------- 4 files changed, 72 insertions(+), 33 deletions(-) diff --git a/ext/misc/sqlite3_stdio.c b/ext/misc/sqlite3_stdio.c index 5447faadf7..46f12dff36 100644 --- a/ext/misc/sqlite3_stdio.c +++ b/ext/misc/sqlite3_stdio.c @@ -30,6 +30,43 @@ #include <io.h> #include <fcntl.h> +/* +** If the SQLITE_U8TEXT_ONLY option is defined, then only use +** _O_U8TEXT, _O_WTEXT, and similar together with the UTF-16 +** interfaces to the Windows CRT. The use of ANSI-only routines +** like fputs() and ANSI modes like _O_TEXT and _O_BINARY is +** avoided. +** +** The downside of using SQLITE_U8TEXT_ONLY is that it becomes +** impossible to output a bare newline character (0x0a) - that is, +** a newline that is not preceded by a carriage return (0x0d). +** And without that capability, sometimes the output will be slightly +** incorrect, as extra 0x0d characters will have been inserted where +** they do not belong. +** +** The SQLITE_U8TEXT_STDIO compile-time option is a compromise. +** It always enables _O_WTEXT or similar for stdin, stdout, stderr, +** but allows other streams to be _O_TEXT and/or O_BINARY. The +** SQLITE_U8TEXT_STDIO option has the same downside as SQLITE_U8TEXT_ONLY +** in that stray 0x0d characters might appear where they ought not, but +** at least with this option those characters only appear on standard +** I/O streams, and not on new streams that might be created by the +** application using sqlite3_fopen() or sqlite3_popen(). +*/ +#if defined(SQLITE_U8TEXT_ONLY) +# define UseWtextForOutput(fd) 1 +# define UseWtextForInput(fd) 1 +# define IsConsole(fd) _isatty(_fileno(fd)) +#elif defined(SQLITE_U8TEXT_STDIO) +# define UseWtextForOutput(fd) ((fd)==stdout || (fd)==stderr) +# define UseWtextForInput(fd) ((fd)==stdin) +# define IsConsole(fd) _isatty(_fileno(fd)) +#else +# define UseWtextForOutput(fd) _isatty(_fileno(fd)) +# define UseWtextForInput(fd) _isatty(_fileno(fd)) +# define IsConsole(fd) 1 +#endif + /* ** Work-alike for the fopen() routine from the standard C library. */ @@ -83,7 +120,7 @@ FILE *sqlite3_popen(const char *zCommand, const char *zMode){ ** Work-alike for fgets() from the standard C library. */ char *sqlite3_fgets(char *buf, int sz, FILE *in){ - if( _isatty(_fileno(in)) ){ + if( UseWtextForInput(in) ){ /* When reading from the command-prompt in Windows, it is necessary ** to use _O_WTEXT input mode to read UTF-16 characters, then translate ** that into UTF-8. Otherwise, non-ASCII characters all get translated @@ -91,7 +128,7 @@ char *sqlite3_fgets(char *buf, int sz, FILE *in){ */ wchar_t *b1 = malloc( sz*sizeof(wchar_t) ); if( b1==0 ) return 0; - _setmode(_fileno(in), _O_WTEXT); + _setmode(_fileno(in), IsConsole(in) ? _O_WTEXT : _O_U8TEXT); if( fgetws(b1, sz/4, in)==0 ){ sqlite3_free(b1); return 0; @@ -110,7 +147,7 @@ char *sqlite3_fgets(char *buf, int sz, FILE *in){ ** Work-alike for fputs() from the standard C library. */ int sqlite3_fputs(const char *z, FILE *out){ - if( _isatty(_fileno(out)) ){ + if( UseWtextForOutput(out) ){ /* When writing to the command-prompt in Windows, it is necessary ** to use _O_WTEXT input mode and write UTF-16 characters. */ @@ -119,7 +156,7 @@ int sqlite3_fputs(const char *z, FILE *out){ if( b1==0 ) return 0; sz = MultiByteToWideChar(CP_UTF8, 0, z, sz, b1, sz); b1[sz] = 0; - _setmode(_fileno(out), _O_WTEXT); + _setmode(_fileno(out), _O_U8TEXT); fputws(b1, out); sqlite3_free(b1); return 0; @@ -136,7 +173,7 @@ int sqlite3_fputs(const char *z, FILE *out){ */ int sqlite3_fprintf(FILE *out, const char *zFormat, ...){ int rc; - if( _isatty(fileno(out)) ){ + if( UseWtextForOutput(out) ){ /* When writing to the command-prompt in Windows, it is necessary ** to use _O_WTEXT input mode and write UTF-16 characters. */ @@ -161,12 +198,14 @@ int sqlite3_fprintf(FILE *out, const char *zFormat, ...){ } /* -** Set the mode for a stream. mode argument is typically _O_BINARY or +** Set the mode for an output stream. mode argument is typically _O_BINARY or ** _O_TEXT. */ void sqlite3_fsetmode(FILE *fp, int mode){ - fflush(fp); - _setmode(_fileno(fp), mode); + if( !UseWtextForOutput(fp) ){ + fflush(fp); + _setmode(_fileno(fp), mode); + } } #endif /* defined(_WIN32) */ diff --git a/manifest b/manifest index ea40af4ac6..7cdc9f8b96 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sshell\stest\scases\sto\saccount\sfor\srecent\sadditions\sto\sthe\s".help"\soutput. -D 2024-09-26T01:29:22.012 +C Provide\sSQLITE_U8TEXT_ONLY\sand\sSQLITE_U8TEXT_STDIO\scompile-time\soptions\nto\sthe\ssqlite3_stdio.c\smodule. +D 2024-09-26T19:16:20.290 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -425,7 +425,7 @@ F ext/misc/shathree.c 1821d90a0040c9accdbe3e3527d378d30569475d758aa70f6848924c0b F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 F ext/misc/spellfix.c c0aa7b80d6df45f7da59d912b38752bcac1af53a5766966160e6c5cdd397dbea F ext/misc/sqlar.c a6175790482328171da47095f87608b48a476d4fac78d8a9ff18b03a2454f634 -F ext/misc/sqlite3_stdio.c aefcfaeefdee26eae2c0d94e41d3720d86b1dc5c96e70132366ab1e204f9ef92 +F ext/misc/sqlite3_stdio.c f110e6f2dc97c67e89f941f82af7dbd221193fa44d1e3ef38a691454a2cbccda F ext/misc/sqlite3_stdio.h f05eaf5e0258f0573910324a789a9586fc360a57678c57a6d63cfaa2245b6176 F ext/misc/stmt.c b090086cd6bd6281c21271d38d576eeffe662f0e6b67536352ce32bbaa438321 F ext/misc/stmtrand.c 59cffa5d8e158943ff1ce078956d8e208e8c04e67307e8f249dece2436dcb7fc @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 5a5881cbe128962b431bfd466ff408db6bf05b971db67200615be38745f0ceef +F src/shell.c.in f82c16f090496e61d4b67500522dbbf8f1b37c77415aafc24a7c84bc9d0c8709 F src/sqlite.h.in 77f55bd1978a04a14db211732f0a609077cf60ba4ccf9baf39988f508945419c F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 660ca5ce6600d897cc2b00b9d39e5d993c1c0e71ec0d5dc706246c053a163281 -R 3b1b1ac1efd2caefa25e8d6c9bf0ff2f +P 54c22bc6165affbea0d1166a0912d19939300ccc4ae33a6b2ed8c510ab61c574 +R 2b2b12aba8675f6b1c9a607cabf2b89d U drh -Z 1e00c19e9c0388401e635e4bb988cbfe +Z a76d82025e5362f7f888a23f868f0cc8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index fac43782cc..04b6c8d8cc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -54c22bc6165affbea0d1166a0912d19939300ccc4ae33a6b2ed8c510ab61c574 +f31588520e3f45b50dcaa9eecab17f52ebb56bb53d0f9bdb88cc596d1a156353 diff --git a/src/shell.c.in b/src/shell.c.in index c848c4c235..b8c247cc2a 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1631,7 +1631,13 @@ static const char *modeDescr[] = { #define SEP_Tab "\t" #define SEP_Space " " #define SEP_Comma "," -#define SEP_CrLf "\r\n" +#ifdef SQLITE_U8TEXT_ONLY + /* With the SQLITE_U8TEXT_ONLY option, the output will always be in + ** text mode. The \r will be inserted automatically. */ +# define SEP_CrLf "\n" +#else +# define SEP_CrLf "\r\n" +#endif #define SEP_Unit "\x1F" #define SEP_Record "\x1E" @@ -4933,9 +4939,10 @@ static const char *(azHelp[]) = { ".clone NEWDB Clone data into NEWDB from the existing database", #endif ".connection [close] [#] Open or close an auxiliary database connection", -#if defined(_WIN32) || defined(WIN32) +#if defined(_WIN32) && !defined(SQLITE_U8TEXT_ONLY) \ + && !defined(SQLITE_U8TEXT_STDIO) ".crnl on|off Translate \\n to \\r\\n. Default ON", -#endif +#endif /* _WIN32 && U8TEXT_ONLY && U8TEXT_STDIO */ ".databases List names and files of attached databases", ".dbconfig ?op? ?val? List or change sqlite3_db_config() options", #if SQLITE_SHELL_HAVE_RECOVER @@ -8425,17 +8432,8 @@ static int do_meta_command(char *zLine, ShellState *p){ /* Undocumented. Legacy only. See "crnl" below */ if( c=='b' && n>=3 && cli_strncmp(azArg[0], "binary", n)==0 ){ - if( nArg==2 ){ - if( booleanValue(azArg[1]) ){ - sqlite3_fsetmode(p->out, _O_BINARY); - }else{ - sqlite3_fsetmode(p->out, _O_TEXT); - } - }else{ - eputz("The \".binary\" command is deprecated. Use \".crnl\" instead.\n" - "Usage: .binary on|off\n"); - rc = 1; - } + eputz("The \".binary\" command is deprecated. Use \".crnl\" instead.\n"); + rc = 1; }else /* The undocumented ".breakpoint" command causes a call to the no-op @@ -8561,6 +8559,10 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( c=='c' && n==4 && cli_strncmp(azArg[0], "crnl", n)==0 ){ +#if !defined(_WIN32) || defined(SQLITE_U8TEXT_ONLY) \ + || defined(SQLITE_U8TEXT_STDIO) + sqlite3_fputs("The \".crnl\" command is disable in this build.\n", p->out); +#else if( nArg==2 ){ if( booleanValue(azArg[1]) ){ sqlite3_fsetmode(p->out, _O_TEXT); @@ -8568,12 +8570,10 @@ static int do_meta_command(char *zLine, ShellState *p){ sqlite3_fsetmode(p->out, _O_BINARY); } }else{ -#if !defined(_WIN32) && !defined(WIN32) - eputz("The \".crnl\" is a no-op on non-Windows machines.\n"); -#endif eputz("Usage: .crnl on|off\n"); rc = 1; } +#endif }else if( c=='d' && n>1 && cli_strncmp(azArg[0], "databases", n)==0 ){ From c94e4a7b2fb1686ef78a518fc6b3ad13e27eecf5 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 26 Sep 2024 22:25:13 +0000 Subject: [PATCH 34/50] Fix a harmless compiler warning in the CLI. FossilOrigin-Name: 27ef1909bb0c4d9470c6074b40500632c68341127a079a3eb3b6a19dbfb2aeac --- manifest | 13 ++++++------- manifest.uuid | 2 +- src/shell.c.in | 6 +++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index c147b4354a..68ea64dcf2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\sext/misc/sqlite3_stdio.c\sportability\sinterface\sand\sincorporate\sit\ninto\sthe\sCLI,\ssqldiff,\sand\ssqlite3_analyzer.\s\sEnhance\sthe\sCLI\swith\sthe\snew\n".www"\sdot-command\sand\srelated\soptions\son\s.once\sand\s.output. -D 2024-09-26T19:38:34.453 +C Fix\sa\sharmless\scompiler\swarning\sin\sthe\sCLI. +D 2024-09-26T22:25:13.188 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -770,7 +770,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in f82c16f090496e61d4b67500522dbbf8f1b37c77415aafc24a7c84bc9d0c8709 +F src/shell.c.in 857c60ed21ae2c58d7740d790e8b22e167136ad1930af50527ec0e584a8cc8aa F src/sqlite.h.in b20547021d20ba016c2fd0500f14f08a21ff23e64a0ed93e72ca0fecb9e1d0a0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2215,9 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 2916460179c6089375188c6e4e3cff1fca5bbbbb7280a10c919e09e75d1f11f8 f31588520e3f45b50dcaa9eecab17f52ebb56bb53d0f9bdb88cc596d1a156353 -R f87c6f9c6a8b13e5a36fdc8ca3678f8e -T +closed f31588520e3f45b50dcaa9eecab17f52ebb56bb53d0f9bdb88cc596d1a156353 +P f97f9944b829a49da12786f934da0a5ad51591afd6d8a19a4a0835f51bbdbff2 +R a6968f0fc463c15c807b790b3704b8a0 U drh -Z ae14ce22d9ca5329be6ced79481d3b29 +Z 47d3a59057a462e974fa3c72ad894820 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a71365e258..edb083fd58 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f97f9944b829a49da12786f934da0a5ad51591afd6d8a19a4a0835f51bbdbff2 +27ef1909bb0c4d9470c6074b40500632c68341127a079a3eb3b6a19dbfb2aeac diff --git a/src/shell.c.in b/src/shell.c.in index b8c247cc2a..56f63fb190 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -12732,7 +12732,11 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){ sqlite3_fprintf(stderr, "attach debugger to process %d and press ENTER to continue...", GETPID()); - sqlite3_fgets(zLine, sizeof(zLine), stdin); + if( sqlite3_fgets(zLine, sizeof(zLine), stdin)!=0 + && cli_strcmp(zLine,"stop")==0 + ){ + exit(1); + } }else{ #if defined(_WIN32) || defined(WIN32) #if SQLITE_OS_WINRT From c707b2eb6d8456f682574a10b718e48bf07c7d99 Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Fri, 27 Sep 2024 16:20:03 +0000 Subject: [PATCH 35/50] Squash sign-comparison warnings reported in [forum:5e605a763a65c3f8 | forum post 5e605a763a65c3f8]. FossilOrigin-Name: e74fce93c518296bdb0a4273cd5fd3f785d37d27750ca456b61a3502135775f9 --- ext/misc/spellfix.c | 8 ++++---- manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/misc/spellfix.c b/ext/misc/spellfix.c index a0c5aafd10..6debdf5dbd 100644 --- a/ext/misc/spellfix.c +++ b/ext/misc/spellfix.c @@ -351,7 +351,7 @@ static int substituteCost(char cPrev, char cFrom, char cTo){ ** Negative values indicate an error: ** -1 One of the inputs is NULL ** -2 Non-ASCII characters on input -** -3 Unable to allocate memory +** -3 Unable to allocate memory ** ** If pnMatch is not NULL, then *pnMatch is set to the number of bytes ** of zB that matched the pattern in zA. If zA does not end with a '*', @@ -360,8 +360,8 @@ static int substituteCost(char cPrev, char cFrom, char cTo){ ** of zB that was deemed to match zA. */ static int editdist1(const char *zA, const char *zB, int *pnMatch){ - int nA, nB; /* Number of characters in zA[] and zB[] */ - int xA, xB; /* Loop counters for zA[] and zB[] */ + unsigned int nA, nB; /* Number of characters in zA[] and zB[] */ + unsigned int xA, xB; /* Loop counters for zA[] and zB[] */ char cA = 0, cB; /* Current character of zA and zB */ char cAprev, cBprev; /* Previous character of zA and zB */ char cAnext, cBnext; /* Next character in zA and zB */ @@ -3021,7 +3021,7 @@ static sqlite3_module spellfix1Module = { */ static int spellfix1Register(sqlite3 *db){ int rc = SQLITE_OK; - int i; + unsigned int i; rc = sqlite3_create_function(db, "spellfix1_translit", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, transliterateSqlFunc, 0, 0); diff --git a/manifest b/manifest index 68ea64dcf2..00d8d3f66e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sharmless\scompiler\swarning\sin\sthe\sCLI. -D 2024-09-26T22:25:13.188 +C Squash\ssign-comparison\swarnings\sreported\sin\s[forum:5e605a763a65c3f8\s|\sforum\spost\s5e605a763a65c3f8]. +D 2024-09-27T16:20:03.346 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -423,7 +423,7 @@ F ext/misc/series.c a6089b5e8e3002bd1e5d9877cee6aead0b9a6426e406c09a399817db9e9a F ext/misc/sha1.c cb5002148c2661b5946f34561701e9105e9d339b713ec8ac057fd888b196dcb9 F ext/misc/shathree.c 1821d90a0040c9accdbe3e3527d378d30569475d758aa70f6848924c0b430e8c F ext/misc/showauth.c 732578f0fe4ce42d577e1c86dc89dd14a006ab52 -F ext/misc/spellfix.c c0aa7b80d6df45f7da59d912b38752bcac1af53a5766966160e6c5cdd397dbea +F ext/misc/spellfix.c bcc42ef3fd29429bc01a83e751332b8d4690e65d45008449bdffe7656371487f F ext/misc/sqlar.c a6175790482328171da47095f87608b48a476d4fac78d8a9ff18b03a2454f634 F ext/misc/sqlite3_stdio.c f110e6f2dc97c67e89f941f82af7dbd221193fa44d1e3ef38a691454a2cbccda F ext/misc/sqlite3_stdio.h f05eaf5e0258f0573910324a789a9586fc360a57678c57a6d63cfaa2245b6176 @@ -2215,8 +2215,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f97f9944b829a49da12786f934da0a5ad51591afd6d8a19a4a0835f51bbdbff2 -R a6968f0fc463c15c807b790b3704b8a0 -U drh -Z 47d3a59057a462e974fa3c72ad894820 +P 27ef1909bb0c4d9470c6074b40500632c68341127a079a3eb3b6a19dbfb2aeac +R 81a4d040bd5425cfeac10fd5ca0ed96b +U stephan +Z 6359f322b683086f026c8375d9816233 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index edb083fd58..40b51b8191 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -27ef1909bb0c4d9470c6074b40500632c68341127a079a3eb3b6a19dbfb2aeac +e74fce93c518296bdb0a4273cd5fd3f785d37d27750ca456b61a3502135775f9 From add19478c1aac09a170517a30453d4a549e078c8 Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Fri, 27 Sep 2024 23:45:40 +0000 Subject: [PATCH 36/50] Fix fiddle build broken by recent build-level reworks. Remove a stale reference to an old CSS file. FossilOrigin-Name: f904b3b7842da036c3e8423bae02cdf207573c92dc379a601eae289eb3c5f547 --- ext/wasm/fiddle.make | 1 - ext/wasm/fiddle/index.html | 1 - ext/wasm/mkwasmbuilds.c | 1 + manifest | 16 ++++++++-------- manifest.uuid | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index c81379fbbd..5c97209122 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -63,7 +63,6 @@ $(EXPORTED_FUNCTIONS.fiddle): $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle) sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@ fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c) -$(eval $(call call-make-pre-post,fiddle-module,vanilla)) ######################################################################## # emit rules for one of the two fiddle builds. $1 must be diff --git a/ext/wasm/fiddle/index.html b/ext/wasm/fiddle/index.html index 5f8647b036..f779749319 100644 --- a/ext/wasm/fiddle/index.html +++ b/ext/wasm/fiddle/index.html @@ -9,7 +9,6 @@ two lines and ensure that these files are on the web server. --> <!--script src="jqterm/jqterm-bundle.min.js"></script> <link rel="stylesheet" href="jqterm/jquery.terminal.min.css"/--> - <link rel="stylesheet" href="emscripten.css"/> <style> /* The following styles are for app-level use. */ :root { diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index 0da005eeb7..a455f3945a 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -229,6 +229,7 @@ int main(void){ "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs", "-sEXPORT_ES6 -sUSE_ES6_IMPORT_META"); + mk_pre_post("fiddle-module","vanilla", 0); mk_pre_post("speedtest1","vanilla", 0); mk_pre_post("speedtest1-wasmfs","esm", "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs"); return rc; diff --git a/manifest b/manifest index 47e74610ab..60f8d5d218 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\swasmfs\sspeedtest1\sbuild\stweaks.\sDisable\sone\swasmfs\sdemo\swhich\swas\sbroken\sby\sEmscripten-side\schanges. -D 2024-09-24T21:54:37.941 +C Fix\sfiddle\sbuild\sbroken\sby\srecent\sbuild-level\sreworks.\sRemove\sa\sstale\sreference\sto\san\sold\sCSS\sfile. +D 2024-09-27T23:45:40.854 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -653,15 +653,15 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 653e212c1e84aa3be168d62a10616ccea45ee9585b0192745d2706707a5248ce F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make 2a1a232157f6638bdcb4496cfc0014ca2ab723fe5d986989c9fd9ee3867e1be7 +F ext/wasm/fiddle.make 8ccee74606582336ba885df75fbd6b40c0bb0d0a686f6472d4b6dacec1393145 F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 -F ext/wasm/fiddle/index.html 739e0b75bc592679665d25e2f7649d2b8b2db678f3b41a772a8720b609b8482d +F ext/wasm/fiddle/index.html c79b1741cbeba78f88af0a84cf5ec7de87a909a6a8d10a369b1f4824c66c2088 F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29aeff8507511f F ext/wasm/index.html e4bbffdb3d40eff12b3f9c7abedef91787e2935620b7f8d40f2c774b80ad8fa9 F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/mkwasmbuilds.c 0619a960ae36a62dffe5be4781266a8f8b3d5bb9159e3bbbce1120cbe7665f2d +F ext/wasm/mkwasmbuilds.c e58bad0558f6b8359e6ebb9262a0bf30dfd1db9715ec8a0de9f1e74433944b57 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -2211,8 +2211,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cee43280727435440b9e01b302a790a1a102aea930bc821ebc737ea519458cef -R 3ad4aa454386a8a2c5afddc12db2471b +P 5ccc85d8f5809d961602dff557dca1ed34f5db61203912387272034e4da02614 +R b423c82bbaeaae132815dac1536d60b7 U stephan -Z 5b453b3ba6239edcf196a762c7d96ef5 +Z 372446199cce1136dc510d3abff62856 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index eb3623a412..794a9bbd77 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5ccc85d8f5809d961602dff557dca1ed34f5db61203912387272034e4da02614 +f904b3b7842da036c3e8423bae02cdf207573c92dc379a601eae289eb3c5f547 From fabae7a134c0adb462aa75d33574f9ebdf924eda Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Sat, 28 Sep 2024 00:39:19 +0000 Subject: [PATCH 37/50] Minor makefile doc fixes. No functional changes. FossilOrigin-Name: b3ad58e1fc73941f2d32bab0e0fac0b95849ae69f84788a431e65bb072e42db5 --- ext/wasm/GNUmakefile | 4 ++-- ext/wasm/wasmfs.make | 2 +- manifest | 17 ++++++++--------- manifest.uuid | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index d98a0cb8ed..ae989040ee 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -367,12 +367,12 @@ DISTCLEAN_FILES += $(bin.stripccomments) ######################################################################## # bin.mkwb is used for generating some of the makefile code for the -# various build builds. It used to be generated in this makefile via a +# various wasm builds. It used to be generated in this makefile via a # difficult-to-read/maintain block of $(eval)'d code. Attempts were # made to generate it from tcl and bash (shell) but having to escape # the $ references in those languages made it just as illegible as the # native makefile code. Somewhat surprisingly, moving that code generation -# to C makes it slightly less illegible than the previousq 3 options. +# to C makes it slightly less illegible than the previous 3 options. bin.mkwb := ./mkwasmbuilds $(bin.mkwb): $(bin.mkwb).c $(MAKEFILE) $(CC) -o $@ $< diff --git a/ext/wasm/wasmfs.make b/ext/wasm/wasmfs.make index 4d34c42140..9de5574f26 100644 --- a/ext/wasm/wasmfs.make +++ b/ext/wasm/wasmfs.make @@ -7,7 +7,7 @@ ######################################################################## MAKEFILE.wasmfs := $(lastword $(MAKEFILE_LIST)) # ensure that the following message starts on line 10 or higher for proper -# alignment! +# $(warning) alignment! ifneq (1,$(MAKING_CLEAN)) $(warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!) $(warning !! The WASMFS build is not well-supported. WASMFS is a proverbial) diff --git a/manifest b/manifest index ff89df3542..b16eb9e49b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\swasm-build-rework\sbranch\sinto\strunk.\sSummary:\s1)\sadd\soptional\sbare-bones\sbuild,\sstripped\sof\smany\soptional\slibrary\sfeatures,\s2)\sreplace\smuch\sof\sthe\shyper-spaghetti\swasm-specific\smakefile\scode\swith\sa\smore\slegible\sstatic\scode\sgenerator. -D 2024-09-28T00:02:52.169 +C Minor\smakefile\sdoc\sfixes.\sNo\sfunctional\schanges. +D 2024-09-28T00:39:19.799 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -603,7 +603,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 34a4590ae3f7ce5a70bf1c6f0384a7935e6c9809281e40165381ba04df34ceae +F ext/wasm/GNUmakefile a35f8f9cd8fca7a8ea5c76492c3b72f8656ff6e62dd770f755d9b024dbdb2a4b F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -612,7 +612,7 @@ F ext/wasm/SQLTester/SQLTester.run.mjs c72b7fe2072d05992f7a3d8c6a1d34e95712513ce F ext/wasm/SQLTester/index.html 3f8a016df0776be76605abf20e815ecaafbe055abac0e1fe5ea080e7846b760d F ext/wasm/SQLTester/touint8array.c 2d5ece04ec1393a6a60c4bf96385bda5e1a10ad49f3038b96460fc5e5aa7e536 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-core 2bcbbfe3b95c043ed6037e2708a2ee078d212dd1612c364f93588d8dc97300fe -F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras fe40d6d758646e38f8b15f709044951e10884214f5453d35502100179c388c13 w ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-session +F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-extras fe40d6d758646e38f8b15f709044951e10884214f5453d35502100179c388c13 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287 F ext/wasm/api/README.md 34fe11466f9c1d81b10a0469e1114e5f1c5a6365c73d80a1a6ca639a1a358b73 @@ -683,7 +683,7 @@ F ext/wasm/tester1.c-pp.js bb8c41a56ca0eabb945ca2e8f06324a7b63ad91630959d714b071 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 -F ext/wasm/wasmfs.make 8067daf346482cdb91414c3f6b8f6ff110bfa874294f73e13479c755af67ec20 +F ext/wasm/wasmfs.make bc8bb227f35d5bd3863a7bd2233437c37472a0d81585979f058f9b9b503bef35 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0 @@ -2213,9 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e74fce93c518296bdb0a4273cd5fd3f785d37d27750ca456b61a3502135775f9 f904b3b7842da036c3e8423bae02cdf207573c92dc379a601eae289eb3c5f547 -R 00aae997005fe8baf8a0564b28d0f4b3 -T +closed f904b3b7842da036c3e8423bae02cdf207573c92dc379a601eae289eb3c5f547 Closed\sby\sintegrate-merge. +P 208c27714646c9bc26eef11266086a71da04bc24e87078de0955e7beb68a821e +R 2a15755da1c3e9e619c193a945de5bc6 U stephan -Z 285fd3333f337a65629db5a9e7f33975 +Z 991ac6d8780a391427387df58194645e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 424b2a3a6c..c3fe76067a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -208c27714646c9bc26eef11266086a71da04bc24e87078de0955e7beb68a821e +b3ad58e1fc73941f2d32bab0e0fac0b95849ae69f84788a431e65bb072e42db5 From 51fb37db61f4602a074dd56bf3f688c5a57ac2cd Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Sat, 28 Sep 2024 11:03:00 +0000 Subject: [PATCH 38/50] For wasm builds: automatically use higher optimization (but slower build) levels when a target related to deliverables (as opposed to dev mode) is explicitly invoked. FossilOrigin-Name: 45361ab9744ccac3419d97fe8951838f14bd28220e3f7f747b39e46cfc3b5a1d --- ext/wasm/GNUmakefile | 29 ++++++++++++++++++++++------- ext/wasm/fiddle.make | 2 ++ manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index ae989040ee..9c0322ea8b 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -145,11 +145,19 @@ $(sqlite3.h): $(MAKE) -C $(dir.top) sqlite3.c $(sqlite3.c): $(sqlite3.h) +######################################################################## +# Special-case builds for which we require certain pre-conditions +# which, if not met, may cause warnings or fatal errors in the build. +# This also affects the default optimization level flags. Note that +# the fiddle targets are in this list because they are used for +# generating sqlite.org/fiddle. +OPTIMIZED_TARGETS := dist snapshot fiddle fiddle.debug + ifneq (1,$(MAKING_CLEAN)) - ifeq (,$(filter release snapshot,$(MAKECMDGOALS))) + ifeq (,$(filter $(OPTIMIZED_TARGETS),$(MAKECMDGOALS))) $(info ==============================================================) - $(info == Development build. Use 'release' or 'snapshot' target) - $(info == for a smaller release build.) + $(info == Development build. Make one of (dist, snapshot) for a) + $(info == smaller release build.) $(info ==============================================================) endif endif @@ -193,11 +201,11 @@ else $(info WARNING: on Ubuntu-like systems it can be installed with:) $(info WARNING: sudo apt install wabt) $(info WARNING: *******************************************************************) + ifneq (,$(filter $(OPTIMIZED_TARGETS),$(MAKECMDGOALS))) + $(error Cannot make release-quality binary because wasm-strip is not available.) + endif wasm-strip.bin := echo "not wasm-stripping" endif - ifneq (,$(filter release snapshot,$(MAKECMDGOALS))) - $(error Cannot make release-quality binary because wasm-strip is not available.) - endif endif maybe-wasm-strip := $(wasm-strip.bin) @@ -443,7 +451,14 @@ emcc.WASM_BIGINT ?= 1 # emcc_opt = optimization-related flags. These are primarily used by # the various oX targets. build times for -O levels higher than 0 are # painful at dev-time. -emcc_opt ?= -O0 +# +# When running any of the $(OPTIMIZED_TARGETS) explicitly, e.g. for +# a release distribution +ifeq (,$(filter $(OPTIMIZED_TARGETS),$(MAKECMDGOALS))) + emcc_opt ?= -O0 +else + emcc_opt ?= -Oz +endif # When passing emcc_opt from the CLI, += and re-assignment have no # effect, so emcc_opt+=-g3 doesn't work. So... diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index 5c97209122..d0e811cac8 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -68,6 +68,8 @@ fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c) # emit rules for one of the two fiddle builds. $1 must be # either $(dir.fiddle) or $(dir.fiddle-debug). $2 must be empty # in the former case and .debug in the latter. +# +# TODO: move this into mkwasmbuilds.c. define make-fiddle-rules fiddle-module.js$(2) := $(1)/fiddle-module.js fiddle-module.wasm$(2) := $$(subst .js,.wasm,$$(fiddle-module.js$(2))) diff --git a/manifest b/manifest index b16eb9e49b..ccedf55294 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\smakefile\sdoc\sfixes.\sNo\sfunctional\schanges. -D 2024-09-28T00:39:19.799 +C For\swasm\sbuilds:\sautomatically\suse\shigher\soptimization\s(but\sslower\sbuild)\slevels\swhen\sa\starget\srelated\sto\sdeliverables\s(as\sopposed\sto\sdev\smode)\sis\sexplicitly\sinvoked. +D 2024-09-28T11:03:00.874 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -603,7 +603,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile a35f8f9cd8fca7a8ea5c76492c3b72f8656ff6e62dd770f755d9b024dbdb2a4b +F ext/wasm/GNUmakefile e9ec8800b8f403e43c905e931beb1c4f921eaf7008932aaab749047fb5f0f14f F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -655,7 +655,7 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 653e212c1e84aa3be168d62a10616ccea45ee9585b0192745d2706707a5248ce F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make 8ccee74606582336ba885df75fbd6b40c0bb0d0a686f6472d4b6dacec1393145 +F ext/wasm/fiddle.make fecd12fc78f5ae3fba5387fee59f83a2bfb012c073e2d956151a8957bfff4731 F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 F ext/wasm/fiddle/index.html c79b1741cbeba78f88af0a84cf5ec7de87a909a6a8d10a369b1f4824c66c2088 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 208c27714646c9bc26eef11266086a71da04bc24e87078de0955e7beb68a821e -R 2a15755da1c3e9e619c193a945de5bc6 +P b3ad58e1fc73941f2d32bab0e0fac0b95849ae69f84788a431e65bb072e42db5 +R 31eec55429d58e8299eead65de81d192 U stephan -Z 991ac6d8780a391427387df58194645e +Z baebfcdbf257af1c75327d449926f47d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c3fe76067a..81251ec111 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b3ad58e1fc73941f2d32bab0e0fac0b95849ae69f84788a431e65bb072e42db5 +45361ab9744ccac3419d97fe8951838f14bd28220e3f7f747b39e46cfc3b5a1d From d4c735d491bc934696449c13f6ca700622eddbbd Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Sat, 28 Sep 2024 11:23:09 +0000 Subject: [PATCH 39/50] Ensure that the temporary build dir is mkdir'd by wasm deps which depend on it. FossilOrigin-Name: cabdf9797281090ab3f95c9f4c2a79878d1c64d1f2a09e433e2309abe5e19e59 --- ext/wasm/GNUmakefile | 16 ++++++++++------ ext/wasm/fiddle.make | 3 ++- manifest | 14 +++++++------- manifest.uuid | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 9c0322ea8b..4219d4317f 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -105,6 +105,10 @@ dir.dout := $(dir.wasm)/jswasm dir.tmp := $(dir.wasm)/bld dir.wasmfs := $(dir.dout) +MKDIR.bld := $(dir.tmp) +$(MKDIR.bld): + -mkdir $@ + CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \ $(dir.fiddle-debug)/* $(dir.dout)/* $(dir.tmp)/* @@ -502,7 +506,7 @@ ifeq (0,$(wasm-bare-bones)) EXPORTED_FUNCTIONS.api.in += $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras endif EXPORTED_FUNCTIONS.api := $(dir.tmp)/EXPORTED_FUNCTIONS.api -$(EXPORTED_FUNCTIONS.api): $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE) +$(EXPORTED_FUNCTIONS.api): $(MKDIR.bld) $(EXPORTED_FUNCTIONS.api.in) $(sqlite3.c) $(MAKEFILE) cat $(EXPORTED_FUNCTIONS.api.in) > $@ ######################################################################## @@ -586,7 +590,7 @@ $(SOAP.js.bld): $(SOAP.js) # preprocessed. It contains all of $(sqlite3-api.jses) but none of the # Emscripten-specific headers and footers. sqlite3-api.js.in := $(dir.tmp)/sqlite3-api.c-pp.js -$(sqlite3-api.js.in): $(sqlite3-api.jses) $(MAKEFILE) +$(sqlite3-api.js.in): $(MKDIR.bld) $(sqlite3-api.jses) $(MAKEFILE) @echo "Making $@..." @for i in $(sqlite3-api.jses); do \ echo "/* BEGIN FILE: $$i */"; \ @@ -753,7 +757,7 @@ emcc.jsflags += -sLLD_REPORT_UNDEFINED ######################################################################## # $(sqlite3-api-build-version.js) injects the build version info into # the bundle in JSON form. -$(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE) +$(sqlite3-api-build-version.js): $(MKDIR.bld) $(bin.version-info) $(MAKEFILE) @echo "Making $@..." @{ \ echo 'globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){'; \ @@ -769,7 +773,7 @@ $(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE) # # Maintenance reminder: there are awk binaries out there which do not # support -e SCRIPT. -$(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) \ +$(sqlite3-license-version.js): $(MKDIR.bld) $(sqlite3.h) $(sqlite3-license-version-header.js) \ $(MAKEFILE) @echo "Making $@..."; { \ cat $(sqlite3-license-version-header.js); \ @@ -797,7 +801,7 @@ post-jses.js := \ $(dir.api)/post-js-header.js \ $(sqlite3-api.js.in) \ $(dir.api)/post-js-footer.js -$(post-js.js.in): $(post-jses.js) $(MAKEFILE) +$(post-js.js.in): $(MKDIR.bld) $(post-jses.js) $(MAKEFILE) @echo "Making $@..." @for i in $(post-jses.js); do \ echo "/* BEGIN FILE: $$i */"; \ @@ -1025,7 +1029,7 @@ speedtest1.exit-runtime1 := -sEXIT_RUNTIME=1 # -sEXIT_RUNTIME=1 but we need EXIT_RUNTIME=0 for the worker-based app # which runs speedtest1 multiple times. -$(EXPORTED_FUNCTIONS.speedtest1): $(EXPORTED_FUNCTIONS.api.core) +$(EXPORTED_FUNCTIONS.speedtest1): $(MKDIR.bld) $(EXPORTED_FUNCTIONS.api.core) @echo "Making $@ ..." @{ echo _wasm_main; cat $(EXPORTED_FUNCTIONS.api.core); } > $@ speedtest1.js := $(dir.dout)/speedtest1.js diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index d0e811cac8..a7e9be68cc 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -59,7 +59,8 @@ fiddle.EXPORTED_FUNCTIONS.in := \ $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-core \ $(dir.api)/EXPORTED_FUNCTIONS.sqlite3-extras -$(EXPORTED_FUNCTIONS.fiddle): $(fiddle.EXPORTED_FUNCTIONS.in) $(MAKEFILE.fiddle) +$(EXPORTED_FUNCTIONS.fiddle): $(MKDIR.bld) $(fiddle.EXPORTED_FUNCTIONS.in) \ + $(MAKEFILE.fiddle) sort -u $(fiddle.EXPORTED_FUNCTIONS.in) > $@ fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c) diff --git a/manifest b/manifest index ccedf55294..6f19450d0e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C For\swasm\sbuilds:\sautomatically\suse\shigher\soptimization\s(but\sslower\sbuild)\slevels\swhen\sa\starget\srelated\sto\sdeliverables\s(as\sopposed\sto\sdev\smode)\sis\sexplicitly\sinvoked. -D 2024-09-28T11:03:00.874 +C Ensure\sthat\sthe\stemporary\sbuild\sdir\sis\smkdir'd\sby\swasm\sdeps\swhich\sdepend\son\sit. +D 2024-09-28T11:23:09.335 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -603,7 +603,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile e9ec8800b8f403e43c905e931beb1c4f921eaf7008932aaab749047fb5f0f14f +F ext/wasm/GNUmakefile abd9c2a5a05dec3a39eea86bee1c05b95c418ac6d92acdd740c1297419148b0b F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -655,7 +655,7 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 653e212c1e84aa3be168d62a10616ccea45ee9585b0192745d2706707a5248ce F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make fecd12fc78f5ae3fba5387fee59f83a2bfb012c073e2d956151a8957bfff4731 +F ext/wasm/fiddle.make 4a350d7e79875c03b8326ee0fc198443555e79fa1dbf56ccd75d6cd871b44c42 F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 F ext/wasm/fiddle/index.html c79b1741cbeba78f88af0a84cf5ec7de87a909a6a8d10a369b1f4824c66c2088 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b3ad58e1fc73941f2d32bab0e0fac0b95849ae69f84788a431e65bb072e42db5 -R 31eec55429d58e8299eead65de81d192 +P 45361ab9744ccac3419d97fe8951838f14bd28220e3f7f747b39e46cfc3b5a1d +R 3ace6beda7c5f348d7740cd089b772f4 U stephan -Z baebfcdbf257af1c75327d449926f47d +Z 1e4b46fc68a5c48e2ab34715ed6387ce # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 81251ec111..1c6eacf9c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -45361ab9744ccac3419d97fe8951838f14bd28220e3f7f747b39e46cfc3b5a1d +cabdf9797281090ab3f95c9f4c2a79878d1c64d1f2a09e433e2309abe5e19e59 From 6a8336987a5b8be924ee174f472d1fe1f6b67de2 Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Sat, 28 Sep 2024 12:01:10 +0000 Subject: [PATCH 40/50] wasm: move the makefile-eval-generated fiddle rules into mkwasmbuilds.c. Squelch some warnings from grep when running 'make clean' on a clean tree. FossilOrigin-Name: 0485d1360b0dbf9987d16ab1df47b6b7a25595881581799f87889f6d4eeb60f4 --- ext/wasm/GNUmakefile | 3 ++ ext/wasm/fiddle.make | 65 +++++++++++------------------------------ ext/wasm/mkwasmbuilds.c | 50 ++++++++++++++++++++++++++++++- manifest | 16 +++++----- manifest.uuid | 2 +- 5 files changed, 78 insertions(+), 58 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 4219d4317f..3fd83e9724 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -133,12 +133,14 @@ sqlite3.canonical.c := $(dir.top)/sqlite3.c sqlite3.c ?= $(firstword $(wildcard $(dir.top)/sqlite3-see.c) $(sqlite3.canonical.c)) sqlite3.h := $(dir.top)/sqlite3.h +ifneq (1,$(MAKING_CLEAN)) ifeq (,$(shell grep sqlite3_activate_see $(sqlite3.c))) SQLITE_C_IS_SEE := 0 else SQLITE_C_IS_SEE := 1 $(info This is an SEE build) endif +endif ########################################################################@ # It's important that sqlite3.h be built to completion before any @@ -871,6 +873,7 @@ sqlite3-api-node.mjs := $(dir.dout)/sqlite3-api-node.mjs sqlite3-node.mjs := $(dir.dout)/sqlite3-node.mjs sqlite3-api-wasmfs.mjs := $(dir.tmp)/sqlite3-api-wasmfs.mjs sqlite3-wasmfs.mjs := $(dir.wasmfs)/sqlite3-wasmfs.mjs +EXPORTED_FUNCTIONS.fiddle := $(dir.tmp)/EXPORTED_FUNCTIONS.fiddle ifneq (1,$(MAKING_CLEAN)) .wasmbuilds.make: $(bin.mkwb) @rm -f $@ diff --git a/ext/wasm/fiddle.make b/ext/wasm/fiddle.make index a7e9be68cc..df5c7ab7b7 100644 --- a/ext/wasm/fiddle.make +++ b/ext/wasm/fiddle.make @@ -7,21 +7,23 @@ MAKEFILE.fiddle := $(lastword $(MAKEFILE_LIST)) ######################################################################## # shell.c and its build flags... -make-np-0 := make -C $(dir.top) -n -p -make-np-1 := sed -e 's/(TOP)/(dir.top)/g' -# Extract SHELL_OPT and SHELL_DEP from the top-most makefile and import -# them as vars here... -$(eval $(shell $(make-np-0) | grep -e '^SHELL_OPT ' | $(make-np-1))) -$(eval $(shell $(make-np-0) | grep -e '^SHELL_DEP ' | $(make-np-1))) -# ^^^ can't do that in 1 invocation b/c newlines get stripped -ifeq (,$(SHELL_OPT)) -$(error Could not parse SHELL_OPT from $(dir.top)/Makefile.) -endif -ifeq (,$(SHELL_DEP)) -$(error Could not parse SHELL_DEP from $(dir.top)/Makefile.) -endif +ifneq (1,$(MAKING_CLEAN)) + make-np-0 := make -C $(dir.top) -n -p + make-np-1 := sed -e 's/(TOP)/(dir.top)/g' + # Extract SHELL_OPT and SHELL_DEP from the top-most makefile and import + # them as vars here... + $(eval $(shell $(make-np-0) | grep -e '^SHELL_OPT ' | $(make-np-1))) + $(eval $(shell $(make-np-0) | grep -e '^SHELL_DEP ' | $(make-np-1))) + # ^^^ can't do that in 1 invocation b/c newlines get stripped + ifeq (,$(SHELL_OPT)) + $(error Could not parse SHELL_OPT from $(dir.top)/Makefile.) + endif + ifeq (,$(SHELL_DEP)) + $(error Could not parse SHELL_DEP from $(dir.top)/Makefile.) + endif $(dir.top)/shell.c: $(SHELL_DEP) $(dir.tool)/mkshellc.tcl $(sqlite3.c) $(MAKE) -C $(dir.top) shell.c +endif # /shell.c ######################################################################## @@ -65,46 +67,13 @@ $(EXPORTED_FUNCTIONS.fiddle): $(MKDIR.bld) $(fiddle.EXPORTED_FUNCTIONS.in) \ fiddle.cses := $(dir.top)/shell.c $(sqlite3-wasm.c) -######################################################################## -# emit rules for one of the two fiddle builds. $1 must be -# either $(dir.fiddle) or $(dir.fiddle-debug). $2 must be empty -# in the former case and .debug in the latter. -# -# TODO: move this into mkwasmbuilds.c. -define make-fiddle-rules -fiddle-module.js$(2) := $(1)/fiddle-module.js -fiddle-module.wasm$(2) := $$(subst .js,.wasm,$$(fiddle-module.js$(2))) -$$(fiddle-module.js$(2)): $$(MAKEFILE) $$(MAKEFILE.fiddle) \ - $$(EXPORTED_FUNCTIONS.fiddle) \ - $$(fiddle.cses) $$(pre-post-fiddle-module-vanilla.deps) $$(SOAP.js) - @test -d "$$(dir $$@)" || mkdir -p "$$(dir $$@)" - $$(emcc.bin) -o $$@ $$(fiddle.emcc-flags$(2)) \ - $$(pre-post-fiddle-module-vanilla.flags) \ - $$(fiddle.cses) - $$(maybe-wasm-strip) $$(fiddle-module.wasm$(2)) - @cp -p $$(SOAP.js) $$(dir $$@) - @if [[ x.debug = x$(2) ]]; then \ - cp -p $$(dir.fiddle)/index.html \ - $$(dir.fiddle)/fiddle.js \ - $$(dir.fiddle)/fiddle-worker.js \ - $$(dir $$@)/.; \ - fi - @for i in $(1)/*.*js $(1)/*.html $(1)/*.wasm; do \ - test -f $$$${i} || continue; \ - gzip < $$$${i} > $$$${i}.gz; \ - done -fiddle$(2): $$(fiddle-module.js$(2)) $(1)/fiddle.js.gz -endef - -$(eval $(call make-fiddle-rules,$(dir.fiddle))) -$(eval $(call make-fiddle-rules,$(dir.fiddle-debug),.debug)) fiddle: $(fiddle-module.js) $(fiddle-module.js.debug) fiddle.debug: $(fiddle-module.js.debug) clean: clean-fiddle clean-fiddle: - rm -f $(fiddle-module.js) \ - $(fiddle-module.wasm) \ + rm -f $(dir.fiddle)/fiddle-module.js \ + $(dir.fiddle)/*.wasm \ $(dir.fiddle)/sqlite3-opfs-*.js \ $(dir.fiddle)/*.gz \ EXPORTED_FUNCTIONS.fiddle diff --git a/ext/wasm/mkwasmbuilds.c b/ext/wasm/mkwasmbuilds.c index a455f3945a..29b6cafae9 100644 --- a/ext/wasm/mkwasmbuilds.c +++ b/ext/wasm/mkwasmbuilds.c @@ -133,6 +133,54 @@ static void mk_pre_post(const char *zName /* build name */, pf("# End --pre/--post flags for %s-%s%s", zName, zMode, zBanner); } +/* +** Emits rules for the fiddle builds. +** +*/ +static void mk_fiddle(){ + int i = 0; + + mk_pre_post("fiddle-module","vanilla", 0); + for( ; i < 2; ++i ){ + const char *zTail = i ? ".debug" : ""; + const char *zDir = i ? "$(dir.fiddle-debug)" : "$(dir.fiddle)"; + + pf("%s# Begin fiddle%s\n", zBanner, zTail); + pf("fiddle-module.js%s := %s/fiddle-module.js\n", zTail, zDir); + pf("fiddle-module.wasm%s := " + "$(subst .js,.wasm,$(fiddle-module.js%s))\n", zTail, zTail); + pf("$(fiddle-module.js%s):%s $(MAKEFILE) $(MAKEFILE.fiddle) " + "$(EXPORTED_FUNCTIONS.fiddle) " + "$(fiddle.cses) $(pre-post-fiddle-module-vanilla.deps) " + "$(SOAP.js)\n", + zTail, (i ? " $(fiddle-module.js)" : "")); + if( 1==i ){/*fiddle.debug*/ + pf(" @test -d \"$(dir $@)\" || mkdir -p \"$(dir $@)\"\n"); + } + pf(" $(emcc.bin) -o $@ $(fiddle.emcc-flags%s) " + "$(pre-post-fiddle-module-vanilla.flags) $(fiddle.cses)\n", + zTail); + pf(" $(maybe-wasm-strip) $(fiddle-module.wasm%s)\n", zTail); + pf(" @cp -p $(SOAP.js) $(dir $@)\n"); + if( 1==i ){/*fiddle.debug*/ + pf(" cp -p $(dir.fiddle)/index.html " + "$(dir.fiddle)/fiddle.js " + "$(dir.fiddle)/fiddle-worker.js " + "$(dir $@)\n"); + } + pf(" @for i in %s/*.*js %s/*.html %s/*.wasm; do \\\n" + " test -f $${i} || continue; \\\n" + " gzip < $${i} > $${i}.gz; \\\n" + " done\n", zDir, zDir, zDir); + if( 0==i ){ + ps("fiddle: $(fiddle-module.js)"); + }else{ + ps("fiddle-debug: $(fiddle-module-debug.js)"); + } + pf("# End fiddle%s%s", zTail, zBanner); + } +} + /* ** Emits makefile code for one build of the library, primarily defined ** by the combination of zName and zMode, each of which must be values @@ -229,7 +277,7 @@ int main(void){ "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs", "-sEXPORT_ES6 -sUSE_ES6_IMPORT_META"); - mk_pre_post("fiddle-module","vanilla", 0); + mk_fiddle(); mk_pre_post("speedtest1","vanilla", 0); mk_pre_post("speedtest1-wasmfs","esm", "$(c-pp.D.sqlite3-bundler-friendly) -Dwasmfs"); return rc; diff --git a/manifest b/manifest index 6f19450d0e..1cbfd1fb3b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Ensure\sthat\sthe\stemporary\sbuild\sdir\sis\smkdir'd\sby\swasm\sdeps\swhich\sdepend\son\sit. -D 2024-09-28T11:23:09.335 +C wasm:\smove\sthe\smakefile-eval-generated\sfiddle\srules\sinto\smkwasmbuilds.c.\sSquelch\ssome\swarnings\sfrom\sgrep\swhen\srunning\s'make\sclean'\son\sa\sclean\stree. +D 2024-09-28T12:01:10.696 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -603,7 +603,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile abd9c2a5a05dec3a39eea86bee1c05b95c418ac6d92acdd740c1297419148b0b +F ext/wasm/GNUmakefile e87c055bb0aa12bf4540b5d12e533608cb70cb2da1b8659d10b1fce03e08240c F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -655,7 +655,7 @@ F ext/wasm/demo-worker1.html 2c178c1890a2beb5a5fecb1453e796d067a4b8d3d2a04d65ca2 F ext/wasm/demo-worker1.js 836bece8615b17b1b572584f7b15912236a5947fe8c68b98d2737d7e287447ef F ext/wasm/dist.make 653e212c1e84aa3be168d62a10616ccea45ee9585b0192745d2706707a5248ce F ext/wasm/example_extra_init.c 2347cd69d19d839ef4e5e77b7855103a7fe3ef2af86f2e8c95839afd8b05862f -F ext/wasm/fiddle.make 4a350d7e79875c03b8326ee0fc198443555e79fa1dbf56ccd75d6cd871b44c42 +F ext/wasm/fiddle.make ec2353f0eddade864f67b993376a0949e27b72465c24b1970940e48b70bc2df1 F ext/wasm/fiddle/fiddle-worker.js 850e66fce39b89d59e161d1abac43a181a4caa89ddeea162765d660277cd84ce F ext/wasm/fiddle/fiddle.js b444a5646a9aac9f3fc06c53d78af5e1912eb235d69a8e6010723e4eb0e9d4a1 F ext/wasm/fiddle/index.html c79b1741cbeba78f88af0a84cf5ec7de87a909a6a8d10a369b1f4824c66c2088 @@ -663,7 +663,7 @@ F ext/wasm/index-dist.html 564b5ec5669676482c5a25dea9e721d8eafed426ecb155f93d29a F ext/wasm/index.html e4bbffdb3d40eff12b3f9c7abedef91787e2935620b7f8d40f2c774b80ad8fa9 F ext/wasm/jaccwabyt/jaccwabyt.js 1264710db3cfbcb6887d95665b7aeba60c1126eaef789ca4cf1a4a17d5bc7f54 F ext/wasm/jaccwabyt/jaccwabyt.md 59a20df389abcc3606eb4eaea7fb7ba14504beb3e345dbea9b99a0618ba3bec8 -F ext/wasm/mkwasmbuilds.c e58bad0558f6b8359e6ebb9262a0bf30dfd1db9715ec8a0de9f1e74433944b57 +F ext/wasm/mkwasmbuilds.c e3580b26bc393e4e4beb25f6349b999878782f3319b740469f64c2e772632e03 F ext/wasm/module-symbols.html dc476b403369b26a1a23773e13b80f41b9a49f0825e81435fe3600a7cfbbe337 F ext/wasm/scratchpad-wasmfs.html a3d7388f3c4b263676b58b526846e9d02dfcb4014ff29d3a5040935286af5b96 F ext/wasm/scratchpad-wasmfs.mjs 66034b9256b218de59248aad796760a1584c1dd842231505895eff00dbd57c63 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 45361ab9744ccac3419d97fe8951838f14bd28220e3f7f747b39e46cfc3b5a1d -R 3ace6beda7c5f348d7740cd089b772f4 +P cabdf9797281090ab3f95c9f4c2a79878d1c64d1f2a09e433e2309abe5e19e59 +R 0187fe6fd0750839e1c4d66882bc06e3 U stephan -Z 1e4b46fc68a5c48e2ab34715ed6387ce +Z 5f0ec8eab9d280a80b50e2d7a52a98d8 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 1c6eacf9c6..698c46feb2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cabdf9797281090ab3f95c9f4c2a79878d1c64d1f2a09e433e2309abe5e19e59 +0485d1360b0dbf9987d16ab1df47b6b7a25595881581799f87889f6d4eeb60f4 From 5ec9ed7fe954b4ffa63588fd6d0386832a10fb16 Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Sat, 28 Sep 2024 13:51:47 +0000 Subject: [PATCH 41/50] Complete a line of documentation which was interrupted mid-sentence. FossilOrigin-Name: c9cbbeda3d1ec4215396aaaf94428b829c4f53329431fa61251914c195f8a9a1 --- ext/wasm/GNUmakefile | 7 +++++-- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 3fd83e9724..e761408e34 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -458,8 +458,11 @@ emcc.WASM_BIGINT ?= 1 # the various oX targets. build times for -O levels higher than 0 are # painful at dev-time. # -# When running any of the $(OPTIMIZED_TARGETS) explicitly, e.g. for -# a release distribution +# When running any of the $(OPTIMIZED_TARGETS) explicitly, e.g. for a +# release distribution, use a higher optimization level. Experience +# has shown -Oz to produce the smallest deliverables with only a +# roughly 10% performance hit in the resulting WASM file compared to +# -O2 (which consistently creates the fastest-running deliverables). ifeq (,$(filter $(OPTIMIZED_TARGETS),$(MAKECMDGOALS))) emcc_opt ?= -O0 else diff --git a/manifest b/manifest index 1cbfd1fb3b..d71c7d09df 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C wasm:\smove\sthe\smakefile-eval-generated\sfiddle\srules\sinto\smkwasmbuilds.c.\sSquelch\ssome\swarnings\sfrom\sgrep\swhen\srunning\s'make\sclean'\son\sa\sclean\stree. -D 2024-09-28T12:01:10.696 +C Complete\sa\sline\sof\sdocumentation\swhich\swas\sinterrupted\smid-sentence. +D 2024-09-28T13:51:47.537 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -603,7 +603,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile e87c055bb0aa12bf4540b5d12e533608cb70cb2da1b8659d10b1fce03e08240c +F ext/wasm/GNUmakefile fbafd2e9514bdf579d2549603e62fab202037315f16402f7e3b9ad227af86ff5 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P cabdf9797281090ab3f95c9f4c2a79878d1c64d1f2a09e433e2309abe5e19e59 -R 0187fe6fd0750839e1c4d66882bc06e3 +P 0485d1360b0dbf9987d16ab1df47b6b7a25595881581799f87889f6d4eeb60f4 +R 4fb55576459952034688327ee6ecebbe U stephan -Z 5f0ec8eab9d280a80b50e2d7a52a98d8 +Z 99f2ab951b6d8ffe813ecc8ee717f06d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 698c46feb2..3526ac9557 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0485d1360b0dbf9987d16ab1df47b6b7a25595881581799f87889f6d4eeb60f4 +c9cbbeda3d1ec4215396aaaf94428b829c4f53329431fa61251914c195f8a9a1 From 33669ef289bfc69aac80b3fc58edbd62006de41f Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Sat, 28 Sep 2024 15:13:49 +0000 Subject: [PATCH 42/50] Add another missing mkdir to the wasm build process. FossilOrigin-Name: e815055b321085deda8607ac3279ef1a1c890fe3bf9d9b9c0a74028e87857a7d --- ext/wasm/GNUmakefile | 2 +- manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index e761408e34..2602e6b792 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -107,7 +107,7 @@ dir.wasmfs := $(dir.dout) MKDIR.bld := $(dir.tmp) $(MKDIR.bld): - -mkdir $@ + -mkdir -p $@ $(dir.dout) CLEAN_FILES += *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ $(dir.fiddle)/*~ \ $(dir.fiddle-debug)/* $(dir.dout)/* $(dir.tmp)/* diff --git a/manifest b/manifest index d71c7d09df..203e87db27 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Complete\sa\sline\sof\sdocumentation\swhich\swas\sinterrupted\smid-sentence. -D 2024-09-28T13:51:47.537 +C Add\sanother\smissing\smkdir\sto\sthe\swasm\sbuild\sprocess. +D 2024-09-28T15:13:49.994 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -603,7 +603,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile fbafd2e9514bdf579d2549603e62fab202037315f16402f7e3b9ad227af86ff5 +F ext/wasm/GNUmakefile 6b94c3125c40932e71bbe46e582d24ed4c829b9fa2ff34dd842b0ed8a948ac6a F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0485d1360b0dbf9987d16ab1df47b6b7a25595881581799f87889f6d4eeb60f4 -R 4fb55576459952034688327ee6ecebbe +P c9cbbeda3d1ec4215396aaaf94428b829c4f53329431fa61251914c195f8a9a1 +R 6a112f9240ce847c284940c2c71c0d81 U stephan -Z 99f2ab951b6d8ffe813ecc8ee717f06d +Z be8aef5e16db8f3b229b77cf96144050 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3526ac9557..34bc5bb12b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c9cbbeda3d1ec4215396aaaf94428b829c4f53329431fa61251914c195f8a9a1 +e815055b321085deda8607ac3279ef1a1c890fe3bf9d9b9c0a74028e87857a7d From 54fd01c4ab06c511c55235de039a7955117fddf0 Mon Sep 17 00:00:00 2001 From: drh <> Date: Sat, 28 Sep 2024 19:52:38 +0000 Subject: [PATCH 43/50] Fix the CLI so that the --bom option only outputs a single BOM, not two. FossilOrigin-Name: 76b6331e6a705a420a64820a18214f07cf4c1d5151e7158d6fff09964e63f352 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 203e87db27..7566dedc21 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sanother\smissing\smkdir\sto\sthe\swasm\sbuild\sprocess. -D 2024-09-28T15:13:49.994 +C Fix\sthe\sCLI\sso\sthat\sthe\s--bom\soption\sonly\soutputs\sa\ssingle\sBOM,\snot\stwo. +D 2024-09-28T19:52:38.443 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -768,7 +768,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 857c60ed21ae2c58d7740d790e8b22e167136ad1930af50527ec0e584a8cc8aa +F src/shell.c.in 345173187067363374187176a8bbe779e359849e635d8288202000ee87f4405a F src/sqlite.h.in b20547021d20ba016c2fd0500f14f08a21ff23e64a0ed93e72ca0fecb9e1d0a0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P c9cbbeda3d1ec4215396aaaf94428b829c4f53329431fa61251914c195f8a9a1 -R 6a112f9240ce847c284940c2c71c0d81 -U stephan -Z be8aef5e16db8f3b229b77cf96144050 +P e815055b321085deda8607ac3279ef1a1c890fe3bf9d9b9c0a74028e87857a7d +R c0b23dfcab02e83590bbedcac610fa7b +U drh +Z 5a1528ca859870969ffba6e26496a443 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 34bc5bb12b..f56b36fa0b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e815055b321085deda8607ac3279ef1a1c890fe3bf9d9b9c0a74028e87857a7d +76b6331e6a705a420a64820a18214f07cf4c1d5151e7158d6fff09964e63f352 diff --git a/src/shell.c.in b/src/shell.c.in index 56f63fb190..d1fc6aa748 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -9913,7 +9913,7 @@ static int do_meta_command(char *zLine, ShellState *p){ int eMode = 0; int bOnce = 0; /* 0: .output, 1: .once, 2: .excel/.www */ int bPlain = 0; /* --plain option */ - static const char *zBomUtf8 = "\xef\xbb\xbf"; + static const char *zBomUtf8 = "\357\273\277"; const char *zBom = 0; failIfSafeMode(p, "cannot run .%s in safe mode", azArg[0]); From d5838eaa42c103649fde3ee1806ff03f7ddece9d Mon Sep 17 00:00:00 2001 From: dan <Dan Kennedy> Date: Mon, 30 Sep 2024 17:28:45 +0000 Subject: [PATCH 44/50] In fts5, avoid starting a new merge of level L if there exists already an ongoing merge of a level less than L. FossilOrigin-Name: 350c6e75ce3c1e81458d1baa73045df489284206e8b279ab3c2f5e3d011c262a --- ext/fts5/fts5_index.c | 7 +++- ext/fts5/test/fts5contentless5.test | 56 +++++++++++++++++++++++++++-- manifest | 16 ++++----- manifest.uuid | 2 +- 4 files changed, 69 insertions(+), 12 deletions(-) diff --git a/ext/fts5/fts5_index.c b/ext/fts5/fts5_index.c index 4363305a56..a51ae19e72 100644 --- a/ext/fts5/fts5_index.c +++ b/ext/fts5/fts5_index.c @@ -4889,6 +4889,11 @@ static int fts5IndexFindDeleteMerge(Fts5Index *p, Fts5Structure *pStruct){ nBest = nPercent; } } + + /* If pLvl is already the input level to an ongoing merge, look no + ** further for a merge candidate. The caller should be allowed to + ** continue merging from pLvl first. */ + if( pLvl->nMerge ) break; } } return iRet; @@ -8813,7 +8818,7 @@ static int fts5structConnectMethod( /* ** We must have a single struct=? constraint that will be passed through -** into the xFilter method. If there is no valid stmt=? constraint, +** into the xFilter method. If there is no valid struct=? constraint, ** then return an SQLITE_CONSTRAINT error. */ static int fts5structBestIndexMethod( diff --git a/ext/fts5/test/fts5contentless5.test b/ext/fts5/test/fts5contentless5.test index 3563678868..86d0753286 100644 --- a/ext/fts5/test/fts5contentless5.test +++ b/ext/fts5/test/fts5contentless5.test @@ -35,8 +35,8 @@ do_execsql_test 1.01 { } # explain_i "UPDATE t1 SET a='a' WHERE t1.rowid=1" -breakpoint -explain_i "UPDATE t1 SET a='a' FROM t2 WHERE t1.rowid=1 AND b IS NULL" +#breakpoint +#explain_i "UPDATE t1 SET a='a' FROM t2 WHERE t1.rowid=1 AND b IS NULL" #breakpoint #explain_i "UPDATE t1 SET a='a' WHERE b IS NULL AND rowid=?" @@ -56,4 +56,56 @@ foreach {tn up err} { do_catchsql_test 1.$tn $up $res($err) } +#------------------------------------------------------------------------- +reset_db + +proc random {n} { expr {abs(int(rand()*$n))} } +proc select_one {list} { + set n [llength $list] + lindex $list [random $n] +} +proc vocab {} { + list abc def ghi jkl mno pqr stu vwx yza +} +proc term {} { + select_one [vocab] +} +proc document {} { + set nTerm [expr [random 3] + 7] + set doc "" + for {set ii 0} {$ii < $nTerm} {incr ii} { + lappend doc [term] + } + set doc +} +db func document document + +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE ft USING fts5(a, contentless_delete=1, content=''); + INSERT INTO ft(ft, rank) VALUES('pgsz', 64); +} + +do_test 2.1 { + for {set ii 1} {$ii < 12} {incr ii} { + db transaction { + for {set jj 0} {$jj < 10} {incr jj} { + set doc [document] + execsql { INSERT INTO ft VALUES($doc); } + } + } + } +} {} + +do_test 2.2 { + foreach r [db eval {SELECT rowid FROM ft}] { + execsql { DELETE FROM ft WHERE rowid=$r } + } +} {} + +set doc [document] +do_execsql_test 2.3 { + INSERT INTO ft VALUES($doc) +} + + finish_test diff --git a/manifest b/manifest index 7566dedc21..77ea93c261 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sCLI\sso\sthat\sthe\s--bom\soption\sonly\soutputs\sa\ssingle\sBOM,\snot\stwo. -D 2024-09-28T19:52:38.443 +C In\sfts5,\savoid\sstarting\sa\snew\smerge\sof\slevel\sL\sif\sthere\sexists\salready\san\songoing\smerge\sof\sa\slevel\sless\sthan\sL. +D 2024-09-30T17:28:45.511 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -99,7 +99,7 @@ F ext/fts5/fts5_buffer.c 0eec58bff585f1a44ea9147eae5da2447292080ea435957f7488c70 F ext/fts5/fts5_config.c da21548ddbc1a457cb42545f527065221ede8ada6a734891b8c34317a7a9506b F ext/fts5/fts5_expr.c 9a56f53700d1860f0ee2f373c2b9074eaf2a7aa0637d0e27a6476de26a3fee33 F ext/fts5/fts5_hash.c adda4272be401566a6e0ba1acbe70ee5cb97fce944bc2e04dc707152a0ec91b1 -F ext/fts5/fts5_index.c 571483823193f09439356741669aa8c81da838ae6f5e1bfa7517f7ee2fb3addd +F ext/fts5/fts5_index.c 368a968570ce12ba40223e284a588d9f93ee23a0133727f0df1fcd64086b1fb6 F ext/fts5/fts5_main.c 4503498d3453e29a3cd89dacaba029011e89cb8c481a6241611d106e7a369bd4 F ext/fts5/fts5_storage.c 3332497823c3d171cf56379f2bd8c971ce15a19aadacff961106462022c92470 F ext/fts5/fts5_tcl.c 4db9258a7882c5eac0da4433042132aaf15b87dd1e1636c7a6ca203abd2c8bfe @@ -145,7 +145,7 @@ F ext/fts5/test/fts5contentless.test 606f063b29ba0f46d4b79aa36cdd1ef4dab5de53eae F ext/fts5/test/fts5contentless2.test 70ffe6c611d8f278240da56734df8a77948f04e2739b358439e9bdcf56ced35f F ext/fts5/test/fts5contentless3.test 75eaae5ad6b284ee447788943974d323228f27cc35a1681da997135cff95bc6a F ext/fts5/test/fts5contentless4.test ec34dc69ef474ca9997dae6d91e072906e0e9a5a4b05ea89964c863833b6eff8 -F ext/fts5/test/fts5contentless5.test 40cdcb4fe751672450829c5a96bd32c25fc2f6076279dd2ce5c58ac9a390132a +F ext/fts5/test/fts5contentless5.test 38cd0392c730dc7090c550321ce3c24ba4c392bc97308b51a4180e9959dca7b5 F ext/fts5/test/fts5corrupt.test 6485f721b88ba355ca5d701e7ee87a4efa3ea578d8e6adb26f51ef956c8328bd F ext/fts5/test/fts5corrupt2.test 335911e3f68b9625d850325f9e29a128db3f4276a8c9d4e32134580da8f924c4 F ext/fts5/test/fts5corrupt3.test 4fc3bf129f1616bea00884a23fd9d7b0e46d01791d2b57fe8d68ac36e8d3ff7c @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P e815055b321085deda8607ac3279ef1a1c890fe3bf9d9b9c0a74028e87857a7d -R c0b23dfcab02e83590bbedcac610fa7b -U drh -Z 5a1528ca859870969ffba6e26496a443 +P 76b6331e6a705a420a64820a18214f07cf4c1d5151e7158d6fff09964e63f352 +R af602edd5730d15273eb424f12f293da +U dan +Z 7c2ca47bd5a0ad794a2bc7691bf0167e # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f56b36fa0b..35fff3b926 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -76b6331e6a705a420a64820a18214f07cf4c1d5151e7158d6fff09964e63f352 +350c6e75ce3c1e81458d1baa73045df489284206e8b279ab3c2f5e3d011c262a From cacef23082b8c60a7c211821a1d679bd25348a1e Mon Sep 17 00:00:00 2001 From: drh <> Date: Mon, 30 Sep 2024 18:19:38 +0000 Subject: [PATCH 45/50] Fix the character width tables for the CLI such that all unicode code-points less than 0x300 have a width of 1. This is in fact the case for Mac, Ubuntu, and Windows. FossilOrigin-Name: f0c5a86fefecded07e098e1326dd54c72504b0bb480f710e395d4041a322dfcb --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c.in | 5 +---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 77ea93c261..cd4363196a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sfts5,\savoid\sstarting\sa\snew\smerge\sof\slevel\sL\sif\sthere\sexists\salready\san\songoing\smerge\sof\sa\slevel\sless\sthan\sL. -D 2024-09-30T17:28:45.511 +C Fix\sthe\scharacter\swidth\stables\sfor\sthe\sCLI\ssuch\sthat\sall\sunicode\scode-points\nless\sthan\s0x300\shave\sa\swidth\sof\s1.\s\sThis\sis\sin\sfact\sthe\scase\sfor\sMac,\sUbuntu,\nand\sWindows. +D 2024-09-30T18:19:38.492 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -768,7 +768,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c 9750a281f7ba073b4e6da2be1a6c4071f5d841a7746c5fb3f70d6d793b6675ea F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 4b14337a2742f0c0beeba490e9a05507e9b4b12184b9cd12773501d08d48e3fe -F src/shell.c.in 345173187067363374187176a8bbe779e359849e635d8288202000ee87f4405a +F src/shell.c.in d71d2463459e6cd9c2f2d702545aed5113ffbcea963c19c1e6d3a6d762ef959c F src/sqlite.h.in b20547021d20ba016c2fd0500f14f08a21ff23e64a0ed93e72ca0fecb9e1d0a0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 76b6331e6a705a420a64820a18214f07cf4c1d5151e7158d6fff09964e63f352 -R af602edd5730d15273eb424f12f293da -U dan -Z 7c2ca47bd5a0ad794a2bc7691bf0167e +P 350c6e75ce3c1e81458d1baa73045df489284206e8b279ab3c2f5e3d011c262a +R 196058ccce20b5d040ef28c3115701ff +U drh +Z c9a58ad028df05647dcb5802e9848199 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 35fff3b926..4742ec1d1d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -350c6e75ce3c1e81458d1baa73045df489284206e8b279ab3c2f5e3d011c262a +f0c5a86fefecded07e098e1326dd54c72504b0bb480f710e395d4041a322dfcb diff --git a/src/shell.c.in b/src/shell.c.in index d1fc6aa748..35b9b089fa 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -631,7 +631,7 @@ static const struct { unsigned char w; /* Width of the character in columns */ int iFirst; /* First character in a span having this width */ } aUWidth[] = { - /* {0, 0x00000}, {1, 0x00020}, {0, 0x0007f}, {1, 0x000a0}, */ + /* {1, 0x00000}, */ {0, 0x00300}, {1, 0x00370}, {0, 0x00483}, {1, 0x00487}, {0, 0x00488}, {1, 0x0048a}, {0, 0x00591}, {1, 0x005be}, {0, 0x005bf}, {1, 0x005c0}, {0, 0x005c1}, {1, 0x005c3}, {0, 0x005c4}, {1, 0x005c6}, {0, 0x005c7}, @@ -709,9 +709,6 @@ int cli_wcwidth(int c){ int iFirst, iLast; /* Fast path for common characters */ - if( c<0x20 ) return 0; - if( c<0x7f ) return 1; - if( c<0xa0 ) return 0; if( c<=0x300 ) return 1; /* The general case */ From ed94e0e6778ca00db96690fe93820436cf2676d2 Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Tue, 1 Oct 2024 10:49:30 +0000 Subject: [PATCH 46/50] Add an #if'd-out block to sqlite3-wasm.c mentioning the LONGDOUBLE_TYPE, as brought up in [forum:cbfb0d0ac0a4e349 | forum post cbfb0d0ac]. No functional changes. FossilOrigin-Name: 0b83e8f1ef53b35a9dda0740b4922b8691428f7484f3058833a961f3f8d0b178 --- ext/wasm/api/sqlite3-wasm.c | 15 +++++++++++++++ manifest | 14 +++++++------- manifest.uuid | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index c5dd495e54..1c46b0ec05 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -221,6 +221,21 @@ // See also: //__attribute__((export_name("theExportedName"), used, visibility("default"))) +#if 0 +/* Details at https://sqlite.org/forum/forumpost/cbfb0d0ac0a4e349 +** +** Summary: changing to `double` reduces the wasm file size by a mere +** 2k. It is hypothetically not possible that any clients rely on +** doubles larger than 64-bit because there is no mapping between C +** and JS for them. i.e. we "could" switch LONGDOUBLE_TYPE to double +** for wasm builds with very little risk of problems. Clang 18.1 maps +** `long double` to float128 but Emscripten doesn't (cannot) expose +** that to JS. +*/ +#undef LONGDOUBLE_TYPE +#define LONGDOUBLE_TYPE double +#endif + /* ** Which sqlite3.c we're using needs to be configurable to enable ** building against a custom copy, e.g. the SEE variant. Note that we diff --git a/manifest b/manifest index cd4363196a..77242f8aca 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\scharacter\swidth\stables\sfor\sthe\sCLI\ssuch\sthat\sall\sunicode\scode-points\nless\sthan\s0x300\shave\sa\swidth\sof\s1.\s\sThis\sis\sin\sfact\sthe\scase\sfor\sMac,\sUbuntu,\nand\sWindows. -D 2024-09-30T18:19:38.492 +C Add\san\s#if'd-out\sblock\sto\ssqlite3-wasm.c\smentioning\sthe\sLONGDOUBLE_TYPE,\sas\sbrought\sup\sin\s[forum:cbfb0d0ac0a4e349\s|\sforum\spost\scbfb0d0ac].\sNo\sfunctional\schanges. +D 2024-10-01T10:49:30.088 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -632,7 +632,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js e529a99b7d5a088284821e2902b20d3404b561126969876997d5a73a656c9199 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js e99e3d99f736937914527070f00ab13e9391d3f1cef884ab99a64cbcbee8d675 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616 -F ext/wasm/api/sqlite3-wasm.c 83f5e9f998e9fa4261eb84e9f092210e3ffe03895119f5ded0429eb34ab9d2be +F ext/wasm/api/sqlite3-wasm.c e94665e6625c8b35113cf0eb7dec7acc2d9ed76eed78b3a1abf6cae5ad8097d3 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 350c6e75ce3c1e81458d1baa73045df489284206e8b279ab3c2f5e3d011c262a -R 196058ccce20b5d040ef28c3115701ff -U drh -Z c9a58ad028df05647dcb5802e9848199 +P f0c5a86fefecded07e098e1326dd54c72504b0bb480f710e395d4041a322dfcb +R 95713aa430bd45b55e204d70dfdb0e42 +U stephan +Z 75aa095723616959401f433a579dd985 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 4742ec1d1d..f0f46579dc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f0c5a86fefecded07e098e1326dd54c72504b0bb480f710e395d4041a322dfcb +0b83e8f1ef53b35a9dda0740b4922b8691428f7484f3058833a961f3f8d0b178 From dac22f656646db9b9429d13c7fcd0a20d6b8a9d6 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 1 Oct 2024 16:55:30 +0000 Subject: [PATCH 47/50] Add compile-time option -DSQLITE_USE_LONG_DOUBLE=0 to omit all attempts to use "long double". Or =1 to omit attempts to use the Dekker algorithms to achieve high-resolution floating point. FossilOrigin-Name: ca5964ef70efad3332e0bf9c158eb5fd5006d3022051d1ac506c097c427735a1 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/main.c | 15 ++++++++++----- src/sqliteInt.h | 35 +++++++++++++++++++++++++++++++++++ src/util.c | 4 ++-- src/vdbeaux.c | 2 +- 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/manifest b/manifest index 77242f8aca..38a8eea1a6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\san\s#if'd-out\sblock\sto\ssqlite3-wasm.c\smentioning\sthe\sLONGDOUBLE_TYPE,\sas\sbrought\sup\sin\s[forum:cbfb0d0ac0a4e349\s|\sforum\spost\scbfb0d0ac].\sNo\sfunctional\schanges. -D 2024-10-01T10:49:30.088 +C Add\scompile-time\soption\s-DSQLITE_USE_LONG_DOUBLE=0\sto\somit\sall\sattempts\sto\suse\n"long\sdouble".\s\sOr\s=1\sto\somit\sattempts\sto\suse\sthe\sDekker\salgorithms\sto\sachieve\nhigh-resolution\sfloating\spoint. +D 2024-10-01T16:55:30.223 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -730,7 +730,7 @@ F src/insert.c f8d1a0f8ee258411009c6b7f2d93170e351bd19f5ad89d57e1180644297cbe70 F src/json.c 68a98c020c22127f2d65f08855f7fc7460ff352a6ce0b543d8931dde83319c22 F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36 -F src/main.c 4db6e3bde55ba0b24ccc83600c2b6ea11429f61ce7b3a2e7e3b42e1b45366c3e +F src/main.c 651be111d1fc05dae62d31cc41335748c27c67455cf777a2d7f48ce1fef585f6 F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2 @@ -772,7 +772,7 @@ F src/shell.c.in d71d2463459e6cd9c2f2d702545aed5113ffbcea963c19c1e6d3a6d762ef959 F src/sqlite.h.in b20547021d20ba016c2fd0500f14f08a21ff23e64a0ed93e72ca0fecb9e1d0a0 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54 -F src/sqliteInt.h 5978cbb11becc3ce6471015d770d95f694ece06336c496f691df1b02460e9cd5 +F src/sqliteInt.h e4940181e20f67b23b7e1b43807ceb3a9cdb38860225de3d5df7eea37bbe6651 F src/sqliteLimit.h 6878ab64bdeb8c24a1d762d45635e34b96da21132179023338c93f820eee6728 F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -835,13 +835,13 @@ F src/trigger.c 0bb986a5b96047fd597c6aac28588853df56064e576e6b81ba777ef2ccaac461 F src/update.c 0e01aa6a3edf9ec112b33eb714b9016a81241497b1fb7c3e74332f4f71756508 F src/upsert.c 215328c3f91623c520ec8672c44323553f12caeb4f01b1090ebdca99fdf7b4f1 F src/utf.c 7bc550af6f3ddd5f5dc82d092c41f728acb760c92e0b47f391963b01ae52569b -F src/util.c 5d1a0134cf4240648d1c6bb5cc8efaca0ea2b5d5c840985aec7e947271f04375 +F src/util.c ae41aadb960cb15d17e8bb9ec0ebb514e1f7ead773ae9fba281ed67c4d240c48 F src/vacuum.c b763b6457bd058d2072ef9364832351fd8d11e8abf70cbb349657360f7d55c40 F src/vdbe.c be5f58bc29f60252e041a618eae59e8d57d460ba136c5403cf0abf955560c457 F src/vdbe.h c2549a215898a390de6669cfa32adba56f0d7e17ba5a7f7b14506d6fd5f0c36a F src/vdbeInt.h af7d7e8291edd0b19f2cd698e60e4d4031078f9a2f2328ac8f0b7efb134f8a1d F src/vdbeapi.c 53c7e26a2c0821a892b20eee2cde4656e31998212f3d515576c780dfaa45fd17 -F src/vdbeaux.c 676dbee99b4febdd94bc9658667a2e3bc413c4c0e356242d90f98a1155d513e5 +F src/vdbeaux.c aa1bd97dc53406c26619b847f4c7f4f0137ee8c7ba9b266f93351e06aefb522e F src/vdbeblob.c 255be187436da38b01f276c02e6a08103489bbe2a7c6c21537b7aecbe0e1f797 F src/vdbemem.c df568ef0187e4be2788c35174f6d9b8566ab9475f9aff2d73907ed05aa5684b2 F src/vdbesort.c d0a3c7056c081703c8b6d91ad60f17da5e062a5c64bf568ed0fa1b5f4cae311f @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f0c5a86fefecded07e098e1326dd54c72504b0bb480f710e395d4041a322dfcb -R 95713aa430bd45b55e204d70dfdb0e42 -U stephan -Z 75aa095723616959401f433a579dd985 +P 0b83e8f1ef53b35a9dda0740b4922b8691428f7484f3058833a961f3f8d0b178 +R 1afae59e0efb08982f93adc40d14c2a9 +U drh +Z 56bb71650eaf744de022c729aea7d991 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index f0f46579dc..72b7e4100f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0b83e8f1ef53b35a9dda0740b4922b8691428f7484f3058833a961f3f8d0b178 +ca5964ef70efad3332e0bf9c158eb5fd5006d3022051d1ac506c097c427735a1 diff --git a/src/main.c b/src/main.c index 6ab09c5560..bd0cbc731a 100644 --- a/src/main.c +++ b/src/main.c @@ -159,6 +159,7 @@ char *sqlite3_temp_directory = 0; */ char *sqlite3_data_directory = 0; +#if !defined(SQLITE_OMIT_WSD) && !defined(SQLITE_USE_LONG_DOUBLE) /* ** Determine whether or not high-precision (long double) floating point ** math works correctly on CPU currently running. @@ -183,7 +184,7 @@ static SQLITE_NOINLINE int hasHighPrecisionDouble(int rc){ return b!=c; } } - +#endif /* !SQLITE_OMIT_WSD && !SQLITE_USE_LONG_DOUBLE */ /* ** Initialize SQLite. @@ -380,9 +381,7 @@ int sqlite3_initialize(void){ } #endif - /* Experimentally determine if high-precision floating point is - ** available. */ -#ifndef SQLITE_OMIT_WSD +#if !defined(SQLITE_OMIT_WSD) && !defined(SQLITE_USE_LONG_DOUBLE) sqlite3Config.bUseLongDouble = hasHighPrecisionDouble(rc); #endif @@ -4645,12 +4644,18 @@ int sqlite3_test_control(int op, ...){ ** X==0 Disable bUseLongDouble ** X==1 Enable bUseLongDouble ** X>=2 Set bUseLongDouble to its default value for this platform + ** + ** If the SQLITE_USE_LONG_DOUBLE compile-time option has been used, then + ** the bUseLongDouble setting is fixed. This test-control becomes a + ** no-op, except that it still reports the fixed setting. */ case SQLITE_TESTCTRL_USELONGDOUBLE: { +#if !defined(SQLITE_USE_LONG_DOUBLE) int b = va_arg(ap, int); if( b>=2 ) b = hasHighPrecisionDouble(b); if( b>=0 ) sqlite3Config.bUseLongDouble = b>0; - rc = sqlite3Config.bUseLongDouble!=0; +#endif + rc = SqliteUseLongDouble!=0; break; } #endif diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 604f7e975e..5b166d9a36 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4249,6 +4249,41 @@ typedef struct { # define Tuning(X) 0 #endif +/* By default, SQLite will use long double if the long double type +** actually provides higher resolution than double. This use or non-use +** of long double is switchable at run-time by a test-control. Dekker +** algorithms are used for high-precision floating point when long double +** is not available. +** +** Having the run-time option to enable/disable long double support +** causes problems for some compiler tool chains. So the following +** compile-time option is available to permanently enable/disable the use +** of long double. +** +** -DSQLITE_USE_LONG_DOUBLE=0 Omit all use of "long double" from +** the code. Instead, the Dekker algorithm +** is always used when high-precision +** floating point is required. +** +** -DSQLITE_USE_LONG_DOUBLE=1 Always use long double when high +** precision is needed. Never fall back +** to using Dekker algorithms. +** +** If the SQLITE_USE_LONG_DOUBLE macro is not defined, then the determination +** of whether or not to use long double is made at run-time. +*/ +#ifndef SQLITE_USE_LONG_DOUBLE +# define SqliteUseLongDouble sqlite3Config.bUseLongDouble +#elif SQLITE_USE_LONG_DOUBLE+0==1 +# define SqliteUseLongDouble 1 +#elif SQLITE_USE_LONG_DOUBLE+0==0 +# undef LONGDOUBLE_TYPE +# define LONGDOUBLE_TYPE double +# define SqliteUseLongDouble 0 +#else +# error "SQLITE_USE_LONG_DOUBLE should be set to either 0 or 1" +#endif + /* ** Structure containing global configuration data for the SQLite library. ** diff --git a/src/util.c b/src/util.c index 0cebb474a2..7a82ce81bf 100644 --- a/src/util.c +++ b/src/util.c @@ -652,7 +652,7 @@ do_atof_calc: if( e==0 ){ *pResult = s; - }else if( sqlite3Config.bUseLongDouble ){ + }else if( SqliteUseLongDouble ){ LONGDOUBLE_TYPE r = (LONGDOUBLE_TYPE)s; if( e>0 ){ while( e>=100 ){ e-=100; r *= 1.0e+100L; } @@ -1063,7 +1063,7 @@ void sqlite3FpDecode(FpDecode *p, double r, int iRound, int mxRound){ /* Multiply r by powers of ten until it lands somewhere in between ** 1.0e+19 and 1.0e+17. */ - if( sqlite3Config.bUseLongDouble ){ + if( SqliteUseLongDouble ){ LONGDOUBLE_TYPE rr = r; if( rr>=1.0e+19 ){ while( rr>=1.0e+119L ){ exp+=100; rr *= 1.0e-100L; } diff --git a/src/vdbeaux.c b/src/vdbeaux.c index a66bdecffb..929190b3af 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4528,7 +4528,7 @@ int sqlite3IntFloatCompare(i64 i, double r){ ** than NULL */ return 1; } - if( sqlite3Config.bUseLongDouble ){ + if( SqliteUseLongDouble ){ LONGDOUBLE_TYPE x = (LONGDOUBLE_TYPE)i; testcase( x<r ); testcase( x>r ); From c9c1b65698ed3fa83985c92e02dd872b56948f79 Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Tue, 1 Oct 2024 17:08:23 +0000 Subject: [PATCH 48/50] Use the new SQLITE_USE_LONG_DOUBLE to disable long-double support in WASM builds, as they cannot be represented in JS and this saves approximately 5.5kb in the resulting wasm file. FossilOrigin-Name: fa7b56f776b715d061581fad6f04b871504ff5d808e7364419d1d6cdef82c5ee --- ext/wasm/GNUmakefile | 2 ++ ext/wasm/api/sqlite3-wasm.c | 6 ++++++ manifest | 16 ++++++++-------- manifest.uuid | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index 2602e6b792..a68f813d6b 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -239,6 +239,7 @@ SQLITE_OPT.common := \ '-DSQLITE_DEFAULT_UNIX_VFS="unix-none"' \ -DSQLITE_USE_URI=1 \ -DSQLITE_C=$(sqlite3.c) \ + -DSQLITE_USE_LONG_DOUBLE=0 \ -DSQLITE_OMIT_DEPRECATED \ -DSQLITE_OMIT_UTF16 \ -DSQLITE_OMIT_LOAD_EXTENSION \ @@ -251,6 +252,7 @@ SQLITE_OPT.common := \ # to be able to run without this: SQLITE_OPT.common += -DSQLITE_WASM_ENABLE_C_TESTS +# Extra flags for full-featured builds... SQLITE_OPT.full-featured := \ -DSQLITE_ENABLE_BYTECODE_VTAB \ -DSQLITE_ENABLE_DBPAGE_VTAB \ diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 1c46b0ec05..945acd23dd 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -127,6 +127,10 @@ # define SQLITE_USE_URI 1 #endif +#ifndef SQLITE_USE_LONG_DOUBLE +# define SQLITE_USE_LONG_DOUBLE 0 +#endif + #ifdef SQLITE_WASM_EXTRA_INIT # define SQLITE_EXTRA_INIT sqlite3_wasm_extra_init #endif @@ -159,6 +163,8 @@ # define SQLITE_OMIT_PROGRESS_CALLBACK # undef SQLITE_OMIT_WAL # define SQLITE_OMIT_WAL +# undef SQLITE_USE_LONG_DOUBLE +# define SQLITE_USE_LONG_DOUBLE 0 /* The following OMITs do not work with the standard amalgamation, so require a custom build: diff --git a/manifest b/manifest index 38a8eea1a6..037e9a4724 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\scompile-time\soption\s-DSQLITE_USE_LONG_DOUBLE=0\sto\somit\sall\sattempts\sto\suse\n"long\sdouble".\s\sOr\s=1\sto\somit\sattempts\sto\suse\sthe\sDekker\salgorithms\sto\sachieve\nhigh-resolution\sfloating\spoint. -D 2024-10-01T16:55:30.223 +C Use\sthe\snew\sSQLITE_USE_LONG_DOUBLE\sto\sdisable\slong-double\ssupport\sin\sWASM\sbuilds,\sas\sthey\scannot\sbe\srepresented\sin\sJS\sand\sthis\ssaves\sapproximately\s5.5kb\sin\sthe\sresulting\swasm\sfile. +D 2024-10-01T17:08:23.912 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -603,7 +603,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt ca7e9ee82ca4e1c1744295f8184dd70edfae1992865d26c64303f539eb6c084c F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c -F ext/wasm/GNUmakefile 6b94c3125c40932e71bbe46e582d24ed4c829b9fa2ff34dd842b0ed8a948ac6a +F ext/wasm/GNUmakefile c2ee5993e727dd2c1f0f784f47843fb7af45cebd23626b537bae2d2d8f4a3abd F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193 F ext/wasm/SQLTester/GNUmakefile e0794f676d55819951bbfae45cc5e8d7818dc460492dc317ce7f0d2eca15caff @@ -632,7 +632,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js e529a99b7d5a088284821e2902b20d3404b561126969876997d5a73a656c9199 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js e99e3d99f736937914527070f00ab13e9391d3f1cef884ab99a64cbcbee8d675 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616 -F ext/wasm/api/sqlite3-wasm.c e94665e6625c8b35113cf0eb7dec7acc2d9ed76eed78b3a1abf6cae5ad8097d3 +F ext/wasm/api/sqlite3-wasm.c 2ac6cff59668eed42a87b8b21ff66f0edf82b25c04bbb8adda0c4eff28ed11ce F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0b83e8f1ef53b35a9dda0740b4922b8691428f7484f3058833a961f3f8d0b178 -R 1afae59e0efb08982f93adc40d14c2a9 -U drh -Z 56bb71650eaf744de022c729aea7d991 +P ca5964ef70efad3332e0bf9c158eb5fd5006d3022051d1ac506c097c427735a1 +R 7b5589656a320d55088e87a9d21d3695 +U stephan +Z b3281d7ec085a9e7d4c5e83e25b26b8b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 72b7e4100f..7113b4ff6a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ca5964ef70efad3332e0bf9c158eb5fd5006d3022051d1ac506c097c427735a1 +fa7b56f776b715d061581fad6f04b871504ff5d808e7364419d1d6cdef82c5ee From 1f2faa647f32b4182c43156f5107a59574647104 Mon Sep 17 00:00:00 2001 From: stephan <stephan@noemail.net> Date: Tue, 1 Oct 2024 17:57:55 +0000 Subject: [PATCH 49/50] Another comment about the LONGDOUBLE wasm topic. No code changes. FossilOrigin-Name: 1755831cb1ac58241e0b11d8d003b5eca39b65aa3cb84229b215662028b1b3c0 --- ext/wasm/api/sqlite3-wasm.c | 2 ++ manifest | 12 ++++++------ manifest.uuid | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 945acd23dd..b689b426fb 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -237,6 +237,8 @@ ** for wasm builds with very little risk of problems. Clang 18.1 maps ** `long double` to float128 but Emscripten doesn't (cannot) expose ** that to JS. +** +** See also: SQLITE_USE_LONG_DOUBLE */ #undef LONGDOUBLE_TYPE #define LONGDOUBLE_TYPE double diff --git a/manifest b/manifest index 037e9a4724..65c7f28e25 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Use\sthe\snew\sSQLITE_USE_LONG_DOUBLE\sto\sdisable\slong-double\ssupport\sin\sWASM\sbuilds,\sas\sthey\scannot\sbe\srepresented\sin\sJS\sand\sthis\ssaves\sapproximately\s5.5kb\sin\sthe\sresulting\swasm\sfile. -D 2024-10-01T17:08:23.912 +C Another\scomment\sabout\sthe\sLONGDOUBLE\swasm\stopic.\sNo\scode\schanges. +D 2024-10-01T17:57:55.467 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -632,7 +632,7 @@ F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js e529a99b7d5a088284821e2902b20d3404b561126969876997d5a73a656c9199 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js e99e3d99f736937914527070f00ab13e9391d3f1cef884ab99a64cbcbee8d675 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js e809739d71e8b35dfe1b55d24d91f02d04239e6aef7ca1ea92a15a29e704f616 -F ext/wasm/api/sqlite3-wasm.c 2ac6cff59668eed42a87b8b21ff66f0edf82b25c04bbb8adda0c4eff28ed11ce +F ext/wasm/api/sqlite3-wasm.c 2d4340f2dacd9119e95c470d9c4f392e399feffc292962b855f0a67ffb0fc418 F ext/wasm/api/sqlite3-worker1-promiser.c-pp.js 46f303ba8ddd1b2f0a391798837beddfa72e8c897038c8047eda49ce7d5ed46b F ext/wasm/api/sqlite3-worker1.c-pp.js 5e8706c2c4af2a57fbcdc02f4e7ef79869971bc21bb8ede777687786ce1c92d5 F ext/wasm/batch-runner-sahpool.html e9a38fdeb36a13eac7b50241dfe7ae066fe3f51f5c0b0151e7baee5fce0d07a7 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P ca5964ef70efad3332e0bf9c158eb5fd5006d3022051d1ac506c097c427735a1 -R 7b5589656a320d55088e87a9d21d3695 +P fa7b56f776b715d061581fad6f04b871504ff5d808e7364419d1d6cdef82c5ee +R f9afa03cdf9385554f9061800ab5a24b U stephan -Z b3281d7ec085a9e7d4c5e83e25b26b8b +Z 7a6ac00554cffba6a7d224734b670d11 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7113b4ff6a..d4c262a19a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fa7b56f776b715d061581fad6f04b871504ff5d808e7364419d1d6cdef82c5ee +1755831cb1ac58241e0b11d8d003b5eca39b65aa3cb84229b215662028b1b3c0 From 7151010919cff7ab5134173f5d22fdf534104c34 Mon Sep 17 00:00:00 2001 From: drh <> Date: Tue, 1 Oct 2024 19:10:47 +0000 Subject: [PATCH 50/50] New #ifdefs to omit code that is unused when SQLITE_USE_LONG DOUBLE is defined. FossilOrigin-Name: 98066e2d226e7d2eceec1931a1432baea956f49bf3c708d8a6d511fa4e864ca3 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/util.c | 4 ++++ src/vdbeaux.c | 6 +++++- test/speedtest1.c | 12 +++++++++--- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index 65c7f28e25..ac49e358bf 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Another\scomment\sabout\sthe\sLONGDOUBLE\swasm\stopic.\sNo\scode\schanges. -D 2024-10-01T17:57:55.467 +C New\s#ifdefs\sto\somit\scode\sthat\sis\sunused\swhen\sSQLITE_USE_LONG\sDOUBLE\sis\sdefined. +D 2024-10-01T19:10:47.855 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -835,13 +835,13 @@ F src/trigger.c 0bb986a5b96047fd597c6aac28588853df56064e576e6b81ba777ef2ccaac461 F src/update.c 0e01aa6a3edf9ec112b33eb714b9016a81241497b1fb7c3e74332f4f71756508 F src/upsert.c 215328c3f91623c520ec8672c44323553f12caeb4f01b1090ebdca99fdf7b4f1 F src/utf.c 7bc550af6f3ddd5f5dc82d092c41f728acb760c92e0b47f391963b01ae52569b -F src/util.c ae41aadb960cb15d17e8bb9ec0ebb514e1f7ead773ae9fba281ed67c4d240c48 +F src/util.c aea7987484ec05764eabdd63b55eb63ea85cfb5b95dde70a667711c1d326f1a7 F src/vacuum.c b763b6457bd058d2072ef9364832351fd8d11e8abf70cbb349657360f7d55c40 F src/vdbe.c be5f58bc29f60252e041a618eae59e8d57d460ba136c5403cf0abf955560c457 F src/vdbe.h c2549a215898a390de6669cfa32adba56f0d7e17ba5a7f7b14506d6fd5f0c36a F src/vdbeInt.h af7d7e8291edd0b19f2cd698e60e4d4031078f9a2f2328ac8f0b7efb134f8a1d F src/vdbeapi.c 53c7e26a2c0821a892b20eee2cde4656e31998212f3d515576c780dfaa45fd17 -F src/vdbeaux.c aa1bd97dc53406c26619b847f4c7f4f0137ee8c7ba9b266f93351e06aefb522e +F src/vdbeaux.c a30204ae8820ee5165736c2e67fe9b62ad47690c72248b4adba0435b0b3f8bfe F src/vdbeblob.c 255be187436da38b01f276c02e6a08103489bbe2a7c6c21537b7aecbe0e1f797 F src/vdbemem.c df568ef0187e4be2788c35174f6d9b8566ab9475f9aff2d73907ed05aa5684b2 F src/vdbesort.c d0a3c7056c081703c8b6d91ad60f17da5e062a5c64bf568ed0fa1b5f4cae311f @@ -1668,7 +1668,7 @@ F test/speed3.test 694affeb9100526007436334cf7d08f3d74b85ef F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 377a0c48e5a92e0b11c1c5ebb1bc9d83a7312c922bc0cb05970ef5d6a96d1f0c -F test/speedtest1.c 19c9b60908d25502d2831f97efee8b81006c356ab8c08327e25d24a4144f2131 +F test/speedtest1.c 82f273f6df420bb1563d5202277e4a907e4e032a96a86fa7cf8c7aed34b32724 F test/spellfix.test 951a6405d49d1a23d6b78027d3877b4a33eeb8221dcab5704b499755bb4f552e F test/spellfix2.test dfc8f519a3fc204cb2dfa8b4f29821ae90f6f8c3 F test/spellfix3.test 0f9efaaa502a0e0a09848028518a6fb096c8ad33 @@ -2213,8 +2213,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P fa7b56f776b715d061581fad6f04b871504ff5d808e7364419d1d6cdef82c5ee -R f9afa03cdf9385554f9061800ab5a24b -U stephan -Z 7a6ac00554cffba6a7d224734b670d11 +P 1755831cb1ac58241e0b11d8d003b5eca39b65aa3cb84229b215662028b1b3c0 +R aec30d14f5d302123caffa8ac548b88e +U drh +Z 3d8c02a9a1123f16b58018bc4d458ba9 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index d4c262a19a..19cf9165e2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1755831cb1ac58241e0b11d8d003b5eca39b65aa3cb84229b215662028b1b3c0 +98066e2d226e7d2eceec1931a1432baea956f49bf3c708d8a6d511fa4e864ca3 diff --git a/src/util.c b/src/util.c index 7a82ce81bf..6725306eda 100644 --- a/src/util.c +++ b/src/util.c @@ -458,6 +458,7 @@ u8 sqlite3StrIHash(const char *z){ return h; } +#if !defined(SQLITE_USE_LONG_DOUBLE) || SQLITE_USE_LONG_DOUBLE+0==0 /* Double-Double multiplication. (x[0],x[1]) *= (y,yy) ** ** Reference: @@ -493,6 +494,9 @@ static void dekkerMul2(volatile double *x, double y, double yy){ x[1] = c - x[0]; x[1] += cc; } +#else +# define dekkerMul2(A,B,C) /* No-op if SqliteUseLongDouble is always true */ +#endif /* ** The string z[] is an text representation of a real number. diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 929190b3af..5ff4ca928c 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -4512,9 +4512,13 @@ SQLITE_NOINLINE int sqlite3BlobCompare(const Mem *pB1, const Mem *pB2){ ** We must use separate SQLITE_NOINLINE functions here, since otherwise ** optimizer code movement causes gcov to become very confused. */ -#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG) +#if (defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_DEBUG)) \ + && (!defined(SQLITE_USE_LONG_DOUBLE) || SQLITE_USE_LONG_DOUBLE+0==0) static int SQLITE_NOINLINE doubleLt(double a, double b){ return a<b; } static int SQLITE_NOINLINE doubleEq(double a, double b){ return a==b; } +#else +# define doubleLt(A,B) 1 +# define doubleEq(A,B) 1 #endif /* diff --git a/test/speedtest1.c b/test/speedtest1.c index 5709423818..00559b3bc8 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -2277,6 +2277,7 @@ int main(int argc, char **argv){ int iCur, iHi; /* Stats values, current and "highwater" */ int i; /* Loop counter */ int rc; /* API return code */ + int useLongDouble = -1; /* True to set use of long-double */ #ifdef SQLITE_SPEEDTEST1_WASM /* Resetting all state is important for the WASM build, which may @@ -2334,6 +2335,8 @@ int main(int argc, char **argv){ }else if( strcmp(z,"key")==0 ){ ARGC_VALUE_CHECK(1); zKey = argv[++i]; + }else if( strcmp(z,"longdouble")==0 ){ + useLongDouble = 1; }else if( strcmp(z,"lookaside")==0 ){ ARGC_VALUE_CHECK(2); nLook = integerValue(argv[i+1]); @@ -2353,9 +2356,7 @@ int main(int argc, char **argv){ mmapSize = integerValue(argv[++i]); #endif }else if( strcmp(z,"nolongdouble")==0 ){ -#ifdef SQLITE_TESTCTRL_USELONGDOUBLE - sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, 0); -#endif + useLongDouble = 0; }else if( strcmp(z,"nomutex")==0 ){ openFlags |= SQLITE_OPEN_NOMUTEX; }else if( strcmp(z,"nosync")==0 ){ @@ -2528,6 +2529,11 @@ int main(int argc, char **argv){ if( rc ) fatal_error("lookaside configuration failed: %d\n", rc); } #endif +#ifdef SQLITE_TESTCTRL_USELONGDOUBLE + if( useLongDouble>=0 ){ + sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE, useLongDouble); + } +#endif if( g.nReserve>0 ){ sqlite3_file_control(g.db, 0, SQLITE_FCNTL_RESERVE_BYTES, &g.nReserve); }