/ Changes On Branch begin-concurrent-pnu
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch begin-concurrent-pnu Excluding Merge-Ins

This is equivalent to a diff from 123cbb33 to 5fa4cbcb

2020-08-31
20:29
Update this branch with the "PRAGMA noop_update" fix from begin-concurrent-pnu. (Leaf check-in: 3c0423f0 user: dan tags: begin-concurrent-report)
20:27
Restore the "PRAGMA noop_update" feature that was broken by [2b3241cf67c8eea7]. (Leaf check-in: 5fa4cbcb user: dan tags: begin-concurrent-pnu)
2020-08-10
21:30
Merge recent trunk fixes into the begin-concurrent-pnu branch. (check-in: 2ae78c99 user: drh tags: begin-concurrent-pnu)
2018-12-29
20:42
Fix a problem causing a corrupt pager-cache if an OOM or IO error was encountered while committing a concurrent transacation. (check-in: 48ca30f9 user: dan tags: begin-concurrent)
2018-12-18
17:47
Merge latest begin-concurrent changes into this branch. (check-in: a93ca38b user: dan tags: begin-concurrent-pnu)
17:20
Merge latest trunk changes into this branch. (check-in: 123cbb33 user: dan tags: begin-concurrent)
2018-12-17
22:19
Move variable declaration to address compilation issue (C89). (check-in: d64f248d user: mistachkin tags: trunk)
2018-12-06
02:08
Merge bug fixes from trunk. (check-in: 1e13aaa2 user: drh tags: begin-concurrent)

Added LICENSE.md.

            1  +The author disclaims copyright to this source code.  In place of
            2  +a legal notice, here is a blessing:
            3  +
            4  +  *   May you do good and not evil.
            5  +  *   May you find forgiveness for yourself and forgive others.
            6  +  *   May you share freely, never taking more than you give.

Changes to Makefile.in.

   186    186            notify.lo opcodes.lo os.lo os_unix.lo os_win.lo \
   187    187            pager.lo parse.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \
   188    188            random.lo resolve.lo rowset.lo rtree.lo \
   189    189            sqlite3session.lo select.lo sqlite3rbu.lo status.lo stmt.lo \
   190    190            table.lo threads.lo tokenize.lo treeview.lo trigger.lo \
   191    191            update.lo userauth.lo upsert.lo util.lo vacuum.lo \
   192    192            vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \
   193         -         vdbetrace.lo wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \
          193  +         vdbetrace.lo vdbevtab.lo \
          194  +         wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \
   194    195            window.lo utf.lo vtab.lo
   195    196   
   196    197   # Object files for the amalgamation.
   197    198   #
   198    199   LIBOBJS1 = sqlite3.lo
   199    200   
   200    201   # Determine the real value of LIBOBJ based on the 'configure' script
................................................................................
   292    293     $(TOP)/src/vdbe.h \
   293    294     $(TOP)/src/vdbeapi.c \
   294    295     $(TOP)/src/vdbeaux.c \
   295    296     $(TOP)/src/vdbeblob.c \
   296    297     $(TOP)/src/vdbemem.c \
   297    298     $(TOP)/src/vdbesort.c \
   298    299     $(TOP)/src/vdbetrace.c \
          300  +  $(TOP)/src/vdbevtab.c \
   299    301     $(TOP)/src/vdbeInt.h \
   300    302     $(TOP)/src/vtab.c \
   301    303     $(TOP)/src/vxworks.h \
   302    304     $(TOP)/src/wal.c \
   303    305     $(TOP)/src/wal.h \
   304    306     $(TOP)/src/walker.c \
   305    307     $(TOP)/src/where.c \
................................................................................
   418    420     $(TOP)/src/test_schema.c \
   419    421     $(TOP)/src/test_server.c \
   420    422     $(TOP)/src/test_superlock.c \
   421    423     $(TOP)/src/test_syscall.c \
   422    424     $(TOP)/src/test_tclsh.c \
   423    425     $(TOP)/src/test_tclvar.c \
   424    426     $(TOP)/src/test_thread.c \
          427  +  $(TOP)/src/test_vdbecov.c \
   425    428     $(TOP)/src/test_vfs.c \
   426    429     $(TOP)/src/test_windirent.c \
   427    430     $(TOP)/src/test_window.c \
   428    431     $(TOP)/src/test_wsd.c       \
   429    432     $(TOP)/ext/fts3/fts3_term.c \
   430    433     $(TOP)/ext/fts3/fts3_test.c  \
   431    434     $(TOP)/ext/session/test_session.c \
................................................................................
   436    439   TESTSRC += \
   437    440     $(TOP)/ext/expert/sqlite3expert.c \
   438    441     $(TOP)/ext/expert/test_expert.c \
   439    442     $(TOP)/ext/misc/amatch.c \
   440    443     $(TOP)/ext/misc/carray.c \
   441    444     $(TOP)/ext/misc/closure.c \
   442    445     $(TOP)/ext/misc/csv.c \
          446  +  $(TOP)/ext/misc/decimal.c \
   443    447     $(TOP)/ext/misc/eval.c \
   444    448     $(TOP)/ext/misc/explain.c \
   445    449     $(TOP)/ext/misc/fileio.c \
   446    450     $(TOP)/ext/misc/fuzzer.c \
   447    451     $(TOP)/ext/fts5/fts5_tcl.c \
   448    452     $(TOP)/ext/fts5/fts5_test_mi.c \
   449    453     $(TOP)/ext/fts5/fts5_test_tok.c \
   450    454     $(TOP)/ext/misc/ieee754.c \
   451    455     $(TOP)/ext/misc/mmapwarm.c \
   452    456     $(TOP)/ext/misc/nextchar.c \
   453    457     $(TOP)/ext/misc/normalize.c \
   454    458     $(TOP)/ext/misc/percentile.c \
          459  +  $(TOP)/ext/misc/prefixes.c \
   455    460     $(TOP)/ext/misc/regexp.c \
   456    461     $(TOP)/ext/misc/remember.c \
   457    462     $(TOP)/ext/misc/series.c \
   458    463     $(TOP)/ext/misc/spellfix.c \
   459    464     $(TOP)/ext/misc/totype.c \
   460    465     $(TOP)/ext/misc/unionvtab.c \
   461    466     $(TOP)/ext/misc/wholenumber.c \
................................................................................
   496    501     $(TOP)/src/utf.c \
   497    502     $(TOP)/src/util.c \
   498    503     $(TOP)/src/vdbeapi.c \
   499    504     $(TOP)/src/vdbeaux.c \
   500    505     $(TOP)/src/vdbe.c \
   501    506     $(TOP)/src/vdbemem.c \
   502    507     $(TOP)/src/vdbetrace.c \
          508  +  $(TOP)/src/vdbevtab.c \
   503    509     $(TOP)/src/where.c \
   504    510     $(TOP)/src/wherecode.c \
   505    511     $(TOP)/src/whereexpr.c \
   506    512     $(TOP)/src/window.c \
   507    513     parse.c \
   508    514     $(TOP)/ext/fts3/fts3.c \
   509    515     $(TOP)/ext/fts3/fts3_aux.c \
................................................................................
   584    590   FUZZDATA = \
   585    591     $(TOP)/test/fuzzdata1.db \
   586    592     $(TOP)/test/fuzzdata2.db \
   587    593     $(TOP)/test/fuzzdata3.db \
   588    594     $(TOP)/test/fuzzdata4.db \
   589    595     $(TOP)/test/fuzzdata5.db \
   590    596     $(TOP)/test/fuzzdata6.db \
   591         -  $(TOP)/test/fuzzdata7.db
          597  +  $(TOP)/test/fuzzdata7.db \
          598  +  $(TOP)/test/fuzzdata8.db
   592    599   
   593    600   # Standard options to testfixture
   594    601   #
   595    602   TESTOPTS = --verbose=file --output=test-out.txt
   596    603   
   597    604   # Extra compiler options for various shell tools
   598    605   #
................................................................................
   600    607   #SHELL_OPT += -DSQLITE_ENABLE_FTS5
   601    608   SHELL_OPT += -DSQLITE_ENABLE_RTREE
   602    609   SHELL_OPT += -DSQLITE_ENABLE_EXPLAIN_COMMENTS
   603    610   SHELL_OPT += -DSQLITE_ENABLE_UNKNOWN_SQL_FUNCTION
   604    611   SHELL_OPT += -DSQLITE_ENABLE_STMTVTAB
   605    612   SHELL_OPT += -DSQLITE_ENABLE_DBPAGE_VTAB
   606    613   SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
          614  +SHELL_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
   607    615   SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
   608    616   SHELL_OPT += -DSQLITE_ENABLE_DESERIALIZE
   609         -SHELL_OPT += -DSQLITE_INTROSPECTION_PRAGMAS
   610    617   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   611    618   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
   612    619   FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
   613    620   FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
          621  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DESERIALIZE
          622  +FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
          623  +FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS3_PARENTHESIS
          624  +#FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
          625  +FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
          626  +FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
          627  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
          628  +FUZZCHECK_OPT += -DSQLITE_ENABLE_BYTECODE_VTAB
   614    629   FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c
   615    630   DBFUZZ_OPT =
   616    631   
   617    632   # This is the default Makefile target.  The objects listed here
   618    633   # are what get build when you type just "make" with no arguments.
   619    634   #
   620    635   all:	sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)
................................................................................
   676    691   
   677    692   DBFUZZ2_OPTS = \
   678    693     -DSQLITE_THREADSAFE=0 \
   679    694     -DSQLITE_OMIT_LOAD_EXTENSION \
   680    695     -DSQLITE_ENABLE_DESERIALIZE \
   681    696     -DSQLITE_DEBUG \
   682    697     -DSQLITE_ENABLE_DBSTAT_VTAB \
          698  +  -DSQLITE_ENABLE_BYTECODE_VTAB \
   683    699     -DSQLITE_ENABLE_RTREE \
   684    700     -DSQLITE_ENABLE_FTS4 \
   685         -  -DSQLITE_EANBLE_FTS5
          701  +  -DSQLITE_ENABLE_FTS5
   686    702   
   687         -dbfuzz2:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          703  +dbfuzz2$(TEXE):	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          704  +	$(CC) $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
          705  +		-DSTANDALONE -o dbfuzz2 \
          706  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
          707  +	mkdir -p dbfuzz2-dir
          708  +	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
          709  +
          710  +dbfuzz2-asan:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          711  +	clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
          712  +		-fsanitize=fuzzer,undefined,address -o dbfuzz2-asan \
          713  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
          714  +	mkdir -p dbfuzz2-dir
          715  +	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
          716  +
          717  +dbfuzz2-msan:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
   688    718   	clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
   689         -		-fsanitize=fuzzer,undefined,address -o dbfuzz2 \
   690         -		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c
          719  +		-fsanitize=fuzzer,undefined,memory -o dbfuzz2-msan \
          720  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
   691    721   	mkdir -p dbfuzz2-dir
   692    722   	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
   693    723   
   694    724   mptester$(TEXE):	sqlite3.lo $(TOP)/mptest/mptest.c
   695    725   	$(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.lo \
   696    726   		$(TLIBS) -rpath "$(libdir)"
   697    727   
................................................................................
   978   1008   
   979   1009   vdbesort.lo:	$(TOP)/src/vdbesort.c $(HDR)
   980   1010   	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vdbesort.c
   981   1011   
   982   1012   vdbetrace.lo:	$(TOP)/src/vdbetrace.c $(HDR)
   983   1013   	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vdbetrace.c
   984   1014   
         1015  +vdbevtab.lo:	$(TOP)/src/vdbevtab.c $(HDR)
         1016  +	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vdbevtab.c
         1017  +
   985   1018   vtab.lo:	$(TOP)/src/vtab.c $(HDR)
   986   1019   	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/vtab.c
   987   1020   
   988   1021   wal.lo:	$(TOP)/src/wal.c $(HDR)
   989   1022   	$(LTCOMPILE) $(TEMP_STORE) -c $(TOP)/src/wal.c
   990   1023   
   991   1024   walker.lo:	$(TOP)/src/walker.c $(HDR)
................................................................................
  1024   1057   opcodes.h:	parse.h $(TOP)/src/vdbe.c $(TOP)/tool/mkopcodeh.tcl
  1025   1058   	cat parse.h $(TOP)/src/vdbe.c | $(TCLSH_CMD) $(TOP)/tool/mkopcodeh.tcl >opcodes.h
  1026   1059   
  1027   1060   # Rules to build parse.c and parse.h - the outputs of lemon.
  1028   1061   #
  1029   1062   parse.h:	parse.c
  1030   1063   
  1031         -parse.c:	$(TOP)/src/parse.y lemon$(BEXE) $(TOP)/tool/addopcodes.tcl
         1064  +parse.c:	$(TOP)/src/parse.y lemon$(BEXE)
  1032   1065   	cp $(TOP)/src/parse.y .
  1033         -	rm -f parse.h
  1034         -	./lemon$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) parse.y
  1035         -	mv parse.h parse.h.temp
  1036         -	$(TCLSH_CMD) $(TOP)/tool/addopcodes.tcl parse.h.temp >parse.h
         1066  +	./lemon$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) -S parse.y
  1037   1067   
  1038   1068   sqlite3.h:	$(TOP)/src/sqlite.h.in $(TOP)/manifest mksourceid$(BEXE) $(TOP)/VERSION
  1039   1069   	$(TCLSH_CMD) $(TOP)/tool/mksqlite3h.tcl $(TOP) >sqlite3.h
         1070  +
         1071  +sqlite3rc.h:	$(TOP)/src/sqlite3.rc $(TOP)/VERSION
         1072  +	echo '#ifndef SQLITE_RESOURCE_VERSION' >$@
         1073  +	echo -n '#define SQLITE_RESOURCE_VERSION ' >>$@
         1074  +	cat $(TOP)/VERSION | $(TCLSH_CMD) $(TOP)/tool/replace.tcl exact . , >>$@
         1075  +	echo '#endif' >>sqlite3rc.h
  1040   1076   
  1041   1077   keywordhash.h:	$(TOP)/tool/mkkeywordhash.c
  1042   1078   	$(BCC) -o mkkeywordhash$(BEXE) $(OPT_FEATURE_FLAGS) $(OPTS) $(TOP)/tool/mkkeywordhash.c
  1043   1079   	./mkkeywordhash$(BEXE) >keywordhash.h
  1044   1080   
  1045   1081   # Source files that go into making shell.c
  1046   1082   SHELL_SRC = \
  1047   1083   	$(TOP)/src/shell.c.in \
  1048   1084           $(TOP)/ext/misc/appendvfs.c \
  1049         -	$(TOP)/ext/misc/shathree.c \
         1085  +	$(TOP)/ext/misc/completion.c \
         1086  +        $(TOP)/ext/misc/decimal.c \
  1050   1087   	$(TOP)/ext/misc/fileio.c \
  1051         -	$(TOP)/ext/misc/completion.c \
         1088  +        $(TOP)/ext/misc/ieee754.c \
         1089  +	$(TOP)/ext/misc/shathree.c \
  1052   1090   	$(TOP)/ext/misc/sqlar.c \
         1091  +        $(TOP)/ext/misc/uint.c \
  1053   1092   	$(TOP)/ext/expert/sqlite3expert.c \
  1054   1093   	$(TOP)/ext/expert/sqlite3expert.h \
  1055   1094   	$(TOP)/ext/misc/zipfile.c \
         1095  +	$(TOP)/ext/misc/memtrace.c \
  1056   1096           $(TOP)/src/test_windirent.c
  1057   1097   
  1058   1098   shell.c:	$(SHELL_SRC) $(TOP)/tool/mkshellc.tcl
  1059   1099   	$(TCLSH_CMD) $(TOP)/tool/mkshellc.tcl >shell.c
  1060   1100   
  1061   1101   
  1062   1102   
................................................................................
  1122   1162   
  1123   1163   fts3_write.lo:	$(TOP)/ext/fts3/fts3_write.c $(HDR) $(EXTHDR)
  1124   1164   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_write.c
  1125   1165   
  1126   1166   rtree.lo:	$(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR)
  1127   1167   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c
  1128   1168   
  1129         -sqlite3session.lo:	$(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
         1169  +userauth.lo:	$(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
  1130   1170   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/userauth/userauth.c
  1131   1171   
  1132         -userauth.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
         1172  +sqlite3session.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
  1133   1173   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/session/sqlite3session.c
  1134   1174   
  1135   1175   json1.lo:	$(TOP)/ext/misc/json1.c
  1136   1176   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/json1.c
  1137   1177   
  1138   1178   stmt.lo:	$(TOP)/ext/misc/stmt.c
  1139   1179   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/stmt.c
................................................................................
  1153   1193      fts5parse.c fts5parse.h \
  1154   1194      $(TOP)/ext/fts5/fts5_storage.c \
  1155   1195      $(TOP)/ext/fts5/fts5_tokenize.c \
  1156   1196      $(TOP)/ext/fts5/fts5_unicode2.c \
  1157   1197      $(TOP)/ext/fts5/fts5_varint.c \
  1158   1198      $(TOP)/ext/fts5/fts5_vocab.c  \
  1159   1199   
  1160         -fts5parse.c:	$(TOP)/ext/fts5/fts5parse.y lemon
         1200  +fts5parse.c:	$(TOP)/ext/fts5/fts5parse.y lemon$(BEXE)
  1161   1201   	cp $(TOP)/ext/fts5/fts5parse.y .
  1162   1202   	rm -f fts5parse.h
  1163         -	./lemon$(BEXE) $(OPTS) fts5parse.y
         1203  +	./lemon$(BEXE) $(OPTS) -S fts5parse.y
  1164   1204   
  1165   1205   fts5parse.h: fts5parse.c
  1166   1206   
  1167   1207   fts5.c: $(FTS5_SRC)
  1168   1208   	$(TCLSH_CMD) $(TOP)/ext/fts5/tool/mkfts5c.tcl
  1169   1209   	cp $(TOP)/ext/fts5/fts5.h .
  1170   1210   
................................................................................
  1186   1226   TESTFIXTURE_FLAGS += -DTCLSH_INIT_PROC=sqlite3TestInit
  1187   1227   TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE
  1188   1228   TESTFIXTURE_FLAGS += -DBUILD_sqlite
  1189   1229   TESTFIXTURE_FLAGS += -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
  1190   1230   TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024
  1191   1231   TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_STMTVTAB
  1192   1232   TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DBPAGE_VTAB
         1233  +TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_BYTECODE_VTAB
  1193   1234   TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DESERIALIZE
  1194   1235   
  1195   1236   TESTFIXTURE_SRC0 = $(TESTSRC2) libsqlite3.la
  1196   1237   TESTFIXTURE_SRC1 = sqlite3.c
  1197   1238   TESTFIXTURE_SRC = $(TESTSRC) $(TOP)/src/tclsqlite.c
  1198   1239   TESTFIXTURE_SRC += $(TESTFIXTURE_SRC$(USE_AMALGAMATION))
  1199   1240   
................................................................................
  1218   1259   	./testfixture$(TEXE) $(TOP)/test/full.test
  1219   1260   
  1220   1261   # Fuzz testing
  1221   1262   fuzztest:	fuzzcheck$(TEXE) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
  1222   1263   	./fuzzcheck$(TEXE) $(FUZZDATA)
  1223   1264   	./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
  1224   1265   
  1225         -fastfuzztest:	fuzzcheck$(TEXE) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
  1226         -	./fuzzcheck$(TEXE) --limit-mem 100M $(FUZZDATA)
  1227         -	./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
  1228         -
  1229   1266   valgrindfuzz:	fuzzcheck$(TEXT) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
  1230   1267   	valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M --timeout 600 $(FUZZDATA)
  1231   1268   	valgrind ./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
  1232   1269   
  1233   1270   # The veryquick.test TCL tests.
  1234   1271   #
  1235   1272   tcltest:	./testfixture$(TEXE)
................................................................................
  1239   1276   #
  1240   1277   quicktest:	./testfixture$(TEXE)
  1241   1278   	./testfixture$(TEXE) $(TOP)/test/extraquick.test $(TESTOPTS)
  1242   1279   
  1243   1280   # This is the common case.  Run many tests that do not take too long,
  1244   1281   # including fuzzcheck, sqlite3_analyzer, and sqldiff tests.
  1245   1282   #
  1246         -test:	fastfuzztest sourcetest $(TESTPROGS) tcltest
         1283  +test:	fuzztest sourcetest $(TESTPROGS) tcltest
  1247   1284   
  1248   1285   # Run a test using valgrind.  This can take a really long time
  1249   1286   # because valgrind is so much slower than a native machine.
  1250   1287   #
  1251   1288   valgrindtest:	$(TESTPROGS) valgrindfuzz
  1252   1289   	OMIT_MISUSE=1 valgrind -v ./testfixture$(TEXE) $(TOP)/test/permutations.test valgrind $(TESTOPTS)
  1253   1290   
................................................................................
  1254   1291   # A very fast test that checks basic sanity.  The name comes from
  1255   1292   # the 60s-era electronics testing:  "Turn it on and see if smoke
  1256   1293   # comes out."
  1257   1294   #
  1258   1295   smoketest:	$(TESTPROGS) fuzzcheck$(TEXE)
  1259   1296   	./testfixture$(TEXE) $(TOP)/test/main.test $(TESTOPTS)
  1260   1297   
         1298  +shelltest: $(TESTPROGS)
         1299  +	./testfixture$(TEXT) $(TOP)/test/permutations.test shell
         1300  +
  1261   1301   sqlite3_analyzer.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in
  1262   1302   	$(TCLSH_CMD) $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in >sqlite3_analyzer.c
  1263   1303   
  1264   1304   sqlite3_analyzer$(TEXE): sqlite3_analyzer.c
  1265   1305   	$(LTLINK) sqlite3_analyzer.c -o $@ $(LIBTCL) $(TLIBS)
  1266   1306   
  1267   1307   sqltclsh.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/sqltclsh.tcl $(TOP)/ext/misc/appendvfs.c $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqltclsh.c.in
................................................................................
  1308   1348   showwal$(TEXE):	$(TOP)/tool/showwal.c sqlite3.lo
  1309   1349   	$(LTLINK) -o $@ $(TOP)/tool/showwal.c sqlite3.lo $(TLIBS)
  1310   1350   
  1311   1351   showshm$(TEXE):	$(TOP)/tool/showshm.c
  1312   1352   	$(LTLINK) -o $@ $(TOP)/tool/showshm.c
  1313   1353   
  1314   1354   index_usage$(TEXE): $(TOP)/tool/index_usage.c sqlite3.lo
  1315         -	$(LTLINK) -o $@ $(TOP)/tool/index_usage.c sqlite3.lo $(TLIBS)
         1355  +	$(LTLINK) $(SHELL_OPT) -o $@ $(TOP)/tool/index_usage.c sqlite3.lo $(TLIBS)
  1316   1356   
  1317   1357   changeset$(TEXE):	$(TOP)/ext/session/changeset.c sqlite3.lo
  1318   1358   	$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c sqlite3.lo $(TLIBS)
  1319   1359   
  1320   1360   changesetfuzz$(TEXE):	$(TOP)/ext/session/changesetfuzz.c sqlite3.lo
  1321   1361   	$(LTLINK) -o $@ $(TOP)/ext/session/changesetfuzz.c sqlite3.lo $(TLIBS)
  1322   1362   
................................................................................
  1347   1387   	$(LTLINK) $(TOP)/tool/loadfts.c libsqlite3.la -o $@ $(TLIBS)
  1348   1388   
  1349   1389   # This target will fail if the SQLite amalgamation contains any exported
  1350   1390   # symbols that do not begin with "sqlite3_". It is run as part of the
  1351   1391   # releasetest.tcl script.
  1352   1392   #
  1353   1393   VALIDIDS=' sqlite3(changeset|changegroup|session)?_'
  1354         -checksymbols: sqlite3.lo
  1355         -	nm -g --defined-only sqlite3.lo | egrep -v $(VALIDIDS); test $$? -ne 0
         1394  +checksymbols: sqlite3.o
         1395  +	nm -g --defined-only sqlite3.o
         1396  +	nm -g --defined-only sqlite3.o | egrep -v $(VALIDIDS); test $$? -ne 0
  1356   1397   	echo '0 errors out of 1 tests'
  1357   1398   
  1358   1399   # Build the amalgamation-autoconf package.  The amalamgation-tarball target builds
  1359   1400   # a tarball named for the version number.  Ex:  sqlite-autoconf-3110000.tar.gz.
  1360   1401   # The snapshot-tarball target builds a tarball named by the SHA1 hash
  1361   1402   #
  1362         -amalgamation-tarball: sqlite3.c
         1403  +amalgamation-tarball: sqlite3.c sqlite3rc.h
  1363   1404   	TOP=$(TOP) sh $(TOP)/tool/mkautoconfamal.sh --normal
  1364   1405   
  1365         -snapshot-tarball: sqlite3.c
         1406  +snapshot-tarball: sqlite3.c sqlite3rc.h
  1366   1407   	TOP=$(TOP) sh $(TOP)/tool/mkautoconfamal.sh --snapshot
  1367   1408   
  1368   1409   # The next two rules are used to support the "threadtest" target. Building
  1369   1410   # threadtest runs a few thread-safety tests that are implemented in C. This
  1370   1411   # target is invoked by the releasetest.tcl script.
  1371   1412   #
  1372   1413   THREADTEST3_SRC = $(TOP)/test/threadtest3.c    \
................................................................................
  1397   1438   	$(INSTALL) -d $(DESTDIR)$(includedir)
  1398   1439   	$(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(includedir)
  1399   1440   	$(INSTALL) -m 0644 $(TOP)/src/sqlite3ext.h $(DESTDIR)$(includedir)
  1400   1441   	$(INSTALL) -d $(DESTDIR)$(pkgconfigdir)
  1401   1442   	$(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir)
  1402   1443   
  1403   1444   pkgIndex.tcl:
  1404         -	echo 'package ifneeded sqlite3 $(RELEASE) [list load $(TCLLIBDIR)/libtclsqlite3$(SHLIB_SUFFIX) sqlite3]' > $@
         1445  +	echo 'package ifneeded sqlite3 $(RELEASE) [list load [file join $$dir libtclsqlite3[info sharedlibextension]] sqlite3]' > $@
  1405   1446   tcl_install:	lib_install libtclsqlite3.la pkgIndex.tcl
  1406   1447   	$(INSTALL) -d $(DESTDIR)$(TCLLIBDIR)
  1407   1448   	$(LTINSTALL) libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR)
  1408   1449   	rm -f $(DESTDIR)$(TCLLIBDIR)/libtclsqlite3.la $(DESTDIR)$(TCLLIBDIR)/libtclsqlite3.a
  1409   1450   	$(INSTALL) -m 0644 pkgIndex.tcl $(DESTDIR)$(TCLLIBDIR)
  1410   1451   
  1411   1452   clean:

Changes to Makefile.linux-gcc.

    15     15   #    that contains this "Makefile.in" and the "configure.in" script.
    16     16   #
    17     17   TOP = ../sqlite
    18     18   
    19     19   #### C Compiler and options for use in building executables that
    20     20   #    will run on the platform that is doing the build.
    21     21   #
    22         -BCC = gcc -g -O2
           22  +BCC = gcc -g -O0
    23     23   #BCC = /opt/ancic/bin/c89 -0
    24     24   
    25     25   #### If the target operating system supports the "usleep()" system
    26     26   #    call, then define the HAVE_USLEEP macro for all C modules.
    27     27   #
    28     28   #USLEEP = 
    29     29   USLEEP = -DHAVE_USLEEP=1
................................................................................
    34     34   #
    35     35   #THREADSAFE = -DTHREADSAFE=1
    36     36   THREADSAFE = -DTHREADSAFE=0
    37     37   
    38     38   #### Specify any extra linker options needed to make the library
    39     39   #    thread safe
    40     40   #
    41         -#THREADLIB = -lpthread
    42         -THREADLIB = 
           41  +THREADLIB = -lpthread -lm -ldl
           42  +#THREADLIB = 
    43     43   
    44     44   #### Specify any extra libraries needed to access required functions.
    45     45   #
    46     46   #TLIBS = -lrt    # fdatasync on Solaris 8
    47     47   TLIBS = 
    48     48   
    49     49   #### Leave SQLITE_DEBUG undefined for maximum speed.  Use SQLITE_DEBUG=1
................................................................................
    50     50   #    to check for memory leaks.  Use SQLITE_DEBUG=2 to print a log of all
    51     51   #    malloc()s and free()s in order to track down memory leaks.
    52     52   #    
    53     53   #    SQLite uses some expensive assert() statements in the inner loop.
    54     54   #    You can make the library go almost twice as fast if you compile
    55     55   #    with -DNDEBUG=1
    56     56   #
    57         -#OPTS = -DSQLITE_DEBUG=2
    58         -#OPTS = -DSQLITE_DEBUG=1
    59         -#OPTS = 
    60         -OPTS = -DNDEBUG=1
    61         -OPTS += -DHAVE_FDATASYNC=1
           57  +OPTS += -DSQLITE_DEBUG=1
           58  +OPTS += -DSQLITE_ENABLE_WHERETRACE
           59  +OPTS += -DSQLITE_ENABLE_SELECTTRACE
    62     60   
    63     61   #### The suffix to add to executable files.  ".exe" for windows.
    64     62   #    Nothing for unix.
    65     63   #
    66     64   #EXE = .exe
    67     65   EXE =
    68     66   
    69     67   #### C Compile and options for use in building executables that 
    70     68   #    will run on the target platform.  This is usually the same
    71     69   #    as BCC, unless you are cross-compiling.
    72     70   #
    73         -TCC = gcc -O6
           71  +TCC = gcc -O0
    74     72   #TCC = gcc -g -O0 -Wall
    75     73   #TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage
    76     74   #TCC = /opt/mingw/bin/i386-mingw32-gcc -O6
    77     75   #TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive
    78     76   
    79     77   #### Tools used to build a static library.
    80     78   #
................................................................................
    87     85   SO = so
    88     86   SHPREFIX = lib
    89     87   # SO = dll
    90     88   # SHPREFIX =
    91     89   
    92     90   #### Extra compiler options needed for programs that use the TCL library.
    93     91   #
    94         -#TCL_FLAGS =
    95         -#TCL_FLAGS = -DSTATIC_BUILD=1
    96         -TCL_FLAGS = -I/home/drh/tcltk/8.5linux
    97         -#TCL_FLAGS = -I/home/drh/tcltk/8.5win -DSTATIC_BUILD=1
    98         -#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux
           92  +TCL_FLAGS = -I/home/drh/tcl/include/tcl8.6
    99     93   
   100     94   #### Linker options needed to link against the TCL library.
   101     95   #
   102     96   #LIBTCL = -ltcl -lm -ldl
   103         -LIBTCL = /home/drh/tcltk/8.5linux/libtcl8.5g.a -lm -ldl
   104         -#LIBTCL = /home/drh/tcltk/8.5win/libtcl85s.a -lmsvcrt
   105         -#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc
           97  +LIBTCL = /home/drh/tcl/lib/libtcl8.6.a -lm -lpthread -ldl -lz
   106     98   
   107     99   #### Additional objects for SQLite library when TCL support is enabled.
   108    100   #TCLOBJ =
   109    101   TCLOBJ = tclsqlite.o
   110    102   
   111    103   #### Compiler options needed for programs that use the readline() library.
   112    104   #

Changes to Makefile.msc.

    69     69   # If necessary, create a list of harmless compiler warnings to disable when
    70     70   # compiling the various tools.  For the SQLite source code itself, warnings,
    71     71   # if any, will be disabled from within it.
    72     72   #
    73     73   !IFNDEF NO_WARN
    74     74   !IF $(USE_FULLWARN)!=0
    75     75   NO_WARN = -wd4054 -wd4055 -wd4100 -wd4127 -wd4130 -wd4152 -wd4189 -wd4206
    76         -NO_WARN = $(NO_WARN) -wd4210 -wd4232 -wd4305 -wd4306 -wd4702 -wd4706
           76  +NO_WARN = $(NO_WARN) -wd4210 -wd4232 -wd4244 -wd4305 -wd4306 -wd4702 -wd4706
    77     77   !ENDIF
    78     78   !ENDIF
    79     79   
    80     80   # Set this non-0 to use the library paths and other options necessary for
    81     81   # Windows Phone 8.1.
    82     82   #
    83     83   !IFNDEF USE_WP81_OPTS
................................................................................
   230    230   # 5 == SQLITE_DEBUG_OS_TRACE: Enables output from the OSTRACE() macros.
   231    231   # 6 == SQLITE_ENABLE_IOTRACE: Enables output from the IOTRACE() macros.
   232    232   #
   233    233   !IFNDEF DEBUG
   234    234   DEBUG = 0
   235    235   !ENDIF
   236    236   
          237  +# <<mark>>
          238  +# Disable use of the --linemacros argument to the mksqlite3c.tcl tool, which
          239  +# is used to build the amalgamation.
          240  +#
          241  +!IFNDEF NO_LINEMACROS
          242  +NO_LINEMACROS = 0
          243  +!ENDIF
          244  +# <</mark>>
          245  +
   237    246   # Enable use of available compiler optimizations?  Normally, this should be
   238    247   # non-zero.  Setting this to zero, thus disabling all compiler optimizations,
   239    248   # can be useful for testing.
   240    249   #
   241    250   !IFNDEF OPTIMIZATIONS
   242    251   OPTIMIZATIONS = 2
   243    252   !ENDIF
   244    253   
   245    254   # Set this to non-0 to enable support for the session extension.
   246    255   #
   247    256   !IFNDEF SESSION
   248    257   SESSION = 0
   249    258   !ENDIF
          259  +
          260  +# Set this to non-0 to enable support for the rbu extension.
          261  +#
          262  +!IFNDEF RBU
          263  +RBU = 0
          264  +!ENDIF
   250    265   
   251    266   # Set the source code file to be used by executables and libraries when
   252    267   # they need the amalgamation.
   253    268   #
   254    269   !IFNDEF SQLITE3C
   255    270   !IF $(SPLIT_AMALGAMATION)!=0
   256    271   SQLITE3C = sqlite3-all.c
................................................................................
   315    330   !IFNDEF SQLITETCLH
   316    331   SQLITETCLH = sqlite_tcl.h
   317    332   !ENDIF
   318    333   
   319    334   !IFNDEF SQLITETCLDECLSH
   320    335   SQLITETCLDECLSH = sqlite_tclDecls.h
   321    336   !ENDIF
          337  +
          338  +# This is the name to use for the dynamic link library (DLL) containing the
          339  +# Tcl bindings for SQLite.
          340  +#
          341  +!IFNDEF SQLITE3TCLDLL
          342  +SQLITE3TCLDLL = tclsqlite3.dll
          343  +!ENDIF
   322    344   
   323    345   # These are the additional targets that the targets that integrate with the
   324    346   # Tcl library should depend on when compiling, etc.
   325    347   #
   326    348   !IFNDEF SQLITE_TCL_DEP
   327    349   !IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0
   328    350   SQLITE_TCL_DEP = $(SQLITETCLDECLSH) $(SQLITETCLH)
................................................................................
   340    362   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3=1
   341    363   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1
   342    364   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_GEOPOLY=1
   343    365   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
   344    366   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
   345    367   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
   346    368   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
   347         -OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_INTROSPECTION_PRAGMAS=1
          369  +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
   348    370   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
   349    371   !ENDIF
   350    372   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
   351    373   !ENDIF
   352    374   
   353    375   # Should the session extension be enabled?  If so, add compilation options
   354    376   # to enable it.
   355    377   #
   356    378   !IF $(SESSION)!=0
   357    379   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_SESSION=1
   358    380   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK=1
   359    381   !ENDIF
          382  +
          383  +# Should the rbu extension be enabled?  If so, add compilation options
          384  +# to enable it.
          385  +#
          386  +!IF $(RBU)!=0
          387  +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RBU=1
          388  +!ENDIF
   360    389   
   361    390   # These are the "extended" SQLite compilation options used when compiling for
   362    391   # the Windows 10 platform.
   363    392   #
   364    393   !IFNDEF EXT_FEATURE_FLAGS
   365    394   !IF $(FOR_WIN10)!=0
   366    395   EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4=1
................................................................................
   491    520   
   492    521   UCRTLIBPATH = $(UCRTLIBPATH:\\=\)
   493    522   
   494    523   # C compiler and options for use in building executables that
   495    524   # will run on the platform that is doing the build.
   496    525   #
   497    526   !IF $(USE_FULLWARN)!=0
   498         -BCC = $(NCC) -nologo -W4 $(CCOPTS) $(BCCOPTS)
          527  +BCC = $(NCC) -nologo -W4 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
   499    528   !ELSE
   500         -BCC = $(NCC) -nologo -W3 $(CCOPTS) $(BCCOPTS)
          529  +BCC = $(NCC) -nologo -W3 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
   501    530   !ENDIF
   502    531   
   503    532   # Check if assembly code listings should be generated for the source
   504    533   # code files to be compiled.
   505    534   #
   506    535   !IF $(USE_LISTINGS)!=0
   507    536   BCC = $(BCC) -FAcs
................................................................................
   752    781   MKSQLITE3C_TOOL = $(TOP)\tool\mksqlite3c-noext.tcl
   753    782   !ELSE
   754    783   MKSQLITE3C_TOOL = $(TOP)\tool\mksqlite3c.tcl
   755    784   !ENDIF
   756    785   !ENDIF
   757    786   
   758    787   !IFNDEF MKSQLITE3C_ARGS
   759         -!IF $(DEBUG)>1
          788  +!IF $(DEBUG)>1 && $(NO_LINEMACROS)==0
   760    789   MKSQLITE3C_ARGS = --linemacros
   761    790   !ELSE
   762    791   MKSQLITE3C_ARGS =
   763    792   !ENDIF
   764    793   !IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0
   765    794   MKSQLITE3C_ARGS = $(MKSQLITE3C_ARGS) --useapicall
   766    795   !ENDIF
................................................................................
   849    878   # <<mark>>
   850    879   # The locations of the Tcl header and library files.  Also, the library that
   851    880   # non-stubs enabled programs using Tcl must link against.  These variables
   852    881   # (TCLINCDIR, TCLLIBDIR, and LIBTCL) may be overridden via the environment
   853    882   # prior to running nmake in order to match the actual installed location and
   854    883   # version on this machine.
   855    884   #
          885  +!IFNDEF TCLVERSION
          886  +TCLVERSION = 86
          887  +!ENDIF
          888  +
          889  +!IFNDEF TCLSUFFIX
          890  +TCLSUFFIX =
          891  +!ENDIF
          892  +
   856    893   !IFNDEF TCLDIR
   857    894   TCLDIR = $(TOP)\compat\tcl
   858    895   !ENDIF
   859    896   
   860    897   !IFNDEF TCLINCDIR
   861    898   TCLINCDIR = $(TCLDIR)\include
   862    899   !ENDIF
   863    900   
   864    901   !IFNDEF TCLLIBDIR
   865    902   TCLLIBDIR = $(TCLDIR)\lib
   866    903   !ENDIF
   867    904   
   868    905   !IFNDEF LIBTCL
   869         -LIBTCL = tcl86.lib
          906  +LIBTCL = tcl$(TCLVERSION)$(TCLSUFFIX).lib
   870    907   !ENDIF
   871    908   
   872    909   !IFNDEF LIBTCLSTUB
   873         -LIBTCLSTUB = tclstub86.lib
          910  +LIBTCLSTUB = tclstub$(TCLVERSION)$(TCLSUFFIX).lib
   874    911   !ENDIF
   875    912   
   876    913   !IFNDEF LIBTCLPATH
   877    914   LIBTCLPATH = $(TCLDIR)\bin
   878    915   !ENDIF
   879    916   
   880    917   # The locations of the zlib header and library files.  These variables
................................................................................
  1059   1096   RCC = $(RCC) -I$(ICUINCDIR)
  1060   1097   !ENDIF
  1061   1098   # <</mark>>
  1062   1099   
  1063   1100   # Command line prefixes for compiling code, compiling resources,
  1064   1101   # linking, etc.
  1065   1102   #
  1066         -LTCOMPILE = $(TCC) -Fo$@
         1103  +LTCOMPILE = $(TCC) -Fo$@ -Fd$*.pdb
  1067   1104   LTRCOMPILE = $(RCC) -r
  1068   1105   LTLIB = lib.exe
  1069   1106   LTLINK = $(TCC) -Fe$@
  1070   1107   
  1071   1108   # If requested, link to the RPCRT4 library.
  1072   1109   #
  1073   1110   !IF $(USE_RPCRT4_LIB)!=0
................................................................................
  1077   1114   # If a platform was set, force the linker to target that.
  1078   1115   # Note that the vcvars*.bat family of batch files typically
  1079   1116   # set this for you.  Otherwise, the linker will attempt
  1080   1117   # to deduce the binary type based on the object files.
  1081   1118   !IFDEF PLATFORM
  1082   1119   LTLINKOPTS = /NOLOGO /MACHINE:$(PLATFORM)
  1083   1120   LTLIBOPTS = /NOLOGO /MACHINE:$(PLATFORM)
         1121  +!ELSEIF "$(VISUALSTUDIOVERSION)"=="12.0" || \
         1122  +        "$(VISUALSTUDIOVERSION)"=="14.0" || \
         1123  +        "$(VISUALSTUDIOVERSION)"=="15.0"
         1124  +LTLINKOPTS = /NOLOGO /MACHINE:x86
         1125  +LTLIBOPTS = /NOLOGO /MACHINE:x86
  1084   1126   !ELSE
  1085   1127   LTLINKOPTS = /NOLOGO
  1086   1128   LTLIBOPTS = /NOLOGO
  1087   1129   !ENDIF
  1088   1130   
  1089   1131   # When compiling for use in the WinRT environment, the following
  1090   1132   # linker option must be used to mark the executable as runnable
................................................................................
  1210   1252            notify.lo opcodes.lo os.lo os_unix.lo os_win.lo \
  1211   1253            pager.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \
  1212   1254            random.lo resolve.lo rowset.lo rtree.lo \
  1213   1255            sqlite3session.lo select.lo sqlite3rbu.lo status.lo stmt.lo \
  1214   1256            table.lo threads.lo tokenize.lo treeview.lo trigger.lo \
  1215   1257            update.lo upsert.lo util.lo vacuum.lo \
  1216   1258            vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \
  1217         -         vdbetrace.lo wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \
         1259  +         vdbetrace.lo vdbevtab.lo wal.lo walker.lo where.lo wherecode.lo \
         1260  +         whereexpr.lo \
  1218   1261            window.lo utf.lo vtab.lo
  1219   1262   # <</mark>>
  1220   1263   
  1221   1264   # Object files for the amalgamation.
  1222   1265   #
  1223   1266   LIBOBJS1 = sqlite3.lo
  1224   1267   
................................................................................
  1317   1360     $(TOP)\src\vdbe.c \
  1318   1361     $(TOP)\src\vdbeapi.c \
  1319   1362     $(TOP)\src\vdbeaux.c \
  1320   1363     $(TOP)\src\vdbeblob.c \
  1321   1364     $(TOP)\src\vdbemem.c \
  1322   1365     $(TOP)\src\vdbesort.c \
  1323   1366     $(TOP)\src\vdbetrace.c \
         1367  +  $(TOP)\src\vdbevtab.c \
  1324   1368     $(TOP)\src\vtab.c \
  1325   1369     $(TOP)\src\wal.c \
  1326   1370     $(TOP)\src\walker.c \
  1327   1371     $(TOP)\src\where.c \
  1328   1372     $(TOP)\src\wherecode.c \
  1329   1373     $(TOP)\src\whereexpr.c \
  1330   1374     $(TOP)\src\window.c
................................................................................
  1447   1491     $(SQLITETCLDECLSH)
  1448   1492   !ELSE
  1449   1493   SRC12 =
  1450   1494   !ENDIF
  1451   1495   
  1452   1496   # All source code files.
  1453   1497   #
  1454         -SRC = $(SRC00) $(SRC01) $(SRC03) $(SRC04) $(SRC05) $(SRC06) $(SRC07) $(SRC08) $(SRC09) $(SRC10) $(SRC11)
         1498  +SRC = $(SRC00) $(SRC01) $(SRC03) $(SRC04) $(SRC05) $(SRC06) $(SRC07) $(SRC08) $(SRC09) $(SRC10) $(SRC11) $(SRC12)
  1455   1499   
  1456   1500   # Source code to the test files.
  1457   1501   #
  1458   1502   TESTSRC = \
  1459   1503     $(TOP)\src\test1.c \
  1460   1504     $(TOP)\src\test2.c \
  1461   1505     $(TOP)\src\test3.c \
................................................................................
  1493   1537     $(TOP)\src\test_schema.c \
  1494   1538     $(TOP)\src\test_server.c \
  1495   1539     $(TOP)\src\test_superlock.c \
  1496   1540     $(TOP)\src\test_syscall.c \
  1497   1541     $(TOP)\src\test_tclsh.c \
  1498   1542     $(TOP)\src\test_tclvar.c \
  1499   1543     $(TOP)\src\test_thread.c \
         1544  +  $(TOP)\src\test_vdbecov.c \
  1500   1545     $(TOP)\src\test_vfs.c \
  1501   1546     $(TOP)\src\test_windirent.c \
  1502   1547     $(TOP)\src\test_window.c \
  1503   1548     $(TOP)\src\test_wsd.c \
  1504   1549     $(TOP)\ext\fts3\fts3_term.c \
  1505   1550     $(TOP)\ext\fts3\fts3_test.c \
  1506   1551     $(TOP)\ext\rbu\test_rbu.c \
................................................................................
  1511   1556   TESTEXT = \
  1512   1557     $(TOP)\ext\expert\sqlite3expert.c \
  1513   1558     $(TOP)\ext\expert\test_expert.c \
  1514   1559     $(TOP)\ext\misc\amatch.c \
  1515   1560     $(TOP)\ext\misc\carray.c \
  1516   1561     $(TOP)\ext\misc\closure.c \
  1517   1562     $(TOP)\ext\misc\csv.c \
         1563  +  $(TOP)\ext\misc\decimal.c \
  1518   1564     $(TOP)\ext\misc\eval.c \
  1519   1565     $(TOP)\ext\misc\explain.c \
  1520   1566     $(TOP)\ext\misc\fileio.c \
  1521   1567     $(TOP)\ext\misc\fuzzer.c \
  1522   1568     $(TOP)\ext\fts5\fts5_tcl.c \
  1523   1569     $(TOP)\ext\fts5\fts5_test_mi.c \
  1524   1570     $(TOP)\ext\fts5\fts5_test_tok.c \
  1525   1571     $(TOP)\ext\misc\ieee754.c \
  1526   1572     $(TOP)\ext\misc\mmapwarm.c \
  1527   1573     $(TOP)\ext\misc\nextchar.c \
  1528   1574     $(TOP)\ext\misc\normalize.c \
  1529   1575     $(TOP)\ext\misc\percentile.c \
         1576  +  $(TOP)\ext\misc\prefixes.c \
  1530   1577     $(TOP)\ext\misc\regexp.c \
  1531   1578     $(TOP)\ext\misc\remember.c \
  1532   1579     $(TOP)\ext\misc\series.c \
  1533   1580     $(TOP)\ext\misc\spellfix.c \
  1534   1581     $(TOP)\ext\misc\totype.c \
  1535   1582     $(TOP)\ext\misc\unionvtab.c \
  1536   1583     $(TOP)\ext\misc\wholenumber.c
................................................................................
  1621   1668   FUZZDATA = \
  1622   1669     $(TOP)\test\fuzzdata1.db \
  1623   1670     $(TOP)\test\fuzzdata2.db \
  1624   1671     $(TOP)\test\fuzzdata3.db \
  1625   1672     $(TOP)\test\fuzzdata4.db \
  1626   1673     $(TOP)\test\fuzzdata5.db \
  1627   1674     $(TOP)\test\fuzzdata6.db \
  1628         -  $(TOP)\test\fuzzdata7.db
         1675  +  $(TOP)\test\fuzzdata7.db \
         1676  +  $(TOP)\test\fuzzdata8.db
  1629   1677   # <</mark>>
  1630   1678   
  1631   1679   # Additional compiler options for the shell.  These are only effective
  1632   1680   # when the shell is not being dynamically linked.
  1633   1681   #
  1634   1682   !IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0
  1635   1683   SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
................................................................................
  1639   1687   !ENDIF
  1640   1688   
  1641   1689   # <<mark>>
  1642   1690   # Extra compiler options for various test tools.
  1643   1691   #
  1644   1692   MPTESTER_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5
  1645   1693   FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1
  1646         -FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
         1694  +FUZZCHECK_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
         1695  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DESERIALIZE
         1696  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS4
         1697  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
         1698  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_GEOPOLY
         1699  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
         1700  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_BYTECODE_VTAB
         1701  +
  1647   1702   FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c
  1648   1703   OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
  1649   1704   DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION
  1650   1705   KV_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
  1651   1706   ST_COMPILE_OPTS = -DSQLITE_THREADSAFE=0
  1652   1707   
  1653   1708   # Standard options to testfixture.
  1654   1709   #
  1655   1710   TESTOPTS = --verbose=file --output=test-out.txt
  1656   1711   
  1657   1712   # Extra targets for the "all" target that require Tcl.
  1658   1713   #
  1659   1714   !IF $(NO_TCL)==0
  1660         -ALL_TCL_TARGETS = libtclsqlite3.lib
         1715  +ALL_TCL_TARGETS = $(SQLITE3TCLDLL)
  1661   1716   !ELSE
  1662   1717   ALL_TCL_TARGETS =
  1663   1718   !ENDIF
  1664   1719   # <</mark>>
  1665   1720   
  1666   1721   # This is the default Makefile target.  The objects listed here
  1667   1722   # are what get build when you type just "make" with no arguments.
................................................................................
  1685   1740   shell:	$(SQLITE3EXE)
  1686   1741   
  1687   1742   # <<mark>>
  1688   1743   libsqlite3.lib:	$(LIBOBJ)
  1689   1744   	$(LTLIB) $(LTLIBOPTS) /OUT:$@ $(LIBOBJ) $(TLIBS)
  1690   1745   
  1691   1746   libtclsqlite3.lib:	tclsqlite.lo libsqlite3.lib
  1692         -	$(LTLIB) $(LTLIBOPTS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS)
         1747  +	$(LTLIB) $(LTLIBOPTS) $(TCLLIBPATHS) $(LTLIBPATHS) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCLSTUB) $(TLIBS)
         1748  +
         1749  +tclsqlite3.def:	tclsqlite.lo
         1750  +	echo EXPORTS > tclsqlite3.def
         1751  +	dumpbin /all tclsqlite.lo \
         1752  +		| $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+/EXPORT:_?((?:Sqlite3|Tclsqlite3)_[^@]*)(?:@\d+)?$$" \1 \
         1753  +		| sort >> tclsqlite3.def
         1754  +
         1755  +pkgIndex.tcl:	$(TOP)\VERSION
         1756  +	for /F %%V in ('type "$(TOP)\VERSION"') do ( \
         1757  +		echo package ifneeded sqlite3 @version@ [list load [file join $$dir $(SQLITE3TCLDLL)] sqlite3] \
         1758  +			| $(TCLSH_CMD) $(TOP)\tool\replace.tcl exact @version@ %%V > pkgIndex.tcl \
         1759  +	)
         1760  +
         1761  +$(SQLITE3TCLDLL):	libtclsqlite3.lib $(LIBRESOBJS) tclsqlite3.def pkgIndex.tcl
         1762  +	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /DEF:tclsqlite3.def /OUT:$@ libtclsqlite3.lib $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1693   1763   # <</mark>>
  1694   1764   
  1695   1765   $(SQLITE3DLL):	$(LIBOBJ) $(LIBRESOBJS) $(CORE_LINK_DEP)
  1696   1766   	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL $(CORE_LINK_OPTS) /OUT:$@ $(LIBOBJ) $(LIBRESOBJS) $(LTLIBS) $(TLIBS)
  1697   1767   
  1698   1768   # <<block2>>
  1699   1769   sqlite3.def:	libsqlite3.lib
  1700   1770   	echo EXPORTS > sqlite3.def
  1701   1771   	dumpbin /all libsqlite3.lib \
  1702         -		| $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3(?:session|changeset|changegroup|rebaser)?_[^@]*)(?:@\d+)?$$" \1 \
         1772  +		| $(TCLSH_CMD) $(TOP)\tool\replace.tcl include "^\s+1 _?(sqlite3(?:session|changeset|changegroup|rebaser|rbu)?_[^@]*)(?:@\d+)?$$" \1 \
  1703   1773   		| sort >> sqlite3.def
  1704   1774   # <</block2>>
  1705   1775   
  1706   1776   $(SQLITE3EXE):	shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H)
  1707   1777   	$(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) shell.c $(SHELL_CORE_SRC) \
  1708   1778   		/link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS)
  1709   1779   
................................................................................
  1726   1796   fuzzershell.exe:	$(TOP)\tool\fuzzershell.c $(SQLITE3C) $(SQLITE3H)
  1727   1797   	$(LTLINK) $(NO_WARN) $(FUZZERSHELL_COMPILE_OPTS) $(TOP)\tool\fuzzershell.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1728   1798   
  1729   1799   dbfuzz.exe:	$(TOP)\test\dbfuzz.c $(SQLITE3C) $(SQLITE3H)
  1730   1800   	$(LTLINK) $(NO_WARN) $(DBFUZZ_COMPILE_OPTS) $(TOP)\test\dbfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1731   1801   
  1732   1802   fuzzcheck.exe:	$(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
  1733         -	$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         1803  +	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1734   1804   
  1735   1805   ossshell.exe:	$(OSSSHELL_SRC) $(SQLITE3C) $(SQLITE3H)
  1736         -	$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         1806  +	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1737   1807   
  1738   1808   sessionfuzz.exe:	zlib $(TOP)\test\sessionfuzz.c $(SQLITE3C) $(SQLITE3H)
  1739   1809   	$(LTLINK) $(NO_WARN) -I$(ZLIBINCDIR) $(TOP)\test\sessionfuzz.c /link $(LDFLAGS) $(LTLINKOPTS) /LIBPATH:$(ZLIBLIBDIR) $(ZLIBLIB)
  1740   1810   
  1741   1811   mptester.exe:	$(TOP)\mptest\mptest.c $(SQLITE3C) $(SQLITE3H)
  1742   1812   	$(LTLINK) $(NO_WARN) $(MPTESTER_COMPILE_OPTS) $(TOP)\mptest\mptest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1743   1813   
................................................................................
  1773   1843   	for %i in ($(SRC07)) do copy /Y %i tsrc
  1774   1844   	for %i in ($(SRC08)) do copy /Y %i tsrc
  1775   1845   	for %i in ($(SRC09)) do copy /Y %i tsrc
  1776   1846   	for %i in ($(SRC10)) do copy /Y %i tsrc
  1777   1847   	for %i in ($(SRC11)) do copy /Y %i tsrc
  1778   1848   	for %i in ($(SRC12)) do copy /Y %i tsrc
  1779   1849   	copy /Y fts5.c tsrc
         1850  +	copy /B tsrc\fts5.c +,,
  1780   1851   	copy /Y fts5.h tsrc
         1852  +	copy /B tsrc\fts5.h +,,
  1781   1853   	del /Q tsrc\sqlite.h.in tsrc\parse.y 2>NUL
  1782   1854   	$(TCLSH_CMD) $(TOP)\tool\vdbe-compress.tcl $(OPTS) < tsrc\vdbe.c > vdbe.new
  1783   1855   	move vdbe.new tsrc\vdbe.c
  1784   1856   	echo > .target_source
  1785   1857   
  1786         -sqlite3.c:	.target_source sqlite3ext.h $(MKSQLITE3C_TOOL)
         1858  +sqlite3.c:	.target_source sqlite3ext.h sqlite3session.h $(MKSQLITE3C_TOOL)
  1787   1859   	$(TCLSH_CMD) $(MKSQLITE3C_TOOL) $(MKSQLITE3C_ARGS)
  1788         -	copy $(TOP)\ext\session\sqlite3session.h .
  1789   1860   
  1790   1861   sqlite3-all.c:	sqlite3.c $(TOP)\tool\split-sqlite3c.tcl
  1791   1862   	$(TCLSH_CMD) $(TOP)\tool\split-sqlite3c.tcl
  1792   1863   # <</mark>>
  1793   1864   
  1794   1865   # Rule to build the amalgamation
  1795   1866   #
................................................................................
  1796   1867   sqlite3.lo:	$(SQLITE3C)
  1797   1868   	$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(SQLITE3C)
  1798   1869   
  1799   1870   # <<mark>>
  1800   1871   # Rules to build the LEMON compiler generator
  1801   1872   #
  1802   1873   lempar.c:	$(TOP)\tool\lempar.c
  1803         -	copy $(TOP)\tool\lempar.c .
         1874  +	copy /Y $(TOP)\tool\lempar.c .
         1875  +	copy /B lempar.c +,,
  1804   1876   
  1805   1877   lemon.exe:	$(TOP)\tool\lemon.c lempar.c
  1806   1878   	$(BCC) $(NO_WARN) -Daccess=_access \
  1807   1879   		-Fe$@ $(TOP)\tool\lemon.c /link $(LDFLAGS) $(NLTLINKOPTS) $(NLTLIBPATHS)
  1808   1880   
  1809   1881   # <<mark>>
  1810   1882   # Rules to build the source-id generator tool
................................................................................
  1825   1897   	$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c opcodes.c
  1826   1898   # <</mark>>
  1827   1899   
  1828   1900   # Rule to build the Win32 resources object file.
  1829   1901   #
  1830   1902   !IF $(USE_RC)!=0
  1831   1903   # <<block1>>
  1832         -$(LIBRESOBJS):	$(TOP)\src\sqlite3.rc $(SQLITE3H)
         1904  +$(LIBRESOBJS):	$(TOP)\src\sqlite3.rc $(SQLITE3H) $(TOP)\VERSION
  1833   1905   	echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h
  1834   1906   	for /F %%V in ('type "$(TOP)\VERSION"') do ( \
  1835   1907   		echo #define SQLITE_RESOURCE_VERSION %%V \
  1836   1908   			| $(TCLSH_CMD) $(TOP)\tool\replace.tcl exact . ^, >> sqlite3rc.h \
  1837   1909   	)
  1838   1910   	echo #endif >> sqlite3rc.h
  1839   1911   	$(LTRCOMPILE) -fo $(LIBRESOBJS) $(TOP)\src\sqlite3.rc
................................................................................
  2049   2121   
  2050   2122   vdbesort.lo:	$(TOP)\src\vdbesort.c $(HDR)
  2051   2123   	$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbesort.c
  2052   2124   
  2053   2125   vdbetrace.lo:	$(TOP)\src\vdbetrace.c $(HDR)
  2054   2126   	$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbetrace.c
  2055   2127   
         2128  +vdbevtab.lo:	$(TOP)\src\vdbevtab.c $(HDR)
         2129  +	$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vdbevtab.c
         2130  +
  2056   2131   vtab.lo:	$(TOP)\src\vtab.c $(HDR)
  2057   2132   	$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\vtab.c
  2058   2133   
  2059   2134   wal.lo:	$(TOP)\src\wal.c $(HDR)
  2060   2135   	$(LTCOMPILE) $(CORE_COMPILE_OPTS) -c $(TOP)\src\wal.c
  2061   2136   
  2062   2137   walker.lo:	$(TOP)\src\walker.c $(HDR)
................................................................................
  2091   2166   opcodes.h:	parse.h $(TOP)\src\vdbe.c $(TOP)\tool\mkopcodeh.tcl
  2092   2167   	type parse.h $(TOP)\src\vdbe.c | $(TCLSH_CMD) $(TOP)\tool\mkopcodeh.tcl > opcodes.h
  2093   2168   
  2094   2169   # Rules to build parse.c and parse.h - the outputs of lemon.
  2095   2170   #
  2096   2171   parse.h:	parse.c
  2097   2172   
  2098         -parse.c:	$(TOP)\src\parse.y lemon.exe $(TOP)\tool\addopcodes.tcl
         2173  +parse.c:	$(TOP)\src\parse.y lemon.exe
  2099   2174   	del /Q parse.y parse.h parse.h.temp 2>NUL
  2100         -	copy $(TOP)\src\parse.y .
  2101         -	.\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) parse.y
  2102         -	move parse.h parse.h.temp
  2103         -	$(TCLSH_CMD) $(TOP)\tool\addopcodes.tcl parse.h.temp > parse.h
         2175  +	copy /Y $(TOP)\src\parse.y .
         2176  +	copy /B parse.y +,,
         2177  +	.\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) -S parse.y
  2104   2178   
  2105   2179   $(SQLITE3H):	$(TOP)\src\sqlite.h.in $(TOP)\manifest mksourceid.exe $(TOP)\VERSION
  2106   2180   	$(TCLSH_CMD) $(TOP)\tool\mksqlite3h.tcl $(TOP:\=/) > $(SQLITE3H) $(MKSQLITE3H_ARGS)
  2107   2181   
  2108   2182   sqlite3ext.h:	.target_source
  2109   2183   !IF $(USE_STDCALL)!=0 || $(FOR_WIN10)!=0
  2110   2184   	type tsrc\sqlite3ext.h | $(TCLSH_CMD) $(TOP)\tool\replace.tcl regsub "\(\*\)" "(SQLITE_CALLBACK *)" \
  2111   2185   		| $(TCLSH_CMD) $(TOP)\tool\replace.tcl regsub "\(\*" "(SQLITE_APICALL *" > sqlite3ext.h
  2112   2186   	copy /Y sqlite3ext.h tsrc\sqlite3ext.h
  2113   2187   !ELSE
  2114   2188   	copy /Y tsrc\sqlite3ext.h sqlite3ext.h
         2189  +	copy /B sqlite3ext.h +,,
  2115   2190   !ENDIF
         2191  +
         2192  +sqlite3session.h:	$(TOP)\ext\session\sqlite3session.h
         2193  +	copy /Y $(TOP)\ext\session\sqlite3session.h .
         2194  +	copy /B sqlite3session.h +,,
  2116   2195   
  2117   2196   mkkeywordhash.exe:	$(TOP)\tool\mkkeywordhash.c
  2118   2197   	$(BCC) $(NO_WARN) -Fe$@ $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) \
  2119   2198   		$(TOP)\tool\mkkeywordhash.c /link $(LDFLAGS) $(NLTLINKOPTS) $(NLTLIBPATHS)
  2120   2199   
  2121   2200   keywordhash.h:	$(TOP)\tool\mkkeywordhash.c mkkeywordhash.exe
  2122   2201   	.\mkkeywordhash.exe > keywordhash.h
  2123   2202   
  2124   2203   # Source files that go into making shell.c
  2125   2204   SHELL_SRC = \
  2126   2205   	$(TOP)\src\shell.c.in \
  2127   2206   	$(TOP)\ext\misc\appendvfs.c \
  2128         -	$(TOP)\ext\misc\shathree.c \
         2207  +	$(TOP)\ext\misc\completion.c \
         2208  +        $(TOP)\ext\misc\decimal.c \
  2129   2209   	$(TOP)\ext\misc\fileio.c \
  2130         -	$(TOP)\ext\misc\completion.c \
         2210  +        $(TOP)\ext\misc\ieee754.c \
         2211  +	$(TOP)\ext\misc\shathree.c \
         2212  +	$(TOP)\ext\misc\uint.c \
  2131   2213   	$(TOP)\ext\expert\sqlite3expert.c \
  2132   2214   	$(TOP)\ext\expert\sqlite3expert.h \
         2215  +	$(TOP)\ext\misc\memtrace.c \
  2133   2216   	$(TOP)\src\test_windirent.c
  2134   2217   
  2135   2218   # If use of zlib is enabled, add the "zipfile.c" source file.
  2136   2219   #
  2137   2220   !IF $(USE_ZLIB)!=0
  2138   2221   SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\sqlar.c
  2139   2222   SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\zipfile.c
................................................................................
  2253   2336      $(TOP)\ext\lsm1\lsm_tree.c \
  2254   2337      $(TOP)\ext\lsm1\lsm_unix.c \
  2255   2338      $(TOP)\ext\lsm1\lsm_varint.c \
  2256   2339      $(TOP)\ext\lsm1\lsm_vtab.c \
  2257   2340      $(TOP)\ext\lsm1\lsm_win32.c
  2258   2341   
  2259   2342   fts5parse.c:	$(TOP)\ext\fts5\fts5parse.y lemon.exe
  2260         -	copy $(TOP)\ext\fts5\fts5parse.y .
         2343  +	copy /Y $(TOP)\ext\fts5\fts5parse.y .
         2344  +	copy /B fts5parse.y +,,
  2261   2345   	del /Q fts5parse.h 2>NUL
  2262         -	.\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) fts5parse.y
         2346  +	.\lemon.exe $(REQ_FEATURE_FLAGS) $(OPT_FEATURE_FLAGS) $(EXT_FEATURE_FLAGS) $(OPTS) -S fts5parse.y
  2263   2347   
  2264   2348   fts5parse.h:	fts5parse.c
  2265   2349   
  2266   2350   fts5.c:	$(FTS5_SRC)
  2267   2351   	$(TCLSH_CMD) $(TOP)\ext\fts5\tool\mkfts5c.tcl
  2268         -	copy $(TOP)\ext\fts5\fts5.h .
         2352  +	copy /Y $(TOP)\ext\fts5\fts5.h .
         2353  +	copy /B fts5.h +,,
  2269   2354   
  2270   2355   lsm1.c:	$(LSM1_SRC)
  2271   2356   	$(TCLSH_CMD) $(TOP)\ext\lsm1\tool\mklsm1c.tcl
  2272         -	copy $(TOP)\ext\lsm1\lsm.h .
         2357  +	copy /Y $(TOP)\ext\lsm1\lsm.h .
         2358  +	copy /B lsm.h +,,
  2273   2359   
  2274   2360   fts5.lo:	fts5.c $(HDR) $(EXTHDR)
  2275   2361   	$(LTCOMPILE) $(CORE_COMPILE_OPTS) $(NO_WARN) -DSQLITE_CORE -c fts5.c
  2276   2362   
  2277   2363   fts5_ext.lo:	fts5.c $(HDR) $(EXTHDR)
  2278   2364   	$(LTCOMPILE) $(NO_WARN) -c fts5.c
  2279   2365   
................................................................................
  2293   2379   TESTFIXTURE_FLAGS = -DTCLSH_INIT_PROC=sqlite3TestInit -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1
  2294   2380   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERVER=1 -DSQLITE_PRIVATE=""
  2295   2381   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CORE $(NO_WARN)
  2296   2382   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
  2297   2383   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_DEFAULT_PAGE_SIZE=1024
  2298   2384   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
  2299   2385   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
         2386  +TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
  2300   2387   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
  2301   2388   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
  2302   2389   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS)
  2303   2390   
  2304   2391   TESTFIXTURE_SRC0 = $(TESTEXT) $(TESTSRC2)
  2305   2392   TESTFIXTURE_SRC1 = $(TESTEXT) $(SQLITE3C)
  2306   2393   !IF $(USE_AMALGAMATION)==0
................................................................................
  2358   2445   queryplantest:	testfixture.exe shell
  2359   2446   	@set PATH=$(LIBTCLPATH);$(PATH)
  2360   2447   	.\testfixture.exe $(TOP)\test\permutations.test queryplanner $(TESTOPTS)
  2361   2448   
  2362   2449   fuzztest:	fuzzcheck.exe
  2363   2450   	.\fuzzcheck.exe $(FUZZDATA)
  2364   2451   
  2365         -fastfuzztest:	fuzzcheck.exe
  2366         -	.\fuzzcheck.exe --limit-mem 100M $(FUZZDATA)
  2367         -
  2368   2452   # Minimal testing that runs in less than 3 minutes (on a fast machine)
  2369   2453   #
  2370   2454   quicktest:	testfixture.exe sourcetest
  2371   2455   	@set PATH=$(LIBTCLPATH);$(PATH)
  2372   2456   	.\testfixture.exe $(TOP)\test\extraquick.test $(TESTOPTS)
  2373   2457   
  2374   2458   # This is the common case.  Run many tests that do not take too long,
  2375   2459   # including fuzzcheck, sqlite3_analyzer, and sqldiff tests.
  2376   2460   #
  2377         -test:	$(TESTPROGS) sourcetest fastfuzztest
         2461  +test:	$(TESTPROGS) sourcetest fuzztest
  2378   2462   	@set PATH=$(LIBTCLPATH);$(PATH)
  2379   2463   	.\testfixture.exe $(TOP)\test\veryquick.test $(TESTOPTS)
  2380   2464   
  2381   2465   smoketest:	$(TESTPROGS)
  2382   2466   	@set PATH=$(LIBTCLPATH);$(PATH)
  2383   2467   	.\testfixture.exe $(TOP)\test\main.test $(TESTOPTS)
  2384   2468   
         2469  +shelltest: $(TESTPROGS)
         2470  +	.\testfixture.exe $(TOP)\test\permutations.test shell
         2471  +
  2385   2472   sqlite3_analyzer.c:	$(SQLITE3C) $(SQLITE3H) $(TOP)\src\tclsqlite.c $(TOP)\tool\spaceanal.tcl $(TOP)\tool\mkccode.tcl $(TOP)\tool\sqlite3_analyzer.c.in $(SQLITE_TCL_DEP)
  2386   2473   	$(TCLSH_CMD) $(TOP)\tool\mkccode.tcl $(TOP)\tool\sqlite3_analyzer.c.in > $@
  2387   2474   
  2388   2475   sqlite3_analyzer.exe:	sqlite3_analyzer.c $(LIBRESOBJS)
  2389   2476   	$(LTLINK) $(NO_WARN) -DBUILD_sqlite -I$(TCLINCDIR) sqlite3_analyzer.c \
  2390   2477   		/link $(LDFLAGS) $(LTLINKOPTS) $(TCLLIBPATHS) $(LTLIBPATHS) $(LIBRESOBJS) $(TCLLIBS) $(LTLIBS) $(TLIBS)
  2391   2478   
................................................................................
  2501   2588   # <</mark>>
  2502   2589   
  2503   2590   clean:
  2504   2591   	del /Q *.exp *.lo *.ilk *.lib *.obj *.ncb *.pdb *.sdf *.suo 2>NUL
  2505   2592   	del /Q *.bsc *.def *.cod *.da *.bb *.bbg *.vc gmon.out 2>NUL
  2506   2593   	del /Q $(SQLITE3EXE) $(SQLITE3DLL) Replace.exe 2>NUL
  2507   2594   # <<mark>>
         2595  +	del /Q $(SQLITE3TCLDLL) pkgIndex.tcl 2>NUL
  2508   2596   	del /Q opcodes.c opcodes.h 2>NUL
  2509   2597   	del /Q lemon.* lempar.c parse.* 2>NUL
  2510   2598   	del /Q mksourceid.* mkkeywordhash.* keywordhash.h 2>NUL
  2511   2599   	del /Q notasharedlib.* 2>NUL
  2512   2600   	-rmdir /Q/S .deps 2>NUL
  2513   2601   	-rmdir /Q/S .libs 2>NUL
  2514   2602   	-rmdir /Q/S tsrc 2>NUL
  2515   2603   	del /Q .target_source 2>NUL
  2516   2604   	del /Q tclsqlite3.exe $(SQLITETCLH) $(SQLITETCLDECLSH) 2>NUL
  2517   2605   	del /Q lsm.dll lsmtest.exe 2>NUL
         2606  +	del /Q atrc.exe changesetfuzz.exe dbtotxt.exe index_usage.exe 2>NUL
  2518   2607   	del /Q testloadext.dll 2>NUL
  2519   2608   	del /Q testfixture.exe test.db 2>NUL
  2520   2609   	del /Q LogEst.exe fts3view.exe rollback-test.exe showdb.exe dbdump.exe 2>NUL
  2521   2610   	del /Q changeset.exe 2>NUL
  2522   2611   	del /Q showjournal.exe showstat4.exe showwal.exe speedtest1.exe 2>NUL
  2523   2612   	del /Q mptester.exe wordcount.exe rbu.exe srcck1.exe 2>NUL
  2524   2613   	del /Q sqlite3.c sqlite3-*.c sqlite3.h 2>NUL

Changes to README.md.

     1      1   <h1 align="center">SQLite Source Repository</h1>
     2      2   
     3      3   This repository contains the complete source code for the 
     4      4   [SQLite database engine](https://sqlite.org/).  Some test scripts 
     5      5   are also included.  However, many other test scripts
     6      6   and most of the documentation are managed separately.
     7      7   
     8         -SQLite [does not use Git](https://sqlite.org/whynotgit.html).
     9         -If you are reading this on GitHub, then you are looking at an
    10         -unofficial mirror. See <https://sqlite.org/src> for the official
    11         -repository.
    12         -
    13         -## Obtaining The Code
            8  +## Version Control
    14      9   
    15     10   SQLite sources are managed using the
    16     11   [Fossil](https://www.fossil-scm.org/), a distributed version control system
    17         -that was specifically designed to support SQLite development.
           12  +that was specifically designed and written to support SQLite development.
           13  +The [Fossil repository](https://sqlite.org/src/timeline) contains the urtext.
           14  +
           15  +If you are reading this on GitHub or some other Git repository or service,
           16  +then you are looking at a mirror.  The names of check-ins and
           17  +other artifacts in a Git mirror are different from the official
           18  +names for those objects.  The offical names for check-ins are
           19  +found in a footer on the check-in comment for authorized mirrors.
           20  +The official check-in name can also be seen in the `manifest.uuid` file
           21  +in the root of the tree.  Always use the official name, not  the
           22  +Git-name, when communicating about an SQLite check-in.
           23  +
           24  +If you pulled your SQLite source code from a secondary source and want to
           25  +verify its integrity, there are hints on how to do that in the
           26  +[Verifying Code Authenticity](#vauth) section below.
           27  +
           28  +## Obtaining The Code
           29  +
    18     30   If you do not want to use Fossil, you can download tarballs or ZIP
    19     31   archives or [SQLite archives](https://sqlite.org/cli.html#sqlar) as follows:
    20     32   
    21     33     *  Lastest trunk check-in as
    22     34        [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz),
    23     35        [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip), or
    24     36        [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar).
................................................................................
    25     37   
    26     38     *  Latest release as
    27     39        [Tarball](https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release),
    28     40        [ZIP-archive](https://www.sqlite.org/src/zip/sqlite.zip?r=release), or
    29     41        [SQLite-archive](https://www.sqlite.org/src/sqlar/sqlite.sqlar?r=release).
    30     42   
    31     43     *  For other check-ins, substitute an appropriate branch name or
    32         -     tag or hash prefix for "release" in the URLs of the previous
           44  +     tag or hash prefix in place of "release" in the URLs of the previous
    33     45        bullet.  Or browse the [timeline](https://www.sqlite.org/src/timeline)
    34     46        to locate the check-in desired, click on its information page link,
    35     47        then click on the "Tarball" or "ZIP Archive" links on the information
    36     48        page.
    37     49   
    38     50   If you do want to use Fossil to check out the source tree, 
    39     51   first install Fossil version 2.0 or later.
................................................................................
   159    171   used to generate that documentation are in a separate source repository.
   160    172   
   161    173   The SQL language parser is **parse.c** which is generate from a grammar in
   162    174   the src/parse.y file.  The conversion of "parse.y" into "parse.c" is done
   163    175   by the [lemon](./doc/lemon.html) LALR(1) parser generator.  The source code
   164    176   for lemon is at tool/lemon.c.  Lemon uses the tool/lempar.c file as a
   165    177   template for generating its parser.
   166         -
   167    178   Lemon also generates the **parse.h** header file, at the same time it
   168         -generates parse.c. But the parse.h header file is
   169         -modified further (to add additional symbols) using the ./addopcodes.tcl
   170         -Tcl script.
          179  +generates parse.c.
   171    180   
   172    181   The **opcodes.h** header file contains macros that define the numbers
   173    182   corresponding to opcodes in the "VDBE" virtual machine.  The opcodes.h
   174    183   file is generated by the scanning the src/vdbe.c source file.  The
   175    184   Tcl script at ./mkopcodeh.tcl does this scan and generates opcodes.h.
   176    185   A second Tcl script, ./mkopcodec.tcl, then scans opcodes.h to generate
   177    186   the **opcodes.c** source file, which contains a reverse mapping from
................................................................................
   290    299   
   291    300     *  **ext/misc/json1.c** - This file implements the various JSON functions
   292    301        that are build into SQLite.
   293    302   
   294    303   There are many other source files.  Each has a succinct header comment that
   295    304   describes its purpose and role within the larger system.
   296    305   
          306  +<a name="vauth"></a>
          307  +## Verifying Code Authenticity
          308  +
          309  +The `manifest` file at the root directory of the source tree
          310  +contains either a SHA3-256 hash (for newer files) or a SHA1 hash (for 
          311  +older files) for every source file in the repository.
          312  +The SHA3-256 hash of the `manifest`
          313  +file itself is the official name of the version of the source tree that you
          314  +have. The `manifest.uuid` file should contain the SHA3-256 hash of the
          315  +`manifest` file. If all of the above hash comparisons are correct, then
          316  +you can be confident that your source tree is authentic and unadulterated.
          317  +
          318  +The format of the `manifest` file should be mostly self-explanatory, but
          319  +if you want details, they are available
          320  +[here](https://fossil-scm.org/fossil/doc/trunk/www/fileformat.wiki#manifest).
   297    321   
   298    322   ## Contacts
   299    323   
   300         -The main SQLite webpage is [http://www.sqlite.org/](http://www.sqlite.org/)
          324  +The main SQLite website is [http://www.sqlite.org/](http://www.sqlite.org/)
   301    325   with geographically distributed backups at
   302    326   [http://www2.sqlite.org/](http://www2.sqlite.org) and
   303    327   [http://www3.sqlite.org/](http://www3.sqlite.org).

Changes to VERSION.

     1         -3.27.0
            1  +3.33.0

Changes to autoconf/Makefile.am.

     9      9   EXTRA_sqlite3_SOURCES = sqlite3.c
    10     10   sqlite3_LDADD = @EXTRA_SHELL_OBJ@ @READLINE_LIBS@
    11     11   sqlite3_DEPENDENCIES = @EXTRA_SHELL_OBJ@
    12     12   sqlite3_CFLAGS = $(AM_CFLAGS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBSTAT_VTAB $(SHELL_CFLAGS)
    13     13   
    14     14   include_HEADERS = sqlite3.h sqlite3ext.h
    15     15   
    16         -EXTRA_DIST = sqlite3.1 tea Makefile.msc sqlite3.rc README.txt Replace.cs Makefile.fallback
           16  +EXTRA_DIST = sqlite3.1 tea Makefile.msc sqlite3.rc sqlite3rc.h README.txt Replace.cs Makefile.fallback
    17     17   pkgconfigdir = ${libdir}/pkgconfig
    18     18   pkgconfig_DATA = sqlite3.pc
    19     19   
    20     20   man_MANS = sqlite3.1

Changes to autoconf/Makefile.msc.

    69     69   # If necessary, create a list of harmless compiler warnings to disable when
    70     70   # compiling the various tools.  For the SQLite source code itself, warnings,
    71     71   # if any, will be disabled from within it.
    72     72   #
    73     73   !IFNDEF NO_WARN
    74     74   !IF $(USE_FULLWARN)!=0
    75     75   NO_WARN = -wd4054 -wd4055 -wd4100 -wd4127 -wd4130 -wd4152 -wd4189 -wd4206
    76         -NO_WARN = $(NO_WARN) -wd4210 -wd4232 -wd4305 -wd4306 -wd4702 -wd4706
           76  +NO_WARN = $(NO_WARN) -wd4210 -wd4232 -wd4244 -wd4305 -wd4306 -wd4702 -wd4706
    77     77   !ENDIF
    78     78   !ENDIF
    79     79   
    80     80   # Set this non-0 to use the library paths and other options necessary for
    81     81   # Windows Phone 8.1.
    82     82   #
    83     83   !IFNDEF USE_WP81_OPTS
................................................................................
   191    191   # 4 == SQLITE_WIN32_MALLOC_VALIDATE: Validate the Win32 native heap per call.
   192    192   # 5 == SQLITE_DEBUG_OS_TRACE: Enables output from the OSTRACE() macros.
   193    193   # 6 == SQLITE_ENABLE_IOTRACE: Enables output from the IOTRACE() macros.
   194    194   #
   195    195   !IFNDEF DEBUG
   196    196   DEBUG = 0
   197    197   !ENDIF
          198  +
   198    199   
   199    200   # Enable use of available compiler optimizations?  Normally, this should be
   200    201   # non-zero.  Setting this to zero, thus disabling all compiler optimizations,
   201    202   # can be useful for testing.
   202    203   #
   203    204   !IFNDEF OPTIMIZATIONS
   204    205   OPTIMIZATIONS = 2
................................................................................
   205    206   !ENDIF
   206    207   
   207    208   # Set this to non-0 to enable support for the session extension.
   208    209   #
   209    210   !IFNDEF SESSION
   210    211   SESSION = 0
   211    212   !ENDIF
          213  +
          214  +# Set this to non-0 to enable support for the rbu extension.
          215  +#
          216  +!IFNDEF RBU
          217  +RBU = 0
          218  +!ENDIF
   212    219   
   213    220   # Set the source code file to be used by executables and libraries when
   214    221   # they need the amalgamation.
   215    222   #
   216    223   !IFNDEF SQLITE3C
   217    224   !IF $(SPLIT_AMALGAMATION)!=0
   218    225   SQLITE3C = sqlite3-all.c
................................................................................
   278    285   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3=1
   279    286   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1
   280    287   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_GEOPOLY=1
   281    288   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
   282    289   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
   283    290   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
   284    291   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
   285         -OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_INTROSPECTION_PRAGMAS=1
          292  +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_BYTECODE_VTAB=1
   286    293   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
   287    294   !ENDIF
   288    295   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
   289    296   !ENDIF
   290    297   
   291    298   # Should the session extension be enabled?  If so, add compilation options
   292    299   # to enable it.
   293    300   #
   294    301   !IF $(SESSION)!=0
   295    302   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_SESSION=1
   296    303   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_PREUPDATE_HOOK=1
   297    304   !ENDIF
          305  +
          306  +# Should the rbu extension be enabled?  If so, add compilation options
          307  +# to enable it.
          308  +#
          309  +!IF $(RBU)!=0
          310  +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RBU=1
          311  +!ENDIF
   298    312   
   299    313   # These are the "extended" SQLite compilation options used when compiling for
   300    314   # the Windows 10 platform.
   301    315   #
   302    316   !IFNDEF EXT_FEATURE_FLAGS
   303    317   !IF $(FOR_WIN10)!=0
   304    318   EXT_FEATURE_FLAGS = $(EXT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4=1
................................................................................
   429    443   
   430    444   UCRTLIBPATH = $(UCRTLIBPATH:\\=\)
   431    445   
   432    446   # C compiler and options for use in building executables that
   433    447   # will run on the platform that is doing the build.
   434    448   #
   435    449   !IF $(USE_FULLWARN)!=0
   436         -BCC = $(NCC) -nologo -W4 $(CCOPTS) $(BCCOPTS)
          450  +BCC = $(NCC) -nologo -W4 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
   437    451   !ELSE
   438         -BCC = $(NCC) -nologo -W3 $(CCOPTS) $(BCCOPTS)
          452  +BCC = $(NCC) -nologo -W3 -Fd$*.pdb $(CCOPTS) $(BCCOPTS)
   439    453   !ENDIF
   440    454   
   441    455   # Check if assembly code listings should be generated for the source
   442    456   # code files to be compiled.
   443    457   #
   444    458   !IF $(USE_LISTINGS)!=0
   445    459   BCC = $(BCC) -FAcs
................................................................................
   804    818   BCC = $(BCC) -Zi
   805    819   !ENDIF
   806    820   
   807    821   
   808    822   # Command line prefixes for compiling code, compiling resources,
   809    823   # linking, etc.
   810    824   #
   811         -LTCOMPILE = $(TCC) -Fo$@
          825  +LTCOMPILE = $(TCC) -Fo$@ -Fd$*.pdb
   812    826   LTRCOMPILE = $(RCC) -r
   813    827   LTLIB = lib.exe
   814    828   LTLINK = $(TCC) -Fe$@
   815    829   
   816    830   # If requested, link to the RPCRT4 library.
   817    831   #
   818    832   !IF $(USE_RPCRT4_LIB)!=0
................................................................................
   822    836   # If a platform was set, force the linker to target that.
   823    837   # Note that the vcvars*.bat family of batch files typically
   824    838   # set this for you.  Otherwise, the linker will attempt
   825    839   # to deduce the binary type based on the object files.
   826    840   !IFDEF PLATFORM
   827    841   LTLINKOPTS = /NOLOGO /MACHINE:$(PLATFORM)
   828    842   LTLIBOPTS = /NOLOGO /MACHINE:$(PLATFORM)
          843  +!ELSEIF "$(VISUALSTUDIOVERSION)"=="12.0" || \
          844  +        "$(VISUALSTUDIOVERSION)"=="14.0" || \
          845  +        "$(VISUALSTUDIOVERSION)"=="15.0"
          846  +LTLINKOPTS = /NOLOGO /MACHINE:x86
          847  +LTLIBOPTS = /NOLOGO /MACHINE:x86
   829    848   !ELSE
   830    849   LTLINKOPTS = /NOLOGO
   831    850   LTLIBOPTS = /NOLOGO
   832    851   !ENDIF
   833    852   
   834    853   # When compiling for use in the WinRT environment, the following
   835    854   # linker option must be used to mark the executable as runnable
................................................................................
   969    988   
   970    989   Replace.exe:
   971    990   	$(CSC) /target:exe $(TOP)\Replace.cs
   972    991   
   973    992   sqlite3.def:	Replace.exe $(LIBOBJ)
   974    993   	echo EXPORTS > sqlite3.def
   975    994   	dumpbin /all $(LIBOBJ) \
   976         -		| .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \
          995  +		| .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser|rbu)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \
   977    996   		| sort >> sqlite3.def
   978    997   
   979    998   $(SQLITE3EXE):	shell.c $(SHELL_CORE_DEP) $(LIBRESOBJS) $(SHELL_CORE_SRC) $(SQLITE3H)
   980    999   	$(LTLINK) $(SHELL_COMPILE_OPTS) $(READLINE_FLAGS) shell.c $(SHELL_CORE_SRC) \
   981   1000   		/link $(SQLITE3EXEPDB) $(LDFLAGS) $(LTLINKOPTS) $(SHELL_LINK_OPTS) $(LTLIBPATHS) $(LIBRESOBJS) $(LIBREADLINE) $(LTLIBS) $(TLIBS)
   982   1001   
   983   1002   

Changes to autoconf/configure.ac.

   157    157   #-----------------------------------------------------------------------
   158    158   #   --enable-rtree
   159    159   #
   160    160   AC_ARG_ENABLE(rtree, [AS_HELP_STRING(
   161    161     [--enable-rtree], [include rtree support [default=yes]])], 
   162    162     [], [enable_rtree=yes])
   163    163   if test x"$enable_rtree" = "xyes"; then
   164         -  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_RTREE"
          164  +  BUILD_CFLAGS="$BUILD_CFLAGS -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_GEOPOLY"
   165    165   fi
   166    166   #-----------------------------------------------------------------------
   167    167   
   168    168   #-----------------------------------------------------------------------
   169    169   #   --enable-session
   170    170   #
   171    171   AC_ARG_ENABLE(session, [AS_HELP_STRING(

Changes to autoconf/tea/configure.ac.

    15     15   # Set your package name and version numbers here.
    16     16   #
    17     17   # This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION
    18     18   # set as provided.  These will also be added as -D defs in your Makefile
    19     19   # so you can encode the package version directly into the source files.
    20     20   #-----------------------------------------------------------------------
    21     21   
    22         -AC_INIT([sqlite], [3.7.4])
           22  +AC_INIT([sqlite], [3.32.0])
    23     23   
    24     24   #--------------------------------------------------------------------
    25     25   # Call TEA_INIT as the first TEA_ macro to set up initial vars.
    26     26   # This will define a ${TEA_PLATFORM} variable == "unix" or "windows"
    27     27   # as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE.
    28     28   #--------------------------------------------------------------------
    29     29   

Changes to autoconf/tea/win/makefile.vc.

   149    149   # would install it into $(INSTALLDIR)\lib\sample04
   150    150   #
   151    151   # You need to specify the object files that need to be linked into your
   152    152   # binary here.
   153    153   #
   154    154   #-------------------------------------------------------------------------
   155    155   
   156         -PROJECT = sqlite3
          156  +PROJECT = tclsqlite3
   157    157   !include "rules.vc"
   158    158   
   159    159   # nmakehelp -V <file> <tag> will search the file for tag, skips until a
   160    160   #	number and returns all character until a character not in [0-9.ab]
   161    161   #	is read.
   162    162   
   163    163   !if [echo REM = This file is generated from Makefile.vc > versions.vc]
   164    164   !endif
   165         -# get project version from row "AC_INIT([sqlite], [3.7.14])"
          165  +# get project version from row "AC_INIT([sqlite], [3.x.y])"
   166    166   !if [echo DOTVERSION = \>> versions.vc] \
   167         -   && [nmakehlp -V ..\configure.in AC_INIT >> versions.vc]
          167  +   && [nmakehlp -V ..\configure.ac AC_INIT >> versions.vc]
   168    168   !endif
   169    169   !include "versions.vc"
   170    170   
   171    171   VERSION         = $(DOTVERSION:.=)
   172    172   STUBPREFIX      = $(PROJECT)stub
   173    173   
   174         -DLLOBJS = \
   175         -	$(TMP_DIR)\tclsqlite3.obj
   176         -
   177    174   #-------------------------------------------------------------------------
   178    175   # Target names and paths ( shouldn't need changing )
   179    176   #-------------------------------------------------------------------------
   180    177   
   181    178   BINROOT		= .
   182    179   ROOT            = ..
   183    180   
   184    181   PRJIMPLIB	= $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib
   185         -PRJLIBNAME	= $(PROJECT)$(VERSION)$(SUFX).$(EXT)
          182  +PRJLIBNAME	= $(PROJECT).$(EXT)
   186    183   PRJLIB		= $(OUT_DIR)\$(PRJLIBNAME)
   187    184   
   188    185   PRJSTUBLIBNAME	= $(STUBPREFIX)$(VERSION).lib
   189    186   PRJSTUBLIB	= $(OUT_DIR)\$(PRJSTUBLIBNAME)
   190    187   
   191    188   ### Make sure we use backslash only.
   192    189   PRJ_INSTALL_DIR         = $(_INSTALLDIR)\$(PROJECT)$(DOTVERSION)
................................................................................
   199    196   ### The following paths CANNOT have spaces in them.
   200    197   GENERICDIR	= $(ROOT)\generic
   201    198   WINDIR		= $(ROOT)\win
   202    199   LIBDIR          = $(ROOT)\library
   203    200   DOCDIR		= $(ROOT)\doc
   204    201   TOOLSDIR	= $(ROOT)\tools
   205    202   COMPATDIR	= $(ROOT)\compat
          203  +
          204  +### Figure out where the primary source code file(s) is/are.
          205  +!if exist("$(ROOT)\..\..\sqlite3.c") && exist("$(ROOT)\..\..\src\tclsqlite.c")
          206  +SQL_INCLUDES = -I"$(ROOT)\..\.."
          207  +SQLITE_SRCDIR = $(ROOT)\..\..
          208  +TCLSQLITE_SRCDIR = $(ROOT)\..\..\src
          209  +DLLOBJS = $(TMP_DIR)\sqlite3.obj $(TMP_DIR)\tclsqlite.obj
          210  +!else
          211  +TCLSQLITE_SRCDIR = $(ROOT)\generic
          212  +DLLOBJS = $(TMP_DIR)\tclsqlite3.obj
          213  +!endif
   206    214   
   207    215   #---------------------------------------------------------------------
   208    216   # Compile flags
   209    217   #---------------------------------------------------------------------
   210    218   
   211    219   !if !$(DEBUG)
   212    220   !if $(OPTIMIZING)
................................................................................
   219    227   ### Warnings are too many, can't support warnings into errors.
   220    228   cdebug	= -Z7 -Od -GZ
   221    229   !else
   222    230   cdebug	= -Z7 -WX -Od -GZ
   223    231   !endif
   224    232   
   225    233   ### Declarations common to all compiler options
   226         -cflags = -nologo -c -W3 -YX -Fp$(TMP_DIR)^\
          234  +cflags = -nologo -c -W3 -D_CRT_SECURE_NO_WARNINGS -YX -Fp$(TMP_DIR)^\
   227    235   
   228    236   !if $(MSVCRT)
   229    237   !if $(DEBUG)
   230    238   crt = -MDd
   231    239   !else
   232    240   crt = -MD
   233    241   !endif
................................................................................
   235    243   !if $(DEBUG)
   236    244   crt = -MTd
   237    245   !else
   238    246   crt = -MT
   239    247   !endif
   240    248   !endif
   241    249   
   242         -INCLUDES	= $(TCL_INCLUDES) -I"$(WINDIR)" -I"$(GENERICDIR)" \
   243         -                  -I"$(ROOT)\.."
          250  +INCLUDES	= $(SQL_INCLUDES) $(TCL_INCLUDES) -I"$(WINDIR)" \
          251  +                  -I"$(GENERICDIR)" -I"$(ROOT)\.."
   244    252   BASE_CLFAGS	= $(cflags) $(cdebug) $(crt) $(INCLUDES) \
   245    253                     -DSQLITE_3_SUFFIX_ONLY=1 -DSQLITE_ENABLE_RTREE=1 \
   246    254                     -DSQLITE_ENABLE_FTS3=1 -DSQLITE_OMIT_DEPRECATED=1
   247    255   CON_CFLAGS	= $(cflags) $(cdebug) $(crt) -DCONSOLE -DSQLITE_ENABLE_FTS3=1
   248    256   TCL_CFLAGS	= -DBUILD_sqlite -DUSE_TCL_STUBS \
   249    257                     -DPACKAGE_VERSION="\"$(DOTVERSION)\"" $(BASE_CLFAGS) \
   250    258                     $(OPTDEFINES)
................................................................................
   337    345   $(PRJSTUBLIB): $(PRJSTUBOBJS)
   338    346   	$(lib32) -nologo -out:$@ $(PRJSTUBOBJS)
   339    347   
   340    348   #---------------------------------------------------------------------
   341    349   # Implicit rules
   342    350   #---------------------------------------------------------------------
   343    351   
   344         -{$(WINDIR)}.c{$(TMP_DIR)}.obj::
   345         -    $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<<
   346         -$<
   347         -<<
          352  +$(TMP_DIR)\sqlite3.obj:		$(SQLITE_SRCDIR)\sqlite3.c
          353  +	$(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ \
          354  +		-c $(SQLITE_SRCDIR)\sqlite3.c
   348    355   
   349         -{$(GENERICDIR)}.c{$(TMP_DIR)}.obj::
   350         -    $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<<
   351         -$<
   352         -<<
          356  +$(TMP_DIR)\tclsqlite.obj:	$(TCLSQLITE_SRCDIR)\tclsqlite.c
          357  +	$(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ \
          358  +		-c $(TCLSQLITE_SRCDIR)\tclsqlite.c
   353    359   
   354         -{$(COMPATDIR)}.c{$(TMP_DIR)}.obj::
   355         -    $(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ @<<
   356         -$<
   357         -<<
          360  +$(TMP_DIR)\tclsqlite3.obj:	$(TCLSQLITE_SRCDIR)\tclsqlite3.c
          361  +	$(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ \
          362  +		-c $(TCLSQLITE_SRCDIR)\tclsqlite3.c
   358    363   
   359    364   {$(WINDIR)}.rc{$(TMP_DIR)}.res:
   360    365   	$(rc32) -fo $@ -r -i "$(GENERICDIR)" -D__WIN32__ \
   361    366   !if $(DEBUG)
   362    367   	-d DEBUG \
   363    368   !endif
   364    369   !if $(TCL_THREADS)

Changes to config.guess.

     1      1   #! /bin/sh
     2      2   # Attempt to guess a canonical system name.
     3         -#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
     4         -#   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
     5         -#   Inc.
            3  +#   Copyright 1992-2019 Free Software Foundation, Inc.
     6      4   
     7         -timestamp='2007-07-22'
            5  +timestamp='2019-05-28'
     8      6   
     9      7   # This file is free software; you can redistribute it and/or modify it
    10      8   # under the terms of the GNU General Public License as published by
    11         -# the Free Software Foundation; either version 2 of the License, or
            9  +# the Free Software Foundation; either version 3 of the License, or
    12     10   # (at your option) any later version.
    13     11   #
    14     12   # This program is distributed in the hope that it will be useful, but
    15     13   # WITHOUT ANY WARRANTY; without even the implied warranty of
    16     14   # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    17     15   # General Public License for more details.
    18     16   #
    19     17   # You should have received a copy of the GNU General Public License
    20         -# along with this program; if not, write to the Free Software
    21         -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    22         -# 02110-1301, USA.
           18  +# along with this program; if not, see <https://www.gnu.org/licenses/>.
    23     19   #
    24     20   # As a special exception to the GNU General Public License, if you
    25     21   # distribute this file as part of a program that contains a
    26     22   # configuration script generated by Autoconf, you may include it under
    27         -# the same distribution terms that you use for the rest of that program.
    28         -
    29         -
    30         -# Originally written by Per Bothner <per@bothner.com>.
    31         -# Please send patches to <config-patches@gnu.org>.  Submit a context
    32         -# diff and a properly formatted ChangeLog entry.
           23  +# the same distribution terms that you use for the rest of that
           24  +# program.  This Exception is an additional permission under section 7
           25  +# of the GNU General Public License, version 3 ("GPLv3").
           26  +#
           27  +# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.
           28  +#
           29  +# You can get the latest version of this script from:
           30  +# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
    33     31   #
    34         -# This script attempts to guess a canonical system name similar to
    35         -# config.sub.  If it succeeds, it prints the system name on stdout, and
    36         -# exits with 0.  Otherwise, it exits with 1.
    37         -#
    38         -# The plan is that this can be called by configure scripts if you
    39         -# don't specify an explicit build system type.
           32  +# Please send patches to <config-patches@gnu.org>.
           33  +
    40     34   
    41     35   me=`echo "$0" | sed -e 's,.*/,,'`
    42     36   
    43     37   usage="\
    44     38   Usage: $0 [OPTION]
    45     39   
    46     40   Output the configuration name of the system \`$me' is run on.
    47     41   
    48         -Operation modes:
           42  +Options:
    49     43     -h, --help         print this help, then exit
    50     44     -t, --time-stamp   print date of last modification, then exit
    51     45     -v, --version      print version number, then exit
    52     46   
    53     47   Report bugs and patches to <config-patches@gnu.org>."
    54     48   
    55     49   version="\
    56     50   GNU config.guess ($timestamp)
    57     51   
    58     52   Originally written by Per Bothner.
    59         -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    60         -Free Software Foundation, Inc.
           53  +Copyright 1992-2019 Free Software Foundation, Inc.
    61     54   
    62     55   This is free software; see the source for copying conditions.  There is NO
    63     56   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
    64     57   
    65     58   help="
    66     59   Try \`$me --help' for more information."
    67     60   
................................................................................
    87     80   done
    88     81   
    89     82   if test $# != 0; then
    90     83     echo "$me: too many arguments$help" >&2
    91     84     exit 1
    92     85   fi
    93     86   
    94         -trap 'exit 1' 1 2 15
    95         -
    96     87   # CC_FOR_BUILD -- compiler used by this script. Note that the use of a
    97     88   # compiler to aid in system detection is discouraged as it requires
    98     89   # temporary files to be created and, as you can see below, it is a
    99     90   # headache to deal with in a portable fashion.
   100     91   
   101     92   # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
   102     93   # use `HOST_CC' if defined, but it is deprecated.
   103     94   
   104     95   # Portable tmp directory creation inspired by the Autoconf team.
   105     96   
   106         -set_cc_for_build='
   107         -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
   108         -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
   109         -: ${TMPDIR=/tmp} ;
   110         - { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
   111         - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
   112         - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
   113         - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
   114         -dummy=$tmp/dummy ;
   115         -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
   116         -case $CC_FOR_BUILD,$HOST_CC,$CC in
   117         - ,,)    echo "int x;" > $dummy.c ;
   118         -	for c in cc gcc c89 c99 ; do
   119         -	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
   120         -	     CC_FOR_BUILD="$c"; break ;
   121         -	  fi ;
   122         -	done ;
   123         -	if test x"$CC_FOR_BUILD" = x ; then
   124         -	  CC_FOR_BUILD=no_compiler_found ;
   125         -	fi
   126         -	;;
   127         - ,,*)   CC_FOR_BUILD=$CC ;;
   128         - ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
   129         -esac ; set_cc_for_build= ;'
           97  +tmp=
           98  +# shellcheck disable=SC2172
           99  +trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15
          100  +
          101  +set_cc_for_build() {
          102  +    : "${TMPDIR=/tmp}"
          103  +    # shellcheck disable=SC2039
          104  +    { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
          105  +	{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } ||
          106  +	{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } ||
          107  +	{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; }
          108  +    dummy=$tmp/dummy
          109  +    case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in
          110  +	,,)    echo "int x;" > "$dummy.c"
          111  +	       for driver in cc gcc c89 c99 ; do
          112  +		   if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then
          113  +		       CC_FOR_BUILD="$driver"
          114  +		       break
          115  +		   fi
          116  +	       done
          117  +	       if test x"$CC_FOR_BUILD" = x ; then
          118  +		   CC_FOR_BUILD=no_compiler_found
          119  +	       fi
          120  +	       ;;
          121  +	,,*)   CC_FOR_BUILD=$CC ;;
          122  +	,*,*)  CC_FOR_BUILD=$HOST_CC ;;
          123  +    esac
          124  +}
   130    125   
   131    126   # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
   132    127   # (ghazi@noc.rutgers.edu 1994-08-24)
   133         -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
          128  +if test -f /.attbin/uname ; then
   134    129   	PATH=$PATH:/.attbin ; export PATH
   135    130   fi
   136    131   
   137    132   UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
   138    133   UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
   139    134   UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
   140    135   UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
   141    136   
   142         -if [ "${UNAME_SYSTEM}" = "Linux" ] ; then
   143         -	eval $set_cc_for_build
   144         -	cat << EOF > $dummy.c
          137  +case "$UNAME_SYSTEM" in
          138  +Linux|GNU|GNU/*)
          139  +	# If the system lacks a compiler, then just pick glibc.
          140  +	# We could probably try harder.
          141  +	LIBC=gnu
          142  +
          143  +	set_cc_for_build
          144  +	cat <<-EOF > "$dummy.c"
   145    145   	#include <features.h>
   146         -	#ifdef __UCLIBC__
   147         -	# ifdef __UCLIBC_CONFIG_VERSION__
   148         -	LIBC=uclibc __UCLIBC_CONFIG_VERSION__
   149         -	# else
          146  +	#if defined(__UCLIBC__)
   150    147   	LIBC=uclibc
   151         -	# endif
          148  +	#elif defined(__dietlibc__)
          149  +	LIBC=dietlibc
   152    150   	#else
   153    151   	LIBC=gnu
   154    152   	#endif
   155         -EOF
   156         -	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep LIBC= | sed -e 's: ::g'`
   157         -fi
          153  +	EOF
          154  +	eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`"
          155  +
          156  +	# If ldd exists, use it to detect musl libc.
          157  +	if command -v ldd >/dev/null && \
          158  +		ldd --version 2>&1 | grep -q ^musl
          159  +	then
          160  +	    LIBC=musl
          161  +	fi
          162  +	;;
          163  +esac
   158    164   
   159    165   # Note: order is significant - the case branches are not exclusive.
   160    166   
   161         -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
          167  +case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in
   162    168       *:NetBSD:*:*)
   163    169   	# NetBSD (nbsd) targets should (where applicable) match one or
   164         -	# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
          170  +	# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
   165    171   	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
   166    172   	# switched to ELF, *-*-netbsd* would select the old
   167    173   	# object file format.  This provides both forward
   168    174   	# compatibility and a consistent mechanism for selecting the
   169    175   	# object file format.
   170    176   	#
   171    177   	# Note: NetBSD doesn't particularly care about the vendor
   172    178   	# portion of the name.  We always set it to "unknown".
   173    179   	sysctl="sysctl -n hw.machine_arch"
   174         -	UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
   175         -	    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
   176         -	case "${UNAME_MACHINE_ARCH}" in
          180  +	UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \
          181  +	    "/sbin/$sysctl" 2>/dev/null || \
          182  +	    "/usr/sbin/$sysctl" 2>/dev/null || \
          183  +	    echo unknown)`
          184  +	case "$UNAME_MACHINE_ARCH" in
   177    185   	    armeb) machine=armeb-unknown ;;
   178    186   	    arm*) machine=arm-unknown ;;
   179    187   	    sh3el) machine=shl-unknown ;;
   180    188   	    sh3eb) machine=sh-unknown ;;
   181    189   	    sh5el) machine=sh5le-unknown ;;
   182         -	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
          190  +	    earmv*)
          191  +		arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'`
          192  +		endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'`
          193  +		machine="${arch}${endian}"-unknown
          194  +		;;
          195  +	    *) machine="$UNAME_MACHINE_ARCH"-unknown ;;
   183    196   	esac
   184    197   	# The Operating System including object format, if it has switched
   185         -	# to ELF recently, or will in the future.
   186         -	case "${UNAME_MACHINE_ARCH}" in
          198  +	# to ELF recently (or will in the future) and ABI.
          199  +	case "$UNAME_MACHINE_ARCH" in
          200  +	    earm*)
          201  +		os=netbsdelf
          202  +		;;
   187    203   	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
   188         -		eval $set_cc_for_build
          204  +		set_cc_for_build
   189    205   		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
   190         -			| grep __ELF__ >/dev/null
          206  +			| grep -q __ELF__
   191    207   		then
   192    208   		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
   193    209   		    # Return netbsd for either.  FIX?
   194    210   		    os=netbsd
   195    211   		else
   196    212   		    os=netbsdelf
   197    213   		fi
   198    214   		;;
   199    215   	    *)
   200         -	        os=netbsd
          216  +		os=netbsd
          217  +		;;
          218  +	esac
          219  +	# Determine ABI tags.
          220  +	case "$UNAME_MACHINE_ARCH" in
          221  +	    earm*)
          222  +		expr='s/^earmv[0-9]/-eabi/;s/eb$//'
          223  +		abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"`
   201    224   		;;
   202    225   	esac
   203    226   	# The OS release
   204    227   	# Debian GNU/NetBSD machines have a different userland, and
   205    228   	# thus, need a distinct triplet. However, they do not need
   206    229   	# kernel version information, so it can be replaced with a
   207    230   	# suitable tag, in the style of linux-gnu.
   208         -	case "${UNAME_VERSION}" in
          231  +	case "$UNAME_VERSION" in
   209    232   	    Debian*)
   210    233   		release='-gnu'
   211    234   		;;
   212    235   	    *)
   213         -		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
          236  +		release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2`
   214    237   		;;
   215    238   	esac
   216    239   	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
   217    240   	# contains redundant information, the shorter form:
   218    241   	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
   219         -	echo "${machine}-${os}${release}"
          242  +	echo "$machine-${os}${release}${abi-}"
          243  +	exit ;;
          244  +    *:Bitrig:*:*)
          245  +	UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
          246  +	echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE"
   220    247   	exit ;;
   221    248       *:OpenBSD:*:*)
   222    249   	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
   223         -	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
          250  +	echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE"
          251  +	exit ;;
          252  +    *:LibertyBSD:*:*)
          253  +	UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'`
          254  +	echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE"
          255  +	exit ;;
          256  +    *:MidnightBSD:*:*)
          257  +	echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE"
   224    258   	exit ;;
   225    259       *:ekkoBSD:*:*)
   226         -	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
          260  +	echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE"
   227    261   	exit ;;
   228    262       *:SolidBSD:*:*)
   229         -	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
          263  +	echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE"
   230    264   	exit ;;
   231    265       macppc:MirBSD:*:*)
   232         -	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
          266  +	echo powerpc-unknown-mirbsd"$UNAME_RELEASE"
   233    267   	exit ;;
   234    268       *:MirBSD:*:*)
   235         -	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
          269  +	echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE"
   236    270   	exit ;;
          271  +    *:Sortix:*:*)
          272  +	echo "$UNAME_MACHINE"-unknown-sortix
          273  +	exit ;;
          274  +    *:Redox:*:*)
          275  +	echo "$UNAME_MACHINE"-unknown-redox
          276  +	exit ;;
          277  +    mips:OSF1:*.*)
          278  +        echo mips-dec-osf1
          279  +        exit ;;
   237    280       alpha:OSF1:*:*)
   238    281   	case $UNAME_RELEASE in
   239    282   	*4.0)
   240    283   		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
   241    284   		;;
   242    285   	*5.*)
   243         -	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
          286  +		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
   244    287   		;;
   245    288   	esac
   246    289   	# According to Compaq, /usr/sbin/psrinfo has been available on
   247    290   	# OSF/1 and Tru64 systems produced since 1995.  I hope that
   248    291   	# covers most systems running today.  This code pipes the CPU
   249    292   	# types through head -n 1, so we only detect the type of CPU 0.
   250    293   	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
   251    294   	case "$ALPHA_CPU_TYPE" in
   252    295   	    "EV4 (21064)")
   253         -		UNAME_MACHINE="alpha" ;;
          296  +		UNAME_MACHINE=alpha ;;
   254    297   	    "EV4.5 (21064)")
   255         -		UNAME_MACHINE="alpha" ;;
          298  +		UNAME_MACHINE=alpha ;;
   256    299   	    "LCA4 (21066/21068)")
   257         -		UNAME_MACHINE="alpha" ;;
          300  +		UNAME_MACHINE=alpha ;;
   258    301   	    "EV5 (21164)")
   259         -		UNAME_MACHINE="alphaev5" ;;
          302  +		UNAME_MACHINE=alphaev5 ;;
   260    303   	    "EV5.6 (21164A)")
   261         -		UNAME_MACHINE="alphaev56" ;;
          304  +		UNAME_MACHINE=alphaev56 ;;
   262    305   	    "EV5.6 (21164PC)")
   263         -		UNAME_MACHINE="alphapca56" ;;
          306  +		UNAME_MACHINE=alphapca56 ;;
   264    307   	    "EV5.7 (21164PC)")
   265         -		UNAME_MACHINE="alphapca57" ;;
          308  +		UNAME_MACHINE=alphapca57 ;;
   266    309   	    "EV6 (21264)")
   267         -		UNAME_MACHINE="alphaev6" ;;
          310  +		UNAME_MACHINE=alphaev6 ;;
   268    311   	    "EV6.7 (21264A)")
   269         -		UNAME_MACHINE="alphaev67" ;;
          312  +		UNAME_MACHINE=alphaev67 ;;
   270    313   	    "EV6.8CB (21264C)")
   271         -		UNAME_MACHINE="alphaev68" ;;
          314  +		UNAME_MACHINE=alphaev68 ;;
   272    315   	    "EV6.8AL (21264B)")
   273         -		UNAME_MACHINE="alphaev68" ;;
          316  +		UNAME_MACHINE=alphaev68 ;;
   274    317   	    "EV6.8CX (21264D)")
   275         -		UNAME_MACHINE="alphaev68" ;;
          318  +		UNAME_MACHINE=alphaev68 ;;
   276    319   	    "EV6.9A (21264/EV69A)")
   277         -		UNAME_MACHINE="alphaev69" ;;
          320  +		UNAME_MACHINE=alphaev69 ;;
   278    321   	    "EV7 (21364)")
   279         -		UNAME_MACHINE="alphaev7" ;;
          322  +		UNAME_MACHINE=alphaev7 ;;
   280    323   	    "EV7.9 (21364A)")
   281         -		UNAME_MACHINE="alphaev79" ;;
          324  +		UNAME_MACHINE=alphaev79 ;;
   282    325   	esac
   283    326   	# A Pn.n version is a patched version.
   284    327   	# A Vn.n version is a released version.
   285    328   	# A Tn.n version is a released field test version.
   286    329   	# A Xn.n version is an unreleased experimental baselevel.
   287    330   	# 1.2 uses "1.2" for uname -r.
   288         -	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
   289         -	exit ;;
   290         -    Alpha\ *:Windows_NT*:*)
   291         -	# How do we know it's Interix rather than the generic POSIX subsystem?
   292         -	# Should we change UNAME_MACHINE based on the output of uname instead
   293         -	# of the specific Alpha model?
   294         -	echo alpha-pc-interix
   295         -	exit ;;
   296         -    21064:Windows_NT:50:3)
   297         -	echo alpha-dec-winnt3.5
   298         -	exit ;;
          331  +	echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`"
          332  +	# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
          333  +	exitcode=$?
          334  +	trap '' 0
          335  +	exit $exitcode ;;
   299    336       Amiga*:UNIX_System_V:4.0:*)
   300    337   	echo m68k-unknown-sysv4
   301    338   	exit ;;
   302    339       *:[Aa]miga[Oo][Ss]:*:*)
   303         -	echo ${UNAME_MACHINE}-unknown-amigaos
          340  +	echo "$UNAME_MACHINE"-unknown-amigaos
   304    341   	exit ;;
   305    342       *:[Mm]orph[Oo][Ss]:*:*)
   306         -	echo ${UNAME_MACHINE}-unknown-morphos
          343  +	echo "$UNAME_MACHINE"-unknown-morphos
   307    344   	exit ;;
   308    345       *:OS/390:*:*)
   309    346   	echo i370-ibm-openedition
   310    347   	exit ;;
   311    348       *:z/VM:*:*)
   312    349   	echo s390-ibm-zvmoe
   313    350   	exit ;;
   314    351       *:OS400:*:*)
   315         -        echo powerpc-ibm-os400
          352  +	echo powerpc-ibm-os400
   316    353   	exit ;;
   317    354       arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
   318         -	echo arm-acorn-riscix${UNAME_RELEASE}
          355  +	echo arm-acorn-riscix"$UNAME_RELEASE"
   319    356   	exit ;;
   320         -    arm:riscos:*:*|arm:RISCOS:*:*)
          357  +    arm*:riscos:*:*|arm*:RISCOS:*:*)
   321    358   	echo arm-unknown-riscos
   322    359   	exit ;;
   323    360       SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
   324    361   	echo hppa1.1-hitachi-hiuxmpp
   325    362   	exit ;;
   326    363       Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
   327    364   	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
................................................................................
   337    374       DRS?6000:unix:4.0:6*)
   338    375   	echo sparc-icl-nx6
   339    376   	exit ;;
   340    377       DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
   341    378   	case `/usr/bin/uname -p` in
   342    379   	    sparc) echo sparc-icl-nx7; exit ;;
   343    380   	esac ;;
          381  +    s390x:SunOS:*:*)
          382  +	echo "$UNAME_MACHINE"-ibm-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`"
          383  +	exit ;;
   344    384       sun4H:SunOS:5.*:*)
   345         -	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          385  +	echo sparc-hal-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
   346    386   	exit ;;
   347    387       sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
   348         -	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          388  +	echo sparc-sun-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`"
          389  +	exit ;;
          390  +    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
          391  +	echo i386-pc-auroraux"$UNAME_RELEASE"
   349    392   	exit ;;
   350    393       i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
   351         -	echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          394  +	set_cc_for_build
          395  +	SUN_ARCH=i386
          396  +	# If there is a compiler, see if it is configured for 64-bit objects.
          397  +	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
          398  +	# This test works for both compilers.
          399  +	if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
          400  +	    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
          401  +		(CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
          402  +		grep IS_64BIT_ARCH >/dev/null
          403  +	    then
          404  +		SUN_ARCH=x86_64
          405  +	    fi
          406  +	fi
          407  +	echo "$SUN_ARCH"-pc-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
   352    408   	exit ;;
   353    409       sun4*:SunOS:6*:*)
   354    410   	# According to config.sub, this is the proper way to canonicalize
   355    411   	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
   356    412   	# it's likely to be more like Solaris than SunOS4.
   357         -	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          413  +	echo sparc-sun-solaris3"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
   358    414   	exit ;;
   359    415       sun4*:SunOS:*:*)
   360    416   	case "`/usr/bin/arch -k`" in
   361    417   	    Series*|S4*)
   362    418   		UNAME_RELEASE=`uname -v`
   363    419   		;;
   364    420   	esac
   365    421   	# Japanese Language versions have a version number like `4.1.3-JL'.
   366         -	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
          422  +	echo sparc-sun-sunos"`echo "$UNAME_RELEASE"|sed -e 's/-/_/'`"
   367    423   	exit ;;
   368    424       sun3*:SunOS:*:*)
   369         -	echo m68k-sun-sunos${UNAME_RELEASE}
          425  +	echo m68k-sun-sunos"$UNAME_RELEASE"
   370    426   	exit ;;
   371    427       sun*:*:4.2BSD:*)
   372    428   	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
   373         -	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
          429  +	test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3
   374    430   	case "`/bin/arch`" in
   375    431   	    sun3)
   376         -		echo m68k-sun-sunos${UNAME_RELEASE}
          432  +		echo m68k-sun-sunos"$UNAME_RELEASE"
   377    433   		;;
   378    434   	    sun4)
   379         -		echo sparc-sun-sunos${UNAME_RELEASE}
          435  +		echo sparc-sun-sunos"$UNAME_RELEASE"
   380    436   		;;
   381    437   	esac
   382    438   	exit ;;
   383    439       aushp:SunOS:*:*)
   384         -	echo sparc-auspex-sunos${UNAME_RELEASE}
          440  +	echo sparc-auspex-sunos"$UNAME_RELEASE"
   385    441   	exit ;;
   386    442       # The situation for MiNT is a little confusing.  The machine name
   387    443       # can be virtually everything (everything which is not
   388    444       # "atarist" or "atariste" at least should have a processor
   389    445       # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
   390    446       # to the lowercase version "mint" (or "freemint").  Finally
   391    447       # the system name "TOS" denotes a system which is actually not
   392    448       # MiNT.  But MiNT is downward compatible to TOS, so this should
   393    449       # be no problem.
   394    450       atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
   395         -        echo m68k-atari-mint${UNAME_RELEASE}
          451  +	echo m68k-atari-mint"$UNAME_RELEASE"
   396    452   	exit ;;
   397    453       atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
   398         -	echo m68k-atari-mint${UNAME_RELEASE}
   399         -        exit ;;
          454  +	echo m68k-atari-mint"$UNAME_RELEASE"
          455  +	exit ;;
   400    456       *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
   401         -        echo m68k-atari-mint${UNAME_RELEASE}
          457  +	echo m68k-atari-mint"$UNAME_RELEASE"
   402    458   	exit ;;
   403    459       milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
   404         -        echo m68k-milan-mint${UNAME_RELEASE}
   405         -        exit ;;
          460  +	echo m68k-milan-mint"$UNAME_RELEASE"
          461  +	exit ;;
   406    462       hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
   407         -        echo m68k-hades-mint${UNAME_RELEASE}
   408         -        exit ;;
          463  +	echo m68k-hades-mint"$UNAME_RELEASE"
          464  +	exit ;;
   409    465       *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
   410         -        echo m68k-unknown-mint${UNAME_RELEASE}
   411         -        exit ;;
          466  +	echo m68k-unknown-mint"$UNAME_RELEASE"
          467  +	exit ;;
   412    468       m68k:machten:*:*)
   413         -	echo m68k-apple-machten${UNAME_RELEASE}
          469  +	echo m68k-apple-machten"$UNAME_RELEASE"
   414    470   	exit ;;
   415    471       powerpc:machten:*:*)
   416         -	echo powerpc-apple-machten${UNAME_RELEASE}
          472  +	echo powerpc-apple-machten"$UNAME_RELEASE"
   417    473   	exit ;;
   418    474       RISC*:Mach:*:*)
   419    475   	echo mips-dec-mach_bsd4.3
   420    476   	exit ;;
   421    477       RISC*:ULTRIX:*:*)
   422         -	echo mips-dec-ultrix${UNAME_RELEASE}
          478  +	echo mips-dec-ultrix"$UNAME_RELEASE"
   423    479   	exit ;;
   424    480       VAX*:ULTRIX*:*:*)
   425         -	echo vax-dec-ultrix${UNAME_RELEASE}
          481  +	echo vax-dec-ultrix"$UNAME_RELEASE"
   426    482   	exit ;;
   427    483       2020:CLIX:*:* | 2430:CLIX:*:*)
   428         -	echo clipper-intergraph-clix${UNAME_RELEASE}
          484  +	echo clipper-intergraph-clix"$UNAME_RELEASE"
   429    485   	exit ;;
   430    486       mips:*:*:UMIPS | mips:*:*:RISCos)
   431         -	eval $set_cc_for_build
   432         -	sed 's/^	//' << EOF >$dummy.c
          487  +	set_cc_for_build
          488  +	sed 's/^	//' << EOF > "$dummy.c"
   433    489   #ifdef __cplusplus
   434    490   #include <stdio.h>  /* for printf() prototype */
   435    491   	int main (int argc, char *argv[]) {
   436    492   #else
   437    493   	int main (argc, argv) int argc; char *argv[]; {
   438    494   #endif
   439    495   	#if defined (host_mips) && defined (MIPSEB)
   440    496   	#if defined (SYSTYPE_SYSV)
   441         -	  printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
          497  +	  printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0);
   442    498   	#endif
   443    499   	#if defined (SYSTYPE_SVR4)
   444         -	  printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
          500  +	  printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0);
   445    501   	#endif
   446    502   	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
   447         -	  printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
          503  +	  printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0);
   448    504   	#endif
   449    505   	#endif
   450    506   	  exit (-1);
   451    507   	}
   452    508   EOF
   453         -	$CC_FOR_BUILD -o $dummy $dummy.c &&
   454         -	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
   455         -	  SYSTEM_NAME=`$dummy $dummyarg` &&
          509  +	$CC_FOR_BUILD -o "$dummy" "$dummy.c" &&
          510  +	  dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` &&
          511  +	  SYSTEM_NAME=`"$dummy" "$dummyarg"` &&
   456    512   	    { echo "$SYSTEM_NAME"; exit; }
   457         -	echo mips-mips-riscos${UNAME_RELEASE}
          513  +	echo mips-mips-riscos"$UNAME_RELEASE"
   458    514   	exit ;;
   459    515       Motorola:PowerMAX_OS:*:*)
   460    516   	echo powerpc-motorola-powermax
   461    517   	exit ;;
   462    518       Motorola:*:4.3:PL8-*)
   463    519   	echo powerpc-harris-powermax
   464    520   	exit ;;
................................................................................
   474    530       m88k:*:4*:R4*)
   475    531   	echo m88k-motorola-sysv4
   476    532   	exit ;;
   477    533       m88k:*:3*:R3*)
   478    534   	echo m88k-motorola-sysv3
   479    535   	exit ;;
   480    536       AViiON:dgux:*:*)
   481         -        # DG/UX returns AViiON for all architectures
   482         -        UNAME_PROCESSOR=`/usr/bin/uname -p`
   483         -	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
          537  +	# DG/UX returns AViiON for all architectures
          538  +	UNAME_PROCESSOR=`/usr/bin/uname -p`
          539  +	if [ "$UNAME_PROCESSOR" = mc88100 ] || [ "$UNAME_PROCESSOR" = mc88110 ]
   484    540   	then
   485         -	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
   486         -	       [ ${TARGET_BINARY_INTERFACE}x = x ]
          541  +	    if [ "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx ] || \
          542  +	       [ "$TARGET_BINARY_INTERFACE"x = x ]
   487    543   	    then
   488         -		echo m88k-dg-dgux${UNAME_RELEASE}
          544  +		echo m88k-dg-dgux"$UNAME_RELEASE"
   489    545   	    else
   490         -		echo m88k-dg-dguxbcs${UNAME_RELEASE}
          546  +		echo m88k-dg-dguxbcs"$UNAME_RELEASE"
   491    547   	    fi
   492    548   	else
   493         -	    echo i586-dg-dgux${UNAME_RELEASE}
          549  +	    echo i586-dg-dgux"$UNAME_RELEASE"
   494    550   	fi
   495         - 	exit ;;
          551  +	exit ;;
   496    552       M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
   497    553   	echo m88k-dolphin-sysv3
   498    554   	exit ;;
   499    555       M88*:*:R3*:*)
   500    556   	# Delta 88k system running SVR3
   501    557   	echo m88k-motorola-sysv3
   502    558   	exit ;;
................................................................................
   503    559       XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
   504    560   	echo m88k-tektronix-sysv3
   505    561   	exit ;;
   506    562       Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
   507    563   	echo m68k-tektronix-bsd
   508    564   	exit ;;
   509    565       *:IRIX*:*:*)
   510         -	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
          566  +	echo mips-sgi-irix"`echo "$UNAME_RELEASE"|sed -e 's/-/_/g'`"
   511    567   	exit ;;
   512    568       ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
   513    569   	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
   514    570   	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
   515    571       i*86:AIX:*:*)
   516    572   	echo i386-ibm-aix
   517    573   	exit ;;
   518    574       ia64:AIX:*:*)
   519    575   	if [ -x /usr/bin/oslevel ] ; then
   520    576   		IBM_REV=`/usr/bin/oslevel`
   521    577   	else
   522         -		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
          578  +		IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
   523    579   	fi
   524         -	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
          580  +	echo "$UNAME_MACHINE"-ibm-aix"$IBM_REV"
   525    581   	exit ;;
   526    582       *:AIX:2:3)
   527    583   	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
   528         -		eval $set_cc_for_build
   529         -		sed 's/^		//' << EOF >$dummy.c
          584  +		set_cc_for_build
          585  +		sed 's/^		//' << EOF > "$dummy.c"
   530    586   		#include <sys/systemcfg.h>
   531    587   
   532    588   		main()
   533    589   			{
   534    590   			if (!__power_pc())
   535    591   				exit(1);
   536    592   			puts("powerpc-ibm-aix3.2.5");
   537    593   			exit(0);
   538    594   			}
   539    595   EOF
   540         -		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
          596  +		if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"`
   541    597   		then
   542    598   			echo "$SYSTEM_NAME"
   543    599   		else
   544    600   			echo rs6000-ibm-aix3.2.5
   545    601   		fi
   546    602   	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
   547    603   		echo rs6000-ibm-aix3.2.4
   548    604   	else
   549    605   		echo rs6000-ibm-aix3.2
   550    606   	fi
   551    607   	exit ;;
   552         -    *:AIX:*:[45])
          608  +    *:AIX:*:[4567])
   553    609   	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
   554         -	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
          610  +	if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then
   555    611   		IBM_ARCH=rs6000
   556    612   	else
   557    613   		IBM_ARCH=powerpc
   558    614   	fi
   559         -	if [ -x /usr/bin/oslevel ] ; then
   560         -		IBM_REV=`/usr/bin/oslevel`
          615  +	if [ -x /usr/bin/lslpp ] ; then
          616  +		IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc |
          617  +			   awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`
   561    618   	else
   562         -		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
          619  +		IBM_REV="$UNAME_VERSION.$UNAME_RELEASE"
   563    620   	fi
   564         -	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
          621  +	echo "$IBM_ARCH"-ibm-aix"$IBM_REV"
   565    622   	exit ;;
   566    623       *:AIX:*:*)
   567    624   	echo rs6000-ibm-aix
   568    625   	exit ;;
   569         -    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
          626  +    ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*)
   570    627   	echo romp-ibm-bsd4.4
   571    628   	exit ;;
   572    629       ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
   573         -	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
          630  +	echo romp-ibm-bsd"$UNAME_RELEASE"   # 4.3 with uname added to
   574    631   	exit ;;                             # report: romp-ibm BSD 4.3
   575    632       *:BOSX:*:*)
   576    633   	echo rs6000-bull-bosx
   577    634   	exit ;;
   578    635       DPX/2?00:B.O.S.:*:*)
   579    636   	echo m68k-bull-sysv3
   580    637   	exit ;;
................................................................................
   581    638       9000/[34]??:4.3bsd:1.*:*)
   582    639   	echo m68k-hp-bsd
   583    640   	exit ;;
   584    641       hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
   585    642   	echo m68k-hp-bsd4.4
   586    643   	exit ;;
   587    644       9000/[34678]??:HP-UX:*:*)
   588         -	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
   589         -	case "${UNAME_MACHINE}" in
   590         -	    9000/31? )            HP_ARCH=m68000 ;;
   591         -	    9000/[34]?? )         HP_ARCH=m68k ;;
          645  +	HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'`
          646  +	case "$UNAME_MACHINE" in
          647  +	    9000/31?)            HP_ARCH=m68000 ;;
          648  +	    9000/[34]??)         HP_ARCH=m68k ;;
   592    649   	    9000/[678][0-9][0-9])
   593    650   		if [ -x /usr/bin/getconf ]; then
   594    651   		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
   595         -                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
   596         -                    case "${sc_cpu_version}" in
   597         -                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
   598         -                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
   599         -                      532)                      # CPU_PA_RISC2_0
   600         -                        case "${sc_kernel_bits}" in
   601         -                          32) HP_ARCH="hppa2.0n" ;;
   602         -                          64) HP_ARCH="hppa2.0w" ;;
   603         -			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
   604         -                        esac ;;
   605         -                    esac
          652  +		    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
          653  +		    case "$sc_cpu_version" in
          654  +		      523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0
          655  +		      528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1
          656  +		      532)                      # CPU_PA_RISC2_0
          657  +			case "$sc_kernel_bits" in
          658  +			  32) HP_ARCH=hppa2.0n ;;
          659  +			  64) HP_ARCH=hppa2.0w ;;
          660  +			  '') HP_ARCH=hppa2.0 ;;   # HP-UX 10.20
          661  +			esac ;;
          662  +		    esac
   606    663   		fi
   607         -		if [ "${HP_ARCH}" = "" ]; then
   608         -		    eval $set_cc_for_build
   609         -		    sed 's/^              //' << EOF >$dummy.c
   610         -
   611         -              #define _HPUX_SOURCE
   612         -              #include <stdlib.h>
   613         -              #include <unistd.h>
   614         -
   615         -              int main ()
   616         -              {
   617         -              #if defined(_SC_KERNEL_BITS)
   618         -                  long bits = sysconf(_SC_KERNEL_BITS);
   619         -              #endif
   620         -                  long cpu  = sysconf (_SC_CPU_VERSION);
   621         -
   622         -                  switch (cpu)
   623         -              	{
   624         -              	case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
   625         -              	case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
   626         -              	case CPU_PA_RISC2_0:
   627         -              #if defined(_SC_KERNEL_BITS)
   628         -              	    switch (bits)
   629         -              		{
   630         -              		case 64: puts ("hppa2.0w"); break;
   631         -              		case 32: puts ("hppa2.0n"); break;
   632         -              		default: puts ("hppa2.0"); break;
   633         -              		} break;
   634         -              #else  /* !defined(_SC_KERNEL_BITS) */
   635         -              	    puts ("hppa2.0"); break;
   636         -              #endif
   637         -              	default: puts ("hppa1.0"); break;
   638         -              	}
   639         -                  exit (0);
   640         -              }
          664  +		if [ "$HP_ARCH" = "" ]; then
          665  +		    set_cc_for_build
          666  +		    sed 's/^		//' << EOF > "$dummy.c"
          667  +
          668  +		#define _HPUX_SOURCE
          669  +		#include <stdlib.h>
          670  +		#include <unistd.h>
          671  +
          672  +		int main ()
          673  +		{
          674  +		#if defined(_SC_KERNEL_BITS)
          675  +		    long bits = sysconf(_SC_KERNEL_BITS);
          676  +		#endif
          677  +		    long cpu  = sysconf (_SC_CPU_VERSION);
          678  +
          679  +		    switch (cpu)
          680  +			{
          681  +			case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
          682  +			case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
          683  +			case CPU_PA_RISC2_0:
          684  +		#if defined(_SC_KERNEL_BITS)
          685  +			    switch (bits)
          686  +				{
          687  +				case 64: puts ("hppa2.0w"); break;
          688  +				case 32: puts ("hppa2.0n"); break;
          689  +				default: puts ("hppa2.0"); break;
          690  +				} break;
          691  +		#else  /* !defined(_SC_KERNEL_BITS) */
          692  +			    puts ("hppa2.0"); break;
          693  +		#endif
          694  +			default: puts ("hppa1.0"); break;
          695  +			}
          696  +		    exit (0);
          697  +		}
   641    698   EOF
   642         -		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
          699  +		    (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"`
   643    700   		    test -z "$HP_ARCH" && HP_ARCH=hppa
   644    701   		fi ;;
   645    702   	esac
   646         -	if [ ${HP_ARCH} = "hppa2.0w" ]
          703  +	if [ "$HP_ARCH" = hppa2.0w ]
   647    704   	then
   648         -	    eval $set_cc_for_build
          705  +	    set_cc_for_build
   649    706   
   650    707   	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
   651    708   	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
   652    709   	    # generating 64-bit code.  GNU and HP use different nomenclature:
   653    710   	    #
   654    711   	    # $ CC_FOR_BUILD=cc ./config.guess
   655    712   	    # => hppa2.0w-hp-hpux11.23
   656    713   	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
   657    714   	    # => hppa64-hp-hpux11.23
   658    715   
   659         -	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
   660         -		grep __LP64__ >/dev/null
          716  +	    if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) |
          717  +		grep -q __LP64__
   661    718   	    then
   662         -		HP_ARCH="hppa2.0w"
          719  +		HP_ARCH=hppa2.0w
   663    720   	    else
   664         -		HP_ARCH="hppa64"
          721  +		HP_ARCH=hppa64
   665    722   	    fi
   666    723   	fi
   667         -	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
          724  +	echo "$HP_ARCH"-hp-hpux"$HPUX_REV"
   668    725   	exit ;;
   669    726       ia64:HP-UX:*:*)
   670         -	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
   671         -	echo ia64-hp-hpux${HPUX_REV}
          727  +	HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'`
          728  +	echo ia64-hp-hpux"$HPUX_REV"
   672    729   	exit ;;
   673    730       3050*:HI-UX:*:*)
   674         -	eval $set_cc_for_build
   675         -	sed 's/^	//' << EOF >$dummy.c
          731  +	set_cc_for_build
          732  +	sed 's/^	//' << EOF > "$dummy.c"
   676    733   	#include <unistd.h>
   677    734   	int
   678    735   	main ()
   679    736   	{
   680    737   	  long cpu = sysconf (_SC_CPU_VERSION);
   681    738   	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
   682    739   	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
................................................................................
   693    750   	    }
   694    751   	  else if (CPU_IS_HP_MC68K (cpu))
   695    752   	    puts ("m68k-hitachi-hiuxwe2");
   696    753   	  else puts ("unknown-hitachi-hiuxwe2");
   697    754   	  exit (0);
   698    755   	}
   699    756   EOF
   700         -	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
          757  +	$CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` &&
   701    758   		{ echo "$SYSTEM_NAME"; exit; }
   702    759   	echo unknown-hitachi-hiuxwe2
   703    760   	exit ;;
   704         -    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
          761  +    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*)
   705    762   	echo hppa1.1-hp-bsd
   706    763   	exit ;;
   707    764       9000/8??:4.3bsd:*:*)
   708    765   	echo hppa1.0-hp-bsd
   709    766   	exit ;;
   710    767       *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
   711    768   	echo hppa1.0-hp-mpeix
   712    769   	exit ;;
   713         -    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
          770  +    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*)
   714    771   	echo hppa1.1-hp-osf
   715    772   	exit ;;
   716    773       hp8??:OSF1:*:*)
   717    774   	echo hppa1.0-hp-osf
   718    775   	exit ;;
   719    776       i*86:OSF1:*:*)
   720    777   	if [ -x /usr/sbin/sysversion ] ; then
   721         -	    echo ${UNAME_MACHINE}-unknown-osf1mk
          778  +	    echo "$UNAME_MACHINE"-unknown-osf1mk
   722    779   	else
   723         -	    echo ${UNAME_MACHINE}-unknown-osf1
          780  +	    echo "$UNAME_MACHINE"-unknown-osf1
   724    781   	fi
   725    782   	exit ;;
   726    783       parisc*:Lites*:*:*)
   727    784   	echo hppa1.1-hp-lites
   728    785   	exit ;;
   729    786       C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
   730    787   	echo c1-convex-bsd
   731         -        exit ;;
          788  +	exit ;;
   732    789       C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
   733    790   	if getsysinfo -f scalar_acc
   734    791   	then echo c32-convex-bsd
   735    792   	else echo c2-convex-bsd
   736    793   	fi
   737         -        exit ;;
          794  +	exit ;;
   738    795       C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
   739    796   	echo c34-convex-bsd
   740         -        exit ;;
          797  +	exit ;;
   741    798       C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
   742    799   	echo c38-convex-bsd
   743         -        exit ;;
          800  +	exit ;;
   744    801       C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
   745    802   	echo c4-convex-bsd
   746         -        exit ;;
          803  +	exit ;;
   747    804       CRAY*Y-MP:*:*:*)
   748         -	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          805  +	echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
   749    806   	exit ;;
   750    807       CRAY*[A-Z]90:*:*:*)
   751         -	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
          808  +	echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \
   752    809   	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
   753    810   	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
   754    811   	      -e 's/\.[^.]*$/.X/'
   755    812   	exit ;;
   756    813       CRAY*TS:*:*:*)
   757         -	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          814  +	echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
   758    815   	exit ;;
   759    816       CRAY*T3E:*:*:*)
   760         -	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          817  +	echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
   761    818   	exit ;;
   762    819       CRAY*SV1:*:*:*)
   763         -	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          820  +	echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
   764    821   	exit ;;
   765    822       *:UNICOS/mp:*:*)
   766         -	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          823  +	echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'
   767    824   	exit ;;
   768    825       F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
   769         -	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
   770         -        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
   771         -        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
   772         -        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
   773         -        exit ;;
          826  +	FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
          827  +	FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
          828  +	FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'`
          829  +	echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
          830  +	exit ;;
   774    831       5000:UNIX_System_V:4.*:*)
   775         -        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
   776         -        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
   777         -        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
          832  +	FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'`
          833  +	FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'`
          834  +	echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
   778    835   	exit ;;
   779    836       i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
   780         -	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
          837  +	echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE"
   781    838   	exit ;;
   782    839       sparc*:BSD/OS:*:*)
   783         -	echo sparc-unknown-bsdi${UNAME_RELEASE}
          840  +	echo sparc-unknown-bsdi"$UNAME_RELEASE"
   784    841   	exit ;;
   785    842       *:BSD/OS:*:*)
   786         -	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
          843  +	echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE"
          844  +	exit ;;
          845  +    arm:FreeBSD:*:*)
          846  +	UNAME_PROCESSOR=`uname -p`
          847  +	set_cc_for_build
          848  +	if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
          849  +	    | grep -q __ARM_PCS_VFP
          850  +	then
          851  +	    echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabi
          852  +	else
          853  +	    echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabihf
          854  +	fi
   787    855   	exit ;;
   788    856       *:FreeBSD:*:*)
   789         -	case ${UNAME_MACHINE} in
   790         -	    pc98)
   791         -		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
          857  +	UNAME_PROCESSOR=`/usr/bin/uname -p`
          858  +	case "$UNAME_PROCESSOR" in
   792    859   	    amd64)
   793         -		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
   794         -	    *)
   795         -		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
          860  +		UNAME_PROCESSOR=x86_64 ;;
          861  +	    i386)
          862  +		UNAME_PROCESSOR=i586 ;;
   796    863   	esac
          864  +	echo "$UNAME_PROCESSOR"-unknown-freebsd"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`"
   797    865   	exit ;;
   798    866       i*:CYGWIN*:*)
   799         -	echo ${UNAME_MACHINE}-pc-cygwin
          867  +	echo "$UNAME_MACHINE"-pc-cygwin
          868  +	exit ;;
          869  +    *:MINGW64*:*)
          870  +	echo "$UNAME_MACHINE"-pc-mingw64
   800    871   	exit ;;
   801    872       *:MINGW*:*)
   802         -	echo ${UNAME_MACHINE}-pc-mingw32
          873  +	echo "$UNAME_MACHINE"-pc-mingw32
   803    874   	exit ;;
   804         -    i*:windows32*:*)
   805         -    	# uname -m includes "-pc" on this system.
   806         -    	echo ${UNAME_MACHINE}-mingw32
          875  +    *:MSYS*:*)
          876  +	echo "$UNAME_MACHINE"-pc-msys
   807    877   	exit ;;
   808    878       i*:PW*:*)
   809         -	echo ${UNAME_MACHINE}-pc-pw32
          879  +	echo "$UNAME_MACHINE"-pc-pw32
   810    880   	exit ;;
   811         -    *:Interix*:[3456]*)
   812         -    	case ${UNAME_MACHINE} in
          881  +    *:Interix*:*)
          882  +	case "$UNAME_MACHINE" in
   813    883   	    x86)
   814         -		echo i586-pc-interix${UNAME_RELEASE}
          884  +		echo i586-pc-interix"$UNAME_RELEASE"
          885  +		exit ;;
          886  +	    authenticamd | genuineintel | EM64T)
          887  +		echo x86_64-unknown-interix"$UNAME_RELEASE"
   815    888   		exit ;;
   816         -	    EM64T | authenticamd)
   817         -		echo x86_64-unknown-interix${UNAME_RELEASE}
          889  +	    IA64)
          890  +		echo ia64-unknown-interix"$UNAME_RELEASE"
   818    891   		exit ;;
   819    892   	esac ;;
   820         -    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
   821         -	echo i${UNAME_MACHINE}-pc-mks
   822         -	exit ;;
   823         -    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
   824         -	# How do we know it's Interix rather than the generic POSIX subsystem?
   825         -	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
   826         -	# UNAME_MACHINE based on the output of uname instead of i386?
   827         -	echo i586-pc-interix
   828         -	exit ;;
   829    893       i*:UWIN*:*)
   830         -	echo ${UNAME_MACHINE}-pc-uwin
          894  +	echo "$UNAME_MACHINE"-pc-uwin
   831    895   	exit ;;
   832    896       amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
   833         -	echo x86_64-unknown-cygwin
   834         -	exit ;;
   835         -    p*:CYGWIN*:*)
   836         -	echo powerpcle-unknown-cygwin
          897  +	echo x86_64-pc-cygwin
   837    898   	exit ;;
   838    899       prep*:SunOS:5.*:*)
   839         -	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          900  +	echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
   840    901   	exit ;;
   841    902       *:GNU:*:*)
   842    903   	# the GNU system
   843         -	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
          904  +	echo "`echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,'`-unknown-$LIBC`echo "$UNAME_RELEASE"|sed -e 's,/.*$,,'`"
   844    905   	exit ;;
   845    906       *:GNU/*:*:*)
   846    907   	# other systems with GNU libc and userland
   847         -	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
   848         -	exit ;;
   849         -    i*86:Minix:*:*)
   850         -	echo ${UNAME_MACHINE}-pc-minix
   851         -	exit ;;
   852         -    arm*:Linux:*:*)
   853         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
   854         -	exit ;;
   855         -    avr32*:Linux:*:*)
   856         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
   857         -	exit ;;
   858         -    cris:Linux:*:*)
   859         -	echo cris-axis-linux-${LIBC}
   860         -	exit ;;
   861         -    crisv32:Linux:*:*)
   862         -	echo crisv32-axis-linux-${LIBC}
   863         -	exit ;;
   864         -    frv:Linux:*:*)
   865         -    	echo frv-unknown-linux-${LIBC}
   866         -	exit ;;
   867         -    ia64:Linux:*:*)
   868         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
   869         -	exit ;;
   870         -    m32r*:Linux:*:*)
   871         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
   872         -	exit ;;
   873         -    m68*:Linux:*:*)
   874         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
   875         -	exit ;;
   876         -    mips:Linux:*:*)
   877         -	eval $set_cc_for_build
   878         -	sed 's/^	//' << EOF >$dummy.c
   879         -	#undef CPU
   880         -	#undef mips
   881         -	#undef mipsel
   882         -	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
   883         -	CPU=mipsel
   884         -	#else
   885         -	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
   886         -	CPU=mips
   887         -	#else
   888         -	CPU=
   889         -	#endif
   890         -	#endif
   891         -EOF
   892         -	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
   893         -	    /^CPU/{
   894         -		s: ::g
   895         -		p
   896         -	    }'`"
   897         -	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
   898         -	;;
   899         -    mips64:Linux:*:*)
   900         -	eval $set_cc_for_build
   901         -	sed 's/^	//' << EOF >$dummy.c
   902         -	#undef CPU
   903         -	#undef mips64
   904         -	#undef mips64el
   905         -	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
   906         -	CPU=mips64el
   907         -	#else
   908         -	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
   909         -	CPU=mips64
   910         -	#else
   911         -	CPU=
   912         -	#endif
   913         -	#endif
   914         -EOF
   915         -	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
   916         -	    /^CPU/{
   917         -		s: ::g
   918         -		p
   919         -	    }'`"
   920         -	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
   921         -	;;
   922         -    or32:Linux:*:*)
   923         -	echo or32-unknown-linux-${LIBC}
   924         -	exit ;;
   925         -    ppc:Linux:*:*)
   926         -	echo powerpc-unknown-linux-${LIBC}
   927         -	exit ;;
   928         -    ppc64:Linux:*:*)
   929         -	echo powerpc64-unknown-linux-${LIBC}
          908  +	echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC"
          909  +	exit ;;
          910  +    *:Minix:*:*)
          911  +	echo "$UNAME_MACHINE"-unknown-minix
          912  +	exit ;;
          913  +    aarch64:Linux:*:*)
          914  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          915  +	exit ;;
          916  +    aarch64_be:Linux:*:*)
          917  +	UNAME_MACHINE=aarch64_be
          918  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
   930    919   	exit ;;
   931    920       alpha:Linux:*:*)
   932    921   	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
   933    922   	  EV5)   UNAME_MACHINE=alphaev5 ;;
   934    923   	  EV56)  UNAME_MACHINE=alphaev56 ;;
   935    924   	  PCA56) UNAME_MACHINE=alphapca56 ;;
   936    925   	  PCA57) UNAME_MACHINE=alphapca56 ;;
   937    926   	  EV6)   UNAME_MACHINE=alphaev6 ;;
   938    927   	  EV67)  UNAME_MACHINE=alphaev67 ;;
   939    928   	  EV68*) UNAME_MACHINE=alphaev68 ;;
   940         -        esac
   941         -	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
   942         -	if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
   943         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
          929  +	esac
          930  +	objdump --private-headers /bin/sh | grep -q ld.so.1
          931  +	if test "$?" = 0 ; then LIBC=gnulibc1 ; fi
          932  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          933  +	exit ;;
          934  +    arc:Linux:*:* | arceb:Linux:*:*)
          935  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          936  +	exit ;;
          937  +    arm*:Linux:*:*)
          938  +	set_cc_for_build
          939  +	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
          940  +	    | grep -q __ARM_EABI__
          941  +	then
          942  +	    echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          943  +	else
          944  +	    if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
          945  +		| grep -q __ARM_PCS_VFP
          946  +	    then
          947  +		echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi
          948  +	    else
          949  +		echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf
          950  +	    fi
          951  +	fi
          952  +	exit ;;
          953  +    avr32*:Linux:*:*)
          954  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          955  +	exit ;;
          956  +    cris:Linux:*:*)
          957  +	echo "$UNAME_MACHINE"-axis-linux-"$LIBC"
          958  +	exit ;;
          959  +    crisv32:Linux:*:*)
          960  +	echo "$UNAME_MACHINE"-axis-linux-"$LIBC"
          961  +	exit ;;
          962  +    e2k:Linux:*:*)
          963  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          964  +	exit ;;
          965  +    frv:Linux:*:*)
          966  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          967  +	exit ;;
          968  +    hexagon:Linux:*:*)
          969  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          970  +	exit ;;
          971  +    i*86:Linux:*:*)
          972  +	echo "$UNAME_MACHINE"-pc-linux-"$LIBC"
          973  +	exit ;;
          974  +    ia64:Linux:*:*)
          975  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          976  +	exit ;;
          977  +    k1om:Linux:*:*)
          978  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          979  +	exit ;;
          980  +    m32r*:Linux:*:*)
          981  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          982  +	exit ;;
          983  +    m68*:Linux:*:*)
          984  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
          985  +	exit ;;
          986  +    mips:Linux:*:* | mips64:Linux:*:*)
          987  +	set_cc_for_build
          988  +	IS_GLIBC=0
          989  +	test x"${LIBC}" = xgnu && IS_GLIBC=1
          990  +	sed 's/^	//' << EOF > "$dummy.c"
          991  +	#undef CPU
          992  +	#undef mips
          993  +	#undef mipsel
          994  +	#undef mips64
          995  +	#undef mips64el
          996  +	#if ${IS_GLIBC} && defined(_ABI64)
          997  +	LIBCABI=gnuabi64
          998  +	#else
          999  +	#if ${IS_GLIBC} && defined(_ABIN32)
         1000  +	LIBCABI=gnuabin32
         1001  +	#else
         1002  +	LIBCABI=${LIBC}
         1003  +	#endif
         1004  +	#endif
         1005  +
         1006  +	#if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
         1007  +	CPU=mipsisa64r6
         1008  +	#else
         1009  +	#if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6
         1010  +	CPU=mipsisa32r6
         1011  +	#else
         1012  +	#if defined(__mips64)
         1013  +	CPU=mips64
         1014  +	#else
         1015  +	CPU=mips
         1016  +	#endif
         1017  +	#endif
         1018  +	#endif
         1019  +
         1020  +	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
         1021  +	MIPS_ENDIAN=el
         1022  +	#else
         1023  +	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
         1024  +	MIPS_ENDIAN=
         1025  +	#else
         1026  +	MIPS_ENDIAN=
         1027  +	#endif
         1028  +	#endif
         1029  +EOF
         1030  +	eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`"
         1031  +	test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; }
         1032  +	;;
         1033  +    mips64el:Linux:*:*)
         1034  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
         1035  +	exit ;;
         1036  +    openrisc*:Linux:*:*)
         1037  +	echo or1k-unknown-linux-"$LIBC"
         1038  +	exit ;;
         1039  +    or32:Linux:*:* | or1k*:Linux:*:*)
         1040  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
         1041  +	exit ;;
         1042  +    padre:Linux:*:*)
         1043  +	echo sparc-unknown-linux-"$LIBC"
         1044  +	exit ;;
         1045  +    parisc64:Linux:*:* | hppa64:Linux:*:*)
         1046  +	echo hppa64-unknown-linux-"$LIBC"
   944   1047   	exit ;;
   945   1048       parisc:Linux:*:* | hppa:Linux:*:*)
   946   1049   	# Look for CPU level
   947   1050   	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
   948         -	  PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
   949         -	  PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
   950         -	  *)    echo hppa-unknown-linux-${LIBC} ;;
         1051  +	  PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;;
         1052  +	  PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;;
         1053  +	  *)    echo hppa-unknown-linux-"$LIBC" ;;
   951   1054   	esac
   952   1055   	exit ;;
   953         -    parisc64:Linux:*:* | hppa64:Linux:*:*)
   954         -	echo hppa64-unknown-linux-${LIBC}
         1056  +    ppc64:Linux:*:*)
         1057  +	echo powerpc64-unknown-linux-"$LIBC"
         1058  +	exit ;;
         1059  +    ppc:Linux:*:*)
         1060  +	echo powerpc-unknown-linux-"$LIBC"
         1061  +	exit ;;
         1062  +    ppc64le:Linux:*:*)
         1063  +	echo powerpc64le-unknown-linux-"$LIBC"
         1064  +	exit ;;
         1065  +    ppcle:Linux:*:*)
         1066  +	echo powerpcle-unknown-linux-"$LIBC"
         1067  +	exit ;;
         1068  +    riscv32:Linux:*:* | riscv64:Linux:*:*)
         1069  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
   955   1070   	exit ;;
   956   1071       s390:Linux:*:* | s390x:Linux:*:*)
   957         -	echo ${UNAME_MACHINE}-ibm-linux
         1072  +	echo "$UNAME_MACHINE"-ibm-linux-"$LIBC"
   958   1073   	exit ;;
   959   1074       sh64*:Linux:*:*)
   960         -    	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
         1075  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
   961   1076   	exit ;;
   962   1077       sh*:Linux:*:*)
   963         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
         1078  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
   964   1079   	exit ;;
   965   1080       sparc:Linux:*:* | sparc64:Linux:*:*)
   966         -	echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
         1081  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
         1082  +	exit ;;
         1083  +    tile*:Linux:*:*)
         1084  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
   967   1085   	exit ;;
   968   1086       vax:Linux:*:*)
   969         -	echo ${UNAME_MACHINE}-dec-linux-${LIBC}
         1087  +	echo "$UNAME_MACHINE"-dec-linux-"$LIBC"
   970   1088   	exit ;;
   971   1089       x86_64:Linux:*:*)
   972         -	echo x86_64-unknown-linux-${LIBC}
         1090  +	echo "$UNAME_MACHINE"-pc-linux-"$LIBC"
   973   1091   	exit ;;
   974         -    xtensa:Linux:*:*)
   975         -    	echo xtensa-unknown-linux-${LIBC}
         1092  +    xtensa*:Linux:*:*)
         1093  +	echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"
   976   1094   	exit ;;
   977         -    i*86:Linux:*:*)
   978         -	# The BFD linker knows what the default object file format is, so
   979         -	# first see if it will tell us. cd to the root directory to prevent
   980         -	# problems with other programs or directories called `ld' in the path.
   981         -	# Set LC_ALL=C to ensure ld outputs messages in English.
   982         -	ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
   983         -			 | sed -ne '/supported targets:/!d
   984         -				    s/[ 	][ 	]*/ /g
   985         -				    s/.*supported targets: *//
   986         -				    s/ .*//
   987         -				    p'`
   988         -        case "$ld_supported_targets" in
   989         -	  elf32-i386)
   990         -		TENTATIVE="${UNAME_MACHINE}-pc-linux-${LIBC}"
   991         -		;;
   992         -	  a.out-i386-linux)
   993         -		echo "${UNAME_MACHINE}-pc-linux-${LIBC}aout"
   994         -		exit ;;
   995         -	  coff-i386)
   996         -		echo "${UNAME_MACHINE}-pc-linux-${LIBC}coff"
   997         -		exit ;;
   998         -	  "")
   999         -		# Either a pre-BFD a.out linker (linux-gnuoldld) or
  1000         -		# one that does not give us useful --help.
  1001         -		echo "${UNAME_MACHINE}-pc-linux-${LIBC}oldld"
  1002         -		exit ;;
  1003         -	esac
  1004         -	# This should get integrated into the C code below, but now we hack
  1005         -	if [ "$LIBC" != "gnu" ] ; then echo "$TENTATIVE" && exit 0 ; fi
  1006         -	# Determine whether the default compiler is a.out or elf
  1007         -	eval $set_cc_for_build
  1008         -	sed 's/^	//' << EOF >$dummy.c
  1009         -	#include <features.h>
  1010         -	#ifdef __ELF__
  1011         -	# ifdef __GLIBC__
  1012         -	#  if __GLIBC__ >= 2
  1013         -	LIBC=gnu
  1014         -	#  else
  1015         -	LIBC=gnulibc1
  1016         -	#  endif
  1017         -	# else
  1018         -	LIBC=gnulibc1
  1019         -	# endif
  1020         -	#else
  1021         -	#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
  1022         -	LIBC=gnu
  1023         -	#else
  1024         -	LIBC=gnuaout
  1025         -	#endif
  1026         -	#endif
  1027         -	#ifdef __dietlibc__
  1028         -	LIBC=dietlibc
  1029         -	#endif
  1030         -EOF
  1031         -	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
  1032         -	    /^LIBC/{
  1033         -		s: ::g
  1034         -		p
  1035         -	    }'`"
  1036         -	test x"${LIBC}" != x && {
  1037         -		echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
  1038         -		exit
  1039         -	}
  1040         -	test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
  1041         -	;;
  1042   1095       i*86:DYNIX/ptx:4*:*)
  1043   1096   	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
  1044   1097   	# earlier versions are messed up and put the nodename in both
  1045   1098   	# sysname and nodename.
  1046   1099   	echo i386-sequent-sysv4
  1047   1100   	exit ;;
  1048   1101       i*86:UNIX_SV:4.2MP:2.*)
  1049         -        # Unixware is an offshoot of SVR4, but it has its own version
  1050         -        # number series starting with 2...
  1051         -        # I am not positive that other SVR4 systems won't match this,
         1102  +	# Unixware is an offshoot of SVR4, but it has its own version
         1103  +	# number series starting with 2...
         1104  +	# I am not positive that other SVR4 systems won't match this,
  1052   1105   	# I just have to hope.  -- rms.
  1053         -        # Use sysv4.2uw... so that sysv4* matches it.
  1054         -	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
         1106  +	# Use sysv4.2uw... so that sysv4* matches it.
         1107  +	echo "$UNAME_MACHINE"-pc-sysv4.2uw"$UNAME_VERSION"
  1055   1108   	exit ;;
  1056   1109       i*86:OS/2:*:*)
  1057   1110   	# If we were able to find `uname', then EMX Unix compatibility
  1058   1111   	# is probably installed.
  1059         -	echo ${UNAME_MACHINE}-pc-os2-emx
         1112  +	echo "$UNAME_MACHINE"-pc-os2-emx
  1060   1113   	exit ;;
  1061   1114       i*86:XTS-300:*:STOP)
  1062         -	echo ${UNAME_MACHINE}-unknown-stop
         1115  +	echo "$UNAME_MACHINE"-unknown-stop
  1063   1116   	exit ;;
  1064   1117       i*86:atheos:*:*)
  1065         -	echo ${UNAME_MACHINE}-unknown-atheos
         1118  +	echo "$UNAME_MACHINE"-unknown-atheos
  1066   1119   	exit ;;
  1067   1120       i*86:syllable:*:*)
  1068         -	echo ${UNAME_MACHINE}-pc-syllable
         1121  +	echo "$UNAME_MACHINE"-pc-syllable
  1069   1122   	exit ;;
  1070         -    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
  1071         -	echo i386-unknown-lynxos${UNAME_RELEASE}
         1123  +    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
         1124  +	echo i386-unknown-lynxos"$UNAME_RELEASE"
  1072   1125   	exit ;;
  1073   1126       i*86:*DOS:*:*)
  1074         -	echo ${UNAME_MACHINE}-pc-msdosdjgpp
         1127  +	echo "$UNAME_MACHINE"-pc-msdosdjgpp
  1075   1128   	exit ;;
  1076         -    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
  1077         -	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
         1129  +    i*86:*:4.*:*)
         1130  +	UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'`
  1078   1131   	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
  1079         -		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
         1132  +		echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL"
  1080   1133   	else
  1081         -		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
         1134  +		echo "$UNAME_MACHINE"-pc-sysv"$UNAME_REL"
  1082   1135   	fi
  1083   1136   	exit ;;
  1084   1137       i*86:*:5:[678]*)
  1085         -    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
         1138  +	# UnixWare 7.x, OpenUNIX and OpenServer 6.
  1086   1139   	case `/bin/uname -X | grep "^Machine"` in
  1087   1140   	    *486*)	     UNAME_MACHINE=i486 ;;
  1088   1141   	    *Pentium)	     UNAME_MACHINE=i586 ;;
  1089   1142   	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
  1090   1143   	esac
  1091         -	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
         1144  +	echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}"
  1092   1145   	exit ;;
  1093   1146       i*86:*:3.2:*)
  1094   1147   	if test -f /usr/options/cb.name; then
  1095   1148   		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
  1096         -		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
         1149  +		echo "$UNAME_MACHINE"-pc-isc"$UNAME_REL"
  1097   1150   	elif /bin/uname -X 2>/dev/null >/dev/null ; then
  1098   1151   		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
  1099   1152   		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
  1100   1153   		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
  1101   1154   			&& UNAME_MACHINE=i586
  1102   1155   		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
  1103   1156   			&& UNAME_MACHINE=i686
  1104   1157   		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
  1105   1158   			&& UNAME_MACHINE=i686
  1106         -		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
         1159  +		echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL"
  1107   1160   	else
  1108         -		echo ${UNAME_MACHINE}-pc-sysv32
         1161  +		echo "$UNAME_MACHINE"-pc-sysv32
  1109   1162   	fi
  1110   1163   	exit ;;
  1111   1164       pc:*:*:*)
  1112   1165   	# Left here for compatibility:
  1113         -        # uname -m prints for DJGPP always 'pc', but it prints nothing about
  1114         -        # the processor, so we play safe by assuming i386.
  1115         -	echo i386-pc-msdosdjgpp
  1116         -        exit ;;
         1166  +	# uname -m prints for DJGPP always 'pc', but it prints nothing about
         1167  +	# the processor, so we play safe by assuming i586.
         1168  +	# Note: whatever this is, it MUST be the same as what config.sub
         1169  +	# prints for the "djgpp" host, or else GDB configure will decide that
         1170  +	# this is a cross-build.
         1171  +	echo i586-pc-msdosdjgpp
         1172  +	exit ;;
  1117   1173       Intel:Mach:3*:*)
  1118   1174   	echo i386-pc-mach3
  1119   1175   	exit ;;
  1120   1176       paragon:*:*:*)
  1121   1177   	echo i860-intel-osf1
  1122   1178   	exit ;;
  1123   1179       i860:*:4.*:*) # i860-SVR4
  1124   1180   	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
  1125         -	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
         1181  +	  echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4
  1126   1182   	else # Add other i860-SVR4 vendors below as they are discovered.
  1127         -	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
         1183  +	  echo i860-unknown-sysv"$UNAME_RELEASE"  # Unknown i860-SVR4
  1128   1184   	fi
  1129   1185   	exit ;;
  1130   1186       mini*:CTIX:SYS*5:*)
  1131   1187   	# "miniframe"
  1132   1188   	echo m68010-convergent-sysv
  1133   1189   	exit ;;
  1134   1190       mc68k:UNIX:SYSTEM5:3.51m)
................................................................................
  1140   1196       M68*:*:R3V[5678]*:*)
  1141   1197   	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
  1142   1198       3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
  1143   1199   	OS_REL=''
  1144   1200   	test -r /etc/.relid \
  1145   1201   	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
  1146   1202   	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
  1147         -	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
         1203  +	  && { echo i486-ncr-sysv4.3"$OS_REL"; exit; }
  1148   1204   	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
  1149         -	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
         1205  +	  && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;;
  1150   1206       3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
  1151         -        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
  1152         -          && { echo i486-ncr-sysv4; exit; } ;;
         1207  +	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
         1208  +	  && { echo i486-ncr-sysv4; exit; } ;;
         1209  +    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
         1210  +	OS_REL='.3'
         1211  +	test -r /etc/.relid \
         1212  +	    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
         1213  +	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
         1214  +	    && { echo i486-ncr-sysv4.3"$OS_REL"; exit; }
         1215  +	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
         1216  +	    && { echo i586-ncr-sysv4.3"$OS_REL"; exit; }
         1217  +	/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
         1218  +	    && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;;
  1153   1219       m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
  1154         -	echo m68k-unknown-lynxos${UNAME_RELEASE}
         1220  +	echo m68k-unknown-lynxos"$UNAME_RELEASE"
  1155   1221   	exit ;;
  1156   1222       mc68030:UNIX_System_V:4.*:*)
  1157   1223   	echo m68k-atari-sysv4
  1158   1224   	exit ;;
  1159   1225       TSUNAMI:LynxOS:2.*:*)
  1160         -	echo sparc-unknown-lynxos${UNAME_RELEASE}
         1226  +	echo sparc-unknown-lynxos"$UNAME_RELEASE"
  1161   1227   	exit ;;
  1162   1228       rs6000:LynxOS:2.*:*)
  1163         -	echo rs6000-unknown-lynxos${UNAME_RELEASE}
         1229  +	echo rs6000-unknown-lynxos"$UNAME_RELEASE"
  1164   1230   	exit ;;
  1165         -    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
  1166         -	echo powerpc-unknown-lynxos${UNAME_RELEASE}
         1231  +    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
         1232  +	echo powerpc-unknown-lynxos"$UNAME_RELEASE"
  1167   1233   	exit ;;
  1168   1234       SM[BE]S:UNIX_SV:*:*)
  1169         -	echo mips-dde-sysv${UNAME_RELEASE}
         1235  +	echo mips-dde-sysv"$UNAME_RELEASE"
  1170   1236   	exit ;;
  1171   1237       RM*:ReliantUNIX-*:*:*)
  1172   1238   	echo mips-sni-sysv4
  1173   1239   	exit ;;
  1174   1240       RM*:SINIX-*:*:*)
  1175   1241   	echo mips-sni-sysv4
  1176   1242   	exit ;;
  1177   1243       *:SINIX-*:*:*)
  1178   1244   	if uname -p 2>/dev/null >/dev/null ; then
  1179   1245   		UNAME_MACHINE=`(uname -p) 2>/dev/null`
  1180         -		echo ${UNAME_MACHINE}-sni-sysv4
         1246  +		echo "$UNAME_MACHINE"-sni-sysv4
  1181   1247   	else
  1182   1248   		echo ns32k-sni-sysv
  1183   1249   	fi
  1184   1250   	exit ;;
  1185         -    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
  1186         -                      # says <Richard.M.Bartel@ccMail.Census.GOV>
  1187         -        echo i586-unisys-sysv4
  1188         -        exit ;;
         1251  +    PENTIUM:*:4.0*:*)	# Unisys `ClearPath HMP IX 4000' SVR4/MP effort
         1252  +			# says <Richard.M.Bartel@ccMail.Census.GOV>
         1253  +	echo i586-unisys-sysv4
         1254  +	exit ;;
  1189   1255       *:UNIX_System_V:4*:FTX*)
  1190   1256   	# From Gerald Hewes <hewes@openmarket.com>.
  1191   1257   	# How about differentiating between stratus architectures? -djm
  1192   1258   	echo hppa1.1-stratus-sysv4
  1193   1259   	exit ;;
  1194   1260       *:*:*:FTX*)
  1195   1261   	# From seanf@swdc.stratus.com.
  1196   1262   	echo i860-stratus-sysv4
  1197   1263   	exit ;;
  1198   1264       i*86:VOS:*:*)
  1199   1265   	# From Paul.Green@stratus.com.
  1200         -	echo ${UNAME_MACHINE}-stratus-vos
         1266  +	echo "$UNAME_MACHINE"-stratus-vos
  1201   1267   	exit ;;
  1202   1268       *:VOS:*:*)
  1203   1269   	# From Paul.Green@stratus.com.
  1204   1270   	echo hppa1.1-stratus-vos
  1205   1271   	exit ;;
  1206   1272       mc68*:A/UX:*:*)
  1207         -	echo m68k-apple-aux${UNAME_RELEASE}
         1273  +	echo m68k-apple-aux"$UNAME_RELEASE"
  1208   1274   	exit ;;
  1209   1275       news*:NEWS-OS:6*:*)
  1210   1276   	echo mips-sony-newsos6
  1211   1277   	exit ;;
  1212   1278       R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
  1213   1279   	if [ -d /usr/nec ]; then
  1214         -	        echo mips-nec-sysv${UNAME_RELEASE}
         1280  +		echo mips-nec-sysv"$UNAME_RELEASE"
  1215   1281   	else
  1216         -	        echo mips-unknown-sysv${UNAME_RELEASE}
         1282  +		echo mips-unknown-sysv"$UNAME_RELEASE"
  1217   1283   	fi
  1218         -        exit ;;
         1284  +	exit ;;
  1219   1285       BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
  1220   1286   	echo powerpc-be-beos
  1221   1287   	exit ;;
  1222   1288       BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
  1223   1289   	echo powerpc-apple-beos
  1224   1290   	exit ;;
  1225   1291       BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
  1226   1292   	echo i586-pc-beos
  1227   1293   	exit ;;
         1294  +    BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
         1295  +	echo i586-pc-haiku
         1296  +	exit ;;
         1297  +    x86_64:Haiku:*:*)
         1298  +	echo x86_64-unknown-haiku
         1299  +	exit ;;
  1228   1300       SX-4:SUPER-UX:*:*)
  1229         -	echo sx4-nec-superux${UNAME_RELEASE}
         1301  +	echo sx4-nec-superux"$UNAME_RELEASE"
  1230   1302   	exit ;;
  1231   1303       SX-5:SUPER-UX:*:*)
  1232         -	echo sx5-nec-superux${UNAME_RELEASE}
         1304  +	echo sx5-nec-superux"$UNAME_RELEASE"
  1233   1305   	exit ;;
  1234   1306       SX-6:SUPER-UX:*:*)
  1235         -	echo sx6-nec-superux${UNAME_RELEASE}
         1307  +	echo sx6-nec-superux"$UNAME_RELEASE"
  1236   1308   	exit ;;
  1237   1309       SX-7:SUPER-UX:*:*)
  1238         -	echo sx7-nec-superux${UNAME_RELEASE}
         1310  +	echo sx7-nec-superux"$UNAME_RELEASE"
  1239   1311   	exit ;;
  1240   1312       SX-8:SUPER-UX:*:*)
  1241         -	echo sx8-nec-superux${UNAME_RELEASE}
         1313  +	echo sx8-nec-superux"$UNAME_RELEASE"
  1242   1314   	exit ;;
  1243   1315       SX-8R:SUPER-UX:*:*)
  1244         -	echo sx8r-nec-superux${UNAME_RELEASE}
         1316  +	echo sx8r-nec-superux"$UNAME_RELEASE"
         1317  +	exit ;;
         1318  +    SX-ACE:SUPER-UX:*:*)
         1319  +	echo sxace-nec-superux"$UNAME_RELEASE"
  1245   1320   	exit ;;
  1246   1321       Power*:Rhapsody:*:*)
  1247         -	echo powerpc-apple-rhapsody${UNAME_RELEASE}
         1322  +	echo powerpc-apple-rhapsody"$UNAME_RELEASE"
  1248   1323   	exit ;;
  1249   1324       *:Rhapsody:*:*)
  1250         -	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
         1325  +	echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE"
  1251   1326   	exit ;;
  1252   1327       *:Darwin:*:*)
  1253         -	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
         1328  +	UNAME_PROCESSOR=`uname -p`
  1254   1329   	case $UNAME_PROCESSOR in
  1255   1330   	    unknown) UNAME_PROCESSOR=powerpc ;;
  1256   1331   	esac
  1257         -	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
         1332  +	if command -v xcode-select > /dev/null 2> /dev/null && \
         1333  +		! xcode-select --print-path > /dev/null 2> /dev/null ; then
         1334  +	    # Avoid executing cc if there is no toolchain installed as
         1335  +	    # cc will be a stub that puts up a graphical alert
         1336  +	    # prompting the user to install developer tools.
         1337  +	    CC_FOR_BUILD=no_compiler_found
         1338  +	else
         1339  +	    set_cc_for_build
         1340  +	fi
         1341  +	if [ "$CC_FOR_BUILD" != no_compiler_found ]; then
         1342  +	    if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
         1343  +		   (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
         1344  +		   grep IS_64BIT_ARCH >/dev/null
         1345  +	    then
         1346  +		case $UNAME_PROCESSOR in
         1347  +		    i386) UNAME_PROCESSOR=x86_64 ;;
         1348  +		    powerpc) UNAME_PROCESSOR=powerpc64 ;;
         1349  +		esac
         1350  +	    fi
         1351  +	    # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc
         1352  +	    if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \
         1353  +		   (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
         1354  +		   grep IS_PPC >/dev/null
         1355  +	    then
         1356  +		UNAME_PROCESSOR=powerpc
         1357  +	    fi
         1358  +	elif test "$UNAME_PROCESSOR" = i386 ; then
         1359  +	    # uname -m returns i386 or x86_64
         1360  +	    UNAME_PROCESSOR=$UNAME_MACHINE
         1361  +	fi
         1362  +	echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE"
  1258   1363   	exit ;;
  1259   1364       *:procnto*:*:* | *:QNX:[0123456789]*:*)
  1260   1365   	UNAME_PROCESSOR=`uname -p`
  1261         -	if test "$UNAME_PROCESSOR" = "x86"; then
         1366  +	if test "$UNAME_PROCESSOR" = x86; then
  1262   1367   		UNAME_PROCESSOR=i386
  1263   1368   		UNAME_MACHINE=pc
  1264   1369   	fi
  1265         -	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
         1370  +	echo "$UNAME_PROCESSOR"-"$UNAME_MACHINE"-nto-qnx"$UNAME_RELEASE"
  1266   1371   	exit ;;
  1267   1372       *:QNX:*:4*)
  1268   1373   	echo i386-pc-qnx
  1269   1374   	exit ;;
  1270         -    NSE-?:NONSTOP_KERNEL:*:*)
  1271         -	echo nse-tandem-nsk${UNAME_RELEASE}
         1375  +    NEO-*:NONSTOP_KERNEL:*:*)
         1376  +	echo neo-tandem-nsk"$UNAME_RELEASE"
  1272   1377   	exit ;;
  1273         -    NSR-?:NONSTOP_KERNEL:*:*)
  1274         -	echo nsr-tandem-nsk${UNAME_RELEASE}
         1378  +    NSE-*:NONSTOP_KERNEL:*:*)
         1379  +	echo nse-tandem-nsk"$UNAME_RELEASE"
         1380  +	exit ;;
         1381  +    NSR-*:NONSTOP_KERNEL:*:*)
         1382  +	echo nsr-tandem-nsk"$UNAME_RELEASE"
         1383  +	exit ;;
         1384  +    NSV-*:NONSTOP_KERNEL:*:*)
         1385  +	echo nsv-tandem-nsk"$UNAME_RELEASE"
         1386  +	exit ;;
         1387  +    NSX-*:NONSTOP_KERNEL:*:*)
         1388  +	echo nsx-tandem-nsk"$UNAME_RELEASE"
  1275   1389   	exit ;;
  1276   1390       *:NonStop-UX:*:*)
  1277   1391   	echo mips-compaq-nonstopux
  1278   1392   	exit ;;
  1279   1393       BS2000:POSIX*:*:*)
  1280   1394   	echo bs2000-siemens-sysv
  1281   1395   	exit ;;
  1282   1396       DS/*:UNIX_System_V:*:*)
  1283         -	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
         1397  +	echo "$UNAME_MACHINE"-"$UNAME_SYSTEM"-"$UNAME_RELEASE"
  1284   1398   	exit ;;
  1285   1399       *:Plan9:*:*)
  1286   1400   	# "uname -m" is not consistent, so use $cputype instead. 386
  1287   1401   	# is converted to i386 for consistency with other x86
  1288   1402   	# operating systems.
  1289         -	if test "$cputype" = "386"; then
         1403  +	# shellcheck disable=SC2154
         1404  +	if test "$cputype" = 386; then
  1290   1405   	    UNAME_MACHINE=i386
  1291   1406   	else
  1292   1407   	    UNAME_MACHINE="$cputype"
  1293   1408   	fi
  1294         -	echo ${UNAME_MACHINE}-unknown-plan9
         1409  +	echo "$UNAME_MACHINE"-unknown-plan9
  1295   1410   	exit ;;
  1296   1411       *:TOPS-10:*:*)
  1297   1412   	echo pdp10-unknown-tops10
  1298   1413   	exit ;;
  1299   1414       *:TENEX:*:*)
  1300   1415   	echo pdp10-unknown-tenex
  1301   1416   	exit ;;
................................................................................
  1308   1423       *:TOPS-20:*:*)
  1309   1424   	echo pdp10-unknown-tops20
  1310   1425   	exit ;;
  1311   1426       *:ITS:*:*)
  1312   1427   	echo pdp10-unknown-its
  1313   1428   	exit ;;
  1314   1429       SEI:*:*:SEIUX)
  1315         -        echo mips-sei-seiux${UNAME_RELEASE}
         1430  +	echo mips-sei-seiux"$UNAME_RELEASE"
  1316   1431   	exit ;;
  1317   1432       *:DragonFly:*:*)
  1318         -	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
         1433  +	echo "$UNAME_MACHINE"-unknown-dragonfly"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`"
  1319   1434   	exit ;;
  1320   1435       *:*VMS:*:*)
  1321         -    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
  1322         -	case "${UNAME_MACHINE}" in
         1436  +	UNAME_MACHINE=`(uname -p) 2>/dev/null`
         1437  +	case "$UNAME_MACHINE" in
  1323   1438   	    A*) echo alpha-dec-vms ; exit ;;
  1324   1439   	    I*) echo ia64-dec-vms ; exit ;;
  1325   1440   	    V*) echo vax-dec-vms ; exit ;;
  1326   1441   	esac ;;
  1327   1442       *:XENIX:*:SysV)
  1328   1443   	echo i386-pc-xenix
  1329   1444   	exit ;;
  1330   1445       i*86:skyos:*:*)
  1331         -	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
         1446  +	echo "$UNAME_MACHINE"-pc-skyos"`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`"
  1332   1447   	exit ;;
  1333   1448       i*86:rdos:*:*)
  1334         -	echo ${UNAME_MACHINE}-pc-rdos
         1449  +	echo "$UNAME_MACHINE"-pc-rdos
         1450  +	exit ;;
         1451  +    i*86:AROS:*:*)
         1452  +	echo "$UNAME_MACHINE"-pc-aros
         1453  +	exit ;;
         1454  +    x86_64:VMkernel:*:*)
         1455  +	echo "$UNAME_MACHINE"-unknown-esx
         1456  +	exit ;;
         1457  +    amd64:Isilon\ OneFS:*:*)
         1458  +	echo x86_64-unknown-onefs
         1459  +	exit ;;
         1460  +    *:Unleashed:*:*)
         1461  +	echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE"
  1335   1462   	exit ;;
  1336   1463   esac
  1337   1464   
  1338         -#echo '(No uname command or uname output not recognized.)' 1>&2
  1339         -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
  1340         -
  1341         -eval $set_cc_for_build
  1342         -cat >$dummy.c <<EOF
         1465  +# No uname command or uname output not recognized.
         1466  +set_cc_for_build
         1467  +cat > "$dummy.c" <<EOF
  1343   1468   #ifdef _SEQUENT_
  1344         -# include <sys/types.h>
  1345         -# include <sys/utsname.h>
         1469  +#include <sys/types.h>
         1470  +#include <sys/utsname.h>
         1471  +#endif
         1472  +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
         1473  +#if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
         1474  +#include <signal.h>
         1475  +#if defined(_SIZE_T_) || defined(SIGLOST)
         1476  +#include <sys/utsname.h>
         1477  +#endif
         1478  +#endif
  1346   1479   #endif
  1347   1480   main ()
  1348   1481   {
  1349   1482   #if defined (sony)
  1350   1483   #if defined (MIPSEB)
  1351   1484     /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
  1352   1485        I don't know....  */
  1353   1486     printf ("mips-sony-bsd\n"); exit (0);
  1354   1487   #else
  1355   1488   #include <sys/param.h>
  1356   1489     printf ("m68k-sony-newsos%s\n",
  1357   1490   #ifdef NEWSOS4
  1358         -          "4"
         1491  +  "4"
  1359   1492   #else
  1360         -	  ""
         1493  +  ""
  1361   1494   #endif
  1362         -         ); exit (0);
         1495  +  ); exit (0);
  1363   1496   #endif
  1364   1497   #endif
  1365   1498   
  1366         -#if defined (__arm) && defined (__acorn) && defined (__unix)
  1367         -  printf ("arm-acorn-riscix\n"); exit (0);
  1368         -#endif
  1369         -
  1370         -#if defined (hp300) && !defined (hpux)
  1371         -  printf ("m68k-hp-bsd\n"); exit (0);
  1372         -#endif
  1373         -
  1374   1499   #if defined (NeXT)
  1375   1500   #if !defined (__ARCHITECTURE__)
  1376   1501   #define __ARCHITECTURE__ "m68k"
  1377   1502   #endif
  1378   1503     int version;
  1379   1504     version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
  1380   1505     if (version < 4)
................................................................................
  1406   1531   #endif
  1407   1532   #if defined (ns32000)
  1408   1533     printf ("ns32k-sequent-dynix\n"); exit (0);
  1409   1534   #endif
  1410   1535   #endif
  1411   1536   
  1412   1537   #if defined (_SEQUENT_)
  1413         -    struct utsname un;
         1538  +  struct utsname un;
  1414   1539   
  1415         -    uname(&un);
  1416         -
  1417         -    if (strncmp(un.version, "V2", 2) == 0) {
  1418         -	printf ("i386-sequent-ptx2\n"); exit (0);
  1419         -    }
  1420         -    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
  1421         -	printf ("i386-sequent-ptx1\n"); exit (0);
  1422         -    }
  1423         -    printf ("i386-sequent-ptx\n"); exit (0);
  1424         -
         1540  +  uname(&un);
         1541  +  if (strncmp(un.version, "V2", 2) == 0) {
         1542  +    printf ("i386-sequent-ptx2\n"); exit (0);
         1543  +  }
         1544  +  if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
         1545  +    printf ("i386-sequent-ptx1\n"); exit (0);
         1546  +  }
         1547  +  printf ("i386-sequent-ptx\n"); exit (0);
  1425   1548   #endif
  1426   1549   
  1427   1550   #if defined (vax)
  1428         -# if !defined (ultrix)
  1429         -#  include <sys/param.h>
  1430         -#  if defined (BSD)
  1431         -#   if BSD == 43
  1432         -      printf ("vax-dec-bsd4.3\n"); exit (0);
  1433         -#   else
  1434         -#    if BSD == 199006
  1435         -      printf ("vax-dec-bsd4.3reno\n"); exit (0);
  1436         -#    else
  1437         -      printf ("vax-dec-bsd\n"); exit (0);
  1438         -#    endif
  1439         -#   endif
  1440         -#  else
  1441         -    printf ("vax-dec-bsd\n"); exit (0);
  1442         -#  endif
  1443         -# else
  1444         -    printf ("vax-dec-ultrix\n"); exit (0);
  1445         -# endif
         1551  +#if !defined (ultrix)
         1552  +#include <sys/param.h>
         1553  +#if defined (BSD)
         1554  +#if BSD == 43
         1555  +  printf ("vax-dec-bsd4.3\n"); exit (0);
         1556  +#else
         1557  +#if BSD == 199006
         1558  +  printf ("vax-dec-bsd4.3reno\n"); exit (0);
         1559  +#else
         1560  +  printf ("vax-dec-bsd\n"); exit (0);
         1561  +#endif
         1562  +#endif
         1563  +#else
         1564  +  printf ("vax-dec-bsd\n"); exit (0);
         1565  +#endif
         1566  +#else
         1567  +#if defined(_SIZE_T_) || defined(SIGLOST)
         1568  +  struct utsname un;
         1569  +  uname (&un);
         1570  +  printf ("vax-dec-ultrix%s\n", un.release); exit (0);
         1571  +#else
         1572  +  printf ("vax-dec-ultrix\n"); exit (0);
         1573  +#endif
         1574  +#endif
         1575  +#endif
         1576  +#if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__)
         1577  +#if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__)
         1578  +#if defined(_SIZE_T_) || defined(SIGLOST)
         1579  +  struct utsname *un;
         1580  +  uname (&un);
         1581  +  printf ("mips-dec-ultrix%s\n", un.release); exit (0);
         1582  +#else
         1583  +  printf ("mips-dec-ultrix\n"); exit (0);
         1584  +#endif
         1585  +#endif
  1446   1586   #endif
  1447   1587   
  1448   1588   #if defined (alliant) && defined (i860)
  1449   1589     printf ("i860-alliant-bsd\n"); exit (0);
  1450   1590   #endif
  1451   1591   
  1452   1592     exit (1);
  1453   1593   }
  1454   1594   EOF
  1455   1595   
  1456         -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
         1596  +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`$dummy` &&
  1457   1597   	{ echo "$SYSTEM_NAME"; exit; }
  1458   1598   
  1459   1599   # Apollos put the system type in the environment.
         1600  +test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; }
  1460   1601   
  1461         -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
         1602  +echo "$0: unable to guess system type" >&2
  1462   1603   
  1463         -# Convex versions that predate uname can use getsysinfo(1)
         1604  +case "$UNAME_MACHINE:$UNAME_SYSTEM" in
         1605  +    mips:Linux | mips64:Linux)
         1606  +	# If we got here on MIPS GNU/Linux, output extra information.
         1607  +	cat >&2 <<EOF
  1464   1608   
  1465         -if [ -x /usr/convex/getsysinfo ]
  1466         -then
  1467         -    case `getsysinfo -f cpu_type` in
  1468         -    c1*)
  1469         -	echo c1-convex-bsd
  1470         -	exit ;;
  1471         -    c2*)
  1472         -	if getsysinfo -f scalar_acc
  1473         -	then echo c32-convex-bsd
  1474         -	else echo c2-convex-bsd
  1475         -	fi
  1476         -	exit ;;
  1477         -    c34*)
  1478         -	echo c34-convex-bsd
  1479         -	exit ;;
  1480         -    c38*)
  1481         -	echo c38-convex-bsd
  1482         -	exit ;;
  1483         -    c4*)
  1484         -	echo c4-convex-bsd
  1485         -	exit ;;
  1486         -    esac
  1487         -fi
         1609  +NOTE: MIPS GNU/Linux systems require a C compiler to fully recognize
         1610  +the system type. Please install a C compiler and try again.
         1611  +EOF
         1612  +	;;
         1613  +esac
  1488   1614   
  1489   1615   cat >&2 <<EOF
  1490         -$0: unable to guess system type
  1491   1616   
  1492         -This script, last modified $timestamp, has failed to recognize
  1493         -the operating system you are using. It is advised that you
  1494         -download the most up to date version of the config scripts from
         1617  +This script (version $timestamp), has failed to recognize the
         1618  +operating system you are using. If your script is old, overwrite *all*
         1619  +copies of config.guess and config.sub with the latest versions from:
  1495   1620   
  1496         -  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess
         1621  +  https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess
  1497   1622   and
  1498         -  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub
         1623  +  https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
  1499   1624   
  1500         -If the version you run ($0) is already up to date, please
  1501         -send the following data and any information you think might be
  1502         -pertinent to <config-patches@gnu.org> in order to provide the needed
  1503         -information to handle your system.
         1625  +If $0 has already been updated, send the following data and any
         1626  +information you think might be pertinent to config-patches@gnu.org to
         1627  +provide the necessary information to handle your system.
  1504   1628   
  1505   1629   config.guess timestamp = $timestamp
  1506   1630   
  1507   1631   uname -m = `(uname -m) 2>/dev/null || echo unknown`
  1508   1632   uname -r = `(uname -r) 2>/dev/null || echo unknown`
  1509   1633   uname -s = `(uname -s) 2>/dev/null || echo unknown`
  1510   1634   uname -v = `(uname -v) 2>/dev/null || echo unknown`
................................................................................
  1515   1639   hostinfo               = `(hostinfo) 2>/dev/null`
  1516   1640   /bin/universe          = `(/bin/universe) 2>/dev/null`
  1517   1641   /usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
  1518   1642   /bin/arch              = `(/bin/arch) 2>/dev/null`
  1519   1643   /usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
  1520   1644   /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
  1521   1645   
  1522         -UNAME_MACHINE = ${UNAME_MACHINE}
  1523         -UNAME_RELEASE = ${UNAME_RELEASE}
  1524         -UNAME_SYSTEM  = ${UNAME_SYSTEM}
  1525         -UNAME_VERSION = ${UNAME_VERSION}
         1646  +UNAME_MACHINE = "$UNAME_MACHINE"
         1647  +UNAME_RELEASE = "$UNAME_RELEASE"
         1648  +UNAME_SYSTEM  = "$UNAME_SYSTEM"
         1649  +UNAME_VERSION = "$UNAME_VERSION"
  1526   1650   EOF
  1527   1651   
  1528   1652   exit 1
  1529   1653   
  1530   1654   # Local variables:
  1531         -# eval: (add-hook 'write-file-hooks 'time-stamp)
         1655  +# eval: (add-hook 'before-save-hook 'time-stamp)
  1532   1656   # time-stamp-start: "timestamp='"
  1533   1657   # time-stamp-format: "%:y-%02m-%02d"
  1534   1658   # time-stamp-end: "'"
  1535   1659   # End:

Changes to config.sub.

     1      1   #! /bin/sh
     2      2   # Configuration validation subroutine script.
     3         -#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
     4         -#   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
     5         -#   Inc.
            3  +#   Copyright 1992-2019 Free Software Foundation, Inc.
     6      4   
     7         -timestamp='2007-06-28'
            5  +timestamp='2019-05-23'
     8      6   
     9         -# This file is (in principle) common to ALL GNU software.
    10         -# The presence of a machine in this file suggests that SOME GNU software
    11         -# can handle that machine.  It does not imply ALL GNU software can.
    12         -#
    13         -# This file is free software; you can redistribute it and/or modify
    14         -# it under the terms of the GNU General Public License as published by
    15         -# the Free Software Foundation; either version 2 of the License, or
            7  +# This file is free software; you can redistribute it and/or modify it
            8  +# under the terms of the GNU General Public License as published by
            9  +# the Free Software Foundation; either version 3 of the License, or
    16     10   # (at your option) any later version.
    17     11   #
    18         -# This program is distributed in the hope that it will be useful,
    19         -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    20         -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21         -# GNU General Public License for more details.
           12  +# This program is distributed in the hope that it will be useful, but
           13  +# WITHOUT ANY WARRANTY; without even the implied warranty of
           14  +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
           15  +# General Public License for more details.
    22     16   #
    23     17   # You should have received a copy of the GNU General Public License
    24         -# along with this program; if not, write to the Free Software
    25         -# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    26         -# 02110-1301, USA.
           18  +# along with this program; if not, see <https://www.gnu.org/licenses/>.
    27     19   #
    28     20   # As a special exception to the GNU General Public License, if you
    29     21   # distribute this file as part of a program that contains a
    30     22   # configuration script generated by Autoconf, you may include it under
    31         -# the same distribution terms that you use for the rest of that program.
           23  +# the same distribution terms that you use for the rest of that
           24  +# program.  This Exception is an additional permission under section 7
           25  +# of the GNU General Public License, version 3 ("GPLv3").
    32     26   
    33     27   
    34         -# Please send patches to <config-patches@gnu.org>.  Submit a context
    35         -# diff and a properly formatted ChangeLog entry.
           28  +# Please send patches to <config-patches@gnu.org>.
    36     29   #
    37     30   # Configuration subroutine to validate and canonicalize a configuration type.
    38     31   # Supply the specified configuration type as an argument.
    39     32   # If it is invalid, we print an error message on stderr and exit with code 1.
    40     33   # Otherwise, we print the canonical config type on stdout and succeed.
    41     34   
           35  +# You can get the latest version of this script from:
           36  +# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub
           37  +
    42     38   # This file is supposed to be the same for all GNU packages
    43     39   # and recognize all the CPU types, system types and aliases
    44     40   # that are meaningful with *any* GNU software.
    45     41   # Each package is responsible for reporting which valid configurations
    46     42   # it does not support.  The user should be able to distinguish
    47     43   # a failure to support a valid configuration from a meaningless
    48     44   # configuration.
................................................................................
    53     49   # or in some cases, the newer four-part form:
    54     50   #	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
    55     51   # It is wrong to echo any other type of specification.
    56     52   
    57     53   me=`echo "$0" | sed -e 's,.*/,,'`
    58     54   
    59     55   usage="\
    60         -Usage: $0 [OPTION] CPU-MFR-OPSYS
    61         -       $0 [OPTION] ALIAS
           56  +Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS
    62     57   
    63     58   Canonicalize a configuration name.
    64     59   
    65         -Operation modes:
           60  +Options:
    66     61     -h, --help         print this help, then exit
    67     62     -t, --time-stamp   print date of last modification, then exit
    68     63     -v, --version      print version number, then exit
    69     64   
    70     65   Report bugs and patches to <config-patches@gnu.org>."
    71     66   
    72     67   version="\
    73     68   GNU config.sub ($timestamp)
    74     69   
    75         -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    76         -Free Software Foundation, Inc.
           70  +Copyright 1992-2019 Free Software Foundation, Inc.
    77     71   
    78     72   This is free software; see the source for copying conditions.  There is NO
    79     73   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
    80     74   
    81     75   help="
    82     76   Try \`$me --help' for more information."
    83     77   
................................................................................
    91     85       --help | --h* | -h )
    92     86          echo "$usage"; exit ;;
    93     87       -- )     # Stop option processing
    94     88          shift; break ;;
    95     89       - )	# Use stdin as input.
    96     90          break ;;
    97     91       -* )
    98         -       echo "$me: invalid option $1$help"
           92  +       echo "$me: invalid option $1$help" >&2
    99     93          exit 1 ;;
   100     94   
   101     95       *local*)
   102     96          # First pass through any local machine types.
   103         -       echo $1
           97  +       echo "$1"
   104     98          exit ;;
   105     99   
   106    100       * )
   107    101          break ;;
   108    102     esac
   109    103   done
   110    104   
................................................................................
   112    106    0) echo "$me: missing argument$help" >&2
   113    107       exit 1;;
   114    108    1) ;;
   115    109    *) echo "$me: too many arguments$help" >&2
   116    110       exit 1;;
   117    111   esac
   118    112   
   119         -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
   120         -# Here we must recognize all the valid KERNEL-OS combinations.
   121         -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
   122         -case $maybe_os in
   123         -  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
   124         -  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
   125         -  storm-chaos* | os2-emx* | rtmk-nova*)
   126         -    os=-$maybe_os
   127         -    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
   128         -    ;;
   129         -  *)
   130         -    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
   131         -    if [ $basic_machine != $1 ]
   132         -    then os=`echo $1 | sed 's/.*-/-/'`
   133         -    else os=; fi
   134         -    ;;
   135         -esac
   136         -
   137         -### Let's recognize common machines as not being operating systems so
   138         -### that things like config.sub decstation-3100 work.  We also
   139         -### recognize some manufacturers as not being operating systems, so we
   140         -### can provide default operating systems below.
   141         -case $os in
   142         -	-sun*os*)
   143         -		# Prevent following clause from handling this invalid input.
   144         -		;;
   145         -	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
   146         -	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
   147         -	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
   148         -	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
   149         -	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
   150         -	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
   151         -	-apple | -axis | -knuth | -cray)
   152         -		os=
   153         -		basic_machine=$1
   154         -		;;
   155         -	-sim | -cisco | -oki | -wec | -winbond)
   156         -		os=
   157         -		basic_machine=$1
   158         -		;;
   159         -	-scout)
   160         -		;;
   161         -	-wrs)
   162         -		os=-vxworks
   163         -		basic_machine=$1
   164         -		;;
   165         -	-chorusos*)
   166         -		os=-chorusos
   167         -		basic_machine=$1
   168         -		;;
   169         - 	-chorusrdb)
   170         - 		os=-chorusrdb
   171         -		basic_machine=$1
   172         - 		;;
   173         -	-hiux*)
   174         -		os=-hiuxwe2
   175         -		;;
   176         -	-sco6)
   177         -		os=-sco5v6
   178         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   179         -		;;
   180         -	-sco5)
   181         -		os=-sco3.2v5
   182         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   183         -		;;
   184         -	-sco4)
   185         -		os=-sco3.2v4
   186         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   187         -		;;
   188         -	-sco3.2.[4-9]*)
   189         -		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
   190         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   191         -		;;
   192         -	-sco3.2v[4-9]*)
   193         -		# Don't forget version if it is 3.2v4 or newer.
   194         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   195         -		;;
   196         -	-sco5v6*)
   197         -		# Don't forget version if it is 3.2v4 or newer.
   198         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   199         -		;;
   200         -	-sco*)
   201         -		os=-sco3.2v2
   202         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   203         -		;;
   204         -	-udk*)
   205         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   206         -		;;
   207         -	-isc)
   208         -		os=-isc2.2
   209         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   210         -		;;
   211         -	-clix*)
   212         -		basic_machine=clipper-intergraph
   213         -		;;
   214         -	-isc*)
   215         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
   216         -		;;
   217         -	-lynx*)
   218         -		os=-lynxos
   219         -		;;
   220         -	-ptx*)
   221         -		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
   222         -		;;
   223         -	-windowsnt*)
   224         -		os=`echo $os | sed -e 's/windowsnt/winnt/'`
   225         -		;;
   226         -	-psos*)
   227         -		os=-psos
   228         -		;;
   229         -	-mint | -mint[0-9]*)
   230         -		basic_machine=m68k-atari
   231         -		os=-mint
          113  +# Split fields of configuration type
          114  +# shellcheck disable=SC2162
          115  +IFS="-" read field1 field2 field3 field4 <<EOF
          116  +$1
          117  +EOF
          118  +
          119  +# Separate into logical components for further validation
          120  +case $1 in
          121  +	*-*-*-*-*)
          122  +		echo Invalid configuration \`"$1"\': more than four components >&2
          123  +		exit 1
          124  +		;;
          125  +	*-*-*-*)
          126  +		basic_machine=$field1-$field2
          127  +		os=$field3-$field4
          128  +		;;
          129  +	*-*-*)
          130  +		# Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two
          131  +		# parts
          132  +		maybe_os=$field2-$field3
          133  +		case $maybe_os in
          134  +			nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc \
          135  +			| linux-newlib* | linux-musl* | linux-uclibc* | uclinux-uclibc* \
          136  +			| uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \
          137  +			| netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \
          138  +			| storm-chaos* | os2-emx* | rtmk-nova*)
          139  +				basic_machine=$field1
          140  +				os=$maybe_os
          141  +				;;
          142  +			android-linux)
          143  +				basic_machine=$field1-unknown
          144  +				os=linux-android
          145  +				;;
          146  +			*)
          147  +				basic_machine=$field1-$field2
          148  +				os=$field3
          149  +				;;
          150  +		esac
          151  +		;;
          152  +	*-*)
          153  +		# A lone config we happen to match not fitting any pattern
          154  +		case $field1-$field2 in
          155  +			decstation-3100)
          156  +				basic_machine=mips-dec
          157  +				os=
          158  +				;;
          159  +			*-*)
          160  +				# Second component is usually, but not always the OS
          161  +				case $field2 in
          162  +					# Prevent following clause from handling this valid os
          163  +					sun*os*)
          164  +						basic_machine=$field1
          165  +						os=$field2
          166  +						;;
          167  +					# Manufacturers
          168  +					dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \
          169  +					| att* | 7300* | 3300* | delta* | motorola* | sun[234]* \
          170  +					| unicom* | ibm* | next | hp | isi* | apollo | altos* \
          171  +					| convergent* | ncr* | news | 32* | 3600* | 3100* \
          172  +					| hitachi* | c[123]* | convex* | sun | crds | omron* | dg \
          173  +					| ultra | tti* | harris | dolphin | highlevel | gould \
          174  +					| cbm | ns | masscomp | apple | axis | knuth | cray \
          175  +					| microblaze* | sim | cisco \
          176  +					| oki | wec | wrs | winbond)
          177  +						basic_machine=$field1-$field2
          178  +						os=
          179  +						;;
          180  +					*)
          181  +						basic_machine=$field1
          182  +						os=$field2
          183  +						;;
          184  +				esac
          185  +			;;
          186  +		esac
          187  +		;;
          188  +	*)
          189  +		# Convert single-component short-hands not valid as part of
          190  +		# multi-component configurations.
          191  +		case $field1 in
          192  +			386bsd)
          193  +				basic_machine=i386-pc
          194  +				os=bsd
          195  +				;;
          196  +			a29khif)
          197  +				basic_machine=a29k-amd
          198  +				os=udi
          199  +				;;
          200  +			adobe68k)
          201  +				basic_machine=m68010-adobe
          202  +				os=scout
          203  +				;;
          204  +			alliant)
          205  +				basic_machine=fx80-alliant
          206  +				os=
          207  +				;;
          208  +			altos | altos3068)
          209  +				basic_machine=m68k-altos
          210  +				os=
          211  +				;;
          212  +			am29k)
          213  +				basic_machine=a29k-none
          214  +				os=bsd
          215  +				;;
          216  +			amdahl)
          217  +				basic_machine=580-amdahl
          218  +				os=sysv
          219  +				;;
          220  +			amiga)
          221  +				basic_machine=m68k-unknown
          222  +				os=
          223  +				;;
          224  +			amigaos | amigados)
          225  +				basic_machine=m68k-unknown
          226  +				os=amigaos
          227  +				;;
          228  +			amigaunix | amix)
          229  +				basic_machine=m68k-unknown
          230  +				os=sysv4
          231  +				;;
          232  +			apollo68)
          233  +				basic_machine=m68k-apollo
          234  +				os=sysv
          235  +				;;
          236  +			apollo68bsd)
          237  +				basic_machine=m68k-apollo
          238  +				os=bsd
          239  +				;;
          240  +			aros)
          241  +				basic_machine=i386-pc
          242  +				os=aros
          243  +				;;
          244  +			aux)
          245  +				basic_machine=m68k-apple
          246  +				os=aux
          247  +				;;
          248  +			balance)
          249  +				basic_machine=ns32k-sequent
          250  +				os=dynix
          251  +				;;
          252  +			blackfin)
          253  +				basic_machine=bfin-unknown
          254  +				os=linux
          255  +				;;
          256  +			cegcc)
          257  +				basic_machine=arm-unknown
          258  +				os=cegcc
          259  +				;;
          260  +			convex-c1)
          261  +				basic_machine=c1-convex
          262  +				os=bsd
          263  +				;;
          264  +			convex-c2)
          265  +				basic_machine=c2-convex
          266  +				os=bsd
          267  +				;;
          268  +			convex-c32)
          269  +				basic_machine=c32-convex
          270  +				os=bsd
          271  +				;;
          272  +			convex-c34)
          273  +				basic_machine=c34-convex
          274  +				os=bsd
          275  +				;;
          276  +			convex-c38)
          277  +				basic_machine=c38-convex
          278  +				os=bsd
          279  +				;;
          280  +			cray)
          281  +				basic_machine=j90-cray
          282  +				os=unicos
          283  +				;;
          284  +			crds | unos)
          285  +				basic_machine=m68k-crds
          286  +				os=
          287  +				;;
          288  +			da30)
          289  +				basic_machine=m68k-da30
          290  +				os=
          291  +				;;
          292  +			decstation | pmax | pmin | dec3100 | decstatn)
          293  +				basic_machine=mips-dec
          294  +				os=
          295  +				;;
          296  +			delta88)
          297  +				basic_machine=m88k-motorola
          298  +				os=sysv3
          299  +				;;
          300  +			dicos)
          301  +				basic_machine=i686-pc
          302  +				os=dicos
          303  +				;;
          304  +			djgpp)
          305  +				basic_machine=i586-pc
          306  +				os=msdosdjgpp
          307  +				;;
          308  +			ebmon29k)
          309  +				basic_machine=a29k-amd
          310  +				os=ebmon
          311  +				;;
          312  +			es1800 | OSE68k | ose68k | ose | OSE)
          313  +				basic_machine=m68k-ericsson
          314  +				os=ose
          315  +				;;
          316  +			gmicro)
          317  +				basic_machine=tron-gmicro
          318  +				os=sysv
          319  +				;;
          320  +			go32)
          321  +				basic_machine=i386-pc
          322  +				os=go32
          323  +				;;
          324  +			h8300hms)
          325  +				basic_machine=h8300-hitachi
          326  +				os=hms
          327  +				;;
          328  +			h8300xray)
          329  +				basic_machine=h8300-hitachi
          330  +				os=xray
          331  +				;;
          332  +			h8500hms)
          333  +				basic_machine=h8500-hitachi
          334  +				os=hms
          335  +				;;
          336  +			harris)
          337  +				basic_machine=m88k-harris
          338  +				os=sysv3
          339  +				;;
          340  +			hp300)
          341  +				basic_machine=m68k-hp
          342  +				;;
          343  +			hp300bsd)
          344  +				basic_machine=m68k-hp
          345  +				os=bsd
          346  +				;;
          347  +			hp300hpux)
          348  +				basic_machine=m68k-hp
          349  +				os=hpux
          350  +				;;
          351  +			hppaosf)
          352  +				basic_machine=hppa1.1-hp
          353  +				os=osf
          354  +				;;
          355  +			hppro)
          356  +				basic_machine=hppa1.1-hp
          357  +				os=proelf
          358  +				;;
          359  +			i386mach)
          360  +				basic_machine=i386-mach
          361  +				os=mach
          362  +				;;
          363  +			vsta)
          364  +				basic_machine=i386-pc
          365  +				os=vsta
          366  +				;;
          367  +			isi68 | isi)
          368  +				basic_machine=m68k-isi
          369  +				os=sysv
          370  +				;;
          371  +			m68knommu)
          372  +				basic_machine=m68k-unknown
          373  +				os=linux
          374  +				;;
          375  +			magnum | m3230)
          376  +				basic_machine=mips-mips
          377  +				os=sysv
          378  +				;;
          379  +			merlin)
          380  +				basic_machine=ns32k-utek
          381  +				os=sysv
          382  +				;;
          383  +			mingw64)
          384  +				basic_machine=x86_64-pc
          385  +				os=mingw64
          386  +				;;
          387  +			mingw32)
          388  +				basic_machine=i686-pc
          389  +				os=mingw32
          390  +				;;
          391  +			mingw32ce)
          392  +				basic_machine=arm-unknown
          393  +				os=mingw32ce
          394  +				;;
          395  +			monitor)
          396  +				basic_machine=m68k-rom68k
          397  +				os=coff
          398  +				;;
          399  +			morphos)
          400  +				basic_machine=powerpc-unknown
          401  +				os=morphos
          402  +				;;
          403  +			moxiebox)
          404  +				basic_machine=moxie-unknown
          405  +				os=moxiebox
          406  +				;;
          407  +			msdos)
          408  +				basic_machine=i386-pc
          409  +				os=msdos
          410  +				;;
          411  +			msys)
          412  +				basic_machine=i686-pc
          413  +				os=msys
          414  +				;;
          415  +			mvs)
          416  +				basic_machine=i370-ibm
          417  +				os=mvs
          418  +				;;
          419  +			nacl)
          420  +				basic_machine=le32-unknown
          421  +				os=nacl
          422  +				;;
          423  +			ncr3000)
          424  +				basic_machine=i486-ncr
          425  +				os=sysv4
          426  +				;;
          427  +			netbsd386)
          428  +				basic_machine=i386-pc
          429  +				os=netbsd
          430  +				;;
          431  +			netwinder)
          432  +				basic_machine=armv4l-rebel
          433  +				os=linux
          434  +				;;
          435  +			news | news700 | news800 | news900)
          436  +				basic_machine=m68k-sony
          437  +				os=newsos
          438  +				;;
          439  +			news1000)
          440  +				basic_machine=m68030-sony
          441  +				os=newsos
          442  +				;;
          443  +			necv70)
          444  +				basic_machine=v70-nec
          445  +				os=sysv
          446  +				;;
          447  +			nh3000)
          448  +				basic_machine=m68k-harris
          449  +				os=cxux
          450  +				;;
          451  +			nh[45]000)
          452  +				basic_machine=m88k-harris
          453  +				os=cxux
          454  +				;;
          455  +			nindy960)
          456  +				basic_machine=i960-intel
          457  +				os=nindy
          458  +				;;
          459  +			mon960)
          460  +				basic_machine=i960-intel
          461  +				os=mon960
          462  +				;;
          463  +			nonstopux)
          464  +				basic_machine=mips-compaq
          465  +				os=nonstopux
          466  +				;;
          467  +			os400)
          468  +				basic_machine=powerpc-ibm
          469  +				os=os400
          470  +				;;
          471  +			OSE68000 | ose68000)
          472  +				basic_machine=m68000-ericsson
          473  +				os=ose
          474  +				;;
          475  +			os68k)
          476  +				basic_machine=m68k-none
          477  +				os=os68k
          478  +				;;
          479  +			paragon)
          480  +				basic_machine=i860-intel
          481  +				os=osf
          482  +				;;
          483  +			parisc)
          484  +				basic_machine=hppa-unknown
          485  +				os=linux
          486  +				;;
          487  +			pw32)
          488  +				basic_machine=i586-unknown
          489  +				os=pw32
          490  +				;;
          491  +			rdos | rdos64)
          492  +				basic_machine=x86_64-pc
          493  +				os=rdos
          494  +				;;
          495  +			rdos32)
          496  +				basic_machine=i386-pc
          497  +				os=rdos
          498  +				;;
          499  +			rom68k)
          500  +				basic_machine=m68k-rom68k
          501  +				os=coff
          502  +				;;
          503  +			sa29200)
          504  +				basic_machine=a29k-amd
          505  +				os=udi
          506  +				;;
          507  +			sei)
          508  +				basic_machine=mips-sei
          509  +				os=seiux
          510  +				;;
          511  +			sequent)
          512  +				basic_machine=i386-sequent
          513  +				os=
          514  +				;;
          515  +			sps7)
          516  +				basic_machine=m68k-bull
          517  +				os=sysv2
          518  +				;;
          519  +			st2000)
          520  +				basic_machine=m68k-tandem
          521  +				os=
          522  +				;;
          523  +			stratus)
          524  +				basic_machine=i860-stratus
          525  +				os=sysv4
          526  +				;;
          527  +			sun2)
          528  +				basic_machine=m68000-sun
          529  +				os=
          530  +				;;
          531  +			sun2os3)
          532  +				basic_machine=m68000-sun
          533  +				os=sunos3
          534  +				;;
          535  +			sun2os4)
          536  +				basic_machine=m68000-sun
          537  +				os=sunos4
          538  +				;;
          539  +			sun3)
          540  +				basic_machine=m68k-sun
          541  +				os=
          542  +				;;
          543  +			sun3os3)
          544  +				basic_machine=m68k-sun
          545  +				os=sunos3
          546  +				;;
          547  +			sun3os4)
          548  +				basic_machine=m68k-sun
          549  +				os=sunos4
          550  +				;;
          551  +			sun4)
          552  +				basic_machine=sparc-sun
          553  +				os=
          554  +				;;
          555  +			sun4os3)
          556  +				basic_machine=sparc-sun
          557  +				os=sunos3
          558  +				;;
          559  +			sun4os4)
          560  +				basic_machine=sparc-sun
          561  +				os=sunos4
          562  +				;;
          563  +			sun4sol2)
          564  +				basic_machine=sparc-sun
          565  +				os=solaris2
          566  +				;;
          567  +			sun386 | sun386i | roadrunner)
          568  +				basic_machine=i386-sun
          569  +				os=
          570  +				;;
          571  +			sv1)
          572  +				basic_machine=sv1-cray
          573  +				os=unicos
          574  +				;;
          575  +			symmetry)
          576  +				basic_machine=i386-sequent
          577  +				os=dynix
          578  +				;;
          579  +			t3e)
          580  +				basic_machine=alphaev5-cray
          581  +				os=unicos
          582  +				;;
          583  +			t90)
          584  +				basic_machine=t90-cray
          585  +				os=unicos
          586  +				;;
          587  +			toad1)
          588  +				basic_machine=pdp10-xkl
          589  +				os=tops20
          590  +				;;
          591  +			tpf)
          592  +				basic_machine=s390x-ibm
          593  +				os=tpf
          594  +				;;
          595  +			udi29k)
          596  +				basic_machine=a29k-amd
          597  +				os=udi
          598  +				;;
          599  +			ultra3)
          600  +				basic_machine=a29k-nyu
          601  +				os=sym1
          602  +				;;
          603  +			v810 | necv810)
          604  +				basic_machine=v810-nec
          605  +				os=none
          606  +				;;
          607  +			vaxv)
          608  +				basic_machine=vax-dec
          609  +				os=sysv
          610  +				;;
          611  +			vms)
          612  +				basic_machine=vax-dec
          613  +				os=vms
          614  +				;;
          615  +			vxworks960)
          616  +				basic_machine=i960-wrs
          617  +				os=vxworks
          618  +				;;
          619  +			vxworks68)
          620  +				basic_machine=m68k-wrs
          621  +				os=vxworks
          622  +				;;
          623  +			vxworks29k)
          624  +				basic_machine=a29k-wrs
          625  +				os=vxworks
          626  +				;;
          627  +			xbox)
          628  +				basic_machine=i686-pc
          629  +				os=mingw32
          630  +				;;
          631  +			ymp)
          632  +				basic_machine=ymp-cray
          633  +				os=unicos
          634  +				;;
          635  +			*)
          636  +				basic_machine=$1
          637  +				os=
          638  +				;;
          639  +		esac
   232    640   		;;
   233    641   esac
   234    642   
   235         -# Decode aliases for certain CPU-COMPANY combinations.
          643  +# Decode 1-component or ad-hoc basic machines
   236    644   case $basic_machine in
   237         -	# Recognize the basic CPU types without company name.
   238         -	# Some are omitted here because they have special meanings below.
   239         -	1750a | 580 \
   240         -	| a29k \
   241         -	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
   242         -	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
   243         -	| am33_2.0 \
   244         -	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
   245         -	| bfin \
   246         -	| c4x | clipper \
   247         -	| d10v | d30v | dlx | dsp16xx | dvp \
   248         -	| fido | fr30 | frv \
   249         -	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
   250         -	| i370 | i860 | i960 | ia64 \
   251         -	| ip2k | iq2000 \
   252         -	| m32c | m32r | m32rle | m68000 | m68k | m88k \
   253         -	| maxq | mb | microblaze | mcore | mep \
   254         -	| mips | mipsbe | mipseb | mipsel | mipsle \
   255         -	| mips16 \
   256         -	| mips64 | mips64el \
   257         -	| mips64vr | mips64vrel \
   258         -	| mips64orion | mips64orionel \
   259         -	| mips64vr4100 | mips64vr4100el \
   260         -	| mips64vr4300 | mips64vr4300el \
   261         -	| mips64vr5000 | mips64vr5000el \
   262         -	| mips64vr5900 | mips64vr5900el \
   263         -	| mipsisa32 | mipsisa32el \
   264         -	| mipsisa32r2 | mipsisa32r2el \
   265         -	| mipsisa64 | mipsisa64el \
   266         -	| mipsisa64r2 | mipsisa64r2el \
   267         -	| mipsisa64sb1 | mipsisa64sb1el \
   268         -	| mipsisa64sr71k | mipsisa64sr71kel \
   269         -	| mipstx39 | mipstx39el \
   270         -	| mn10200 | mn10300 \
   271         -	| mt \
   272         -	| msp430 \
   273         -	| nios | nios2 \
   274         -	| ns16k | ns32k \
   275         -	| or32 \
   276         -	| pdp10 | pdp11 | pj | pjl \
   277         -	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
   278         -	| pyramid \
   279         -	| score \
   280         -	| sh | sh[1234] | sh[24]a | sh[24]a*eb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
   281         -	| sh64 | sh64le \
   282         -	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
   283         -	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
   284         -	| spu | strongarm \
   285         -	| tahoe | thumb | tic4x | tic80 | tron \
   286         -	| v850 | v850e \
   287         -	| we32k \
   288         -	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
   289         -	| z8k)
   290         -		basic_machine=$basic_machine-unknown
   291         -		;;
   292         -	m6811 | m68hc11 | m6812 | m68hc12)
   293         -		# Motorola 68HC11/12.
   294         -		basic_machine=$basic_machine-unknown
   295         -		os=-none
   296         -		;;
   297         -	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
   298         -		;;
   299         -	ms1)
   300         -		basic_machine=mt-unknown
   301         -		;;
   302         -
          645  +	# Here we handle the default manufacturer of certain CPU types.  It is in
          646  +	# some cases the only manufacturer, in others, it is the most popular.
          647  +	w89k)
          648  +		cpu=hppa1.1
          649  +		vendor=winbond
          650  +		;;
          651  +	op50n)
          652  +		cpu=hppa1.1
          653  +		vendor=oki
          654  +		;;
          655  +	op60c)
          656  +		cpu=hppa1.1
          657  +		vendor=oki
          658  +		;;
          659  +	ibm*)
          660  +		cpu=i370
          661  +		vendor=ibm
          662  +		;;
          663  +	orion105)
          664  +		cpu=clipper
          665  +		vendor=highlevel
          666  +		;;
          667  +	mac | mpw | mac-mpw)
          668  +		cpu=m68k
          669  +		vendor=apple
          670  +		;;
          671  +	pmac | pmac-mpw)
          672  +		cpu=powerpc
          673  +		vendor=apple
          674  +		;;
          675  +
          676  +	# Recognize the various machine names and aliases which stand
          677  +	# for a CPU type and a company and sometimes even an OS.
          678  +	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
          679  +		cpu=m68000
          680  +		vendor=att
          681  +		;;
          682  +	3b*)
          683  +		cpu=we32k
          684  +		vendor=att
          685  +		;;
          686  +	bluegene*)
          687  +		cpu=powerpc
          688  +		vendor=ibm
          689  +		os=cnk
          690  +		;;
          691  +	decsystem10* | dec10*)
          692  +		cpu=pdp10
          693  +		vendor=dec
          694  +		os=tops10
          695  +		;;
          696  +	decsystem20* | dec20*)
          697  +		cpu=pdp10
          698  +		vendor=dec
          699  +		os=tops20
          700  +		;;
          701  +	delta | 3300 | motorola-3300 | motorola-delta \
          702  +	      | 3300-motorola | delta-motorola)
          703  +		cpu=m68k
          704  +		vendor=motorola
          705  +		;;
          706  +	dpx2*)
          707  +		cpu=m68k
          708  +		vendor=bull
          709  +		os=sysv3
          710  +		;;
          711  +	encore | umax | mmax)
          712  +		cpu=ns32k
          713  +		vendor=encore
          714  +		;;
          715  +	elxsi)
          716  +		cpu=elxsi
          717  +		vendor=elxsi
          718  +		os=${os:-bsd}
          719  +		;;
          720  +	fx2800)
          721  +		cpu=i860
          722  +		vendor=alliant
          723  +		;;
          724  +	genix)
          725  +		cpu=ns32k
          726  +		vendor=ns
          727  +		;;
          728  +	h3050r* | hiux*)
          729  +		cpu=hppa1.1
          730  +		vendor=hitachi
          731  +		os=hiuxwe2
          732  +		;;
          733  +	hp3k9[0-9][0-9] | hp9[0-9][0-9])
          734  +		cpu=hppa1.0
          735  +		vendor=hp
          736  +		;;
          737  +	hp9k2[0-9][0-9] | hp9k31[0-9])
          738  +		cpu=m68000
          739  +		vendor=hp
          740  +		;;
          741  +	hp9k3[2-9][0-9])
          742  +		cpu=m68k
          743  +		vendor=hp
          744  +		;;
          745  +	hp9k6[0-9][0-9] | hp6[0-9][0-9])
          746  +		cpu=hppa1.0
          747  +		vendor=hp
          748  +		;;
          749  +	hp9k7[0-79][0-9] | hp7[0-79][0-9])
          750  +		cpu=hppa1.1
          751  +		vendor=hp
          752  +		;;
          753  +	hp9k78[0-9] | hp78[0-9])
          754  +		# FIXME: really hppa2.0-hp
          755  +		cpu=hppa1.1
          756  +		vendor=hp
          757  +		;;
          758  +	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
          759  +		# FIXME: really hppa2.0-hp
          760  +		cpu=hppa1.1
          761  +		vendor=hp
          762  +		;;
          763  +	hp9k8[0-9][13679] | hp8[0-9][13679])
          764  +		cpu=hppa1.1
          765  +		vendor=hp
          766  +		;;
          767  +	hp9k8[0-9][0-9] | hp8[0-9][0-9])
          768  +		cpu=hppa1.0
          769  +		vendor=hp
          770  +		;;
          771  +	i*86v32)
          772  +		cpu=`echo "$1" | sed -e 's/86.*/86/'`
          773  +		vendor=pc
          774  +		os=sysv32
          775  +		;;
          776  +	i*86v4*)
          777  +		cpu=`echo "$1" | sed -e 's/86.*/86/'`
          778  +		vendor=pc
          779  +		os=sysv4
          780  +		;;
          781  +	i*86v)
          782  +		cpu=`echo "$1" | sed -e 's/86.*/86/'`
          783  +		vendor=pc
          784  +		os=sysv
          785  +		;;
          786  +	i*86sol2)
          787  +		cpu=`echo "$1" | sed -e 's/86.*/86/'`
          788  +		vendor=pc
          789  +		os=solaris2
          790  +		;;
          791  +	j90 | j90-cray)
          792  +		cpu=j90
          793  +		vendor=cray
          794  +		os=${os:-unicos}
          795  +		;;
          796  +	iris | iris4d)
          797  +		cpu=mips
          798  +		vendor=sgi
          799  +		case $os in
          800  +		    irix*)
          801  +			;;
          802  +		    *)
          803  +			os=irix4
          804  +			;;
          805  +		esac
          806  +		;;
          807  +	miniframe)
          808  +		cpu=m68000
          809  +		vendor=convergent
          810  +		;;
          811  +	*mint | mint[0-9]* | *MiNT | *MiNT[0-9]*)
          812  +		cpu=m68k
          813  +		vendor=atari
          814  +		os=mint
          815  +		;;
          816  +	news-3600 | risc-news)
          817  +		cpu=mips
          818  +		vendor=sony
          819  +		os=newsos
          820  +		;;
          821  +	next | m*-next)
          822  +		cpu=m68k
          823  +		vendor=next
          824  +		case $os in
          825  +		    openstep*)
          826  +		        ;;
          827  +		    nextstep*)
          828  +			;;
          829  +		    ns2*)
          830  +		      os=nextstep2
          831  +			;;
          832  +		    *)
          833  +		      os=nextstep3
          834  +			;;
          835  +		esac
          836  +		;;
          837  +	np1)
          838  +		cpu=np1
          839  +		vendor=gould
          840  +		;;
          841  +	op50n-* | op60c-*)
          842  +		cpu=hppa1.1
          843  +		vendor=oki
          844  +		os=proelf
          845  +		;;
          846  +	pa-hitachi)
          847  +		cpu=hppa1.1
          848  +		vendor=hitachi
          849  +		os=hiuxwe2
          850  +		;;
          851  +	pbd)
          852  +		cpu=sparc
          853  +		vendor=tti
          854  +		;;
          855  +	pbb)
          856  +		cpu=m68k
          857  +		vendor=tti
          858  +		;;
          859  +	pc532)
          860  +		cpu=ns32k
          861  +		vendor=pc532
          862  +		;;
          863  +	pn)
          864  +		cpu=pn
          865  +		vendor=gould
          866  +		;;
          867  +	power)
          868  +		cpu=power
          869  +		vendor=ibm
          870  +		;;
          871  +	ps2)
          872  +		cpu=i386
          873  +		vendor=ibm
          874  +		;;
          875  +	rm[46]00)
          876  +		cpu=mips
          877  +		vendor=siemens
          878  +		;;
          879  +	rtpc | rtpc-*)
          880  +		cpu=romp
          881  +		vendor=ibm
          882  +		;;
          883  +	sde)
          884  +		cpu=mipsisa32
          885  +		vendor=sde
          886  +		os=${os:-elf}
          887  +		;;
          888  +	simso-wrs)
          889  +		cpu=sparclite
          890  +		vendor=wrs
          891  +		os=vxworks
          892  +		;;
          893  +	tower | tower-32)
          894  +		cpu=m68k
          895  +		vendor=ncr
          896  +		;;
          897  +	vpp*|vx|vx-*)
          898  +		cpu=f301
          899  +		vendor=fujitsu
          900  +		;;
          901  +	w65)
          902  +		cpu=w65
          903  +		vendor=wdc
          904  +		;;
          905  +	w89k-*)
          906  +		cpu=hppa1.1
          907  +		vendor=winbond
          908  +		os=proelf
          909  +		;;
          910  +	none)
          911  +		cpu=none
          912  +		vendor=none
          913  +		;;
          914  +	leon|leon[3-9])
          915  +		cpu=sparc
          916  +		vendor=$basic_machine
          917  +		;;
          918  +	leon-*|leon[3-9]-*)
          919  +		cpu=sparc
          920  +		vendor=`echo "$basic_machine" | sed 's/-.*//'`
          921  +		;;
          922  +
          923  +	*-*)
          924  +		# shellcheck disable=SC2162
          925  +		IFS="-" read cpu vendor <<EOF
          926  +$basic_machine
          927  +EOF
          928  +		;;
   303    929   	# We use `pc' rather than `unknown'
   304    930   	# because (1) that's what they normally are, and
   305    931   	# (2) the word "unknown" tends to confuse beginning users.
   306    932   	i*86 | x86_64)
   307         -	  basic_machine=$basic_machine-pc
   308         -	  ;;
   309         -	# Object if more than one company name word.
   310         -	*-*-*)
   311         -		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
   312         -		exit 1
   313         -		;;
   314         -	# Recognize the basic CPU types with company name.
   315         -	580-* \
   316         -	| a29k-* \
   317         -	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
   318         -	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
   319         -	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
   320         -	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
   321         -	| avr-* | avr32-* \
   322         -	| bfin-* | bs2000-* \
   323         -	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
   324         -	| clipper-* | craynv-* | cydra-* \
   325         -	| d10v-* | d30v-* | dlx-* \
   326         -	| elxsi-* \
   327         -	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
   328         -	| h8300-* | h8500-* \
   329         -	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
   330         -	| i*86-* | i860-* | i960-* | ia64-* \
   331         -	| ip2k-* | iq2000-* \
   332         -	| m32c-* | m32r-* | m32rle-* \
   333         -	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
   334         -	| m88110-* | m88k-* | maxq-* | mcore-* \
   335         -	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
   336         -	| mips16-* \
   337         -	| mips64-* | mips64el-* \
   338         -	| mips64vr-* | mips64vrel-* \
   339         -	| mips64orion-* | mips64orionel-* \
   340         -	| mips64vr4100-* | mips64vr4100el-* \
   341         -	| mips64vr4300-* | mips64vr4300el-* \
   342         -	| mips64vr5000-* | mips64vr5000el-* \
   343         -	| mips64vr5900-* | mips64vr5900el-* \
   344         -	| mipsisa32-* | mipsisa32el-* \
   345         -	| mipsisa32r2-* | mipsisa32r2el-* \
   346         -	| mipsisa64-* | mipsisa64el-* \
   347         -	| mipsisa64r2-* | mipsisa64r2el-* \
   348         -	| mipsisa64sb1-* | mipsisa64sb1el-* \
   349         -	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
   350         -	| mipstx39-* | mipstx39el-* \
   351         -	| mmix-* \
   352         -	| mt-* \
   353         -	| msp430-* \
   354         -	| nios-* | nios2-* \
   355         -	| none-* | np1-* | ns16k-* | ns32k-* \
   356         -	| orion-* \
   357         -	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
   358         -	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
   359         -	| pyramid-* \
   360         -	| romp-* | rs6000-* \
   361         -	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]a*eb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
   362         -	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
   363         -	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
   364         -	| sparclite-* \
   365         -	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
   366         -	| tahoe-* | thumb-* \
   367         -	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
   368         -	| tron-* \
   369         -	| v850-* | v850e-* | vax-* \
   370         -	| we32k-* \
   371         -	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
   372         -	| xstormy16-* | xtensa-* \
   373         -	| ymp-* \
   374         -	| z8k-*)
   375         -		;;
   376         -	# Recognize the various machine names and aliases which stand
   377         -	# for a CPU type and a company and sometimes even an OS.
   378         -	386bsd)
   379         -		basic_machine=i386-unknown
   380         -		os=-bsd
   381         -		;;
   382         -	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
   383         -		basic_machine=m68000-att
   384         -		;;
   385         -	3b*)
   386         -		basic_machine=we32k-att
   387         -		;;
   388         -	a29khif)
   389         -		basic_machine=a29k-amd
   390         -		os=-udi
   391         -		;;
   392         -    	abacus)
   393         -		basic_machine=abacus-unknown
   394         -		;;
   395         -	adobe68k)
   396         -		basic_machine=m68010-adobe
   397         -		os=-scout
   398         -		;;
   399         -	alliant | fx80)
   400         -		basic_machine=fx80-alliant
   401         -		;;
   402         -	altos | altos3068)
   403         -		basic_machine=m68k-altos
   404         -		;;
   405         -	am29k)
   406         -		basic_machine=a29k-none
   407         -		os=-bsd
   408         -		;;
   409         -	amd64)
   410         -		basic_machine=x86_64-pc
   411         -		;;
          933  +		cpu=$basic_machine
          934  +		vendor=pc
          935  +		;;
          936  +	# These rules are duplicated from below for sake of the special case above;
          937  +	# i.e. things that normalized to x86 arches should also default to "pc"
          938  +	pc98)
          939  +		cpu=i386
          940  +		vendor=pc
          941  +		;;
          942  +	x64 | amd64)
          943  +		cpu=x86_64
          944  +		vendor=pc
          945  +		;;
          946  +	# Recognize the basic CPU types without company name.
          947  +	*)
          948  +		cpu=$basic_machine
          949  +		vendor=unknown
          950  +		;;
          951  +esac
          952  +
          953  +unset -v basic_machine
          954  +
          955  +# Decode basic machines in the full and proper CPU-Company form.
          956  +case $cpu-$vendor in
          957  +	# Here we handle the default manufacturer of certain CPU types in canonical form. It is in
          958  +	# some cases the only manufacturer, in others, it is the most popular.
          959  +	craynv-unknown)
          960  +		vendor=cray
          961  +		os=${os:-unicosmp}
          962  +		;;
          963  +	c90-unknown | c90-cray)
          964  +		vendor=cray
          965  +		os=${os:-unicos}
          966  +		;;
          967  +	fx80-unknown)
          968  +		vendor=alliant
          969  +		;;
          970  +	romp-unknown)
          971  +		vendor=ibm
          972  +		;;
          973  +	mmix-unknown)
          974  +		vendor=knuth
          975  +		;;
          976  +	microblaze-unknown | microblazeel-unknown)
          977  +		vendor=xilinx
          978  +		;;
          979  +	rs6000-unknown)
          980  +		vendor=ibm
          981  +		;;
          982  +	vax-unknown)
          983  +		vendor=dec
          984  +		;;
          985  +	pdp11-unknown)
          986  +		vendor=dec
          987  +		;;
          988  +	we32k-unknown)
          989  +		vendor=att
          990  +		;;
          991  +	cydra-unknown)
          992  +		vendor=cydrome
          993  +		;;
          994  +	i370-ibm*)
          995  +		vendor=ibm
          996  +		;;
          997  +	orion-unknown)
          998  +		vendor=highlevel
          999  +		;;
         1000  +	xps-unknown | xps100-unknown)
         1001  +		cpu=xps100
         1002  +		vendor=honeywell
         1003  +		;;
         1004  +
         1005  +	# Here we normalize CPU types with a missing or matching vendor
         1006  +	dpx20-unknown | dpx20-bull)
         1007  +		cpu=rs6000
         1008  +		vendor=bull
         1009  +		os=${os:-bosx}
         1010  +		;;
         1011  +
         1012  +	# Here we normalize CPU types irrespective of the vendor
   412   1013   	amd64-*)
   413         -		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
   414         -		;;
   415         -	amdahl)
   416         -		basic_machine=580-amdahl
   417         -		os=-sysv
   418         -		;;
   419         -	amiga | amiga-*)
   420         -		basic_machine=m68k-unknown
   421         -		;;
   422         -	amigaos | amigados)
   423         -		basic_machine=m68k-unknown
   424         -		os=-amigaos
   425         -		;;
   426         -	amigaunix | amix)
   427         -		basic_machine=m68k-unknown
   428         -		os=-sysv4
   429         -		;;
   430         -	apollo68)
   431         -		basic_machine=m68k-apollo
   432         -		os=-sysv
   433         -		;;
   434         -	apollo68bsd)
   435         -		basic_machine=m68k-apollo
   436         -		os=-bsd
   437         -		;;
   438         -	aux)
   439         -		basic_machine=m68k-apple
   440         -		os=-aux
   441         -		;;
   442         -	balance)
   443         -		basic_machine=ns32k-sequent
   444         -		os=-dynix
   445         -		;;
   446         -	c90)
   447         -		basic_machine=c90-cray
   448         -		os=-unicos
   449         -		;;
   450         -	convex-c1)
   451         -		basic_machine=c1-convex
   452         -		os=-bsd
   453         -		;;
   454         -	convex-c2)
   455         -		basic_machine=c2-convex
   456         -		os=-bsd
   457         -		;;
   458         -	convex-c32)
   459         -		basic_machine=c32-convex
   460         -		os=-bsd
   461         -		;;
   462         -	convex-c34)
   463         -		basic_machine=c34-convex
   464         -		os=-bsd
   465         -		;;
   466         -	convex-c38)
   467         -		basic_machine=c38-convex
   468         -		os=-bsd
   469         -		;;
   470         -	cray | j90)
   471         -		basic_machine=j90-cray
   472         -		os=-unicos
   473         -		;;
   474         -	craynv)
   475         -		basic_machine=craynv-cray
   476         -		os=-unicosmp
   477         -		;;
   478         -	cr16)
   479         -		basic_machine=cr16-unknown
   480         -		os=-elf
   481         -		;;
   482         -	crds | unos)
   483         -		basic_machine=m68k-crds
   484         -		;;
   485         -	crisv32 | crisv32-* | etraxfs*)
   486         -		basic_machine=crisv32-axis
   487         -		;;
   488         -	cris | cris-* | etrax*)
   489         -		basic_machine=cris-axis
   490         -		;;
   491         -	crx)
   492         -		basic_machine=crx-unknown
   493         -		os=-elf
   494         -		;;
   495         -	da30 | da30-*)
   496         -		basic_machine=m68k-da30
   497         -		;;
   498         -	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
   499         -		basic_machine=mips-dec
   500         -		;;
   501         -	decsystem10* | dec10*)
   502         -		basic_machine=pdp10-dec
   503         -		os=-tops10
   504         -		;;
   505         -	decsystem20* | dec20*)
   506         -		basic_machine=pdp10-dec
   507         -		os=-tops20
   508         -		;;
   509         -	delta | 3300 | motorola-3300 | motorola-delta \
   510         -	      | 3300-motorola | delta-motorola)
   511         -		basic_machine=m68k-motorola
   512         -		;;
   513         -	delta88)
   514         -		basic_machine=m88k-motorola
   515         -		os=-sysv3
   516         -		;;
   517         -	djgpp)
   518         -		basic_machine=i586-pc
   519         -		os=-msdosdjgpp
   520         -		;;
   521         -	dpx20 | dpx20-*)
   522         -		basic_machine=rs6000-bull
   523         -		os=-bosx
   524         -		;;
   525         -	dpx2* | dpx2*-bull)
   526         -		basic_machine=m68k-bull
   527         -		os=-sysv3
   528         -		;;
   529         -	ebmon29k)
   530         -		basic_machine=a29k-amd
   531         -		os=-ebmon
   532         -		;;
   533         -	elxsi)
   534         -		basic_machine=elxsi-elxsi
   535         -		os=-bsd
   536         -		;;
   537         -	encore | umax | mmax)
   538         -		basic_machine=ns32k-encore
   539         -		;;
   540         -	es1800 | OSE68k | ose68k | ose | OSE)
   541         -		basic_machine=m68k-ericsson
   542         -		os=-ose
   543         -		;;
   544         -	fx2800)
   545         -		basic_machine=i860-alliant
   546         -		;;
   547         -	genix)
   548         -		basic_machine=ns32k-ns
   549         -		;;
   550         -	gmicro)
   551         -		basic_machine=tron-gmicro
   552         -		os=-sysv
   553         -		;;
   554         -	go32)
   555         -		basic_machine=i386-pc
   556         -		os=-go32
   557         -		;;
   558         -	h3050r* | hiux*)
   559         -		basic_machine=hppa1.1-hitachi
   560         -		os=-hiuxwe2
   561         -		;;
   562         -	h8300hms)
   563         -		basic_machine=h8300-hitachi
   564         -		os=-hms
   565         -		;;
   566         -	h8300xray)
   567         -		basic_machine=h8300-hitachi
   568         -		os=-xray
   569         -		;;
   570         -	h8500hms)
   571         -		basic_machine=h8500-hitachi
   572         -		os=-hms
   573         -		;;
   574         -	harris)
   575         -		basic_machine=m88k-harris
   576         -		os=-sysv3
   577         -		;;
   578         -	hp300-*)
   579         -		basic_machine=m68k-hp
   580         -		;;
   581         -	hp300bsd)
   582         -		basic_machine=m68k-hp
   583         -		os=-bsd
   584         -		;;
   585         -	hp300hpux)
   586         -		basic_machine=m68k-hp
   587         -		os=-hpux
   588         -		;;
   589         -	hp3k9[0-9][0-9] | hp9[0-9][0-9])
   590         -		basic_machine=hppa1.0-hp
   591         -		;;
   592         -	hp9k2[0-9][0-9] | hp9k31[0-9])
   593         -		basic_machine=m68000-hp
   594         -		;;
   595         -	hp9k3[2-9][0-9])
   596         -		basic_machine=m68k-hp
   597         -		;;
   598         -	hp9k6[0-9][0-9] | hp6[0-9][0-9])
   599         -		basic_machine=hppa1.0-hp
   600         -		;;
   601         -	hp9k7[0-79][0-9] | hp7[0-79][0-9])
   602         -		basic_machine=hppa1.1-hp
   603         -		;;
   604         -	hp9k78[0-9] | hp78[0-9])
   605         -		# FIXME: really hppa2.0-hp
   606         -		basic_machine=hppa1.1-hp
   607         -		;;
   608         -	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
   609         -		# FIXME: really hppa2.0-hp
   610         -		basic_machine=hppa1.1-hp
   611         -		;;
   612         -	hp9k8[0-9][13679] | hp8[0-9][13679])
   613         -		basic_machine=hppa1.1-hp
   614         -		;;
   615         -	hp9k8[0-9][0-9] | hp8[0-9][0-9])
   616         -		basic_machine=hppa1.0-hp
   617         -		;;
   618         -	hppa-next)
   619         -		os=-nextstep3
   620         -		;;
   621         -	hppaosf)
   622         -		basic_machine=hppa1.1-hp
   623         -		os=-osf
   624         -		;;
   625         -	hppro)
   626         -		basic_machine=hppa1.1-hp
   627         -		os=-proelf
   628         -		;;
   629         -	i370-ibm* | ibm*)
   630         -		basic_machine=i370-ibm
   631         -		;;
   632         -# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
   633         -	i*86v32)
   634         -		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
   635         -		os=-sysv32
   636         -		;;
   637         -	i*86v4*)
   638         -		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
   639         -		os=-sysv4
   640         -		;;
   641         -	i*86v)
   642         -		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
   643         -		os=-sysv
   644         -		;;
   645         -	i*86sol2)
   646         -		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
   647         -		os=-solaris2
   648         -		;;
   649         -	i386mach)
   650         -		basic_machine=i386-mach
   651         -		os=-mach
   652         -		;;
   653         -	i386-vsta | vsta)
   654         -		basic_machine=i386-unknown
   655         -		os=-vsta
   656         -		;;
   657         -	iris | iris4d)
   658         -		basic_machine=mips-sgi
   659         -		case $os in
   660         -		    -irix*)
   661         -			;;
   662         -		    *)
   663         -			os=-irix4
   664         -			;;
   665         -		esac
   666         -		;;
   667         -	isi68 | isi)
   668         -		basic_machine=m68k-isi
   669         -		os=-sysv
   670         -		;;
   671         -	m88k-omron*)
   672         -		basic_machine=m88k-omron
   673         -		;;
   674         -	magnum | m3230)
   675         -		basic_machine=mips-mips
   676         -		os=-sysv
   677         -		;;
   678         -	merlin)
   679         -		basic_machine=ns32k-utek
   680         -		os=-sysv
   681         -		;;
   682         -	mingw32)
   683         -		basic_machine=i386-pc
   684         -		os=-mingw32
   685         -		;;
   686         -	mingw32ce)
   687         -		basic_machine=arm-unknown
   688         -		os=-mingw32ce
   689         -		;;
   690         -	miniframe)
   691         -		basic_machine=m68000-convergent
   692         -		;;
   693         -	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
   694         -		basic_machine=m68k-atari
   695         -		os=-mint
   696         -		;;
   697         -	mipsEE* | ee | ps2)
   698         -		basic_machine=mips64r5900el-scei
   699         -		case $os in
   700         -		    -linux*)
   701         -			;;
   702         -		    *)
   703         -			os=-elf
   704         -			;;
   705         -		esac
   706         -		;;
   707         -	iop)
   708         -		basic_machine=mipsel-scei
   709         -		os=-irx
   710         -		;;
   711         -	dvp)
   712         -		basic_machine=dvp-scei
   713         -		os=-elf
         1014  +		cpu=x86_64
         1015  +		;;
         1016  +	blackfin-*)
         1017  +		cpu=bfin
         1018  +		os=linux
         1019  +		;;
         1020  +	c54x-*)
         1021  +		cpu=tic54x
         1022  +		;;
         1023  +	c55x-*)
         1024  +		cpu=tic55x
         1025  +		;;
         1026  +	c6x-*)
         1027  +		cpu=tic6x
         1028  +		;;
         1029  +	e500v[12]-*)
         1030  +		cpu=powerpc
         1031  +		os=$os"spe"
   714   1032   		;;
   715   1033   	mips3*-*)
   716         -		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
   717         -		;;
   718         -	mips3*)
   719         -		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
   720         -		;;
   721         -	monitor)
   722         -		basic_machine=m68k-rom68k
   723         -		os=-coff
   724         -		;;
   725         -	morphos)
   726         -		basic_machine=powerpc-unknown
   727         -		os=-morphos
   728         -		;;
   729         -	msdos)
   730         -		basic_machine=i386-pc
   731         -		os=-msdos
         1034  +		cpu=mips64
   732   1035   		;;
   733   1036   	ms1-*)
   734         -		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
   735         -		;;
   736         -	mvs)
   737         -		basic_machine=i370-ibm
   738         -		os=-mvs
   739         -		;;
   740         -	ncr3000)
   741         -		basic_machine=i486-ncr
   742         -		os=-sysv4
   743         -		;;
   744         -	netbsd386)
   745         -		basic_machine=i386-unknown
   746         -		os=-netbsd
   747         -		;;
   748         -	netwinder)
   749         -		basic_machine=armv4l-rebel
   750         -		os=-linux
   751         -		;;
   752         -	news | news700 | news800 | news900)
   753         -		basic_machine=m68k-sony
   754         -		os=-newsos
   755         -		;;
   756         -	news1000)
   757         -		basic_machine=m68030-sony
   758         -		os=-newsos
   759         -		;;
   760         -	news-3600 | risc-news)
   761         -		basic_machine=mips-sony
   762         -		os=-newsos
   763         -		;;
   764         -	necv70)
   765         -		basic_machine=v70-nec
   766         -		os=-sysv
   767         -		;;
   768         -	next | m*-next )
   769         -		basic_machine=m68k-next
   770         -		case $os in
   771         -		    -nextstep* )
   772         -			;;
   773         -		    -ns2*)
   774         -		      os=-nextstep2
   775         -			;;
   776         -		    *)
   777         -		      os=-nextstep3
   778         -			;;
   779         -		esac
   780         -		;;
   781         -	nh3000)
   782         -		basic_machine=m68k-harris
   783         -		os=-cxux
   784         -		;;
   785         -	nh[45]000)
   786         -		basic_machine=m88k-harris
   787         -		os=-cxux
   788         -		;;
   789         -	nindy960)
   790         -		basic_machine=i960-intel
   791         -		os=-nindy
   792         -		;;
   793         -	mon960)
   794         -		basic_machine=i960-intel
   795         -		os=-mon960
   796         -		;;
   797         -	nonstopux)
   798         -		basic_machine=mips-compaq
   799         -		os=-nonstopux
   800         -		;;
   801         -	np1)
   802         -		basic_machine=np1-gould
         1037  +		cpu=mt
         1038  +		;;
         1039  +	m68knommu-*)
         1040  +		cpu=m68k
         1041  +		os=linux
         1042  +		;;
         1043  +	m9s12z-* | m68hcs12z-* | hcs12z-* | s12z-*)
         1044  +		cpu=s12z
         1045  +		;;
         1046  +	openrisc-*)
         1047  +		cpu=or32
         1048  +		;;
         1049  +	parisc-*)
         1050  +		cpu=hppa
         1051  +		os=linux
         1052  +		;;
         1053  +	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
         1054  +		cpu=i586
         1055  +		;;
         1056  +	pentiumpro-* | p6-* | 6x86-* | athlon-* | athalon_*-*)
         1057  +		cpu=i686
         1058  +		;;
         1059  +	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
         1060  +		cpu=i686
         1061  +		;;
         1062  +	pentium4-*)
         1063  +		cpu=i786
         1064  +		;;
         1065  +	pc98-*)
         1066  +		cpu=i386
         1067  +		;;
         1068  +	ppc-* | ppcbe-*)
         1069  +		cpu=powerpc
         1070  +		;;
         1071  +	ppcle-* | powerpclittle-*)
         1072  +		cpu=powerpcle
         1073  +		;;
         1074  +	ppc64-*)
         1075  +		cpu=powerpc64
         1076  +		;;
         1077  +	ppc64le-* | powerpc64little-*)
         1078  +		cpu=powerpc64le
         1079  +		;;
         1080  +	sb1-*)
         1081  +		cpu=mipsisa64sb1
         1082  +		;;
         1083  +	sb1el-*)
         1084  +		cpu=mipsisa64sb1el
         1085  +		;;
         1086  +	sh5e[lb]-*)
         1087  +		cpu=`echo "$cpu" | sed 's/^\(sh.\)e\(.\)$/\1\2e/'`
         1088  +		;;
         1089  +	spur-*)
         1090  +		cpu=spur
         1091  +		;;
         1092  +	strongarm-* | thumb-*)
         1093  +		cpu=arm
         1094  +		;;
         1095  +	tx39-*)
         1096  +		cpu=mipstx39
         1097  +		;;
         1098  +	tx39el-*)
         1099  +		cpu=mipstx39el
         1100  +		;;
         1101  +	x64-*)
         1102  +		cpu=x86_64
         1103  +		;;
         1104  +	xscale-* | xscalee[bl]-*)
         1105  +		cpu=`echo "$cpu" | sed 's/^xscale/arm/'`
         1106  +		;;
         1107  +
         1108  +	# Recognize the canonical CPU Types that limit and/or modify the
         1109  +	# company names they are paired with.
         1110  +	cr16-*)
         1111  +		os=${os:-elf}
         1112  +		;;
         1113  +	crisv32-* | etraxfs*-*)
         1114  +		cpu=crisv32
         1115  +		vendor=axis
         1116  +		;;
         1117  +	cris-* | etrax*-*)
         1118  +		cpu=cris
         1119  +		vendor=axis
         1120  +		;;
         1121  +	crx-*)
         1122  +		os=${os:-elf}
         1123  +		;;
         1124  +	neo-tandem)
         1125  +		cpu=neo
         1126  +		vendor=tandem
         1127  +		;;
         1128  +	nse-tandem)
         1129  +		cpu=nse
         1130  +		vendor=tandem
   803   1131   		;;
   804   1132   	nsr-tandem)
   805         -		basic_machine=nsr-tandem
   806         -		;;
   807         -	op50n-* | op60c-*)
   808         -		basic_machine=hppa1.1-oki
   809         -		os=-proelf
   810         -		;;
   811         -	openrisc | openrisc-*)
   812         -		basic_machine=or32-unknown
   813         -		;;
   814         -	os400)
   815         -		basic_machine=powerpc-ibm
   816         -		os=-os400
   817         -		;;
   818         -	OSE68000 | ose68000)
   819         -		basic_machine=m68000-ericsson
   820         -		os=-ose
   821         -		;;
   822         -	os68k)
   823         -		basic_machine=m68k-none
   824         -		os=-os68k
   825         -		;;
   826         -	pa-hitachi)
   827         -		basic_machine=hppa1.1-hitachi
   828         -		os=-hiuxwe2
   829         -		;;
   830         -	paragon)
   831         -		basic_machine=i860-intel
   832         -		os=-osf
   833         -		;;
   834         -	pbd)
   835         -		basic_machine=sparc-tti
   836         -		;;
   837         -	pbb)
   838         -		basic_machine=m68k-tti
   839         -		;;
   840         -	pc532 | pc532-*)
   841         -		basic_machine=ns32k-pc532
   842         -		;;
   843         -	pc98)
   844         -		basic_machine=i386-pc
   845         -		;;
   846         -	pc98-*)
   847         -		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
   848         -		;;
   849         -	pentium | p5 | k5 | k6 | nexgen | viac3)
   850         -		basic_machine=i586-pc
   851         -		;;
   852         -	pentiumpro | p6 | 6x86 | athlon | athlon_*)
   853         -		basic_machine=i686-pc
   854         -		;;
   855         -	pentiumii | pentium2 | pentiumiii | pentium3)
   856         -		basic_machine=i686-pc
   857         -		;;
   858         -	pentium4)
   859         -		basic_machine=i786-pc
   860         -		;;
   861         -	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
   862         -		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
   863         -		;;
   864         -	pentiumpro-* | p6-* | 6x86-* | athlon-*)
   865         -		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
   866         -		;;
   867         -	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
   868         -		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
   869         -		;;
   870         -	pentium4-*)
   871         -		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
   872         -		;;
   873         -	pn)
   874         -		basic_machine=pn-gould
   875         -		;;
   876         -	power)	basic_machine=power-ibm
   877         -		;;
   878         -	ppc)	basic_machine=powerpc-unknown
   879         -		;;
   880         -	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
   881         -		;;
   882         -	ppcle | powerpclittle | ppc-le | powerpc-little)
   883         -		basic_machine=powerpcle-unknown
   884         -		;;
   885         -	ppcle-* | powerpclittle-*)
   886         -		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
   887         -		;;
   888         -	ppc64)	basic_machine=powerpc64-unknown
   889         -		;;
   890         -	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
   891         -		;;
   892         -	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
   893         -		basic_machine=powerpc64le-unknown
   894         -		;;
   895         -	ppc64le-* | powerpc64little-*)
   896         -		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
   897         -		;;
   898         -	ps2)
   899         -		basic_machine=i386-ibm
   900         -		;;
   901         -	pw32)
   902         -		basic_machine=i586-unknown
   903         -		os=-pw32
   904         -		;;
   905         -	rdos)
   906         -		basic_machine=i386-pc
   907         -		os=-rdos
   908         -		;;
   909         -	rom68k)
   910         -		basic_machine=m68k-rom68k
   911         -		os=-coff
   912         -		;;
   913         -	rm[46]00)
   914         -		basic_machine=mips-siemens
   915         -		;;
   916         -	rtpc | rtpc-*)
   917         -		basic_machine=romp-ibm
   918         -		;;
   919         -	s390 | s390-*)
   920         -		basic_machine=s390-ibm
   921         -		;;
   922         -	s390x | s390x-*)
   923         -		basic_machine=s390x-ibm
   924         -		;;
   925         -	sa29200)
   926         -		basic_machine=a29k-amd
   927         -		os=-udi
   928         -		;;
   929         -	sb1)
   930         -		basic_machine=mipsisa64sb1-unknown
   931         -		;;
   932         -	sb1el)
   933         -		basic_machine=mipsisa64sb1el-unknown
   934         -		;;
   935         -	sde)
   936         -		basic_machine=mipsisa32-sde
   937         -		os=-elf
   938         -		;;
   939         -	sei)
   940         -		basic_machine=mips-sei
   941         -		os=-seiux
   942         -		;;
   943         -	sequent)
   944         -		basic_machine=i386-sequent
   945         -		;;
   946         -	sh)
   947         -		basic_machine=sh-hitachi
   948         -		os=-hms
   949         -		;;
   950         -	sh5el)
   951         -		basic_machine=sh5le-unknown
   952         -		;;
   953         -	sh64)
   954         -		basic_machine=sh64-unknown
   955         -		;;
   956         -	sparclite-wrs | simso-wrs)
   957         -		basic_machine=sparclite-wrs
   958         -		os=-vxworks
   959         -		;;
   960         -	sps7)
   961         -		basic_machine=m68k-bull
   962         -		os=-sysv2
   963         -		;;
   964         -	spur)
   965         -		basic_machine=spur-unknown
   966         -		;;
   967         -	st2000)
   968         -		basic_machine=m68k-tandem
   969         -		;;
   970         -	stratus)
   971         -		basic_machine=i860-stratus
   972         -		os=-sysv4
   973         -		;;
   974         -	sun2)
   975         -		basic_machine=m68000-sun
   976         -		;;
   977         -	sun2os3)
   978         -		basic_machine=m68000-sun
   979         -		os=-sunos3
   980         -		;;
   981         -	sun2os4)
   982         -		basic_machine=m68000-sun
   983         -		os=-sunos4
   984         -		;;
   985         -	sun3os3)
   986         -		basic_machine=m68k-sun
   987         -		os=-sunos3
   988         -		;;
   989         -	sun3os4)
   990         -		basic_machine=m68k-sun
   991         -		os=-sunos4
   992         -		;;
   993         -	sun4os3)
   994         -		basic_machine=sparc-sun
   995         -		os=-sunos3
   996         -		;;
   997         -	sun4os4)
   998         -		basic_machine=sparc-sun
   999         -		os=-sunos4
  1000         -		;;
  1001         -	sun4sol2)
  1002         -		basic_machine=sparc-sun
  1003         -		os=-solaris2
  1004         -		;;
  1005         -	sun3 | sun3-*)
  1006         -		basic_machine=m68k-sun
  1007         -		;;
  1008         -	sun4)
  1009         -		basic_machine=sparc-sun
  1010         -		;;
  1011         -	sun386 | sun386i | roadrunner)
  1012         -		basic_machine=i386-sun
  1013         -		;;
  1014         -	sv1)
  1015         -		basic_machine=sv1-cray
  1016         -		os=-unicos
  1017         -		;;
  1018         -	symmetry)
  1019         -		basic_machine=i386-sequent
  1020         -		os=-dynix
  1021         -		;;
  1022         -	t3e)
  1023         -		basic_machine=alphaev5-cray
  1024         -		os=-unicos
  1025         -		;;
  1026         -	t90)
  1027         -		basic_machine=t90-cray
  1028         -		os=-unicos
  1029         -		;;
  1030         -	tic54x | c54x*)
  1031         -		basic_machine=tic54x-unknown
  1032         -		os=-coff
  1033         -		;;
  1034         -	tic55x | c55x*)
  1035         -		basic_machine=tic55x-unknown
  1036         -		os=-coff
  1037         -		;;
  1038         -	tic6x | c6x*)
  1039         -		basic_machine=tic6x-unknown
  1040         -		os=-coff
  1041         -		;;
  1042         -	tx39)
  1043         -		basic_machine=mipstx39-unknown
  1044         -		;;
  1045         -	tx39el)
  1046         -		basic_machine=mipstx39el-unknown
  1047         -		;;
  1048         -	toad1)
  1049         -		basic_machine=pdp10-xkl
  1050         -		os=-tops20
  1051         -		;;
  1052         -	tower | tower-32)
  1053         -		basic_machine=m68k-ncr
  1054         -		;;
  1055         -	tpf)
  1056         -		basic_machine=s390x-ibm
  1057         -		os=-tpf
  1058         -		;;
  1059         -	udi29k)
  1060         -		basic_machine=a29k-amd
  1061         -		os=-udi
  1062         -		;;
  1063         -	ultra3)
  1064         -		basic_machine=a29k-nyu
  1065         -		os=-sym1
  1066         -		;;
  1067         -	v810 | necv810)
  1068         -		basic_machine=v810-nec
  1069         -		os=-none
  1070         -		;;
  1071         -	vaxv)
  1072         -		basic_machine=vax-dec
  1073         -		os=-sysv
  1074         -		;;
  1075         -	vms)
  1076         -		basic_machine=vax-dec
  1077         -		os=-vms
  1078         -		;;
  1079         -	vpp*|vx|vx-*)
  1080         -		basic_machine=f301-fujitsu
  1081         -		;;
  1082         -	vxworks960)
  1083         -		basic_machine=i960-wrs
  1084         -		os=-vxworks
  1085         -		;;
  1086         -	vxworks68)
  1087         -		basic_machine=m68k-wrs
  1088         -		os=-vxworks
  1089         -		;;
  1090         -	vxworks29k)
  1091         -		basic_machine=a29k-wrs
  1092         -		os=-vxworks
  1093         -		;;
  1094         -	w65*)
  1095         -		basic_machine=w65-wdc
  1096         -		os=-none
  1097         -		;;
  1098         -	w89k-*)
  1099         -		basic_machine=hppa1.1-winbond
  1100         -		os=-proelf
  1101         -		;;
  1102         -	xbox)
  1103         -		basic_machine=i686-pc
  1104         -		os=-mingw32
  1105         -		;;
  1106         -	xps | xps100)
  1107         -		basic_machine=xps100-honeywell
  1108         -		;;
  1109         -	ymp)
  1110         -		basic_machine=ymp-cray
  1111         -		os=-unicos
  1112         -		;;
  1113         -	z8k-*-coff)
  1114         -		basic_machine=z8k-unknown
  1115         -		os=-sim
  1116         -		;;
  1117         -	none)
  1118         -		basic_machine=none-none
  1119         -		os=-none
  1120         -		;;
         1133  +		cpu=nsr
         1134  +		vendor=tandem
         1135  +		;;
         1136  +	nsv-tandem)
         1137  +		cpu=nsv
         1138  +		vendor=tandem
         1139  +		;;
         1140  +	nsx-tandem)
         1141  +		cpu=nsx
         1142  +		vendor=tandem
         1143  +		;;
         1144  +	s390-*)
         1145  +		cpu=s390
         1146  +		vendor=ibm
         1147  +		;;
         1148  +	s390x-*)
         1149  +		cpu=s390x
         1150  +		vendor=ibm
         1151  +		;;
         1152  +	tile*-*)
         1153  +		os=${os:-linux-gnu}
         1154  +		;;
         1155  +
         1156  +	*)
         1157  +		# Recognize the canonical CPU types that are allowed with any
         1158  +		# company name.
         1159  +		case $cpu in
         1160  +			1750a | 580 \
         1161  +			| a29k \
         1162  +			| aarch64 | aarch64_be \
         1163  +			| abacus \
         1164  +			| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] \
         1165  +			| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] \
         1166  +			| alphapca5[67] | alpha64pca5[67] \
         1167  +			| am33_2.0 \
         1168  +			| amdgcn \
         1169  +			| arc | arceb \
         1170  +			| arm  | arm[lb]e | arme[lb] | armv* \
         1171  +			| avr | avr32 \
         1172  +			| asmjs \
         1173  +			| ba \
         1174  +			| be32 | be64 \
         1175  +			| bfin | bpf | bs2000 \
         1176  +			| c[123]* | c30 | [cjt]90 | c4x \
         1177  +			| c8051 | clipper | craynv | csky | cydra \
         1178  +			| d10v | d30v | dlx | dsp16xx \
         1179  +			| e2k | elxsi | epiphany \
         1180  +			| f30[01] | f700 | fido | fr30 | frv | ft32 | fx80 \
         1181  +			| h8300 | h8500 \
         1182  +			| hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
         1183  +			| hexagon \
         1184  +			| i370 | i*86 | i860 | i960 | ia16 | ia64 \
         1185  +			| ip2k | iq2000 \
         1186  +			| k1om \
         1187  +			| le32 | le64 \
         1188  +			| lm32 \
         1189  +			| m32c | m32r | m32rle \
         1190  +			| m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \
         1191  +			| m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \
         1192  +			| m88110 | m88k | maxq | mb | mcore | mep | metag \
         1193  +			| microblaze | microblazeel \
         1194  +			| mips | mipsbe | mipseb | mipsel | mipsle \
         1195  +			| mips16 \
         1196  +			| mips64 | mips64eb | mips64el \
         1197  +			| mips64octeon | mips64octeonel \
         1198  +			| mips64orion | mips64orionel \
         1199  +			| mips64r5900 | mips64r5900el \
         1200  +			| mips64vr | mips64vrel \
         1201  +			| mips64vr4100 | mips64vr4100el \
         1202  +			| mips64vr4300 | mips64vr4300el \
         1203  +			| mips64vr5000 | mips64vr5000el \
         1204  +			| mips64vr5900 | mips64vr5900el \
         1205  +			| mipsisa32 | mipsisa32el \
         1206  +			| mipsisa32r2 | mipsisa32r2el \
         1207  +			| mipsisa32r6 | mipsisa32r6el \
         1208  +			| mipsisa64 | mipsisa64el \
         1209  +			| mipsisa64r2 | mipsisa64r2el \
         1210  +			| mipsisa64r6 | mipsisa64r6el \
         1211  +			| mipsisa64sb1 | mipsisa64sb1el \
         1212  +			| mipsisa64sr71k | mipsisa64sr71kel \
         1213  +			| mipsr5900 | mipsr5900el \
         1214  +			| mipstx39 | mipstx39el \
         1215  +			| mmix \
         1216  +			| mn10200 | mn10300 \
         1217  +			| moxie \
         1218  +			| mt \
         1219  +			| msp430 \
         1220  +			| nds32 | nds32le | nds32be \
         1221  +			| nfp \
         1222  +			| nios | nios2 | nios2eb | nios2el \
         1223  +			| none | np1 | ns16k | ns32k | nvptx \
         1224  +			| open8 \
         1225  +			| or1k* \
         1226  +			| or32 \
         1227  +			| orion \
         1228  +			| picochip \
         1229  +			| pdp10 | pdp11 | pj | pjl | pn | power \
         1230  +			| powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \
         1231  +			| pru \
         1232  +			| pyramid \
         1233  +			| riscv | riscv32 | riscv64 \
         1234  +			| rl78 | romp | rs6000 | rx \
         1235  +			| score \
         1236  +			| sh | shl \
         1237  +			| sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \
         1238  +			| sh[1234]e[lb] |  sh[12345][lb]e | sh[23]ele | sh64 | sh64le \
         1239  +			| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet \
         1240  +			| sparclite \
         1241  +			| sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \
         1242  +			| spu \
         1243  +			| tahoe \
         1244  +			| tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \
         1245  +			| tron \
         1246  +			| ubicom32 \
         1247  +			| v70 | v850 | v850e | v850e1 | v850es | v850e2 | v850e2v3 \
         1248  +			| vax \
         1249  +			| visium \
         1250  +			| w65 \
         1251  +			| wasm32 | wasm64 \
         1252  +			| we32k \
         1253  +			| x86 | x86_64 | xc16x | xgate | xps100 \
         1254  +			| xstormy16 | xtensa* \
         1255  +			| ymp \
         1256  +			| z8k | z80)
         1257  +				;;
  1121   1258   
  1122         -# Here we handle the default manufacturer of certain CPU types.  It is in
  1123         -# some cases the only manufacturer, in others, it is the most popular.
  1124         -	w89k)
  1125         -		basic_machine=hppa1.1-winbond
  1126         -		;;
  1127         -	op50n)
  1128         -		basic_machine=hppa1.1-oki
  1129         -		;;
  1130         -	op60c)
  1131         -		basic_machine=hppa1.1-oki
  1132         -		;;
  1133         -	romp)
  1134         -		basic_machine=romp-ibm
  1135         -		;;
  1136         -	mmix)
  1137         -		basic_machine=mmix-knuth
  1138         -		;;
  1139         -	rs6000)
  1140         -		basic_machine=rs6000-ibm
  1141         -		;;
  1142         -	vax)
  1143         -		basic_machine=vax-dec
  1144         -		;;
  1145         -	pdp10)
  1146         -		# there are many clones, so DEC is not a safe bet
  1147         -		basic_machine=pdp10-unknown
  1148         -		;;
  1149         -	pdp11)
  1150         -		basic_machine=pdp11-dec
  1151         -		;;
  1152         -	we32k)
  1153         -		basic_machine=we32k-att
  1154         -		;;
  1155         -	sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele)
  1156         -		basic_machine=sh-unknown
  1157         -		;;
  1158         -	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
  1159         -		basic_machine=sparc-sun
  1160         -		;;
  1161         -	cydra)
  1162         -		basic_machine=cydra-cydrome
  1163         -		;;
  1164         -	orion)
  1165         -		basic_machine=orion-highlevel
  1166         -		;;
  1167         -	orion105)
  1168         -		basic_machine=clipper-highlevel
  1169         -		;;
  1170         -	mac | mpw | mac-mpw)
  1171         -		basic_machine=m68k-apple
  1172         -		;;
  1173         -	pmac | pmac-mpw)
  1174         -		basic_machine=powerpc-apple
  1175         -		;;
  1176         -	*-unknown)
  1177         -		# Make sure to match an already-canonicalized machine name.
  1178         -		;;
  1179         -	*)
  1180         -		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
  1181         -		exit 1
         1259  +			*)
         1260  +				echo Invalid configuration \`"$1"\': machine \`"$cpu-$vendor"\' not recognized 1>&2
         1261  +				exit 1
         1262  +				;;
         1263  +		esac
  1182   1264   		;;
  1183   1265   esac
  1184   1266   
  1185   1267   # Here we canonicalize certain aliases for manufacturers.
  1186         -case $basic_machine in
  1187         -	*-digital*)
  1188         -		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
         1268  +case $vendor in
         1269  +	digital*)
         1270  +		vendor=dec
  1189   1271   		;;
  1190         -	*-commodore*)
  1191         -		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
         1272  +	commodore*)
         1273  +		vendor=cbm
  1192   1274   		;;
  1193   1275   	*)
  1194   1276   		;;
  1195   1277   esac
  1196   1278   
  1197   1279   # Decode manufacturer-specific aliases for certain operating systems.
  1198   1280   
  1199         -if [ x"$os" != x"" ]
         1281  +if [ x$os != x ]
  1200   1282   then
  1201   1283   case $os in
  1202         -        # First match some system type aliases
  1203         -        # that might get confused with valid system types.
  1204         -	# -solaris* is a basic system type, with this one exception.
  1205         -	-solaris1 | -solaris1.*)
         1284  +	# First match some system type aliases that might get confused
         1285  +	# with valid system types.
         1286  +	# solaris* is a basic system type, with this one exception.
         1287  +	auroraux)
         1288  +		os=auroraux
         1289  +		;;
         1290  +	bluegene*)
         1291  +		os=cnk
         1292  +		;;
         1293  +	solaris1 | solaris1.*)
  1206   1294   		os=`echo $os | sed -e 's|solaris1|sunos4|'`
  1207   1295   		;;
  1208         -	-solaris)
  1209         -		os=-solaris2
         1296  +	solaris)
         1297  +		os=solaris2
  1210   1298   		;;
  1211         -	-svr4*)
  1212         -		os=-sysv4
         1299  +	unixware*)
         1300  +		os=sysv4.2uw
  1213   1301   		;;
  1214         -	-unixware*)
  1215         -		os=-sysv4.2uw
  1216         -		;;
  1217         -	-gnu/linux*)
         1302  +	gnu/linux*)
  1218   1303   		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
  1219   1304   		;;
  1220         -	# First accept the basic system types.
         1305  +	# es1800 is here to avoid being matched by es* (a different OS)
         1306  +	es1800*)
         1307  +		os=ose
         1308  +		;;
         1309  +	# Some version numbers need modification
         1310  +	chorusos*)
         1311  +		os=chorusos
         1312  +		;;
         1313  +	isc)
         1314  +		os=isc2.2
         1315  +		;;
         1316  +	sco6)
         1317  +		os=sco5v6
         1318  +		;;
         1319  +	sco5)
         1320  +		os=sco3.2v5
         1321  +		;;
         1322  +	sco4)
         1323  +		os=sco3.2v4
         1324  +		;;
         1325  +	sco3.2.[4-9]*)
         1326  +		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
         1327  +		;;
         1328  +	sco3.2v[4-9]* | sco5v6*)
         1329  +		# Don't forget version if it is 3.2v4 or newer.
         1330  +		;;
         1331  +	scout)
         1332  +		# Don't match below
         1333  +		;;
         1334  +	sco*)
         1335  +		os=sco3.2v2
         1336  +		;;
         1337  +	psos*)
         1338  +		os=psos
         1339  +		;;
         1340  +	# Now accept the basic system types.
  1221   1341   	# The portable systems comes first.
  1222         -	# Each alternative MUST END IN A *, to match a version number.
  1223         -	# -sysv* is not here because it comes later, after sysvr4.
  1224         -	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
  1225         -	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\
  1226         -	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \
  1227         -	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
  1228         -	      | -aos* \
  1229         -	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
  1230         -	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
  1231         -	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
  1232         -	      | -openbsd* | -solidbsd* \
  1233         -	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
  1234         -	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
  1235         -	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
  1236         -	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
  1237         -	      | -chorusos* | -chorusrdb* \
  1238         -	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
  1239         -	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
  1240         -	      | -uxpv* | -beos* | -mpeix* | -udk* \
  1241         -	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
  1242         -	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
  1243         -	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
  1244         -	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
  1245         -	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
  1246         -	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
  1247         -	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -irx*)
         1342  +	# Each alternative MUST end in a * to match a version number.
         1343  +	# sysv* is not here because it comes later, after sysvr4.
         1344  +	gnu* | bsd* | mach* | minix* | genix* | ultrix* | irix* \
         1345  +	     | *vms* | esix* | aix* | cnk* | sunos | sunos[34]*\
         1346  +	     | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \
         1347  +	     | sym* | kopensolaris* | plan9* \
         1348  +	     | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \
         1349  +	     | aos* | aros* | cloudabi* | sortix* \
         1350  +	     | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \
         1351  +	     | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \
         1352  +	     | knetbsd* | mirbsd* | netbsd* \
         1353  +	     | bitrig* | openbsd* | solidbsd* | libertybsd* \
         1354  +	     | ekkobsd* | kfreebsd* | freebsd* | riscix* | lynxos* \
         1355  +	     | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \
         1356  +	     | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \
         1357  +	     | udi* | eabi* | lites* | ieee* | go32* | aux* | hcos* \
         1358  +	     | chorusrdb* | cegcc* | glidix* \
         1359  +	     | cygwin* | msys* | pe* | moss* | proelf* | rtems* \
         1360  +	     | midipix* | mingw32* | mingw64* | linux-gnu* | linux-android* \
         1361  +	     | linux-newlib* | linux-musl* | linux-uclibc* \
         1362  +	     | uxpv* | beos* | mpeix* | udk* | moxiebox* \
         1363  +	     | interix* | uwin* | mks* | rhapsody* | darwin* \
         1364  +	     | openstep* | oskit* | conix* | pw32* | nonstopux* \
         1365  +	     | storm-chaos* | tops10* | tenex* | tops20* | its* \
         1366  +	     | os2* | vos* | palmos* | uclinux* | nucleus* \
         1367  +	     | morphos* | superux* | rtmk* | windiss* \
         1368  +	     | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \
         1369  +	     | skyos* | haiku* | rdos* | toppers* | drops* | es* \
         1370  +	     | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \
         1371  +	     | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi*)
  1248   1372   	# Remember, each alternative MUST END IN *, to match a version number.
  1249   1373   		;;
  1250         -	-qnx*)
  1251         -		case $basic_machine in
  1252         -		    x86-* | i*86-*)
         1374  +	qnx*)
         1375  +		case $cpu in
         1376  +		    x86 | i*86)
         1377  +			;;
         1378  +		    *)
         1379  +			os=nto-$os
         1380  +			;;
         1381  +		esac
         1382  +		;;
         1383  +	hiux*)
         1384  +		os=hiuxwe2
         1385  +		;;
         1386  +	nto-qnx*)
         1387  +		;;
         1388  +	nto*)
         1389  +		os=`echo $os | sed -e 's|nto|nto-qnx|'`
         1390  +		;;
         1391  +	sim | xray | os68k* | v88r* \
         1392  +	    | windows* | osx | abug | netware* | os9* \
         1393  +	    | macos* | mpw* | magic* | mmixware* | mon960* | lnews*)
         1394  +		;;
         1395  +	linux-dietlibc)
         1396  +		os=linux-dietlibc
         1397  +		;;
         1398  +	linux*)
         1399  +		os=`echo $os | sed -e 's|linux|linux-gnu|'`
         1400  +		;;
         1401  +	lynx*178)
         1402  +		os=lynxos178
         1403  +		;;
         1404  +	lynx*5)
         1405  +		os=lynxos5
         1406  +		;;
         1407  +	lynx*)
         1408  +		os=lynxos
         1409  +		;;
         1410  +	mac*)
         1411  +		os=`echo "$os" | sed -e 's|mac|macos|'`
         1412  +		;;
         1413  +	opened*)
         1414  +		os=openedition
         1415  +		;;
         1416  +	os400*)
         1417  +		os=os400
         1418  +		;;
         1419  +	sunos5*)
         1420  +		os=`echo "$os" | sed -e 's|sunos5|solaris2|'`
         1421  +		;;
         1422  +	sunos6*)
         1423  +		os=`echo "$os" | sed -e 's|sunos6|solaris3|'`
         1424  +		;;
         1425  +	wince*)
         1426  +		os=wince
         1427  +		;;
         1428  +	utek*)
         1429  +		os=bsd
         1430  +		;;
         1431  +	dynix*)
         1432  +		os=bsd
         1433  +		;;
         1434  +	acis*)
         1435  +		os=aos
         1436  +		;;
         1437  +	atheos*)
         1438  +		os=atheos
         1439  +		;;
         1440  +	syllable*)
         1441  +		os=syllable
         1442  +		;;
         1443  +	386bsd)
         1444  +		os=bsd
         1445  +		;;
         1446  +	ctix* | uts*)
         1447  +		os=sysv
         1448  +		;;
         1449  +	nova*)
         1450  +		os=rtmk-nova
         1451  +		;;
         1452  +	ns2)
         1453  +		os=nextstep2
         1454  +		;;
         1455  +	nsk*)
         1456  +		os=nsk
         1457  +		;;
         1458  +	# Preserve the version number of sinix5.
         1459  +	sinix5.*)
         1460  +		os=`echo $os | sed -e 's|sinix|sysv|'`
         1461  +		;;
         1462  +	sinix*)
         1463  +		os=sysv4
         1464  +		;;
         1465  +	tpf*)
         1466  +		os=tpf
         1467  +		;;
         1468  +	triton*)
         1469  +		os=sysv3
         1470  +		;;
         1471  +	oss*)
         1472  +		os=sysv3
         1473  +		;;
         1474  +	svr4*)
         1475  +		os=sysv4
         1476  +		;;
         1477  +	svr3)
         1478  +		os=sysv3
         1479  +		;;
         1480  +	sysvr4)
         1481  +		os=sysv4
         1482  +		;;
         1483  +	# This must come after sysvr4.
         1484  +	sysv*)
         1485  +		;;
         1486  +	ose*)
         1487  +		os=ose
         1488  +		;;
         1489  +	*mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
         1490  +		os=mint
         1491  +		;;
         1492  +	zvmoe)
         1493  +		os=zvmoe
         1494  +		;;
         1495  +	dicos*)
         1496  +		os=dicos
         1497  +		;;
         1498  +	pikeos*)
         1499  +		# Until real need of OS specific support for
         1500  +		# particular features comes up, bare metal
         1501  +		# configurations are quite functional.
         1502  +		case $cpu in
         1503  +		    arm*)
         1504  +			os=eabi
  1253   1505   			;;
  1254   1506   		    *)
  1255         -			os=-nto$os
         1507  +			os=elf
  1256   1508   			;;
  1257   1509   		esac
  1258   1510   		;;
  1259         -	-nto-qnx*)
  1260         -		;;
  1261         -	-nto*)
  1262         -		os=`echo $os | sed -e 's|nto|nto-qnx|'`
  1263         -		;;
  1264         -	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
  1265         -	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
  1266         -	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
  1267         -		;;
  1268         -	-mac*)
  1269         -		os=`echo $os | sed -e 's|mac|macos|'`
  1270         -		;;
  1271         -	-linux-dietlibc)
  1272         -		os=-linux-dietlibc
  1273         -		;;
  1274         -	-linux*)
  1275         -		os=`echo $os | sed -e 's|linux|linux-gnu|'`
  1276         -		;;
  1277         -	-sunos5*)
  1278         -		os=`echo $os | sed -e 's|sunos5|solaris2|'`
  1279         -		;;
  1280         -	-sunos6*)
  1281         -		os=`echo $os | sed -e 's|sunos6|solaris3|'`
  1282         -		;;
  1283         -	-opened*)
  1284         -		os=-openedition
  1285         -		;;
  1286         -        -os400*)
  1287         -		os=-os400
  1288         -		;;
  1289         -	-wince*)
  1290         -		os=-wince
  1291         -		;;
  1292         -	-osfrose*)
  1293         -		os=-osfrose
  1294         -		;;
  1295         -	-osf*)
  1296         -		os=-osf
  1297         -		;;
  1298         -	-utek*)
  1299         -		os=-bsd
  1300         -		;;
  1301         -	-dynix*)
  1302         -		os=-bsd
  1303         -		;;
  1304         -	-acis*)
  1305         -		os=-aos
  1306         -		;;
  1307         -	-atheos*)
  1308         -		os=-atheos
  1309         -		;;
  1310         -	-syllable*)
  1311         -		os=-syllable
  1312         -		;;
  1313         -	-386bsd)
  1314         -		os=-bsd
  1315         -		;;
  1316         -	-ctix* | -uts*)
  1317         -		os=-sysv
  1318         -		;;
  1319         -	-nova*)
  1320         -		os=-rtmk-nova
  1321         -		;;
  1322         -	-ns2 )
  1323         -		os=-nextstep2
  1324         -		;;
  1325         -	-nsk*)
  1326         -		os=-nsk
  1327         -		;;
  1328         -	# Preserve the version number of sinix5.
  1329         -	-sinix5.*)
  1330         -		os=`echo $os | sed -e 's|sinix|sysv|'`
  1331         -		;;
  1332         -	-sinix*)
  1333         -		os=-sysv4
  1334         -		;;
  1335         -        -tpf*)
  1336         -		os=-tpf
  1337         -		;;
  1338         -	-triton*)
  1339         -		os=-sysv3
  1340         -		;;
  1341         -	-oss*)
  1342         -		os=-sysv3
  1343         -		;;
  1344         -	-svr4)
  1345         -		os=-sysv4
  1346         -		;;
  1347         -	-svr3)
  1348         -		os=-sysv3
  1349         -		;;
  1350         -	-sysvr4)
  1351         -		os=-sysv4
  1352         -		;;
  1353         -	# This must come after -sysvr4.
  1354         -	-sysv*)
  1355         -		;;
  1356         -	-ose*)
  1357         -		os=-ose
  1358         -		;;
  1359         -	-es1800*)
  1360         -		os=-ose
  1361         -		;;
  1362         -	-xenix)
  1363         -		os=-xenix
  1364         -		;;
  1365         -	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
  1366         -		os=-mint
  1367         -		;;
  1368         -	-aros*)
  1369         -		os=-aros
  1370         -		;;
  1371         -	-kaos*)
  1372         -		os=-kaos
  1373         -		;;
  1374         -	-zvmoe)
  1375         -		os=-zvmoe
  1376         -		;;
  1377         -	-none)
         1511  +	nacl*)
         1512  +		;;
         1513  +	ios)
         1514  +		;;
         1515  +	none)
         1516  +		;;
         1517  +	*-eabi)
  1378   1518   		;;
  1379   1519   	*)
  1380         -		# Get rid of the `-' at the beginning of $os.
  1381         -		os=`echo $os | sed 's/[^-]*-//'`
  1382         -		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
         1520  +		echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2
  1383   1521   		exit 1
  1384   1522   		;;
  1385   1523   esac
  1386   1524   else
  1387   1525   
  1388   1526   # Here we handle the default operating systems that come with various machines.
  1389   1527   # The value should be what the vendor currently ships out the door with their
................................................................................
  1391   1529   
  1392   1530   # Note that if you're going to try to match "-MANUFACTURER" here (say,
  1393   1531   # "-sun"), then you have to tell the case statement up towards the top
  1394   1532   # that MANUFACTURER isn't an operating system.  Otherwise, code above
  1395   1533   # will signal an error saying that MANUFACTURER isn't an operating
  1396   1534   # system, and we'll never get to this point.
  1397   1535   
  1398         -case $basic_machine in
  1399         -        score-*)
  1400         -		os=-elf
         1536  +case $cpu-$vendor in
         1537  +	score-*)
         1538  +		os=elf
  1401   1539   		;;
  1402         -        spu-*)
  1403         -		os=-elf
         1540  +	spu-*)
         1541  +		os=elf
  1404   1542   		;;
  1405   1543   	*-acorn)
  1406         -		os=-riscix1.2
         1544  +		os=riscix1.2
  1407   1545   		;;
  1408   1546   	arm*-rebel)
  1409         -		os=-linux
         1547  +		os=linux
  1410   1548   		;;
  1411   1549   	arm*-semi)
  1412         -		os=-aout
         1550  +		os=aout
  1413   1551   		;;
  1414         -        c4x-* | tic4x-*)
  1415         -        	os=-coff
         1552  +	c4x-* | tic4x-*)
         1553  +		os=coff
         1554  +		;;
         1555  +	c8051-*)
         1556  +		os=elf
         1557  +		;;
         1558  +	clipper-intergraph)
         1559  +		os=clix
         1560  +		;;
         1561  +	hexagon-*)
         1562  +		os=elf
         1563  +		;;
         1564  +	tic54x-*)
         1565  +		os=coff
         1566  +		;;
         1567  +	tic55x-*)
         1568  +		os=coff
         1569  +		;;
         1570  +	tic6x-*)
         1571  +		os=coff
  1416   1572   		;;
  1417   1573   	# This must come before the *-dec entry.
  1418   1574   	pdp10-*)
  1419         -		os=-tops20
         1575  +		os=tops20
  1420   1576   		;;
  1421   1577   	pdp11-*)
  1422         -		os=-none
         1578  +		os=none
  1423   1579   		;;
  1424   1580   	*-dec | vax-*)
  1425         -		os=-ultrix4.2
         1581  +		os=ultrix4.2
  1426   1582   		;;
  1427   1583   	m68*-apollo)
  1428         -		os=-domain
         1584  +		os=domain
  1429   1585   		;;
  1430   1586   	i386-sun)
  1431         -		os=-sunos4.0.2
         1587  +		os=sunos4.0.2
  1432   1588   		;;
  1433   1589   	m68000-sun)
  1434         -		os=-sunos3
  1435         -		# This also exists in the configure program, but was not the
  1436         -		# default.
  1437         -		# os=-sunos4
         1590  +		os=sunos3
  1438   1591   		;;
  1439   1592   	m68*-cisco)
  1440         -		os=-aout
         1593  +		os=aout
  1441   1594   		;;
  1442         -        mep-*)
  1443         -		os=-elf
         1595  +	mep-*)
         1596  +		os=elf
  1444   1597   		;;
  1445   1598   	mips*-cisco)
  1446         -		os=-elf
         1599  +		os=elf
  1447   1600   		;;
  1448   1601   	mips*-*)
  1449         -		os=-elf
         1602  +		os=elf
  1450   1603   		;;
  1451   1604   	or32-*)
  1452         -		os=-coff
         1605  +		os=coff
  1453   1606   		;;
  1454   1607   	*-tti)	# must be before sparc entry or we get the wrong os.
  1455         -		os=-sysv3
         1608  +		os=sysv3
  1456   1609   		;;
  1457   1610   	sparc-* | *-sun)
  1458         -		os=-sunos4.1.1
         1611  +		os=sunos4.1.1
         1612  +		;;
         1613  +	pru-*)
         1614  +		os=elf
  1459   1615   		;;
  1460   1616   	*-be)
  1461         -		os=-beos
  1462         -		;;
  1463         -	*-haiku)
  1464         -		os=-haiku
         1617  +		os=beos
  1465   1618   		;;
  1466   1619   	*-ibm)
  1467         -		os=-aix
         1620  +		os=aix
  1468   1621   		;;
  1469         -    	*-knuth)
  1470         -		os=-mmixware
         1622  +	*-knuth)
         1623  +		os=mmixware
  1471   1624   		;;
  1472   1625   	*-wec)
  1473         -		os=-proelf
         1626  +		os=proelf
  1474   1627   		;;
  1475   1628   	*-winbond)
  1476         -		os=-proelf
         1629  +		os=proelf
  1477   1630   		;;
  1478   1631   	*-oki)
  1479         -		os=-proelf
         1632  +		os=proelf
  1480   1633   		;;
  1481   1634   	*-hp)
  1482         -		os=-hpux
         1635  +		os=hpux
  1483   1636   		;;
  1484   1637   	*-hitachi)
  1485         -		os=-hiux
         1638  +		os=hiux
  1486   1639   		;;
  1487   1640   	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
  1488         -		os=-sysv
         1641  +		os=sysv
  1489   1642   		;;
  1490   1643   	*-cbm)
  1491         -		os=-amigaos
         1644  +		os=amigaos
  1492   1645   		;;
  1493   1646   	*-dg)
  1494         -		os=-dgux
         1647  +		os=dgux
  1495   1648   		;;
  1496   1649   	*-dolphin)
  1497         -		os=-sysv3
         1650  +		os=sysv3
  1498   1651   		;;
  1499   1652   	m68k-ccur)
  1500         -		os=-rtu
         1653  +		os=rtu
  1501   1654   		;;
  1502   1655   	m88k-omron*)
  1503         -		os=-luna
         1656  +		os=luna
  1504   1657   		;;
  1505         -	*-next )
  1506         -		os=-nextstep
         1658  +	*-next)
         1659  +		os=nextstep
  1507   1660   		;;
  1508   1661   	*-sequent)
  1509         -		os=-ptx
         1662  +		os=ptx
  1510   1663   		;;
  1511   1664   	*-crds)
  1512         -		os=-unos
         1665  +		os=unos
  1513   1666   		;;
  1514   1667   	*-ns)
  1515         -		os=-genix
         1668  +		os=genix
  1516   1669   		;;
  1517   1670   	i370-*)
  1518         -		os=-mvs
  1519         -		;;
  1520         -	*-next)
  1521         -		os=-nextstep3
         1671  +		os=mvs
  1522   1672   		;;
  1523   1673   	*-gould)
  1524         -		os=-sysv
         1674  +		os=sysv
  1525   1675   		;;
  1526   1676   	*-highlevel)
  1527         -		os=-bsd
         1677  +		os=bsd
  1528   1678   		;;
  1529   1679   	*-encore)
  1530         -		os=-bsd
         1680  +		os=bsd
  1531   1681   		;;
  1532   1682   	*-sgi)
  1533         -		os=-irix
         1683  +		os=irix
  1534   1684   		;;
  1535   1685   	*-siemens)
  1536         -		os=-sysv4
         1686  +		os=sysv4
  1537   1687   		;;
  1538   1688   	*-masscomp)
  1539         -		os=-rtu
         1689  +		os=rtu
  1540   1690   		;;
  1541   1691   	f30[01]-fujitsu | f700-fujitsu)
  1542         -		os=-uxpv
         1692  +		os=uxpv
  1543   1693   		;;
  1544   1694   	*-rom68k)
  1545         -		os=-coff
         1695  +		os=coff
  1546   1696   		;;
  1547   1697   	*-*bug)
  1548         -		os=-coff
         1698  +		os=coff
  1549   1699   		;;
  1550   1700   	*-apple)
  1551         -		os=-macos
         1701  +		os=macos
  1552   1702   		;;
  1553   1703   	*-atari*)
  1554         -		os=-mint
         1704  +		os=mint
         1705  +		;;
         1706  +	*-wrs)
         1707  +		os=vxworks
  1555   1708   		;;
  1556   1709   	*)
  1557         -		os=-none
         1710  +		os=none
  1558   1711   		;;
  1559   1712   esac
  1560   1713   fi
  1561   1714   
  1562   1715   # Here we handle the case where we know the os, and the CPU type, but not the
  1563   1716   # manufacturer.  We pick the logical manufacturer.
  1564         -vendor=unknown
  1565         -case $basic_machine in
  1566         -	*-unknown)
         1717  +case $vendor in
         1718  +	unknown)
  1567   1719   		case $os in
  1568         -			-riscix*)
         1720  +			riscix*)
  1569   1721   				vendor=acorn
  1570   1722   				;;
  1571         -			-sunos*)
         1723  +			sunos*)
  1572   1724   				vendor=sun
  1573   1725   				;;
  1574         -			-aix*)
         1726  +			cnk*|-aix*)
  1575   1727   				vendor=ibm
  1576   1728   				;;
  1577         -			-beos*)
         1729  +			beos*)
  1578   1730   				vendor=be
  1579   1731   				;;
  1580         -			-hpux*)
         1732  +			hpux*)
  1581   1733   				vendor=hp
  1582   1734   				;;
  1583         -			-mpeix*)
         1735  +			mpeix*)
  1584   1736   				vendor=hp
  1585   1737   				;;
  1586         -			-hiux*)
         1738  +			hiux*)
  1587   1739   				vendor=hitachi
  1588   1740   				;;
  1589         -			-unos*)
         1741  +			unos*)
  1590   1742   				vendor=crds
  1591   1743   				;;
  1592         -			-dgux*)
         1744  +			dgux*)
  1593   1745   				vendor=dg
  1594   1746   				;;
  1595         -			-luna*)
         1747  +			luna*)
  1596   1748   				vendor=omron
  1597   1749   				;;
  1598         -			-genix*)
         1750  +			genix*)
  1599   1751   				vendor=ns
  1600   1752   				;;
  1601         -			-mvs* | -opened*)
         1753  +			clix*)
         1754  +				vendor=intergraph
         1755  +				;;
         1756  +			mvs* | opened*)
  1602   1757   				vendor=ibm
  1603   1758   				;;
  1604         -			-os400*)
         1759  +			os400*)
  1605   1760   				vendor=ibm
  1606   1761   				;;
  1607         -			-ptx*)
         1762  +			ptx*)
  1608   1763   				vendor=sequent
  1609   1764   				;;
  1610         -			-tpf*)
         1765  +			tpf*)
  1611   1766   				vendor=ibm
  1612   1767   				;;
  1613         -			-vxsim* | -vxworks* | -windiss*)
         1768  +			vxsim* | vxworks* | windiss*)
  1614   1769   				vendor=wrs
  1615   1770   				;;
  1616         -			-aux*)
         1771  +			aux*)
  1617   1772   				vendor=apple
  1618   1773   				;;
  1619         -			-hms*)
         1774  +			hms*)
  1620   1775   				vendor=hitachi
  1621   1776   				;;
  1622         -			-mpw* | -macos*)
         1777  +			mpw* | macos*)
  1623   1778   				vendor=apple
  1624   1779   				;;
  1625         -			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
         1780  +			*mint | mint[0-9]* | *MiNT | MiNT[0-9]*)
  1626   1781   				vendor=atari
  1627   1782   				;;
  1628         -			-vos*)
         1783  +			vos*)
  1629   1784   				vendor=stratus
  1630   1785   				;;
  1631   1786   		esac
  1632         -		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
  1633   1787   		;;
  1634   1788   esac
  1635   1789   
  1636         -echo $basic_machine$os
         1790  +echo "$cpu-$vendor-$os"
  1637   1791   exit
  1638   1792   
  1639   1793   # Local variables:
  1640         -# eval: (add-hook 'write-file-hooks 'time-stamp)
         1794  +# eval: (add-hook 'before-save-hook 'time-stamp)
  1641   1795   # time-stamp-start: "timestamp='"
  1642   1796   # time-stamp-format: "%:y-%02m-%02d"
  1643   1797   # time-stamp-end: "'"
  1644   1798   # End:

Changes to configure.

     1      1   #! /bin/sh
     2      2   # Guess values for system-dependent variables and create Makefiles.
     3         -# Generated by GNU Autoconf 2.69 for sqlite 3.27.0.
            3  +# Generated by GNU Autoconf 2.69 for sqlite 3.33.0.
     4      4   #
     5      5   #
     6      6   # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
     7      7   #
     8      8   #
     9      9   # This configure script is free software; the Free Software Foundation
    10     10   # gives unlimited permission to copy, distribute and modify it.
................................................................................
   722    722   subdirs=
   723    723   MFLAGS=
   724    724   MAKEFLAGS=
   725    725   
   726    726   # Identity of this package.
   727    727   PACKAGE_NAME='sqlite'
   728    728   PACKAGE_TARNAME='sqlite'
   729         -PACKAGE_VERSION='3.27.0'
   730         -PACKAGE_STRING='sqlite 3.27.0'
          729  +PACKAGE_VERSION='3.33.0'
          730  +PACKAGE_STRING='sqlite 3.33.0'
   731    731   PACKAGE_BUGREPORT=''
   732    732   PACKAGE_URL=''
   733    733   
   734    734   # Factoring default headers for most tests.
   735    735   ac_includes_default="\
   736    736   #include <stdio.h>
   737    737   #ifdef HAVE_SYS_TYPES_H
................................................................................
   902    902   with_readline_lib
   903    903   with_readline_inc
   904    904   enable_debug
   905    905   enable_amalgamation
   906    906   enable_load_extension
   907    907   enable_memsys5
   908    908   enable_memsys3
          909  +enable_all
   909    910   enable_fts3
   910    911   enable_fts4
   911    912   enable_fts5
   912    913   enable_json1
   913    914   enable_update_limit
   914    915   enable_geopoly
   915    916   enable_rtree
................................................................................
  1462   1463   #
  1463   1464   # Report the --help message.
  1464   1465   #
  1465   1466   if test "$ac_init_help" = "long"; then
  1466   1467     # Omit some internal or obsolete options to make the list less imposing.
  1467   1468     # This message is too long to be a string in the A/UX 3.1 sh.
  1468   1469     cat <<_ACEOF
  1469         -\`configure' configures sqlite 3.27.0 to adapt to many kinds of systems.
         1470  +\`configure' configures sqlite 3.33.0 to adapt to many kinds of systems.
  1470   1471   
  1471   1472   Usage: $0 [OPTION]... [VAR=VALUE]...
  1472   1473   
  1473   1474   To assign environment variables (e.g., CC, CFLAGS...), specify them as
  1474   1475   VAR=VALUE.  See below for descriptions of some of the useful variables.
  1475   1476   
  1476   1477   Defaults for the options are specified in brackets.
................................................................................
  1527   1528     --build=BUILD     configure for building on BUILD [guessed]
  1528   1529     --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  1529   1530   _ACEOF
  1530   1531   fi
  1531   1532   
  1532   1533   if test -n "$ac_init_help"; then
  1533   1534     case $ac_init_help in
  1534         -     short | recursive ) echo "Configuration of sqlite 3.27.0:";;
         1535  +     short | recursive ) echo "Configuration of sqlite 3.33.0:";;
  1535   1536      esac
  1536   1537     cat <<\_ACEOF
  1537   1538   
  1538   1539   Optional Features:
  1539   1540     --disable-option-checking  ignore unrecognized --enable/--with options
  1540   1541     --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  1541   1542     --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
  1555   1556     --enable-debug          enable debugging & verbose explain
  1556   1557     --disable-amalgamation  Disable the amalgamation and instead build all files
  1557   1558                             separately
  1558   1559     --disable-load-extension
  1559   1560                             Disable loading of external extensions
  1560   1561     --enable-memsys5        Enable MEMSYS5
  1561   1562     --enable-memsys3        Enable MEMSYS3
         1563  +  --enable-all            Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions
  1562   1564     --enable-fts3           Enable the FTS3 extension
  1563   1565     --enable-fts4           Enable the FTS4 extension
  1564   1566     --enable-fts5           Enable the FTS5 extension
  1565   1567     --enable-json1          Enable the JSON1 extension
  1566   1568     --enable-update-limit   Enable the UPDATE/DELETE LIMIT clause
  1567   1569     --enable-geopoly        Enable the GEOPOLY extension
  1568   1570     --enable-rtree          Enable the RTREE extension
................................................................................
  1653   1655       cd "$ac_pwd" || { ac_status=$?; break; }
  1654   1656     done
  1655   1657   fi
  1656   1658   
  1657   1659   test -n "$ac_init_help" && exit $ac_status
  1658   1660   if $ac_init_version; then
  1659   1661     cat <<\_ACEOF
  1660         -sqlite configure 3.27.0
         1662  +sqlite configure 3.33.0
  1661   1663   generated by GNU Autoconf 2.69
  1662   1664   
  1663   1665   Copyright (C) 2012 Free Software Foundation, Inc.
  1664   1666   This configure script is free software; the Free Software Foundation
  1665   1667   gives unlimited permission to copy, distribute and modify it.
  1666   1668   _ACEOF
  1667   1669     exit
................................................................................
  2072   2074     eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  2073   2075   
  2074   2076   } # ac_fn_c_check_header_mongrel
  2075   2077   cat >config.log <<_ACEOF
  2076   2078   This file contains any messages produced by compilers while
  2077   2079   running configure, to aid debugging if configure makes a mistake.
  2078   2080   
  2079         -It was created by sqlite $as_me 3.27.0, which was
         2081  +It was created by sqlite $as_me 3.33.0, which was
  2080   2082   generated by GNU Autoconf 2.69.  Invocation command line was
  2081   2083   
  2082   2084     $ $0 $@
  2083   2085   
  2084   2086   _ACEOF
  2085   2087   exec 5>>config.log
  2086   2088   {
................................................................................
  3930   3932   { $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5
  3931   3933   $as_echo_n "checking the name lister ($NM) interface... " >&6; }
  3932   3934   if ${lt_cv_nm_interface+:} false; then :
  3933   3935     $as_echo_n "(cached) " >&6
  3934   3936   else
  3935   3937     lt_cv_nm_interface="BSD nm"
  3936   3938     echo "int some_variable = 0;" > conftest.$ac_ext
  3937         -  (eval echo "\"\$as_me:3937: $ac_compile\"" >&5)
         3939  +  (eval echo "\"\$as_me:3939: $ac_compile\"" >&5)
  3938   3940     (eval "$ac_compile" 2>conftest.err)
  3939   3941     cat conftest.err >&5
  3940         -  (eval echo "\"\$as_me:3940: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
         3942  +  (eval echo "\"\$as_me:3942: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
  3941   3943     (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
  3942   3944     cat conftest.err >&5
  3943         -  (eval echo "\"\$as_me:3943: output\"" >&5)
         3945  +  (eval echo "\"\$as_me:3945: output\"" >&5)
  3944   3946     cat conftest.out >&5
  3945   3947     if $GREP 'External.*some_variable' conftest.out > /dev/null; then
  3946   3948       lt_cv_nm_interface="MS dumpbin"
  3947   3949     fi
  3948   3950     rm -f conftest*
  3949   3951   fi
  3950   3952   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5
................................................................................
  5142   5144   	;;
  5143   5145       esac
  5144   5146     fi
  5145   5147     rm -rf conftest*
  5146   5148     ;;
  5147   5149   *-*-irix6*)
  5148   5150     # Find out which ABI we are using.
  5149         -  echo '#line 5149 "configure"' > conftest.$ac_ext
         5151  +  echo '#line 5151 "configure"' > conftest.$ac_ext
  5150   5152     if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
  5151   5153     (eval $ac_compile) 2>&5
  5152   5154     ac_status=$?
  5153   5155     $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  5154   5156     test $ac_status = 0; }; then
  5155   5157       if test "$lt_cv_prog_gnu_ld" = yes; then
  5156   5158         case `/usr/bin/file conftest.$ac_objext` in
................................................................................
  6667   6669      # Note that $ac_compile itself does not contain backslashes and begins
  6668   6670      # with a dollar sign (not a hyphen), so the echo should work correctly.
  6669   6671      # The option is referenced via a variable to avoid confusing sed.
  6670   6672      lt_compile=`echo "$ac_compile" | $SED \
  6671   6673      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  6672   6674      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  6673   6675      -e 's:$: $lt_compiler_flag:'`
  6674         -   (eval echo "\"\$as_me:6674: $lt_compile\"" >&5)
         6676  +   (eval echo "\"\$as_me:6676: $lt_compile\"" >&5)
  6675   6677      (eval "$lt_compile" 2>conftest.err)
  6676   6678      ac_status=$?
  6677   6679      cat conftest.err >&5
  6678         -   echo "$as_me:6678: \$? = $ac_status" >&5
         6680  +   echo "$as_me:6680: \$? = $ac_status" >&5
  6679   6681      if (exit $ac_status) && test -s "$ac_outfile"; then
  6680   6682        # The compiler can only warn and ignore the option if not recognized
  6681   6683        # So say no if there are warnings other than the usual output.
  6682   6684        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  6683   6685        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  6684   6686        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  6685   6687          lt_cv_prog_compiler_rtti_exceptions=yes
................................................................................
  7006   7008      # Note that $ac_compile itself does not contain backslashes and begins
  7007   7009      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7008   7010      # The option is referenced via a variable to avoid confusing sed.
  7009   7011      lt_compile=`echo "$ac_compile" | $SED \
  7010   7012      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7011   7013      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7012   7014      -e 's:$: $lt_compiler_flag:'`
  7013         -   (eval echo "\"\$as_me:7013: $lt_compile\"" >&5)
         7015  +   (eval echo "\"\$as_me:7015: $lt_compile\"" >&5)
  7014   7016      (eval "$lt_compile" 2>conftest.err)
  7015   7017      ac_status=$?
  7016   7018      cat conftest.err >&5
  7017         -   echo "$as_me:7017: \$? = $ac_status" >&5
         7019  +   echo "$as_me:7019: \$? = $ac_status" >&5
  7018   7020      if (exit $ac_status) && test -s "$ac_outfile"; then
  7019   7021        # The compiler can only warn and ignore the option if not recognized
  7020   7022        # So say no if there are warnings other than the usual output.
  7021   7023        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  7022   7024        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  7023   7025        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  7024   7026          lt_cv_prog_compiler_pic_works=yes
................................................................................
  7111   7113      # (2) before a word containing "conftest.", or (3) at the end.
  7112   7114      # Note that $ac_compile itself does not contain backslashes and begins
  7113   7115      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7114   7116      lt_compile=`echo "$ac_compile" | $SED \
  7115   7117      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7116   7118      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7117   7119      -e 's:$: $lt_compiler_flag:'`
  7118         -   (eval echo "\"\$as_me:7118: $lt_compile\"" >&5)
         7120  +   (eval echo "\"\$as_me:7120: $lt_compile\"" >&5)
  7119   7121      (eval "$lt_compile" 2>out/conftest.err)
  7120   7122      ac_status=$?
  7121   7123      cat out/conftest.err >&5
  7122         -   echo "$as_me:7122: \$? = $ac_status" >&5
         7124  +   echo "$as_me:7124: \$? = $ac_status" >&5
  7123   7125      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7124   7126      then
  7125   7127        # The compiler can only warn and ignore the option if not recognized
  7126   7128        # So say no if there are warnings
  7127   7129        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7128   7130        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7129   7131        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
  7166   7168      # (2) before a word containing "conftest.", or (3) at the end.
  7167   7169      # Note that $ac_compile itself does not contain backslashes and begins
  7168   7170      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7169   7171      lt_compile=`echo "$ac_compile" | $SED \
  7170   7172      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7171   7173      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7172   7174      -e 's:$: $lt_compiler_flag:'`
  7173         -   (eval echo "\"\$as_me:7173: $lt_compile\"" >&5)
         7175  +   (eval echo "\"\$as_me:7175: $lt_compile\"" >&5)
  7174   7176      (eval "$lt_compile" 2>out/conftest.err)
  7175   7177      ac_status=$?
  7176   7178      cat out/conftest.err >&5
  7177         -   echo "$as_me:7177: \$? = $ac_status" >&5
         7179  +   echo "$as_me:7179: \$? = $ac_status" >&5
  7178   7180      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7179   7181      then
  7180   7182        # The compiler can only warn and ignore the option if not recognized
  7181   7183        # So say no if there are warnings
  7182   7184        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7183   7185        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7184   7186        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
  9546   9548   else
  9547   9549     	  if test "$cross_compiling" = yes; then :
  9548   9550     lt_cv_dlopen_self=cross
  9549   9551   else
  9550   9552     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
  9551   9553     lt_status=$lt_dlunknown
  9552   9554     cat > conftest.$ac_ext <<_LT_EOF
  9553         -#line 9553 "configure"
         9555  +#line 9555 "configure"
  9554   9556   #include "confdefs.h"
  9555   9557   
  9556   9558   #if HAVE_DLFCN_H
  9557   9559   #include <dlfcn.h>
  9558   9560   #endif
  9559   9561   
  9560   9562   #include <stdio.h>
................................................................................
  9642   9644   else
  9643   9645     	  if test "$cross_compiling" = yes; then :
  9644   9646     lt_cv_dlopen_self_static=cross
  9645   9647   else
  9646   9648     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
  9647   9649     lt_status=$lt_dlunknown
  9648   9650     cat > conftest.$ac_ext <<_LT_EOF
  9649         -#line 9649 "configure"
         9651  +#line 9651 "configure"
  9650   9652   #include "confdefs.h"
  9651   9653   
  9652   9654   #if HAVE_DLFCN_H
  9653   9655   #include <dlfcn.h>
  9654   9656   #endif
  9655   9657   
  9656   9658   #include <stdio.h>
................................................................................
 11262  11264   #########
 11263  11265   # See whether we should use the amalgamation to build
 11264  11266   # Check whether --enable-amalgamation was given.
 11265  11267   if test "${enable_amalgamation+set}" = set; then :
 11266  11268     enableval=$enable_amalgamation;
 11267  11269   fi
 11268  11270   
 11269         -if test "${enable_amalgamation}" == "no" ; then
        11271  +if test "${enable_amalgamation}" = "no" ; then
 11270  11272     USE_AMALGAMATION=0
 11271  11273   fi
 11272  11274   
 11273  11275   
 11274  11276   #########
 11275  11277   # Look for zlib.  Only needed by extensions and by the sqlite3.exe shell
 11276  11278   for ac_header in zlib.h
................................................................................
 11445  11447     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS3"
 11446  11448     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 11447  11449   $as_echo "yes" >&6; }
 11448  11450   else
 11449  11451     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 11450  11452   $as_echo "no" >&6; }
 11451  11453   fi
        11454  +
        11455  +########
        11456  +# The --enable-extensions argument is short-hand to enable
        11457  +# multiple extensions.
        11458  +# Check whether --enable-all was given.
        11459  +if test "${enable_all+set}" = set; then :
        11460  +  enableval=$enable_all;
        11461  +fi
        11462  +
 11452  11463   
 11453  11464   #########
 11454  11465   # See whether we should enable Full Text Search extensions
 11455  11466   # Check whether --enable-fts3 was given.
 11456  11467   if test "${enable_fts3+set}" = set; then :
 11457  11468     enableval=$enable_fts3;
 11458  11469   fi
................................................................................
 11461  11472     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
 11462  11473   fi
 11463  11474   # Check whether --enable-fts4 was given.
 11464  11475   if test "${enable_fts4+set}" = set; then :
 11465  11476     enableval=$enable_fts4;
 11466  11477   fi
 11467  11478   
 11468         -if test "${enable_fts4}" = "yes" ; then
        11479  +if test "${enable_fts4}" = "yes" -o "${enable_all}" = "yes" ; then
 11469  11480     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
 11470  11481     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
 11471  11482   $as_echo_n "checking for library containing log... " >&6; }
 11472  11483   if ${ac_cv_search_log+:} false; then :
 11473  11484     $as_echo_n "(cached) " >&6
 11474  11485   else
 11475  11486     ac_func_search_save_LIBS=$LIBS
................................................................................
 11525  11536   
 11526  11537   fi
 11527  11538   # Check whether --enable-fts5 was given.
 11528  11539   if test "${enable_fts5+set}" = set; then :
 11529  11540     enableval=$enable_fts5;
 11530  11541   fi
 11531  11542   
 11532         -if test "${enable_fts5}" = "yes" ; then
        11543  +if test "${enable_fts5}" = "yes" -o "${enable_all}" = "yes" ; then
 11533  11544     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
 11534  11545     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing log" >&5
 11535  11546   $as_echo_n "checking for library containing log... " >&6; }
 11536  11547   if ${ac_cv_search_log+:} false; then :
 11537  11548     $as_echo_n "(cached) " >&6
 11538  11549   else
 11539  11550     ac_func_search_save_LIBS=$LIBS
................................................................................
 11592  11603   #########
 11593  11604   # See whether we should enable JSON1
 11594  11605   # Check whether --enable-json1 was given.
 11595  11606   if test "${enable_json1+set}" = set; then :
 11596  11607     enableval=$enable_json1;
 11597  11608   fi
 11598  11609   
 11599         -if test "${enable_json1}" = "yes" ; then
        11610  +if test "${enable_json1}" = "yes" -o "${enable_all}" = "yes" ; then
 11600  11611     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
 11601  11612   fi
 11602  11613   
 11603  11614   #########
 11604  11615   # See whether we should enable the LIMIT clause on UPDATE and DELETE
 11605  11616   # statements.
 11606  11617   # Check whether --enable-update-limit was given.
 11607  11618   if test "${enable_update_limit+set}" = set; then :
 11608  11619     enableval=$enable_update_limit;
 11609  11620   fi
 11610  11621   
 11611         -if test "${enable_udlimit}" = "yes" ; then
        11622  +if test "${enable_update_limit}" = "yes" ; then
 11612  11623     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT"
 11613  11624   fi
 11614  11625   
 11615  11626   #########
 11616  11627   # See whether we should enable GEOPOLY
 11617  11628   # Check whether --enable-geopoly was given.
 11618  11629   if test "${enable_geopoly+set}" = set; then :
 11619  11630     enableval=$enable_geopoly; enable_geopoly=yes
 11620  11631   else
 11621  11632     enable_geopoly=no
 11622  11633   fi
 11623  11634   
 11624         -if test "${enable_geopoly}" = "yes" ; then
        11635  +if test "${enable_geopoly}" = "yes" -o "${enable_all}" = "yes" ; then
 11625  11636     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_GEOPOLY"
 11626  11637     enable_rtree=yes
 11627  11638   fi
 11628  11639   
 11629  11640   #########
 11630  11641   # See whether we should enable RTREE
 11631  11642   # Check whether --enable-rtree was given.
................................................................................
 11640  11651   #########
 11641  11652   # See whether we should enable the SESSION extension
 11642  11653   # Check whether --enable-session was given.
 11643  11654   if test "${enable_session+set}" = set; then :
 11644  11655     enableval=$enable_session;
 11645  11656   fi
 11646  11657   
 11647         -if test "${enable_session}" = "yes" ; then
        11658  +if test "${enable_session}" = "yes" -o "${enable_all}" = "yes" ; then
 11648  11659     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
 11649  11660     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
 11650  11661   fi
 11651  11662   
 11652  11663   #########
 11653  11664   # attempt to duplicate any OMITS and ENABLES into the ${OPT_FEATURE_FLAGS} parameter
 11654  11665   for option in $CFLAGS $CPPFLAGS
................................................................................
 12228  12239   test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
 12229  12240   
 12230  12241   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 12231  12242   # Save the log message, to keep $0 and so on meaningful, and to
 12232  12243   # report actual input values of CONFIG_FILES etc. instead of their
 12233  12244   # values after options handling.
 12234  12245   ac_log="
 12235         -This file was extended by sqlite $as_me 3.27.0, which was
        12246  +This file was extended by sqlite $as_me 3.33.0, which was
 12236  12247   generated by GNU Autoconf 2.69.  Invocation command line was
 12237  12248   
 12238  12249     CONFIG_FILES    = $CONFIG_FILES
 12239  12250     CONFIG_HEADERS  = $CONFIG_HEADERS
 12240  12251     CONFIG_LINKS    = $CONFIG_LINKS
 12241  12252     CONFIG_COMMANDS = $CONFIG_COMMANDS
 12242  12253     $ $0 $@
................................................................................
 12294  12305   
 12295  12306   Report bugs to the package provider."
 12296  12307   
 12297  12308   _ACEOF
 12298  12309   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 12299  12310   ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 12300  12311   ac_cs_version="\\
 12301         -sqlite config.status 3.27.0
        12312  +sqlite config.status 3.33.0
 12302  12313   configured by $0, generated by GNU Autoconf 2.69,
 12303  12314     with options \\"\$ac_cs_config\\"
 12304  12315   
 12305  12316   Copyright (C) 2012 Free Software Foundation, Inc.
 12306  12317   This config.status script is free software; the Free Software Foundation
 12307  12318   gives unlimited permission to copy, distribute and modify it."
 12308  12319   

Changes to configure.ac.

   565    565   fi
   566    566   AC_SUBST(TARGET_DEBUG)
   567    567   
   568    568   #########
   569    569   # See whether we should use the amalgamation to build
   570    570   AC_ARG_ENABLE(amalgamation, AC_HELP_STRING([--disable-amalgamation],
   571    571         [Disable the amalgamation and instead build all files separately]))
   572         -if test "${enable_amalgamation}" == "no" ; then
          572  +if test "${enable_amalgamation}" = "no" ; then
   573    573     USE_AMALGAMATION=0
   574    574   fi
   575    575   AC_SUBST(USE_AMALGAMATION)
   576    576   
   577    577   #########
   578    578   # Look for zlib.  Only needed by extensions and by the sqlite3.exe shell
   579    579   AC_CHECK_HEADERS(zlib.h)
................................................................................
   609    609   if test "${enable_memsys3}" = "yes" -a "${enable_memsys5}" = "no"; then
   610    610     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_MEMSYS3"
   611    611     AC_MSG_RESULT([yes])
   612    612   else
   613    613     AC_MSG_RESULT([no])
   614    614   fi
   615    615   
          616  +########
          617  +# The --enable-extensions argument is short-hand to enable
          618  +# multiple extensions.
          619  +AC_ARG_ENABLE(all, AC_HELP_STRING([--enable-all],
          620  +      [Enable FTS4, FTS5, Geopoly, JSON, RTree, Sessions]))
          621  +
   616    622   #########
   617    623   # See whether we should enable Full Text Search extensions
   618    624   AC_ARG_ENABLE(fts3, AC_HELP_STRING([--enable-fts3],
   619    625         [Enable the FTS3 extension]))
   620    626   if test "${enable_fts3}" = "yes" ; then
   621    627     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS3"
   622    628   fi
   623    629   AC_ARG_ENABLE(fts4, AC_HELP_STRING([--enable-fts4],
   624    630         [Enable the FTS4 extension]))
   625         -if test "${enable_fts4}" = "yes" ; then
          631  +if test "${enable_fts4}" = "yes" -o "${enable_all}" = "yes" ; then
   626    632     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS4"
   627    633     AC_SEARCH_LIBS([log],[m])
   628    634   fi
   629    635   AC_ARG_ENABLE(fts5, AC_HELP_STRING([--enable-fts5],
   630    636         [Enable the FTS5 extension]))
   631         -if test "${enable_fts5}" = "yes" ; then
          637  +if test "${enable_fts5}" = "yes" -o "${enable_all}" = "yes" ; then
   632    638     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_FTS5"
   633    639     AC_SEARCH_LIBS([log],[m])
   634    640   fi
   635    641   
   636    642   #########
   637    643   # See whether we should enable JSON1
   638    644   AC_ARG_ENABLE(json1, AC_HELP_STRING([--enable-json1],[Enable the JSON1 extension]))
   639         -if test "${enable_json1}" = "yes" ; then
          645  +if test "${enable_json1}" = "yes" -o "${enable_all}" = "yes" ; then
   640    646     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_JSON1"
   641    647   fi
   642    648   
   643    649   #########
   644    650   # See whether we should enable the LIMIT clause on UPDATE and DELETE
   645    651   # statements.
   646    652   AC_ARG_ENABLE(update-limit, AC_HELP_STRING([--enable-update-limit],
   647    653         [Enable the UPDATE/DELETE LIMIT clause]))
   648         -if test "${enable_udlimit}" = "yes" ; then
          654  +if test "${enable_update_limit}" = "yes" ; then
   649    655     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT"
   650    656   fi
   651    657   
   652    658   #########
   653    659   # See whether we should enable GEOPOLY
   654    660   AC_ARG_ENABLE(geopoly, AC_HELP_STRING([--enable-geopoly],
   655    661         [Enable the GEOPOLY extension]),
   656    662         [enable_geopoly=yes],[enable_geopoly=no])
   657         -if test "${enable_geopoly}" = "yes" ; then
          663  +if test "${enable_geopoly}" = "yes" -o "${enable_all}" = "yes" ; then
   658    664     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_GEOPOLY"
   659    665     enable_rtree=yes
   660    666   fi
   661    667   
   662    668   #########
   663    669   # See whether we should enable RTREE
   664    670   AC_ARG_ENABLE(rtree, AC_HELP_STRING([--enable-rtree],
................................................................................
   667    673     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_RTREE"
   668    674   fi
   669    675   
   670    676   #########
   671    677   # See whether we should enable the SESSION extension
   672    678   AC_ARG_ENABLE(session, AC_HELP_STRING([--enable-session],
   673    679         [Enable the SESSION extension]))
   674         -if test "${enable_session}" = "yes" ; then
          680  +if test "${enable_session}" = "yes" -o "${enable_all}" = "yes" ; then
   675    681     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_SESSION"
   676    682     OPT_FEATURE_FLAGS="${OPT_FEATURE_FLAGS} -DSQLITE_ENABLE_PREUPDATE_HOOK"
   677    683   fi
   678    684   
   679    685   #########
   680    686   # attempt to duplicate any OMITS and ENABLES into the ${OPT_FEATURE_FLAGS} parameter
   681    687   for option in $CFLAGS $CPPFLAGS

Added doc/begin_concurrent.md.

            1  +
            2  +Begin Concurrent
            3  +================
            4  +
            5  +## Overview
            6  +
            7  +Usually, SQLite allows at most one writer to proceed concurrently. The
            8  +BEGIN CONCURRENT enhancement allows multiple writers to process write
            9  +transactions simultanously if the database is in "wal" or "wal2" mode,
           10  +although the system still serializes COMMIT commands.
           11  +
           12  +When a write-transaction is opened with "BEGIN CONCURRENT", actually 
           13  +locking the database is deferred until a COMMIT is executed. This means
           14  +that any number of transactions started with BEGIN CONCURRENT may proceed
           15  +concurrently. The system uses optimistic page-level-locking to prevent
           16  +conflicting concurrent transactions from being committed.
           17  +
           18  +When a BEGIN CONCURRENT transaction is committed, the system checks whether 
           19  +or not any of the database pages that the transaction has read have been
           20  +modified since the BEGIN CONCURRENT was opened. In other words - it asks 
           21  +if the transaction being committed operates on a different set of data than
           22  +all other concurrently executing transactions. If the answer is "yes, this
           23  +transaction did not read or modify any data modified by any concurrent
           24  +transaction", then the transaction is committed as normal. Otherwise, if the
           25  +transaction does conflict, it cannot be committed and an SQLITE&#95;BUSY&#95;SNAPSHOT
           26  +error is returned. At this point, all the client can do is ROLLBACK the
           27  +transaction.
           28  +
           29  +If SQLITE&#95;BUSY&#95;SNAPSHOT is returned, messages are output via the sqlite3&#95;log
           30  +mechanism indicating the page and table or index on which the conflict
           31  +occurred. This can be useful when optimizing concurrency.
           32  +
           33  +## Application Programming Notes
           34  +
           35  +In order to serialize COMMIT processing, SQLite takes a lock on the database
           36  +as part of each COMMIT command and releases it before returning. At most one
           37  +writer may hold this lock at any one time. If a writer cannot obtain the lock,
           38  +it uses SQLite's busy-handler to pause and retry for a while:
           39  +
           40  +  <a href=https://www.sqlite.org/c3ref/busy_handler.html>
           41  +      https://www.sqlite.org/c3ref/busy_handler.html
           42  +  </a>
           43  +
           44  +If there is significant contention for the writer lock, this mechanism can be
           45  +inefficient. In this case it is better for the application to use a mutex or
           46  +some other mechanism that supports blocking to ensure that at most one writer
           47  +is attempting to COMMIT a BEGIN CONCURRENT transaction at a time. This is
           48  +usually easier if all writers are part of the same operating system process.
           49  +
           50  +If all database clients (readers and writers) are located in the same OS
           51  +process, and if that OS is a Unix variant, then it can be more efficient to
           52  +the built-in VFS "unix-excl" instead of the default "unix". This is because it
           53  +uses more efficient locking primitives.
           54  +
           55  +The key to maximizing concurrency using BEGIN CONCURRENT is to ensure that
           56  +there are a large number of non-conflicting transactions. In SQLite, each
           57  +table and each index is stored as a separate b-tree, each of which is
           58  +distributed over a discrete set of database pages. This means that:
           59  +
           60  +  * Two transactions that write to different sets of tables never 
           61  +    conflict, and that
           62  +
           63  +  * Two transactions that write to the same tables or indexes only 
           64  +    conflict if the values of the keys (either primary keys or indexed 
           65  +    rows) are fairly close together. For example, given a large 
           66  +    table with the schema:
           67  +
           68  +      <pre>     CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB);</pre>
           69  +
           70  +    writing two rows with adjacent values for "a" probably will cause a
           71  +    conflict (as the two keys are stored on the same page), but writing two
           72  +    rows with vastly different values for "a" will not (as the keys will likly
           73  +    be stored on different pages).
           74  +
           75  +Note that, in SQLite, if values are not explicitly supplied for an INTEGER
           76  +PRIMARY KEY, as for example in:
           77  +
           78  +>
           79  +     INSERT INTO t1(b) VALUES(&lt;blob-value>);
           80  +
           81  +then monotonically increasing values are assigned automatically. This is
           82  +terrible for concurrency, as it all but ensures that all new rows are 
           83  +added to the same database page. In such situations, it is better to
           84  +explicitly assign random values to INTEGER PRIMARY KEY fields.
           85  +
           86  +This problem also comes up for non-WITHOUT ROWID tables that do not have an
           87  +explicit INTEGER PRIMARY KEY column. In these cases each table has an implicit
           88  +INTEGER PRIMARY KEY column that is assigned increasing values, leading to the
           89  +same problem as omitting to assign a value to an explicit INTEGER PRIMARY KEY
           90  +column.
           91  +
           92  +For both explicit and implicit INTEGER PRIMARY KEYs, it is possible to have
           93  +SQLite assign values at random (instead of the monotonically increasing
           94  +values) by writing a row with a rowid equal to the largest possible signed
           95  +64-bit integer to the table. For example:
           96  +
           97  +     INSERT INTO t1(a) VALUES(9223372036854775807);
           98  +
           99  +Applications should take care not to malfunction due to the presence of such
          100  +rows.
          101  +
          102  +The nature of some types of indexes, for example indexes on timestamp fields,
          103  +can also cause problems (as concurrent transactions may assign similar
          104  +timestamps that will be stored on the same db page to new records). In these
          105  +cases the database schema may need to be rethought to increase the concurrency
          106  +provided by page-level-locking.
          107  +

Changes to doc/lemon.html.

   100    100   Do not compress the generated action tables.  The parser will be a
   101    101   little larger and slower, but it will detect syntax errors sooner.
   102    102   <li><b>-d</b><i>directory</i>
   103    103   Write all output files into <i>directory</i>.  Normally, output files
   104    104   are written into the directory that contains the input grammar file.
   105    105   <li><b>-D<i>name</i></b>
   106    106   Define C preprocessor macro <i>name</i>.  This macro is usable by
   107         -"<tt><a href='#pifdef'>%ifdef</a></tt>" and
   108         -"<tt><a href='#pifdef'>%ifndef</a></tt>" lines
          107  +"<tt><a href='#pifdef'>%ifdef</a></tt>",
          108  +"<tt><a href='#pifdef'>%ifndef</a></tt>", and
          109  +"<tt><a href="#pifdef">%if</a></tt> lines
   109    110   in the grammar file.
          111  +<li><b>-E</b>
          112  +Run the "%if" preprocessor step only and print the revised grammar
          113  +file.
   110    114   <li><b>-g</b>
   111    115   Do not generate a parser.  Instead write the input grammar to standard
   112    116   output with all comments, actions, and other extraneous text removed.
   113    117   <li><b>-l</b>
   114    118   Omit "#line" directives in the generated parser C code.
   115    119   <li><b>-m</b>
   116    120   Cause the output C source code to be compatible with the "makeheaders"
................................................................................
   119    123   Display all conflicts that are resolved by
   120    124   <a href='#precrules'>precedence rules</a>.
   121    125   <li><b>-q</b>
   122    126   Suppress generation of the report file.
   123    127   <li><b>-r</b>
   124    128   Do not sort or renumber the parser states as part of optimization.
   125    129   <li><b>-s</b>
   126         -Show parser statistics before existing.
          130  +Show parser statistics before exiting.
   127    131   <li><b>-T<i>file</i></b>
   128    132   Use <i>file</i> as the template for the generated C-code parser implementation.
   129    133   <li><b>-x</b>
   130    134   Print the Lemon version number.
   131    135   </ul>
   132    136   
   133    137   <h3>The Parser Interface</h3>
................................................................................
   484    488   </pre>
   485    489   is an error.</p>
   486    490   
   487    491   <p>The precedence of non-terminals is transferred to rules as follows:
   488    492   The precedence of a grammar rule is equal to the precedence of the
   489    493   left-most terminal symbol in the rule for which a precedence is
   490    494   defined.  This is normally what you want, but in those cases where
   491         -you want to precedence of a grammar rule to be something different,
          495  +you want the precedence of a grammar rule to be something different,
   492    496   you can specify an alternative precedence symbol by putting the
   493    497   symbol in square braces after the period at the end of the rule and
   494    498   before any C-code.  For example:</p>
   495    499   
   496    500   <p><pre>
   497    501      expr = MINUS expr.  [NOT]
   498    502   </pre></p>
................................................................................
   551    555   
   552    556   <p>Lemon supports the following special directives:
   553    557   <ul>
   554    558   <li><tt><a href='#pcode'>%code</a></tt>
   555    559   <li><tt><a href='#default_destructor'>%default_destructor</a></tt>
   556    560   <li><tt><a href='#default_type'>%default_type</a></tt>
   557    561   <li><tt><a href='#destructor'>%destructor</a></tt>
          562  +<li><tt><a href='#pifdef'>%else</a></tt>
   558    563   <li><tt><a href='#pifdef'>%endif</a></tt>
   559    564   <li><tt><a href='#extraarg'>%extra_argument</a></tt>
   560    565   <li><tt><a href='#pfallback'>%fallback</a></tt>
          566  +<li><tt><a href='#pifdef'>%if</a></tt>
   561    567   <li><tt><a href='#pifdef'>%ifdef</a></tt>
   562    568   <li><tt><a href='#pifdef'>%ifndef</a></tt>
   563    569   <li><tt><a href='#pinclude'>%include</a></tt>
   564    570   <li><tt><a href='#pleft'>%left</a></tt>
   565    571   <li><tt><a href='#pname'>%name</a></tt>
   566    572   <li><tt><a href='#pnonassoc'>%nonassoc</a></tt>
   567    573   <li><tt><a href='#parse_accept'>%parse_accept</a></tt>
................................................................................
   685    691   <p>The <tt>%extra_context</tt> directive works the same except that it
   686    692   is passed in on the ParseAlloc() or ParseInit() routines instead of
   687    693   on Parse().
   688    694   
   689    695   <a name='extractx'></a>
   690    696   <h4>The <tt>%extra_context</tt> directive</h4>
   691    697   
   692         -The <tt>%extra_context</tt> directive instructs Lemon to add a 2th parameter
          698  +The <tt>%extra_context</tt> directive instructs Lemon to add a 2nd parameter
   693    699   to the parameter list of the ParseAlloc() and ParseInif() functions.  Lemon
   694    700   doesn't do anything itself with these extra argument, but it does
   695    701   store the value make it available to C-code action routines, destructors,
   696    702   and so forth.  For example, if the grammar file contains:</p>
   697    703   
   698    704   <p><pre>
   699    705       %extra_context { MyStruct *pAbc }
   700    706   </pre></p>
   701    707   
   702         -<p>Then the ParseAlloc() and ParseInit() functions will have an 2th parameter
          708  +<p>Then the ParseAlloc() and ParseInit() functions will have an 2nd parameter
   703    709   of type "MyStruct*" and all action routines will have access to
   704         -a variable named "pAbc" that is the value of that 2th parameter.</p>
          710  +a variable named "pAbc" that is the value of that 2nd parameter.</p>
   705    711   
   706    712   <p>The <tt>%extra_argument</tt> directive works the same except that it
   707    713   is passed in on the Parse() routine instead of on ParseAlloc()/ParseInit().
   708    714   
   709    715   <a name='pfallback'></a>
   710    716   <h4>The <tt>%fallback</tt> directive</h4>
   711    717   
................................................................................
   733    739   names terminated by a period.
   734    740   The first token name is the fallback token &mdash; the
   735    741   token to which all the other tokens fall back to.  The second and subsequent
   736    742   arguments are tokens which fall back to the token identified by the first
   737    743   argument.</p>
   738    744   
   739    745   <a name='pifdef'></a>
   740         -<h4>The <tt>%ifdef</tt>, <tt>%ifndef</tt>, and <tt>%endif</tt> directives</h4>
          746  +<h4>The <tt>%if</tt> directive and its friends</h4>
   741    747   
   742         -<p>The <tt>%ifdef</tt>, <tt>%ifndef</tt>, and <tt>%endif</tt> directives
   743         -are similar to #ifdef, #ifndef, and #endif in the C-preprocessor,
          748  +<p>The <tt>%if</tt>, <tt>%ifdef</tt>, <tt>%ifndef</tt>, <tt>%else</tt>,
          749  +and <tt>%endif</tt> directives
          750  +are similar to #if, #ifdef, #ifndef, #else, and #endif in the C-preprocessor,
   744    751   just not as general.
   745    752   Each of these directives must begin at the left margin.  No whitespace
   746    753   is allowed between the "%" and the directive name.</p>
   747    754   
   748    755   <p>Grammar text in between "<tt>%ifdef MACRO</tt>" and the next nested
   749    756   "<tt>%endif</tt>" is
   750    757   ignored unless the "-DMACRO" command-line option is used.  Grammar text
   751    758   betwen "<tt>%ifndef MACRO</tt>" and the next nested "<tt>%endif</tt>" is
   752         -included except when the "-DMACRO" command-line option is used.</p>
          759  +included except when the "-DMACRO" command-line option is used.<p>
   753    760   
   754         -<p>Note that the argument to <tt>%ifdef</tt> and <tt>%ifndef</tt> must
   755         -be a single preprocessor symbol name, not a general expression.
   756         -There is no "<tt>%else</tt>" directive.</p>
          761  +<p>The text in between "<tt>%if</tt> <i>CONDITIONAL</i>" and its
          762  +corresponding <tt>%endif</tt> is included only if <i>CONDITIONAL</i>
          763  +is true.  The CONDITION is one or more macro names, optionally connected
          764  +using the "||" and "&amp;&amp;" binary operators, the "!" unary operator,
          765  +and grouped using balanced parentheses.  Each term is true if the
          766  +corresponding macro exists, and false if it does not exist.</p>
   757    767   
          768  +<p>An optional "<tt>%else</tt>" directive can occur anywhere in between a 
          769  +<tt>%ifdef</tt>, <tt>%ifndef</tt>, or <tt>%if</tt> directive and
          770  +its corresponding <tt>%endif</tt>.</p>
          771  +
          772  +<p>Note that the argument to <tt>%ifdef</tt> and <tt>%ifndef</tt> is
          773  +intended to be a single preprocessor symbol name, not a general expression.
          774  +Use the "<tt>%if</tt>" directive for general expressions.</p>
   758    775   
   759    776   <a name='pinclude'></a>
   760    777   <h4>The <tt>%include</tt> directive</h4>
   761    778   
   762    779   <p>The <tt>%include</tt> directive specifies C code that is included at the
   763    780   top of the generated parser.  You can include any text you want &mdash;
   764    781   the Lemon parser generator copies it blindly.  If you have multiple
................................................................................
   992   1009   <h4>The <tt>%token_type</tt> and <tt>%type</tt> directives</h4>
   993   1010   
   994   1011   <p>These directives are used to specify the data types for values
   995   1012   on the parser's stack associated with terminal and non-terminal
   996   1013   symbols.  The values of all terminal symbols must be of the same
   997   1014   type.  This turns out to be the same data type as the 3rd parameter
   998   1015   to the Parse() function generated by Lemon.  Typically, you will
   999         -make the value of a terminal symbol by a pointer to some kind of
         1016  +make the value of a terminal symbol be a pointer to some kind of
  1000   1017   token structure.  Like this:</p>
  1001   1018   
  1002   1019   <p><pre>
  1003   1020      %token_type    {Token*}
  1004   1021   </pre></p>
  1005   1022   
  1006   1023   <p>If the data type of terminals is not specified, the default value

Added doc/trusted-schema.md.

            1  +# The new-security-options branch
            2  +
            3  +## The problem that the [new-security-options](/timeline?r=new-security-options) branch tries to solve
            4  +
            5  +An attacker might modify the schema of an SQLite database by adding
            6  +structures that cause code to run when some other application opens and
            7  +reads the database.  For example, the attacker might replace a table
            8  +definition with a view.  Or the attacker might add triggers to tables
            9  +or views, or add new CHECK constraints or generated columns or indexes
           10  +with expressions in the index list or in the WHERE clause.  If the
           11  +added features invoke SQL functions or virtual tables with side effects,
           12  +that might cause harm to the system if run by a high-privilege victim.
           13  +Or, the added features might exfiltrate information if the database is
           14  +read by a high-privilege victim.
           15  +
           16  +The changes in this branch strive to make it easier for high-privilege
           17  +applications to safely read SQLite database files that might have been
           18  +maliciously corrupted by an attacker.
           19  +
           20  +## Overview of changes in [new-security-options](/timeline?r=new-security-options)
           21  +
           22  +The basic idea is to tag every SQL function and virtual table with one
           23  +of three risk levels:
           24  +
           25  +  1.  Innocuous
           26  +  2.  Normal
           27  +  3.  Direct-Only
           28  +
           29  +Innocuous functions/vtabs are safe and can be used at any time.
           30  +Direct-only elements, in contrast, might have cause side-effects and
           31  +should only be used from top-level SQL, not from within triggers or views nor
           32  +in elements of the schema such as CHECK constraint, DEFAULT values, 
           33  +generated columns, index expressions, or in the WHERE clause of a 
           34  +partial index that are potentially under the control of an attacker.
           35  +Normal elements behave like Innocuous if TRUSTED\_SCHEMA=on
           36  +and behave like direct-only if TRUSTED\_SCHEMA=off.
           37  +
           38  +Application-defined functions and virtual tables go in as Normal unless
           39  +the application takes deliberate steps to change the risk level.
           40  +
           41  +For backwards compatibility, the default is TRUSTED\_SCHEMA=on.  Documentation
           42  +will be updated to recommend applications turn TRUSTED\_SCHEMA to off.
           43  +
           44  +An innocuous function or virtual table is one that can only read content
           45  +from the database file in which it resides, and can only alter the database
           46  +in which it resides.  Most SQL functions are innocuous.  For example, there
           47  +is no harm in an attacker running the abs() function.
           48  +
           49  +Direct-only elements that have side-effects that go outside the database file
           50  +in which it lives, or return information from outside of the database file.
           51  +Examples of direct-only elements include:
           52  +
           53  +  1.  The fts3\_tokenizer() function
           54  +  2.  The writefile() function
           55  +  3.  The readfile() function
           56  +  4.  The zipvfs virtual table
           57  +  5.  The csv virtual table
           58  +
           59  +We do not want an attacker to be able to add these kinds of things to
           60  +the database schema and possibly trick a high-privilege application 
           61  +from performing any of these actions.  Therefore, functions and vtabs
           62  +with side-effects are marked as Direct-Only.
           63  +
           64  +Legacy applications might add other risky functions or vtabs.  Those will
           65  +go in as "Normal" by default.  For optimal security, we want those risky
           66  +app-defined functions and vtabs to be direct-only, but making that the
           67  +default might break some legacy applications.  Hence, all app-defined
           68  +functions and vtabs go in as Normal, but the application can switch them
           69  +over to "Direct-Only" behavior using a single pragma.
           70  +
           71  +The restrictions on the use of functions and virtual tables do not apply
           72  +to TEMP.  A TEMP VIEW or a TEMP TRIGGER can use any valid SQL function
           73  +or virtual table.  The idea is that TEMP views and triggers must be
           74  +directly created by the application and are thus under the control of the
           75  +application.  TEMP views and triggers cannot be created by an attacker who
           76  +corrupts the schema of a persistent database file.  Hence TEMP views and
           77  +triggers are safe.
           78  +
           79  +## Specific changes
           80  +
           81  +  1.  New sqlite3\_db\_config() option SQLITE\_DBCONFIG\_TRUSTED\_SCHEMA for
           82  +      turning TRUSTED\_SCHEMA on and off.  It defaults to ON.
           83  +
           84  +  2.  Compile-time option -DSQLITE\_TRUSTED\_SCHEMA=0 causes the default
           85  +      TRUSTED\_SCHEMA setting to be off.
           86  +
           87  +  3.  New pragma "PRAGMA trusted\_schema=(ON\|OFF);".  This provides access
           88  +      to the TRUSTED_SCHEMA setting for application coded using scripting
           89  +      languages or other secondary languages where they are unable to make
           90  +      calls to sqlite3\_db\_config().
           91  +
           92  +  4.  New options for the "enc" parameter to sqlite3\_create\_function() and
           93  +      its kin:
           94  +      <ol type="a">
           95  +      <li>  _SQLITE\_INNOCUOUS_  &rarr; tags the new functions as Innocuous
           96  +      <li>  _SQLITE\_DIRECTONLY_ &rarr; tags the new functions as Direct-Only
           97  +      </ol>
           98  +
           99  +  5.  New options to sqlite3\_vtab\_config():
          100  +      <ol type="a">
          101  +      <li>  _SQLITE\_VTAB\_INNOCUOUS_   &rarr; tags the vtab as Innocuous
          102  +      <li>  _SQLITE\_VTAB\_DIRECTONLY_  &rarr; tags the vtab as Direct-Only
          103  +      </ol>
          104  +
          105  +  6.  Change many of the functions and virtual tables in the SQLite source
          106  +      tree to use one of the tags above.
          107  +
          108  +  7.  Enhanced PRAGMA function\_list and virtual-table "pragma\_function\_list"
          109  +      with additional columns.  The columns now are:
          110  +      <ul>
          111  +      <li> _name_      &rarr;  Name of the function
          112  +      <li> _builtin_   &rarr;  1 for built-in functions.  0 otherwise.
          113  +      <li> _type_      &rarr;  's'=Scalar, 'a'=Aggregate, 'w'=Window
          114  +      <li> _enc_       &rarr;  'utf8', 'utf16le', or 'utf16be'
          115  +      <li> _narg_      &rarr;  number of argument
          116  +      <li> _flags_     &rarr;  Bitmask of SQLITE\_INNOCUOUS, SQLITE\_DIRECTONLY,
          117  +                               SQLITE\_DETERMINISTIC, SQLITE\_SUBTYPE, and
          118  +                               SQLITE\_FUNC\_INTERNAL flags.
          119  +      </ul>
          120  +      <p>The last four columns are new.
          121  +
          122  +  8.  The function\_list PRAGMA now also shows all entries for each function.
          123  +      So, for example, if a function can take either 2 or 3 arguments,
          124  +      there are separate rows for the 2-argument and 3-argument versions of
          125  +      the function.
          126  +
          127  +## Additional Notes
          128  +
          129  +The function_list enhancements allow the application to query the set
          130  +of SQL functions that meet various criteria.  For example, to see all
          131  +SQL functions that are never allowed to be used in the schema or in
          132  +trigger or views:
          133  +
          134  +~~~
          135  +    SELECT DISTINCT name FROM pragma_function_list
          136  +     WHERE (flags & 0x80000)!=0
          137  +     ORDER BY name;
          138  +~~~
          139  +
          140  +Doing the same is not possible for virtual tables, as a virtual table
          141  +might be Innocuous, Normal, or Direct-Only depending on the arguments
          142  +passed into the xConnect method.

Added doc/wal-lock.md.

            1  +# Wal-Mode Blocking Locks
            2  +
            3  +On some Unix-like systems, SQLite may be configured to use POSIX blocking locks
            4  +by:
            5  +
            6  +  * building the library with SQLITE\_ENABLE\_SETLK\_TIMEOUT defined, and 
            7  +  * configuring a timeout in ms using the sqlite3\_busy\_timeout() API.
            8  +
            9  +Blocking locks may be advantageous as (a) waiting database clients do not
           10  +need to continuously poll the database lock, and (b) using blocking locks
           11  +facilitates transfer of OS priority between processes when a high priority
           12  +process is blocked by a lower priority one.
           13  +
           14  +Only read/write clients use blocking locks. Clients that have read-only access
           15  +to the \*-shm file nevery use blocking locks.
           16  +
           17  +Threads or processes that access a single database at a time never deadlock as
           18  +a result of blocking database locks. But it is of course possible for threads
           19  +that lock multiple databases simultaneously to do so. In most cases the OS will
           20  +detect the deadlock and return an error.
           21  +
           22  +## Wal Recovery
           23  +
           24  +Wal database "recovery" is a process required when the number of connected
           25  +database clients changes from zero to one. In this case, a client is 
           26  +considered to connect to the database when it first reads data from it.
           27  +Before recovery commences, an exclusive WRITER lock is taken. 
           28  +
           29  +Without blocking locks, if two clients attempt recovery simultaneously, one
           30  +fails to obtain the WRITER lock and either invokes the busy-handler callback or
           31  +returns SQLITE\_BUSY to the user. With blocking locks configured, the second
           32  +client blocks on the WRITER lock.
           33  +
           34  +## Database Readers
           35  +
           36  +Usually, read-only are not blocked by any other database clients, so they 
           37  +have no need of blocking locks.
           38  +
           39  +If a read-only transaction is being opened on a snapshot, the CHECKPOINTER
           40  +lock is required briefly as part of opening the transaction (to check that a
           41  +checkpointer is not currently overwriting the snapshot being opened). A
           42  +blocking lock is used to obtain the CHECKPOINTER lock in this case. A snapshot
           43  +opener may therefore block on and transfer priority to a checkpointer in some
           44  +cases.
           45  +
           46  +## Database Writers
           47  +
           48  +A database writer must obtain the exclusive WRITER lock. It uses a blocking
           49  +lock to do so if any of the following are true:
           50  +
           51  +  * the transaction is an implicit one consisting of a single DML or DDL
           52  +    statement, or
           53  +  * the transaction is opened using BEGIN IMMEDIATE or BEGIN EXCLUSIVE, or
           54  +  * the first SQL statement executed following the BEGIN command is a DML or
           55  +    DDL statement (not a read-only statement like a SELECT).
           56  +
           57  +In other words, in all cases except when an open read-transaction is upgraded
           58  +to a write-transaction. In that case a non-blocking lock is used.
           59  +
           60  +## Database Checkpointers
           61  +
           62  +Database checkpointers takes the following locks, in order:
           63  +
           64  +  * The exclusive CHECKPOINTER lock.
           65  +  * The exclusive WRITER lock (FULL, RESTART and TRUNCATE only).
           66  +  * Exclusive lock on read-mark slots 1-N. These are immediately released after being taken.
           67  +  * Exclusive lock on read-mark 0.
           68  +  * Exclusive lock on read-mark slots 1-N again. These are immediately released
           69  +    after being taken (RESTART and TRUNCATE only).
           70  +
           71  +All of the above use blocking locks.
           72  +
           73  +## Summary
           74  +
           75  +With blocking locks configured, the only cases in which clients should see an
           76  +SQLITE\_BUSY error are:
           77  +
           78  +  * if the OS does not grant a blocking lock before the configured timeout
           79  +    expires, and
           80  +  * when an open read-transaction is upgraded to a write-transaction.
           81  +
           82  +In all other cases the blocking locks implementation should prevent clients
           83  +from having to handle SQLITE\_BUSY errors and facilitate appropriate transfer
           84  +of priorities between competing clients.
           85  +
           86  +Clients that lock multiple databases simultaneously must be wary of deadlock.
           87  +
           88  +

Changes to ext/async/sqlite3async.c.

  1700   1700         break;
  1701   1701     }
  1702   1702     va_end(ap);
  1703   1703     return rc;
  1704   1704   }
  1705   1705   
  1706   1706   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ASYNCIO) */
  1707         -

Changes to ext/async/sqlite3async.h.

   216    216   #define SQLITEASYNC_HALT_NOW   1       /* Halt as soon as possible */
   217    217   #define SQLITEASYNC_HALT_IDLE  2       /* Halt when write-queue is empty */
   218    218   
   219    219   #ifdef __cplusplus
   220    220   }  /* End of the 'extern "C"' block */
   221    221   #endif
   222    222   #endif        /* ifndef __SQLITEASYNC_H_ */
   223         -

Changes to ext/expert/expert1.test.

    33     33   
    34     34   proc squish {txt} {
    35     35     regsub -all {[[:space:]]+} $txt { }
    36     36   }
    37     37   
    38     38   proc do_setup_rec_test {tn setup sql res} {
    39     39     reset_db
           40  +  if {[info exists ::set_main_db_name]} {
           41  +    dbconfig_maindbname_icecube db
           42  +  }
    40     43     db eval $setup
    41     44     uplevel [list do_rec_test $tn $sql $res]
    42     45   }
    43     46   
    44     47   foreach {tn setup} {
    45     48     1 {
    46     49       if {![file executable $CMD]} { continue }
................................................................................
    72     75         $expert destroy
    73     76   
    74     77         set tst [subst -nocommands {set {} [squish [join {$result}]]}]
    75     78         uplevel [list do_test $tn $tst [string trim [squish $res]]]
    76     79       }
    77     80     }
    78     81     3 {
           82  +    if {[info commands sqlite3_expert_new]==""} { continue }
           83  +    set ::set_main_db_name 1
           84  +  }
           85  +  4 {
    79     86       if {![file executable $CLI]} { continue }
    80     87   
    81     88       proc do_rec_test {tn sql res} {
    82     89         set res [squish [string trim $res]]
    83     90         set tst [subst -nocommands { 
    84     91           squish [string trim [exec $::CLI test.db ".expert" {$sql;}]]
    85     92         }]
................................................................................
   130    137   } {
   131    138     SELECT a FROM t1 WHERE a=? ORDER BY b;
   132    139   } {
   133    140     CREATE INDEX t1_idx_000123a7 ON t1(a, b);
   134    141     SEARCH TABLE t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
   135    142   }
   136    143   
          144  +if 0 {
   137    145   do_setup_rec_test $tn.6 {
   138    146     CREATE TABLE t1(a, b, c);
   139    147   } {
   140    148     SELECT min(a) FROM t1
   141    149   } {
   142    150     CREATE INDEX t1_idx_00000061 ON t1(a);
   143    151     SEARCH TABLE t1 USING COVERING INDEX t1_idx_00000061
          152  +}
   144    153   }
   145    154   
   146    155   do_setup_rec_test $tn.7 {
   147    156     CREATE TABLE t1(a, b, c);
   148    157   } {
   149    158     SELECT * FROM t1 ORDER BY a, b, c;
   150    159   } {
................................................................................
   239    248     CREATE TABLE t7(a, b);
   240    249   } {
   241    250     SELECT * FROM t7 WHERE a=? OR b=?
   242    251   } {
   243    252     CREATE INDEX t7_idx_00000062 ON t7(b);
   244    253     CREATE INDEX t7_idx_00000061 ON t7(a);
   245    254     MULTI-INDEX OR
   246         -    SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
   247         -    SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
          255  +    INDEX 1
          256  +      SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
          257  +    INDEX 2
          258  +      SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
   248    259   }
   249    260   
   250    261   # rowid terms.
   251    262   #
   252    263   do_setup_rec_test $tn.13.1 {
   253    264     CREATE TABLE t8(a, b);
   254    265   } {
................................................................................
   328    339     $expert destroy
   329    340   
   330    341     uplevel [list do_test $tn [list set {} $candidates] $res]
   331    342   }
   332    343   
   333    344   
   334    345   reset_db
   335         -do_execsql_test 4.0 {
          346  +do_execsql_test 5.0 {
   336    347     CREATE TABLE t1(a, b);
   337    348     CREATE TABLE t2(c, d);
   338    349   
   339    350     WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
   340    351     INSERT INTO t1 SELECT (i-1)/50, (i-1)/20 FROM s;
   341    352   
   342    353     WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
   343    354     INSERT INTO t2 SELECT (i-1)/20, (i-1)/5 FROM s;
   344    355   }
   345         -do_candidates_test 4.1 {
          356  +do_candidates_test 5.1 {
   346    357     SELECT * FROM t1,t2 WHERE (b=? OR a=?) AND (c=? OR d=?)
   347    358   } {
   348    359     CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20 
   349    360     CREATE INDEX t1_idx_00000061 ON t1(a); -- stat1: 100 50 
   350    361     CREATE INDEX t2_idx_00000063 ON t2(c); -- stat1: 100 20 
   351    362     CREATE INDEX t2_idx_00000064 ON t2(d); -- stat1: 100 5
   352    363   }
   353    364   
   354         -do_candidates_test 4.2 {
          365  +do_candidates_test 5.2 {
   355    366     SELECT * FROM t1,t2 WHERE a=? AND b=? AND c=? AND d=?
   356    367   } {
   357    368     CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 17
   358    369     CREATE INDEX t2_idx_0001295b ON t2(c, d); -- stat1: 100 20 5
   359    370   }
   360    371   
   361         -do_execsql_test 4.3 {
          372  +do_execsql_test 5.3 {
   362    373     CREATE INDEX t1_idx_00000061 ON t1(a); -- stat1: 100 50 
   363    374     CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20 
   364    375     CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 16
   365    376   
   366    377     CREATE INDEX t2_idx_00000063 ON t2(c); -- stat1: 100 20 
   367    378     CREATE INDEX t2_idx_00000064 ON t2(d); -- stat1: 100 5
   368    379     CREATE INDEX t2_idx_0001295b ON t2(c, d); -- stat1: 100 20 5

Changes to ext/expert/sqlite3expert.c.

  1124   1124           "EXPLAIN QUERY PLAN %s", pStmt->zSql
  1125   1125       );
  1126   1126       while( rc==SQLITE_OK && sqlite3_step(pExplain)==SQLITE_ROW ){
  1127   1127         /* int iId = sqlite3_column_int(pExplain, 0); */
  1128   1128         /* int iParent = sqlite3_column_int(pExplain, 1); */
  1129   1129         /* int iNotUsed = sqlite3_column_int(pExplain, 2); */
  1130   1130         const char *zDetail = (const char*)sqlite3_column_text(pExplain, 3);
  1131         -      int nDetail = STRLEN(zDetail);
         1131  +      int nDetail;
  1132   1132         int i;
  1133   1133   
         1134  +      if( !zDetail ) continue;
         1135  +      nDetail = STRLEN(zDetail);
         1136  +
  1134   1137         for(i=0; i<nDetail; i++){
  1135   1138           const char *zIdx = 0;
  1136         -        if( memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
         1139  +        if( i+13<nDetail && memcmp(&zDetail[i], " USING INDEX ", 13)==0 ){
  1137   1140             zIdx = &zDetail[i+13];
  1138         -        }else if( memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0 ){
         1141  +        }else if( i+22<nDetail 
         1142  +            && memcmp(&zDetail[i], " USING COVERING INDEX ", 22)==0 
         1143  +        ){
  1139   1144             zIdx = &zDetail[i+22];
  1140   1145           }
  1141   1146           if( zIdx ){
  1142   1147             const char *zSql;
  1143   1148             int nIdx = 0;
  1144   1149             while( zIdx[nIdx]!='\0' && (zIdx[nIdx]!=' ' || zIdx[nIdx+1]!='(') ){
  1145   1150               nIdx++;
................................................................................
  1214   1219     char **pzErr
  1215   1220   ){
  1216   1221     static const char *zInt = UNIQUE_TABLE_NAME;
  1217   1222     static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
  1218   1223     IdxTable *pTab = pWrite->pTab;
  1219   1224     const char *zTab = pTab->zName;
  1220   1225     const char *zSql = 
  1221         -    "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_master "
         1226  +    "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_schema "
  1222   1227       "WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
  1223   1228       "ORDER BY type;";
  1224   1229     sqlite3_stmt *pSelect = 0;
  1225   1230     int rc = SQLITE_OK;
  1226   1231     char *zWrite = 0;
  1227   1232   
  1228   1233     /* Create the table and its triggers in the temp schema */
................................................................................
  1314   1319   
  1315   1320     /* For each table in the main db schema:
  1316   1321     **
  1317   1322     **   1) Add an entry to the p->pTable list, and
  1318   1323     **   2) Create the equivalent virtual table in dbv.
  1319   1324     */
  1320   1325     rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
  1321         -      "SELECT type, name, sql, 1 FROM sqlite_master "
         1326  +      "SELECT type, name, sql, 1 FROM sqlite_schema "
  1322   1327         "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
  1323   1328         " UNION ALL "
  1324         -      "SELECT type, name, sql, 2 FROM sqlite_master "
         1329  +      "SELECT type, name, sql, 2 FROM sqlite_schema "
  1325   1330         "WHERE type = 'trigger'"
  1326         -      "  AND tbl_name IN(SELECT name FROM sqlite_master WHERE type = 'view') "
         1331  +      "  AND tbl_name IN(SELECT name FROM sqlite_schema WHERE type = 'view') "
  1327   1332         "ORDER BY 4, 1"
  1328   1333     );
  1329   1334     while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSchema) ){
  1330   1335       const char *zType = (const char*)sqlite3_column_text(pSchema, 0);
  1331   1336       const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
  1332   1337       const char *zSql = (const char*)sqlite3_column_text(pSchema, 2);
  1333   1338   
................................................................................
  1489   1494     }
  1490   1495   }
  1491   1496   
  1492   1497   static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
  1493   1498     int rc = SQLITE_OK;
  1494   1499     const char *zMax = 
  1495   1500       "SELECT max(i.seqno) FROM "
  1496         -    "  sqlite_master AS s, "
         1501  +    "  sqlite_schema AS s, "
  1497   1502       "  pragma_index_list(s.name) AS l, "
  1498   1503       "  pragma_index_info(l.name) AS i "
  1499   1504       "WHERE s.type = 'table'";
  1500   1505     sqlite3_stmt *pMax = 0;
  1501   1506   
  1502   1507     *pnMax = 0;
  1503   1508     rc = idxPrepareStmt(db, &pMax, pzErr, zMax);
................................................................................
  1642   1647     i64 iPrev = -100000;
  1643   1648     sqlite3_stmt *pAllIndex = 0;
  1644   1649     sqlite3_stmt *pIndexXInfo = 0;
  1645   1650     sqlite3_stmt *pWrite = 0;
  1646   1651   
  1647   1652     const char *zAllIndex =
  1648   1653       "SELECT s.rowid, s.name, l.name FROM "
  1649         -    "  sqlite_master AS s, "
         1654  +    "  sqlite_schema AS s, "
  1650   1655       "  pragma_index_list(s.name) AS l "
  1651   1656       "WHERE s.type = 'table'";
  1652   1657     const char *zIndexXInfo = 
  1653   1658       "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
  1654   1659     const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
  1655   1660   
  1656   1661     /* If iSample==0, no sqlite_stat1 data is required. */
................................................................................
  1716   1721   
  1717   1722     for(i=0; i<pCtx->nSlot; i++){
  1718   1723       sqlite3_free(pCtx->aSlot[i].z);
  1719   1724     }
  1720   1725     sqlite3_free(pCtx);
  1721   1726   
  1722   1727     if( rc==SQLITE_OK ){
  1723         -    rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_master", 0, 0, 0);
         1728  +    rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_schema", 0, 0, 0);
  1724   1729     }
  1725   1730   
  1726   1731     sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
  1727   1732     return rc;
  1728   1733   }
  1729   1734   
  1730   1735   /*
................................................................................
  1755   1760     }
  1756   1761     
  1757   1762   
  1758   1763     /* Copy the entire schema of database [db] into [dbm]. */
  1759   1764     if( rc==SQLITE_OK ){
  1760   1765       sqlite3_stmt *pSql;
  1761   1766       rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg, 
  1762         -        "SELECT sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%%'"
         1767  +        "SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
  1763   1768           " AND sql NOT LIKE 'CREATE VIRTUAL %%'"
  1764   1769       );
  1765   1770       while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
  1766   1771         const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
  1767   1772         rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
  1768   1773       }
  1769   1774       idxFinalize(&rc, pSql);
................................................................................
  1946   1951       idxWriteFree(p->pWrite);
  1947   1952       idxHashClear(&p->hIdx);
  1948   1953       sqlite3_free(p->zCandidates);
  1949   1954       sqlite3_free(p);
  1950   1955     }
  1951   1956   }
  1952   1957   
  1953         -#endif /* ifndef SQLITE_OMIT_VIRTUAL_TABLE */
         1958  +#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */

Changes to ext/expert/sqlite3expert.h.

     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   */
    13         -
    14         -
           13  +#if !defined(SQLITEEXPERT_H)
           14  +#define SQLITEEXPERT_H 1
    15     15   #include "sqlite3.h"
    16     16   
    17     17   typedef struct sqlite3expert sqlite3expert;
    18     18   
    19     19   /*
    20     20   ** Create a new sqlite3expert object.
    21     21   **
................................................................................
   161    161   /*
   162    162   ** Free an (sqlite3expert*) handle and all associated resources. There 
   163    163   ** should be one call to this function for each successful call to 
   164    164   ** sqlite3-expert_new().
   165    165   */
   166    166   void sqlite3_expert_destroy(sqlite3expert*);
   167    167   
   168         -
          168  +#endif  /* !defined(SQLITEEXPERT_H) */

Changes to ext/fts3/README.content.

   170    170   
   171    171       INSERT INTO t3(t3) VALUES('rebuild');
   172    172   
   173    173     This command may also be used with ordinary FTS4 tables, although it may
   174    174     only be useful if the full-text index has somehow become corrupt. It is an
   175    175     error to attempt to rebuild the full-text index maintained by a contentless
   176    176     FTS4 table.
   177         -
   178         -

Changes to ext/fts3/README.tokenizers.

    48     48     returned. If only one argument is passed, a pointer to the tokenizer
    49     49     implementation currently registered as <tokenizer-name> is returned,
    50     50     encoded as a blob. Or, if no such tokenizer exists, an SQL exception
    51     51     (error) is raised.
    52     52   
    53     53     SECURITY: If the fts3 extension is used in an environment where potentially
    54     54       malicious users may execute arbitrary SQL (i.e. gears), they should be
    55         -    prevented from invoking the fts3_tokenizer() function, possibly using the
    56         -    authorisation callback.
           55  +    prevented from invoking the fts3_tokenizer() function.  The
           56  +    fts3_tokenizer() function is disabled by default. It is only enabled
           57  +    by SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER. Do not enable it in
           58  +    security sensitive environments.
    57     59   
    58     60     See "Sample code" below for an example of calling the fts3_tokenizer()
    59     61     function from C code.
    60     62   
    61     63   3. ICU Library Tokenizers
    62     64   
    63     65     If this extension is compiled with the SQLITE_ENABLE_ICU pre-processor 

Changes to ext/fts3/fts3.c.

   316    316   #ifndef SQLITE_AMALGAMATION
   317    317   # if defined(SQLITE_DEBUG)
   318    318   int sqlite3Fts3Always(int b) { assert( b ); return b; }
   319    319   int sqlite3Fts3Never(int b)  { assert( !b ); return b; }
   320    320   # endif
   321    321   #endif
   322    322   
          323  +/*
          324  +** This variable is set to false when running tests for which the on disk
          325  +** structures should not be corrupt. Otherwise, true. If it is false, extra
          326  +** assert() conditions in the fts3 code are activated - conditions that are
          327  +** only true if it is guaranteed that the fts3 database is not corrupt.
          328  +*/
          329  +int sqlite3_fts3_may_be_corrupt = 1;
          330  +
   323    331   /* 
   324    332   ** Write a 64-bit variable-length integer to memory starting at p[0].
   325    333   ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
   326    334   ** The number of bytes written is returned.
   327    335   */
   328    336   int sqlite3Fts3PutVarint(char *p, sqlite_int64 v){
   329    337     unsigned char *q = (unsigned char *) p;
................................................................................
   334    342     }while( vu!=0 );
   335    343     q[-1] &= 0x7f;  /* turn off high bit in final byte */
   336    344     assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
   337    345     return (int) (q - (unsigned char *)p);
   338    346   }
   339    347   
   340    348   #define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
   341         -  v = (v & mask1) | ( (*ptr++) << shift );                    \
          349  +  v = (v & mask1) | ( (*(const unsigned char*)(ptr++)) << shift );  \
   342    350     if( (v & mask2)==0 ){ var = v; return ret; }
   343    351   #define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
   344    352     v = (*ptr++);                                               \
   345    353     if( (v & mask2)==0 ){ var = v; return ret; }
   346    354   
   347         -/* 
   348         -** Read a 64-bit variable-length integer from memory starting at p[0].
   349         -** Return the number of bytes read, or 0 on error.
   350         -** The value is stored in *v.
   351         -*/
   352         -int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
          355  +int sqlite3Fts3GetVarintU(const char *pBuf, sqlite_uint64 *v){
   353    356     const unsigned char *p = (const unsigned char*)pBuf;
   354    357     const unsigned char *pStart = p;
   355    358     u32 a;
   356    359     u64 b;
   357    360     int shift;
   358    361   
   359    362     GETVARINT_INIT(a, p, 0,  0x00,     0x80, *v, 1);
................................................................................
   366    369       u64 c = *p++;
   367    370       b += (c&0x7F) << shift;
   368    371       if( (c & 0x80)==0 ) break;
   369    372     }
   370    373     *v = b;
   371    374     return (int)(p - pStart);
   372    375   }
          376  +
          377  +/* 
          378  +** Read a 64-bit variable-length integer from memory starting at p[0].
          379  +** Return the number of bytes read, or 0 on error.
          380  +** The value is stored in *v.
          381  +*/
          382  +int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){
          383  +  return sqlite3Fts3GetVarintU(pBuf, (sqlite3_uint64*)v);
          384  +}
          385  +
          386  +/* 
          387  +** Read a 64-bit variable-length integer from memory starting at p[0] and
          388  +** not extending past pEnd[-1].
          389  +** Return the number of bytes read, or 0 on error.
          390  +** The value is stored in *v.
          391  +*/
          392  +int sqlite3Fts3GetVarintBounded(
          393  +  const char *pBuf,
          394  +  const char *pEnd,
          395  +  sqlite_int64 *v
          396  +){
          397  +  const unsigned char *p = (const unsigned char*)pBuf;
          398  +  const unsigned char *pStart = p;
          399  +  const unsigned char *pX = (const unsigned char*)pEnd;
          400  +  u64 b = 0;
          401  +  int shift;
          402  +  for(shift=0; shift<=63; shift+=7){
          403  +    u64 c = p<pX ? *p : 0;
          404  +    p++;
          405  +    b += (c&0x7F) << shift;
          406  +    if( (c & 0x80)==0 ) break;
          407  +  }
          408  +  *v = b;
          409  +  return (int)(p - pStart);
          410  +}
   373    411   
   374    412   /*
   375    413   ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to 
   376    414   ** a non-negative 32-bit integer before it is returned.
   377    415   */
   378    416   int sqlite3Fts3GetVarint32(const char *p, int *pi){
          417  +  const unsigned char *ptr = (const unsigned char*)p;
   379    418     u32 a;
   380    419   
   381    420   #ifndef fts3GetVarint32
   382         -  GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
          421  +  GETVARINT_INIT(a, ptr, 0,  0x00,     0x80, *pi, 1);
   383    422   #else
   384         -  a = (*p++);
          423  +  a = (*ptr++);
   385    424     assert( a & 0x80 );
   386    425   #endif
   387    426   
   388         -  GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
   389         -  GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
   390         -  GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
          427  +  GETVARINT_STEP(a, ptr, 7,  0x7F,     0x4000, *pi, 2);
          428  +  GETVARINT_STEP(a, ptr, 14, 0x3FFF,   0x200000, *pi, 3);
          429  +  GETVARINT_STEP(a, ptr, 21, 0x1FFFFF, 0x10000000, *pi, 4);
   391    430     a = (a & 0x0FFFFFFF );
   392         -  *pi = (int)(a | ((u32)(*p & 0x07) << 28));
          431  +  *pi = (int)(a | ((u32)(*ptr & 0x07) << 28));
   393    432     assert( 0==(a & 0x80000000) );
   394    433     assert( *pi>=0 );
   395    434     return 5;
   396    435   }
   397    436   
   398    437   /*
   399    438   ** Return the number of bytes required to encode v as a varint
................................................................................
   556    595   static int fts3DestroyMethod(sqlite3_vtab *pVtab){
   557    596     Fts3Table *p = (Fts3Table *)pVtab;
   558    597     int rc = SQLITE_OK;              /* Return code */
   559    598     const char *zDb = p->zDb;        /* Name of database (e.g. "main", "temp") */
   560    599     sqlite3 *db = p->db;             /* Database handle */
   561    600   
   562    601     /* Drop the shadow tables */
   563         -  if( p->zContentTbl==0 ){
   564         -    fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
   565         -  }
   566         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
   567         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
   568         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
   569         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
          602  +  fts3DbExec(&rc, db, 
          603  +    "DROP TABLE IF EXISTS %Q.'%q_segments';"
          604  +    "DROP TABLE IF EXISTS %Q.'%q_segdir';"
          605  +    "DROP TABLE IF EXISTS %Q.'%q_docsize';"
          606  +    "DROP TABLE IF EXISTS %Q.'%q_stat';"
          607  +    "%s DROP TABLE IF EXISTS %Q.'%q_content';",
          608  +    zDb, p->zName,
          609  +    zDb, p->zName,
          610  +    zDb, p->zName,
          611  +    zDb, p->zName,
          612  +    (p->zContentTbl ? "--" : ""), zDb,p->zName
          613  +  );
   570    614   
   571    615     /* If everything has worked, invoke fts3DisconnectMethod() to free the
   572    616     ** memory associated with the Fts3Table structure and return SQLITE_OK.
   573    617     ** Otherwise, return an SQLite error code.
   574    618     */
   575    619     return (rc==SQLITE_OK ? fts3DisconnectMethod(pVtab) : rc);
   576    620   }
................................................................................
   794    838   **     fts3QuoteId("un \"zip\"")   ->    "un \"\"zip\"\""
   795    839   **
   796    840   ** The pointer returned points to memory obtained from sqlite3_malloc(). It
   797    841   ** is the callers responsibility to call sqlite3_free() to release this
   798    842   ** memory.
   799    843   */
   800    844   static char *fts3QuoteId(char const *zInput){
   801         -  int nRet;
          845  +  sqlite3_int64 nRet;
   802    846     char *zRet;
   803    847     nRet = 2 + (int)strlen(zInput)*2 + 1;
   804         -  zRet = sqlite3_malloc(nRet);
          848  +  zRet = sqlite3_malloc64(nRet);
   805    849     if( zRet ){
   806    850       int i;
   807    851       char *z = zRet;
   808    852       *(z++) = '"';
   809    853       for(i=0; zInput[i]; i++){
   810    854         if( zInput[i]=='"' ) *(z++) = '"';
   811    855         *(z++) = zInput[i];
................................................................................
   913    957     }
   914    958     if( p->zLanguageid ){
   915    959       fts3Appendf(pRc, &zRet, ", ?");
   916    960     }
   917    961     sqlite3_free(zFree);
   918    962     return zRet;
   919    963   }
          964  +
          965  +/*
          966  +** Buffer z contains a positive integer value encoded as utf-8 text.
          967  +** Decode this value and store it in *pnOut, returning the number of bytes
          968  +** consumed. If an overflow error occurs return a negative value.
          969  +*/
          970  +int sqlite3Fts3ReadInt(const char *z, int *pnOut){
          971  +  u64 iVal = 0;
          972  +  int i;
          973  +  for(i=0; z[i]>='0' && z[i]<='9'; i++){
          974  +    iVal = iVal*10 + (z[i] - '0');
          975  +    if( iVal>0x7FFFFFFF ) return -1;
          976  +  }
          977  +  *pnOut = (int)iVal;
          978  +  return i;
          979  +}
   920    980   
   921    981   /*
   922    982   ** This function interprets the string at (*pp) as a non-negative integer
   923    983   ** value. It reads the integer and sets *pnOut to the value read, then 
   924    984   ** sets *pp to point to the byte immediately following the last byte of
   925    985   ** the integer value.
   926    986   **
................................................................................
   929    989   ** If *pp does not being with a decimal digit SQLITE_ERROR is returned and
   930    990   ** the output value undefined. Otherwise SQLITE_OK is returned.
   931    991   **
   932    992   ** This function is used when parsing the "prefix=" FTS4 parameter.
   933    993   */
   934    994   static int fts3GobbleInt(const char **pp, int *pnOut){
   935    995     const int MAX_NPREFIX = 10000000;
   936         -  const char *p;                  /* Iterator pointer */
   937    996     int nInt = 0;                   /* Output value */
   938         -
   939         -  for(p=*pp; p[0]>='0' && p[0]<='9'; p++){
   940         -    nInt = nInt * 10 + (p[0] - '0');
   941         -    if( nInt>MAX_NPREFIX ){
   942         -      nInt = 0;
   943         -      break;
   944         -    }
          997  +  int nByte;
          998  +  nByte = sqlite3Fts3ReadInt(*pp, &nInt);
          999  +  if( nInt>MAX_NPREFIX ){
         1000  +    nInt = 0;
   945   1001     }
   946         -  if( p==*pp ) return SQLITE_ERROR;
         1002  +  if( nByte==0 ){
         1003  +    return SQLITE_ERROR;
         1004  +  }
   947   1005     *pnOut = nInt;
   948         -  *pp = p;
         1006  +  *pp += nByte;
   949   1007     return SQLITE_OK;
   950   1008   }
   951   1009   
   952   1010   /*
   953   1011   ** This function is called to allocate an array of Fts3Index structures
   954   1012   ** representing the indexes maintained by the current FTS table. FTS tables
   955   1013   ** always maintain the main "terms" index, but may also maintain one or
................................................................................
   978   1036       const char *p;
   979   1037       nIndex++;
   980   1038       for(p=zParam; *p; p++){
   981   1039         if( *p==',' ) nIndex++;
   982   1040       }
   983   1041     }
   984   1042   
   985         -  aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex);
         1043  +  aIndex = sqlite3_malloc64(sizeof(struct Fts3Index) * nIndex);
   986   1044     *apIndex = aIndex;
   987   1045     if( !aIndex ){
   988   1046       return SQLITE_NOMEM;
   989   1047     }
   990   1048   
   991   1049     memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
   992   1050     if( zParam ){
................................................................................
  1057   1115         sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
  1058   1116       }
  1059   1117     }
  1060   1118     sqlite3_free(zSql);
  1061   1119   
  1062   1120     if( rc==SQLITE_OK ){
  1063   1121       const char **azCol;           /* Output array */
  1064         -    int nStr = 0;                 /* Size of all column names (incl. 0x00) */
         1122  +    sqlite3_int64 nStr = 0;       /* Size of all column names (incl. 0x00) */
  1065   1123       int nCol;                     /* Number of table columns */
  1066   1124       int i;                        /* Used to iterate through columns */
  1067   1125   
  1068   1126       /* Loop through the returned columns. Set nStr to the number of bytes of
  1069   1127       ** space required to store a copy of each column name, including the
  1070   1128       ** nul-terminator byte.  */
  1071   1129       nCol = sqlite3_column_count(pStmt);
  1072   1130       for(i=0; i<nCol; i++){
  1073   1131         const char *zCol = sqlite3_column_name(pStmt, i);
  1074         -      nStr += (int)strlen(zCol) + 1;
         1132  +      nStr += strlen(zCol) + 1;
  1075   1133       }
  1076   1134   
  1077   1135       /* Allocate and populate the array to return. */
  1078         -    azCol = (const char **)sqlite3_malloc(sizeof(char *) * nCol + nStr);
         1136  +    azCol = (const char **)sqlite3_malloc64(sizeof(char *) * nCol + nStr);
  1079   1137       if( azCol==0 ){
  1080   1138         rc = SQLITE_NOMEM;
  1081   1139       }else{
  1082   1140         char *p = (char *)&azCol[nCol];
  1083   1141         for(i=0; i<nCol; i++){
  1084   1142           const char *zCol = sqlite3_column_name(pStmt, i);
  1085   1143           int n = (int)strlen(zCol)+1;
................................................................................
  1119   1177     sqlite3_vtab **ppVTab,          /* Write the resulting vtab structure here */
  1120   1178     char **pzErr                    /* Write any error message here */
  1121   1179   ){
  1122   1180     Fts3Hash *pHash = (Fts3Hash *)pAux;
  1123   1181     Fts3Table *p = 0;               /* Pointer to allocated vtab */
  1124   1182     int rc = SQLITE_OK;             /* Return code */
  1125   1183     int i;                          /* Iterator variable */
  1126         -  int nByte;                      /* Size of allocation used for *p */
         1184  +  sqlite3_int64 nByte;            /* Size of allocation used for *p */
  1127   1185     int iCol;                       /* Column index */
  1128   1186     int nString = 0;                /* Bytes required to hold all column names */
  1129   1187     int nCol = 0;                   /* Number of columns in the FTS table */
  1130   1188     char *zCsr;                     /* Space for holding column names */
  1131   1189     int nDb;                        /* Bytes required to hold database name */
  1132   1190     int nName;                      /* Bytes required to hold table name */
  1133   1191     int isFts4 = (argv[0][3]=='4'); /* True for FTS4, false for FTS3 */
................................................................................
  1153   1211          || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
  1154   1212     );
  1155   1213   
  1156   1214     nDb = (int)strlen(argv[1]) + 1;
  1157   1215     nName = (int)strlen(argv[2]) + 1;
  1158   1216   
  1159   1217     nByte = sizeof(const char *) * (argc-2);
  1160         -  aCol = (const char **)sqlite3_malloc(nByte);
         1218  +  aCol = (const char **)sqlite3_malloc64(nByte);
  1161   1219     if( aCol ){
  1162   1220       memset((void*)aCol, 0, nByte);
  1163         -    azNotindexed = (char **)sqlite3_malloc(nByte);
         1221  +    azNotindexed = (char **)sqlite3_malloc64(nByte);
  1164   1222     }
  1165   1223     if( azNotindexed ){
  1166   1224       memset(azNotindexed, 0, nByte);
  1167   1225     }
  1168   1226     if( !aCol || !azNotindexed ){
  1169   1227       rc = SQLITE_NOMEM;
  1170   1228       goto fts3_init_out;
................................................................................
  1351   1409     nByte = sizeof(Fts3Table) +                  /* Fts3Table */
  1352   1410             nCol * sizeof(char *) +              /* azColumn */
  1353   1411             nIndex * sizeof(struct Fts3Index) +  /* aIndex */
  1354   1412             nCol * sizeof(u8) +                  /* abNotindexed */
  1355   1413             nName +                              /* zName */
  1356   1414             nDb +                                /* zDb */
  1357   1415             nString;                             /* Space for azColumn strings */
  1358         -  p = (Fts3Table*)sqlite3_malloc(nByte);
         1416  +  p = (Fts3Table*)sqlite3_malloc64(nByte);
  1359   1417     if( p==0 ){
  1360   1418       rc = SQLITE_NOMEM;
  1361   1419       goto fts3_init_out;
  1362   1420     }
  1363   1421     memset(p, 0, nByte);
  1364   1422     p->db = db;
  1365   1423     p->nColumn = nCol;
................................................................................
  1455   1513       p->bHasStat = 2;
  1456   1514     }
  1457   1515   
  1458   1516     /* Figure out the page-size for the database. This is required in order to
  1459   1517     ** estimate the cost of loading large doclists from the database.  */
  1460   1518     fts3DatabasePageSize(&rc, p);
  1461   1519     p->nNodeSize = p->nPgsz-35;
         1520  +
         1521  +#if defined(SQLITE_DEBUG)||defined(SQLITE_TEST)
         1522  +  p->nMergeCount = FTS3_MERGE_COUNT;
         1523  +#endif
  1462   1524   
  1463   1525     /* Declare the table schema to SQLite. */
  1464   1526     fts3DeclareVtab(&rc, p);
  1465   1527   
  1466   1528   fts3_init_out:
  1467   1529     sqlite3_free(zPrefix);
  1468   1530     sqlite3_free(aIndex);
................................................................................
  1550   1612     int i;                          /* Iterator variable */
  1551   1613     int iCons = -1;                 /* Index of constraint to use */
  1552   1614   
  1553   1615     int iLangidCons = -1;           /* Index of langid=x constraint, if present */
  1554   1616     int iDocidGe = -1;              /* Index of docid>=x constraint, if present */
  1555   1617     int iDocidLe = -1;              /* Index of docid<=x constraint, if present */
  1556   1618     int iIdx;
         1619  +
         1620  +  if( p->bLock ){
         1621  +    return SQLITE_ERROR;
         1622  +  }
  1557   1623   
  1558   1624     /* By default use a full table scan. This is an expensive option,
  1559   1625     ** so search through the constraints to see if a more efficient 
  1560   1626     ** strategy is possible.
  1561   1627     */
  1562   1628     pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
  1563   1629     pInfo->estimatedCost = 5000000;
................................................................................
  1749   1815       char *zSql;
  1750   1816       if( p->pSeekStmt ){
  1751   1817         pCsr->pStmt = p->pSeekStmt;
  1752   1818         p->pSeekStmt = 0;
  1753   1819       }else{
  1754   1820         zSql = sqlite3_mprintf("SELECT %s WHERE rowid = ?", p->zReadExprlist);
  1755   1821         if( !zSql ) return SQLITE_NOMEM;
  1756         -      rc = sqlite3_prepare_v3(p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
         1822  +      p->bLock++;
         1823  +      rc = sqlite3_prepare_v3(
         1824  +          p->db, zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
         1825  +      );
         1826  +      p->bLock--;
  1757   1827         sqlite3_free(zSql);
  1758   1828       }
  1759   1829       if( rc==SQLITE_OK ) pCsr->bSeekStmt = 1;
  1760   1830     }
  1761   1831     return rc;
  1762   1832   }
  1763   1833   
................................................................................
  1767   1837   ** SQLITE_OK on success.  
  1768   1838   */
  1769   1839   static int fts3CursorSeek(sqlite3_context *pContext, Fts3Cursor *pCsr){
  1770   1840     int rc = SQLITE_OK;
  1771   1841     if( pCsr->isRequireSeek ){
  1772   1842       rc = fts3CursorSeekStmt(pCsr);
  1773   1843       if( rc==SQLITE_OK ){
         1844  +      Fts3Table *pTab = (Fts3Table*)pCsr->base.pVtab;
         1845  +      pTab->bLock++;
  1774   1846         sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iPrevId);
  1775   1847         pCsr->isRequireSeek = 0;
  1776   1848         if( SQLITE_ROW==sqlite3_step(pCsr->pStmt) ){
         1849  +        pTab->bLock--;
  1777   1850           return SQLITE_OK;
  1778   1851         }else{
         1852  +        pTab->bLock--;
  1779   1853           rc = sqlite3_reset(pCsr->pStmt);
  1780   1854           if( rc==SQLITE_OK && ((Fts3Table *)pCsr->base.pVtab)->zContentTbl==0 ){
  1781   1855             /* If no row was found and no error has occurred, then the %_content
  1782   1856             ** table is missing a row that is present in the full-text index.
  1783   1857             ** The data structures are corrupt.  */
  1784   1858             rc = FTS_CORRUPT_VTAB;
  1785   1859             pCsr->isEof = 1;
................................................................................
  1820   1894     int rc = SQLITE_OK;             /* Return code */
  1821   1895     const char *zCsr = zNode;       /* Cursor to iterate through node */
  1822   1896     const char *zEnd = &zCsr[nNode];/* End of interior node buffer */
  1823   1897     char *zBuffer = 0;              /* Buffer to load terms into */
  1824   1898     i64 nAlloc = 0;                 /* Size of allocated buffer */
  1825   1899     int isFirstTerm = 1;            /* True when processing first term on page */
  1826   1900     sqlite3_int64 iChild;           /* Block id of child node to descend to */
         1901  +  int nBuffer = 0;                /* Total term size */
  1827   1902   
  1828   1903     /* Skip over the 'height' varint that occurs at the start of every 
  1829   1904     ** interior node. Then load the blockid of the left-child of the b-tree
  1830   1905     ** node into variable iChild.  
  1831   1906     **
  1832   1907     ** Even if the data structure on disk is corrupted, this (reading two
  1833   1908     ** varints from the buffer) does not risk an overread. If zNode is a
................................................................................
  1844   1919       return FTS_CORRUPT_VTAB;
  1845   1920     }
  1846   1921     
  1847   1922     while( zCsr<zEnd && (piFirst || piLast) ){
  1848   1923       int cmp;                      /* memcmp() result */
  1849   1924       int nSuffix;                  /* Size of term suffix */
  1850   1925       int nPrefix = 0;              /* Size of term prefix */
  1851         -    int nBuffer;                  /* Total term size */
  1852   1926     
  1853   1927       /* Load the next term on the node into zBuffer. Use realloc() to expand
  1854   1928       ** the size of zBuffer if required.  */
  1855   1929       if( !isFirstTerm ){
  1856   1930         zCsr += fts3GetVarint32(zCsr, &nPrefix);
         1931  +      if( nPrefix>nBuffer ){
         1932  +        rc = FTS_CORRUPT_VTAB;
         1933  +        goto finish_scan;
         1934  +      }
  1857   1935       }
  1858   1936       isFirstTerm = 0;
  1859   1937       zCsr += fts3GetVarint32(zCsr, &nSuffix);
  1860   1938       
  1861   1939       assert( nPrefix>=0 && nSuffix>=0 );
  1862         -    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
         1940  +    if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
  1863   1941         rc = FTS_CORRUPT_VTAB;
  1864   1942         goto finish_scan;
  1865   1943       }
  1866   1944       if( (i64)nPrefix+nSuffix>nAlloc ){
  1867   1945         char *zNew;
  1868   1946         nAlloc = ((i64)nPrefix+nSuffix) * 2;
  1869   1947         zNew = (char *)sqlite3_realloc64(zBuffer, nAlloc);
................................................................................
  1943   2021     int rc = SQLITE_OK;             /* Return code */
  1944   2022     int iHeight;                    /* Height of this node in tree */
  1945   2023   
  1946   2024     assert( piLeaf || piLeaf2 );
  1947   2025   
  1948   2026     fts3GetVarint32(zNode, &iHeight);
  1949   2027     rc = fts3ScanInteriorNode(zTerm, nTerm, zNode, nNode, piLeaf, piLeaf2);
  1950         -  assert( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
         2028  +  assert_fts3_nc( !piLeaf2 || !piLeaf || rc!=SQLITE_OK || (*piLeaf<=*piLeaf2) );
  1951   2029   
  1952   2030     if( rc==SQLITE_OK && iHeight>1 ){
  1953   2031       char *zBlob = 0;              /* Blob read from %_segments table */
  1954   2032       int nBlob = 0;                /* Size of zBlob in bytes */
  1955   2033   
  1956   2034       if( piLeaf && piLeaf2 && (*piLeaf!=*piLeaf2) ){
  1957   2035         rc = sqlite3Fts3ReadBlock(p, *piLeaf, &zBlob, &nBlob, 0);
................................................................................
  1963   2041         zBlob = 0;
  1964   2042       }
  1965   2043   
  1966   2044       if( rc==SQLITE_OK ){
  1967   2045         rc = sqlite3Fts3ReadBlock(p, piLeaf?*piLeaf:*piLeaf2, &zBlob, &nBlob, 0);
  1968   2046       }
  1969   2047       if( rc==SQLITE_OK ){
  1970         -      rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, piLeaf2);
         2048  +      int iNewHeight = 0;
         2049  +      fts3GetVarint32(zBlob, &iNewHeight);
         2050  +      if( iNewHeight>=iHeight ){
         2051  +        rc = FTS_CORRUPT_VTAB;
         2052  +      }else{
         2053  +        rc = fts3SelectLeaf(p, zTerm, nTerm, zBlob, nBlob, piLeaf, piLeaf2);
         2054  +      }
  1971   2055       }
  1972   2056       sqlite3_free(zBlob);
  1973   2057     }
  1974   2058   
  1975   2059     return rc;
  1976   2060   }
  1977   2061   
................................................................................
  1980   2064   ** varints. Each call to this function appends a single varint to a list.
  1981   2065   */
  1982   2066   static void fts3PutDeltaVarint(
  1983   2067     char **pp,                      /* IN/OUT: Output pointer */
  1984   2068     sqlite3_int64 *piPrev,          /* IN/OUT: Previous value written to list */
  1985   2069     sqlite3_int64 iVal              /* Write this value to the list */
  1986   2070   ){
  1987         -  assert( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
         2071  +  assert_fts3_nc( iVal-*piPrev > 0 || (*piPrev==0 && iVal==0) );
  1988   2072     *pp += sqlite3Fts3PutVarint(*pp, iVal-*piPrev);
  1989   2073     *piPrev = iVal;
  1990   2074   }
  1991   2075   
  1992   2076   /*
  1993   2077   ** When this function is called, *ppPoslist is assumed to point to the 
  1994   2078   ** start of a position-list. After it returns, *ppPoslist points to the
................................................................................
  2068   2152       p += n;
  2069   2153       *pp = p;
  2070   2154     }
  2071   2155     *ppPoslist = pEnd;
  2072   2156   }
  2073   2157   
  2074   2158   /*
  2075         -** Value used to signify the end of an position-list. This is safe because
  2076         -** it is not possible to have a document with 2^31 terms.
         2159  +** Value used to signify the end of an position-list. This must be
         2160  +** as large or larger than any value that might appear on the
         2161  +** position-list, even a position list that has been corrupted.
  2077   2162   */
  2078         -#define POSITION_LIST_END 0x7fffffff
         2163  +#define POSITION_LIST_END LARGEST_INT64
  2079   2164   
  2080   2165   /*
  2081   2166   ** This function is used to help parse position-lists. When this function is
  2082   2167   ** called, *pp may point to the start of the next varint in the position-list
  2083   2168   ** being parsed, or it may point to 1 byte past the end of the position-list
  2084   2169   ** (in which case **pp will be a terminator bytes POS_END (0) or
  2085   2170   ** (1)).
................................................................................
  2096   2181   ** the next position.
  2097   2182   */
  2098   2183   static void fts3ReadNextPos(
  2099   2184     char **pp,                    /* IN/OUT: Pointer into position-list buffer */
  2100   2185     sqlite3_int64 *pi             /* IN/OUT: Value read from position-list */
  2101   2186   ){
  2102   2187     if( (**pp)&0xFE ){
  2103         -    fts3GetDeltaVarint(pp, pi);
         2188  +    int iVal;
         2189  +    *pp += fts3GetVarint32((*pp), &iVal);
         2190  +    *pi += iVal;
  2104   2191       *pi -= 2;
  2105   2192     }else{
  2106   2193       *pi = POSITION_LIST_END;
  2107   2194     }
  2108   2195   }
  2109   2196   
  2110   2197   /*
................................................................................
  2130   2217   /*
  2131   2218   ** Compute the union of two position lists.  The output written
  2132   2219   ** into *pp contains all positions of both *pp1 and *pp2 in sorted
  2133   2220   ** order and with any duplicates removed.  All pointers are
  2134   2221   ** updated appropriately.   The caller is responsible for insuring
  2135   2222   ** that there is enough space in *pp to hold the complete output.
  2136   2223   */
  2137         -static void fts3PoslistMerge(
         2224  +static int fts3PoslistMerge(
  2138   2225     char **pp,                      /* Output buffer */
  2139   2226     char **pp1,                     /* Left input list */
  2140   2227     char **pp2                      /* Right input list */
  2141   2228   ){
  2142   2229     char *p = *pp;
  2143   2230     char *p1 = *pp1;
  2144   2231     char *p2 = *pp2;
  2145   2232   
  2146   2233     while( *p1 || *p2 ){
  2147   2234       int iCol1;         /* The current column index in pp1 */
  2148   2235       int iCol2;         /* The current column index in pp2 */
  2149   2236   
  2150         -    if( *p1==POS_COLUMN ) fts3GetVarint32(&p1[1], &iCol1);
  2151         -    else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
         2237  +    if( *p1==POS_COLUMN ){ 
         2238  +      fts3GetVarint32(&p1[1], &iCol1);
         2239  +      if( iCol1==0 ) return FTS_CORRUPT_VTAB;
         2240  +    }
         2241  +    else if( *p1==POS_END ) iCol1 = 0x7fffffff;
  2152   2242       else iCol1 = 0;
  2153   2243   
  2154         -    if( *p2==POS_COLUMN ) fts3GetVarint32(&p2[1], &iCol2);
  2155         -    else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
         2244  +    if( *p2==POS_COLUMN ){
         2245  +      fts3GetVarint32(&p2[1], &iCol2);
         2246  +      if( iCol2==0 ) return FTS_CORRUPT_VTAB;
         2247  +    }
         2248  +    else if( *p2==POS_END ) iCol2 = 0x7fffffff;
  2156   2249       else iCol2 = 0;
  2157   2250   
  2158   2251       if( iCol1==iCol2 ){
  2159   2252         sqlite3_int64 i1 = 0;       /* Last position from pp1 */
  2160   2253         sqlite3_int64 i2 = 0;       /* Last position from pp2 */
  2161   2254         sqlite3_int64 iPrev = 0;
  2162   2255         int n = fts3PutColNumber(&p, iCol1);
................................................................................
  2170   2263         ** POS_END (0) or POS_COLUMN (1). The following block merges the two lists
  2171   2264         ** and writes the results to buffer p. p is left pointing to the byte
  2172   2265         ** after the list written. No terminator (POS_END or POS_COLUMN) is
  2173   2266         ** written to the output.
  2174   2267         */
  2175   2268         fts3GetDeltaVarint(&p1, &i1);
  2176   2269         fts3GetDeltaVarint(&p2, &i2);
         2270  +      if( i1<2 || i2<2 ){
         2271  +        break;
         2272  +      }
  2177   2273         do {
  2178   2274           fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2); 
  2179   2275           iPrev -= 2;
  2180   2276           if( i1==i2 ){
  2181   2277             fts3ReadNextPos(&p1, &i1);
  2182   2278             fts3ReadNextPos(&p2, &i2);
  2183   2279           }else if( i1<i2 ){
................................................................................
  2195   2291       }
  2196   2292     }
  2197   2293   
  2198   2294     *p++ = POS_END;
  2199   2295     *pp = p;
  2200   2296     *pp1 = p1 + 1;
  2201   2297     *pp2 = p2 + 1;
         2298  +  return SQLITE_OK;
  2202   2299   }
  2203   2300   
  2204   2301   /*
  2205   2302   ** This function is used to merge two position lists into one. When it is
  2206   2303   ** called, *pp1 and *pp2 must both point to position lists. A position-list is
  2207   2304   ** the part of a doclist that follows each document id. For example, if a row
  2208   2305   ** contains:
................................................................................
  2237   2334     char *p2 = *pp2;
  2238   2335     int iCol1 = 0;
  2239   2336     int iCol2 = 0;
  2240   2337   
  2241   2338     /* Never set both isSaveLeft and isExact for the same invocation. */
  2242   2339     assert( isSaveLeft==0 || isExact==0 );
  2243   2340   
  2244         -  assert( p!=0 && *p1!=0 && *p2!=0 );
         2341  +  assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 );
  2245   2342     if( *p1==POS_COLUMN ){ 
  2246   2343       p1++;
  2247   2344       p1 += fts3GetVarint32(p1, &iCol1);
  2248   2345     }
  2249   2346     if( *p2==POS_COLUMN ){ 
  2250   2347       p2++;
  2251   2348       p2 += fts3GetVarint32(p2, &iCol2);
................................................................................
  2259   2356         sqlite3_int64 iPos2 = 0;
  2260   2357   
  2261   2358         if( iCol1 ){
  2262   2359           *p++ = POS_COLUMN;
  2263   2360           p += sqlite3Fts3PutVarint(p, iCol1);
  2264   2361         }
  2265   2362   
  2266         -      assert( *p1!=POS_END && *p1!=POS_COLUMN );
  2267         -      assert( *p2!=POS_END && *p2!=POS_COLUMN );
  2268   2363         fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
  2269   2364         fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
         2365  +      if( iPos1<0 || iPos2<0 ) break;
  2270   2366   
  2271   2367         while( 1 ){
  2272   2368           if( iPos2==iPos1+nToken 
  2273   2369            || (isExact==0 && iPos2>iPos1 && iPos2<=iPos1+nToken) 
  2274   2370           ){
  2275   2371             sqlite3_int64 iSave;
  2276   2372             iSave = isSaveLeft ? iPos1 : iPos2;
................................................................................
  2411   2507     char *pEnd,                     /* End of buffer */
  2412   2508     int bDescIdx,                   /* True if docids are descending */
  2413   2509     sqlite3_int64 *pVal             /* IN/OUT: Integer value */
  2414   2510   ){
  2415   2511     if( *pp>=pEnd ){
  2416   2512       *pp = 0;
  2417   2513     }else{
  2418         -    sqlite3_int64 iVal;
  2419         -    *pp += sqlite3Fts3GetVarint(*pp, &iVal);
         2514  +    u64 iVal;
         2515  +    *pp += sqlite3Fts3GetVarintU(*pp, &iVal);
  2420   2516       if( bDescIdx ){
  2421         -      *pVal -= iVal;
         2517  +      *pVal = (i64)((u64)*pVal - iVal);
  2422   2518       }else{
  2423         -      *pVal += iVal;
         2519  +      *pVal = (i64)((u64)*pVal + iVal);
  2424   2520       }
  2425   2521     }
  2426   2522   }
  2427   2523   
  2428   2524   /*
  2429   2525   ** This function is used to write a single varint to a buffer. The varint
  2430   2526   ** is written to *pp. Before returning, *pp is set to point 1 byte past the
................................................................................
  2443   2539   static void fts3PutDeltaVarint3(
  2444   2540     char **pp,                      /* IN/OUT: Output pointer */
  2445   2541     int bDescIdx,                   /* True for descending docids */
  2446   2542     sqlite3_int64 *piPrev,          /* IN/OUT: Previous value written to list */
  2447   2543     int *pbFirst,                   /* IN/OUT: True after first int written */
  2448   2544     sqlite3_int64 iVal              /* Write this value to the list */
  2449   2545   ){
  2450         -  sqlite3_int64 iWrite;
         2546  +  sqlite3_uint64 iWrite;
  2451   2547     if( bDescIdx==0 || *pbFirst==0 ){
  2452         -    iWrite = iVal - *piPrev;
         2548  +    assert_fts3_nc( *pbFirst==0 || iVal>=*piPrev );
         2549  +    iWrite = (u64)iVal - (u64)*piPrev;
  2453   2550     }else{
  2454         -    iWrite = *piPrev - iVal;
         2551  +    assert_fts3_nc( *piPrev>=iVal );
         2552  +    iWrite = (u64)*piPrev - (u64)iVal;
  2455   2553     }
  2456   2554     assert( *pbFirst || *piPrev==0 );
  2457         -  assert( *pbFirst==0 || iWrite>0 );
         2555  +  assert_fts3_nc( *pbFirst==0 || iWrite>0 );
  2458   2556     *pp += sqlite3Fts3PutVarint(*pp, iWrite);
  2459   2557     *piPrev = iVal;
  2460   2558     *pbFirst = 1;
  2461   2559   }
  2462   2560   
  2463   2561   
  2464   2562   /*
................................................................................
  2466   2564   ** arguments are 64-bit docid values. If the value of the stack variable
  2467   2565   ** bDescDoclist is 0 when this macro is invoked, then it returns (i1-i2). 
  2468   2566   ** Otherwise, (i2-i1).
  2469   2567   **
  2470   2568   ** Using this makes it easier to write code that can merge doclists that are
  2471   2569   ** sorted in either ascending or descending order.
  2472   2570   */
  2473         -#define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1-i2))
         2571  +/* #define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i64)((u64)i1-i2)) */
         2572  +#define DOCID_CMP(i1, i2) ((bDescDoclist?-1:1) * (i1>i2?1:((i1==i2)?0:-1)))
  2474   2573   
  2475   2574   /*
  2476   2575   ** This function does an "OR" merge of two doclists (output contains all
  2477   2576   ** positions contained in either argument doclist). If the docids in the 
  2478   2577   ** input doclists are sorted in ascending order, parameter bDescDoclist
  2479   2578   ** should be false. If they are sorted in ascending order, it should be
  2480   2579   ** passed a non-zero value.
................................................................................
  2488   2587   */
  2489   2588   static int fts3DoclistOrMerge(
  2490   2589     int bDescDoclist,               /* True if arguments are desc */
  2491   2590     char *a1, int n1,               /* First doclist */
  2492   2591     char *a2, int n2,               /* Second doclist */
  2493   2592     char **paOut, int *pnOut        /* OUT: Malloc'd doclist */
  2494   2593   ){
         2594  +  int rc = SQLITE_OK;
  2495   2595     sqlite3_int64 i1 = 0;
  2496   2596     sqlite3_int64 i2 = 0;
  2497   2597     sqlite3_int64 iPrev = 0;
  2498   2598     char *pEnd1 = &a1[n1];
  2499   2599     char *pEnd2 = &a2[n2];
  2500   2600     char *p1 = a1;
  2501   2601     char *p2 = a2;
................................................................................
  2531   2631     ** The space required to store the output is therefore the sum of the
  2532   2632     ** sizes of the two inputs, plus enough space for exactly one of the input
  2533   2633     ** docids to grow. 
  2534   2634     **
  2535   2635     ** A symetric argument may be made if the doclists are in descending 
  2536   2636     ** order.
  2537   2637     */
  2538         -  aOut = sqlite3_malloc(n1+n2+FTS3_VARINT_MAX-1);
         2638  +  aOut = sqlite3_malloc64((i64)n1+n2+FTS3_VARINT_MAX-1+FTS3_BUFFER_PADDING);
  2539   2639     if( !aOut ) return SQLITE_NOMEM;
  2540   2640   
  2541   2641     p = aOut;
  2542   2642     fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
  2543   2643     fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
  2544   2644     while( p1 || p2 ){
  2545   2645       sqlite3_int64 iDiff = DOCID_CMP(i1, i2);
  2546   2646   
  2547   2647       if( p2 && p1 && iDiff==0 ){
  2548   2648         fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i1);
  2549         -      fts3PoslistMerge(&p, &p1, &p2);
         2649  +      rc = fts3PoslistMerge(&p, &p1, &p2);
         2650  +      if( rc ) break;
  2550   2651         fts3GetDeltaVarint3(&p1, pEnd1, bDescDoclist, &i1);
  2551   2652         fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
  2552   2653       }else if( !p2 || (p1 && iDiff<0) ){
  2553   2654         fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i1);
  2554   2655         fts3PoslistCopy(&p, &p1);
  2555   2656         fts3GetDeltaVarint3(&p1, pEnd1, bDescDoclist, &i1);
  2556   2657       }else{
  2557   2658         fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i2);
  2558   2659         fts3PoslistCopy(&p, &p2);
  2559   2660         fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
  2560   2661       }
         2662  +    
         2663  +    assert( (p-aOut)<=((p1?(p1-a1):n1)+(p2?(p2-a2):n2)+FTS3_VARINT_MAX-1) );
  2561   2664     }
  2562   2665   
         2666  +  if( rc!=SQLITE_OK ){
         2667  +    sqlite3_free(aOut);
         2668  +    p = aOut = 0;
         2669  +  }else{
         2670  +    assert( (p-aOut)<=n1+n2+FTS3_VARINT_MAX-1 );
         2671  +    memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
         2672  +  }
  2563   2673     *paOut = aOut;
  2564   2674     *pnOut = (int)(p-aOut);
  2565         -  assert( *pnOut<=n1+n2+FTS3_VARINT_MAX-1 );
  2566         -  return SQLITE_OK;
         2675  +  return rc;
  2567   2676   }
  2568   2677   
  2569   2678   /*
  2570   2679   ** This function does a "phrase" merge of two doclists. In a phrase merge,
  2571   2680   ** the output contains a copy of each position from the right-hand input
  2572   2681   ** doclist for which there is a position in the left-hand input doclist
  2573   2682   ** exactly nDist tokens before it.
................................................................................
  2594   2703     char *p2 = aRight;
  2595   2704     char *p;
  2596   2705     int bFirstOut = 0;
  2597   2706     char *aOut;
  2598   2707   
  2599   2708     assert( nDist>0 );
  2600   2709     if( bDescDoclist ){
  2601         -    aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX);
         2710  +    aOut = sqlite3_malloc64((sqlite3_int64)*pnRight + FTS3_VARINT_MAX);
  2602   2711       if( aOut==0 ) return SQLITE_NOMEM;
  2603   2712     }else{
  2604   2713       aOut = aRight;
  2605   2714     }
  2606   2715     p = aOut;
  2607   2716   
  2608   2717     fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
................................................................................
  2778   2887       **
  2779   2888       ** Similar padding is added in the fts3DoclistOrMerge() function.
  2780   2889       */
  2781   2890       pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
  2782   2891       pTS->anOutput[0] = nDoclist;
  2783   2892       if( pTS->aaOutput[0] ){
  2784   2893         memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
         2894  +      memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
  2785   2895       }else{
  2786   2896         return SQLITE_NOMEM;
  2787   2897       }
  2788   2898     }else{
  2789   2899       char *aMerge = aDoclist;
  2790   2900       int nMerge = nDoclist;
  2791   2901       int iOut;
................................................................................
  2829   2939   */
  2830   2940   static int fts3SegReaderCursorAppend(
  2831   2941     Fts3MultiSegReader *pCsr, 
  2832   2942     Fts3SegReader *pNew
  2833   2943   ){
  2834   2944     if( (pCsr->nSegment%16)==0 ){
  2835   2945       Fts3SegReader **apNew;
  2836         -    int nByte = (pCsr->nSegment + 16)*sizeof(Fts3SegReader*);
  2837         -    apNew = (Fts3SegReader **)sqlite3_realloc(pCsr->apSegment, nByte);
         2946  +    sqlite3_int64 nByte = (pCsr->nSegment + 16)*sizeof(Fts3SegReader*);
         2947  +    apNew = (Fts3SegReader **)sqlite3_realloc64(pCsr->apSegment, nByte);
  2838   2948       if( !apNew ){
  2839   2949         sqlite3Fts3SegReaderFree(pNew);
  2840   2950         return SQLITE_NOMEM;
  2841   2951       }
  2842   2952       pCsr->apSegment = apNew;
  2843   2953     }
  2844   2954     pCsr->apSegment[pCsr->nSegment++] = pNew;
................................................................................
  2869   2979   
  2870   2980     /* If iLevel is less than 0 and this is not a scan, include a seg-reader 
  2871   2981     ** for the pending-terms. If this is a scan, then this call must be being
  2872   2982     ** made by an fts4aux module, not an FTS table. In this case calling
  2873   2983     ** Fts3SegReaderPending might segfault, as the data structures used by 
  2874   2984     ** fts4aux are not completely populated. So it's easiest to filter these
  2875   2985     ** calls out here.  */
  2876         -  if( iLevel<0 && p->aIndex ){
         2986  +  if( iLevel<0 && p->aIndex && p->iPrevLangid==iLangid ){
  2877   2987       Fts3SegReader *pSeg = 0;
  2878   2988       rc = sqlite3Fts3SegReaderPending(p, iIndex, zTerm, nTerm, isPrefix||isScan, &pSeg);
  2879   2989       if( rc==SQLITE_OK && pSeg ){
  2880   2990         rc = fts3SegReaderCursorAppend(pCsr, pSeg);
  2881   2991       }
  2882   2992     }
  2883   2993   
................................................................................
  2894   3004         sqlite3_int64 iLeavesEndBlock = sqlite3_column_int64(pStmt, 2);
  2895   3005         sqlite3_int64 iEndBlock = sqlite3_column_int64(pStmt, 3);
  2896   3006         int nRoot = sqlite3_column_bytes(pStmt, 4);
  2897   3007         char const *zRoot = sqlite3_column_blob(pStmt, 4);
  2898   3008   
  2899   3009         /* If zTerm is not NULL, and this segment is not stored entirely on its
  2900   3010         ** root node, the range of leaves scanned can be reduced. Do this. */
  2901         -      if( iStartBlock && zTerm ){
         3011  +      if( iStartBlock && zTerm && zRoot ){
  2902   3012           sqlite3_int64 *pi = (isPrefix ? &iLeavesEndBlock : 0);
  2903   3013           rc = fts3SelectLeaf(p, zTerm, nTerm, zRoot, nRoot, &iStartBlock, pi);
  2904   3014           if( rc!=SQLITE_OK ) goto finished;
  2905   3015           if( isPrefix==0 && isScan==0 ) iLeavesEndBlock = iStartBlock;
  2906   3016         }
  2907   3017    
  2908   3018         rc = sqlite3Fts3SegReaderNew(pCsr->nSegment+1, 
................................................................................
  3132   3242   ** even if we reach end-of-file.  The fts3EofMethod() will be called
  3133   3243   ** subsequently to determine whether or not an EOF was hit.
  3134   3244   */
  3135   3245   static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
  3136   3246     int rc;
  3137   3247     Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
  3138   3248     if( pCsr->eSearch==FTS3_DOCID_SEARCH || pCsr->eSearch==FTS3_FULLSCAN_SEARCH ){
         3249  +    Fts3Table *pTab = (Fts3Table*)pCursor->pVtab;
         3250  +    pTab->bLock++;
  3139   3251       if( SQLITE_ROW!=sqlite3_step(pCsr->pStmt) ){
  3140   3252         pCsr->isEof = 1;
  3141   3253         rc = sqlite3_reset(pCsr->pStmt);
  3142   3254       }else{
  3143   3255         pCsr->iPrevId = sqlite3_column_int64(pCsr->pStmt, 0);
  3144   3256         rc = SQLITE_OK;
  3145   3257       }
         3258  +    pTab->bLock--;
  3146   3259     }else{
  3147   3260       rc = fts3EvalNext((Fts3Cursor *)pCursor);
  3148   3261     }
  3149   3262     assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
  3150   3263     return rc;
  3151   3264   }
  3152   3265   
  3153         -/*
  3154         -** The following are copied from sqliteInt.h.
  3155         -**
  3156         -** Constants for the largest and smallest possible 64-bit signed integers.
  3157         -** These macros are designed to work correctly on both 32-bit and 64-bit
  3158         -** compilers.
  3159         -*/
  3160         -#ifndef SQLITE_AMALGAMATION
  3161         -# define LARGEST_INT64  (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
  3162         -# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
  3163         -#endif
  3164         -
  3165   3266   /*
  3166   3267   ** If the numeric type of argument pVal is "integer", then return it
  3167   3268   ** converted to a 64-bit signed integer. Otherwise, return a copy of
  3168   3269   ** the second parameter, iDefault.
  3169   3270   */
  3170   3271   static sqlite3_int64 fts3DocidRange(sqlite3_value *pVal, i64 iDefault){
  3171   3272     if( pVal ){
................................................................................
  3210   3311     sqlite3_value *pLangid = 0;     /* The "langid = ?" constraint, if any */
  3211   3312     sqlite3_value *pDocidGe = 0;    /* The "docid >= ?" constraint, if any */
  3212   3313     sqlite3_value *pDocidLe = 0;    /* The "docid <= ?" constraint, if any */
  3213   3314     int iIdx;
  3214   3315   
  3215   3316     UNUSED_PARAMETER(idxStr);
  3216   3317     UNUSED_PARAMETER(nVal);
         3318  +
         3319  +  if( p->bLock ){
         3320  +    return SQLITE_ERROR;
         3321  +  }
  3217   3322   
  3218   3323     eSearch = (idxNum & 0x0000FFFF);
  3219   3324     assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
  3220   3325     assert( p->pSegments==0 );
  3221   3326   
  3222   3327     /* Collect arguments into local variables */
  3223   3328     iIdx = 0;
................................................................................
  3282   3387         );
  3283   3388       }else{
  3284   3389         zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s", 
  3285   3390             p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
  3286   3391         );
  3287   3392       }
  3288   3393       if( zSql ){
  3289         -      rc = sqlite3_prepare_v3(p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0);
         3394  +      p->bLock++;
         3395  +      rc = sqlite3_prepare_v3(
         3396  +          p->db,zSql,-1,SQLITE_PREPARE_PERSISTENT,&pCsr->pStmt,0
         3397  +      );
         3398  +      p->bLock--;
  3290   3399         sqlite3_free(zSql);
  3291   3400       }else{
  3292   3401         rc = SQLITE_NOMEM;
  3293   3402       }
  3294   3403     }else if( eSearch==FTS3_DOCID_SEARCH ){
  3295   3404       rc = fts3CursorSeekStmt(pCsr);
  3296   3405       if( rc==SQLITE_OK ){
................................................................................
  3366   3475           sqlite3_result_int64(pCtx, pCsr->iLangid);
  3367   3476           break;
  3368   3477         }else if( p->zLanguageid==0 ){
  3369   3478           sqlite3_result_int(pCtx, 0);
  3370   3479           break;
  3371   3480         }else{
  3372   3481           iCol = p->nColumn;
  3373         -        /* fall-through */
         3482  +        /* no break */ deliberate_fall_through
  3374   3483         }
  3375   3484   
  3376   3485       default:
  3377   3486         /* A user column. Or, if this is a full-table scan, possibly the
  3378   3487         ** language-id column. Seek the cursor. */
  3379   3488         rc = fts3CursorSeek(0, pCsr);
  3380   3489         if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
................................................................................
  3609   3718           "wrong number of arguments to function snippet()", -1);
  3610   3719       return;
  3611   3720     }
  3612   3721     if( fts3FunctionArg(pContext, "snippet", apVal[0], &pCsr) ) return;
  3613   3722   
  3614   3723     switch( nVal ){
  3615   3724       case 6: nToken = sqlite3_value_int(apVal[5]);
         3725  +            /* no break */ deliberate_fall_through
  3616   3726       case 5: iCol = sqlite3_value_int(apVal[4]);
         3727  +            /* no break */ deliberate_fall_through
  3617   3728       case 4: zEllipsis = (const char*)sqlite3_value_text(apVal[3]);
         3729  +            /* no break */ deliberate_fall_through
  3618   3730       case 3: zEnd = (const char*)sqlite3_value_text(apVal[2]);
         3731  +            /* no break */ deliberate_fall_through
  3619   3732       case 2: zStart = (const char*)sqlite3_value_text(apVal[1]);
  3620   3733     }
  3621   3734     if( !zEllipsis || !zEnd || !zStart ){
  3622   3735       sqlite3_result_error_nomem(pContext);
  3623   3736     }else if( nToken==0 ){
  3624   3737       sqlite3_result_text(pContext, "", -1, SQLITE_STATIC);
  3625   3738     }else if( SQLITE_OK==fts3CursorSeek(pContext, pCsr) ){
................................................................................
  3836   3949   **
  3837   3950   ** Discard the contents of the pending terms table.
  3838   3951   */
  3839   3952   static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
  3840   3953     Fts3Table *p = (Fts3Table*)pVtab;
  3841   3954     UNUSED_PARAMETER(iSavepoint);
  3842   3955     assert( p->inTransaction );
  3843         -  assert( p->mxSavepoint >= iSavepoint );
  3844   3956     TESTONLY( p->mxSavepoint = iSavepoint );
  3845   3957     sqlite3Fts3PendingTermsClear(p);
  3846   3958     return SQLITE_OK;
  3847   3959   }
  3848   3960   
  3849   3961   /*
  3850   3962   ** Return true if zName is the extension on one of the shadow tables used
................................................................................
  4300   4412     ** scanned in forward order, and the phrase consists of 
  4301   4413     ** MAX_INCR_PHRASE_TOKENS or fewer tokens, none of which are are "^first"
  4302   4414     ** tokens or prefix tokens that cannot use a prefix-index.  */
  4303   4415     int bHaveIncr = 0;
  4304   4416     int bIncrOk = (bOptOk 
  4305   4417      && pCsr->bDesc==pTab->bDescIdx 
  4306   4418      && p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
  4307         -#ifdef SQLITE_TEST
         4419  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  4308   4420      && pTab->bNoIncrDoclist==0
  4309   4421   #endif
  4310   4422     );
  4311   4423     for(i=0; bIncrOk==1 && i<p->nToken; i++){
  4312   4424       Fts3PhraseToken *pToken = &p->aToken[i];
  4313   4425       if( pToken->bFirst || (pToken->pSegcsr!=0 && !pToken->pSegcsr->bLookup) ){
  4314   4426         bIncrOk = 0;
................................................................................
  4411   4523     sqlite3_int64 *piDocid,         /* IN/OUT: Docid pointer */
  4412   4524     u8 *pbEof                       /* OUT: End-of-file flag */
  4413   4525   ){
  4414   4526     char *p = *ppIter;
  4415   4527   
  4416   4528     assert( nDoclist>0 );
  4417   4529     assert( *pbEof==0 );
  4418         -  assert( p || *piDocid==0 );
         4530  +  assert_fts3_nc( p || *piDocid==0 );
  4419   4531     assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) );
  4420   4532   
  4421   4533     if( p==0 ){
  4422   4534       p = aDoclist;
  4423   4535       p += sqlite3Fts3GetVarint(p, piDocid);
  4424   4536     }else{
  4425   4537       fts3PoslistCopy(0, &p);
................................................................................
  4442   4554   */
  4443   4555   static void fts3EvalDlPhraseNext(
  4444   4556     Fts3Table *pTab,
  4445   4557     Fts3Doclist *pDL,
  4446   4558     u8 *pbEof
  4447   4559   ){
  4448   4560     char *pIter;                            /* Used to iterate through aAll */
  4449         -  char *pEnd = &pDL->aAll[pDL->nAll];     /* 1 byte past end of aAll */
         4561  +  char *pEnd;                             /* 1 byte past end of aAll */
  4450   4562    
  4451   4563     if( pDL->pNextDocid ){
  4452   4564       pIter = pDL->pNextDocid;
         4565  +    assert( pDL->aAll!=0 || pIter==0 );
  4453   4566     }else{
  4454   4567       pIter = pDL->aAll;
  4455   4568     }
  4456   4569   
  4457         -  if( pIter>=pEnd ){
         4570  +  if( pIter==0 || pIter>=(pEnd = pDL->aAll + pDL->nAll) ){
  4458   4571       /* We have already reached the end of this doclist. EOF. */
  4459   4572       *pbEof = 1;
  4460   4573     }else{
  4461   4574       sqlite3_int64 iDelta;
  4462   4575       pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
  4463   4576       if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){
  4464   4577         pDL->iDocid += iDelta;
................................................................................
  4611   4724           }
  4612   4725         }
  4613   4726   
  4614   4727         /* Check if the current entries really are a phrase match */
  4615   4728         if( bEof==0 ){
  4616   4729           int nList = 0;
  4617   4730           int nByte = a[p->nToken-1].nList;
  4618         -        char *aDoclist = sqlite3_malloc(nByte+1);
         4731  +        char *aDoclist = sqlite3_malloc(nByte+FTS3_BUFFER_PADDING);
  4619   4732           if( !aDoclist ) return SQLITE_NOMEM;
  4620   4733           memcpy(aDoclist, a[p->nToken-1].pList, nByte+1);
         4734  +        memset(&aDoclist[nByte], 0, FTS3_BUFFER_PADDING);
  4621   4735   
  4622   4736           for(i=0; i<(p->nToken-1); i++){
  4623   4737             if( a[i].bIgnore==0 ){
  4624   4738               char *pL = a[i].pList;
  4625   4739               char *pR = aDoclist;
  4626   4740               char *pOut = aDoclist;
  4627   4741               int nDist = p->nToken-1-i;
................................................................................
  4821   4935       sqlite3_int64 nByte = 0;
  4822   4936       const char *pEnd;
  4823   4937       const char *a;
  4824   4938   
  4825   4939       rc = sqlite3Fts3SelectDoctotal(p, &pStmt);
  4826   4940       if( rc!=SQLITE_OK ) return rc;
  4827   4941       a = sqlite3_column_blob(pStmt, 0);
  4828         -    assert( a );
  4829         -
  4830         -    pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
  4831         -    a += sqlite3Fts3GetVarint(a, &nDoc);
  4832         -    while( a<pEnd ){
  4833         -      a += sqlite3Fts3GetVarint(a, &nByte);
         4942  +    testcase( a==0 );  /* If %_stat.value set to X'' */
         4943  +    if( a ){
         4944  +      pEnd = &a[sqlite3_column_bytes(pStmt, 0)];
         4945  +      a += sqlite3Fts3GetVarintBounded(a, pEnd, &nDoc);
         4946  +      while( a<pEnd ){
         4947  +        a += sqlite3Fts3GetVarintBounded(a, pEnd, &nByte);
         4948  +      }
  4834   4949       }
  4835   4950       if( nDoc==0 || nByte==0 ){
  4836   4951         sqlite3_reset(pStmt);
  4837   4952         return FTS_CORRUPT_VTAB;
  4838   4953       }
  4839   4954   
  4840   4955       pCsr->nDoc = nDoc;
................................................................................
  5004   5119     fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc);
  5005   5120   
  5006   5121     /* Determine which, if any, tokens in the expression should be deferred. */
  5007   5122   #ifndef SQLITE_DISABLE_FTS4_DEFERRED
  5008   5123     if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
  5009   5124       Fts3TokenAndCost *aTC;
  5010   5125       Fts3Expr **apOr;
  5011         -    aTC = (Fts3TokenAndCost *)sqlite3_malloc(
         5126  +    aTC = (Fts3TokenAndCost *)sqlite3_malloc64(
  5012   5127           sizeof(Fts3TokenAndCost) * nToken
  5013   5128         + sizeof(Fts3Expr *) * nOr * 2
  5014   5129       );
  5015   5130       apOr = (Fts3Expr **)&aTC[nToken];
  5016   5131   
  5017   5132       if( !aTC ){
  5018   5133         rc = SQLITE_NOMEM;
................................................................................
  5058   5173   ** the phrase object passed as the fifth argument according to a NEAR
  5059   5174   ** condition. For example:
  5060   5175   **
  5061   5176   **     abc NEAR/5 "def ghi"
  5062   5177   **
  5063   5178   ** Parameter nNear is passed the NEAR distance of the expression (5 in
  5064   5179   ** the example above). When this function is called, *paPoslist points to
  5065         -** the position list, and *pnToken is the number of phrase tokens in, the
         5180  +** the position list, and *pnToken is the number of phrase tokens in the
  5066   5181   ** phrase on the other side of the NEAR operator to pPhrase. For example,
  5067   5182   ** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to
  5068   5183   ** the position list associated with phrase "abc".
  5069   5184   **
  5070   5185   ** All positions in the pPhrase position list that are not sufficiently
  5071   5186   ** close to a position in the *paPoslist position list are removed. If this
  5072   5187   ** leaves 0 positions, zero is returned. Otherwise, non-zero.
................................................................................
  5093   5208   
  5094   5209     p2 = pOut = pPhrase->doclist.pList;
  5095   5210     res = fts3PoslistNearMerge(
  5096   5211       &pOut, aTmp, nParam1, nParam2, paPoslist, &p2
  5097   5212     );
  5098   5213     if( res ){
  5099   5214       nNew = (int)(pOut - pPhrase->doclist.pList) - 1;
  5100         -    assert( pPhrase->doclist.pList[nNew]=='\0' );
  5101         -    assert( nNew<=pPhrase->doclist.nList && nNew>0 );
  5102         -    memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
  5103         -    pPhrase->doclist.nList = nNew;
         5215  +    if( nNew>=0 ){
         5216  +      assert( pPhrase->doclist.pList[nNew]=='\0' );
         5217  +      assert( nNew<=pPhrase->doclist.nList && nNew>0 );
         5218  +      memset(&pPhrase->doclist.pList[nNew], 0, pPhrase->doclist.nList - nNew);
         5219  +      pPhrase->doclist.nList = nNew;
         5220  +    }
  5104   5221       *paPoslist = pPhrase->doclist.pList;
  5105   5222       *pnToken = pPhrase->nToken;
  5106   5223     }
  5107   5224   
  5108   5225     return res;
  5109   5226   }
  5110   5227   
................................................................................
  5205   5322               if( pLeft->pPhrase && pLeft->pPhrase->doclist.aAll ){
  5206   5323                 Fts3Doclist *pDl = &pLeft->pPhrase->doclist;
  5207   5324                 while( *pRc==SQLITE_OK && pLeft->bEof==0 ){
  5208   5325                   memset(pDl->pList, 0, pDl->nList);
  5209   5326                   fts3EvalNextRow(pCsr, pLeft, pRc);
  5210   5327                 }
  5211   5328               }
         5329  +            pRight->bEof = pLeft->bEof = 1;
  5212   5330             }
  5213   5331           }
  5214   5332           break;
  5215   5333         }
  5216   5334     
  5217   5335         case FTSQUERY_OR: {
  5218   5336           Fts3Expr *pLeft = pExpr->pLeft;
................................................................................
  5315   5433     ** no exceptions to this - it's the way the parser in fts3_expr.c works.
  5316   5434     */
  5317   5435     if( *pRc==SQLITE_OK 
  5318   5436      && pExpr->eType==FTSQUERY_NEAR 
  5319   5437      && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
  5320   5438     ){
  5321   5439       Fts3Expr *p; 
  5322         -    int nTmp = 0;                 /* Bytes of temp space */
         5440  +    sqlite3_int64 nTmp = 0;       /* Bytes of temp space */
  5323   5441       char *aTmp;                   /* Temp space for PoslistNearMerge() */
  5324   5442   
  5325   5443       /* Allocate temporary working space. */
  5326   5444       for(p=pExpr; p->pLeft; p=p->pLeft){
  5327   5445         assert( p->pRight->pPhrase->doclist.nList>0 );
  5328   5446         nTmp += p->pRight->pPhrase->doclist.nList;
  5329   5447       }
  5330   5448       nTmp += p->pPhrase->doclist.nList;
  5331         -    aTmp = sqlite3_malloc(nTmp*2);
         5449  +    aTmp = sqlite3_malloc64(nTmp*2);
  5332   5450       if( !aTmp ){
  5333   5451         *pRc = SQLITE_NOMEM;
  5334   5452         res = 0;
  5335   5453       }else{
  5336   5454         char *aPoslist = p->pPhrase->doclist.pList;
  5337   5455         int nToken = p->pPhrase->nToken;
  5338   5456   
................................................................................
  5447   5565             }
  5448   5566             *pRc = fts3EvalDeferredPhrase(pCsr, pPhrase);
  5449   5567             bHit = (pPhrase->doclist.pList!=0);
  5450   5568             pExpr->iDocid = pCsr->iPrevId;
  5451   5569           }else
  5452   5570   #endif
  5453   5571           {
  5454         -          bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId);
         5572  +          bHit = ( 
         5573  +              pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId
         5574  +           && pExpr->pPhrase->doclist.nList>0
         5575  +          );
  5455   5576           }
  5456   5577           break;
  5457   5578         }
  5458   5579       }
  5459   5580     }
  5460   5581     return bHit;
  5461   5582   }
................................................................................
  5594   5715   ** After allocating the Fts3Expr.aMI[] array for each phrase in the 
  5595   5716   ** expression rooted at pExpr, the cursor iterates through all rows matched
  5596   5717   ** by pExpr, calling this function for each row. This function increments
  5597   5718   ** the values in Fts3Expr.aMI[] according to the position-list currently
  5598   5719   ** found in Fts3Expr.pPhrase->doclist.pList for each of the phrase 
  5599   5720   ** expression nodes.
  5600   5721   */
  5601         -static void fts3EvalUpdateCounts(Fts3Expr *pExpr){
         5722  +static void fts3EvalUpdateCounts(Fts3Expr *pExpr, int nCol){
  5602   5723     if( pExpr ){
  5603   5724       Fts3Phrase *pPhrase = pExpr->pPhrase;
  5604   5725       if( pPhrase && pPhrase->doclist.pList ){
  5605   5726         int iCol = 0;
  5606   5727         char *p = pPhrase->doclist.pList;
  5607   5728   
  5608         -      assert( *p );
  5609         -      while( 1 ){
         5729  +      do{
  5610   5730           u8 c = 0;
  5611   5731           int iCnt = 0;
  5612   5732           while( 0xFE & (*p | c) ){
  5613   5733             if( (c&0x80)==0 ) iCnt++;
  5614   5734             c = *p++ & 0x80;
  5615   5735           }
  5616   5736   
................................................................................
  5618   5738           ** aMI[iCol*3 + 2] = Number of rows containing at least one instance
  5619   5739           */
  5620   5740           pExpr->aMI[iCol*3 + 1] += iCnt;
  5621   5741           pExpr->aMI[iCol*3 + 2] += (iCnt>0);
  5622   5742           if( *p==0x00 ) break;
  5623   5743           p++;
  5624   5744           p += fts3GetVarint32(p, &iCol);
  5625         -      }
         5745  +      }while( iCol<nCol );
  5626   5746       }
  5627   5747   
  5628         -    fts3EvalUpdateCounts(pExpr->pLeft);
  5629         -    fts3EvalUpdateCounts(pExpr->pRight);
         5748  +    fts3EvalUpdateCounts(pExpr->pLeft, nCol);
         5749  +    fts3EvalUpdateCounts(pExpr->pRight, nCol);
  5630   5750     }
  5631   5751   }
  5632   5752   
  5633   5753   /*
  5634   5754   ** Expression pExpr must be of type FTSQUERY_PHRASE.
  5635   5755   **
  5636   5756   ** If it is not already allocated and populated, this function allocates and
................................................................................
  5666   5786       bEof = pRoot->bEof;
  5667   5787       assert( pRoot->bStart );
  5668   5788   
  5669   5789       /* Allocate space for the aMSI[] array of each FTSQUERY_PHRASE node */
  5670   5790       for(p=pRoot; p; p=p->pLeft){
  5671   5791         Fts3Expr *pE = (p->eType==FTSQUERY_PHRASE?p:p->pRight);
  5672   5792         assert( pE->aMI==0 );
  5673         -      pE->aMI = (u32 *)sqlite3_malloc(pTab->nColumn * 3 * sizeof(u32));
         5793  +      pE->aMI = (u32 *)sqlite3_malloc64(pTab->nColumn * 3 * sizeof(u32));
  5674   5794         if( !pE->aMI ) return SQLITE_NOMEM;
  5675   5795         memset(pE->aMI, 0, pTab->nColumn * 3 * sizeof(u32));
  5676   5796       }
  5677   5797   
  5678   5798       fts3EvalRestart(pCsr, pRoot, &rc);
  5679   5799   
  5680   5800       while( pCsr->isEof==0 && rc==SQLITE_OK ){
................................................................................
  5692   5812           pCsr->iPrevId = pRoot->iDocid;
  5693   5813         }while( pCsr->isEof==0 
  5694   5814              && pRoot->eType==FTSQUERY_NEAR 
  5695   5815              && sqlite3Fts3EvalTestDeferred(pCsr, &rc) 
  5696   5816         );
  5697   5817   
  5698   5818         if( rc==SQLITE_OK && pCsr->isEof==0 ){
  5699         -        fts3EvalUpdateCounts(pRoot);
         5819  +        fts3EvalUpdateCounts(pRoot, pTab->nColumn);
  5700   5820         }
  5701   5821       }
  5702   5822   
  5703   5823       pCsr->isEof = 0;
  5704   5824       pCsr->iPrevId = iPrevId;
  5705   5825   
  5706   5826       if( bEof ){
................................................................................
  5711   5831         ** do loop can not be written:
  5712   5832         **
  5713   5833         **   do {...} while( pRoot->iDocid<iDocid && rc==SQLITE_OK );
  5714   5834         */
  5715   5835         fts3EvalRestart(pCsr, pRoot, &rc);
  5716   5836         do {
  5717   5837           fts3EvalNextRow(pCsr, pRoot, &rc);
  5718         -        assert( pRoot->bEof==0 );
         5838  +        assert_fts3_nc( pRoot->bEof==0 );
         5839  +        if( pRoot->bEof ) rc = FTS_CORRUPT_VTAB;
  5719   5840         }while( pRoot->iDocid!=iDocid && rc==SQLITE_OK );
  5720   5841       }
  5721   5842     }
  5722   5843     return rc;
  5723   5844   }
  5724   5845   
  5725   5846   /*

Changes to ext/fts3/fts3Int.h.

    91     91   
    92     92   /*
    93     93   ** Maximum length of a varint encoded integer. The varint format is different
    94     94   ** from that used by SQLite, so the maximum length is 10, not 9.
    95     95   */
    96     96   #define FTS3_VARINT_MAX 10
    97     97   
           98  +#define FTS3_BUFFER_PADDING 8
           99  +
    98    100   /*
    99    101   ** FTS4 virtual tables may maintain multiple indexes - one index of all terms
   100    102   ** in the document set and zero or more prefix indexes. All indexes are stored
   101    103   ** as one or more b+-trees in the %_segments and %_segdir tables. 
   102    104   **
   103    105   ** It is possible to determine which index a b+-tree belongs to based on the
   104    106   ** value stored in the "%_segdir.level" column. Given this value L, the index
................................................................................
   123    125   
   124    126   /*
   125    127   ** Terminator values for position-lists and column-lists.
   126    128   */
   127    129   #define POS_COLUMN  (1)     /* Column-list terminator */
   128    130   #define POS_END     (0)     /* Position-list terminator */ 
   129    131   
          132  +/*
          133  +** The assert_fts3_nc() macro is similar to the assert() macro, except that it
          134  +** is used for assert() conditions that are true only if it can be 
          135  +** guranteed that the database is not corrupt.
          136  +*/
          137  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
          138  +extern int sqlite3_fts3_may_be_corrupt;
          139  +# define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
          140  +#else
          141  +# define assert_fts3_nc(x) assert(x)
          142  +#endif
          143  +
   130    144   /*
   131    145   ** This section provides definitions to allow the
   132    146   ** FTS3 extension to be compiled outside of the 
   133    147   ** amalgamation.
   134    148   */
   135    149   #ifndef SQLITE_AMALGAMATION
   136    150   /*
................................................................................
   177    191   ** within testcase() and assert() macros.
   178    192   */
   179    193   #if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
   180    194   # define TESTONLY(X)  X
   181    195   #else
   182    196   # define TESTONLY(X)
   183    197   #endif
          198  +
          199  +#define LARGEST_INT64  (0xffffffff|(((i64)0x7fffffff)<<32))
          200  +#define SMALLEST_INT64 (((i64)-1) - LARGEST_INT64)
          201  +
          202  +#define deliberate_fall_through
   184    203   
   185    204   #endif /* SQLITE_AMALGAMATION */
   186    205   
   187    206   #ifdef SQLITE_DEBUG
   188    207   int sqlite3Fts3Corrupt(void);
   189    208   # define FTS_CORRUPT_VTAB sqlite3Fts3Corrupt()
   190    209   #else
................................................................................
   221    240     char **azColumn;                /* column names.  malloced */
   222    241     u8 *abNotindexed;               /* True for 'notindexed' columns */
   223    242     sqlite3_tokenizer *pTokenizer;  /* tokenizer for inserts and queries */
   224    243     char *zContentTbl;              /* content=xxx option, or NULL */
   225    244     char *zLanguageid;              /* languageid=xxx option, or NULL */
   226    245     int nAutoincrmerge;             /* Value configured by 'automerge' */
   227    246     u32 nLeafAdd;                   /* Number of leaf blocks added this trans */
          247  +  int bLock;                      /* Used to prevent recursive content= tbls */
   228    248   
   229    249     /* Precompiled statements used by the implementation. Each of these 
   230    250     ** statements is run and reset within a single virtual table API call. 
   231    251     */
   232    252     sqlite3_stmt *aStmt[40];
   233    253     sqlite3_stmt *pSeekStmt;        /* Cache for fts3CursorSeekStmt() */
   234    254   
................................................................................
   279    299     ** values do not contribute to FTS functionality; they are used for
   280    300     ** verifying the operation of the SQLite core.
   281    301     */
   282    302     int inTransaction;     /* True after xBegin but before xCommit/xRollback */
   283    303     int mxSavepoint;       /* Largest valid xSavepoint integer */
   284    304   #endif
   285    305   
   286         -#ifdef SQLITE_TEST
          306  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
   287    307     /* True to disable the incremental doclist optimization. This is controled
   288    308     ** by special insert command 'test-no-incr-doclist'.  */
   289    309     int bNoIncrDoclist;
          310  +
          311  +  /* Number of segments in a level */
          312  +  int nMergeCount;
   290    313   #endif
   291    314   };
          315  +
          316  +/* Macro to find the number of segments to merge */
          317  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
          318  +# define MergeCount(P) ((P)->nMergeCount)
          319  +#else
          320  +# define MergeCount(P) FTS3_MERGE_COUNT
          321  +#endif
   292    322   
   293    323   /*
   294    324   ** When the core wants to read from the virtual table, it creates a
   295    325   ** virtual table cursor (an instance of the following structure) using
   296    326   ** the xOpen method. Cursors are destroyed using the xClose method.
   297    327   */
   298    328   struct Fts3Cursor {
................................................................................
   549    579     (*(u8*)(p)&0x80) ? sqlite3Fts3GetVarint32(p, piVal) : (*piVal=*(u8*)(p), 1) \
   550    580   )
   551    581   
   552    582   /* fts3.c */
   553    583   void sqlite3Fts3ErrMsg(char**,const char*,...);
   554    584   int sqlite3Fts3PutVarint(char *, sqlite3_int64);
   555    585   int sqlite3Fts3GetVarint(const char *, sqlite_int64 *);
          586  +int sqlite3Fts3GetVarintU(const char *, sqlite_uint64 *);
          587  +int sqlite3Fts3GetVarintBounded(const char*,const char*,sqlite3_int64*);
   556    588   int sqlite3Fts3GetVarint32(const char *, int *);
   557    589   int sqlite3Fts3VarintLen(sqlite3_uint64);
   558    590   void sqlite3Fts3Dequote(char *);
   559    591   void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*);
   560    592   int sqlite3Fts3EvalPhraseStats(Fts3Cursor *, Fts3Expr *, u32 *);
   561    593   int sqlite3Fts3FirstFilter(sqlite3_int64, char *, int, char *);
   562    594   void sqlite3Fts3CreateStatTable(int*, Fts3Table*);
   563    595   int sqlite3Fts3EvalTestDeferred(Fts3Cursor *pCsr, int *pRc);
          596  +int sqlite3Fts3ReadInt(const char *z, int *pnOut);
   564    597   
   565    598   /* fts3_tokenizer.c */
   566    599   const char *sqlite3Fts3NextToken(const char *, int *);
   567    600   int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *);
   568    601   int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *, 
   569    602       sqlite3_tokenizer **, char **
   570    603   );

Changes to ext/fts3/fts3_aux.c.

    62     62     sqlite3_vtab **ppVtab,          /* OUT: New sqlite3_vtab object */
    63     63     char **pzErr                    /* OUT: sqlite3_malloc'd error message */
    64     64   ){
    65     65     char const *zDb;                /* Name of database (e.g. "main") */
    66     66     char const *zFts3;              /* Name of fts3 table */
    67     67     int nDb;                        /* Result of strlen(zDb) */
    68     68     int nFts3;                      /* Result of strlen(zFts3) */
    69         -  int nByte;                      /* Bytes of space to allocate here */
           69  +  sqlite3_int64 nByte;            /* Bytes of space to allocate here */
    70     70     int rc;                         /* value returned by declare_vtab() */
    71     71     Fts3auxTable *p;                /* Virtual table object to return */
    72     72   
    73     73     UNUSED_PARAMETER(pUnused);
    74     74   
    75     75     /* The user should invoke this in one of two forms:
    76     76     **
................................................................................
    94     94     }
    95     95     nFts3 = (int)strlen(zFts3);
    96     96   
    97     97     rc = sqlite3_declare_vtab(db, FTS3_AUX_SCHEMA);
    98     98     if( rc!=SQLITE_OK ) return rc;
    99     99   
   100    100     nByte = sizeof(Fts3auxTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
   101         -  p = (Fts3auxTable *)sqlite3_malloc(nByte);
          101  +  p = (Fts3auxTable *)sqlite3_malloc64(nByte);
   102    102     if( !p ) return SQLITE_NOMEM;
   103    103     memset(p, 0, nByte);
   104    104   
   105    105     p->pFts3Tab = (Fts3Table *)&p[1];
   106    106     p->pFts3Tab->zDb = (char *)&p->pFts3Tab[1];
   107    107     p->pFts3Tab->zName = &p->pFts3Tab->zDb[nDb+1];
   108    108     p->pFts3Tab->db = db;
................................................................................
   244    244     sqlite3_free(pCsr);
   245    245     return SQLITE_OK;
   246    246   }
   247    247   
   248    248   static int fts3auxGrowStatArray(Fts3auxCursor *pCsr, int nSize){
   249    249     if( nSize>pCsr->nStat ){
   250    250       struct Fts3auxColstats *aNew;
   251         -    aNew = (struct Fts3auxColstats *)sqlite3_realloc(pCsr->aStat, 
          251  +    aNew = (struct Fts3auxColstats *)sqlite3_realloc64(pCsr->aStat, 
   252    252           sizeof(struct Fts3auxColstats) * nSize
   253    253       );
   254    254       if( aNew==0 ) return SQLITE_NOMEM;
   255    255       memset(&aNew[pCsr->nStat], 0, 
   256    256           sizeof(struct Fts3auxColstats) * (nSize - pCsr->nStat)
   257    257       );
   258    258       pCsr->aStat = aNew;
................................................................................
   412    412     if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
   413    413   
   414    414     if( iEq>=0 || iGe>=0 ){
   415    415       const unsigned char *zStr = sqlite3_value_text(apVal[0]);
   416    416       assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
   417    417       if( zStr ){
   418    418         pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
   419         -      pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]);
   420    419         if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
          420  +      pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
   421    421       }
   422    422     }
   423    423   
   424    424     if( iLe>=0 ){
   425    425       pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
   426         -    pCsr->nStop = sqlite3_value_bytes(apVal[iLe]);
   427    426       if( pCsr->zStop==0 ) return SQLITE_NOMEM;
          427  +    pCsr->nStop = (int)strlen(pCsr->zStop);
   428    428     }
   429    429     
   430    430     if( iLangid>=0 ){
   431    431       iLangVal = sqlite3_value_int(apVal[iLangid]);
   432    432   
   433    433       /* If the user specified a negative value for the languageid, use zero
   434    434       ** instead. This works, as the "languageid=?" constraint will also

Changes to ext/fts3/fts3_expr.c.

   118    118   }
   119    119   
   120    120   /*
   121    121   ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
   122    122   ** zero the memory before returning a pointer to it. If unsuccessful, 
   123    123   ** return NULL.
   124    124   */
   125         -static void *fts3MallocZero(int nByte){
   126         -  void *pRet = sqlite3_malloc(nByte);
          125  +static void *fts3MallocZero(sqlite3_int64 nByte){
          126  +  void *pRet = sqlite3_malloc64(nByte);
   127    127     if( pRet ) memset(pRet, 0, nByte);
   128    128     return pRet;
   129    129   }
   130    130   
   131    131   int sqlite3Fts3OpenTokenizer(
   132    132     sqlite3_tokenizer *pTokenizer,
   133    133     int iLangid,
................................................................................
   194    194     }
   195    195   
   196    196     *pnConsumed = i;
   197    197     rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
   198    198     if( rc==SQLITE_OK ){
   199    199       const char *zToken;
   200    200       int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
   201         -    int nByte;                               /* total space to allocate */
          201  +    sqlite3_int64 nByte;                    /* total space to allocate */
   202    202   
   203    203       rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
   204    204       if( rc==SQLITE_OK ){
   205    205         nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
   206    206         pRet = (Fts3Expr *)fts3MallocZero(nByte);
   207    207         if( !pRet ){
   208    208           rc = SQLITE_NOMEM;
................................................................................
   248    248   }
   249    249   
   250    250   
   251    251   /*
   252    252   ** Enlarge a memory allocation.  If an out-of-memory allocation occurs,
   253    253   ** then free the old allocation.
   254    254   */
   255         -static void *fts3ReallocOrFree(void *pOrig, int nNew){
   256         -  void *pRet = sqlite3_realloc(pOrig, nNew);
          255  +static void *fts3ReallocOrFree(void *pOrig, sqlite3_int64 nNew){
          256  +  void *pRet = sqlite3_realloc64(pOrig, nNew);
   257    257     if( !pRet ){
   258    258       sqlite3_free(pOrig);
   259    259     }
   260    260     return pRet;
   261    261   }
   262    262   
   263    263   /*
................................................................................
   442    442         int nKey = pKey->n;
   443    443         char cNext;
   444    444   
   445    445         /* If this is a "NEAR" keyword, check for an explicit nearness. */
   446    446         if( pKey->eType==FTSQUERY_NEAR ){
   447    447           assert( nKey==4 );
   448    448           if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){
   449         -          nNear = 0;
   450         -          for(nKey=5; zInput[nKey]>='0' && zInput[nKey]<='9'; nKey++){
   451         -            nNear = nNear * 10 + (zInput[nKey] - '0');
   452         -          }
          449  +          nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear);
   453    450           }
   454    451         }
   455    452   
   456    453         /* At this point this is probably a keyword. But for that to be true,
   457    454         ** the next byte must contain either whitespace, an open or close
   458    455         ** parenthesis, a quote character, or EOF. 
   459    456         */
................................................................................
   493    490     }
   494    491   
   495    492     if( sqlite3_fts3_enable_parentheses ){
   496    493       if( *zInput=='(' ){
   497    494         int nConsumed = 0;
   498    495         pParse->nNest++;
   499    496         rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed);
   500         -      if( rc==SQLITE_OK && !*ppExpr ){ rc = SQLITE_DONE; }
   501    497         *pnConsumed = (int)(zInput - z) + 1 + nConsumed;
   502    498         return rc;
   503    499       }else if( *zInput==')' ){
   504    500         pParse->nNest--;
   505    501         *pnConsumed = (int)((zInput - z) + 1);
   506    502         *ppExpr = 0;
   507    503         return SQLITE_DONE;
................................................................................
   792    788     if( nMaxDepth==0 ){
   793    789       rc = SQLITE_ERROR;
   794    790     }
   795    791   
   796    792     if( rc==SQLITE_OK ){
   797    793       if( (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
   798    794         Fts3Expr **apLeaf;
   799         -      apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
          795  +      apLeaf = (Fts3Expr **)sqlite3_malloc64(sizeof(Fts3Expr *) * nMaxDepth);
   800    796         if( 0==apLeaf ){
   801    797           rc = SQLITE_NOMEM;
   802    798         }else{
   803    799           memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
   804    800         }
   805    801   
   806    802         if( rc==SQLITE_OK ){
................................................................................
  1212   1208       sqlite3_free(zErr);
  1213   1209       return;
  1214   1210     }
  1215   1211   
  1216   1212     zExpr = (const char *)sqlite3_value_text(argv[1]);
  1217   1213     nExpr = sqlite3_value_bytes(argv[1]);
  1218   1214     nCol = argc-2;
  1219         -  azCol = (char **)sqlite3_malloc(nCol*sizeof(char *));
         1215  +  azCol = (char **)sqlite3_malloc64(nCol*sizeof(char *));
  1220   1216     if( !azCol ){
  1221   1217       sqlite3_result_error_nomem(context);
  1222   1218       goto exprtest_out;
  1223   1219     }
  1224   1220     for(ii=0; ii<nCol; ii++){
  1225   1221       azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
  1226   1222     }

Changes to ext/fts3/fts3_hash.c.

    31     31   #include <string.h>
    32     32   
    33     33   #include "fts3_hash.h"
    34     34   
    35     35   /*
    36     36   ** Malloc and Free functions
    37     37   */
    38         -static void *fts3HashMalloc(int n){
    39         -  void *p = sqlite3_malloc(n);
           38  +static void *fts3HashMalloc(sqlite3_int64 n){
           39  +  void *p = sqlite3_malloc64(n);
    40     40     if( p ){
    41     41       memset(p, 0, n);
    42     42     }
    43     43     return p;
    44     44   }
    45     45   static void fts3HashFree(void *p){
    46     46     sqlite3_free(p);

Changes to ext/fts3/fts3_icu.c.

    56     56   ){
    57     57     IcuTokenizer *p;
    58     58     int n = 0;
    59     59   
    60     60     if( argc>0 ){
    61     61       n = strlen(argv[0])+1;
    62     62     }
    63         -  p = (IcuTokenizer *)sqlite3_malloc(sizeof(IcuTokenizer)+n);
           63  +  p = (IcuTokenizer *)sqlite3_malloc64(sizeof(IcuTokenizer)+n);
    64     64     if( !p ){
    65     65       return SQLITE_NOMEM;
    66     66     }
    67     67     memset(p, 0, sizeof(IcuTokenizer));
    68     68   
    69     69     if( n ){
    70     70       p->zLocale = (char *)&p[1];
................................................................................
   113    113     if( zInput==0 ){
   114    114       nInput = 0;
   115    115       zInput = "";
   116    116     }else if( nInput<0 ){
   117    117       nInput = strlen(zInput);
   118    118     }
   119    119     nChar = nInput+1;
   120         -  pCsr = (IcuCursor *)sqlite3_malloc(
          120  +  pCsr = (IcuCursor *)sqlite3_malloc64(
   121    121         sizeof(IcuCursor) +                /* IcuCursor */
   122    122         ((nChar+3)&~3) * sizeof(UChar) +   /* IcuCursor.aChar[] */
   123    123         (nChar+1) * sizeof(int)            /* IcuCursor.aOffset[] */
   124    124     );
   125    125     if( !pCsr ){
   126    126       return SQLITE_NOMEM;
   127    127     }

Changes to ext/fts3/fts3_snippet.c.

   124    124   /*************************************************************************
   125    125   ** Start of MatchinfoBuffer code.
   126    126   */
   127    127   
   128    128   /*
   129    129   ** Allocate a two-slot MatchinfoBuffer object.
   130    130   */
   131         -static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
          131  +static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
   132    132     MatchinfoBuffer *pRet;
   133         -  int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
   134         -  int nStr = (int)strlen(zMatchinfo);
          133  +  sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
          134  +                           + sizeof(MatchinfoBuffer);
          135  +  sqlite3_int64 nStr = strlen(zMatchinfo);
   135    136   
   136         -  pRet = sqlite3_malloc(nByte + nStr+1);
          137  +  pRet = sqlite3_malloc64(nByte + nStr+1);
   137    138     if( pRet ){
   138    139       memset(pRet, 0, nByte);
   139    140       pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
   140         -    pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1);
   141         -    pRet->nElem = nElem;
          141  +    pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
          142  +                                      + sizeof(u32)*((int)nElem+1);
          143  +    pRet->nElem = (int)nElem;
   142    144       pRet->zMatchinfo = ((char*)pRet) + nByte;
   143    145       memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
   144    146       pRet->aRef[0] = 1;
   145    147     }
   146    148   
   147    149     return pRet;
   148    150   }
................................................................................
   174    176       xRet = fts3MIBufferFree;
   175    177     }
   176    178     else if( p->aRef[2]==0 ){
   177    179       p->aRef[2] = 1;
   178    180       aOut = &p->aMatchinfo[p->nElem+2];
   179    181       xRet = fts3MIBufferFree;
   180    182     }else{
   181         -    aOut = (u32*)sqlite3_malloc(p->nElem * sizeof(u32));
          183  +    aOut = (u32*)sqlite3_malloc64(p->nElem * sizeof(u32));
   182    184       if( aOut ){
   183    185         xRet = sqlite3_free;
   184    186         if( p->bGlobal ) memcpy(aOut, &p->aMatchinfo[1], p->nElem*sizeof(u32));
   185    187       }
   186    188     }
   187    189   
   188    190     *paOut = aOut;
................................................................................
   425    427   
   426    428     for(i=0; i<pIter->nPhrase; i++){
   427    429       SnippetPhrase *pPhrase = &pIter->aPhrase[i];
   428    430       if( pPhrase->pTail ){
   429    431         char *pCsr = pPhrase->pTail;
   430    432         int iCsr = pPhrase->iTail;
   431    433   
   432         -      while( iCsr<(iStart+pIter->nSnippet) ){
          434  +      while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
   433    435           int j;
   434         -        u64 mPhrase = (u64)1 << i;
          436  +        u64 mPhrase = (u64)1 << (i%64);
   435    437           u64 mPos = (u64)1 << (iCsr - iStart);
   436         -        assert( iCsr>=iStart );
          438  +        assert( iCsr>=iStart && (iCsr - iStart)<=64 );
          439  +        assert( i>=0 );
   437    440           if( (mCover|mCovered)&mPhrase ){
   438    441             iScore++;
   439    442           }else{
   440    443             iScore += 1000;
   441    444           }
   442    445           mCover |= mPhrase;
   443    446   
................................................................................
   471    474     pPhrase->nToken = pExpr->pPhrase->nToken;
   472    475     rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr);
   473    476     assert( rc==SQLITE_OK || pCsr==0 );
   474    477     if( pCsr ){
   475    478       int iFirst = 0;
   476    479       pPhrase->pList = pCsr;
   477    480       fts3GetDeltaPosition(&pCsr, &iFirst);
   478         -    assert( iFirst>=0 );
   479         -    pPhrase->pHead = pCsr;
   480         -    pPhrase->pTail = pCsr;
   481         -    pPhrase->iHead = iFirst;
   482         -    pPhrase->iTail = iFirst;
          481  +    if( iFirst<0 ){
          482  +      rc = FTS_CORRUPT_VTAB;
          483  +    }else{
          484  +      pPhrase->pHead = pCsr;
          485  +      pPhrase->pTail = pCsr;
          486  +      pPhrase->iHead = iFirst;
          487  +      pPhrase->iTail = iFirst;
          488  +    }
   483    489     }else{
   484    490       assert( rc!=SQLITE_OK || (
   485    491          pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0 
   486    492       ));
   487    493     }
   488    494   
   489    495     return rc;
................................................................................
   512    518     u64 *pmSeen,                    /* IN/OUT: Mask of phrases seen */
   513    519     SnippetFragment *pFragment,     /* OUT: Best snippet found */
   514    520     int *piScore                    /* OUT: Score of snippet pFragment */
   515    521   ){
   516    522     int rc;                         /* Return Code */
   517    523     int nList;                      /* Number of phrases in expression */
   518    524     SnippetIter sIter;              /* Iterates through snippet candidates */
   519         -  int nByte;                      /* Number of bytes of space to allocate */
          525  +  sqlite3_int64 nByte;            /* Number of bytes of space to allocate */
   520    526     int iBestScore = -1;            /* Best snippet score found so far */
   521    527     int i;                          /* Loop counter */
   522    528   
   523    529     memset(&sIter, 0, sizeof(sIter));
   524    530   
   525    531     /* Iterate through the phrases in the expression to count them. The same
   526    532     ** callback makes sure the doclists are loaded for each phrase.
................................................................................
   530    536       return rc;
   531    537     }
   532    538   
   533    539     /* Now that it is known how many phrases there are, allocate and zero
   534    540     ** the required space using malloc().
   535    541     */
   536    542     nByte = sizeof(SnippetPhrase) * nList;
   537         -  sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc(nByte);
          543  +  sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte);
   538    544     if( !sIter.aPhrase ){
   539    545       return SQLITE_NOMEM;
   540    546     }
   541    547     memset(sIter.aPhrase, 0, nByte);
   542    548   
   543    549     /* Initialize the contents of the SnippetIter object. Then iterate through
   544    550     ** the set of phrases in the expression to populate the aPhrase[] array.
................................................................................
   550    556     sIter.iCurrent = -1;
   551    557     rc = fts3ExprIterate(pCsr->pExpr, fts3SnippetFindPositions, (void*)&sIter);
   552    558     if( rc==SQLITE_OK ){
   553    559   
   554    560       /* Set the *pmSeen output variable. */
   555    561       for(i=0; i<nList; i++){
   556    562         if( sIter.aPhrase[i].pHead ){
   557         -        *pmSeen |= (u64)1 << i;
          563  +        *pmSeen |= (u64)1 << (i%64);
   558    564         }
   559    565       }
   560    566   
   561    567       /* Loop through all candidate snippets. Store the best snippet in 
   562    568        ** *pFragment. Store its associated 'score' in iBestScore.
   563    569        */
   564    570       pFragment->iCol = iCol;
................................................................................
   600    606     }
   601    607   
   602    608     /* If there is insufficient space allocated at StrBuffer.z, use realloc()
   603    609     ** to grow the buffer until so that it is big enough to accomadate the
   604    610     ** appended data.
   605    611     */
   606    612     if( pStr->n+nAppend+1>=pStr->nAlloc ){
   607         -    int nAlloc = pStr->nAlloc+nAppend+100;
   608         -    char *zNew = sqlite3_realloc(pStr->z, nAlloc);
          613  +    sqlite3_int64 nAlloc = pStr->nAlloc+(sqlite3_int64)nAppend+100;
          614  +    char *zNew = sqlite3_realloc64(pStr->z, nAlloc);
   609    615       if( !zNew ){
   610    616         return SQLITE_NOMEM;
   611    617       }
   612    618       pStr->z = zNew;
   613    619       pStr->nAlloc = nAlloc;
   614    620     }
   615    621     assert( pStr->z!=0 && (pStr->nAlloc >= pStr->n+nAppend+1) );
................................................................................
   656    662     if( hlmask ){
   657    663       int nLeft;                    /* Tokens to the left of first highlight */
   658    664       int nRight;                   /* Tokens to the right of last highlight */
   659    665       int nDesired;                 /* Ideal number of tokens to shift forward */
   660    666   
   661    667       for(nLeft=0; !(hlmask & ((u64)1 << nLeft)); nLeft++);
   662    668       for(nRight=0; !(hlmask & ((u64)1 << (nSnippet-1-nRight))); nRight++);
          669  +    assert( (nSnippet-1-nRight)<=63 && (nSnippet-1-nRight)>=0 );
   663    670       nDesired = (nLeft-nRight)/2;
   664    671   
   665    672       /* Ideally, the start of the snippet should be pushed forward in the
   666    673       ** document nDesired tokens. This block checks if there are actually
   667    674       ** nDesired tokens to the right of the snippet. If so, *piPos and
   668    675       ** *pHlMask are updated to shift the snippet nDesired tokens to the
   669    676       ** right. Otherwise, the snippet is shifted by the number of tokens
................................................................................
   848    855     *ppCollist = pEnd;
   849    856     return nEntry;
   850    857   }
   851    858   
   852    859   /*
   853    860   ** This function gathers 'y' or 'b' data for a single phrase.
   854    861   */
   855         -static void fts3ExprLHits(
          862  +static int fts3ExprLHits(
   856    863     Fts3Expr *pExpr,                /* Phrase expression node */
   857    864     MatchInfo *p                    /* Matchinfo context */
   858    865   ){
   859    866     Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
   860    867     int iStart;
   861    868     Fts3Phrase *pPhrase = pExpr->pPhrase;
   862    869     char *pIter = pPhrase->doclist.pList;
................................................................................
   865    872     assert( p->flag==FTS3_MATCHINFO_LHITS_BM || p->flag==FTS3_MATCHINFO_LHITS );
   866    873     if( p->flag==FTS3_MATCHINFO_LHITS ){
   867    874       iStart = pExpr->iPhrase * p->nCol;
   868    875     }else{
   869    876       iStart = pExpr->iPhrase * ((p->nCol + 31) / 32);
   870    877     }
   871    878   
   872         -  while( 1 ){
          879  +  if( pIter ) while( 1 ){
   873    880       int nHit = fts3ColumnlistCount(&pIter);
   874    881       if( (pPhrase->iColumn>=pTab->nColumn || pPhrase->iColumn==iCol) ){
   875    882         if( p->flag==FTS3_MATCHINFO_LHITS ){
   876    883           p->aMatchinfo[iStart + iCol] = (u32)nHit;
   877    884         }else if( nHit ){
   878    885           p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
   879    886         }
   880    887       }
   881    888       assert( *pIter==0x00 || *pIter==0x01 );
   882    889       if( *pIter!=0x01 ) break;
   883    890       pIter++;
   884    891       pIter += fts3GetVarint32(pIter, &iCol);
          892  +    if( iCol>=p->nCol ) return FTS_CORRUPT_VTAB;
   885    893     }
          894  +  return SQLITE_OK;
   886    895   }
   887    896   
   888    897   /*
   889    898   ** Gather the results for matchinfo directives 'y' and 'b'.
   890    899   */
   891         -static void fts3ExprLHitGather(
          900  +static int fts3ExprLHitGather(
   892    901     Fts3Expr *pExpr,
   893    902     MatchInfo *p
   894    903   ){
          904  +  int rc = SQLITE_OK;
   895    905     assert( (pExpr->pLeft==0)==(pExpr->pRight==0) );
   896    906     if( pExpr->bEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
   897    907       if( pExpr->pLeft ){
   898         -      fts3ExprLHitGather(pExpr->pLeft, p);
   899         -      fts3ExprLHitGather(pExpr->pRight, p);
          908  +      rc = fts3ExprLHitGather(pExpr->pLeft, p);
          909  +      if( rc==SQLITE_OK ) rc = fts3ExprLHitGather(pExpr->pRight, p);
   900    910       }else{
   901         -      fts3ExprLHits(pExpr, p);
          911  +      rc = fts3ExprLHits(pExpr, p);
   902    912       }
   903    913     }
          914  +  return rc;
   904    915   }
   905    916   
   906    917   /*
   907    918   ** fts3ExprIterate() callback used to collect the "global" matchinfo stats
   908    919   ** for a single query. 
   909    920   **
   910    921   ** fts3ExprIterate() callback to load the 'global' elements of a
................................................................................
   986    997     ){
   987    998       return SQLITE_OK;
   988    999     }
   989   1000     sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
   990   1001     return SQLITE_ERROR;
   991   1002   }
   992   1003   
   993         -static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
   994         -  int nVal;                       /* Number of integers output by cArg */
         1004  +static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
         1005  +  size_t nVal;                      /* Number of integers output by cArg */
   995   1006   
   996   1007     switch( cArg ){
   997   1008       case FTS3_MATCHINFO_NDOC:
   998   1009       case FTS3_MATCHINFO_NPHRASE: 
   999   1010       case FTS3_MATCHINFO_NCOL: 
  1000   1011         nVal = 1;
  1001   1012         break;
................................................................................
  1023   1034     return nVal;
  1024   1035   }
  1025   1036   
  1026   1037   static int fts3MatchinfoSelectDoctotal(
  1027   1038     Fts3Table *pTab,
  1028   1039     sqlite3_stmt **ppStmt,
  1029   1040     sqlite3_int64 *pnDoc,
  1030         -  const char **paLen
         1041  +  const char **paLen,
         1042  +  const char **ppEnd
  1031   1043   ){
  1032   1044     sqlite3_stmt *pStmt;
  1033   1045     const char *a;
         1046  +  const char *pEnd;
  1034   1047     sqlite3_int64 nDoc;
         1048  +  int n;
         1049  +
  1035   1050   
  1036   1051     if( !*ppStmt ){
  1037   1052       int rc = sqlite3Fts3SelectDoctotal(pTab, ppStmt);
  1038   1053       if( rc!=SQLITE_OK ) return rc;
  1039   1054     }
  1040   1055     pStmt = *ppStmt;
  1041   1056     assert( sqlite3_data_count(pStmt)==1 );
  1042   1057   
         1058  +  n = sqlite3_column_bytes(pStmt, 0);
  1043   1059     a = sqlite3_column_blob(pStmt, 0);
  1044         -  a += sqlite3Fts3GetVarint(a, &nDoc);
  1045         -  if( nDoc==0 ) return FTS_CORRUPT_VTAB;
  1046         -  *pnDoc = (u32)nDoc;
         1060  +  if( a==0 ){
         1061  +    return FTS_CORRUPT_VTAB;
         1062  +  }
         1063  +  pEnd = a + n;
         1064  +  a += sqlite3Fts3GetVarintBounded(a, pEnd, &nDoc);
         1065  +  if( nDoc<=0 || a>pEnd ){
         1066  +    return FTS_CORRUPT_VTAB;
         1067  +  }
         1068  +  *pnDoc = nDoc;
  1047   1069   
  1048   1070     if( paLen ) *paLen = a;
         1071  +  if( ppEnd ) *ppEnd = pEnd;
  1049   1072     return SQLITE_OK;
  1050   1073   }
  1051   1074   
  1052   1075   /*
  1053   1076   ** An instance of the following structure is used to store state while 
  1054   1077   ** iterating through a multi-column position-list corresponding to the
  1055   1078   ** hits for a single phrase on a single row in order to calculate the
................................................................................
  1113   1136   ** undefined.
  1114   1137   */
  1115   1138   static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
  1116   1139     LcsIterator *aIter;
  1117   1140     int i;
  1118   1141     int iCol;
  1119   1142     int nToken = 0;
         1143  +  int rc = SQLITE_OK;
  1120   1144   
  1121   1145     /* Allocate and populate the array of LcsIterator objects. The array
  1122   1146     ** contains one element for each matchable phrase in the query.
  1123   1147     **/
  1124         -  aIter = sqlite3_malloc(sizeof(LcsIterator) * pCsr->nPhrase);
         1148  +  aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase);
  1125   1149     if( !aIter ) return SQLITE_NOMEM;
  1126   1150     memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase);
  1127   1151     (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
  1128   1152   
  1129   1153     for(i=0; i<pInfo->nPhrase; i++){
  1130   1154       LcsIterator *pIter = &aIter[i];
  1131   1155       nToken -= pIter->pExpr->pPhrase->nToken;
................................................................................
  1133   1157     }
  1134   1158   
  1135   1159     for(iCol=0; iCol<pInfo->nCol; iCol++){
  1136   1160       int nLcs = 0;                 /* LCS value for this column */
  1137   1161       int nLive = 0;                /* Number of iterators in aIter not at EOF */
  1138   1162   
  1139   1163       for(i=0; i<pInfo->nPhrase; i++){
  1140         -      int rc;
  1141   1164         LcsIterator *pIt = &aIter[i];
  1142   1165         rc = sqlite3Fts3EvalPhrasePoslist(pCsr, pIt->pExpr, iCol, &pIt->pRead);
  1143         -      if( rc!=SQLITE_OK ) return rc;
         1166  +      if( rc!=SQLITE_OK ) goto matchinfo_lcs_out;
  1144   1167         if( pIt->pRead ){
  1145   1168           pIt->iPos = pIt->iPosOffset;
  1146         -        fts3LcsIteratorAdvance(&aIter[i]);
         1169  +        fts3LcsIteratorAdvance(pIt);
         1170  +        if( pIt->pRead==0 ){
         1171  +          rc = FTS_CORRUPT_VTAB;
         1172  +          goto matchinfo_lcs_out;
         1173  +        }
  1147   1174           nLive++;
  1148   1175         }
  1149   1176       }
  1150   1177   
  1151   1178       while( nLive>0 ){
  1152   1179         LcsIterator *pAdv = 0;      /* The iterator to advance by one position */
  1153   1180         int nThisLcs = 0;           /* LCS for the current iterator positions */
................................................................................
  1171   1198         }
  1172   1199         if( fts3LcsIteratorAdvance(pAdv) ) nLive--;
  1173   1200       }
  1174   1201   
  1175   1202       pInfo->aMatchinfo[iCol] = nLcs;
  1176   1203     }
  1177   1204   
         1205  + matchinfo_lcs_out:
  1178   1206     sqlite3_free(aIter);
  1179         -  return SQLITE_OK;
         1207  +  return rc;
  1180   1208   }
  1181   1209   
  1182   1210   /*
  1183   1211   ** Populate the buffer pInfo->aMatchinfo[] with an array of integers to
  1184   1212   ** be returned by the matchinfo() function. Argument zArg contains the 
  1185   1213   ** format string passed as the second argument to matchinfo (or the
  1186   1214   ** default value "pcx" if no second argument was specified). The format
................................................................................
  1217   1245         case FTS3_MATCHINFO_NCOL:
  1218   1246           if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nCol;
  1219   1247           break;
  1220   1248           
  1221   1249         case FTS3_MATCHINFO_NDOC:
  1222   1250           if( bGlobal ){
  1223   1251             sqlite3_int64 nDoc = 0;
  1224         -          rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, 0);
         1252  +          rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, 0, 0);
  1225   1253             pInfo->aMatchinfo[0] = (u32)nDoc;
  1226   1254           }
  1227   1255           break;
  1228   1256   
  1229   1257         case FTS3_MATCHINFO_AVGLENGTH: 
  1230   1258           if( bGlobal ){
  1231   1259             sqlite3_int64 nDoc;     /* Number of rows in table */
  1232   1260             const char *a;          /* Aggregate column length array */
         1261  +          const char *pEnd;       /* First byte past end of length array */
  1233   1262   
  1234         -          rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, &a);
         1263  +          rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, &a, &pEnd);
  1235   1264             if( rc==SQLITE_OK ){
  1236   1265               int iCol;
  1237   1266               for(iCol=0; iCol<pInfo->nCol; iCol++){
  1238   1267                 u32 iVal;
  1239   1268                 sqlite3_int64 nToken;
  1240   1269                 a += sqlite3Fts3GetVarint(a, &nToken);
         1270  +              if( a>pEnd ){
         1271  +                rc = SQLITE_CORRUPT_VTAB;
         1272  +                break;
         1273  +              }
  1241   1274                 iVal = (u32)(((u32)(nToken&0xffffffff)+nDoc/2)/nDoc);
  1242   1275                 pInfo->aMatchinfo[iCol] = iVal;
  1243   1276               }
  1244   1277             }
  1245   1278           }
  1246   1279           break;
  1247   1280   
  1248   1281         case FTS3_MATCHINFO_LENGTH: {
  1249   1282           sqlite3_stmt *pSelectDocsize = 0;
  1250   1283           rc = sqlite3Fts3SelectDocsize(pTab, pCsr->iPrevId, &pSelectDocsize);
  1251   1284           if( rc==SQLITE_OK ){
  1252   1285             int iCol;
  1253   1286             const char *a = sqlite3_column_blob(pSelectDocsize, 0);
         1287  +          const char *pEnd = a + sqlite3_column_bytes(pSelectDocsize, 0);
  1254   1288             for(iCol=0; iCol<pInfo->nCol; iCol++){
  1255   1289               sqlite3_int64 nToken;
  1256         -            a += sqlite3Fts3GetVarint(a, &nToken);
         1290  +            a += sqlite3Fts3GetVarintBounded(a, pEnd, &nToken);
         1291  +            if( a>pEnd ){
         1292  +              rc = SQLITE_CORRUPT_VTAB;
         1293  +              break;
         1294  +            }
  1257   1295               pInfo->aMatchinfo[iCol] = (u32)nToken;
  1258   1296             }
  1259   1297           }
  1260   1298           sqlite3_reset(pSelectDocsize);
  1261   1299           break;
  1262   1300         }
  1263   1301   
................................................................................
  1266   1304           if( rc==SQLITE_OK ){
  1267   1305             rc = fts3MatchinfoLcs(pCsr, pInfo);
  1268   1306           }
  1269   1307           break;
  1270   1308   
  1271   1309         case FTS3_MATCHINFO_LHITS_BM:
  1272   1310         case FTS3_MATCHINFO_LHITS: {
  1273         -        int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
         1311  +        size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
  1274   1312           memset(pInfo->aMatchinfo, 0, nZero);
  1275         -        fts3ExprLHitGather(pCsr->pExpr, pInfo);
         1313  +        rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
  1276   1314           break;
  1277   1315         }
  1278   1316   
  1279   1317         default: {
  1280   1318           Fts3Expr *pExpr;
  1281   1319           assert( zArg[i]==FTS3_MATCHINFO_HITS );
  1282   1320           pExpr = pCsr->pExpr;
  1283   1321           rc = fts3ExprLoadDoclists(pCsr, 0, 0);
  1284   1322           if( rc!=SQLITE_OK ) break;
  1285   1323           if( bGlobal ){
  1286   1324             if( pCsr->pDeferred ){
  1287         -            rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc, 0);
         1325  +            rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &pInfo->nDoc,0,0);
  1288   1326               if( rc!=SQLITE_OK ) break;
  1289   1327             }
  1290   1328             rc = fts3ExprIterate(pExpr, fts3ExprGlobalHitsCb,(void*)pInfo);
  1291   1329             sqlite3Fts3EvalTestDeferred(pCsr, &rc);
  1292   1330             if( rc!=SQLITE_OK ) break;
  1293   1331           }
  1294   1332           (void)fts3ExprIterate(pExpr, fts3ExprLocalHitsCb,(void*)pInfo);
................................................................................
  1335   1373   
  1336   1374     /* If Fts3Cursor.pMIBuffer is NULL, then this is the first time the
  1337   1375     ** matchinfo function has been called for this query. In this case 
  1338   1376     ** allocate the array used to accumulate the matchinfo data and
  1339   1377     ** initialize those elements that are constant for every row.
  1340   1378     */
  1341   1379     if( pCsr->pMIBuffer==0 ){
  1342         -    int nMatchinfo = 0;           /* Number of u32 elements in match-info */
         1380  +    size_t nMatchinfo = 0;        /* Number of u32 elements in match-info */
  1343   1381       int i;                        /* Used to iterate through zArg */
  1344   1382   
  1345   1383       /* Determine the number of phrases in the query */
  1346   1384       pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
  1347   1385       sInfo.nPhrase = pCsr->nPhrase;
  1348   1386   
  1349   1387       /* Determine the number of integers in the buffer returned by this call. */
................................................................................
  1419   1457     SnippetFragment aSnippet[4];    /* Maximum of 4 fragments per snippet */
  1420   1458     int nFToken = -1;               /* Number of tokens in each fragment */
  1421   1459   
  1422   1460     if( !pCsr->pExpr ){
  1423   1461       sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
  1424   1462       return;
  1425   1463     }
         1464  +
         1465  +  /* Limit the snippet length to 64 tokens. */
         1466  +  if( nToken<-64 ) nToken = -64;
         1467  +  if( nToken>+64 ) nToken = +64;
  1426   1468   
  1427   1469     for(nSnippet=1; 1; nSnippet++){
  1428   1470   
  1429   1471       int iSnip;                    /* Loop counter 0..nSnippet-1 */
  1430   1472       u64 mCovered = 0;             /* Bitmask of phrases covered by snippet */
  1431   1473       u64 mSeen = 0;                /* Bitmask of phrases seen by BestSnippet() */
  1432   1474   
................................................................................
  1521   1563     int rc;
  1522   1564   
  1523   1565     UNUSED_PARAMETER(iPhrase);
  1524   1566     rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
  1525   1567     nTerm = pExpr->pPhrase->nToken;
  1526   1568     if( pList ){
  1527   1569       fts3GetDeltaPosition(&pList, &iPos);
  1528         -    assert( iPos>=0 );
         1570  +    assert_fts3_nc( iPos>=0 );
  1529   1571     }
  1530   1572   
  1531   1573     for(iTerm=0; iTerm<nTerm; iTerm++){
  1532   1574       TermOffset *pT = &p->aTerm[p->iTerm++];
  1533   1575       pT->iOff = nTerm-iTerm-1;
  1534   1576       pT->pList = pList;
  1535   1577       pT->iPos = iPos;
................................................................................
  1562   1604     assert( pCsr->isRequireSeek==0 );
  1563   1605   
  1564   1606     /* Count the number of terms in the query */
  1565   1607     rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
  1566   1608     if( rc!=SQLITE_OK ) goto offsets_out;
  1567   1609   
  1568   1610     /* Allocate the array of TermOffset iterators. */
  1569         -  sCtx.aTerm = (TermOffset *)sqlite3_malloc(sizeof(TermOffset)*nToken);
         1611  +  sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken);
  1570   1612     if( 0==sCtx.aTerm ){
  1571   1613       rc = SQLITE_NOMEM;
  1572   1614       goto offsets_out;
  1573   1615     }
  1574   1616     sCtx.iDocid = pCsr->iPrevId;
  1575   1617     sCtx.pCsr = pCsr;
  1576   1618   
................................................................................
  1631   1673           }
  1632   1674         }
  1633   1675   
  1634   1676         if( !pTerm ){
  1635   1677           /* All offsets for this column have been gathered. */
  1636   1678           rc = SQLITE_DONE;
  1637   1679         }else{
  1638         -        assert( iCurrent<=iMinPos );
         1680  +        assert_fts3_nc( iCurrent<=iMinPos );
  1639   1681           if( 0==(0xFE&*pTerm->pList) ){
  1640   1682             pTerm->pList = 0;
  1641   1683           }else{
  1642   1684             fts3GetDeltaPosition(&pTerm->pList, &pTerm->iPos);
  1643   1685           }
  1644   1686           while( rc==SQLITE_OK && iCurrent<iMinPos ){
  1645   1687             rc = pMod->xNext(pC, &ZDUMMY, &NDUMMY, &iStart, &iEnd, &iCurrent);

Changes to ext/fts3/fts3_term.c.

    64     64     sqlite3_vtab **ppVtab,          /* OUT: New sqlite3_vtab object */
    65     65     char **pzErr                    /* OUT: sqlite3_malloc'd error message */
    66     66   ){
    67     67     char const *zDb;                /* Name of database (e.g. "main") */
    68     68     char const *zFts3;              /* Name of fts3 table */
    69     69     int nDb;                        /* Result of strlen(zDb) */
    70     70     int nFts3;                      /* Result of strlen(zFts3) */
    71         -  int nByte;                      /* Bytes of space to allocate here */
           71  +  sqlite3_int64 nByte;            /* Bytes of space to allocate here */
    72     72     int rc;                         /* value returned by declare_vtab() */
    73         -  Fts3termTable *p;                /* Virtual table object to return */
           73  +  Fts3termTable *p;               /* Virtual table object to return */
    74     74     int iIndex = 0;
    75     75   
    76     76     UNUSED_PARAMETER(pCtx);
    77     77     if( argc==5 ){
    78     78       iIndex = atoi(argv[4]);
    79     79       argc--;
    80     80     }
................................................................................
    92     92     zFts3 = argv[3];
    93     93     nFts3 = (int)strlen(zFts3);
    94     94   
    95     95     rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA);
    96     96     if( rc!=SQLITE_OK ) return rc;
    97     97   
    98     98     nByte = sizeof(Fts3termTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
    99         -  p = (Fts3termTable *)sqlite3_malloc(nByte);
           99  +  p = (Fts3termTable *)sqlite3_malloc64(nByte);
   100    100     if( !p ) return SQLITE_NOMEM;
   101         -  memset(p, 0, nByte);
          101  +  memset(p, 0, (size_t)nByte);
   102    102   
   103    103     p->pFts3Tab = (Fts3Table *)&p[1];
   104    104     p->pFts3Tab->zDb = (char *)&p->pFts3Tab[1];
   105    105     p->pFts3Tab->zName = &p->pFts3Tab->zDb[nDb+1];
   106    106     p->pFts3Tab->db = db;
   107    107     p->pFts3Tab->nIndex = iIndex+1;
   108    108     p->iIndex = iIndex;

Changes to ext/fts3/fts3_test.c.

   444    444     while( p<pEnd && testIsTokenChar(*p)==0 ) p++;
   445    445   
   446    446     if( p==pEnd ){
   447    447       rc = SQLITE_DONE;
   448    448     }else{
   449    449       /* Advance to the end of the token */
   450    450       const char *pToken = p;
   451         -    int nToken;
          451  +    sqlite3_int64 nToken;
   452    452       while( p<pEnd && testIsTokenChar(*p) ) p++;
   453         -    nToken = (int)(p-pToken);
          453  +    nToken = (sqlite3_int64)(p-pToken);
   454    454   
   455    455       /* Copy the token into the buffer */
   456    456       if( nToken>pCsr->nBuffer ){
   457    457         sqlite3_free(pCsr->aBuffer);
   458         -      pCsr->aBuffer = sqlite3_malloc(nToken);
          458  +      pCsr->aBuffer = sqlite3_malloc64(nToken);
   459    459       }
   460    460       if( pCsr->aBuffer==0 ){
   461    461         rc = SQLITE_NOMEM;
   462    462       }else{
   463    463         int i;
   464    464   
   465    465         if( pCsr->iLangid & 0x00000001 ){
................................................................................
   467    467         }else{
   468    468           for(i=0; i<nToken; i++) pCsr->aBuffer[i] = (char)testTolower(pToken[i]);
   469    469         }
   470    470         pCsr->iToken++;
   471    471         pCsr->iInput = (int)(p - pCsr->aInput);
   472    472   
   473    473         *ppToken = pCsr->aBuffer;
   474         -      *pnBytes = nToken;
          474  +      *pnBytes = (int)nToken;
   475    475         *piStartOffset = (int)(pToken - pCsr->aInput);
   476    476         *piEndOffset = (int)(p - pCsr->aInput);
   477    477         *piPosition = pCsr->iToken;
   478    478       }
   479    479     }
   480    480   
   481    481     return rc;
................................................................................
   569    569     UNUSED_PARAMETER(clientData);
   570    570     return TCL_OK;
   571    571   }
   572    572   
   573    573   /* 
   574    574   ** End of tokenizer code.
   575    575   **************************************************************************/ 
          576  +
          577  +/*
          578  +**      sqlite3_fts3_may_be_corrupt BOOLEAN
          579  +**
          580  +** Set or clear the global "may-be-corrupt" flag. Return the old value.
          581  +*/
          582  +static int SQLITE_TCLAPI fts3_may_be_corrupt(
          583  +  void * clientData,
          584  +  Tcl_Interp *interp,
          585  +  int objc,
          586  +  Tcl_Obj *CONST objv[]
          587  +){
          588  +  int bOld = sqlite3_fts3_may_be_corrupt;
          589  +
          590  +  if( objc!=2 && objc!=1 ){
          591  +    Tcl_WrongNumArgs(interp, 1, objv, "?BOOLEAN?");
          592  +    return TCL_ERROR;
          593  +  }
          594  +  if( objc==2 ){
          595  +    int bNew;
          596  +    if( Tcl_GetBooleanFromObj(interp, objv[1], &bNew) ) return TCL_ERROR;
          597  +    sqlite3_fts3_may_be_corrupt = bNew;
          598  +  }
          599  +
          600  +  Tcl_SetObjResult(interp, Tcl_NewIntObj(bOld));
          601  +  return TCL_OK;
          602  +}
   576    603   
   577    604   int Sqlitetestfts3_Init(Tcl_Interp *interp){
   578    605     Tcl_CreateObjCommand(interp, "fts3_near_match", fts3_near_match_cmd, 0, 0);
   579    606     Tcl_CreateObjCommand(interp, 
   580    607         "fts3_configure_incr_load", fts3_configure_incr_load_cmd, 0, 0
   581    608     );
   582    609     Tcl_CreateObjCommand(
   583    610         interp, "fts3_test_tokenizer", fts3_test_tokenizer_cmd, 0, 0
   584    611     );
   585         -
   586    612     Tcl_CreateObjCommand(
   587    613         interp, "fts3_test_varint", fts3_test_varint_cmd, 0, 0
   588    614     );
          615  +  Tcl_CreateObjCommand(
          616  +      interp, "sqlite3_fts3_may_be_corrupt", fts3_may_be_corrupt, 0, 0
          617  +  );
   589    618     return TCL_OK;
   590    619   }
   591    620   #endif                  /* SQLITE_ENABLE_FTS3 || SQLITE_ENABLE_FTS4 */
   592    621   #endif                  /* ifdef SQLITE_TEST */

Changes to ext/fts3/fts3_tokenize_vtab.c.

   118    118       int nByte = 0;
   119    119       char **azDequote;
   120    120   
   121    121       for(i=0; i<argc; i++){
   122    122         nByte += (int)(strlen(argv[i]) + 1);
   123    123       }
   124    124   
   125         -    *pazDequote = azDequote = sqlite3_malloc(sizeof(char *)*argc + nByte);
          125  +    *pazDequote = azDequote = sqlite3_malloc64(sizeof(char *)*argc + nByte);
   126    126       if( azDequote==0 ){
   127    127         rc = SQLITE_NOMEM;
   128    128       }else{
   129    129         char *pSpace = (char *)&azDequote[argc];
   130    130         for(i=0; i<argc; i++){
   131    131           int n = (int)strlen(argv[i]);
   132    132           azDequote[i] = pSpace;
................................................................................
   342    342     UNUSED_PARAMETER(idxStr);
   343    343     UNUSED_PARAMETER(nVal);
   344    344   
   345    345     fts3tokResetCursor(pCsr);
   346    346     if( idxNum==1 ){
   347    347       const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
   348    348       int nByte = sqlite3_value_bytes(apVal[0]);
   349         -    pCsr->zInput = sqlite3_malloc(nByte+1);
          349  +    pCsr->zInput = sqlite3_malloc64(nByte+1);
   350    350       if( pCsr->zInput==0 ){
   351    351         rc = SQLITE_NOMEM;
   352    352       }else{
   353         -      memcpy(pCsr->zInput, zByte, nByte);
          353  +      if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
   354    354         pCsr->zInput[nByte] = 0;
   355    355         rc = pTab->pMod->xOpen(pTab->pTok, pCsr->zInput, nByte, &pCsr->pCsr);
   356    356         if( rc==SQLITE_OK ){
   357    357           pCsr->pCsr->pTokenizer = pTab->pTok;
   358    358         }
   359    359       }
   360    360     }

Changes to ext/fts3/fts3_tokenizer.c.

    75     75   
    76     76     pHash = (Fts3Hash *)sqlite3_user_data(context);
    77     77   
    78     78     zName = sqlite3_value_text(argv[0]);
    79     79     nName = sqlite3_value_bytes(argv[0])+1;
    80     80   
    81     81     if( argc==2 ){
    82         -    if( fts3TokenizerEnabled(context) ){
           82  +    if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[1]) ){
    83     83         void *pOld;
    84     84         int n = sqlite3_value_bytes(argv[1]);
    85     85         if( zName==0 || n!=sizeof(pPtr) ){
    86     86           sqlite3_result_error(context, "argument type mismatch", -1);
    87     87           return;
    88     88         }
    89     89         pPtr = *(void **)sqlite3_value_blob(argv[1]);
................................................................................
   102    102       if( !pPtr ){
   103    103         char *zErr = sqlite3_mprintf("unknown tokenizer: %s", zName);
   104    104         sqlite3_result_error(context, zErr, -1);
   105    105         sqlite3_free(zErr);
   106    106         return;
   107    107       }
   108    108     }
   109         -  sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
          109  +  if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
          110  +    sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
          111  +  }
   110    112   }
   111    113   
   112    114   int sqlite3Fts3IsIdChar(char c){
   113    115     static const char isFtsIdChar[] = {
   114    116         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 0x */
   115    117         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 1x */
   116    118         0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /* 2x */
................................................................................
   190    192       sqlite3Fts3ErrMsg(pzErr, "unknown tokenizer: %s", z);
   191    193       rc = SQLITE_ERROR;
   192    194     }else{
   193    195       char const **aArg = 0;
   194    196       int iArg = 0;
   195    197       z = &z[n+1];
   196    198       while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
   197         -      int nNew = sizeof(char *)*(iArg+1);
   198         -      char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
          199  +      sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
          200  +      char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
   199    201         if( !aNew ){
   200    202           sqlite3_free(zCopy);
   201    203           sqlite3_free((void *)aArg);
   202    204           return SQLITE_NOMEM;
   203    205         }
   204    206         aArg = aNew;
   205    207         aArg[iArg++] = z;
................................................................................
   384    386     rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
   385    387     if( rc!=SQLITE_OK ){
   386    388       return rc;
   387    389     }
   388    390   
   389    391     sqlite3_bind_text(pStmt, 1, zName, -1, SQLITE_STATIC);
   390    392     if( SQLITE_ROW==sqlite3_step(pStmt) ){
   391         -    if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB ){
          393  +    if( sqlite3_column_type(pStmt, 0)==SQLITE_BLOB
          394  +     && sqlite3_column_bytes(pStmt, 0)==sizeof(*pp)
          395  +    ){
   392    396         memcpy((void *)pp, sqlite3_column_blob(pStmt, 0), sizeof(*pp));
   393    397       }
   394    398     }
   395    399   
   396    400     return sqlite3_finalize(pStmt);
   397    401   }
   398    402   
................................................................................
   473    477   int sqlite3Fts3InitHashTable(
   474    478     sqlite3 *db, 
   475    479     Fts3Hash *pHash, 
   476    480     const char *zName
   477    481   ){
   478    482     int rc = SQLITE_OK;
   479    483     void *p = (void *)pHash;
   480         -  const int any = SQLITE_ANY;
          484  +  const int any = SQLITE_UTF8|SQLITE_DIRECTONLY;
   481    485   
   482    486   #ifdef SQLITE_TEST
   483    487     char *zTest = 0;
   484    488     char *zTest2 = 0;
   485    489     void *pdb = (void *)db;
   486    490     zTest = sqlite3_mprintf("%s_test", zName);
   487    491     zTest2 = sqlite3_mprintf("%s_internal_test", zName);

Changes to ext/fts3/fts3_unicode.c.

   151    151       }
   152    152     }
   153    153   
   154    154     if( nEntry ){
   155    155       int *aNew;                    /* New aiException[] array */
   156    156       int nNew;                     /* Number of valid entries in array aNew[] */
   157    157   
   158         -    aNew = sqlite3_realloc(p->aiException, (p->nException+nEntry)*sizeof(int));
          158  +    aNew = sqlite3_realloc64(p->aiException,(p->nException+nEntry)*sizeof(int));
   159    159       if( aNew==0 ) return SQLITE_NOMEM;
   160    160       nNew = p->nException;
   161    161   
   162    162       z = (const unsigned char *)zIn;
   163    163       while( z<zTerm ){
   164    164         READ_UTF8(z, zTerm, iCode);
   165    165         if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum 
................................................................................
   340    340   
   341    341     zOut = pCsr->zToken;
   342    342     do {
   343    343       int iOut;
   344    344   
   345    345       /* Grow the output buffer if required. */
   346    346       if( (zOut-pCsr->zToken)>=(pCsr->nAlloc-4) ){
   347         -      char *zNew = sqlite3_realloc(pCsr->zToken, pCsr->nAlloc+64);
          347  +      char *zNew = sqlite3_realloc64(pCsr->zToken, pCsr->nAlloc+64);
   348    348         if( !zNew ) return SQLITE_NOMEM;
   349    349         zOut = &zNew[zOut - pCsr->zToken];
   350    350         pCsr->zToken = zNew;
   351    351         pCsr->nAlloc += 64;
   352    352       }
   353    353   
   354    354       /* Write the folded case of the last character read to the output */

Changes to ext/fts3/fts3_unicode2.c.

     1      1   /*
     2         -** 2012 May 25
            2  +** 2012-05-25
     3      3   **
     4      4   ** The author disclaims copyright to this source code.  In place of
     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
................................................................................
   174    174       61726, 61784, 61800, 61816, 61836, 61880, 61896, 61914, 
   175    175       61948, 61998, 62062, 62122, 62154, 62184, 62200, 62218, 
   176    176       62252, 62302, 62364, 62410, 62442, 62478, 62536, 62554, 
   177    177       62584, 62604, 62640, 62648, 62656, 62664, 62730, 62766, 
   178    178       62830, 62890, 62924, 62974, 63032, 63050, 63082, 63118, 
   179    179       63182, 63242, 63274, 63310, 63368, 63390, 
   180    180     };
   181         -#define HIBIT ((char)0x80)
   182         -  char aChar[] = {
          181  +#define HIBIT ((unsigned char)0x80)
          182  +  unsigned char aChar[] = {
   183    183       '\0',      'a',       'c',       'e',       'i',       'n',       
   184    184       'o',       'u',       'y',       'y',       'a',       'c',       
   185    185       'd',       'e',       'e',       'g',       'h',       'i',       
   186    186       'j',       'k',       'l',       'n',       'o',       'r',       
   187    187       's',       't',       'u',       'u',       'w',       'y',       
   188    188       'z',       'o',       'u',       'a',       'i',       'o',       
   189    189       'u',       'u'|HIBIT, 'a'|HIBIT, 'g',       'k',       'o',       
................................................................................
   196    196       'f',       'g',       'h',       'h',       'i',       'i'|HIBIT, 
   197    197       'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',       
   198    198       'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',       
   199    199       's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',       
   200    200       'w',       'x',       'y',       'z',       'h',       't',       
   201    201       'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT, 
   202    202       'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT, 
   203         -    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',  
          203  +    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',       
   204    204     };
   205    205   
   206    206     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
   207    207     int iRes = 0;
   208    208     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
   209    209     int iLo = 0;
   210    210     while( iHi>=iLo ){
................................................................................
   227    227   ** is a diacritical modifier character.
   228    228   */
   229    229   int sqlite3FtsUnicodeIsdiacritic(int c){
   230    230     unsigned int mask0 = 0x08029FDF;
   231    231     unsigned int mask1 = 0x000361F8;
   232    232     if( c<768 || c>817 ) return 0;
   233    233     return (c < 768+32) ?
   234         -      (mask0 & (1 << (c-768))) :
   235         -      (mask1 & (1 << (c-768-32)));
          234  +      (mask0 & ((unsigned int)1 << (c-768))) :
          235  +      (mask1 & ((unsigned int)1 << (c-768-32)));
   236    236   }
   237    237   
   238    238   
   239    239   /*
   240    240   ** Interpret the argument as a unicode codepoint. If the codepoint
   241    241   ** is an upper case character that has a lower case equivalent,
   242    242   ** return the codepoint corresponding to the lower case version.

Changes to ext/fts3/fts3_write.c.

    19     19   
    20     20   #include "fts3Int.h"
    21     21   #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
    22     22   
    23     23   #include <string.h>
    24     24   #include <assert.h>
    25     25   #include <stdlib.h>
    26         -
           26  +#include <stdio.h>
    27     27   
    28     28   #define FTS_MAX_APPENDABLE_HEIGHT 16
    29     29   
    30     30   /*
    31     31   ** When full-text index nodes are loaded from disk, the buffer that they
    32     32   ** are loaded into has the following number of bytes of padding at the end 
    33     33   ** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer
................................................................................
    63     63   # define FTS3_NODE_CHUNK_THRESHOLD test_fts3_node_chunk_threshold
    64     64   #else
    65     65   # define FTS3_NODE_CHUNKSIZE (4*1024) 
    66     66   # define FTS3_NODE_CHUNK_THRESHOLD (FTS3_NODE_CHUNKSIZE*4)
    67     67   #endif
    68     68   
    69     69   /*
    70         -** The two values that may be meaningfully bound to the :1 parameter in
           70  +** The values that may be meaningfully bound to the :1 parameter in
    71     71   ** statements SQL_REPLACE_STAT and SQL_SELECT_STAT.
    72     72   */
    73     73   #define FTS_STAT_DOCTOTAL      0
    74     74   #define FTS_STAT_INCRMERGEHINT 1
    75     75   #define FTS_STAT_AUTOINCRMERGE 2
    76     76   
    77     77   /*
................................................................................
   331    331   /* This statement is used to determine which level to read the input from
   332    332   ** when performing an incremental merge. It returns the absolute level number
   333    333   ** of the oldest level in the db that contains at least ? segments. Or,
   334    334   ** if no level in the FTS index contains more than ? segments, the statement
   335    335   ** returns zero rows.  */
   336    336   /* 28 */ "SELECT level, count(*) AS cnt FROM %Q.'%q_segdir' "
   337    337            "  GROUP BY level HAVING cnt>=?"
   338         -         "  ORDER BY (level %% 1024) ASC LIMIT 1",
          338  +         "  ORDER BY (level %% 1024) ASC, 2 DESC LIMIT 1",
   339    339   
   340    340   /* Estimate the upper limit on the number of leaf nodes in a new segment
   341    341   ** created by merging the oldest :2 segments from absolute level :1. See 
   342    342   ** function sqlite3Fts3Incrmerge() for details.  */
   343    343   /* 29 */ "SELECT 2 * total(1 + leaves_end_block - start_block) "
   344         -         "  FROM %Q.'%q_segdir' WHERE level = ? AND idx < ?",
          344  +         "  FROM (SELECT * FROM %Q.'%q_segdir' "
          345  +         "        WHERE level = ? ORDER BY idx ASC LIMIT ?"
          346  +         "  )",
   345    347   
   346    348   /* SQL_DELETE_SEGDIR_ENTRY
   347    349   **   Delete the %_segdir entry on absolute level :1 with index :2.  */
   348    350   /* 30 */ "DELETE FROM %Q.'%q_segdir' WHERE level = ? AND idx = ?",
   349    351   
   350    352   /* SQL_SHIFT_SEGDIR_ENTRY
   351    353   **   Modify the idx value for the segment with idx=:3 on absolute level :2
................................................................................
   392    394     sqlite3_stmt *pStmt;
   393    395   
   394    396     assert( SizeofArray(azSql)==SizeofArray(p->aStmt) );
   395    397     assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
   396    398     
   397    399     pStmt = p->aStmt[eStmt];
   398    400     if( !pStmt ){
          401  +    int f = SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB;
   399    402       char *zSql;
   400    403       if( eStmt==SQL_CONTENT_INSERT ){
   401    404         zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName, p->zWriteExprlist);
   402    405       }else if( eStmt==SQL_SELECT_CONTENT_BY_ROWID ){
          406  +      f &= ~SQLITE_PREPARE_NO_VTAB;
   403    407         zSql = sqlite3_mprintf(azSql[eStmt], p->zReadExprlist);
   404    408       }else{
   405    409         zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName);
   406    410       }
   407    411       if( !zSql ){
   408    412         rc = SQLITE_NOMEM;
   409    413       }else{
   410         -      rc = sqlite3_prepare_v3(p->db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
   411         -                              &pStmt, NULL);
          414  +      rc = sqlite3_prepare_v3(p->db, zSql, -1, f, &pStmt, NULL);
   412    415         sqlite3_free(zSql);
   413    416         assert( rc==SQLITE_OK || pStmt==0 );
   414    417         p->aStmt[eStmt] = pStmt;
   415    418       }
   416    419     }
   417    420     if( apVal ){
   418    421       int i;
................................................................................
   562    565   static sqlite3_int64 getAbsoluteLevel(
   563    566     Fts3Table *p,                   /* FTS3 table handle */
   564    567     int iLangid,                    /* Language id */
   565    568     int iIndex,                     /* Index in p->aIndex[] */
   566    569     int iLevel                      /* Level of segments */
   567    570   ){
   568    571     sqlite3_int64 iBase;            /* First absolute level for iLangid/iIndex */
   569         -  assert( iLangid>=0 );
          572  +  assert_fts3_nc( iLangid>=0 );
   570    573     assert( p->nIndex>0 );
   571    574     assert( iIndex>=0 && iIndex<p->nIndex );
   572    575   
   573    576     iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL;
   574    577     return iBase + iLevel;
   575    578   }
   576    579   
................................................................................
   691    694   ){
   692    695     PendingList *p = *pp;
   693    696     int rc = SQLITE_OK;
   694    697   
   695    698     assert( !p || p->iLastDocid<=iDocid );
   696    699   
   697    700