/ Check-in [59e0d4f3]
Login

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

Overview
Comment:Merge the latest trunk changes into the apple-osx branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1: 59e0d4f3d9af81d0c920812a6583228faa300cd6
User & Date: drh 2011-12-08 21:08:53
Context
2012-01-03
21:54
Pull all the latest trunk changes over into the apple-osx branch. check-in: 8a048423 user: drh tags: apple-osx
2011-12-08
21:08
Merge the latest trunk changes into the apple-osx branch. check-in: 59e0d4f3 user: drh tags: apple-osx
20:41
Hand merge the zone allocator for MacOS from the apple-osx branch. check-in: 0d955c20 user: drh tags: trunk
2011-10-31
19:59
Fix a problem with sqlite3_backup_step() that resulted from a faulty merge. check-in: dacdec78 user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   528    528   	$(TCLSH_CMD) $(TOP)/tool/vdbe-compress.tcl <tsrc/vdbe.c >vdbe.new
   529    529   	mv vdbe.new tsrc/vdbe.c
   530    530   	touch .target_source
   531    531   
   532    532   sqlite3.c:	.target_source $(TOP)/tool/mksqlite3c.tcl
   533    533   	$(TCLSH_CMD) $(TOP)/tool/mksqlite3c.tcl
   534    534   
          535  +tclsqlite3.c:	sqlite3.c
          536  +	echo '#ifndef USE_SYSTEM_SQLITE' >tclsqlite3.c
          537  +	cat sqlite3.c >>tclsqlite3.c
          538  +	echo '#endif /* USE_SYSTEM_SQLITE */' >>tclsqlite3.c
          539  +	cat $(TOP)/src/tclsqlite.c >>tclsqlite3.c
          540  +
   535    541   sqlite3-all.c:	sqlite3.c $(TOP)/tool/split-sqlite3c.tcl
   536    542   	$(TCLSH_CMD) $(TOP)/tool/split-sqlite3c.tcl
   537    543   
   538    544   # Rule to build the amalgamation
   539    545   #
   540    546   sqlite3.lo:	sqlite3.c
   541    547   	$(LTCOMPILE) $(TEMP_STORE) -c sqlite3.c

Changes to Makefile.msc.

    45     45   
    46     46   # C Compile and options for use in building executables that
    47     47   # will run on the target platform.  (BCC and TCC are usually the
    48     48   # same unless your are cross-compiling.)
    49     49   #
    50     50   TCC = cl.exe -W3 -DSQLITE_OS_WIN=1 -I. -I$(TOP)\src -fp:precise
    51     51   
           52  +# We always have the _msize function available when using MSVC.
           53  +TCC = $(TCC) -DHAVE_MALLOC_USABLE_SIZE -Dmalloc_usable_size=_msize
           54  +
    52     55   # The mksqlite3c.tcl and mksqlite3h.tcl scripts will pull in 
    53     56   # any extension header files by default.  For non-amalgamation
    54     57   # builds, we need to make sure the compiler can find these.
    55     58   #
    56     59   !IF $(USE_AMALGAMATION)==0
    57     60   TCC = $(TCC) -I$(TOP)\ext\fts3
    58     61   TCC = $(TCC) -I$(TOP)\ext\rtree

Changes to VERSION.

     1         -3.7.9
            1  +3.7.10

Changes to config.h.in.

    28     28   #undef HAVE_INTTYPES_H
    29     29   
    30     30   /* Define to 1 if you have the `localtime_r' function. */
    31     31   #undef HAVE_LOCALTIME_R
    32     32   
    33     33   /* Define to 1 if you have the `localtime_s' function. */
    34     34   #undef HAVE_LOCALTIME_S
           35  +
           36  +/* Define to 1 if you have the `malloc_usable_size' function. */
           37  +#undef HAVE_MALLOC_USABLE_SIZE
    35     38   
    36     39   /* Define to 1 if you have the <memory.h> header file. */
    37     40   #undef HAVE_MEMORY_H
    38     41   
    39     42   /* Define to 1 if you have the <stdint.h> header file. */
    40     43   #undef HAVE_STDINT_H
    41     44   

Changes to configure.

     1      1   #! /bin/sh
     2      2   # Guess values for system-dependent variables and create Makefiles.
     3         -# Generated by GNU Autoconf 2.67 for sqlite 3.7.9.
            3  +# Generated by GNU Autoconf 2.68 for sqlite 3.7.10.
     4      4   #
     5      5   #
     6      6   # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
     7      7   # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
     8      8   # Foundation, Inc.
     9      9   #
    10     10   #
................................................................................
    85     85   # We need space, tab and new line, in precisely that order.  Quoting is
    86     86   # there to prevent editors from complaining about space-tab.
    87     87   # (If _AS_PATH_WALK were called with IFS unset, it would disable word
    88     88   # splitting by setting IFS to empty value.)
    89     89   IFS=" ""	$as_nl"
    90     90   
    91     91   # Find who we are.  Look in the path if we contain no directory separator.
           92  +as_myself=
    92     93   case $0 in #((
    93     94     *[\\/]* ) as_myself=$0 ;;
    94     95     *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
    95     96   for as_dir in $PATH
    96     97   do
    97     98     IFS=$as_save_IFS
    98     99     test -z "$as_dir" && as_dir=.
................................................................................
   210    211   IFS=$as_save_IFS
   211    212   
   212    213   
   213    214         if test "x$CONFIG_SHELL" != x; then :
   214    215     # We cannot yet assume a decent shell, so we have to provide a
   215    216   	# neutralization value for shells without unset; and this also
   216    217   	# works around shells that cannot unset nonexistent variables.
          218  +	# Preserve -v and -x to the replacement shell.
   217    219   	BASH_ENV=/dev/null
   218    220   	ENV=/dev/null
   219    221   	(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
   220    222   	export CONFIG_SHELL
   221         -	exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"}
          223  +	case $- in # ((((
          224  +	  *v*x* | *x*v* ) as_opts=-vx ;;
          225  +	  *v* ) as_opts=-v ;;
          226  +	  *x* ) as_opts=-x ;;
          227  +	  * ) as_opts= ;;
          228  +	esac
          229  +	exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"}
   222    230   fi
   223    231   
   224    232       if test x$as_have_required = xno; then :
   225    233     $as_echo "$0: This script requires a shell more modern than all"
   226    234     $as_echo "$0: the shells that I found on your system."
   227    235     if test x${ZSH_VERSION+set} = xset ; then
   228    236       $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
................................................................................
   694    702   subdirs=
   695    703   MFLAGS=
   696    704   MAKEFLAGS=
   697    705   
   698    706   # Identity of this package.
   699    707   PACKAGE_NAME='sqlite'
   700    708   PACKAGE_TARNAME='sqlite'
   701         -PACKAGE_VERSION='3.7.9'
   702         -PACKAGE_STRING='sqlite 3.7.9'
          709  +PACKAGE_VERSION='3.7.10'
          710  +PACKAGE_STRING='sqlite 3.7.10'
   703    711   PACKAGE_BUGREPORT=''
   704    712   PACKAGE_URL=''
   705    713   
   706    714   # Factoring default headers for most tests.
   707    715   ac_includes_default="\
   708    716   #include <stdio.h>
   709    717   #ifdef HAVE_SYS_TYPES_H
................................................................................
  1290   1298       export $ac_envvar ;;
  1291   1299   
  1292   1300     *)
  1293   1301       # FIXME: should be removed in autoconf 3.0.
  1294   1302       $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
  1295   1303       expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
  1296   1304         $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
  1297         -    : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
         1305  +    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
  1298   1306       ;;
  1299   1307   
  1300   1308     esac
  1301   1309   done
  1302   1310   
  1303   1311   if test -n "$ac_prev"; then
  1304   1312     ac_option=--`echo $ac_prev | sed 's/_/-/g'`
................................................................................
  1428   1436   #
  1429   1437   # Report the --help message.
  1430   1438   #
  1431   1439   if test "$ac_init_help" = "long"; then
  1432   1440     # Omit some internal or obsolete options to make the list less imposing.
  1433   1441     # This message is too long to be a string in the A/UX 3.1 sh.
  1434   1442     cat <<_ACEOF
  1435         -\`configure' configures sqlite 3.7.9 to adapt to many kinds of systems.
         1443  +\`configure' configures sqlite 3.7.10 to adapt to many kinds of systems.
  1436   1444   
  1437   1445   Usage: $0 [OPTION]... [VAR=VALUE]...
  1438   1446   
  1439   1447   To assign environment variables (e.g., CC, CFLAGS...), specify them as
  1440   1448   VAR=VALUE.  See below for descriptions of some of the useful variables.
  1441   1449   
  1442   1450   Defaults for the options are specified in brackets.
................................................................................
  1493   1501     --build=BUILD     configure for building on BUILD [guessed]
  1494   1502     --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  1495   1503   _ACEOF
  1496   1504   fi
  1497   1505   
  1498   1506   if test -n "$ac_init_help"; then
  1499   1507     case $ac_init_help in
  1500         -     short | recursive ) echo "Configuration of sqlite 3.7.9:";;
         1508  +     short | recursive ) echo "Configuration of sqlite 3.7.10:";;
  1501   1509      esac
  1502   1510     cat <<\_ACEOF
  1503   1511   
  1504   1512   Optional Features:
  1505   1513     --disable-option-checking  ignore unrecognized --enable/--with options
  1506   1514     --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  1507   1515     --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
  1610   1618       cd "$ac_pwd" || { ac_status=$?; break; }
  1611   1619     done
  1612   1620   fi
  1613   1621   
  1614   1622   test -n "$ac_init_help" && exit $ac_status
  1615   1623   if $ac_init_version; then
  1616   1624     cat <<\_ACEOF
  1617         -sqlite configure 3.7.9
  1618         -generated by GNU Autoconf 2.67
         1625  +sqlite configure 3.7.10
         1626  +generated by GNU Autoconf 2.68
  1619   1627   
  1620   1628   Copyright (C) 2010 Free Software Foundation, Inc.
  1621   1629   This configure script is free software; the Free Software Foundation
  1622   1630   gives unlimited permission to copy, distribute and modify it.
  1623   1631   _ACEOF
  1624   1632     exit
  1625   1633   fi
................................................................................
  1657   1665     ac_retval=0
  1658   1666   else
  1659   1667     $as_echo "$as_me: failed program was:" >&5
  1660   1668   sed 's/^/| /' conftest.$ac_ext >&5
  1661   1669   
  1662   1670   	ac_retval=1
  1663   1671   fi
  1664         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         1672  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1665   1673     as_fn_set_status $ac_retval
  1666   1674   
  1667   1675   } # ac_fn_c_try_compile
  1668   1676   
  1669   1677   # ac_fn_c_try_link LINENO
  1670   1678   # -----------------------
  1671   1679   # Try to link conftest.$ac_ext, and return whether this succeeded.
................................................................................
  1703   1711   	ac_retval=1
  1704   1712   fi
  1705   1713     # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
  1706   1714     # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
  1707   1715     # interfere with the next link command; also delete a directory that is
  1708   1716     # left behind by Apple's compiler.  We do this before executing the actions.
  1709   1717     rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  1710         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         1718  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1711   1719     as_fn_set_status $ac_retval
  1712   1720   
  1713   1721   } # ac_fn_c_try_link
  1714   1722   
  1715   1723   # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
  1716   1724   # -------------------------------------------------------
  1717   1725   # Tests whether HEADER exists and can be compiled using the include files in
  1718   1726   # INCLUDES, setting the cache variable VAR accordingly.
  1719   1727   ac_fn_c_check_header_compile ()
  1720   1728   {
  1721   1729     as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  1722   1730     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
  1723   1731   $as_echo_n "checking for $2... " >&6; }
  1724         -if eval "test \"\${$3+set}\"" = set; then :
         1732  +if eval \${$3+:} false; then :
  1725   1733     $as_echo_n "(cached) " >&6
  1726   1734   else
  1727   1735     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  1728   1736   /* end confdefs.h.  */
  1729   1737   $4
  1730   1738   #include <$2>
  1731   1739   _ACEOF
................................................................................
  1735   1743     eval "$3=no"
  1736   1744   fi
  1737   1745   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  1738   1746   fi
  1739   1747   eval ac_res=\$$3
  1740   1748   	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
  1741   1749   $as_echo "$ac_res" >&6; }
  1742         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         1750  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1743   1751   
  1744   1752   } # ac_fn_c_check_header_compile
  1745   1753   
  1746   1754   # ac_fn_c_try_cpp LINENO
  1747   1755   # ----------------------
  1748   1756   # Try to preprocess conftest.$ac_ext, and return whether this succeeded.
  1749   1757   ac_fn_c_try_cpp ()
................................................................................
  1771   1779     ac_retval=0
  1772   1780   else
  1773   1781     $as_echo "$as_me: failed program was:" >&5
  1774   1782   sed 's/^/| /' conftest.$ac_ext >&5
  1775   1783   
  1776   1784       ac_retval=1
  1777   1785   fi
  1778         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         1786  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1779   1787     as_fn_set_status $ac_retval
  1780   1788   
  1781   1789   } # ac_fn_c_try_cpp
  1782   1790   
  1783   1791   # ac_fn_c_try_run LINENO
  1784   1792   # ----------------------
  1785   1793   # Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
................................................................................
  1813   1821     $as_echo "$as_me: program exited with status $ac_status" >&5
  1814   1822          $as_echo "$as_me: failed program was:" >&5
  1815   1823   sed 's/^/| /' conftest.$ac_ext >&5
  1816   1824   
  1817   1825          ac_retval=$ac_status
  1818   1826   fi
  1819   1827     rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  1820         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         1828  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1821   1829     as_fn_set_status $ac_retval
  1822   1830   
  1823   1831   } # ac_fn_c_try_run
  1824   1832   
  1825   1833   # ac_fn_c_check_func LINENO FUNC VAR
  1826   1834   # ----------------------------------
  1827   1835   # Tests whether FUNC exists, setting the cache variable VAR accordingly
  1828   1836   ac_fn_c_check_func ()
  1829   1837   {
  1830   1838     as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  1831   1839     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
  1832   1840   $as_echo_n "checking for $2... " >&6; }
  1833         -if eval "test \"\${$3+set}\"" = set; then :
         1841  +if eval \${$3+:} false; then :
  1834   1842     $as_echo_n "(cached) " >&6
  1835   1843   else
  1836   1844     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  1837   1845   /* end confdefs.h.  */
  1838   1846   /* Define $2 to an innocuous variant, in case <limits.h> declares $2.
  1839   1847      For example, HP-UX 11i <limits.h> declares gettimeofday.  */
  1840   1848   #define $2 innocuous_$2
................................................................................
  1881   1889   fi
  1882   1890   rm -f core conftest.err conftest.$ac_objext \
  1883   1891       conftest$ac_exeext conftest.$ac_ext
  1884   1892   fi
  1885   1893   eval ac_res=\$$3
  1886   1894   	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
  1887   1895   $as_echo "$ac_res" >&6; }
  1888         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         1896  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1889   1897   
  1890   1898   } # ac_fn_c_check_func
  1891   1899   
  1892   1900   # ac_fn_c_check_type LINENO TYPE VAR INCLUDES
  1893   1901   # -------------------------------------------
  1894   1902   # Tests whether TYPE exists after having included INCLUDES, setting cache
  1895   1903   # variable VAR accordingly.
  1896   1904   ac_fn_c_check_type ()
  1897   1905   {
  1898   1906     as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  1899   1907     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
  1900   1908   $as_echo_n "checking for $2... " >&6; }
  1901         -if eval "test \"\${$3+set}\"" = set; then :
         1909  +if eval \${$3+:} false; then :
  1902   1910     $as_echo_n "(cached) " >&6
  1903   1911   else
  1904   1912     eval "$3=no"
  1905   1913     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  1906   1914   /* end confdefs.h.  */
  1907   1915   $4
  1908   1916   int
................................................................................
  1935   1943   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  1936   1944   fi
  1937   1945   rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  1938   1946   fi
  1939   1947   eval ac_res=\$$3
  1940   1948   	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
  1941   1949   $as_echo "$ac_res" >&6; }
  1942         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         1950  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1943   1951   
  1944   1952   } # ac_fn_c_check_type
  1945   1953   
  1946   1954   # ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
  1947   1955   # -------------------------------------------------------
  1948   1956   # Tests whether HEADER exists, giving a warning if it cannot be compiled using
  1949   1957   # the include files in INCLUDES and setting the cache variable VAR
  1950   1958   # accordingly.
  1951   1959   ac_fn_c_check_header_mongrel ()
  1952   1960   {
  1953   1961     as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  1954         -  if eval "test \"\${$3+set}\"" = set; then :
         1962  +  if eval \${$3+:} false; then :
  1955   1963     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
  1956   1964   $as_echo_n "checking for $2... " >&6; }
  1957         -if eval "test \"\${$3+set}\"" = set; then :
         1965  +if eval \${$3+:} false; then :
  1958   1966     $as_echo_n "(cached) " >&6
  1959   1967   fi
  1960   1968   eval ac_res=\$$3
  1961   1969   	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
  1962   1970   $as_echo "$ac_res" >&6; }
  1963   1971   else
  1964   1972     # Is the header compilable?
................................................................................
  2013   2021   $as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
  2014   2022       { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
  2015   2023   $as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
  2016   2024       ;;
  2017   2025   esac
  2018   2026     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
  2019   2027   $as_echo_n "checking for $2... " >&6; }
  2020         -if eval "test \"\${$3+set}\"" = set; then :
         2028  +if eval \${$3+:} false; then :
  2021   2029     $as_echo_n "(cached) " >&6
  2022   2030   else
  2023   2031     eval "$3=\$ac_header_compiler"
  2024   2032   fi
  2025   2033   eval ac_res=\$$3
  2026   2034   	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
  2027   2035   $as_echo "$ac_res" >&6; }
  2028   2036   fi
  2029         -  eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;}
         2037  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  2030   2038   
  2031   2039   } # ac_fn_c_check_header_mongrel
  2032   2040   cat >config.log <<_ACEOF
  2033   2041   This file contains any messages produced by compilers while
  2034   2042   running configure, to aid debugging if configure makes a mistake.
  2035   2043   
  2036         -It was created by sqlite $as_me 3.7.9, which was
  2037         -generated by GNU Autoconf 2.67.  Invocation command line was
         2044  +It was created by sqlite $as_me 3.7.10, which was
         2045  +generated by GNU Autoconf 2.68.  Invocation command line was
  2038   2046   
  2039   2047     $ $0 $@
  2040   2048   
  2041   2049   _ACEOF
  2042   2050   exec 5>>config.log
  2043   2051   {
  2044   2052   cat <<_ASUNAME
................................................................................
  2288   2296       { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
  2289   2297   $as_echo "$as_me: loading site script $ac_site_file" >&6;}
  2290   2298       sed 's/^/| /' "$ac_site_file" >&5
  2291   2299       . "$ac_site_file" \
  2292   2300         || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  2293   2301   $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  2294   2302   as_fn_error $? "failed to load site script $ac_site_file
  2295         -See \`config.log' for more details" "$LINENO" 5 ; }
         2303  +See \`config.log' for more details" "$LINENO" 5; }
  2296   2304     fi
  2297   2305   done
  2298   2306   
  2299   2307   if test -r "$cache_file"; then
  2300   2308     # Some versions of bash will fail to source /dev/null (special files
  2301   2309     # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
  2302   2310     if test /dev/null != "$cache_file" && test -f "$cache_file"; then
................................................................................
  2452   2460   
  2453   2461   # Make sure we can run config.sub.
  2454   2462   $SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
  2455   2463     as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
  2456   2464   
  2457   2465   { $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
  2458   2466   $as_echo_n "checking build system type... " >&6; }
  2459         -if test "${ac_cv_build+set}" = set; then :
         2467  +if ${ac_cv_build+:} false; then :
  2460   2468     $as_echo_n "(cached) " >&6
  2461   2469   else
  2462   2470     ac_build_alias=$build_alias
  2463   2471   test "x$ac_build_alias" = x &&
  2464   2472     ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
  2465   2473   test "x$ac_build_alias" = x &&
  2466   2474     as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
................................................................................
  2468   2476     as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
  2469   2477   
  2470   2478   fi
  2471   2479   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
  2472   2480   $as_echo "$ac_cv_build" >&6; }
  2473   2481   case $ac_cv_build in
  2474   2482   *-*-*) ;;
  2475         -*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5 ;;
         2483  +*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
  2476   2484   esac
  2477   2485   build=$ac_cv_build
  2478   2486   ac_save_IFS=$IFS; IFS='-'
  2479   2487   set x $ac_cv_build
  2480   2488   shift
  2481   2489   build_cpu=$1
  2482   2490   build_vendor=$2
................................................................................
  2486   2494   build_os=$*
  2487   2495   IFS=$ac_save_IFS
  2488   2496   case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
  2489   2497   
  2490   2498   
  2491   2499   { $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
  2492   2500   $as_echo_n "checking host system type... " >&6; }
  2493         -if test "${ac_cv_host+set}" = set; then :
         2501  +if ${ac_cv_host+:} false; then :
  2494   2502     $as_echo_n "(cached) " >&6
  2495   2503   else
  2496   2504     if test "x$host_alias" = x; then
  2497   2505     ac_cv_host=$ac_cv_build
  2498   2506   else
  2499   2507     ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
  2500   2508       as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
................................................................................
  2501   2509   fi
  2502   2510   
  2503   2511   fi
  2504   2512   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
  2505   2513   $as_echo "$ac_cv_host" >&6; }
  2506   2514   case $ac_cv_host in
  2507   2515   *-*-*) ;;
  2508         -*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5 ;;
         2516  +*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
  2509   2517   esac
  2510   2518   host=$ac_cv_host
  2511   2519   ac_save_IFS=$IFS; IFS='-'
  2512   2520   set x $ac_cv_host
  2513   2521   shift
  2514   2522   host_cpu=$1
  2515   2523   host_vendor=$2
................................................................................
  2527   2535   ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
  2528   2536   ac_compiler_gnu=$ac_cv_c_compiler_gnu
  2529   2537   if test -n "$ac_tool_prefix"; then
  2530   2538     # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
  2531   2539   set dummy ${ac_tool_prefix}gcc; ac_word=$2
  2532   2540   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  2533   2541   $as_echo_n "checking for $ac_word... " >&6; }
  2534         -if test "${ac_cv_prog_CC+set}" = set; then :
         2542  +if ${ac_cv_prog_CC+:} false; then :
  2535   2543     $as_echo_n "(cached) " >&6
  2536   2544   else
  2537   2545     if test -n "$CC"; then
  2538   2546     ac_cv_prog_CC="$CC" # Let the user override the test.
  2539   2547   else
  2540   2548   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  2541   2549   for as_dir in $PATH
................................................................................
  2567   2575   fi
  2568   2576   if test -z "$ac_cv_prog_CC"; then
  2569   2577     ac_ct_CC=$CC
  2570   2578     # Extract the first word of "gcc", so it can be a program name with args.
  2571   2579   set dummy gcc; ac_word=$2
  2572   2580   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  2573   2581   $as_echo_n "checking for $ac_word... " >&6; }
  2574         -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
         2582  +if ${ac_cv_prog_ac_ct_CC+:} false; then :
  2575   2583     $as_echo_n "(cached) " >&6
  2576   2584   else
  2577   2585     if test -n "$ac_ct_CC"; then
  2578   2586     ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
  2579   2587   else
  2580   2588   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  2581   2589   for as_dir in $PATH
................................................................................
  2620   2628   
  2621   2629   if test -z "$CC"; then
  2622   2630             if test -n "$ac_tool_prefix"; then
  2623   2631       # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
  2624   2632   set dummy ${ac_tool_prefix}cc; ac_word=$2
  2625   2633   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  2626   2634   $as_echo_n "checking for $ac_word... " >&6; }
  2627         -if test "${ac_cv_prog_CC+set}" = set; then :
         2635  +if ${ac_cv_prog_CC+:} false; then :
  2628   2636     $as_echo_n "(cached) " >&6
  2629   2637   else
  2630   2638     if test -n "$CC"; then
  2631   2639     ac_cv_prog_CC="$CC" # Let the user override the test.
  2632   2640   else
  2633   2641   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  2634   2642   for as_dir in $PATH
................................................................................
  2660   2668     fi
  2661   2669   fi
  2662   2670   if test -z "$CC"; then
  2663   2671     # Extract the first word of "cc", so it can be a program name with args.
  2664   2672   set dummy cc; ac_word=$2
  2665   2673   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  2666   2674   $as_echo_n "checking for $ac_word... " >&6; }
  2667         -if test "${ac_cv_prog_CC+set}" = set; then :
         2675  +if ${ac_cv_prog_CC+:} false; then :
  2668   2676     $as_echo_n "(cached) " >&6
  2669   2677   else
  2670   2678     if test -n "$CC"; then
  2671   2679     ac_cv_prog_CC="$CC" # Let the user override the test.
  2672   2680   else
  2673   2681     ac_prog_rejected=no
  2674   2682   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
................................................................................
  2719   2727     if test -n "$ac_tool_prefix"; then
  2720   2728     for ac_prog in cl.exe
  2721   2729     do
  2722   2730       # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
  2723   2731   set dummy $ac_tool_prefix$ac_prog; ac_word=$2
  2724   2732   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  2725   2733   $as_echo_n "checking for $ac_word... " >&6; }
  2726         -if test "${ac_cv_prog_CC+set}" = set; then :
         2734  +if ${ac_cv_prog_CC+:} false; then :
  2727   2735     $as_echo_n "(cached) " >&6
  2728   2736   else
  2729   2737     if test -n "$CC"; then
  2730   2738     ac_cv_prog_CC="$CC" # Let the user override the test.
  2731   2739   else
  2732   2740   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  2733   2741   for as_dir in $PATH
................................................................................
  2763   2771     ac_ct_CC=$CC
  2764   2772     for ac_prog in cl.exe
  2765   2773   do
  2766   2774     # Extract the first word of "$ac_prog", so it can be a program name with args.
  2767   2775   set dummy $ac_prog; ac_word=$2
  2768   2776   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  2769   2777   $as_echo_n "checking for $ac_word... " >&6; }
  2770         -if test "${ac_cv_prog_ac_ct_CC+set}" = set; then :
         2778  +if ${ac_cv_prog_ac_ct_CC+:} false; then :
  2771   2779     $as_echo_n "(cached) " >&6
  2772   2780   else
  2773   2781     if test -n "$ac_ct_CC"; then
  2774   2782     ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
  2775   2783   else
  2776   2784   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  2777   2785   for as_dir in $PATH
................................................................................
  2818   2826   
  2819   2827   fi
  2820   2828   
  2821   2829   
  2822   2830   test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  2823   2831   $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  2824   2832   as_fn_error $? "no acceptable C compiler found in \$PATH
  2825         -See \`config.log' for more details" "$LINENO" 5 ; }
         2833  +See \`config.log' for more details" "$LINENO" 5; }
  2826   2834   
  2827   2835   # Provide some information about the compiler.
  2828   2836   $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
  2829   2837   set X $ac_compile
  2830   2838   ac_compiler=$2
  2831   2839   for ac_option in --version -v -V -qversion; do
  2832   2840     { { ac_try="$ac_compiler $ac_option >&5"
................................................................................
  2933   2941   $as_echo "no" >&6; }
  2934   2942   $as_echo "$as_me: failed program was:" >&5
  2935   2943   sed 's/^/| /' conftest.$ac_ext >&5
  2936   2944   
  2937   2945   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  2938   2946   $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  2939   2947   as_fn_error 77 "C compiler cannot create executables
  2940         -See \`config.log' for more details" "$LINENO" 5 ; }
         2948  +See \`config.log' for more details" "$LINENO" 5; }
  2941   2949   else
  2942   2950     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
  2943   2951   $as_echo "yes" >&6; }
  2944   2952   fi
  2945   2953   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
  2946   2954   $as_echo_n "checking for C compiler default output file name... " >&6; }
  2947   2955   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
................................................................................
  2976   2984       * ) break;;
  2977   2985     esac
  2978   2986   done
  2979   2987   else
  2980   2988     { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  2981   2989   $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  2982   2990   as_fn_error $? "cannot compute suffix of executables: cannot compile and link
  2983         -See \`config.log' for more details" "$LINENO" 5 ; }
         2991  +See \`config.log' for more details" "$LINENO" 5; }
  2984   2992   fi
  2985   2993   rm -f conftest conftest$ac_cv_exeext
  2986   2994   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
  2987   2995   $as_echo "$ac_cv_exeext" >&6; }
  2988   2996   
  2989   2997   rm -f conftest.$ac_ext
  2990   2998   EXEEXT=$ac_cv_exeext
................................................................................
  3035   3043       if test "$cross_compiling" = maybe; then
  3036   3044   	cross_compiling=yes
  3037   3045       else
  3038   3046   	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  3039   3047   $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  3040   3048   as_fn_error $? "cannot run C compiled programs.
  3041   3049   If you meant to cross compile, use \`--host'.
  3042         -See \`config.log' for more details" "$LINENO" 5 ; }
         3050  +See \`config.log' for more details" "$LINENO" 5; }
  3043   3051       fi
  3044   3052     fi
  3045   3053   fi
  3046   3054   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
  3047   3055   $as_echo "$cross_compiling" >&6; }
  3048   3056   
  3049   3057   rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
  3050   3058   ac_clean_files=$ac_clean_files_save
  3051   3059   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
  3052   3060   $as_echo_n "checking for suffix of object files... " >&6; }
  3053         -if test "${ac_cv_objext+set}" = set; then :
         3061  +if ${ac_cv_objext+:} false; then :
  3054   3062     $as_echo_n "(cached) " >&6
  3055   3063   else
  3056   3064     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  3057   3065   /* end confdefs.h.  */
  3058   3066   
  3059   3067   int
  3060   3068   main ()
................................................................................
  3087   3095   else
  3088   3096     $as_echo "$as_me: failed program was:" >&5
  3089   3097   sed 's/^/| /' conftest.$ac_ext >&5
  3090   3098   
  3091   3099   { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  3092   3100   $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  3093   3101   as_fn_error $? "cannot compute suffix of object files: cannot compile
  3094         -See \`config.log' for more details" "$LINENO" 5 ; }
         3102  +See \`config.log' for more details" "$LINENO" 5; }
  3095   3103   fi
  3096   3104   rm -f conftest.$ac_cv_objext conftest.$ac_ext
  3097   3105   fi
  3098   3106   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
  3099   3107   $as_echo "$ac_cv_objext" >&6; }
  3100   3108   OBJEXT=$ac_cv_objext
  3101   3109   ac_objext=$OBJEXT
  3102   3110   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
  3103   3111   $as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
  3104         -if test "${ac_cv_c_compiler_gnu+set}" = set; then :
         3112  +if ${ac_cv_c_compiler_gnu+:} false; then :
  3105   3113     $as_echo_n "(cached) " >&6
  3106   3114   else
  3107   3115     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  3108   3116   /* end confdefs.h.  */
  3109   3117   
  3110   3118   int
  3111   3119   main ()
................................................................................
  3134   3142   else
  3135   3143     GCC=
  3136   3144   fi
  3137   3145   ac_test_CFLAGS=${CFLAGS+set}
  3138   3146   ac_save_CFLAGS=$CFLAGS
  3139   3147   { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
  3140   3148   $as_echo_n "checking whether $CC accepts -g... " >&6; }
  3141         -if test "${ac_cv_prog_cc_g+set}" = set; then :
         3149  +if ${ac_cv_prog_cc_g+:} false; then :
  3142   3150     $as_echo_n "(cached) " >&6
  3143   3151   else
  3144   3152     ac_save_c_werror_flag=$ac_c_werror_flag
  3145   3153      ac_c_werror_flag=yes
  3146   3154      ac_cv_prog_cc_g=no
  3147   3155      CFLAGS="-g"
  3148   3156      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
................................................................................
  3212   3220       CFLAGS="-O2"
  3213   3221     else
  3214   3222       CFLAGS=
  3215   3223     fi
  3216   3224   fi
  3217   3225   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
  3218   3226   $as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
  3219         -if test "${ac_cv_prog_cc_c89+set}" = set; then :
         3227  +if ${ac_cv_prog_cc_c89+:} false; then :
  3220   3228     $as_echo_n "(cached) " >&6
  3221   3229   else
  3222   3230     ac_cv_prog_cc_c89=no
  3223   3231   ac_save_CC=$CC
  3224   3232   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  3225   3233   /* end confdefs.h.  */
  3226   3234   #include <stdarg.h>
................................................................................
  3309   3317   ac_cpp='$CPP $CPPFLAGS'
  3310   3318   ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
  3311   3319   ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
  3312   3320   ac_compiler_gnu=$ac_cv_c_compiler_gnu
  3313   3321   
  3314   3322   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
  3315   3323   $as_echo_n "checking for a sed that does not truncate output... " >&6; }
  3316         -if test "${ac_cv_path_SED+set}" = set; then :
         3324  +if ${ac_cv_path_SED+:} false; then :
  3317   3325     $as_echo_n "(cached) " >&6
  3318   3326   else
  3319   3327               ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
  3320   3328        for ac_i in 1 2 3 4 5 6 7; do
  3321   3329          ac_script="$ac_script$as_nl$ac_script"
  3322   3330        done
  3323   3331        echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
................................................................................
  3391   3399   
  3392   3400   
  3393   3401   
  3394   3402   
  3395   3403   
  3396   3404   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
  3397   3405   $as_echo_n "checking for grep that handles long lines and -e... " >&6; }
  3398         -if test "${ac_cv_path_GREP+set}" = set; then :
         3406  +if ${ac_cv_path_GREP+:} false; then :
  3399   3407     $as_echo_n "(cached) " >&6
  3400   3408   else
  3401   3409     if test -z "$GREP"; then
  3402   3410     ac_path_GREP_found=false
  3403   3411     # Loop through the user's path and test for each of PROGNAME-LIST
  3404   3412     as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  3405   3413   for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
................................................................................
  3454   3462   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
  3455   3463   $as_echo "$ac_cv_path_GREP" >&6; }
  3456   3464    GREP="$ac_cv_path_GREP"
  3457   3465   
  3458   3466   
  3459   3467   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
  3460   3468   $as_echo_n "checking for egrep... " >&6; }
  3461         -if test "${ac_cv_path_EGREP+set}" = set; then :
         3469  +if ${ac_cv_path_EGREP+:} false; then :
  3462   3470     $as_echo_n "(cached) " >&6
  3463   3471   else
  3464   3472     if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
  3465   3473      then ac_cv_path_EGREP="$GREP -E"
  3466   3474      else
  3467   3475        if test -z "$EGREP"; then
  3468   3476     ac_path_EGREP_found=false
................................................................................
  3521   3529   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
  3522   3530   $as_echo "$ac_cv_path_EGREP" >&6; }
  3523   3531    EGREP="$ac_cv_path_EGREP"
  3524   3532   
  3525   3533   
  3526   3534   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5
  3527   3535   $as_echo_n "checking for fgrep... " >&6; }
  3528         -if test "${ac_cv_path_FGREP+set}" = set; then :
         3536  +if ${ac_cv_path_FGREP+:} false; then :
  3529   3537     $as_echo_n "(cached) " >&6
  3530   3538   else
  3531   3539     if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1
  3532   3540      then ac_cv_path_FGREP="$GREP -F"
  3533   3541      else
  3534   3542        if test -z "$FGREP"; then
  3535   3543     ac_path_FGREP_found=false
................................................................................
  3652   3660   elif test "$with_gnu_ld" = yes; then
  3653   3661     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5
  3654   3662   $as_echo_n "checking for GNU ld... " >&6; }
  3655   3663   else
  3656   3664     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5
  3657   3665   $as_echo_n "checking for non-GNU ld... " >&6; }
  3658   3666   fi
  3659         -if test "${lt_cv_path_LD+set}" = set; then :
         3667  +if ${lt_cv_path_LD+:} false; then :
  3660   3668     $as_echo_n "(cached) " >&6
  3661   3669   else
  3662   3670     if test -z "$LD"; then
  3663   3671     lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
  3664   3672     for ac_dir in $PATH; do
  3665   3673       IFS="$lt_save_ifs"
  3666   3674       test -z "$ac_dir" && ac_dir=.
................................................................................
  3692   3700   else
  3693   3701     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
  3694   3702   $as_echo "no" >&6; }
  3695   3703   fi
  3696   3704   test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5
  3697   3705   { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5
  3698   3706   $as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; }
  3699         -if test "${lt_cv_prog_gnu_ld+set}" = set; then :
         3707  +if ${lt_cv_prog_gnu_ld+:} false; then :
  3700   3708     $as_echo_n "(cached) " >&6
  3701   3709   else
  3702   3710     # I'd rather use --version here, but apparently some GNU lds only accept -v.
  3703   3711   case `$LD -v 2>&1 </dev/null` in
  3704   3712   *GNU* | *'with BFD'*)
  3705   3713     lt_cv_prog_gnu_ld=yes
  3706   3714     ;;
................................................................................
  3719   3727   
  3720   3728   
  3721   3729   
  3722   3730   
  3723   3731   
  3724   3732   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5
  3725   3733   $as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; }
  3726         -if test "${lt_cv_path_NM+set}" = set; then :
         3734  +if ${lt_cv_path_NM+:} false; then :
  3727   3735     $as_echo_n "(cached) " >&6
  3728   3736   else
  3729   3737     if test -n "$NM"; then
  3730   3738     # Let the user override the test.
  3731   3739     lt_cv_path_NM="$NM"
  3732   3740   else
  3733   3741     lt_nm_to_check="${ac_tool_prefix}nm"
................................................................................
  3779   3787     if test -n "$ac_tool_prefix"; then
  3780   3788     for ac_prog in "dumpbin -symbols" "link -dump -symbols"
  3781   3789     do
  3782   3790       # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
  3783   3791   set dummy $ac_tool_prefix$ac_prog; ac_word=$2
  3784   3792   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  3785   3793   $as_echo_n "checking for $ac_word... " >&6; }
  3786         -if test "${ac_cv_prog_DUMPBIN+set}" = set; then :
         3794  +if ${ac_cv_prog_DUMPBIN+:} false; then :
  3787   3795     $as_echo_n "(cached) " >&6
  3788   3796   else
  3789   3797     if test -n "$DUMPBIN"; then
  3790   3798     ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test.
  3791   3799   else
  3792   3800   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  3793   3801   for as_dir in $PATH
................................................................................
  3823   3831     ac_ct_DUMPBIN=$DUMPBIN
  3824   3832     for ac_prog in "dumpbin -symbols" "link -dump -symbols"
  3825   3833   do
  3826   3834     # Extract the first word of "$ac_prog", so it can be a program name with args.
  3827   3835   set dummy $ac_prog; ac_word=$2
  3828   3836   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  3829   3837   $as_echo_n "checking for $ac_word... " >&6; }
  3830         -if test "${ac_cv_prog_ac_ct_DUMPBIN+set}" = set; then :
         3838  +if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then :
  3831   3839     $as_echo_n "(cached) " >&6
  3832   3840   else
  3833   3841     if test -n "$ac_ct_DUMPBIN"; then
  3834   3842     ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test.
  3835   3843   else
  3836   3844   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  3837   3845   for as_dir in $PATH
................................................................................
  3886   3894   
  3887   3895   
  3888   3896   
  3889   3897   
  3890   3898   
  3891   3899   { $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5
  3892   3900   $as_echo_n "checking the name lister ($NM) interface... " >&6; }
  3893         -if test "${lt_cv_nm_interface+set}" = set; then :
         3901  +if ${lt_cv_nm_interface+:} false; then :
  3894   3902     $as_echo_n "(cached) " >&6
  3895   3903   else
  3896   3904     lt_cv_nm_interface="BSD nm"
  3897   3905     echo "int some_variable = 0;" > conftest.$ac_ext
  3898         -  (eval echo "\"\$as_me:3898: $ac_compile\"" >&5)
         3906  +  (eval echo "\"\$as_me:3906: $ac_compile\"" >&5)
  3899   3907     (eval "$ac_compile" 2>conftest.err)
  3900   3908     cat conftest.err >&5
  3901         -  (eval echo "\"\$as_me:3901: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
         3909  +  (eval echo "\"\$as_me:3909: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
  3902   3910     (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
  3903   3911     cat conftest.err >&5
  3904         -  (eval echo "\"\$as_me:3904: output\"" >&5)
         3912  +  (eval echo "\"\$as_me:3912: output\"" >&5)
  3905   3913     cat conftest.out >&5
  3906   3914     if $GREP 'External.*some_variable' conftest.out > /dev/null; then
  3907   3915       lt_cv_nm_interface="MS dumpbin"
  3908   3916     fi
  3909   3917     rm -f conftest*
  3910   3918   fi
  3911   3919   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5
................................................................................
  3921   3929     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
  3922   3930   $as_echo "no, using $LN_S" >&6; }
  3923   3931   fi
  3924   3932   
  3925   3933   # find the maximum length of command line arguments
  3926   3934   { $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5
  3927   3935   $as_echo_n "checking the maximum length of command line arguments... " >&6; }
  3928         -if test "${lt_cv_sys_max_cmd_len+set}" = set; then :
         3936  +if ${lt_cv_sys_max_cmd_len+:} false; then :
  3929   3937     $as_echo_n "(cached) " >&6
  3930   3938   else
  3931   3939       i=0
  3932   3940     teststring="ABCD"
  3933   3941   
  3934   3942     case $build_os in
  3935   3943     msdosdjgpp*)
................................................................................
  4113   4121   
  4114   4122   
  4115   4123   
  4116   4124   
  4117   4125   
  4118   4126   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5
  4119   4127   $as_echo_n "checking for $LD option to reload object files... " >&6; }
  4120         -if test "${lt_cv_ld_reload_flag+set}" = set; then :
         4128  +if ${lt_cv_ld_reload_flag+:} false; then :
  4121   4129     $as_echo_n "(cached) " >&6
  4122   4130   else
  4123   4131     lt_cv_ld_reload_flag='-r'
  4124   4132   fi
  4125   4133   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5
  4126   4134   $as_echo "$lt_cv_ld_reload_flag" >&6; }
  4127   4135   reload_flag=$lt_cv_ld_reload_flag
................................................................................
  4149   4157   
  4150   4158   
  4151   4159   if test -n "$ac_tool_prefix"; then
  4152   4160     # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args.
  4153   4161   set dummy ${ac_tool_prefix}objdump; ac_word=$2
  4154   4162   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4155   4163   $as_echo_n "checking for $ac_word... " >&6; }
  4156         -if test "${ac_cv_prog_OBJDUMP+set}" = set; then :
         4164  +if ${ac_cv_prog_OBJDUMP+:} false; then :
  4157   4165     $as_echo_n "(cached) " >&6
  4158   4166   else
  4159   4167     if test -n "$OBJDUMP"; then
  4160   4168     ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test.
  4161   4169   else
  4162   4170   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4163   4171   for as_dir in $PATH
................................................................................
  4189   4197   fi
  4190   4198   if test -z "$ac_cv_prog_OBJDUMP"; then
  4191   4199     ac_ct_OBJDUMP=$OBJDUMP
  4192   4200     # Extract the first word of "objdump", so it can be a program name with args.
  4193   4201   set dummy objdump; ac_word=$2
  4194   4202   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4195   4203   $as_echo_n "checking for $ac_word... " >&6; }
  4196         -if test "${ac_cv_prog_ac_ct_OBJDUMP+set}" = set; then :
         4204  +if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then :
  4197   4205     $as_echo_n "(cached) " >&6
  4198   4206   else
  4199   4207     if test -n "$ac_ct_OBJDUMP"; then
  4200   4208     ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test.
  4201   4209   else
  4202   4210   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4203   4211   for as_dir in $PATH
................................................................................
  4248   4256   
  4249   4257   
  4250   4258   
  4251   4259   
  4252   4260   
  4253   4261   { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5
  4254   4262   $as_echo_n "checking how to recognize dependent libraries... " >&6; }
  4255         -if test "${lt_cv_deplibs_check_method+set}" = set; then :
         4263  +if ${lt_cv_deplibs_check_method+:} false; then :
  4256   4264     $as_echo_n "(cached) " >&6
  4257   4265   else
  4258   4266     lt_cv_file_magic_cmd='$MAGIC_CMD'
  4259   4267   lt_cv_file_magic_test_file=
  4260   4268   lt_cv_deplibs_check_method='unknown'
  4261   4269   # Need to set the preceding variable on all platforms that support
  4262   4270   # interlibrary dependencies.
................................................................................
  4464   4472   
  4465   4473   
  4466   4474   if test -n "$ac_tool_prefix"; then
  4467   4475     # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
  4468   4476   set dummy ${ac_tool_prefix}ar; ac_word=$2
  4469   4477   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4470   4478   $as_echo_n "checking for $ac_word... " >&6; }
  4471         -if test "${ac_cv_prog_AR+set}" = set; then :
         4479  +if ${ac_cv_prog_AR+:} false; then :
  4472   4480     $as_echo_n "(cached) " >&6
  4473   4481   else
  4474   4482     if test -n "$AR"; then
  4475   4483     ac_cv_prog_AR="$AR" # Let the user override the test.
  4476   4484   else
  4477   4485   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4478   4486   for as_dir in $PATH
................................................................................
  4504   4512   fi
  4505   4513   if test -z "$ac_cv_prog_AR"; then
  4506   4514     ac_ct_AR=$AR
  4507   4515     # Extract the first word of "ar", so it can be a program name with args.
  4508   4516   set dummy ar; ac_word=$2
  4509   4517   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4510   4518   $as_echo_n "checking for $ac_word... " >&6; }
  4511         -if test "${ac_cv_prog_ac_ct_AR+set}" = set; then :
         4519  +if ${ac_cv_prog_ac_ct_AR+:} false; then :
  4512   4520     $as_echo_n "(cached) " >&6
  4513   4521   else
  4514   4522     if test -n "$ac_ct_AR"; then
  4515   4523     ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
  4516   4524   else
  4517   4525   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4518   4526   for as_dir in $PATH
................................................................................
  4569   4577   
  4570   4578   
  4571   4579   if test -n "$ac_tool_prefix"; then
  4572   4580     # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args.
  4573   4581   set dummy ${ac_tool_prefix}strip; ac_word=$2
  4574   4582   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4575   4583   $as_echo_n "checking for $ac_word... " >&6; }
  4576         -if test "${ac_cv_prog_STRIP+set}" = set; then :
         4584  +if ${ac_cv_prog_STRIP+:} false; then :
  4577   4585     $as_echo_n "(cached) " >&6
  4578   4586   else
  4579   4587     if test -n "$STRIP"; then
  4580   4588     ac_cv_prog_STRIP="$STRIP" # Let the user override the test.
  4581   4589   else
  4582   4590   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4583   4591   for as_dir in $PATH
................................................................................
  4609   4617   fi
  4610   4618   if test -z "$ac_cv_prog_STRIP"; then
  4611   4619     ac_ct_STRIP=$STRIP
  4612   4620     # Extract the first word of "strip", so it can be a program name with args.
  4613   4621   set dummy strip; ac_word=$2
  4614   4622   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4615   4623   $as_echo_n "checking for $ac_word... " >&6; }
  4616         -if test "${ac_cv_prog_ac_ct_STRIP+set}" = set; then :
         4624  +if ${ac_cv_prog_ac_ct_STRIP+:} false; then :
  4617   4625     $as_echo_n "(cached) " >&6
  4618   4626   else
  4619   4627     if test -n "$ac_ct_STRIP"; then
  4620   4628     ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test.
  4621   4629   else
  4622   4630   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4623   4631   for as_dir in $PATH
................................................................................
  4668   4676   
  4669   4677   
  4670   4678   if test -n "$ac_tool_prefix"; then
  4671   4679     # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
  4672   4680   set dummy ${ac_tool_prefix}ranlib; ac_word=$2
  4673   4681   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4674   4682   $as_echo_n "checking for $ac_word... " >&6; }
  4675         -if test "${ac_cv_prog_RANLIB+set}" = set; then :
         4683  +if ${ac_cv_prog_RANLIB+:} false; then :
  4676   4684     $as_echo_n "(cached) " >&6
  4677   4685   else
  4678   4686     if test -n "$RANLIB"; then
  4679   4687     ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
  4680   4688   else
  4681   4689   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4682   4690   for as_dir in $PATH
................................................................................
  4708   4716   fi
  4709   4717   if test -z "$ac_cv_prog_RANLIB"; then
  4710   4718     ac_ct_RANLIB=$RANLIB
  4711   4719     # Extract the first word of "ranlib", so it can be a program name with args.
  4712   4720   set dummy ranlib; ac_word=$2
  4713   4721   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  4714   4722   $as_echo_n "checking for $ac_word... " >&6; }
  4715         -if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then :
         4723  +if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
  4716   4724     $as_echo_n "(cached) " >&6
  4717   4725   else
  4718   4726     if test -n "$ac_ct_RANLIB"; then
  4719   4727     ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
  4720   4728   else
  4721   4729   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  4722   4730   for as_dir in $PATH
................................................................................
  4825   4833   # Allow CC to be a program name with arguments.
  4826   4834   compiler=$CC
  4827   4835   
  4828   4836   
  4829   4837   # Check for command to grab the raw symbol name followed by C symbol from nm.
  4830   4838   { $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5
  4831   4839   $as_echo_n "checking command to parse $NM output from $compiler object... " >&6; }
  4832         -if test "${lt_cv_sys_global_symbol_pipe+set}" = set; then :
         4840  +if ${lt_cv_sys_global_symbol_pipe+:} false; then :
  4833   4841     $as_echo_n "(cached) " >&6
  4834   4842   else
  4835   4843   
  4836   4844   # These are sane defaults that work on at least a few old systems.
  4837   4845   # [They come from Ultrix.  What could be older than Ultrix?!! ;)]
  4838   4846   
  4839   4847   # Character class describing NM global symbol codes.
................................................................................
  5103   5111   	;;
  5104   5112       esac
  5105   5113     fi
  5106   5114     rm -rf conftest*
  5107   5115     ;;
  5108   5116   *-*-irix6*)
  5109   5117     # Find out which ABI we are using.
  5110         -  echo '#line 5110 "configure"' > conftest.$ac_ext
         5118  +  echo '#line 5118 "configure"' > conftest.$ac_ext
  5111   5119     if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
  5112   5120     (eval $ac_compile) 2>&5
  5113   5121     ac_status=$?
  5114   5122     $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  5115   5123     test $ac_status = 0; }; then
  5116   5124       if test "$lt_cv_prog_gnu_ld" = yes; then
  5117   5125         case `/usr/bin/file conftest.$ac_objext` in
................................................................................
  5197   5205   
  5198   5206   *-*-sco3.2v5*)
  5199   5207     # On SCO OpenServer 5, we need -belf to get full-featured binaries.
  5200   5208     SAVE_CFLAGS="$CFLAGS"
  5201   5209     CFLAGS="$CFLAGS -belf"
  5202   5210     { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5
  5203   5211   $as_echo_n "checking whether the C compiler needs -belf... " >&6; }
  5204         -if test "${lt_cv_cc_needs_belf+set}" = set; then :
         5212  +if ${lt_cv_cc_needs_belf+:} false; then :
  5205   5213     $as_echo_n "(cached) " >&6
  5206   5214   else
  5207   5215     ac_ext=c
  5208   5216   ac_cpp='$CPP $CPPFLAGS'
  5209   5217   ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
  5210   5218   ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
  5211   5219   ac_compiler_gnu=$ac_cv_c_compiler_gnu
................................................................................
  5273   5281     case $host_os in
  5274   5282       rhapsody* | darwin*)
  5275   5283       if test -n "$ac_tool_prefix"; then
  5276   5284     # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args.
  5277   5285   set dummy ${ac_tool_prefix}dsymutil; ac_word=$2
  5278   5286   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5279   5287   $as_echo_n "checking for $ac_word... " >&6; }
  5280         -if test "${ac_cv_prog_DSYMUTIL+set}" = set; then :
         5288  +if ${ac_cv_prog_DSYMUTIL+:} false; then :
  5281   5289     $as_echo_n "(cached) " >&6
  5282   5290   else
  5283   5291     if test -n "$DSYMUTIL"; then
  5284   5292     ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test.
  5285   5293   else
  5286   5294   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5287   5295   for as_dir in $PATH
................................................................................
  5313   5321   fi
  5314   5322   if test -z "$ac_cv_prog_DSYMUTIL"; then
  5315   5323     ac_ct_DSYMUTIL=$DSYMUTIL
  5316   5324     # Extract the first word of "dsymutil", so it can be a program name with args.
  5317   5325   set dummy dsymutil; ac_word=$2
  5318   5326   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5319   5327   $as_echo_n "checking for $ac_word... " >&6; }
  5320         -if test "${ac_cv_prog_ac_ct_DSYMUTIL+set}" = set; then :
         5328  +if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then :
  5321   5329     $as_echo_n "(cached) " >&6
  5322   5330   else
  5323   5331     if test -n "$ac_ct_DSYMUTIL"; then
  5324   5332     ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test.
  5325   5333   else
  5326   5334   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5327   5335   for as_dir in $PATH
................................................................................
  5365   5373   fi
  5366   5374   
  5367   5375       if test -n "$ac_tool_prefix"; then
  5368   5376     # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args.
  5369   5377   set dummy ${ac_tool_prefix}nmedit; ac_word=$2
  5370   5378   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5371   5379   $as_echo_n "checking for $ac_word... " >&6; }
  5372         -if test "${ac_cv_prog_NMEDIT+set}" = set; then :
         5380  +if ${ac_cv_prog_NMEDIT+:} false; then :
  5373   5381     $as_echo_n "(cached) " >&6
  5374   5382   else
  5375   5383     if test -n "$NMEDIT"; then
  5376   5384     ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test.
  5377   5385   else
  5378   5386   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5379   5387   for as_dir in $PATH
................................................................................
  5405   5413   fi
  5406   5414   if test -z "$ac_cv_prog_NMEDIT"; then
  5407   5415     ac_ct_NMEDIT=$NMEDIT
  5408   5416     # Extract the first word of "nmedit", so it can be a program name with args.
  5409   5417   set dummy nmedit; ac_word=$2
  5410   5418   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5411   5419   $as_echo_n "checking for $ac_word... " >&6; }
  5412         -if test "${ac_cv_prog_ac_ct_NMEDIT+set}" = set; then :
         5420  +if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then :
  5413   5421     $as_echo_n "(cached) " >&6
  5414   5422   else
  5415   5423     if test -n "$ac_ct_NMEDIT"; then
  5416   5424     ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test.
  5417   5425   else
  5418   5426   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5419   5427   for as_dir in $PATH
................................................................................
  5457   5465   fi
  5458   5466   
  5459   5467       if test -n "$ac_tool_prefix"; then
  5460   5468     # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args.
  5461   5469   set dummy ${ac_tool_prefix}lipo; ac_word=$2
  5462   5470   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5463   5471   $as_echo_n "checking for $ac_word... " >&6; }
  5464         -if test "${ac_cv_prog_LIPO+set}" = set; then :
         5472  +if ${ac_cv_prog_LIPO+:} false; then :
  5465   5473     $as_echo_n "(cached) " >&6
  5466   5474   else
  5467   5475     if test -n "$LIPO"; then
  5468   5476     ac_cv_prog_LIPO="$LIPO" # Let the user override the test.
  5469   5477   else
  5470   5478   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5471   5479   for as_dir in $PATH
................................................................................
  5497   5505   fi
  5498   5506   if test -z "$ac_cv_prog_LIPO"; then
  5499   5507     ac_ct_LIPO=$LIPO
  5500   5508     # Extract the first word of "lipo", so it can be a program name with args.
  5501   5509   set dummy lipo; ac_word=$2
  5502   5510   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5503   5511   $as_echo_n "checking for $ac_word... " >&6; }
  5504         -if test "${ac_cv_prog_ac_ct_LIPO+set}" = set; then :
         5512  +if ${ac_cv_prog_ac_ct_LIPO+:} false; then :
  5505   5513     $as_echo_n "(cached) " >&6
  5506   5514   else
  5507   5515     if test -n "$ac_ct_LIPO"; then
  5508   5516     ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test.
  5509   5517   else
  5510   5518   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5511   5519   for as_dir in $PATH
................................................................................
  5549   5557   fi
  5550   5558   
  5551   5559       if test -n "$ac_tool_prefix"; then
  5552   5560     # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args.
  5553   5561   set dummy ${ac_tool_prefix}otool; ac_word=$2
  5554   5562   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5555   5563   $as_echo_n "checking for $ac_word... " >&6; }
  5556         -if test "${ac_cv_prog_OTOOL+set}" = set; then :
         5564  +if ${ac_cv_prog_OTOOL+:} false; then :
  5557   5565     $as_echo_n "(cached) " >&6
  5558   5566   else
  5559   5567     if test -n "$OTOOL"; then
  5560   5568     ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test.
  5561   5569   else
  5562   5570   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5563   5571   for as_dir in $PATH
................................................................................
  5589   5597   fi
  5590   5598   if test -z "$ac_cv_prog_OTOOL"; then
  5591   5599     ac_ct_OTOOL=$OTOOL
  5592   5600     # Extract the first word of "otool", so it can be a program name with args.
  5593   5601   set dummy otool; ac_word=$2
  5594   5602   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5595   5603   $as_echo_n "checking for $ac_word... " >&6; }
  5596         -if test "${ac_cv_prog_ac_ct_OTOOL+set}" = set; then :
         5604  +if ${ac_cv_prog_ac_ct_OTOOL+:} false; then :
  5597   5605     $as_echo_n "(cached) " >&6
  5598   5606   else
  5599   5607     if test -n "$ac_ct_OTOOL"; then
  5600   5608     ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test.
  5601   5609   else
  5602   5610   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5603   5611   for as_dir in $PATH
................................................................................
  5641   5649   fi
  5642   5650   
  5643   5651       if test -n "$ac_tool_prefix"; then
  5644   5652     # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args.
  5645   5653   set dummy ${ac_tool_prefix}otool64; ac_word=$2
  5646   5654   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5647   5655   $as_echo_n "checking for $ac_word... " >&6; }
  5648         -if test "${ac_cv_prog_OTOOL64+set}" = set; then :
         5656  +if ${ac_cv_prog_OTOOL64+:} false; then :
  5649   5657     $as_echo_n "(cached) " >&6
  5650   5658   else
  5651   5659     if test -n "$OTOOL64"; then
  5652   5660     ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test.
  5653   5661   else
  5654   5662   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5655   5663   for as_dir in $PATH
................................................................................
  5681   5689   fi
  5682   5690   if test -z "$ac_cv_prog_OTOOL64"; then
  5683   5691     ac_ct_OTOOL64=$OTOOL64
  5684   5692     # Extract the first word of "otool64", so it can be a program name with args.
  5685   5693   set dummy otool64; ac_word=$2
  5686   5694   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  5687   5695   $as_echo_n "checking for $ac_word... " >&6; }
  5688         -if test "${ac_cv_prog_ac_ct_OTOOL64+set}" = set; then :
         5696  +if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then :
  5689   5697     $as_echo_n "(cached) " >&6
  5690   5698   else
  5691   5699     if test -n "$ac_ct_OTOOL64"; then
  5692   5700     ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test.
  5693   5701   else
  5694   5702   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  5695   5703   for as_dir in $PATH
................................................................................
  5756   5764   
  5757   5765   
  5758   5766   
  5759   5767   
  5760   5768   
  5761   5769       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5
  5762   5770   $as_echo_n "checking for -single_module linker flag... " >&6; }
  5763         -if test "${lt_cv_apple_cc_single_mod+set}" = set; then :
         5771  +if ${lt_cv_apple_cc_single_mod+:} false; then :
  5764   5772     $as_echo_n "(cached) " >&6
  5765   5773   else
  5766   5774     lt_cv_apple_cc_single_mod=no
  5767   5775         if test -z "${LT_MULTI_MODULE}"; then
  5768   5776   	# By default we will add the -single_module flag. You can override
  5769   5777   	# by either setting the environment variable LT_MULTI_MODULE
  5770   5778   	# non-empty at configure time, or by adding -multi_module to the
................................................................................
  5785   5793   	rm -f conftest.*
  5786   5794         fi
  5787   5795   fi
  5788   5796   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5
  5789   5797   $as_echo "$lt_cv_apple_cc_single_mod" >&6; }
  5790   5798       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5
  5791   5799   $as_echo_n "checking for -exported_symbols_list linker flag... " >&6; }
  5792         -if test "${lt_cv_ld_exported_symbols_list+set}" = set; then :
         5800  +if ${lt_cv_ld_exported_symbols_list+:} false; then :
  5793   5801     $as_echo_n "(cached) " >&6
  5794   5802   else
  5795   5803     lt_cv_ld_exported_symbols_list=no
  5796   5804         save_LDFLAGS=$LDFLAGS
  5797   5805         echo "_main" > conftest.sym
  5798   5806         LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
  5799   5807         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
................................................................................
  5862   5870   { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
  5863   5871   $as_echo_n "checking how to run the C preprocessor... " >&6; }
  5864   5872   # On Suns, sometimes $CPP names a directory.
  5865   5873   if test -n "$CPP" && test -d "$CPP"; then
  5866   5874     CPP=
  5867   5875   fi
  5868   5876   if test -z "$CPP"; then
  5869         -  if test "${ac_cv_prog_CPP+set}" = set; then :
         5877  +  if ${ac_cv_prog_CPP+:} false; then :
  5870   5878     $as_echo_n "(cached) " >&6
  5871   5879   else
  5872   5880         # Double quotes because CPP needs to be expanded
  5873   5881       for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
  5874   5882       do
  5875   5883         ac_preproc_ok=false
  5876   5884   for ac_c_preproc_warn_flag in '' yes
................................................................................
  5978   5986   rm -f conftest.i conftest.err conftest.$ac_ext
  5979   5987   if $ac_preproc_ok; then :
  5980   5988   
  5981   5989   else
  5982   5990     { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
  5983   5991   $as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  5984   5992   as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
  5985         -See \`config.log' for more details" "$LINENO" 5 ; }
         5993  +See \`config.log' for more details" "$LINENO" 5; }
  5986   5994   fi
  5987   5995   
  5988   5996   ac_ext=c
  5989   5997   ac_cpp='$CPP $CPPFLAGS'
  5990   5998   ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
  5991   5999   ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
  5992   6000   ac_compiler_gnu=$ac_cv_c_compiler_gnu
  5993   6001   
  5994   6002   
  5995   6003   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
  5996   6004   $as_echo_n "checking for ANSI C header files... " >&6; }
  5997         -if test "${ac_cv_header_stdc+set}" = set; then :
         6005  +if ${ac_cv_header_stdc+:} false; then :
  5998   6006     $as_echo_n "(cached) " >&6
  5999   6007   else
  6000   6008     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  6001   6009   /* end confdefs.h.  */
  6002   6010   #include <stdlib.h>
  6003   6011   #include <stdarg.h>
  6004   6012   #include <string.h>
................................................................................
  6121   6129   done
  6122   6130   
  6123   6131   
  6124   6132   for ac_header in dlfcn.h
  6125   6133   do :
  6126   6134     ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default
  6127   6135   "
  6128         -if test "x$ac_cv_header_dlfcn_h" = x""yes; then :
         6136  +if test "x$ac_cv_header_dlfcn_h" = xyes; then :
  6129   6137     cat >>confdefs.h <<_ACEOF
  6130   6138   #define HAVE_DLFCN_H 1
  6131   6139   _ACEOF
  6132   6140   
  6133   6141   fi
  6134   6142   
  6135   6143   done
................................................................................
  6305   6313   
  6306   6314   if test -n "${ZSH_VERSION+set}" ; then
  6307   6315      setopt NO_GLOB_SUBST
  6308   6316   fi
  6309   6317   
  6310   6318   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5
  6311   6319   $as_echo_n "checking for objdir... " >&6; }
  6312         -if test "${lt_cv_objdir+set}" = set; then :
         6320  +if ${lt_cv_objdir+:} false; then :
  6313   6321     $as_echo_n "(cached) " >&6
  6314   6322   else
  6315   6323     rm -f .libs 2>/dev/null
  6316   6324   mkdir .libs 2>/dev/null
  6317   6325   if test -d .libs; then
  6318   6326     lt_cv_objdir=.libs
  6319   6327   else
................................................................................
  6413   6421   # Only perform the check for file, if the check method requires it
  6414   6422   test -z "$MAGIC_CMD" && MAGIC_CMD=file
  6415   6423   case $deplibs_check_method in
  6416   6424   file_magic*)
  6417   6425     if test "$file_magic_cmd" = '$MAGIC_CMD'; then
  6418   6426       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5
  6419   6427   $as_echo_n "checking for ${ac_tool_prefix}file... " >&6; }
  6420         -if test "${lt_cv_path_MAGIC_CMD+set}" = set; then :
         6428  +if ${lt_cv_path_MAGIC_CMD+:} false; then :
  6421   6429     $as_echo_n "(cached) " >&6
  6422   6430   else
  6423   6431     case $MAGIC_CMD in
  6424   6432   [\\/*] |  ?:[\\/]*)
  6425   6433     lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
  6426   6434     ;;
  6427   6435   *)
................................................................................
  6479   6487   
  6480   6488   
  6481   6489   
  6482   6490   if test -z "$lt_cv_path_MAGIC_CMD"; then
  6483   6491     if test -n "$ac_tool_prefix"; then
  6484   6492       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5
  6485   6493   $as_echo_n "checking for file... " >&6; }
  6486         -if test "${lt_cv_path_MAGIC_CMD+set}" = set; then :
         6494  +if ${lt_cv_path_MAGIC_CMD+:} false; then :
  6487   6495     $as_echo_n "(cached) " >&6
  6488   6496   else
  6489   6497     case $MAGIC_CMD in
  6490   6498   [\\/*] |  ?:[\\/]*)
  6491   6499     lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
  6492   6500     ;;
  6493   6501   *)
................................................................................
  6612   6620   lt_prog_compiler_no_builtin_flag=
  6613   6621   
  6614   6622   if test "$GCC" = yes; then
  6615   6623     lt_prog_compiler_no_builtin_flag=' -fno-builtin'
  6616   6624   
  6617   6625     { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
  6618   6626   $as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; }
  6619         -if test "${lt_cv_prog_compiler_rtti_exceptions+set}" = set; then :
         6627  +if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then :
  6620   6628     $as_echo_n "(cached) " >&6
  6621   6629   else
  6622   6630     lt_cv_prog_compiler_rtti_exceptions=no
  6623   6631      ac_outfile=conftest.$ac_objext
  6624   6632      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
  6625   6633      lt_compiler_flag="-fno-rtti -fno-exceptions"
  6626   6634      # Insert the option either (1) after the last *FLAGS variable, or
................................................................................
  6628   6636      # Note that $ac_compile itself does not contain backslashes and begins
  6629   6637      # with a dollar sign (not a hyphen), so the echo should work correctly.
  6630   6638      # The option is referenced via a variable to avoid confusing sed.
  6631   6639      lt_compile=`echo "$ac_compile" | $SED \
  6632   6640      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  6633   6641      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  6634   6642      -e 's:$: $lt_compiler_flag:'`
  6635         -   (eval echo "\"\$as_me:6635: $lt_compile\"" >&5)
         6643  +   (eval echo "\"\$as_me:6643: $lt_compile\"" >&5)
  6636   6644      (eval "$lt_compile" 2>conftest.err)
  6637   6645      ac_status=$?
  6638   6646      cat conftest.err >&5
  6639         -   echo "$as_me:6639: \$? = $ac_status" >&5
         6647  +   echo "$as_me:6647: \$? = $ac_status" >&5
  6640   6648      if (exit $ac_status) && test -s "$ac_outfile"; then
  6641   6649        # The compiler can only warn and ignore the option if not recognized
  6642   6650        # So say no if there are warnings other than the usual output.
  6643   6651        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  6644   6652        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  6645   6653        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  6646   6654          lt_cv_prog_compiler_rtti_exceptions=yes
................................................................................
  6951   6959   
  6952   6960   #
  6953   6961   # Check to make sure the PIC flag actually works.
  6954   6962   #
  6955   6963   if test -n "$lt_prog_compiler_pic"; then
  6956   6964     { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5
  6957   6965   $as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; }
  6958         -if test "${lt_cv_prog_compiler_pic_works+set}" = set; then :
         6966  +if ${lt_cv_prog_compiler_pic_works+:} false; then :
  6959   6967     $as_echo_n "(cached) " >&6
  6960   6968   else
  6961   6969     lt_cv_prog_compiler_pic_works=no
  6962   6970      ac_outfile=conftest.$ac_objext
  6963   6971      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
  6964   6972      lt_compiler_flag="$lt_prog_compiler_pic -DPIC"
  6965   6973      # Insert the option either (1) after the last *FLAGS variable, or
................................................................................
  6967   6975      # Note that $ac_compile itself does not contain backslashes and begins
  6968   6976      # with a dollar sign (not a hyphen), so the echo should work correctly.
  6969   6977      # The option is referenced via a variable to avoid confusing sed.
  6970   6978      lt_compile=`echo "$ac_compile" | $SED \
  6971   6979      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  6972   6980      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  6973   6981      -e 's:$: $lt_compiler_flag:'`
  6974         -   (eval echo "\"\$as_me:6974: $lt_compile\"" >&5)
         6982  +   (eval echo "\"\$as_me:6982: $lt_compile\"" >&5)
  6975   6983      (eval "$lt_compile" 2>conftest.err)
  6976   6984      ac_status=$?
  6977   6985      cat conftest.err >&5
  6978         -   echo "$as_me:6978: \$? = $ac_status" >&5
         6986  +   echo "$as_me:6986: \$? = $ac_status" >&5
  6979   6987      if (exit $ac_status) && test -s "$ac_outfile"; then
  6980   6988        # The compiler can only warn and ignore the option if not recognized
  6981   6989        # So say no if there are warnings other than the usual output.
  6982   6990        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
  6983   6991        $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
  6984   6992        if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
  6985   6993          lt_cv_prog_compiler_pic_works=yes
................................................................................
  7010   7018   
  7011   7019   #
  7012   7020   # Check to make sure the static flag actually works.
  7013   7021   #
  7014   7022   wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\"
  7015   7023   { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5
  7016   7024   $as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; }
  7017         -if test "${lt_cv_prog_compiler_static_works+set}" = set; then :
         7025  +if ${lt_cv_prog_compiler_static_works+:} false; then :
  7018   7026     $as_echo_n "(cached) " >&6
  7019   7027   else
  7020   7028     lt_cv_prog_compiler_static_works=no
  7021   7029      save_LDFLAGS="$LDFLAGS"
  7022   7030      LDFLAGS="$LDFLAGS $lt_tmp_static_flag"
  7023   7031      echo "$lt_simple_link_test_code" > conftest.$ac_ext
  7024   7032      if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
................................................................................
  7053   7061   
  7054   7062   
  7055   7063   
  7056   7064   
  7057   7065   
  7058   7066     { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
  7059   7067   $as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
  7060         -if test "${lt_cv_prog_compiler_c_o+set}" = set; then :
         7068  +if ${lt_cv_prog_compiler_c_o+:} false; then :
  7061   7069     $as_echo_n "(cached) " >&6
  7062   7070   else
  7063   7071     lt_cv_prog_compiler_c_o=no
  7064   7072      $RM -r conftest 2>/dev/null
  7065   7073      mkdir conftest
  7066   7074      cd conftest
  7067   7075      mkdir out
................................................................................
  7072   7080      # (2) before a word containing "conftest.", or (3) at the end.
  7073   7081      # Note that $ac_compile itself does not contain backslashes and begins
  7074   7082      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7075   7083      lt_compile=`echo "$ac_compile" | $SED \
  7076   7084      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7077   7085      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7078   7086      -e 's:$: $lt_compiler_flag:'`
  7079         -   (eval echo "\"\$as_me:7079: $lt_compile\"" >&5)
         7087  +   (eval echo "\"\$as_me:7087: $lt_compile\"" >&5)
  7080   7088      (eval "$lt_compile" 2>out/conftest.err)
  7081   7089      ac_status=$?
  7082   7090      cat out/conftest.err >&5
  7083         -   echo "$as_me:7083: \$? = $ac_status" >&5
         7091  +   echo "$as_me:7091: \$? = $ac_status" >&5
  7084   7092      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7085   7093      then
  7086   7094        # The compiler can only warn and ignore the option if not recognized
  7087   7095        # So say no if there are warnings
  7088   7096        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7089   7097        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7090   7098        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
  7108   7116   
  7109   7117   
  7110   7118   
  7111   7119   
  7112   7120   
  7113   7121     { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5
  7114   7122   $as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; }
  7115         -if test "${lt_cv_prog_compiler_c_o+set}" = set; then :
         7123  +if ${lt_cv_prog_compiler_c_o+:} false; then :
  7116   7124     $as_echo_n "(cached) " >&6
  7117   7125   else
  7118   7126     lt_cv_prog_compiler_c_o=no
  7119   7127      $RM -r conftest 2>/dev/null
  7120   7128      mkdir conftest
  7121   7129      cd conftest
  7122   7130      mkdir out
................................................................................
  7127   7135      # (2) before a word containing "conftest.", or (3) at the end.
  7128   7136      # Note that $ac_compile itself does not contain backslashes and begins
  7129   7137      # with a dollar sign (not a hyphen), so the echo should work correctly.
  7130   7138      lt_compile=`echo "$ac_compile" | $SED \
  7131   7139      -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
  7132   7140      -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
  7133   7141      -e 's:$: $lt_compiler_flag:'`
  7134         -   (eval echo "\"\$as_me:7134: $lt_compile\"" >&5)
         7142  +   (eval echo "\"\$as_me:7142: $lt_compile\"" >&5)
  7135   7143      (eval "$lt_compile" 2>out/conftest.err)
  7136   7144      ac_status=$?
  7137   7145      cat out/conftest.err >&5
  7138         -   echo "$as_me:7138: \$? = $ac_status" >&5
         7146  +   echo "$as_me:7146: \$? = $ac_status" >&5
  7139   7147      if (exit $ac_status) && test -s out/conftest2.$ac_objext
  7140   7148      then
  7141   7149        # The compiler can only warn and ignore the option if not recognized
  7142   7150        # So say no if there are warnings
  7143   7151        $ECHO "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
  7144   7152        $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
  7145   7153        if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
................................................................................
  9249   9257       lt_cv_dlopen_libs=
  9250   9258       ;;
  9251   9259   
  9252   9260     darwin*)
  9253   9261     # if libdl is installed we need to link against it
  9254   9262       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
  9255   9263   $as_echo_n "checking for dlopen in -ldl... " >&6; }
  9256         -if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
         9264  +if ${ac_cv_lib_dl_dlopen+:} false; then :
  9257   9265     $as_echo_n "(cached) " >&6
  9258   9266   else
  9259   9267     ac_check_lib_save_LIBS=$LIBS
  9260   9268   LIBS="-ldl  $LIBS"
  9261   9269   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  9262   9270   /* end confdefs.h.  */
  9263   9271   
................................................................................
  9283   9291   fi
  9284   9292   rm -f core conftest.err conftest.$ac_objext \
  9285   9293       conftest$ac_exeext conftest.$ac_ext
  9286   9294   LIBS=$ac_check_lib_save_LIBS
  9287   9295   fi
  9288   9296   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
  9289   9297   $as_echo "$ac_cv_lib_dl_dlopen" >&6; }
  9290         -if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
         9298  +if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
  9291   9299     lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
  9292   9300   else
  9293   9301   
  9294   9302       lt_cv_dlopen="dyld"
  9295   9303       lt_cv_dlopen_libs=
  9296   9304       lt_cv_dlopen_self=yes
  9297   9305   
  9298   9306   fi
  9299   9307   
  9300   9308       ;;
  9301   9309   
  9302   9310     *)
  9303   9311       ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load"
  9304         -if test "x$ac_cv_func_shl_load" = x""yes; then :
         9312  +if test "x$ac_cv_func_shl_load" = xyes; then :
  9305   9313     lt_cv_dlopen="shl_load"
  9306   9314   else
  9307   9315     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
  9308   9316   $as_echo_n "checking for shl_load in -ldld... " >&6; }
  9309         -if test "${ac_cv_lib_dld_shl_load+set}" = set; then :
         9317  +if ${ac_cv_lib_dld_shl_load+:} false; then :
  9310   9318     $as_echo_n "(cached) " >&6
  9311   9319   else
  9312   9320     ac_check_lib_save_LIBS=$LIBS
  9313   9321   LIBS="-ldld  $LIBS"
  9314   9322   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  9315   9323   /* end confdefs.h.  */
  9316   9324   
................................................................................
  9336   9344   fi
  9337   9345   rm -f core conftest.err conftest.$ac_objext \
  9338   9346       conftest$ac_exeext conftest.$ac_ext
  9339   9347   LIBS=$ac_check_lib_save_LIBS
  9340   9348   fi
  9341   9349   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
  9342   9350   $as_echo "$ac_cv_lib_dld_shl_load" >&6; }
  9343         -if test "x$ac_cv_lib_dld_shl_load" = x""yes; then :
         9351  +if test "x$ac_cv_lib_dld_shl_load" = xyes; then :
  9344   9352     lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"
  9345   9353   else
  9346   9354     ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen"
  9347         -if test "x$ac_cv_func_dlopen" = x""yes; then :
         9355  +if test "x$ac_cv_func_dlopen" = xyes; then :
  9348   9356     lt_cv_dlopen="dlopen"
  9349   9357   else
  9350   9358     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5
  9351   9359   $as_echo_n "checking for dlopen in -ldl... " >&6; }
  9352         -if test "${ac_cv_lib_dl_dlopen+set}" = set; then :
         9360  +if ${ac_cv_lib_dl_dlopen+:} false; then :
  9353   9361     $as_echo_n "(cached) " >&6
  9354   9362   else
  9355   9363     ac_check_lib_save_LIBS=$LIBS
  9356   9364   LIBS="-ldl  $LIBS"
  9357   9365   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  9358   9366   /* end confdefs.h.  */
  9359   9367   
................................................................................
  9379   9387   fi
  9380   9388   rm -f core conftest.err conftest.$ac_objext \
  9381   9389       conftest$ac_exeext conftest.$ac_ext
  9382   9390   LIBS=$ac_check_lib_save_LIBS
  9383   9391   fi
  9384   9392   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5
  9385   9393   $as_echo "$ac_cv_lib_dl_dlopen" >&6; }
  9386         -if test "x$ac_cv_lib_dl_dlopen" = x""yes; then :
         9394  +if test "x$ac_cv_lib_dl_dlopen" = xyes; then :
  9387   9395     lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
  9388   9396   else
  9389   9397     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5
  9390   9398   $as_echo_n "checking for dlopen in -lsvld... " >&6; }
  9391         -if test "${ac_cv_lib_svld_dlopen+set}" = set; then :
         9399  +if ${ac_cv_lib_svld_dlopen+:} false; then :
  9392   9400     $as_echo_n "(cached) " >&6
  9393   9401   else
  9394   9402     ac_check_lib_save_LIBS=$LIBS
  9395   9403   LIBS="-lsvld  $LIBS"
  9396   9404   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  9397   9405   /* end confdefs.h.  */
  9398   9406   
................................................................................
  9418   9426   fi
  9419   9427   rm -f core conftest.err conftest.$ac_objext \
  9420   9428       conftest$ac_exeext conftest.$ac_ext
  9421   9429   LIBS=$ac_check_lib_save_LIBS
  9422   9430   fi
  9423   9431   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5
  9424   9432   $as_echo "$ac_cv_lib_svld_dlopen" >&6; }
  9425         -if test "x$ac_cv_lib_svld_dlopen" = x""yes; then :
         9433  +if test "x$ac_cv_lib_svld_dlopen" = xyes; then :
  9426   9434     lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
  9427   9435   else
  9428   9436     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5
  9429   9437   $as_echo_n "checking for dld_link in -ldld... " >&6; }
  9430         -if test "${ac_cv_lib_dld_dld_link+set}" = set; then :
         9438  +if ${ac_cv_lib_dld_dld_link+:} false; then :
  9431   9439     $as_echo_n "(cached) " >&6
  9432   9440   else
  9433   9441     ac_check_lib_save_LIBS=$LIBS
  9434   9442   LIBS="-ldld  $LIBS"
  9435   9443   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  9436   9444   /* end confdefs.h.  */
  9437   9445   
................................................................................
  9457   9465   fi
  9458   9466   rm -f core conftest.err conftest.$ac_objext \
  9459   9467       conftest$ac_exeext conftest.$ac_ext
  9460   9468   LIBS=$ac_check_lib_save_LIBS
  9461   9469   fi
  9462   9470   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5
  9463   9471   $as_echo "$ac_cv_lib_dld_dld_link" >&6; }
  9464         -if test "x$ac_cv_lib_dld_dld_link" = x""yes; then :
         9472  +if test "x$ac_cv_lib_dld_dld_link" = xyes; then :
  9465   9473     lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"
  9466   9474   fi
  9467   9475   
  9468   9476   
  9469   9477   fi
  9470   9478   
  9471   9479   
................................................................................
  9498   9506       wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
  9499   9507   
  9500   9508       save_LIBS="$LIBS"
  9501   9509       LIBS="$lt_cv_dlopen_libs $LIBS"
  9502   9510   
  9503   9511       { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5
  9504   9512   $as_echo_n "checking whether a program can dlopen itself... " >&6; }
  9505         -if test "${lt_cv_dlopen_self+set}" = set; then :
         9513  +if ${lt_cv_dlopen_self+:} false; then :
  9506   9514     $as_echo_n "(cached) " >&6
  9507   9515   else
  9508   9516     	  if test "$cross_compiling" = yes; then :
  9509   9517     lt_cv_dlopen_self=cross
  9510   9518   else
  9511   9519     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
  9512   9520     lt_status=$lt_dlunknown
  9513   9521     cat > conftest.$ac_ext <<_LT_EOF
  9514         -#line 9514 "configure"
         9522  +#line 9522 "configure"
  9515   9523   #include "confdefs.h"
  9516   9524   
  9517   9525   #if HAVE_DLFCN_H
  9518   9526   #include <dlfcn.h>
  9519   9527   #endif
  9520   9528   
  9521   9529   #include <stdio.h>
................................................................................
  9594   9602   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5
  9595   9603   $as_echo "$lt_cv_dlopen_self" >&6; }
  9596   9604   
  9597   9605       if test "x$lt_cv_dlopen_self" = xyes; then
  9598   9606         wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
  9599   9607         { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5
  9600   9608   $as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; }
  9601         -if test "${lt_cv_dlopen_self_static+set}" = set; then :
         9609  +if ${lt_cv_dlopen_self_static+:} false; then :
  9602   9610     $as_echo_n "(cached) " >&6
  9603   9611   else
  9604   9612     	  if test "$cross_compiling" = yes; then :
  9605   9613     lt_cv_dlopen_self_static=cross
  9606   9614   else
  9607   9615     lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
  9608   9616     lt_status=$lt_dlunknown
  9609   9617     cat > conftest.$ac_ext <<_LT_EOF
  9610         -#line 9610 "configure"
         9618  +#line 9618 "configure"
  9611   9619   #include "confdefs.h"
  9612   9620   
  9613   9621   #if HAVE_DLFCN_H
  9614   9622   #include <dlfcn.h>
  9615   9623   #endif
  9616   9624   
  9617   9625   #include <stdio.h>
................................................................................
  9847   9855   # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
  9848   9856   # OS/2's system install, which has a completely different semantic
  9849   9857   # ./install, which can be erroneously created by make from ./install.sh.
  9850   9858   # Reject install programs that cannot install multiple files.
  9851   9859   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
  9852   9860   $as_echo_n "checking for a BSD-compatible install... " >&6; }
  9853   9861   if test -z "$INSTALL"; then
  9854         -if test "${ac_cv_path_install+set}" = set; then :
         9862  +if ${ac_cv_path_install+:} false; then :
  9855   9863     $as_echo_n "(cached) " >&6
  9856   9864   else
  9857   9865     as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  9858   9866   for as_dir in $PATH
  9859   9867   do
  9860   9868     IFS=$as_save_IFS
  9861   9869     test -z "$as_dir" && as_dir=.
................................................................................
  9929   9937   
  9930   9938   for ac_prog in gawk mawk nawk awk
  9931   9939   do
  9932   9940     # Extract the first word of "$ac_prog", so it can be a program name with args.
  9933   9941   set dummy $ac_prog; ac_word=$2
  9934   9942   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
  9935   9943   $as_echo_n "checking for $ac_word... " >&6; }
  9936         -if test "${ac_cv_prog_AWK+set}" = set; then :
         9944  +if ${ac_cv_prog_AWK+:} false; then :
  9937   9945     $as_echo_n "(cached) " >&6
  9938   9946   else
  9939   9947     if test -n "$AWK"; then
  9940   9948     ac_cv_prog_AWK="$AWK" # Let the user override the test.
  9941   9949   else
  9942   9950   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
  9943   9951   for as_dir in $PATH
................................................................................
  9978   9986     enableval=$enable_largefile;
  9979   9987   fi
  9980   9988   
  9981   9989   if test "$enable_largefile" != no; then
  9982   9990   
  9983   9991     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for special C compiler options needed for large files" >&5
  9984   9992   $as_echo_n "checking for special C compiler options needed for large files... " >&6; }
  9985         -if test "${ac_cv_sys_largefile_CC+set}" = set; then :
         9993  +if ${ac_cv_sys_largefile_CC+:} false; then :
  9986   9994     $as_echo_n "(cached) " >&6
  9987   9995   else
  9988   9996     ac_cv_sys_largefile_CC=no
  9989   9997        if test "$GCC" != yes; then
  9990   9998          ac_save_CC=$CC
  9991   9999          while :; do
  9992  10000   	 # IRIX 6.2 and later do not support large files by default,
................................................................................
 10029  10037   $as_echo "$ac_cv_sys_largefile_CC" >&6; }
 10030  10038     if test "$ac_cv_sys_largefile_CC" != no; then
 10031  10039       CC=$CC$ac_cv_sys_largefile_CC
 10032  10040     fi
 10033  10041   
 10034  10042     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FILE_OFFSET_BITS value needed for large files" >&5
 10035  10043   $as_echo_n "checking for _FILE_OFFSET_BITS value needed for large files... " >&6; }
 10036         -if test "${ac_cv_sys_file_offset_bits+set}" = set; then :
        10044  +if ${ac_cv_sys_file_offset_bits+:} false; then :
 10037  10045     $as_echo_n "(cached) " >&6
 10038  10046   else
 10039  10047     while :; do
 10040  10048     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 10041  10049   /* end confdefs.h.  */
 10042  10050   #include <sys/types.h>
 10043  10051    /* Check that off_t can represent 2**63 - 1 correctly.
................................................................................
 10098  10106   _ACEOF
 10099  10107   ;;
 10100  10108   esac
 10101  10109   rm -rf conftest*
 10102  10110     if test $ac_cv_sys_file_offset_bits = unknown; then
 10103  10111       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _LARGE_FILES value needed for large files" >&5
 10104  10112   $as_echo_n "checking for _LARGE_FILES value needed for large files... " >&6; }
 10105         -if test "${ac_cv_sys_large_files+set}" = set; then :
        10113  +if ${ac_cv_sys_large_files+:} false; then :
 10106  10114     $as_echo_n "(cached) " >&6
 10107  10115   else
 10108  10116     while :; do
 10109  10117     cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 10110  10118   /* end confdefs.h.  */
 10111  10119   #include <sys/types.h>
 10112  10120    /* Check that off_t can represent 2**63 - 1 correctly.
................................................................................
 10171  10179     fi
 10172  10180   fi
 10173  10181   
 10174  10182   
 10175  10183   #########
 10176  10184   # Check for needed/wanted data types
 10177  10185   ac_fn_c_check_type "$LINENO" "int8_t" "ac_cv_type_int8_t" "$ac_includes_default"
 10178         -if test "x$ac_cv_type_int8_t" = x""yes; then :
        10186  +if test "x$ac_cv_type_int8_t" = xyes; then :
 10179  10187   
 10180  10188   cat >>confdefs.h <<_ACEOF
 10181  10189   #define HAVE_INT8_T 1
 10182  10190   _ACEOF
 10183  10191   
 10184  10192   
 10185  10193   fi
 10186  10194   ac_fn_c_check_type "$LINENO" "int16_t" "ac_cv_type_int16_t" "$ac_includes_default"
 10187         -if test "x$ac_cv_type_int16_t" = x""yes; then :
        10195  +if test "x$ac_cv_type_int16_t" = xyes; then :
 10188  10196   
 10189  10197   cat >>confdefs.h <<_ACEOF
 10190  10198   #define HAVE_INT16_T 1
 10191  10199   _ACEOF
 10192  10200   
 10193  10201   
 10194  10202   fi
 10195  10203   ac_fn_c_check_type "$LINENO" "int32_t" "ac_cv_type_int32_t" "$ac_includes_default"
 10196         -if test "x$ac_cv_type_int32_t" = x""yes; then :
        10204  +if test "x$ac_cv_type_int32_t" = xyes; then :
 10197  10205   
 10198  10206   cat >>confdefs.h <<_ACEOF
 10199  10207   #define HAVE_INT32_T 1
 10200  10208   _ACEOF
 10201  10209   
 10202  10210   
 10203  10211   fi
 10204  10212   ac_fn_c_check_type "$LINENO" "int64_t" "ac_cv_type_int64_t" "$ac_includes_default"
 10205         -if test "x$ac_cv_type_int64_t" = x""yes; then :
        10213  +if test "x$ac_cv_type_int64_t" = xyes; then :
 10206  10214   
 10207  10215   cat >>confdefs.h <<_ACEOF
 10208  10216   #define HAVE_INT64_T 1
 10209  10217   _ACEOF
 10210  10218   
 10211  10219   
 10212  10220   fi
 10213  10221   ac_fn_c_check_type "$LINENO" "intptr_t" "ac_cv_type_intptr_t" "$ac_includes_default"
 10214         -if test "x$ac_cv_type_intptr_t" = x""yes; then :
        10222  +if test "x$ac_cv_type_intptr_t" = xyes; then :
 10215  10223   
 10216  10224   cat >>confdefs.h <<_ACEOF
 10217  10225   #define HAVE_INTPTR_T 1
 10218  10226   _ACEOF
 10219  10227   
 10220  10228   
 10221  10229   fi
 10222  10230   ac_fn_c_check_type "$LINENO" "uint8_t" "ac_cv_type_uint8_t" "$ac_includes_default"
 10223         -if test "x$ac_cv_type_uint8_t" = x""yes; then :
        10231  +if test "x$ac_cv_type_uint8_t" = xyes; then :
 10224  10232   
 10225  10233   cat >>confdefs.h <<_ACEOF
 10226  10234   #define HAVE_UINT8_T 1
 10227  10235   _ACEOF
 10228  10236   
 10229  10237   
 10230  10238   fi
 10231  10239   ac_fn_c_check_type "$LINENO" "uint16_t" "ac_cv_type_uint16_t" "$ac_includes_default"
 10232         -if test "x$ac_cv_type_uint16_t" = x""yes; then :
        10240  +if test "x$ac_cv_type_uint16_t" = xyes; then :
 10233  10241   
 10234  10242   cat >>confdefs.h <<_ACEOF
 10235  10243   #define HAVE_UINT16_T 1
 10236  10244   _ACEOF
 10237  10245   
 10238  10246   
 10239  10247   fi
 10240  10248   ac_fn_c_check_type "$LINENO" "uint32_t" "ac_cv_type_uint32_t" "$ac_includes_default"
 10241         -if test "x$ac_cv_type_uint32_t" = x""yes; then :
        10249  +if test "x$ac_cv_type_uint32_t" = xyes; then :
 10242  10250   
 10243  10251   cat >>confdefs.h <<_ACEOF
 10244  10252   #define HAVE_UINT32_T 1
 10245  10253   _ACEOF
 10246  10254   
 10247  10255   
 10248  10256   fi
 10249  10257   ac_fn_c_check_type "$LINENO" "uint64_t" "ac_cv_type_uint64_t" "$ac_includes_default"
 10250         -if test "x$ac_cv_type_uint64_t" = x""yes; then :
        10258  +if test "x$ac_cv_type_uint64_t" = xyes; then :
 10251  10259   
 10252  10260   cat >>confdefs.h <<_ACEOF
 10253  10261   #define HAVE_UINT64_T 1
 10254  10262   _ACEOF
 10255  10263   
 10256  10264   
 10257  10265   fi
 10258  10266   ac_fn_c_check_type "$LINENO" "uintptr_t" "ac_cv_type_uintptr_t" "$ac_includes_default"
 10259         -if test "x$ac_cv_type_uintptr_t" = x""yes; then :
        10267  +if test "x$ac_cv_type_uintptr_t" = xyes; then :
 10260  10268   
 10261  10269   cat >>confdefs.h <<_ACEOF
 10262  10270   #define HAVE_UINTPTR_T 1
 10263  10271   _ACEOF
 10264  10272   
 10265  10273   
 10266  10274   fi
................................................................................
 10281  10289   
 10282  10290   done
 10283  10291   
 10284  10292   
 10285  10293   #########
 10286  10294   # Figure out whether or not we have these functions
 10287  10295   #
 10288         -for ac_func in usleep fdatasync localtime_r gmtime_r localtime_s utime
        10296  +for ac_func in usleep fdatasync localtime_r gmtime_r localtime_s utime malloc_usable_size
 10289  10297   do :
 10290  10298     as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 10291  10299   ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
 10292  10300   if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
 10293  10301     cat >>confdefs.h <<_ACEOF
 10294  10302   #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 10295  10303   _ACEOF
................................................................................
 10310  10318   #
 10311  10319   for ac_prog in tclsh8.5 tclsh
 10312  10320   do
 10313  10321     # Extract the first word of "$ac_prog", so it can be a program name with args.
 10314  10322   set dummy $ac_prog; ac_word=$2
 10315  10323   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 10316  10324   $as_echo_n "checking for $ac_word... " >&6; }
 10317         -if test "${ac_cv_prog_TCLSH_CMD+set}" = set; then :
        10325  +if ${ac_cv_prog_TCLSH_CMD+:} false; then :
 10318  10326     $as_echo_n "(cached) " >&6
 10319  10327   else
 10320  10328     if test -n "$TCLSH_CMD"; then
 10321  10329     ac_cv_prog_TCLSH_CMD="$TCLSH_CMD" # Let the user override the test.
 10322  10330   else
 10323  10331   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 10324  10332   for as_dir in $PATH
................................................................................
 10444  10452   	if test "${BUILD_CC+set}" != set; then
 10445  10453   		for ac_prog in gcc cc cl
 10446  10454   do
 10447  10455     # Extract the first word of "$ac_prog", so it can be a program name with args.
 10448  10456   set dummy $ac_prog; ac_word=$2
 10449  10457   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 10450  10458   $as_echo_n "checking for $ac_word... " >&6; }
 10451         -if test "${ac_cv_prog_BUILD_CC+set}" = set; then :
        10459  +if ${ac_cv_prog_BUILD_CC+:} false; then :
 10452  10460     $as_echo_n "(cached) " >&6
 10453  10461   else
 10454  10462     if test -n "$BUILD_CC"; then
 10455  10463     ac_cv_prog_BUILD_CC="$BUILD_CC" # Let the user override the test.
 10456  10464   else
 10457  10465   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 10458  10466   for as_dir in $PATH
................................................................................
 10513  10521   $as_echo "yes" >&6; }
 10514  10522   fi
 10515  10523   
 10516  10524   
 10517  10525   if test "$SQLITE_THREADSAFE" = "1"; then
 10518  10526     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing pthread_create" >&5
 10519  10527   $as_echo_n "checking for library containing pthread_create... " >&6; }
 10520         -if test "${ac_cv_search_pthread_create+set}" = set; then :
        10528  +if ${ac_cv_search_pthread_create+:} false; then :
 10521  10529     $as_echo_n "(cached) " >&6
 10522  10530   else
 10523  10531     ac_func_search_save_LIBS=$LIBS
 10524  10532   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 10525  10533   /* end confdefs.h.  */
 10526  10534   
 10527  10535   /* Override any GCC internal prototype to avoid an error.
................................................................................
 10547  10555       LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
 10548  10556     fi
 10549  10557     if ac_fn_c_try_link "$LINENO"; then :
 10550  10558     ac_cv_search_pthread_create=$ac_res
 10551  10559   fi
 10552  10560   rm -f core conftest.err conftest.$ac_objext \
 10553  10561       conftest$ac_exeext
 10554         -  if test "${ac_cv_search_pthread_create+set}" = set; then :
        10562  +  if ${ac_cv_search_pthread_create+:} false; then :
 10555  10563     break
 10556  10564   fi
 10557  10565   done
 10558         -if test "${ac_cv_search_pthread_create+set}" = set; then :
        10566  +if ${ac_cv_search_pthread_create+:} false; then :
 10559  10567   
 10560  10568   else
 10561  10569     ac_cv_search_pthread_create=no
 10562  10570   fi
 10563  10571   rm conftest.$ac_ext
 10564  10572   LIBS=$ac_func_search_save_LIBS
 10565  10573   fi
................................................................................
 10741  10749   # Check whether --with-tcl was given.
 10742  10750   if test "${with_tcl+set}" = set; then :
 10743  10751     withval=$with_tcl; with_tclconfig=${withval}
 10744  10752   fi
 10745  10753   
 10746  10754     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5
 10747  10755   $as_echo_n "checking for Tcl configuration... " >&6; }
 10748         -  if test "${ac_cv_c_tclconfig+set}" = set; then :
        10756  +  if ${ac_cv_c_tclconfig+:} false; then :
 10749  10757     $as_echo_n "(cached) " >&6
 10750  10758   else
 10751  10759   
 10752  10760       # First check to see if --with-tcl was specified.
 10753  10761       if test x"${with_tclconfig}" != x ; then
 10754  10762         if test -f "${with_tclconfig}/tclConfig.sh" ; then
 10755  10763           ac_cv_c_tclconfig=`(cd ${with_tclconfig}; pwd)`
................................................................................
 10925  10933   fi
 10926  10934   
 10927  10935   	if test "x$with_readline_lib" = xauto; then
 10928  10936   		save_LIBS="$LIBS"
 10929  10937   		LIBS=""
 10930  10938   		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing tgetent" >&5
 10931  10939   $as_echo_n "checking for library containing tgetent... " >&6; }
 10932         -if test "${ac_cv_search_tgetent+set}" = set; then :
        10940  +if ${ac_cv_search_tgetent+:} false; then :
 10933  10941     $as_echo_n "(cached) " >&6
 10934  10942   else
 10935  10943     ac_func_search_save_LIBS=$LIBS
 10936  10944   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 10937  10945   /* end confdefs.h.  */
 10938  10946   
 10939  10947   /* Override any GCC internal prototype to avoid an error.
................................................................................
 10959  10967       LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
 10960  10968     fi
 10961  10969     if ac_fn_c_try_link "$LINENO"; then :
 10962  10970     ac_cv_search_tgetent=$ac_res
 10963  10971   fi
 10964  10972   rm -f core conftest.err conftest.$ac_objext \
 10965  10973       conftest$ac_exeext
 10966         -  if test "${ac_cv_search_tgetent+set}" = set; then :
        10974  +  if ${ac_cv_search_tgetent+:} false; then :
 10967  10975     break
 10968  10976   fi
 10969  10977   done
 10970         -if test "${ac_cv_search_tgetent+set}" = set; then :
        10978  +if ${ac_cv_search_tgetent+:} false; then :
 10971  10979   
 10972  10980   else
 10973  10981     ac_cv_search_tgetent=no
 10974  10982   fi
 10975  10983   rm conftest.$ac_ext
 10976  10984   LIBS=$ac_func_search_save_LIBS
 10977  10985   fi
................................................................................
 10983  10991     term_LIBS="$LIBS"
 10984  10992   else
 10985  10993     term_LIBS=""
 10986  10994   fi
 10987  10995   
 10988  10996   		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for readline in -lreadline" >&5
 10989  10997   $as_echo_n "checking for readline in -lreadline... " >&6; }
 10990         -if test "${ac_cv_lib_readline_readline+set}" = set; then :
        10998  +if ${ac_cv_lib_readline_readline+:} false; then :
 10991  10999     $as_echo_n "(cached) " >&6
 10992  11000   else
 10993  11001     ac_check_lib_save_LIBS=$LIBS
 10994  11002   LIBS="-lreadline  $LIBS"
 10995  11003   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 10996  11004   /* end confdefs.h.  */
 10997  11005   
................................................................................
 11017  11025   fi
 11018  11026   rm -f core conftest.err conftest.$ac_objext \
 11019  11027       conftest$ac_exeext conftest.$ac_ext
 11020  11028   LIBS=$ac_check_lib_save_LIBS
 11021  11029   fi
 11022  11030   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_readline_readline" >&5
 11023  11031   $as_echo "$ac_cv_lib_readline_readline" >&6; }
 11024         -if test "x$ac_cv_lib_readline_readline" = x""yes; then :
        11032  +if test "x$ac_cv_lib_readline_readline" = xyes; then :
 11025  11033     TARGET_READLINE_LIBS="-lreadline"
 11026  11034   else
 11027  11035     found="no"
 11028  11036   fi
 11029  11037   
 11030  11038   		TARGET_READLINE_LIBS="$TARGET_READLINE_LIBS $term_LIBS"
 11031  11039   		LIBS="$save_LIBS"
................................................................................
 11039  11047     withval=$with_readline_inc; with_readline_inc=$withval
 11040  11048   else
 11041  11049     with_readline_inc="auto"
 11042  11050   fi
 11043  11051   
 11044  11052   	if test "x$with_readline_inc" = xauto; then
 11045  11053   		ac_fn_c_check_header_mongrel "$LINENO" "readline.h" "ac_cv_header_readline_h" "$ac_includes_default"
 11046         -if test "x$ac_cv_header_readline_h" = x""yes; then :
        11054  +if test "x$ac_cv_header_readline_h" = xyes; then :
 11047  11055     found="yes"
 11048  11056   else
 11049  11057   
 11050  11058   			found="no"
 11051  11059   			if test "$cross_compiling" != yes; then
 11052  11060   				for dir in /usr /usr/local /usr/local/readline /usr/contrib /mingw; do
 11053  11061   					for subdir in include include/readline; do
 11054  11062   						as_ac_File=`$as_echo "ac_cv_file_$dir/$subdir/readline.h" | $as_tr_sh`
 11055  11063   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $dir/$subdir/readline.h" >&5
 11056  11064   $as_echo_n "checking for $dir/$subdir/readline.h... " >&6; }
 11057         -if eval "test \"\${$as_ac_File+set}\"" = set; then :
        11065  +if eval \${$as_ac_File+:} false; then :
 11058  11066     $as_echo_n "(cached) " >&6
 11059  11067   else
 11060  11068     test "$cross_compiling" = yes &&
 11061  11069     as_fn_error $? "cannot check for file existence when cross compiling" "$LINENO" 5
 11062  11070   if test -r "$dir/$subdir/readline.h"; then
 11063  11071     eval "$as_ac_File=yes"
 11064  11072   else
................................................................................
 11103  11111   
 11104  11112   ##########
 11105  11113   # Figure out what C libraries are required to compile programs
 11106  11114   # that use "fdatasync()" function.
 11107  11115   #
 11108  11116   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing fdatasync" >&5
 11109  11117   $as_echo_n "checking for library containing fdatasync... " >&6; }
 11110         -if test "${ac_cv_search_fdatasync+set}" = set; then :
        11118  +if ${ac_cv_search_fdatasync+:} false; then :
 11111  11119     $as_echo_n "(cached) " >&6
 11112  11120   else
 11113  11121     ac_func_search_save_LIBS=$LIBS
 11114  11122   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 11115  11123   /* end confdefs.h.  */
 11116  11124   
 11117  11125   /* Override any GCC internal prototype to avoid an error.
................................................................................
 11137  11145       LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
 11138  11146     fi
 11139  11147     if ac_fn_c_try_link "$LINENO"; then :
 11140  11148     ac_cv_search_fdatasync=$ac_res
 11141  11149   fi
 11142  11150   rm -f core conftest.err conftest.$ac_objext \
 11143  11151       conftest$ac_exeext
 11144         -  if test "${ac_cv_search_fdatasync+set}" = set; then :
        11152  +  if ${ac_cv_search_fdatasync+:} false; then :
 11145  11153     break
 11146  11154   fi
 11147  11155   done
 11148         -if test "${ac_cv_search_fdatasync+set}" = set; then :
        11156  +if ${ac_cv_search_fdatasync+:} false; then :
 11149  11157   
 11150  11158   else
 11151  11159     ac_cv_search_fdatasync=no
 11152  11160   fi
 11153  11161   rm conftest.$ac_ext
 11154  11162   LIBS=$ac_func_search_save_LIBS
 11155  11163   fi
................................................................................
 11201  11209     use_loadextension=no
 11202  11210   fi
 11203  11211   
 11204  11212   if test "${use_loadextension}" = "yes" ; then
 11205  11213     OPT_FEATURE_FLAGS=""
 11206  11214     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
 11207  11215   $as_echo_n "checking for library containing dlopen... " >&6; }
 11208         -if test "${ac_cv_search_dlopen+set}" = set; then :
        11216  +if ${ac_cv_search_dlopen+:} false; then :
 11209  11217     $as_echo_n "(cached) " >&6
 11210  11218   else
 11211  11219     ac_func_search_save_LIBS=$LIBS
 11212  11220   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 11213  11221   /* end confdefs.h.  */
 11214  11222   
 11215  11223   /* Override any GCC internal prototype to avoid an error.
................................................................................
 11235  11243       LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
 11236  11244     fi
 11237  11245     if ac_fn_c_try_link "$LINENO"; then :
 11238  11246     ac_cv_search_dlopen=$ac_res
 11239  11247   fi
 11240  11248   rm -f core conftest.err conftest.$ac_objext \
 11241  11249       conftest$ac_exeext
 11242         -  if test "${ac_cv_search_dlopen+set}" = set; then :
        11250  +  if ${ac_cv_search_dlopen+:} false; then :
 11243  11251     break
 11244  11252   fi
 11245  11253   done
 11246         -if test "${ac_cv_search_dlopen+set}" = set; then :
        11254  +if ${ac_cv_search_dlopen+:} false; then :
 11247  11255   
 11248  11256   else
 11249  11257     ac_cv_search_dlopen=no
 11250  11258   fi
 11251  11259   rm conftest.$ac_ext
 11252  11260   LIBS=$ac_func_search_save_LIBS
 11253  11261   fi
................................................................................
 11402  11410        :clear
 11403  11411        s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
 11404  11412        t end
 11405  11413        s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
 11406  11414        :end' >>confcache
 11407  11415   if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
 11408  11416     if test -w "$cache_file"; then
 11409         -    test "x$cache_file" != "x/dev/null" &&
        11417  +    if test "x$cache_file" != "x/dev/null"; then
 11410  11418         { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
 11411  11419   $as_echo "$as_me: updating cache $cache_file" >&6;}
 11412         -    cat confcache >$cache_file
        11420  +      if test ! -f "$cache_file" || test -h "$cache_file"; then
        11421  +	cat confcache >"$cache_file"
        11422  +      else
        11423  +        case $cache_file in #(
        11424  +        */* | ?:*)
        11425  +	  mv -f confcache "$cache_file"$$ &&
        11426  +	  mv -f "$cache_file"$$ "$cache_file" ;; #(
        11427  +        *)
        11428  +	  mv -f confcache "$cache_file" ;;
        11429  +	esac
        11430  +      fi
        11431  +    fi
 11413  11432     else
 11414  11433       { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
 11415  11434   $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
 11416  11435     fi
 11417  11436   fi
 11418  11437   rm -f confcache
 11419  11438   
................................................................................
 11437  11456   done
 11438  11457   LIBOBJS=$ac_libobjs
 11439  11458   
 11440  11459   LTLIBOBJS=$ac_ltlibobjs
 11441  11460   
 11442  11461   
 11443  11462   
 11444         -: ${CONFIG_STATUS=./config.status}
        11463  +: "${CONFIG_STATUS=./config.status}"
 11445  11464   ac_write_fail=0
 11446  11465   ac_clean_files_save=$ac_clean_files
 11447  11466   ac_clean_files="$ac_clean_files $CONFIG_STATUS"
 11448  11467   { $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
 11449  11468   $as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
 11450  11469   as_write_fail=0
 11451  11470   cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
................................................................................
 11538  11557   # We need space, tab and new line, in precisely that order.  Quoting is
 11539  11558   # there to prevent editors from complaining about space-tab.
 11540  11559   # (If _AS_PATH_WALK were called with IFS unset, it would disable word
 11541  11560   # splitting by setting IFS to empty value.)
 11542  11561   IFS=" ""	$as_nl"
 11543  11562   
 11544  11563   # Find who we are.  Look in the path if we contain no directory separator.
        11564  +as_myself=
 11545  11565   case $0 in #((
 11546  11566     *[\\/]* ) as_myself=$0 ;;
 11547  11567     *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 11548  11568   for as_dir in $PATH
 11549  11569   do
 11550  11570     IFS=$as_save_IFS
 11551  11571     test -z "$as_dir" && as_dir=.
................................................................................
 11844  11864   test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
 11845  11865   
 11846  11866   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 11847  11867   # Save the log message, to keep $0 and so on meaningful, and to
 11848  11868   # report actual input values of CONFIG_FILES etc. instead of their
 11849  11869   # values after options handling.
 11850  11870   ac_log="
 11851         -This file was extended by sqlite $as_me 3.7.9, which was
 11852         -generated by GNU Autoconf 2.67.  Invocation command line was
        11871  +This file was extended by sqlite $as_me 3.7.10, which was
        11872  +generated by GNU Autoconf 2.68.  Invocation command line was
 11853  11873   
 11854  11874     CONFIG_FILES    = $CONFIG_FILES
 11855  11875     CONFIG_HEADERS  = $CONFIG_HEADERS
 11856  11876     CONFIG_LINKS    = $CONFIG_LINKS
 11857  11877     CONFIG_COMMANDS = $CONFIG_COMMANDS
 11858  11878     $ $0 $@
 11859  11879   
................................................................................
 11910  11930   
 11911  11931   Report bugs to the package provider."
 11912  11932   
 11913  11933   _ACEOF
 11914  11934   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 11915  11935   ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 11916  11936   ac_cs_version="\\
 11917         -sqlite config.status 3.7.9
 11918         -configured by $0, generated by GNU Autoconf 2.67,
        11937  +sqlite config.status 3.7.10
        11938  +configured by $0, generated by GNU Autoconf 2.68,
 11919  11939     with options \\"\$ac_cs_config\\"
 11920  11940   
 11921  11941   Copyright (C) 2010 Free Software Foundation, Inc.
 11922  11942   This config.status script is free software; the Free Software Foundation
 11923  11943   gives unlimited permission to copy, distribute and modify it."
 11924  11944   
 11925  11945   ac_pwd='$ac_pwd'
................................................................................
 12297  12317   do
 12298  12318     case $ac_config_target in
 12299  12319       "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
 12300  12320       "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
 12301  12321       "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
 12302  12322       "sqlite3.pc") CONFIG_FILES="$CONFIG_FILES sqlite3.pc" ;;
 12303  12323   
 12304         -  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5 ;;
        12324  +  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
 12305  12325     esac
 12306  12326   done
 12307  12327   
 12308  12328   
 12309  12329   # If the user did not use the arguments to specify the items to instantiate,
 12310  12330   # then the envvar interface is used.  Set only those that are not.
 12311  12331   # We use the long form for the default assignment because of an extremely
................................................................................
 12320  12340   # simply because there is no reason against having it here, and in addition,
 12321  12341   # creating and moving files from /tmp can sometimes cause problems.
 12322  12342   # Hook for its removal unless debugging.
 12323  12343   # Note that there is a small window in which the directory will not be cleaned:
 12324  12344   # after its creation but before its name has been assigned to `$tmp'.
 12325  12345   $debug ||
 12326  12346   {
 12327         -  tmp=
        12347  +  tmp= ac_tmp=
 12328  12348     trap 'exit_status=$?
 12329         -  { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status
        12349  +  : "${ac_tmp:=$tmp}"
        12350  +  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
 12330  12351   ' 0
 12331  12352     trap 'as_fn_exit 1' 1 2 13 15
 12332  12353   }
 12333  12354   # Create a (secure) tmp directory for tmp files.
 12334  12355   
 12335  12356   {
 12336  12357     tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
 12337         -  test -n "$tmp" && test -d "$tmp"
        12358  +  test -d "$tmp"
 12338  12359   }  ||
 12339  12360   {
 12340  12361     tmp=./conf$$-$RANDOM
 12341  12362     (umask 077 && mkdir "$tmp")
 12342  12363   } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
        12364  +ac_tmp=$tmp
 12343  12365   
 12344  12366   # Set up the scripts for CONFIG_FILES section.
 12345  12367   # No need to generate them if there are no CONFIG_FILES.
 12346  12368   # This happens for instance with `./config.status config.h'.
 12347  12369   if test -n "$CONFIG_FILES"; then
 12348  12370   
 12349  12371   
................................................................................
 12357  12379   ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' </dev/null 2>/dev/null`
 12358  12380   if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then
 12359  12381     ac_cs_awk_cr='\\r'
 12360  12382   else
 12361  12383     ac_cs_awk_cr=$ac_cr
 12362  12384   fi
 12363  12385   
 12364         -echo 'BEGIN {' >"$tmp/subs1.awk" &&
        12386  +echo 'BEGIN {' >"$ac_tmp/subs1.awk" &&
 12365  12387   _ACEOF
 12366  12388   
 12367  12389   
 12368  12390   {
 12369  12391     echo "cat >conf$$subs.awk <<_ACEOF" &&
 12370  12392     echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' &&
 12371  12393     echo "_ACEOF"
................................................................................
 12385  12407     else
 12386  12408       ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
 12387  12409     fi
 12388  12410   done
 12389  12411   rm -f conf$$subs.sh
 12390  12412   
 12391  12413   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 12392         -cat >>"\$tmp/subs1.awk" <<\\_ACAWK &&
        12414  +cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&
 12393  12415   _ACEOF
 12394  12416   sed -n '
 12395  12417   h
 12396  12418   s/^/S["/; s/!.*/"]=/
 12397  12419   p
 12398  12420   g
 12399  12421   s/^[^!]*!//
................................................................................
 12433  12455     N
 12434  12456     s/\n//
 12435  12457   }
 12436  12458   ' >>$CONFIG_STATUS || ac_write_fail=1
 12437  12459   rm -f conf$$subs.awk
 12438  12460   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 12439  12461   _ACAWK
 12440         -cat >>"\$tmp/subs1.awk" <<_ACAWK &&
        12462  +cat >>"\$ac_tmp/subs1.awk" <<_ACAWK &&
 12441  12463     for (key in S) S_is_set[key] = 1
 12442  12464     FS = ""
 12443  12465   
 12444  12466   }
 12445  12467   {
 12446  12468     line = $ 0
 12447  12469     nfields = split(line, field, "@")
................................................................................
 12465  12487   _ACAWK
 12466  12488   _ACEOF
 12467  12489   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 12468  12490   if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then
 12469  12491     sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g"
 12470  12492   else
 12471  12493     cat
 12472         -fi < "$tmp/subs1.awk" > "$tmp/subs.awk" \
        12494  +fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \
 12473  12495     || as_fn_error $? "could not setup config files machinery" "$LINENO" 5
 12474  12496   _ACEOF
 12475  12497   
 12476  12498   # VPATH may cause trouble with some makes, so we remove sole $(srcdir),
 12477  12499   # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and
 12478  12500   # trailing colons and then remove the whole line if VPATH becomes empty
 12479  12501   # (actually we leave an empty line to preserve line numbers).
................................................................................
 12499  12521   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 12500  12522   fi # test -n "$CONFIG_FILES"
 12501  12523   
 12502  12524   # Set up the scripts for CONFIG_HEADERS section.
 12503  12525   # No need to generate them if there are no CONFIG_HEADERS.
 12504  12526   # This happens for instance with `./config.status Makefile'.
 12505  12527   if test -n "$CONFIG_HEADERS"; then
 12506         -cat >"$tmp/defines.awk" <<\_ACAWK ||
        12528  +cat >"$ac_tmp/defines.awk" <<\_ACAWK ||
 12507  12529   BEGIN {
 12508  12530   _ACEOF
 12509  12531   
 12510  12532   # Transform confdefs.h into an awk script `defines.awk', embedded as
 12511  12533   # here-document in config.status, that substitutes the proper values into
 12512  12534   # config.h.in to produce config.h.
 12513  12535   
 12514  12536   # Create a delimiter string that does not exist in confdefs.h, to ease
 12515  12537   # handling of long lines.
 12516  12538   ac_delim='%!_!# '
 12517  12539   for ac_last_try in false false :; do
 12518         -  ac_t=`sed -n "/$ac_delim/p" confdefs.h`
 12519         -  if test -z "$ac_t"; then
        12540  +  ac_tt=`sed -n "/$ac_delim/p" confdefs.h`
        12541  +  if test -z "$ac_tt"; then
 12520  12542       break
 12521  12543     elif $ac_last_try; then
 12522  12544       as_fn_error $? "could not make $CONFIG_HEADERS" "$LINENO" 5
 12523  12545     else
 12524  12546       ac_delim="$ac_delim!$ac_delim _$ac_delim!! "
 12525  12547     fi
 12526  12548   done
................................................................................
 12613  12635   for ac_tag
 12614  12636   do
 12615  12637     case $ac_tag in
 12616  12638     :[FHLC]) ac_mode=$ac_tag; continue;;
 12617  12639     esac
 12618  12640     case $ac_mode$ac_tag in
 12619  12641     :[FHL]*:*);;
 12620         -  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5 ;;
        12642  +  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
 12621  12643     :[FH]-) ac_tag=-:-;;
 12622  12644     :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
 12623  12645     esac
 12624  12646     ac_save_IFS=$IFS
 12625  12647     IFS=:
 12626  12648     set x $ac_tag
 12627  12649     IFS=$ac_save_IFS
................................................................................
 12632  12654     case $ac_mode in
 12633  12655     :L) ac_source=$1;;
 12634  12656     :[FH])
 12635  12657       ac_file_inputs=
 12636  12658       for ac_f
 12637  12659       do
 12638  12660         case $ac_f in
 12639         -      -) ac_f="$tmp/stdin";;
        12661  +      -) ac_f="$ac_tmp/stdin";;
 12640  12662         *) # Look for the file first in the build tree, then in the source tree
 12641  12663   	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
 12642  12664   	 # because $ac_f cannot contain `:'.
 12643  12665   	 test -f "$ac_f" ||
 12644  12666   	   case $ac_f in
 12645  12667   	   [\\/$]*) false;;
 12646  12668   	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
 12647  12669   	   esac ||
 12648         -	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5 ;;
        12670  +	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
 12649  12671         esac
 12650  12672         case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
 12651  12673         as_fn_append ac_file_inputs " '$ac_f'"
 12652  12674       done
 12653  12675   
 12654  12676       # Let's still pretend it is `configure' which instantiates (i.e., don't
 12655  12677       # use $as_me), people would be surprised to read:
................................................................................
 12667  12689       *\&* | *\|* | *\\* )
 12668  12690          ac_sed_conf_input=`$as_echo "$configure_input" |
 12669  12691          sed 's/[\\\\&|]/\\\\&/g'`;; #(
 12670  12692       *) ac_sed_conf_input=$configure_input;;
 12671  12693       esac
 12672  12694   
 12673  12695       case $ac_tag in
 12674         -    *:-:* | *:-) cat >"$tmp/stdin" \
 12675         -      || as_fn_error $? "could not create $ac_file" "$LINENO" 5  ;;
        12696  +    *:-:* | *:-) cat >"$ac_tmp/stdin" \
        12697  +      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
 12676  12698       esac
 12677  12699       ;;
 12678  12700     esac
 12679  12701   
 12680  12702     ac_dir=`$as_dirname -- "$ac_file" ||
 12681  12703   $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
 12682  12704   	 X"$ac_file" : 'X\(//\)[^/]' \| \
................................................................................
 12798  12820   s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t
 12799  12821   s&@builddir@&$ac_builddir&;t t
 12800  12822   s&@abs_builddir@&$ac_abs_builddir&;t t
 12801  12823   s&@abs_top_builddir@&$ac_abs_top_builddir&;t t
 12802  12824   s&@INSTALL@&$ac_INSTALL&;t t
 12803  12825   $ac_datarootdir_hack
 12804  12826   "
 12805         -eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$tmp/subs.awk" >$tmp/out \
 12806         -  || as_fn_error $? "could not create $ac_file" "$LINENO" 5
        12827  +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
        12828  +  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5
 12807  12829   
 12808  12830   test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
 12809         -  { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } &&
 12810         -  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } &&
        12831  +  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
        12832  +  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
        12833  +      "$ac_tmp/out"`; test -z "$ac_out"; } &&
 12811  12834     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 12812  12835   which seems to be undefined.  Please make sure it is defined" >&5
 12813  12836   $as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
 12814  12837   which seems to be undefined.  Please make sure it is defined" >&2;}
 12815  12838   
 12816         -  rm -f "$tmp/stdin"
        12839  +  rm -f "$ac_tmp/stdin"
 12817  12840     case $ac_file in
 12818         -  -) cat "$tmp/out" && rm -f "$tmp/out";;
 12819         -  *) rm -f "$ac_file" && mv "$tmp/out" "$ac_file";;
        12841  +  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
        12842  +  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
 12820  12843     esac \
 12821  12844     || as_fn_error $? "could not create $ac_file" "$LINENO" 5
 12822  12845    ;;
 12823  12846     :H)
 12824  12847     #
 12825  12848     # CONFIG_HEADER
 12826  12849     #
 12827  12850     if test x"$ac_file" != x-; then
 12828  12851       {
 12829  12852         $as_echo "/* $configure_input  */" \
 12830         -      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs"
 12831         -    } >"$tmp/config.h" \
        12853  +      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs"
        12854  +    } >"$ac_tmp/config.h" \
 12832  12855         || as_fn_error $? "could not create $ac_file" "$LINENO" 5
 12833         -    if diff "$ac_file" "$tmp/config.h" >/dev/null 2>&1; then
        12856  +    if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then
 12834  12857         { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5
 12835  12858   $as_echo "$as_me: $ac_file is unchanged" >&6;}
 12836  12859       else
 12837  12860         rm -f "$ac_file"
 12838         -      mv "$tmp/config.h" "$ac_file" \
        12861  +      mv "$ac_tmp/config.h" "$ac_file" \
 12839  12862   	|| as_fn_error $? "could not create $ac_file" "$LINENO" 5
 12840  12863       fi
 12841  12864     else
 12842  12865       $as_echo "/* $configure_input  */" \
 12843         -      && eval '$AWK -f "$tmp/defines.awk"' "$ac_file_inputs" \
        12866  +      && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \
 12844  12867         || as_fn_error $? "could not create -" "$LINENO" 5
 12845  12868     fi
 12846  12869    ;;
 12847  12870   
 12848  12871     :C)  { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5
 12849  12872   $as_echo "$as_me: executing $ac_file commands" >&6;}
 12850  12873    ;;

Changes to configure.ac.

   123    123   #########
   124    124   # Check for needed/wanted headers
   125    125   AC_CHECK_HEADERS([sys/types.h stdlib.h stdint.h inttypes.h])
   126    126   
   127    127   #########
   128    128   # Figure out whether or not we have these functions
   129    129   #
   130         -AC_CHECK_FUNCS([usleep fdatasync localtime_r gmtime_r localtime_s utime])
          130  +AC_CHECK_FUNCS([usleep fdatasync localtime_r gmtime_r localtime_s utime malloc_usable_size])
   131    131   
   132    132   #########
   133    133   # By default, we use the amalgamation (this may be changed below...)
   134    134   #
   135    135   USE_AMALGAMATION=1
   136    136   
   137    137   #########

Changes to ext/fts3/fts3.c.

   708    708     ...                             /* Arguments for printf format string */
   709    709   ){
   710    710     if( *pRc==SQLITE_OK ){
   711    711       va_list ap;
   712    712       char *z;
   713    713       va_start(ap, zFormat);
   714    714       z = sqlite3_vmprintf(zFormat, ap);
          715  +    va_end(ap);
   715    716       if( z && *pz ){
   716    717         char *z2 = sqlite3_mprintf("%s%s", *pz, z);
   717    718         sqlite3_free(z);
   718    719         z = z2;
   719    720       }
   720    721       if( z==0 ) *pRc = SQLITE_NOMEM;
   721    722       sqlite3_free(*pz);

Changes to src/btree.c.

   861    861   ** Given a btree page and a cell index (0 means the first cell on
   862    862   ** the page, 1 means the second cell, and so forth) return a pointer
   863    863   ** to the cell content.
   864    864   **
   865    865   ** This routine works only for pages that do not contain overflow cells.
   866    866   */
   867    867   #define findCell(P,I) \
   868         -  ((P)->aData + ((P)->maskPage & get2byte(&(P)->aData[(P)->cellOffset+2*(I)])))
          868  +  ((P)->aData + ((P)->maskPage & get2byte(&(P)->aCellIdx[2*(I)])))
   869    869   #define findCellv2(D,M,O,I) (D+(M&get2byte(D+(O+2*(I)))))
   870    870   
   871    871   
   872    872   /*
   873    873   ** This a more complex version of findCell() that works for
   874    874   ** pages that do contain overflow cells.
   875    875   */
................................................................................
  1411   1411       data = pPage->aData;
  1412   1412       if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
  1413   1413       assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
  1414   1414       pPage->maskPage = (u16)(pBt->pageSize - 1);
  1415   1415       pPage->nOverflow = 0;
  1416   1416       usableSize = pBt->usableSize;
  1417   1417       pPage->cellOffset = cellOffset = hdr + 12 - 4*pPage->leaf;
         1418  +    pPage->aDataEnd = &data[usableSize];
         1419  +    pPage->aCellIdx = &data[cellOffset];
  1418   1420       top = get2byteNotZero(&data[hdr+5]);
  1419   1421       pPage->nCell = get2byte(&data[hdr+3]);
  1420   1422       if( pPage->nCell>MX_CELL(pBt) ){
  1421   1423         /* To many cells for a single page.  The page must be corrupt */
  1422   1424         return SQLITE_CORRUPT_BKPT;
  1423   1425       }
  1424   1426       testcase( pPage->nCell==MX_CELL(pBt) );
................................................................................
  1514   1516     memset(&data[hdr+1], 0, 4);
  1515   1517     data[hdr+7] = 0;
  1516   1518     put2byte(&data[hdr+5], pBt->usableSize);
  1517   1519     pPage->nFree = (u16)(pBt->usableSize - first);
  1518   1520     decodeFlags(pPage, flags);
  1519   1521     pPage->hdrOffset = hdr;
  1520   1522     pPage->cellOffset = first;
         1523  +  pPage->aDataEnd = &data[pBt->usableSize];
         1524  +  pPage->aCellIdx = &data[first];
  1521   1525     pPage->nOverflow = 0;
  1522   1526     assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
  1523   1527     pPage->maskPage = (u16)(pBt->pageSize - 1);
  1524   1528     pPage->nCell = 0;
  1525   1529     pPage->isInit = 1;
  1526   1530   }
  1527   1531   
................................................................................
  1774   1778         char *zFullPathname = sqlite3Malloc(nFullPathname);
  1775   1779         MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
  1776   1780         p->sharable = 1;
  1777   1781         if( !zFullPathname ){
  1778   1782           sqlite3_free(p);
  1779   1783           return SQLITE_NOMEM;
  1780   1784         }
  1781         -      sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
         1785  +      rc = sqlite3OsFullPathname(pVfs, zFilename, nFullPathname, zFullPathname);
         1786  +      if( rc ){
         1787  +        sqlite3_free(zFullPathname);
         1788  +        sqlite3_free(p);
         1789  +        return rc;
         1790  +      }
  1782   1791   #if SQLITE_THREADSAFE
  1783   1792         mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
  1784   1793         sqlite3_mutex_enter(mutexOpen);
  1785   1794         mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
  1786   1795         sqlite3_mutex_enter(mutexShared);
  1787   1796   #endif
  1788   1797         for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
................................................................................
  4573   4582           ** page is less than 16384 bytes and may be stored as a 2-byte
  4574   4583           ** varint. This information is used to attempt to avoid parsing 
  4575   4584           ** the entire cell by checking for the cases where the record is 
  4576   4585           ** stored entirely within the b-tree page by inspecting the first 
  4577   4586           ** 2 bytes of the cell.
  4578   4587           */
  4579   4588           int nCell = pCell[0];
  4580         -        if( !(nCell & 0x80) && nCell<=pPage->maxLocal ){
         4589  +        if( !(nCell & 0x80)
         4590  +         && nCell<=pPage->maxLocal
         4591  +         && (pCell+nCell+1)<=pPage->aDataEnd
         4592  +        ){
  4581   4593             /* This branch runs if the record-size field of the cell is a
  4582   4594             ** single byte varint and the record fits entirely on the main
  4583   4595             ** b-tree page.  */
         4596  +          testcase( pCell+nCell+1==pPage->aDataEnd );
  4584   4597             c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey);
  4585   4598           }else if( !(pCell[1] & 0x80) 
  4586   4599             && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal
         4600  +          && (pCell+nCell+2)<=pPage->aDataEnd
  4587   4601           ){
  4588   4602             /* The record-size field is a 2 byte varint and the record 
  4589   4603             ** fits entirely on the main b-tree page.  */
         4604  +          testcase( pCell+nCell+2==pPage->aDataEnd );
  4590   4605             c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey);
  4591   4606           }else{
  4592   4607             /* The record flows over onto one or more overflow pages. In
  4593   4608             ** this case the whole cell needs to be parsed, a buffer allocated
  4594   4609             ** and accessPayload() used to retrieve the record into the
  4595   4610             ** buffer before VdbeRecordCompare() can be called. */
  4596   4611             void *pCellKey;
................................................................................
  5477   5492     if( *pRC ) return;
  5478   5493   
  5479   5494     assert( idx>=0 && idx<pPage->nCell );
  5480   5495     assert( sz==cellSize(pPage, idx) );
  5481   5496     assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  5482   5497     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  5483   5498     data = pPage->aData;
  5484         -  ptr = &data[pPage->cellOffset + 2*idx];
         5499  +  ptr = &pPage->aCellIdx[2*idx];
  5485   5500     pc = get2byte(ptr);
  5486   5501     hdr = pPage->hdrOffset;
  5487   5502     testcase( pc==get2byte(&data[hdr+5]) );
  5488   5503     testcase( pc+sz==pPage->pBt->usableSize );
  5489   5504     if( pc < (u32)get2byte(&data[hdr+5]) || pc+sz > pPage->pBt->usableSize ){
  5490   5505       *pRC = SQLITE_CORRUPT_BKPT;
  5491   5506       return;
  5492   5507     }
  5493   5508     rc = freeSpace(pPage, pc, sz);
  5494   5509     if( rc ){
  5495   5510       *pRC = rc;
  5496   5511       return;
  5497   5512     }
  5498         -  endPtr = &data[pPage->cellOffset + 2*pPage->nCell - 2];
         5513  +  endPtr = &pPage->aCellIdx[2*pPage->nCell - 2];
  5499   5514     assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 );  /* ptr is always 2-byte aligned */
  5500   5515     while( ptr<endPtr ){
  5501   5516       *(u16*)ptr = *(u16*)&ptr[2];
  5502   5517       ptr += 2;
  5503   5518     }
  5504   5519     pPage->nCell--;
  5505   5520     put2byte(&data[hdr+3], pPage->nCell);
................................................................................
  5633   5648               && (int)MX_CELL(pPage->pBt)<=10921);
  5634   5649     assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  5635   5650   
  5636   5651     /* Check that the page has just been zeroed by zeroPage() */
  5637   5652     assert( pPage->nCell==0 );
  5638   5653     assert( get2byteNotZero(&data[hdr+5])==nUsable );
  5639   5654   
  5640         -  pCellptr = &data[pPage->cellOffset + nCell*2];
         5655  +  pCellptr = &pPage->aCellIdx[nCell*2];
  5641   5656     cellbody = nUsable;
  5642   5657     for(i=nCell-1; i>=0; i--){
  5643   5658       u16 sz = aSize[i];
  5644   5659       pCellptr -= 2;
  5645   5660       cellbody -= sz;
  5646   5661       put2byte(pCellptr, cellbody);
  5647   5662       memcpy(&data[cellbody], apCell[i], sz);

Changes to src/btreeInt.h.

   285    285     u16 maskPage;        /* Mask for page offset */
   286    286     struct _OvflCell {   /* Cells that will not fit on aData[] */
   287    287       u8 *pCell;          /* Pointers to the body of the overflow cell */
   288    288       u16 idx;            /* Insert this cell before idx-th non-overflow cell */
   289    289     } aOvfl[5];
   290    290     BtShared *pBt;       /* Pointer to BtShared that this page is part of */
   291    291     u8 *aData;           /* Pointer to disk image of the page data */
          292  +  u8 *aDataEnd;        /* One byte past the end of usable data */
          293  +  u8 *aCellIdx;        /* The cell index area */
   292    294     DbPage *pDbPage;     /* Pager page handle */
   293    295     Pgno pgno;           /* Page number for this page */
   294    296   };
   295    297   
   296    298   /*
   297    299   ** The in-memory image of a disk page has the auxiliary information appended
   298    300   ** to the end.  EXTRA_SIZE is the number of bytes of space needed to hold

Changes to src/build.c.

  2657   2657   
  2658   2658     /* 
  2659   2659     ** Allocate the index structure. 
  2660   2660     */
  2661   2661     nName = sqlite3Strlen30(zName);
  2662   2662     nCol = pList->nExpr;
  2663   2663     pIndex = sqlite3DbMallocZero(db, 
  2664         -      sizeof(Index) +              /* Index structure  */
  2665         -      sizeof(tRowcnt)*(nCol+1) +   /* Index.aiRowEst   */
  2666         -      sizeof(int)*nCol +           /* Index.aiColumn   */
  2667         -      sizeof(char *)*nCol +        /* Index.azColl     */
  2668         -      sizeof(u8)*nCol +            /* Index.aSortOrder */
  2669         -      nName + 1 +                  /* Index.zName      */
  2670         -      nExtra                       /* Collation sequence names */
         2664  +      sizeof(Index) +                      /* Index structure  */
         2665  +      ROUND8(sizeof(tRowcnt)*(nCol+1)) +   /* Index.aiRowEst   */
         2666  +      sizeof(char *)*nCol +                /* Index.azColl     */
         2667  +      sizeof(int)*nCol +                   /* Index.aiColumn   */
         2668  +      sizeof(u8)*nCol +                    /* Index.aSortOrder */
         2669  +      nName + 1 +                          /* Index.zName      */
         2670  +      nExtra                               /* Collation sequence names */
  2671   2671     );
  2672   2672     if( db->mallocFailed ){
  2673   2673       goto exit_create_index;
  2674   2674     }
  2675   2675     pIndex->aiRowEst = (tRowcnt*)(&pIndex[1]);
  2676         -  pIndex->azColl = (char**)(&pIndex->aiRowEst[nCol+1]);
         2676  +  pIndex->azColl = (char**)
         2677  +     ((char*)pIndex->aiRowEst + ROUND8(sizeof(tRowcnt)*nCol+1));
         2678  +  assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowEst) );
         2679  +  assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
  2677   2680     pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
  2678   2681     pIndex->aSortOrder = (u8 *)(&pIndex->aiColumn[nCol]);
  2679   2682     pIndex->zName = (char *)(&pIndex->aSortOrder[nCol]);
  2680   2683     zExtra = (char *)(&pIndex->zName[nName+1]);
  2681   2684     memcpy(pIndex->zName, zName, nName+1);
  2682   2685     pIndex->pTable = pTab;
  2683   2686     pIndex->nColumn = pList->nExpr;

Changes to src/delete.c.

   144    144     SrcList *pSelectSrc = NULL;  /* SELECT rowid FROM x ... (dup of pSrc) */
   145    145     Select *pSelect = NULL;      /* Complete SELECT tree */
   146    146   
   147    147     /* Check that there isn't an ORDER BY without a LIMIT clause.
   148    148     */
   149    149     if( pOrderBy && (pLimit == 0) ) {
   150    150       sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
   151         -    pParse->parseError = 1;
   152    151       goto limit_where_cleanup_2;
   153    152     }
   154    153   
   155    154     /* We only need to generate a select expression if there
   156    155     ** is a limit/offset term to enforce.
   157    156     */
   158    157     if( pLimit == 0 ) {

Changes to src/expr.c.

   936    936       struct IdList_item *pOldItem = &p->a[i];
   937    937       pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
   938    938       pNewItem->idx = pOldItem->idx;
   939    939     }
   940    940     return pNew;
   941    941   }
   942    942   Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
   943         -  Select *pNew;
          943  +  Select *pNew, *pPrior;
   944    944     if( p==0 ) return 0;
   945    945     pNew = sqlite3DbMallocRaw(db, sizeof(*p) );
   946    946     if( pNew==0 ) return 0;
   947    947     pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
   948    948     pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
   949    949     pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
   950    950     pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
   951    951     pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
   952    952     pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
   953    953     pNew->op = p->op;
   954         -  pNew->pPrior = sqlite3SelectDup(db, p->pPrior, flags);
          954  +  pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
          955  +  if( pPrior ) pPrior->pNext = pNew;
          956  +  pNew->pNext = 0;
   955    957     pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
   956    958     pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
   957    959     pNew->iLimit = 0;
   958    960     pNew->iOffset = 0;
   959    961     pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
   960    962     pNew->pRightmost = 0;
   961    963     pNew->addrOpenEphm[0] = -1;
................................................................................
  3758   3760   void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){
  3759   3761     sqlite3ExprCacheRemove(pParse, iReg, nReg);
  3760   3762     if( nReg>pParse->nRangeReg ){
  3761   3763       pParse->nRangeReg = nReg;
  3762   3764       pParse->iRangeReg = iReg;
  3763   3765     }
  3764   3766   }
         3767  +
         3768  +/*
         3769  +** Mark all temporary registers as being unavailable for reuse.
         3770  +*/
         3771  +void sqlite3ClearTempRegCache(Parse *pParse){
         3772  +  pParse->nTempReg = 0;
         3773  +  pParse->nRangeReg = 0;
         3774  +}

Changes to src/global.c.

   143    143      SQLITE_THREADSAFE==1,      /* bFullMutex */
   144    144      SQLITE_USE_URI,            /* bOpenUri */
   145    145      0x7ffffffe,                /* mxStrlen */
   146    146      128,                       /* szLookaside */
   147    147      500,                       /* nLookaside */
   148    148      {0,0,0,0,0,0,0,0},         /* m */
   149    149      {0,0,0,0,0,0,0,0,0},       /* mutex */
   150         -   {0,0,0,0,0,0,0,0,0,0,0},   /* pcache */
          150  +   {0,0,0,0,0,0,0,0,0,0,0},   /* pcache2 */
   151    151      (void*)0,                  /* pHeap */
   152    152      0,                         /* nHeap */
   153    153      0, 0,                      /* mnHeap, mxHeap */
   154    154      (void*)0,                  /* pScratch */
   155    155      0,                         /* szScratch */
   156    156      0,                         /* nScratch */
   157    157      (void*)0,                  /* pPage */

Changes to src/insert.c.

    43     43   **  ------------------------------
    44     44   **  'a'            TEXT
    45     45   **  'b'            NONE
    46     46   **  'c'            NUMERIC
    47     47   **  'd'            INTEGER
    48     48   **  'e'            REAL
    49     49   **
    50         -** An extra 'b' is appended to the end of the string to cover the
           50  +** An extra 'd' is appended to the end of the string to cover the
    51     51   ** rowid that appears as the last column in every index.
    52     52   **
    53     53   ** Memory for the buffer containing the column index affinity string
    54     54   ** is managed along with the rest of the Index structure. It will be
    55     55   ** released when sqlite3DeleteIndex() is called.
    56     56   */
    57     57   const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
................................................................................
    71     71       if( !pIdx->zColAff ){
    72     72         db->mallocFailed = 1;
    73     73         return 0;
    74     74       }
    75     75       for(n=0; n<pIdx->nColumn; n++){
    76     76         pIdx->zColAff[n] = pTab->aCol[pIdx->aiColumn[n]].affinity;
    77     77       }
    78         -    pIdx->zColAff[n++] = SQLITE_AFF_NONE;
           78  +    pIdx->zColAff[n++] = SQLITE_AFF_INTEGER;
    79     79       pIdx->zColAff[n] = 0;
    80     80     }
    81     81    
    82     82     return pIdx->zColAff;
    83     83   }
    84     84   
    85     85   /*
................................................................................
  1574   1574   }
  1575   1575   
  1576   1576   /*
  1577   1577   ** Attempt the transfer optimization on INSERTs of the form
  1578   1578   **
  1579   1579   **     INSERT INTO tab1 SELECT * FROM tab2;
  1580   1580   **
  1581         -** This optimization is only attempted if
  1582         -**
  1583         -**    (1)  tab1 and tab2 have identical schemas including all the
  1584         -**         same indices and constraints
         1581  +** The xfer optimization transfers raw records from tab2 over to tab1.  
         1582  +** Columns are not decoded and reassemblied, which greatly improves
         1583  +** performance.  Raw index records are transferred in the same way.
  1585   1584   **
  1586         -**    (2)  tab1 and tab2 are different tables
         1585  +** The xfer optimization is only attempted if tab1 and tab2 are compatible.
         1586  +** There are lots of rules for determining compatibility - see comments
         1587  +** embedded in the code for details.
  1587   1588   **
  1588         -**    (3)  There must be no triggers on tab1
  1589         -**
  1590         -**    (4)  The result set of the SELECT statement is "*"
  1591         -**
  1592         -**    (5)  The SELECT statement has no WHERE, HAVING, ORDER BY, GROUP BY,
  1593         -**         or LIMIT clause.
         1589  +** This routine returns TRUE if the optimization is guaranteed to be used.
         1590  +** Sometimes the xfer optimization will only work if the destination table
         1591  +** is empty - a factor that can only be determined at run-time.  In that
         1592  +** case, this routine generates code for the xfer optimization but also
         1593  +** does a test to see if the destination table is empty and jumps over the
         1594  +** xfer optimization code if the test fails.  In that case, this routine
         1595  +** returns FALSE so that the caller will know to go ahead and generate
         1596  +** an unoptimized transfer.  This routine also returns FALSE if there
         1597  +** is no chance that the xfer optimization can be applied.
  1594   1598   **
  1595         -**    (6)  The SELECT statement is a simple (not a compound) select that
  1596         -**         contains only tab2 in its FROM clause
  1597         -**
  1598         -** This method for implementing the INSERT transfers raw records from
  1599         -** tab2 over to tab1.  The columns are not decoded.  Raw records from
  1600         -** the indices of tab2 are transfered to tab1 as well.  In so doing,
  1601         -** the resulting tab1 has much less fragmentation.
  1602         -**
  1603         -** This routine returns TRUE if the optimization is attempted.  If any
  1604         -** of the conditions above fail so that the optimization should not
  1605         -** be attempted, then this routine returns FALSE.
         1599  +** This optimization is particularly useful at making VACUUM run faster.
  1606   1600   */
  1607   1601   static int xferOptimization(
  1608   1602     Parse *pParse,        /* Parser context */
  1609   1603     Table *pDest,         /* The table we are inserting into */
  1610   1604     Select *pSelect,      /* A SELECT statement to use as the data source */
  1611   1605     int onError,          /* How to handle constraint errors */
  1612   1606     int iDbDest           /* The database of pDest */
................................................................................
  1635   1629     }
  1636   1630   #ifndef SQLITE_OMIT_VIRTUALTABLE
  1637   1631     if( pDest->tabFlags & TF_Virtual ){
  1638   1632       return 0;   /* tab1 must not be a virtual table */
  1639   1633     }
  1640   1634   #endif
  1641   1635     if( onError==OE_Default ){
  1642         -    onError = OE_Abort;
  1643         -  }
  1644         -  if( onError!=OE_Abort && onError!=OE_Rollback ){
  1645         -    return 0;   /* Cannot do OR REPLACE or OR IGNORE or OR FAIL */
         1636  +    if( pDest->iPKey>=0 ) onError = pDest->keyConf;
         1637  +    if( onError==OE_Default ) onError = OE_Abort;
  1646   1638     }
  1647   1639     assert(pSelect->pSrc);   /* allocated even if there is no FROM clause */
  1648   1640     if( pSelect->pSrc->nSrc!=1 ){
  1649   1641       return 0;   /* FROM clause must have exactly one term */
  1650   1642     }
  1651   1643     if( pSelect->pSrc->a[0].pSelect ){
  1652   1644       return 0;   /* FROM clause cannot contain a subquery */
................................................................................
  1744   1736     ** not worth the effort.  Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
  1745   1737     */
  1746   1738     if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){
  1747   1739       return 0;
  1748   1740     }
  1749   1741   #endif
  1750   1742     if( (pParse->db->flags & SQLITE_CountRows)!=0 ){
  1751         -    return 0;
         1743  +    return 0;  /* xfer opt does not play well with PRAGMA count_changes */
  1752   1744     }
  1753   1745   
  1754         -  /* If we get this far, it means either:
  1755         -  **
  1756         -  **    *   We can always do the transfer if the table contains an
  1757         -  **        an integer primary key
  1758         -  **
  1759         -  **    *   We can conditionally do the transfer if the destination
  1760         -  **        table is empty.
         1746  +  /* If we get this far, it means that the xfer optimization is at
         1747  +  ** least a possibility, though it might only work if the destination
         1748  +  ** table (tab1) is initially empty.
  1761   1749     */
  1762   1750   #ifdef SQLITE_TEST
  1763   1751     sqlite3_xferopt_count++;
  1764   1752   #endif
  1765   1753     iDbSrc = sqlite3SchemaToIndex(pParse->db, pSrc->pSchema);
  1766   1754     v = sqlite3GetVdbe(pParse);
  1767   1755     sqlite3CodeVerifySchema(pParse, iDbSrc);
  1768   1756     iSrc = pParse->nTab++;
  1769   1757     iDest = pParse->nTab++;
  1770   1758     regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
  1771   1759     sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
  1772         -  if( (pDest->iPKey<0 && pDest->pIndex!=0) || destHasUniqueIdx ){
  1773         -    /* If tables do not have an INTEGER PRIMARY KEY and there
  1774         -    ** are indices to be copied and the destination is not empty,
  1775         -    ** we have to disallow the transfer optimization because the
  1776         -    ** the rowids might change which will mess up indexing.
         1760  +  if( (pDest->iPKey<0 && pDest->pIndex!=0)          /* (1) */
         1761  +   || destHasUniqueIdx                              /* (2) */
         1762  +   || (onError!=OE_Abort && onError!=OE_Rollback)   /* (3) */
         1763  +  ){
         1764  +    /* In some circumstances, we are able to run the xfer optimization
         1765  +    ** only if the destination table is initially empty.  This code makes
         1766  +    ** that determination.  Conditions under which the destination must
         1767  +    ** be empty:
         1768  +    **
         1769  +    ** (1) There is no INTEGER PRIMARY KEY but there are indices.
         1770  +    **     (If the destination is not initially empty, the rowid fields
         1771  +    **     of index entries might need to change.)
         1772  +    **
         1773  +    ** (2) The destination has a unique index.  (The xfer optimization 
         1774  +    **     is unable to test uniqueness.)
  1777   1775       **
  1778         -    ** Or if the destination has a UNIQUE index and is not empty,
  1779         -    ** we also disallow the transfer optimization because we cannot
  1780         -    ** insure that all entries in the union of DEST and SRC will be
  1781         -    ** unique.
         1776  +    ** (3) onError is something other than OE_Abort and OE_Rollback.
  1782   1777       */
  1783   1778       addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
  1784   1779       emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
  1785   1780       sqlite3VdbeJumpHere(v, addr1);
  1786   1781     }else{
  1787   1782       emptyDestTest = 0;
  1788   1783     }

Changes to src/main.c.

   364    364         sqlite3GlobalConfig.pPage = va_arg(ap, void*);
   365    365         sqlite3GlobalConfig.szPage = va_arg(ap, int);
   366    366         sqlite3GlobalConfig.nPage = va_arg(ap, int);
   367    367         break;
   368    368       }
   369    369   
   370    370       case SQLITE_CONFIG_PCACHE: {
   371         -      /* Specify an alternative page cache implementation */
   372         -      sqlite3GlobalConfig.pcache = *va_arg(ap, sqlite3_pcache_methods*);
          371  +      /* no-op */
   373    372         break;
   374    373       }
   375         -
   376    374       case SQLITE_CONFIG_GETPCACHE: {
   377         -      if( sqlite3GlobalConfig.pcache.xInit==0 ){
          375  +      /* now an error */
          376  +      rc = SQLITE_ERROR;
          377  +      break;
          378  +    }
          379  +
          380  +    case SQLITE_CONFIG_PCACHE2: {
          381  +      /* Specify an alternative page cache implementation */
          382  +      sqlite3GlobalConfig.pcache2 = *va_arg(ap, sqlite3_pcache_methods2*);
          383  +      break;
          384  +    }
          385  +    case SQLITE_CONFIG_GETPCACHE2: {
          386  +      if( sqlite3GlobalConfig.pcache2.xInit==0 ){
   378    387           sqlite3PCacheSetDefault();
   379    388         }
   380         -      *va_arg(ap, sqlite3_pcache_methods*) = sqlite3GlobalConfig.pcache;
          389  +      *va_arg(ap, sqlite3_pcache_methods2*) = sqlite3GlobalConfig.pcache2;
   381    390         break;
   382    391       }
   383    392   
   384    393   #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
   385    394       case SQLITE_CONFIG_HEAP: {
   386    395         /* Designate a buffer for heap memory space */
   387    396         sqlite3GlobalConfig.pHeap = va_arg(ap, void*);
................................................................................
   472    481     /* Free any existing lookaside buffer for this handle before
   473    482     ** allocating a new one so we don't have to have space for 
   474    483     ** both at the same time.
   475    484     */
   476    485     if( db->lookaside.bMalloced ){
   477    486       sqlite3_free(db->lookaside.pStart);
   478    487     }
   479         -  /* The size of a lookaside slot needs to be larger than a pointer
   480         -  ** to be useful.
          488  +  /* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
          489  +  ** than a pointer to be useful.
   481    490     */
          491  +  sz = ROUNDDOWN8(sz);  /* IMP: R-33038-09382 */
   482    492     if( sz<=(int)sizeof(LookasideSlot*) ) sz = 0;
   483    493     if( cnt<0 ) cnt = 0;
   484    494     if( sz==0 || cnt==0 ){
   485    495       sz = 0;
   486    496       pStart = 0;
   487    497     }else if( pBuf==0 ){
   488         -    sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
   489    498       sqlite3BeginBenignMalloc();
   490    499       pStart = sqlite3Malloc( sz*cnt );  /* IMP: R-61949-35727 */
   491    500       sqlite3EndBenignMalloc();
          501  +    if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
   492    502     }else{
   493         -    sz = ROUNDDOWN8(sz); /* IMP: R-33038-09382 */
   494    503       pStart = pBuf;
   495    504     }
   496    505     db->lookaside.pStart = pStart;
   497    506     db->lookaside.pFree = 0;
   498    507     db->lookaside.sz = (u16)sz;
   499    508     if( pStart ){
   500    509       int i;
................................................................................
   519    528   
   520    529   /*
   521    530   ** Return the mutex associated with a database connection.
   522    531   */
   523    532   sqlite3_mutex *sqlite3_db_mutex(sqlite3 *db){
   524    533     return db->mutex;
   525    534   }
          535  +
          536  +/*
          537  +** Free up as much memory as we can from the given database
          538  +** connection.
          539  +*/
          540  +int sqlite3_db_release_memory(sqlite3 *db){
          541  +  int i;
          542  +  sqlite3BtreeEnterAll(db);
          543  +  for(i=0; i<db->nDb; i++){
          544  +    Btree *pBt = db->aDb[i].pBt;
          545  +    if( pBt ){
          546  +      Pager *pPager = sqlite3BtreePager(pBt);
          547  +      sqlite3PagerShrink(pPager);
          548  +    }
          549  +  }
          550  +  sqlite3BtreeLeaveAll(db);
          551  +  return SQLITE_OK;
          552  +}
   526    553   
   527    554   /*
   528    555   ** Configuration settings for an individual database connection
   529    556   */
   530    557   int sqlite3_db_config(sqlite3 *db, int op, ...){
   531    558     va_list ap;
   532    559     int rc;
................................................................................
  1631   1658   ** Create a new collating function for database "db".  The name is zName
  1632   1659   ** and the encoding is enc.
  1633   1660   */
  1634   1661   static int createCollation(
  1635   1662     sqlite3* db,
  1636   1663     const char *zName, 
  1637   1664     u8 enc,
  1638         -  u8 collType,
  1639   1665     void* pCtx,
  1640   1666     int(*xCompare)(void*,int,const void*,int,const void*),
  1641   1667     void(*xDel)(void*)
  1642   1668   ){
  1643   1669     CollSeq *pColl;
  1644   1670     int enc2;
  1645   1671     int nName = sqlite3Strlen30(zName);
................................................................................
  1696   1722   
  1697   1723     pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 1);
  1698   1724     if( pColl==0 ) return SQLITE_NOMEM;
  1699   1725     pColl->xCmp = xCompare;
  1700   1726     pColl->pUser = pCtx;
  1701   1727     pColl->xDel = xDel;
  1702   1728     pColl->enc = (u8)(enc2 | (enc & SQLITE_UTF16_ALIGNED));
  1703         -  pColl->type = collType;
  1704   1729     sqlite3Error(db, SQLITE_OK, 0);
  1705   1730     return SQLITE_OK;
  1706   1731   }
  1707   1732   
  1708   1733   
  1709   1734   /*
  1710   1735   ** This array defines hard upper bounds on limit values.  The
................................................................................
  2171   2196     sqlite3HashInit(&db->aModule);
  2172   2197   #endif
  2173   2198   
  2174   2199     /* Add the default collation sequence BINARY. BINARY works for both UTF-8
  2175   2200     ** and UTF-16, so add a version for each to avoid any unnecessary
  2176   2201     ** conversions. The only error that can occur here is a malloc() failure.
  2177   2202     */
  2178         -  createCollation(db, "BINARY", SQLITE_UTF8, SQLITE_COLL_BINARY, 0,
  2179         -                  binCollFunc, 0);
  2180         -  createCollation(db, "BINARY", SQLITE_UTF16BE, SQLITE_COLL_BINARY, 0,
  2181         -                  binCollFunc, 0);
  2182         -  createCollation(db, "BINARY", SQLITE_UTF16LE, SQLITE_COLL_BINARY, 0,
  2183         -                  binCollFunc, 0);
  2184         -  createCollation(db, "RTRIM", SQLITE_UTF8, SQLITE_COLL_USER, (void*)1,
  2185         -                  binCollFunc, 0);
         2203  +  createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0);
         2204  +  createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0);
         2205  +  createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0);
         2206  +  createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0);
  2186   2207     if( db->mallocFailed ){
  2187   2208       goto opendb_out;
  2188   2209     }
  2189   2210     db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 0);
  2190   2211     assert( db->pDfltColl!=0 );
  2191   2212   
  2192   2213     /* Also add a UTF-8 case-insensitive collation sequence. */
  2193         -  createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0,
  2194         -                  nocaseCollatingFunc, 0);
         2214  +  createCollation(db, "NOCASE", SQLITE_UTF8, 0, nocaseCollatingFunc, 0);
  2195   2215   
  2196   2216     /* Parse the filename/URI argument. */
  2197   2217     db->openFlags = flags;
  2198   2218     rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg);
  2199   2219     if( rc!=SQLITE_OK ){
  2200   2220       if( rc==SQLITE_NOMEM ) db->mallocFailed = 1;
  2201   2221       sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg);
................................................................................
  2396   2416     int enc, 
  2397   2417     void* pCtx,
  2398   2418     int(*xCompare)(void*,int,const void*,int,const void*)
  2399   2419   ){
  2400   2420     int rc;
  2401   2421     sqlite3_mutex_enter(db->mutex);
  2402   2422     assert( !db->mallocFailed );
  2403         -  rc = createCollation(db, zName, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
         2423  +  rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, 0);
  2404   2424     rc = sqlite3ApiExit(db, rc);
  2405   2425     sqlite3_mutex_leave(db->mutex);
  2406   2426     return rc;
  2407   2427   }
  2408   2428   
  2409   2429   /*
  2410   2430   ** Register a new collation sequence with the database handle db.
................................................................................
  2416   2436     void* pCtx,
  2417   2437     int(*xCompare)(void*,int,const void*,int,const void*),
  2418   2438     void(*xDel)(void*)
  2419   2439   ){
  2420   2440     int rc;
  2421   2441     sqlite3_mutex_enter(db->mutex);
  2422   2442     assert( !db->mallocFailed );
  2423         -  rc = createCollation(db, zName, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, xDel);
         2443  +  rc = createCollation(db, zName, (u8)enc, pCtx, xCompare, xDel);
  2424   2444     rc = sqlite3ApiExit(db, rc);
  2425   2445     sqlite3_mutex_leave(db->mutex);
  2426   2446     return rc;
  2427   2447   }
  2428   2448   
  2429   2449   #ifndef SQLITE_OMIT_UTF16
  2430   2450   /*
................................................................................
  2439   2459   ){
  2440   2460     int rc = SQLITE_OK;
  2441   2461     char *zName8;
  2442   2462     sqlite3_mutex_enter(db->mutex);
  2443   2463     assert( !db->mallocFailed );
  2444   2464     zName8 = sqlite3Utf16to8(db, zName, -1, SQLITE_UTF16NATIVE);
  2445   2465     if( zName8 ){
  2446         -    rc = createCollation(db, zName8, (u8)enc, SQLITE_COLL_USER, pCtx, xCompare, 0);
         2466  +    rc = createCollation(db, zName8, (u8)enc, pCtx, xCompare, 0);
  2447   2467       sqlite3DbFree(db, zName8);
  2448   2468     }
  2449   2469     rc = sqlite3ApiExit(db, rc);
  2450   2470     sqlite3_mutex_leave(db->mutex);
  2451   2471     return rc;
  2452   2472   }
  2453   2473   #endif /* SQLITE_OMIT_UTF16 */
................................................................................
  2922   2942         const char *zWord = va_arg(ap, const char*);
  2923   2943         int n = sqlite3Strlen30(zWord);
  2924   2944         rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0;
  2925   2945         break;
  2926   2946       }
  2927   2947   #endif 
  2928   2948   
  2929         -    /* sqlite3_test_control(SQLITE_TESTCTRL_PGHDRSZ)
  2930         -    **
  2931         -    ** Return the size of a pcache header in bytes.
  2932         -    */
  2933         -    case SQLITE_TESTCTRL_PGHDRSZ: {
  2934         -      rc = sizeof(PgHdr);
  2935         -      break;
  2936         -    }
  2937         -
  2938   2949       /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
  2939   2950       **
  2940   2951       ** Pass pFree into sqlite3ScratchFree(). 
  2941   2952       ** If sz>0 then allocate a scratch buffer into pNew.  
  2942   2953       */
  2943   2954       case SQLITE_TESTCTRL_SCRATCHMALLOC: {
  2944   2955         void *pFree, **ppNew;
................................................................................
  2982   2993   const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam){
  2983   2994     zFilename += sqlite3Strlen30(zFilename) + 1;
  2984   2995     while( zFilename[0] ){
  2985   2996       int x = strcmp(zFilename, zParam);
  2986   2997       zFilename += sqlite3Strlen30(zFilename) + 1;
  2987   2998       if( x==0 ) return zFilename;
  2988   2999       zFilename += sqlite3Strlen30(zFilename) + 1;
         3000  +  }
         3001  +  return 0;
         3002  +}
         3003  +
         3004  +/*
         3005  +** Return the filename of the database associated with a database
         3006  +** connection.
         3007  +*/
         3008  +const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName){
         3009  +  int i;
         3010  +  for(i=0; i<db->nDb; i++){
         3011  +    if( db->aDb[i].pBt && sqlite3StrICmp(zDbName, db->aDb[i].zName)==0 ){
         3012  +      return sqlite3BtreeGetFilename(db->aDb[i].pBt);
         3013  +    }
  2989   3014     }
  2990   3015     return 0;
  2991   3016   }
  2992   3017   
  2993   3018   #if (SQLITE_ENABLE_APPLE_SPI>0) && defined(__APPLE__)
  2994   3019   
  2995   3020   #include "sqlite3_private.h"

Changes to src/os.c.

    23     23   ** from within OsOpen()), but some third-party implementations may.
    24     24   ** So we test the effects of a malloc() failing and the sqlite3OsXXX()
    25     25   ** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro.
    26     26   **
    27     27   ** The following functions are instrumented for malloc() failure 
    28     28   ** testing:
    29     29   **
    30         -**     sqlite3OsOpen()
    31     30   **     sqlite3OsRead()
    32     31   **     sqlite3OsWrite()
    33     32   **     sqlite3OsSync()
           33  +**     sqlite3OsFileSize()
    34     34   **     sqlite3OsLock()
           35  +**     sqlite3OsCheckReservedLock()
           36  +**     sqlite3OsFileControl()
           37  +**     sqlite3OsShmMap()
           38  +**     sqlite3OsOpen()
           39  +**     sqlite3OsDelete()
           40  +**     sqlite3OsAccess()
           41  +**     sqlite3OsFullPathname()
    35     42   **
    36     43   */
    37     44   #if defined(SQLITE_TEST)
    38     45   int sqlite3_memdebug_vfs_oom_test = 1;
    39     46     #define DO_OS_MALLOC_TEST(x)                                       \
    40     47     if (sqlite3_memdebug_vfs_oom_test && (!x || !sqlite3IsMemJournal(x))) {  \
    41     48       void *pTstAlloc = sqlite3Malloc(10);                             \
................................................................................
    87     94     return id->pMethods->xUnlock(id, lockType);
    88     95   }
    89     96   int sqlite3OsCheckReservedLock(sqlite3_file *id, int *pResOut){
    90     97     DO_OS_MALLOC_TEST(id);
    91     98     return id->pMethods->xCheckReservedLock(id, pResOut);
    92     99   }
    93    100   int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
          101  +  DO_OS_MALLOC_TEST(id);
    94    102     return id->pMethods->xFileControl(id, op, pArg);
    95    103   }
    96    104   int sqlite3OsSectorSize(sqlite3_file *id){
    97    105     int (*xSectorSize)(sqlite3_file*) = id->pMethods->xSectorSize;
    98    106     return (xSectorSize ? xSectorSize(id) : SQLITE_DEFAULT_SECTOR_SIZE);
    99    107   }
   100    108   int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
................................................................................
   112    120   int sqlite3OsShmMap(
   113    121     sqlite3_file *id,               /* Database file handle */
   114    122     int iPage,
   115    123     int pgsz,
   116    124     int bExtend,                    /* True to extend file if necessary */
   117    125     void volatile **pp              /* OUT: Pointer to mapping */
   118    126   ){
          127  +  DO_OS_MALLOC_TEST(id);
   119    128     return id->pMethods->xShmMap(id, iPage, pgsz, bExtend, pp);
   120    129   }
   121    130   
   122    131   /*
   123    132   ** The next group of routines are convenience wrappers around the
   124    133   ** VFS methods.
   125    134   */
................................................................................
   143    152     openFlags = flags & 0x87f7f;
   144    153   #endif
   145    154     rc = pVfs->xOpen(pVfs, zPath, pFile, openFlags, pFlagsOut);
   146    155     assert( rc==SQLITE_OK || pFile->pMethods==0 );
   147    156     return rc;
   148    157   }
   149    158   int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
          159  +  DO_OS_MALLOC_TEST(0);
   150    160     return pVfs->xDelete(pVfs, zPath, dirSync);
   151    161   }
   152    162   int sqlite3OsAccess(
   153    163     sqlite3_vfs *pVfs, 
   154    164     const char *zPath, 
   155    165     int flags, 
   156    166     int *pResOut
................................................................................
   160    170   }
   161    171   int sqlite3OsFullPathname(
   162    172     sqlite3_vfs *pVfs, 
   163    173     const char *zPath, 
   164    174     int nPathOut, 
   165    175     char *zPathOut
   166    176   ){
          177  +  DO_OS_MALLOC_TEST(0);
   167    178     zPathOut[0] = 0;
   168    179     return pVfs->xFullPathname(pVfs, zPath, nPathOut, zPathOut);
   169    180   }
   170    181   #ifndef SQLITE_OMIT_LOAD_EXTENSION
   171    182   void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
   172    183     return pVfs->xDlOpen(pVfs, zPath);
   173    184   }

Changes to src/os.h.

    61     61   # endif
    62     62   #else
    63     63   # ifndef SQLITE_OS_WIN
    64     64   #  define SQLITE_OS_WIN 0
    65     65   # endif
    66     66   #endif
    67     67   
           68  +/*
           69  +** Determine if we are dealing with Windows NT.
           70  +*/
           71  +#if defined(_WIN32_WINNT)
           72  +# define SQLITE_OS_WINNT 1
           73  +#else
           74  +# define SQLITE_OS_WINNT 0
           75  +#endif
           76  +
    68     77   /*
    69     78   ** Determine if we are dealing with WindowsCE - which has a much
    70     79   ** reduced API.
    71     80   */
    72     81   #if defined(_WIN32_WCE)
    73     82   # define SQLITE_OS_WINCE 1
    74     83   #else

Changes to src/os_unix.c.

   693    693   
   694    694     { "unlink",       (sqlite3_syscall_ptr)unlink,           0 },
   695    695   #define osUnlink    ((int(*)(const char*))aSyscall[16].pCurrent)
   696    696   
   697    697     { "openDirectory",    (sqlite3_syscall_ptr)openDirectory,      0 },
   698    698   #define osOpenDirectory ((int(*)(const char*,int*))aSyscall[17].pCurrent)
   699    699   
          700  +  { "mkdir",        (sqlite3_syscall_ptr)mkdir,           0 },
          701  +#define osMkdir     ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
          702  +
          703  +  { "rmdir",        (sqlite3_syscall_ptr)rmdir,           0 },
          704  +#define osRmdir     ((int(*)(const char*))aSyscall[19].pCurrent)
          705  +
   700    706   }; /* End of the overrideable system calls */
   701    707   
   702    708   /*
   703    709   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
   704    710   ** "unix" VFSes.  Return SQLITE_OK opon successfully updating the
   705    711   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
   706    712   ** system call named zName.
................................................................................
  2202   2208   /******************* End of the no-op lock implementation *********************
  2203   2209   ******************************************************************************/
  2204   2210   
  2205   2211   /******************************************************************************
  2206   2212   ************************* Begin dot-file Locking ******************************
  2207   2213   **
  2208   2214   ** The dotfile locking implementation uses the existance of separate lock
  2209         -** files in order to control access to the database.  This works on just
  2210         -** about every filesystem imaginable.  But there are serious downsides:
         2215  +** files (really a directory) to control access to the database.  This works
         2216  +** on just about every filesystem imaginable.  But there are serious downsides:
  2211   2217   **
  2212   2218   **    (1)  There is zero concurrency.  A single reader blocks all other
  2213   2219   **         connections from reading or writing the database.
  2214   2220   **
  2215   2221   **    (2)  An application crash or power loss can leave stale lock files
  2216   2222   **         sitting around that need to be cleared manually.
  2217   2223   **
  2218   2224   ** Nevertheless, a dotlock is an appropriate locking mode for use if no
  2219   2225   ** other locking strategy is available.
  2220   2226   **
  2221         -** Dotfile locking works by creating a file in the same directory as the
  2222         -** database and with the same name but with a ".lock" extension added.
  2223         -** The existance of a lock file implies an EXCLUSIVE lock.  All other lock
  2224         -** types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE.
         2227  +** Dotfile locking works by creating a subdirectory in the same directory as
         2228  +** the database and with the same name but with a ".lock" extension added.
         2229  +** The existance of a lock directory implies an EXCLUSIVE lock.  All other
         2230  +** lock types (SHARED, RESERVED, PENDING) are mapped into EXCLUSIVE.
  2225   2231   */
  2226   2232   
  2227   2233   /*
  2228   2234   ** The file suffix added to the data base filename in order to create the
  2229         -** lock file.
         2235  +** lock directory.
  2230   2236   */
  2231   2237   #define DOTLOCK_SUFFIX ".lock"
  2232   2238   
  2233   2239   /*
  2234   2240   ** This routine checks if there is a RESERVED lock held on the specified
  2235   2241   ** file by this or any other process. If such a lock is held, set *pResOut
  2236   2242   ** to a non-zero value otherwise *pResOut is set to zero.  The return value
................................................................................
  2289   2295   ** routine to lower a locking level.
  2290   2296   **
  2291   2297   ** With dotfile locking, we really only support state (4): EXCLUSIVE.
  2292   2298   ** But we track the other locking levels internally.
  2293   2299   */
  2294   2300   static int dotlockLock(sqlite3_file *id, int eFileLock) {
  2295   2301     unixFile *pFile = (unixFile*)id;
  2296         -  int fd;
  2297   2302     char *zLockFile = (char *)pFile->lockingContext;
  2298   2303     int rc = SQLITE_OK;
  2299   2304   
  2300   2305   
  2301   2306     /* If we have any lock, then the lock file already exists.  All we have
  2302   2307     ** to do is adjust our internal record of the lock level.
  2303   2308     */
................................................................................
  2309   2314   #else
  2310   2315       utimes(zLockFile, NULL);
  2311   2316   #endif
  2312   2317       return SQLITE_OK;
  2313   2318     }
  2314   2319     
  2315   2320     /* grab an exclusive lock */
  2316         -  fd = robust_open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600);
  2317         -  if( fd<0 ){
  2318         -    /* failed to open/create the file, someone else may have stolen the lock */
         2321  +  rc = osMkdir(zLockFile, 0777);
         2322  +  if( rc<0 ){
         2323  +    /* failed to open/create the lock directory */
  2319   2324       int tErrno = errno;
  2320   2325       if( EEXIST == tErrno ){
  2321   2326         rc = SQLITE_BUSY;
  2322   2327       } else {
  2323   2328         rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK);
  2324   2329         if( IS_LOCK_ERROR(rc) ){
  2325   2330           pFile->lastErrno = tErrno;
  2326   2331         }
  2327   2332       }
  2328   2333       return rc;
  2329   2334     } 
  2330         -#if OSCLOSE_CHECK_CLOSE_IOERR
  2331         -  if( close(fd) ){
  2332         -    pFile->lastErrno = errno;
  2333         -    rc = SQLITE_IOERR_CLOSE;
  2334         -  }
  2335         -#else
  2336         -  robust_close(pFile, fd, __LINE__);
  2337         -#endif
  2338   2335     
  2339   2336     /* got it, set the type and return ok */
  2340   2337     pFile->eFileLock = eFileLock;
  2341   2338     return rc;
  2342   2339   }
  2343   2340   
  2344   2341   /*
................................................................................
  2349   2346   ** the requested locking level, this routine is a no-op.
  2350   2347   **
  2351   2348   ** When the locking level reaches NO_LOCK, delete the lock file.
  2352   2349   */
  2353   2350   static int dotlockUnlock(sqlite3_file *id, int eFileLock) {
  2354   2351     unixFile *pFile = (unixFile*)id;
  2355   2352     char *zLockFile = (char *)pFile->lockingContext;
         2353  +  int rc;
  2356   2354   
  2357   2355     assert( pFile );
  2358   2356     OSTRACE(("UNLOCK  %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock,
  2359   2357   	   pFile->eFileLock, getpid()));
  2360   2358     assert( eFileLock<=SHARED_LOCK );
  2361   2359     
  2362   2360     /* no-op if possible */
................................................................................
  2370   2368     if( eFileLock==SHARED_LOCK ){
  2371   2369       pFile->eFileLock = SHARED_LOCK;
  2372   2370       return SQLITE_OK;
  2373   2371     }
  2374   2372     
  2375   2373     /* To fully unlock the database, delete the lock file */
  2376   2374     assert( eFileLock==NO_LOCK );
  2377         -  if( osUnlink(zLockFile) ){
         2375  +  rc = osRmdir(zLockFile);
         2376  +  if( rc<0 && errno==ENOTDIR ) rc = osUnlink(zLockFile);
         2377  +  if( rc<0 ){
  2378   2378       int rc = 0;
  2379   2379       int tErrno = errno;
  2380   2380       if( ENOENT != tErrno ){
  2381   2381   #if OSLOCKING_CHECK_BUSY_IOERR
  2382   2382         rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
  2383   2383   #else
  2384   2384         rc = SQLITE_IOERR_UNLOCK;
................................................................................
  3316   3316   ** See tickets #2741 and #2681.
  3317   3317   **
  3318   3318   ** To avoid stomping the errno value on a failed read the lastErrno value
  3319   3319   ** is set before returning.
  3320   3320   */
  3321   3321   static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
  3322   3322     int got;
         3323  +  int prior = 0;
  3323   3324   #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
  3324   3325     i64 newOffset;
  3325   3326   #endif
  3326   3327     TIMER_START;
         3328  +  do{
  3327   3329   #if defined(USE_PREAD)
  3328         -  do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
  3329         -  SimulateIOError( got = -1 );
         3330  +    got = osPread(id->h, pBuf, cnt, offset);
         3331  +    SimulateIOError( got = -1 );
  3330   3332   #elif defined(USE_PREAD64)
  3331         -  do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR);
  3332         -  SimulateIOError( got = -1 );
         3333  +    got = osPread64(id->h, pBuf, cnt, offset);
         3334  +    SimulateIOError( got = -1 );
  3333   3335   #else
  3334         -  newOffset = lseek(id->h, offset, SEEK_SET);
  3335         -  SimulateIOError( newOffset-- );
  3336         -  if( newOffset!=offset ){
  3337         -    if( newOffset == -1 ){
         3336  +    newOffset = lseek(id->h, offset, SEEK_SET);
         3337  +    SimulateIOError( newOffset-- );
         3338  +    if( newOffset!=offset ){
         3339  +      if( newOffset == -1 ){
         3340  +        ((unixFile*)id)->lastErrno = errno;
         3341  +      }else{
         3342  +        ((unixFile*)id)->lastErrno = 0;			
         3343  +      }
         3344  +      return -1;
         3345  +    }
         3346  +    got = osRead(id->h, pBuf, cnt);
         3347  +#endif
         3348  +    if( got==cnt ) break;
         3349  +    if( got<0 ){
         3350  +      if( errno==EINTR ){ got = 1; continue; }
         3351  +      prior = 0;
  3338   3352         ((unixFile*)id)->lastErrno = errno;
  3339         -    }else{
  3340         -      ((unixFile*)id)->lastErrno = 0;			
         3353  +      break;
         3354  +    }else if( got>0 ){
         3355  +      cnt -= got;
         3356  +      offset += got;
         3357  +      prior += got;
         3358  +      pBuf = (void*)(got + (char*)pBuf);
  3341   3359       }
  3342         -    return -1;
  3343         -  }
  3344         -  do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
  3345         -#endif
         3360  +  }while( got>0 );
  3346   3361     TIMER_END;
  3347         -  if( got<0 ){
  3348         -    ((unixFile*)id)->lastErrno = errno;
  3349         -  }
  3350         -  OSTRACE(("READ    %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED));
  3351         -  return got;
         3362  +  OSTRACE(("READ    %-3d %5d %7lld %llu\n",
         3363  +            id->h, got+prior, offset-prior, TIMER_ELAPSED));
         3364  +  return got+prior;
  3352   3365   }
  3353   3366   
  3354   3367   /*
  3355   3368   ** Read data from a file into a buffer.  Return SQLITE_OK if all
  3356   3369   ** bytes were read successfully and SQLITE_IOERR if anything goes
  3357   3370   ** wrong.
  3358   3371   */
................................................................................
  6611   6624     buf[0] = lockPath[0];
  6612   6625     for( i=1; i<len; i++ ){
  6613   6626       if( lockPath[i] == '/' && (i - start > 0) ){
  6614   6627         /* only mkdir if leaf dir != "." or "/" or ".." */
  6615   6628         if( i-start>2 || (i-start==1 && buf[start] != '.' && buf[start] != '/') 
  6616   6629            || (i-start==2 && buf[start] != '.' && buf[start+1] != '.') ){
  6617   6630           buf[i]='\0';
  6618         -        if( mkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){
         6631  +        if( osMkdir(buf, SQLITE_DEFAULT_PROXYDIR_PERMISSIONS) ){
  6619   6632             int err=errno;
  6620   6633             if( err!=EEXIST ) {
  6621   6634               OSTRACE(("CREATELOCKPATH  FAILED creating %s, "
  6622   6635                        "'%s' proxy lock path=%s pid=%d\n",
  6623   6636                        buf, strerror(err), lockPath, getpid()));
  6624   6637               return err;
  6625   6638             }
................................................................................
  7697   7710       UNIXVFS("unix-proxy",    proxyIoFinder ),
  7698   7711   #endif
  7699   7712     };
  7700   7713     unsigned int i;          /* Loop counter */
  7701   7714   
  7702   7715     /* Double-check that the aSyscall[] array has been constructed
  7703   7716     ** correctly.  See ticket [bb3a86e890c8e96ab] */
  7704         -  assert( ArraySize(aSyscall)==18 );
         7717  +  assert( ArraySize(aSyscall)==20 );
  7705   7718   
  7706   7719     /* Register all VFSes defined in the aVfs[] array */
  7707   7720     for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
  7708   7721       sqlite3_vfs_register(&aVfs[i], i==0);
  7709   7722     }
  7710   7723     return SQLITE_OK; 
  7711   7724   }

Changes to src/os_win.c.

     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         -** This file contains code that is specific to windows.
           13  +** This file contains code that is specific to Windows.
    14     14   */
    15     15   #include "sqliteInt.h"
    16         -#if SQLITE_OS_WIN               /* This file is used for windows only */
    17         -
    18         -
    19         -/*
    20         -** A Note About Memory Allocation:
    21         -**
    22         -** This driver uses malloc()/free() directly rather than going through
    23         -** the SQLite-wrappers sqlite3_malloc()/sqlite3_free().  Those wrappers
    24         -** are designed for use on embedded systems where memory is scarce and
    25         -** malloc failures happen frequently.  Win32 does not typically run on
    26         -** embedded systems, and when it does the developers normally have bigger
    27         -** problems to worry about than running out of memory.  So there is not
    28         -** a compelling need to use the wrappers.
    29         -**
    30         -** But there is a good reason to not use the wrappers.  If we use the
    31         -** wrappers then we will get simulated malloc() failures within this
    32         -** driver.  And that causes all kinds of problems for our tests.  We
    33         -** could enhance SQLite to deal with simulated malloc failures within
    34         -** the OS driver, but the code to deal with those failure would not
    35         -** be exercised on Linux (which does not need to malloc() in the driver)
    36         -** and so we would have difficulty writing coverage tests for that
    37         -** code.  Better to leave the code out, we think.
    38         -**
    39         -** The point of this discussion is as follows:  When creating a new
    40         -** OS layer for an embedded system, if you use this file as an example,
    41         -** avoid the use of malloc()/free().  Those routines work ok on windows
    42         -** desktops but not so well in embedded systems.
    43         -*/
    44         -
    45         -#include <winbase.h>
           16  +#if SQLITE_OS_WIN               /* This file is used for Windows only */
    46     17   
    47     18   #ifdef __CYGWIN__
    48     19   # include <sys/cygwin.h>
    49     20   #endif
    50     21   
    51         -/*
    52         -** Macros used to determine whether or not to use threads.
    53         -*/
    54         -#if defined(THREADSAFE) && THREADSAFE
    55         -# define SQLITE_W32_THREADS 1
    56         -#endif
    57         -
    58     22   /*
    59     23   ** Include code that is common to all os_*.c files
    60     24   */
    61     25   #include "os_common.h"
    62     26   
    63     27   /*
    64         -** Some microsoft compilers lack this definition.
           28  +** Some Microsoft compilers lack this definition.
    65     29   */
    66     30   #ifndef INVALID_FILE_ATTRIBUTES
    67     31   # define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 
    68     32   #endif
    69     33   
    70         -/*
    71         -** Determine if we are dealing with WindowsCE - which has a much
    72         -** reduced API.
    73         -*/
    74         -#if SQLITE_OS_WINCE
    75         -# define AreFileApisANSI() 1
    76         -# define FormatMessageW(a,b,c,d,e,f,g) 0
    77         -#endif
    78         -
    79     34   /* Forward references */
    80     35   typedef struct winShm winShm;           /* A connection to shared-memory */
    81     36   typedef struct winShmNode winShmNode;   /* A region of shared-memory */
    82     37   
    83     38   /*
    84     39   ** WinCE lacks native support for file locking so we have to fake it
    85     40   ** with some code of our own.
................................................................................
   107     62     u8 bPersistWal;         /* True to persist WAL files */
   108     63     DWORD lastErrno;        /* The Windows errno from the last I/O error */
   109     64     DWORD sectorSize;       /* Sector size of the device file is on */
   110     65     winShm *pShm;           /* Instance of shared memory on this file */
   111     66     const char *zPath;      /* Full pathname of this file */
   112     67     int szChunk;            /* Chunk size configured by FCNTL_CHUNK_SIZE */
   113     68   #if SQLITE_OS_WINCE
   114         -  WCHAR *zDeleteOnClose;  /* Name of file to delete when closing */
           69  +  LPWSTR zDeleteOnClose;  /* Name of file to delete when closing */
   115     70     HANDLE hMutex;          /* Mutex used to control access to shared lock */  
   116     71     HANDLE hShared;         /* Shared memory segment used for locking */
   117     72     winceLock local;        /* Locks obtained by this instance of winFile */
   118     73     winceLock *shared;      /* Global shared lock memory for the file  */
   119     74   #endif
   120     75   };
   121     76   
................................................................................
   196    151   static int getSectorSize(
   197    152       sqlite3_vfs *pVfs,
   198    153       const char *zRelative     /* UTF-8 file name */
   199    154   );
   200    155   
   201    156   /*
   202    157   ** The following variable is (normally) set once and never changes
   203         -** thereafter.  It records whether the operating system is Win95
          158  +** thereafter.  It records whether the operating system is Win9x
   204    159   ** or WinNT.
   205    160   **
   206    161   ** 0:   Operating system unknown.
   207         -** 1:   Operating system is Win95.
          162  +** 1:   Operating system is Win9x.
   208    163   ** 2:   Operating system is WinNT.
   209    164   **
   210    165   ** In order to facilitate testing on a WinNT system, the test fixture
   211    166   ** can manually set this value to 1 to emulate Win98 behavior.
   212    167   */
   213    168   #ifdef SQLITE_TEST
   214    169   int sqlite3_os_type = 0;
   215    170   #else
   216    171   static int sqlite3_os_type = 0;
   217    172   #endif
          173  +
          174  +/*
          175  +** Many system calls are accessed through pointer-to-functions so that
          176  +** they may be overridden at runtime to facilitate fault injection during
          177  +** testing and sandboxing.  The following array holds the names and pointers
          178  +** to all overrideable system calls.
          179  +*/
          180  +#if !SQLITE_OS_WINCE
          181  +#  define SQLITE_WIN32_HAS_ANSI
          182  +#endif
          183  +
          184  +#if SQLITE_OS_WINCE || SQLITE_OS_WINNT
          185  +#  define SQLITE_WIN32_HAS_WIDE
          186  +#endif
          187  +
          188  +#ifndef SYSCALL
          189  +#  define SYSCALL sqlite3_syscall_ptr
          190  +#endif
          191  +
          192  +#if SQLITE_OS_WINCE
          193  +/*
          194  +** These macros are necessary because Windows CE does not natively support the
          195  +** Win32 APIs LockFile, UnlockFile, and LockFileEx.
          196  + */
          197  +
          198  +#  define LockFile(a,b,c,d,e)       winceLockFile(&a, b, c, d, e)
          199  +#  define UnlockFile(a,b,c,d,e)     winceUnlockFile(&a, b, c, d, e)
          200  +#  define LockFileEx(a,b,c,d,e,f)   winceLockFileEx(&a, b, c, d, e, f)
          201  +
          202  +/*
          203  +** These are the special syscall hacks for Windows CE.  The locking related
          204  +** defines here refer to the macros defined just above.
          205  + */
          206  +
          207  +#  define osAreFileApisANSI()       1
          208  +#  define osLockFile                LockFile
          209  +#  define osUnlockFile              UnlockFile
          210  +#  define osLockFileEx              LockFileEx
          211  +#endif
          212  +
          213  +static struct win_syscall {
          214  +  const char *zName;            /* Name of the sytem call */
          215  +  sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
          216  +  sqlite3_syscall_ptr pDefault; /* Default value */
          217  +} aSyscall[] = {
          218  +#if !SQLITE_OS_WINCE
          219  +  { "AreFileApisANSI",         (SYSCALL)AreFileApisANSI,         0 },
          220  +
          221  +#define osAreFileApisANSI ((BOOL(WINAPI*)(VOID))aSyscall[0].pCurrent)
          222  +#else
          223  +  { "AreFileApisANSI",         (SYSCALL)0,                       0 },
          224  +#endif
          225  +
          226  +#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          227  +  { "CharLowerW",              (SYSCALL)CharLowerW,              0 },
          228  +#else
          229  +  { "CharLowerW",              (SYSCALL)0,                       0 },
          230  +#endif
          231  +
          232  +#define osCharLowerW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[1].pCurrent)
          233  +
          234  +#if SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          235  +  { "CharUpperW",              (SYSCALL)CharUpperW,              0 },
          236  +#else
          237  +  { "CharUpperW",              (SYSCALL)0,                       0 },
          238  +#endif
          239  +
          240  +#define osCharUpperW ((LPWSTR(WINAPI*)(LPWSTR))aSyscall[2].pCurrent)
          241  +
          242  +  { "CloseHandle",             (SYSCALL)CloseHandle,             0 },
          243  +
          244  +#define osCloseHandle ((BOOL(WINAPI*)(HANDLE))aSyscall[3].pCurrent)
          245  +
          246  +#if defined(SQLITE_WIN32_HAS_ANSI)
          247  +  { "CreateFileA",             (SYSCALL)CreateFileA,             0 },
          248  +#else
          249  +  { "CreateFileA",             (SYSCALL)0,                       0 },
          250  +#endif
          251  +
          252  +#define osCreateFileA ((HANDLE(WINAPI*)(LPCSTR,DWORD,DWORD, \
          253  +        LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[4].pCurrent)
          254  +
          255  +#if defined(SQLITE_WIN32_HAS_WIDE)
          256  +  { "CreateFileW",             (SYSCALL)CreateFileW,             0 },
          257  +#else
          258  +  { "CreateFileW",             (SYSCALL)0,                       0 },
          259  +#endif
          260  +
          261  +#define osCreateFileW ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD, \
          262  +        LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE))aSyscall[5].pCurrent)
          263  +
          264  +  { "CreateFileMapping",       (SYSCALL)CreateFileMapping,       0 },
          265  +
          266  +#define osCreateFileMapping ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
          267  +        DWORD,DWORD,DWORD,LPCTSTR))aSyscall[6].pCurrent)
          268  +
          269  +#if defined(SQLITE_WIN32_HAS_WIDE)
          270  +  { "CreateFileMappingW",      (SYSCALL)CreateFileMappingW,      0 },
          271  +#else
          272  +  { "CreateFileMappingW",      (SYSCALL)0,                       0 },
          273  +#endif
          274  +
          275  +#define osCreateFileMappingW ((HANDLE(WINAPI*)(HANDLE,LPSECURITY_ATTRIBUTES, \
          276  +        DWORD,DWORD,DWORD,LPCWSTR))aSyscall[7].pCurrent)
          277  +
          278  +#if defined(SQLITE_WIN32_HAS_WIDE)
          279  +  { "CreateMutexW",            (SYSCALL)CreateMutexW,            0 },
          280  +#else
          281  +  { "CreateMutexW",            (SYSCALL)0,                       0 },
          282  +#endif
          283  +
          284  +#define osCreateMutexW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,BOOL, \
          285  +        LPCWSTR))aSyscall[8].pCurrent)
          286  +
          287  +#if defined(SQLITE_WIN32_HAS_ANSI)
          288  +  { "DeleteFileA",             (SYSCALL)DeleteFileA,             0 },
          289  +#else
          290  +  { "DeleteFileA",             (SYSCALL)0,                       0 },
          291  +#endif
          292  +
          293  +#define osDeleteFileA ((BOOL(WINAPI*)(LPCSTR))aSyscall[9].pCurrent)
          294  +
          295  +#if defined(SQLITE_WIN32_HAS_WIDE)
          296  +  { "DeleteFileW",             (SYSCALL)DeleteFileW,             0 },
          297  +#else
          298  +  { "DeleteFileW",             (SYSCALL)0,                       0 },
          299  +#endif
          300  +
          301  +#define osDeleteFileW ((BOOL(WINAPI*)(LPCWSTR))aSyscall[10].pCurrent)
          302  +
          303  +#if SQLITE_OS_WINCE
          304  +  { "FileTimeToLocalFileTime", (SYSCALL)FileTimeToLocalFileTime, 0 },
          305  +#else
          306  +  { "FileTimeToLocalFileTime", (SYSCALL)0,                       0 },
          307  +#endif
          308  +
          309  +#define osFileTimeToLocalFileTime ((BOOL(WINAPI*)(CONST FILETIME*, \
          310  +        LPFILETIME))aSyscall[11].pCurrent)
          311  +
          312  +#if SQLITE_OS_WINCE
          313  +  { "FileTimeToSystemTime",    (SYSCALL)FileTimeToSystemTime,    0 },
          314  +#else
          315  +  { "FileTimeToSystemTime",    (SYSCALL)0,                       0 },
          316  +#endif
          317  +
          318  +#define osFileTimeToSystemTime ((BOOL(WINAPI*)(CONST FILETIME*, \
          319  +        LPSYSTEMTIME))aSyscall[12].pCurrent)
          320  +
          321  +  { "FlushFileBuffers",        (SYSCALL)FlushFileBuffers,        0 },
          322  +
          323  +#define osFlushFileBuffers ((BOOL(WINAPI*)(HANDLE))aSyscall[13].pCurrent)
          324  +
          325  +#if defined(SQLITE_WIN32_HAS_ANSI)
          326  +  { "FormatMessageA",          (SYSCALL)FormatMessageA,          0 },
          327  +#else
          328  +  { "FormatMessageA",          (SYSCALL)0,                       0 },
          329  +#endif
          330  +
          331  +#define osFormatMessageA ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPSTR, \
          332  +        DWORD,va_list*))aSyscall[14].pCurrent)
          333  +
          334  +#if defined(SQLITE_WIN32_HAS_WIDE)
          335  +  { "FormatMessageW",          (SYSCALL)FormatMessageW,          0 },
          336  +#else
          337  +  { "FormatMessageW",          (SYSCALL)0,                       0 },
          338  +#endif
          339  +
          340  +#define osFormatMessageW ((DWORD(WINAPI*)(DWORD,LPCVOID,DWORD,DWORD,LPWSTR, \
          341  +        DWORD,va_list*))aSyscall[15].pCurrent)
          342  +
          343  +  { "FreeLibrary",             (SYSCALL)FreeLibrary,             0 },
          344  +
          345  +#define osFreeLibrary ((BOOL(WINAPI*)(HMODULE))aSyscall[16].pCurrent)
          346  +
          347  +  { "GetCurrentProcessId",     (SYSCALL)GetCurrentProcessId,     0 },
          348  +
          349  +#define osGetCurrentProcessId ((DWORD(WINAPI*)(VOID))aSyscall[17].pCurrent)
          350  +
          351  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
          352  +  { "GetDiskFreeSpaceA",       (SYSCALL)GetDiskFreeSpaceA,       0 },
          353  +#else
          354  +  { "GetDiskFreeSpaceA",       (SYSCALL)0,                       0 },
          355  +#endif
          356  +
          357  +#define osGetDiskFreeSpaceA ((BOOL(WINAPI*)(LPCSTR,LPDWORD,LPDWORD,LPDWORD, \
          358  +        LPDWORD))aSyscall[18].pCurrent)
          359  +
          360  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          361  +  { "GetDiskFreeSpaceW",       (SYSCALL)GetDiskFreeSpaceW,       0 },
          362  +#else
          363  +  { "GetDiskFreeSpaceW",       (SYSCALL)0,                       0 },
          364  +#endif
          365  +
          366  +#define osGetDiskFreeSpaceW ((BOOL(WINAPI*)(LPCWSTR,LPDWORD,LPDWORD,LPDWORD, \
          367  +        LPDWORD))aSyscall[19].pCurrent)
          368  +
          369  +#if defined(SQLITE_WIN32_HAS_ANSI)
          370  +  { "GetFileAttributesA",      (SYSCALL)GetFileAttributesA,      0 },
          371  +#else
          372  +  { "GetFileAttributesA",      (SYSCALL)0,                       0 },
          373  +#endif
          374  +
          375  +#define osGetFileAttributesA ((DWORD(WINAPI*)(LPCSTR))aSyscall[20].pCurrent)
          376  +
          377  +#if defined(SQLITE_WIN32_HAS_WIDE)
          378  +  { "GetFileAttributesW",      (SYSCALL)GetFileAttributesW,      0 },
          379  +#else
          380  +  { "GetFileAttributesW",      (SYSCALL)0,                       0 },
          381  +#endif
          382  +
          383  +#define osGetFileAttributesW ((DWORD(WINAPI*)(LPCWSTR))aSyscall[21].pCurrent)
          384  +
          385  +#if defined(SQLITE_WIN32_HAS_WIDE)
          386  +  { "GetFileAttributesExW",    (SYSCALL)GetFileAttributesExW,    0 },
          387  +#else
          388  +  { "GetFileAttributesExW",    (SYSCALL)0,                       0 },
          389  +#endif
          390  +
          391  +#define osGetFileAttributesExW ((BOOL(WINAPI*)(LPCWSTR,GET_FILEEX_INFO_LEVELS, \
          392  +        LPVOID))aSyscall[22].pCurrent)
          393  +
          394  +  { "GetFileSize",             (SYSCALL)GetFileSize,             0 },
          395  +
          396  +#define osGetFileSize ((DWORD(WINAPI*)(HANDLE,LPDWORD))aSyscall[23].pCurrent)
          397  +
          398  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_ANSI)
          399  +  { "GetFullPathNameA",        (SYSCALL)GetFullPathNameA,        0 },
          400  +#else
          401  +  { "GetFullPathNameA",        (SYSCALL)0,                       0 },
          402  +#endif
          403  +
          404  +#define osGetFullPathNameA ((DWORD(WINAPI*)(LPCSTR,DWORD,LPSTR, \
          405  +        LPSTR*))aSyscall[24].pCurrent)
          406  +
          407  +#if !SQLITE_OS_WINCE && defined(SQLITE_WIN32_HAS_WIDE)
          408  +  { "GetFullPathNameW",        (SYSCALL)GetFullPathNameW,        0 },
          409  +#else
          410  +  { "GetFullPathNameW",        (SYSCALL)0,                       0 },
          411  +#endif
          412  +
          413  +#define osGetFullPathNameW ((DWORD(WINAPI*)(LPCWSTR,DWORD,LPWSTR, \
          414  +        LPWSTR*))aSyscall[25].pCurrent)
          415  +
          416  +  { "GetLastError",            (SYSCALL)GetLastError,            0 },
          417  +
          418  +#define osGetLastError ((DWORD(WINAPI*)(VOID))aSyscall[26].pCurrent)
          419  +
          420  +#if SQLITE_OS_WINCE
          421  +  /* The GetProcAddressA() routine is only available on Windows CE. */
          422  +  { "GetProcAddressA",         (SYSCALL)GetProcAddressA,         0 },
          423  +#else
          424  +  /* All other Windows platforms expect GetProcAddress() to take
          425  +  ** an ANSI string regardless of the _UNICODE setting */
          426  +  { "GetProcAddressA",         (SYSCALL)GetProcAddress,          0 },
          427  +#endif
          428  +
          429  +#define osGetProcAddressA ((FARPROC(WINAPI*)(HMODULE, \
          430  +        LPCSTR))aSyscall[27].pCurrent)
          431  +
          432  +  { "GetSystemInfo",           (SYSCALL)GetSystemInfo,           0 },
          433  +
          434  +#define osGetSystemInfo ((VOID(WINAPI*)(LPSYSTEM_INFO))aSyscall[28].pCurrent)
          435  +
          436  +  { "GetSystemTime",           (SYSCALL)GetSystemTime,           0 },
          437  +
          438  +#define osGetSystemTime ((VOID(WINAPI*)(LPSYSTEMTIME))aSyscall[29].pCurrent)
          439  +
          440  +#if !SQLITE_OS_WINCE
          441  +  { "GetSystemTimeAsFileTime", (SYSCALL)GetSystemTimeAsFileTime, 0 },
          442  +#else
          443  +  { "GetSystemTimeAsFileTime", (SYSCALL)0,                       0 },
          444  +#endif
          445  +
          446  +#define osGetSystemTimeAsFileTime ((VOID(WINAPI*)( \
          447  +        LPFILETIME))aSyscall[30].pCurrent)
          448  +
          449  +#if defined(SQLITE_WIN32_HAS_ANSI)
          450  +  { "GetTempPathA",            (SYSCALL)GetTempPathA,            0 },
          451  +#else
          452  +  { "GetTempPathA",            (SYSCALL)0,                       0 },
          453  +#endif
          454  +
          455  +#define osGetTempPathA ((DWORD(WINAPI*)(DWORD,LPSTR))aSyscall[31].pCurrent)
          456  +
          457  +#if defined(SQLITE_WIN32_HAS_WIDE)
          458  +  { "GetTempPathW",            (SYSCALL)GetTempPathW,            0 },
          459  +#else
          460  +  { "GetTempPathW",            (SYSCALL)0,                       0 },
          461  +#endif
          462  +
          463  +#define osGetTempPathW ((DWORD(WINAPI*)(DWORD,LPWSTR))aSyscall[32].pCurrent)
          464  +
          465  +  { "GetTickCount",            (SYSCALL)GetTickCount,            0 },
          466  +
          467  +#define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent)
          468  +
          469  +#if defined(SQLITE_WIN32_HAS_ANSI)
          470  +  { "GetVersionExA",           (SYSCALL)GetVersionExA,           0 },
          471  +#else
          472  +  { "GetVersionExA",           (SYSCALL)0,                       0 },
          473  +#endif
          474  +
          475  +#define osGetVersionExA ((BOOL(WINAPI*)( \
          476  +        LPOSVERSIONINFOA))aSyscall[34].pCurrent)
          477  +
          478  +  { "HeapAlloc",               (SYSCALL)HeapAlloc,               0 },
          479  +
          480  +#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
          481  +        SIZE_T))aSyscall[35].pCurrent)
          482  +
          483  +  { "HeapCreate",              (SYSCALL)HeapCreate,              0 },
          484  +
          485  +#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
          486  +        SIZE_T))aSyscall[36].pCurrent)
          487  +
          488  +  { "HeapDestroy",             (SYSCALL)HeapDestroy,             0 },
          489  +
          490  +#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
          491  +
          492  +  { "HeapFree",                (SYSCALL)HeapFree,                0 },
          493  +
          494  +#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
          495  +
          496  +  { "HeapReAlloc",             (SYSCALL)HeapReAlloc,             0 },
          497  +
          498  +#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
          499  +        SIZE_T))aSyscall[39].pCurrent)
          500  +
          501  +  { "HeapSize",                (SYSCALL)HeapSize,                0 },
          502  +
          503  +#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
          504  +        LPCVOID))aSyscall[40].pCurrent)
          505  +
          506  +  { "HeapValidate",            (SYSCALL)HeapValidate,            0 },
          507  +
          508  +#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
          509  +        LPCVOID))aSyscall[41].pCurrent)
          510  +
          511  +#if defined(SQLITE_WIN32_HAS_ANSI)
          512  +  { "LoadLibraryA",            (SYSCALL)LoadLibraryA,            0 },
          513  +#else
          514  +  { "LoadLibraryA",            (SYSCALL)0,                       0 },
          515  +#endif
          516  +
          517  +#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
          518  +
          519  +#if defined(SQLITE_WIN32_HAS_WIDE)
          520  +  { "LoadLibraryW",            (SYSCALL)LoadLibraryW,            0 },
          521  +#else
          522  +  { "LoadLibraryW",            (SYSCALL)0,                       0 },
          523  +#endif
          524  +
          525  +#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
          526  +
          527  +  { "LocalFree",               (SYSCALL)LocalFree,               0 },
          528  +
          529  +#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
          530  +
          531  +#if !SQLITE_OS_WINCE
          532  +  { "LockFile",                (SYSCALL)LockFile,                0 },
          533  +
          534  +#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          535  +        DWORD))aSyscall[45].pCurrent)
          536  +#else
          537  +  { "LockFile",                (SYSCALL)0,                       0 },
          538  +#endif
          539  +
          540  +#if !SQLITE_OS_WINCE
          541  +  { "LockFileEx",              (SYSCALL)LockFileEx,              0 },
          542  +
          543  +#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
          544  +        LPOVERLAPPED))aSyscall[46].pCurrent)
          545  +#else
          546  +  { "LockFileEx",              (SYSCALL)0,                       0 },
          547  +#endif
          548  +
          549  +  { "MapViewOfFile",           (SYSCALL)MapViewOfFile,           0 },
          550  +
          551  +#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          552  +        SIZE_T))aSyscall[47].pCurrent)
          553  +
          554  +  { "MultiByteToWideChar",     (SYSCALL)MultiByteToWideChar,     0 },
          555  +
          556  +#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
          557  +        int))aSyscall[48].pCurrent)
          558  +
          559  +  { "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
          560  +
          561  +#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
          562  +        LARGE_INTEGER*))aSyscall[49].pCurrent)
          563  +
          564  +  { "ReadFile",                (SYSCALL)ReadFile,                0 },
          565  +
          566  +#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
          567  +        LPOVERLAPPED))aSyscall[50].pCurrent)
          568  +
          569  +  { "SetEndOfFile",            (SYSCALL)SetEndOfFile,            0 },
          570  +
          571  +#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
          572  +
          573  +  { "SetFilePointer",          (SYSCALL)SetFilePointer,          0 },
          574  +
          575  +#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
          576  +        DWORD))aSyscall[52].pCurrent)
          577  +
          578  +  { "Sleep",                   (SYSCALL)Sleep,                   0 },
          579  +
          580  +#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
          581  +
          582  +  { "SystemTimeToFileTime",    (SYSCALL)SystemTimeToFileTime,    0 },
          583  +
          584  +#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
          585  +        LPFILETIME))aSyscall[54].pCurrent)
          586  +
          587  +#if !SQLITE_OS_WINCE
          588  +  { "UnlockFile",              (SYSCALL)UnlockFile,              0 },
          589  +
          590  +#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          591  +        DWORD))aSyscall[55].pCurrent)
          592  +#else
          593  +  { "UnlockFile",              (SYSCALL)0,                       0 },
          594  +#endif
          595  +
          596  +#if !SQLITE_OS_WINCE
          597  +  { "UnlockFileEx",            (SYSCALL)UnlockFileEx,            0 },
          598  +
          599  +#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
          600  +        LPOVERLAPPED))aSyscall[56].pCurrent)
          601  +#else
          602  +  { "UnlockFileEx",            (SYSCALL)0,                       0 },
          603  +#endif
          604  +
          605  +  { "UnmapViewOfFile",         (SYSCALL)UnmapViewOfFile,         0 },
          606  +
          607  +#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
          608  +
          609  +  { "WideCharToMultiByte",     (SYSCALL)WideCharToMultiByte,     0 },
          610  +
          611  +#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
          612  +        LPCSTR,LPBOOL))aSyscall[58].pCurrent)
          613  +
          614  +  { "WriteFile",               (SYSCALL)WriteFile,               0 },
          615  +
          616  +#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
          617  +        LPOVERLAPPED))aSyscall[59].pCurrent)
          618  +
          619  +}; /* End of the overrideable system calls */
          620  +
          621  +/*
          622  +** This is the xSetSystemCall() method of sqlite3_vfs for all of the
          623  +** "win32" VFSes.  Return SQLITE_OK opon successfully updating the
          624  +** system call pointer, or SQLITE_NOTFOUND if there is no configurable
          625  +** system call named zName.
          626  +*/
          627  +static int winSetSystemCall(
          628  +  sqlite3_vfs *pNotUsed,        /* The VFS pointer.  Not used */
          629  +  const char *zName,            /* Name of system call to override */
          630  +  sqlite3_syscall_ptr pNewFunc  /* Pointer to new system call value */
          631  +){
          632  +  unsigned int i;
          633  +  int rc = SQLITE_NOTFOUND;
          634  +
          635  +  UNUSED_PARAMETER(pNotUsed);
          636  +  if( zName==0 ){
          637  +    /* If no zName is given, restore all system calls to their default
          638  +    ** settings and return NULL
          639  +    */
          640  +    rc = SQLITE_OK;
          641  +    for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          642  +      if( aSyscall[i].pDefault ){
          643  +        aSyscall[i].pCurrent = aSyscall[i].pDefault;
          644  +      }
          645  +    }
          646  +  }else{
          647  +    /* If zName is specified, operate on only the one system call
          648  +    ** specified.
          649  +    */
          650  +    for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          651  +      if( strcmp(zName, aSyscall[i].zName)==0 ){
          652  +        if( aSyscall[i].pDefault==0 ){
          653  +          aSyscall[i].pDefault = aSyscall[i].pCurrent;
          654  +        }
          655  +        rc = SQLITE_OK;
          656  +        if( pNewFunc==0 ) pNewFunc = aSyscall[i].pDefault;
          657  +        aSyscall[i].pCurrent = pNewFunc;
          658  +        break;
          659  +      }
          660  +    }
          661  +  }
          662  +  return rc;
          663  +}
          664  +
          665  +/*
          666  +** Return the value of a system call.  Return NULL if zName is not a
          667  +** recognized system call name.  NULL is also returned if the system call
          668  +** is currently undefined.
          669  +*/
          670  +static sqlite3_syscall_ptr winGetSystemCall(
          671  +  sqlite3_vfs *pNotUsed,
          672  +  const char *zName
          673  +){
          674  +  unsigned int i;
          675  +
          676  +  UNUSED_PARAMETER(pNotUsed);
          677  +  for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
          678  +    if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
          679  +  }
          680  +  return 0;
          681  +}
          682  +
          683  +/*
          684  +** Return the name of the first system call after zName.  If zName==NULL
          685  +** then return the name of the first system call.  Return NULL if zName
          686  +** is the last system call or if zName is not the name of a valid
          687  +** system call.
          688  +*/
          689  +static const char *winNextSystemCall(sqlite3_vfs *p, const char *zName){
          690  +  int i = -1;
          691  +
          692  +  UNUSED_PARAMETER(p);
          693  +  if( zName ){
          694  +    for(i=0; i<ArraySize(aSyscall)-1; i++){
          695  +      if( strcmp(zName, aSyscall[i].zName)==0 ) break;
          696  +    }
          697  +  }
          698  +  for(i++; i<ArraySize(aSyscall); i++){
          699  +    if( aSyscall[i].pCurrent!=0 ) return aSyscall[i].zName;
          700  +  }
          701  +  return 0;
          702  +}
   218    703   
   219    704   /*
   220    705   ** Return true (non-zero) if we are running under WinNT, Win2K, WinXP,
   221    706   ** or WinCE.  Return false (zero) for Win95, Win98, or WinME.
   222    707   **
   223    708   ** Here is an interesting observation:  Win95, Win98, and WinME lack
   224    709   ** the LockFileEx() API.  But we can still statically link against that
................................................................................
   228    713   ** the LockFileEx() API.
   229    714   */
   230    715   #if SQLITE_OS_WINCE
   231    716   # define isNT()  (1)
   232    717   #else
   233    718     static int isNT(void){
   234    719       if( sqlite3_os_type==0 ){
   235         -      OSVERSIONINFO sInfo;
          720  +      OSVERSIONINFOA sInfo;
   236    721         sInfo.dwOSVersionInfoSize = sizeof(sInfo);
   237         -      GetVersionEx(&sInfo);
          722  +      osGetVersionExA(&sInfo);
   238    723         sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
   239    724       }
   240    725       return sqlite3_os_type==2;
   241    726     }
   242    727   #endif /* SQLITE_OS_WINCE */
   243    728   
   244    729   #ifdef SQLITE_WIN32_MALLOC
................................................................................
   250    735     void *p;
   251    736   
   252    737     winMemAssertMagic();
   253    738     hHeap = winMemGetHeap();
   254    739     assert( hHeap!=0 );
   255    740     assert( hHeap!=INVALID_HANDLE_VALUE );
   256    741   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   257         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          742  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   258    743   #endif
   259    744     assert( nBytes>=0 );
   260         -  p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
          745  +  p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
   261    746     if( !p ){
   262    747       sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
   263         -        nBytes, GetLastError(), (void*)hHeap);
          748  +                nBytes, osGetLastError(), (void*)hHeap);
   264    749     }
   265    750     return p;
   266    751   }
   267    752   
   268    753   /*
   269    754   ** Free memory.
   270    755   */
................................................................................
   272    757     HANDLE hHeap;
   273    758   
   274    759     winMemAssertMagic();
   275    760     hHeap = winMemGetHeap();
   276    761     assert( hHeap!=0 );
   277    762     assert( hHeap!=INVALID_HANDLE_VALUE );
   278    763   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   279         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
          764  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
   280    765   #endif
   281    766     if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
   282         -  if( !HeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
          767  +  if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
   283    768       sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
   284         -        pPrior, GetLastError(), (void*)hHeap);
          769  +                pPrior, osGetLastError(), (void*)hHeap);
   285    770     }
   286    771   }
   287    772   
   288    773   /*
   289    774   ** Change the size of an existing memory allocation
   290    775   */
   291    776   static void *winMemRealloc(void *pPrior, int nBytes){
................................................................................
   293    778     void *p;
   294    779   
   295    780     winMemAssertMagic();
   296    781     hHeap = winMemGetHeap();
   297    782     assert( hHeap!=0 );
   298    783     assert( hHeap!=INVALID_HANDLE_VALUE );
   299    784   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   300         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
          785  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) );
   301    786   #endif
   302    787     assert( nBytes>=0 );
   303    788     if( !pPrior ){
   304         -    p = HeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
          789  +    p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
   305    790     }else{
   306         -    p = HeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
          791  +    p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
   307    792     }
   308    793     if( !p ){
   309    794       sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
   310         -        pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, GetLastError(),
   311         -        (void*)hHeap);
          795  +                pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(),
          796  +                (void*)hHeap);
   312    797     }
   313    798     return p;
   314    799   }
   315    800   
   316    801   /*
   317    802   ** Return the size of an outstanding allocation, in bytes.
   318    803   */
................................................................................
   321    806     SIZE_T n;
   322    807   
   323    808     winMemAssertMagic();
   324    809     hHeap = winMemGetHeap();
   325    810     assert( hHeap!=0 );
   326    811     assert( hHeap!=INVALID_HANDLE_VALUE );
   327    812   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   328         -  assert ( HeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          813  +  assert ( osHeapValidate(hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   329    814   #endif
   330    815     if( !p ) return 0;
   331         -  n = HeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
          816  +  n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
   332    817     if( n==(SIZE_T)-1 ){
   333    818       sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
   334         -        p, GetLastError(), (void*)hHeap);
          819  +                p, osGetLastError(), (void*)hHeap);
   335    820       return 0;
   336    821     }
   337    822     return (int)n;
   338    823   }
   339    824   
   340    825   /*
   341    826   ** Round up a request size to the next valid allocation size.
................................................................................
   349    834   */
   350    835   static int winMemInit(void *pAppData){
   351    836     winMemData *pWinMemData = (winMemData *)pAppData;
   352    837   
   353    838     if( !pWinMemData ) return SQLITE_ERROR;
   354    839     assert( pWinMemData->magic==WINMEM_MAGIC );
   355    840     if( !pWinMemData->hHeap ){
   356         -    pWinMemData->hHeap = HeapCreate(SQLITE_WIN32_HEAP_FLAGS,
   357         -                                    SQLITE_WIN32_HEAP_INIT_SIZE,
   358         -                                    SQLITE_WIN32_HEAP_MAX_SIZE);
          841  +    pWinMemData->hHeap = osHeapCreate(SQLITE_WIN32_HEAP_FLAGS,
          842  +                                      SQLITE_WIN32_HEAP_INIT_SIZE,
          843  +                                      SQLITE_WIN32_HEAP_MAX_SIZE);
   359    844       if( !pWinMemData->hHeap ){
   360    845         sqlite3_log(SQLITE_NOMEM,
   361    846             "failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u",
   362         -          GetLastError(), SQLITE_WIN32_HEAP_FLAGS, SQLITE_WIN32_HEAP_INIT_SIZE,
   363         -          SQLITE_WIN32_HEAP_MAX_SIZE);
          847  +          osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
          848  +          SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
   364    849         return SQLITE_NOMEM;
   365    850       }
   366    851       pWinMemData->bOwned = TRUE;
   367    852     }
   368    853     assert( pWinMemData->hHeap!=0 );
   369    854     assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
   370    855   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   371         -  assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          856  +  assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   372    857   #endif
   373    858     return SQLITE_OK;
   374    859   }
   375    860   
   376    861   /*
   377    862   ** Deinitialize this module.
   378    863   */
................................................................................
   379    864   static void winMemShutdown(void *pAppData){
   380    865     winMemData *pWinMemData = (winMemData *)pAppData;
   381    866   
   382    867     if( !pWinMemData ) return;
   383    868     if( pWinMemData->hHeap ){
   384    869       assert( pWinMemData->hHeap!=INVALID_HANDLE_VALUE );
   385    870   #ifdef SQLITE_WIN32_MALLOC_VALIDATE
   386         -    assert( HeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
          871  +    assert( osHeapValidate(pWinMemData->hHeap, SQLITE_WIN32_HEAP_FLAGS, NULL) );
   387    872   #endif
   388    873       if( pWinMemData->bOwned ){
   389         -      if( !HeapDestroy(pWinMemData->hHeap) ){
          874  +      if( !osHeapDestroy(pWinMemData->hHeap) ){
   390    875           sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
   391         -            GetLastError(), (void*)pWinMemData->hHeap);
          876  +                    osGetLastError(), (void*)pWinMemData->hHeap);
   392    877         }
   393    878         pWinMemData->bOwned = FALSE;
   394    879       }
   395    880       pWinMemData->hHeap = NULL;
   396    881     }
   397    882   }
   398    883   
................................................................................
   420    905   
   421    906   void sqlite3MemSetDefault(void){
   422    907     sqlite3_config(SQLITE_CONFIG_MALLOC, sqlite3MemGetWin32());
   423    908   }
   424    909   #endif /* SQLITE_WIN32_MALLOC */
   425    910   
   426    911   /*
   427         -** Convert a UTF-8 string to microsoft unicode (UTF-16?). 
          912  +** Convert a UTF-8 string to Microsoft Unicode (UTF-16?). 
   428    913   **
   429    914   ** Space to hold the returned string is obtained from malloc.
   430    915   */
   431         -static WCHAR *utf8ToUnicode(const char *zFilename){
          916  +static LPWSTR utf8ToUnicode(const char *zFilename){
   432    917     int nChar;
   433         -  WCHAR *zWideFilename;
          918  +  LPWSTR zWideFilename;
   434    919   
   435         -  nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
   436         -  zWideFilename = malloc( nChar*sizeof(zWideFilename[0]) );
          920  +  nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, NULL, 0);
          921  +  zWideFilename = sqlite3_malloc( nChar*sizeof(zWideFilename[0]) );
   437    922     if( zWideFilename==0 ){
   438    923       return 0;
   439    924     }
   440         -  nChar = MultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename, nChar);
          925  +  nChar = osMultiByteToWideChar(CP_UTF8, 0, zFilename, -1, zWideFilename,
          926  +                                nChar);
   441    927     if( nChar==0 ){
   442         -    free(zWideFilename);
          928  +    sqlite3_free(zWideFilename);
   443    929       zWideFilename = 0;
   444    930     }
   445    931     return zWideFilename;
   446    932   }
   447    933   
   448    934   /*
   449         -** Convert microsoft unicode to UTF-8.  Space to hold the returned string is
   450         -** obtained from malloc().
          935  +** Convert Microsoft Unicode to UTF-8.  Space to hold the returned string is
          936  +** obtained from sqlite3_malloc().
   451    937   */
   452         -static char *unicodeToUtf8(const WCHAR *zWideFilename){
          938  +static char *unicodeToUtf8(LPCWSTR zWideFilename){
   453    939     int nByte;
   454    940     char *zFilename;
   455    941   
   456         -  nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
   457         -  zFilename = malloc( nByte );
          942  +  nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);
          943  +  zFilename = sqlite3_malloc( nByte );
   458    944     if( zFilename==0 ){
   459    945       return 0;
   460    946     }
   461         -  nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
   462         -                              0, 0);
          947  +  nByte = osWideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte,
          948  +                                0, 0);
   463    949     if( nByte == 0 ){
   464         -    free(zFilename);
          950  +    sqlite3_free(zFilename);
   465    951       zFilename = 0;
   466    952     }
   467    953     return zFilename;
   468    954   }
   469    955   
   470    956   /*
   471         -** Convert an ansi string to microsoft unicode, based on the
          957  +** Convert an ANSI string to Microsoft Unicode, based on the
   472    958   ** current codepage settings for file apis.
   473    959   ** 
   474    960   ** Space to hold the returned string is obtained
   475         -** from malloc.
          961  +** from sqlite3_malloc.
   476    962   */
   477         -static WCHAR *mbcsToUnicode(const char *zFilename){
          963  +static LPWSTR mbcsToUnicode(const char *zFilename){
   478    964     int nByte;
   479         -  WCHAR *zMbcsFilename;
   480         -  int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
          965  +  LPWSTR zMbcsFilename;
          966  +  int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP;
   481    967   
   482         -  nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);
   483         -  zMbcsFilename = malloc( nByte*sizeof(zMbcsFilename[0]) );
          968  +  nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL,
          969  +                                0)*sizeof(WCHAR);
          970  +  zMbcsFilename = sqlite3_malloc( nByte*sizeof(zMbcsFilename[0]) );
   484    971     if( zMbcsFilename==0 ){
   485    972       return 0;
   486    973     }
   487         -  nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);
          974  +  nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename,
          975  +                                nByte);
   488    976     if( nByte==0 ){
   489         -    free(zMbcsFilename);
          977  +    sqlite3_free(zMbcsFilename);
   490    978       zMbcsFilename = 0;
   491    979     }
   492    980     return zMbcsFilename;
   493    981   }
   494    982   
   495    983   /*
   496         -** Convert microsoft unicode to multibyte character string, based on the
   497         -** user's Ansi codepage.
          984  +** Convert Microsoft Unicode to multi-byte character string, based on the
          985  +** user's ANSI codepage.
   498    986   **
   499    987   ** Space to hold the returned string is obtained from
   500         -** malloc().
          988  +** sqlite3_malloc().
   501    989   */
   502         -static char *unicodeToMbcs(const WCHAR *zWideFilename){
          990  +static char *unicodeToMbcs(LPCWSTR zWideFilename){
   503    991     int nByte;
   504    992     char *zFilename;
   505         -  int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
          993  +  int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP;
   506    994   
   507         -  nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
   508         -  zFilename = malloc( nByte );
          995  +  nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, 0, 0, 0, 0);
          996  +  zFilename = sqlite3_malloc( nByte );
   509    997     if( zFilename==0 ){
   510    998       return 0;
   511    999     }
   512         -  nByte = WideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename, nByte,
   513         -                              0, 0);
         1000  +  nByte = osWideCharToMultiByte(codepage, 0, zWideFilename, -1, zFilename,
         1001  +                                nByte, 0, 0);
   514   1002     if( nByte == 0 ){
   515         -    free(zFilename);
         1003  +    sqlite3_free(zFilename);
   516   1004       zFilename = 0;
   517   1005     }
   518   1006     return zFilename;
   519   1007   }
   520   1008   
   521   1009   /*
   522   1010   ** Convert multibyte character string to UTF-8.  Space to hold the
   523         -** returned string is obtained from malloc().
         1011  +** returned string is obtained from sqlite3_malloc().
   524   1012   */
   525   1013   char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){
   526   1014     char *zFilenameUtf8;
   527         -  WCHAR *zTmpWide;
         1015  +  LPWSTR zTmpWide;
   528   1016   
   529   1017     zTmpWide = mbcsToUnicode(zFilename);
   530   1018     if( zTmpWide==0 ){
   531   1019       return 0;
   532   1020     }
   533   1021     zFilenameUtf8 = unicodeToUtf8(zTmpWide);
   534         -  free(zTmpWide);
         1022  +  sqlite3_free(zTmpWide);
   535   1023     return zFilenameUtf8;
   536   1024   }
   537   1025   
   538   1026   /*
   539   1027   ** Convert UTF-8 to multibyte character string.  Space to hold the 
   540         -** returned string is obtained from malloc().
         1028  +** returned string is obtained from sqlite3_malloc().
   541   1029   */
   542   1030   char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){
   543   1031     char *zFilenameMbcs;
   544         -  WCHAR *zTmpWide;
         1032  +  LPWSTR zTmpWide;
   545   1033   
   546   1034     zTmpWide = utf8ToUnicode(zFilename);
   547   1035     if( zTmpWide==0 ){
   548   1036       return 0;
   549   1037     }
   550   1038     zFilenameMbcs = unicodeToMbcs(zTmpWide);
   551         -  free(zTmpWide);
         1039  +  sqlite3_free(zTmpWide);
   552   1040     return zFilenameMbcs;
   553   1041   }
   554   1042   
   555   1043   
   556   1044   /*
   557   1045   ** The return value of getLastErrorMsg
   558   1046   ** is zero if the error message fits in the buffer, or non-zero
   559   1047   ** otherwise (if the message was truncated).
   560   1048   */
   561         -static int getLastErrorMsg(int nBuf, char *zBuf){
         1049  +static int getLastErrorMsg(DWORD lastErrno, int nBuf, char *zBuf){
   562   1050     /* FormatMessage returns 0 on failure.  Otherwise it
   563   1051     ** returns the number of TCHARs written to the output
   564   1052     ** buffer, excluding the terminating null char.
   565   1053     */
   566         -  DWORD error = GetLastError();
   567   1054     DWORD dwLen = 0;
   568   1055     char *zOut = 0;
   569   1056   
   570   1057     if( isNT() ){
   571         -    WCHAR *zTempWide = NULL;
   572         -    dwLen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
   573         -                           NULL,
   574         -                           error,
   575         -                           0,
   576         -                           (LPWSTR) &zTempWide,
   577         -                           0,
   578         -                           0);
         1058  +    LPWSTR zTempWide = NULL;
         1059  +    dwLen = osFormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
         1060  +                             FORMAT_MESSAGE_FROM_SYSTEM |
         1061  +                             FORMAT_MESSAGE_IGNORE_INSERTS,
         1062  +                             NULL,
         1063  +                             lastErrno,
         1064  +                             0,
         1065  +                             (LPWSTR) &zTempWide,
         1066  +                             0,
         1067  +                             0);
   579   1068       if( dwLen > 0 ){
   580   1069         /* allocate a buffer and convert to UTF8 */
         1070  +      sqlite3BeginBenignMalloc();
   581   1071         zOut = unicodeToUtf8(zTempWide);
         1072  +      sqlite3EndBenignMalloc();
   582   1073         /* free the system buffer allocated by FormatMessage */
   583         -      LocalFree(zTempWide);
         1074  +      osLocalFree(zTempWide);
   584   1075       }
   585   1076   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
   586         -** Since the ASCII version of these Windows API do not exist for WINCE,
         1077  +** Since the ANSI version of these Windows API do not exist for WINCE,
   587   1078   ** it's important to not reference them for WINCE builds.
   588   1079   */
   589   1080   #if SQLITE_OS_WINCE==0
   590   1081     }else{
   591   1082       char *zTemp = NULL;
   592         -    dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
   593         -                           NULL,
   594         -                           error,
   595         -                           0,
   596         -                           (LPSTR) &zTemp,
   597         -                           0,
   598         -                           0);
         1083  +    dwLen = osFormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
         1084  +                             FORMAT_MESSAGE_FROM_SYSTEM |
         1085  +                             FORMAT_MESSAGE_IGNORE_INSERTS,
         1086  +                             NULL,
         1087  +                             lastErrno,
         1088  +                             0,
         1089  +                             (LPSTR) &zTemp,
         1090  +                             0,
         1091  +                             0);
   599   1092       if( dwLen > 0 ){
   600   1093         /* allocate a buffer and convert to UTF8 */
         1094  +      sqlite3BeginBenignMalloc();
   601   1095         zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
         1096  +      sqlite3EndBenignMalloc();
   602   1097         /* free the system buffer allocated by FormatMessage */
   603         -      LocalFree(zTemp);
         1098  +      osLocalFree(zTemp);
   604   1099       }
   605   1100   #endif
   606   1101     }
   607   1102     if( 0 == dwLen ){
   608         -    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", error, error);
         1103  +    sqlite3_snprintf(nBuf, zBuf, "OsError 0x%x (%u)", lastErrno, lastErrno);
   609   1104     }else{
   610   1105       /* copy a maximum of nBuf chars to output buffer */
   611   1106       sqlite3_snprintf(nBuf, zBuf, "%s", zOut);
   612   1107       /* free the UTF8 buffer */
   613         -    free(zOut);
         1108  +    sqlite3_free(zOut);
   614   1109     }
   615   1110     return 0;
   616   1111   }
   617   1112   
   618   1113   /*
   619   1114   **
   620   1115   ** This function - winLogErrorAtLine() - is only ever called via the macro
................................................................................
   626   1121   ** FormatMessage.
   627   1122   **
   628   1123   ** The first argument passed to the macro should be the error code that
   629   1124   ** will be returned to SQLite (e.g. SQLITE_IOERR_DELETE, SQLITE_CANTOPEN). 
   630   1125   ** The two subsequent arguments should be the name of the OS function that
   631   1126   ** failed and the the associated file-system path, if any.
   632   1127   */
   633         -#define winLogError(a,b,c)     winLogErrorAtLine(a,b,c,__LINE__)
         1128  +#define winLogError(a,b,c,d)   winLogErrorAtLine(a,b,c,d,__LINE__)
   634   1129   static int winLogErrorAtLine(
   635   1130     int errcode,                    /* SQLite error code */
         1131  +  DWORD lastErrno,                /* Win32 last error */
   636   1132     const char *zFunc,              /* Name of OS function that failed */
   637   1133     const char *zPath,              /* File path associated with error */
   638   1134     int iLine                       /* Source line number where error occurred */
   639   1135   ){
   640   1136     char zMsg[500];                 /* Human readable error text */
   641   1137     int i;                          /* Loop counter */
   642         -  DWORD iErrno = GetLastError();  /* Error code */
   643   1138   
   644   1139     zMsg[0] = 0;
   645         -  getLastErrorMsg(sizeof(zMsg), zMsg);
         1140  +  getLastErrorMsg(lastErrno, sizeof(zMsg), zMsg);
   646   1141     assert( errcode!=SQLITE_OK );
   647   1142     if( zPath==0 ) zPath = "";
   648   1143     for(i=0; zMsg[i] && zMsg[i]!='\r' && zMsg[i]!='\n'; i++){}
   649   1144     zMsg[i] = 0;
   650   1145     sqlite3_log(errcode,
   651   1146         "os_win.c:%d: (%d) %s(%s) - %s",
   652         -      iLine, iErrno, zFunc, zPath, zMsg
         1147  +      iLine, lastErrno, zFunc, zPath, zMsg
   653   1148     );
   654   1149   
   655   1150     return errcode;
   656   1151   }
   657   1152   
   658   1153   /*
   659   1154   ** The number of times that a ReadFile(), WriteFile(), and DeleteFile()
................................................................................
   671   1166   static int win32IoerrRetryDelay = SQLITE_WIN32_IOERR_RETRY_DELAY;
   672   1167   
   673   1168   /*
   674   1169   ** If a ReadFile() or WriteFile() error occurs, invoke this routine
   675   1170   ** to see if it should be retried.  Return TRUE to retry.  Return FALSE
   676   1171   ** to give up with an error.
   677   1172   */
   678         -static int retryIoerr(int *pnRetry){
   679         -  DWORD e;
         1173  +static int retryIoerr(int *pnRetry, DWORD *pError){
         1174  +  DWORD e = osGetLastError();
   680   1175     if( *pnRetry>=win32IoerrRetry ){
         1176  +    if( pError ){
         1177  +      *pError = e;
         1178  +    }
   681   1179       return 0;
   682   1180     }
   683         -  e = GetLastError();
   684   1181     if( e==ERROR_ACCESS_DENIED ||
   685   1182         e==ERROR_LOCK_VIOLATION ||
   686   1183         e==ERROR_SHARING_VIOLATION ){
   687         -    Sleep(win32IoerrRetryDelay*(1+*pnRetry));
         1184  +    osSleep(win32IoerrRetryDelay*(1+*pnRetry));
   688   1185       ++*pnRetry;
   689   1186       return 1;
   690   1187     }
         1188  +  if( pError ){
         1189  +    *pError = e;
         1190  +  }
   691   1191     return 0;
   692   1192   }
   693   1193   
   694   1194   /*
   695   1195   ** Log a I/O error retry episode.
   696   1196   */
   697   1197   static void logIoerr(int nRetry){
................................................................................
   704   1204   }
   705   1205   
   706   1206   #if SQLITE_OS_WINCE
   707   1207   /*************************************************************************
   708   1208   ** This section contains code for WinCE only.
   709   1209   */
   710   1210   /*
   711         -** WindowsCE does not have a localtime() function.  So create a
         1211  +** Windows CE does not have a localtime() function.  So create a
   712   1212   ** substitute.
   713   1213   */
   714   1214   #include <time.h>
   715   1215   struct tm *__cdecl localtime(const time_t *t)
   716   1216   {
   717   1217     static struct tm y;
   718   1218     FILETIME uTm, lTm;
   719   1219     SYSTEMTIME pTm;
   720   1220     sqlite3_int64 t64;
   721   1221     t64 = *t;
   722   1222     t64 = (t64 + 11644473600)*10000000;
   723   1223     uTm.dwLowDateTime = (DWORD)(t64 & 0xFFFFFFFF);
   724   1224     uTm.dwHighDateTime= (DWORD)(t64 >> 32);
   725         -  FileTimeToLocalFileTime(&uTm,&lTm);
   726         -  FileTimeToSystemTime(&lTm,&pTm);
         1225  +  osFileTimeToLocalFileTime(&uTm,&lTm);
         1226  +  osFileTimeToSystemTime(&lTm,&pTm);
   727   1227     y.tm_year = pTm.wYear - 1900;
   728   1228     y.tm_mon = pTm.wMonth - 1;
   729   1229     y.tm_wday = pTm.wDayOfWeek;
   730   1230     y.tm_mday = pTm.wDay;
   731   1231     y.tm_hour = pTm.wHour;
   732   1232     y.tm_min = pTm.wMinute;
   733   1233     y.tm_sec = pTm.wSecond;
   734   1234     return &y;
   735   1235   }
   736   1236   
   737         -/* This will never be called, but defined to make the code compile */
   738         -#define GetTempPathA(a,b)
   739         -
   740         -#define LockFile(a,b,c,d,e)       winceLockFile(&a, b, c, d, e)
   741         -#define UnlockFile(a,b,c,d,e)     winceUnlockFile(&a, b, c, d, e)
   742         -#define LockFileEx(a,b,c,d,e,f)   winceLockFileEx(&a, b, c, d, e, f)
   743         -
   744   1237   #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
   745   1238   
   746   1239   /*
   747   1240   ** Acquire a lock on the handle h
   748   1241   */
   749   1242   static void winceMutexAcquire(HANDLE h){
   750   1243      DWORD dwErr;
................................................................................
   758   1251   #define winceMutexRelease(h) ReleaseMutex(h)
   759   1252   
   760   1253   /*
   761   1254   ** Create the mutex and shared memory used for locking in the file
   762   1255   ** descriptor pFile
   763   1256   */
   764   1257   static BOOL winceCreateLock(const char *zFilename, winFile *pFile){
   765         -  WCHAR *zTok;
   766         -  WCHAR *zName = utf8ToUnicode(zFilename);
         1258  +  LPWSTR zTok;
         1259  +  LPWSTR zName;
   767   1260     BOOL bInit = TRUE;
         1261  +
         1262  +  zName = utf8ToUnicode(zFilename);
         1263  +  if( zName==0 ){
         1264  +    /* out of memory */
         1265  +    return FALSE;
         1266  +  }
   768   1267   
   769   1268     /* Initialize the local lockdata */
   770         -  ZeroMemory(&pFile->local, sizeof(pFile->local));
         1269  +  memset(&pFile->local, 0, sizeof(pFile->local));
   771   1270   
   772   1271     /* Replace the backslashes from the filename and lowercase it
   773   1272     ** to derive a mutex name. */
   774         -  zTok = CharLowerW(zName);
         1273  +  zTok = osCharLowerW(zName);
   775   1274     for (;*zTok;zTok++){
   776   1275       if (*zTok == '\\') *zTok = '_';
   777   1276     }
   778   1277   
   779   1278     /* Create/open the named mutex */
   780         -  pFile->hMutex = CreateMutexW(NULL, FALSE, zName);
         1279  +  pFile->hMutex = osCreateMutexW(NULL, FALSE, zName);
   781   1280     if (!pFile->hMutex){
   782         -    pFile->lastErrno = GetLastError();
   783         -    winLogError(SQLITE_ERROR, "winceCreateLock1", zFilename);
   784         -    free(zName);
         1281  +    pFile->lastErrno = osGetLastError();
         1282  +    winLogError(SQLITE_ERROR, pFile->lastErrno, "winceCreateLock1", zFilename);
         1283  +    sqlite3_free(zName);
   785   1284       return FALSE;
   786   1285     }
   787   1286   
   788   1287     /* Acquire the mutex before continuing */
   789   1288     winceMutexAcquire(pFile->hMutex);
   790   1289     
   791   1290     /* Since the names of named mutexes, semaphores, file mappings etc are 
   792   1291     ** case-sensitive, take advantage of that by uppercasing the mutex name
   793   1292     ** and using that as the shared filemapping name.
   794   1293     */
   795         -  CharUpperW(zName);
   796         -  pFile->hShared = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
   797         -                                       PAGE_READWRITE, 0, sizeof(winceLock),
   798         -                                       zName);  
         1294  +  osCharUpperW(zName);
         1295  +  pFile->hShared = osCreateFileMappingW(INVALID_HANDLE_VALUE, NULL,
         1296  +                                        PAGE_READWRITE, 0, sizeof(winceLock),
         1297  +                                        zName);  
   799   1298   
   800   1299     /* Set a flag that indicates we're the first to create the memory so it 
   801   1300     ** must be zero-initialized */
   802         -  if (GetLastError() == ERROR_ALREADY_EXISTS){
         1301  +  if (osGetLastError() == ERROR_ALREADY_EXISTS){
   803   1302       bInit = FALSE;
   804   1303     }
   805   1304   
   806         -  free(zName);
         1305  +  sqlite3_free(zName);
   807   1306   
   808   1307     /* If we succeeded in making the shared memory handle, map it. */
   809   1308     if (pFile->hShared){
   810         -    pFile->shared = (winceLock*)MapViewOfFile(pFile->hShared, 
         1309  +    pFile->shared = (winceLock*)osMapViewOfFile(pFile->hShared, 
   811   1310                FILE_MAP_READ|FILE_MAP_WRITE, 0, 0, sizeof(winceLock));
   812   1311       /* If mapping failed, close the shared memory handle and erase it */
   813   1312       if (!pFile->shared){
   814         -      pFile->lastErrno = GetLastError();
   815         -      winLogError(SQLITE_ERROR, "winceCreateLock2", zFilename);
   816         -      CloseHandle(pFile->hShared);
         1313  +      pFile->lastErrno = osGetLastError();
         1314  +      winLogError(SQLITE_ERROR, pFile->lastErrno,
         1315  +               "winceCreateLock2", zFilename);
         1316  +      osCloseHandle(pFile->hShared);
   817   1317         pFile->hShared = NULL;
   818   1318       }
   819   1319     }
   820   1320   
   821   1321     /* If shared memory could not be created, then close the mutex and fail */
   822   1322     if (pFile->hShared == NULL){
   823   1323       winceMutexRelease(pFile->hMutex);
   824         -    CloseHandle(pFile->hMutex);
         1324  +    osCloseHandle(pFile->hMutex);
   825   1325       pFile->hMutex = NULL;
   826   1326       return FALSE;
   827   1327     }
   828   1328     
   829   1329     /* Initialize the shared memory if we're supposed to */
   830   1330     if (bInit) {
   831         -    ZeroMemory(pFile->shared, sizeof(winceLock));
         1331  +    memset(pFile->shared, 0, sizeof(winceLock));
   832   1332     }
   833   1333   
   834   1334     winceMutexRelease(pFile->hMutex);
   835   1335     return TRUE;
   836   1336   }
   837   1337   
   838   1338   /*
................................................................................
   855   1355         pFile->shared->bPending = FALSE;
   856   1356       }
   857   1357       if (pFile->local.bExclusive){
   858   1358         pFile->shared->bExclusive = FALSE;
   859   1359       }
   860   1360   
   861   1361       /* De-reference and close our copy of the shared memory handle */
   862         -    UnmapViewOfFile(pFile->shared);
   863         -    CloseHandle(pFile->hShared);
         1362  +    osUnmapViewOfFile(pFile->shared);
         1363  +    osCloseHandle(pFile->hShared);
   864   1364   
   865   1365       /* Done with the mutex */
   866   1366       winceMutexRelease(pFile->hMutex);    
   867         -    CloseHandle(pFile->hMutex);
         1367  +    osCloseHandle(pFile->hMutex);
   868   1368       pFile->hMutex = NULL;
   869   1369     }
   870   1370   }
   871   1371   
   872   1372   /* 
   873         -** An implementation of the LockFile() API of windows for wince
         1373  +** An implementation of the LockFile() API of Windows for CE
   874   1374   */
   875   1375   static BOOL winceLockFile(
   876   1376     HANDLE *phFile,
   877   1377     DWORD dwFileOffsetLow,
   878   1378     DWORD dwFileOffsetHigh,
   879   1379     DWORD nNumberOfBytesToLockLow,
   880   1380     DWORD nNumberOfBytesToLockHigh
................................................................................
   930   1430     }
   931   1431   
   932   1432     winceMutexRelease(pFile->hMutex);
   933   1433     return bReturn;
   934   1434   }
   935   1435   
   936   1436   /*
   937         -** An implementation of the UnlockFile API of windows for wince
         1437  +** An implementation of the UnlockFile API of Windows for CE
   938   1438   */
   939   1439   static BOOL winceUnlockFile(
   940   1440     HANDLE *phFile,
   941   1441     DWORD dwFileOffsetLow,
   942   1442     DWORD dwFileOffsetHigh,
   943   1443     DWORD nNumberOfBytesToUnlockLow,
   944   1444     DWORD nNumberOfBytesToUnlockHigh
................................................................................
   992   1492     }
   993   1493   
   994   1494     winceMutexRelease(pFile->hMutex);
   995   1495     return bReturn;
   996   1496   }
   997   1497   
   998   1498   /*
   999         -** An implementation of the LockFileEx() API of windows for wince
         1499  +** An implementation of the LockFileEx() API of Windows for CE
  1000   1500   */
  1001   1501   static BOOL winceLockFileEx(
  1002   1502     HANDLE *phFile,
  1003   1503     DWORD dwFlags,
  1004   1504     DWORD dwReserved,
  1005   1505     DWORD nNumberOfBytesToLockLow,
  1006   1506     DWORD nNumberOfBytesToLockHigh,
................................................................................
  1025   1525   
  1026   1526   /*****************************************************************************
  1027   1527   ** The next group of routines implement the I/O methods specified
  1028   1528   ** by the sqlite3_io_methods object.
  1029   1529   ******************************************************************************/
  1030   1530   
  1031   1531   /*
  1032         -** Some microsoft compilers lack this definition.
         1532  +** Some Microsoft compilers lack this definition.
  1033   1533   */
  1034   1534   #ifndef INVALID_SET_FILE_POINTER
  1035   1535   # define INVALID_SET_FILE_POINTER ((DWORD)-1)
  1036   1536   #endif
  1037   1537   
  1038   1538   /*
  1039   1539   ** Move the current position of the file handle passed as the first 
................................................................................
  1040   1540   ** argument to offset iOffset within the file. If successful, return 0. 
  1041   1541   ** Otherwise, set pFile->lastErrno and return non-zero.
  1042   1542   */
  1043   1543   static int seekWinFile(winFile *pFile, sqlite3_int64 iOffset){
  1044   1544     LONG upperBits;                 /* Most sig. 32 bits of new offset */
  1045   1545     LONG lowerBits;                 /* Least sig. 32 bits of new offset */
  1046   1546     DWORD dwRet;                    /* Value returned by SetFilePointer() */
         1547  +  DWORD lastErrno;                /* Value returned by GetLastError() */
  1047   1548   
  1048   1549     upperBits = (LONG)((iOffset>>32) & 0x7fffffff);
  1049   1550     lowerBits = (LONG)(iOffset & 0xffffffff);
  1050   1551   
  1051   1552     /* API oddity: If successful, SetFilePointer() returns a dword 
  1052   1553     ** containing the lower 32-bits of the new file-offset. Or, if it fails,
  1053   1554     ** it returns INVALID_SET_FILE_POINTER. However according to MSDN, 
  1054   1555     ** INVALID_SET_FILE_POINTER may also be a valid new offset. So to determine 
  1055   1556     ** whether an error has actually occured, it is also necessary to call 
  1056   1557     ** GetLastError().
  1057   1558     */
  1058         -  dwRet = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
  1059         -  if( (dwRet==INVALID_SET_FILE_POINTER && GetLastError()!=NO_ERROR) ){
  1060         -    pFile->lastErrno = GetLastError();
  1061         -    winLogError(SQLITE_IOERR_SEEK, "seekWinFile", pFile->zPath);
         1559  +  dwRet = osSetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
         1560  +
         1561  +  if( (dwRet==INVALID_SET_FILE_POINTER
         1562  +      && ((lastErrno = osGetLastError())!=NO_ERROR)) ){
         1563  +    pFile->lastErrno = lastErrno;
         1564  +    winLogError(SQLITE_IOERR_SEEK, pFile->lastErrno,
         1565  +             "seekWinFile", pFile->zPath);
  1062   1566       return 1;
  1063   1567     }
  1064   1568   
  1065   1569     return 0;
  1066   1570   }
  1067   1571   
  1068   1572   /*
  1069   1573   ** Close a file.
  1070   1574   **
  1071   1575   ** It is reported that an attempt to close a handle might sometimes
  1072         -** fail.  This is a very unreasonable result, but windows is notorious
         1576  +** fail.  This is a very unreasonable result, but Windows is notorious
  1073   1577   ** for being unreasonable so I do not doubt that it might happen.  If
  1074   1578   ** the close fails, we pause for 100 milliseconds and try again.  As
  1075   1579   ** many as MX_CLOSE_ATTEMPT attempts to close the handle are made before
  1076   1580   ** giving up and returning an error.
  1077   1581   */
  1078   1582   #define MX_CLOSE_ATTEMPT 3
  1079   1583   static int winClose(sqlite3_file *id){
................................................................................
  1080   1584     int rc, cnt = 0;
  1081   1585     winFile *pFile = (winFile*)id;
  1082   1586   
  1083   1587     assert( id!=0 );
  1084   1588     assert( pFile->pShm==0 );
  1085   1589     OSTRACE(("CLOSE %d\n", pFile->h));
  1086   1590     do{
  1087         -    rc = CloseHandle(pFile->h);
         1591  +    rc = osCloseHandle(pFile->h);
  1088   1592       /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
  1089         -  }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (Sleep(100), 1) );
         1593  +  }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (osSleep(100), 1) );
  1090   1594   #if SQLITE_OS_WINCE
  1091   1595   #define WINCE_DELETION_ATTEMPTS 3
  1092   1596     winceDestroyLock(pFile);
  1093   1597     if( pFile->zDeleteOnClose ){
  1094   1598       int cnt = 0;
  1095   1599       while(
  1096         -           DeleteFileW(pFile->zDeleteOnClose)==0
  1097         -        && GetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff 
         1600  +           osDeleteFileW(pFile->zDeleteOnClose)==0
         1601  +        && osGetFileAttributesW(pFile->zDeleteOnClose)!=0xffffffff 
  1098   1602           && cnt++ < WINCE_DELETION_ATTEMPTS
  1099   1603       ){
  1100         -       Sleep(100);  /* Wait a little before trying again */
         1604  +       osSleep(100);  /* Wait a little before trying again */
  1101   1605       }
  1102         -    free(pFile->zDeleteOnClose);
         1606  +    sqlite3_free(pFile->zDeleteOnClose);
  1103   1607     }
  1104   1608   #endif
  1105   1609     OSTRACE(("CLOSE %d %s\n", pFile->h, rc ? "ok" : "failed"));
  1106   1610     OpenCounter(-1);
  1107   1611     return rc ? SQLITE_OK
  1108         -            : winLogError(SQLITE_IOERR_CLOSE, "winClose", pFile->zPath);
         1612  +            : winLogError(SQLITE_IOERR_CLOSE, osGetLastError(),
         1613  +                          "winClose", pFile->zPath);
  1109   1614   }
  1110   1615   
  1111   1616   /*
  1112   1617   ** Read data from a file into a buffer.  Return SQLITE_OK if all
  1113   1618   ** bytes were read successfully and SQLITE_IOERR if anything goes
  1114   1619   ** wrong.
  1115   1620   */
................................................................................
  1126   1631     assert( id!=0 );
  1127   1632     SimulateIOError(return SQLITE_IOERR_READ);
  1128   1633     OSTRACE(("READ %d lock=%d\n", pFile->h, pFile->locktype));
  1129   1634   
  1130   1635     if( seekWinFile(pFile, offset) ){
  1131   1636       return SQLITE_FULL;
  1132   1637     }
  1133         -  while( !ReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
  1134         -    if( retryIoerr(&nRetry) ) continue;
  1135         -    pFile->lastErrno = GetLastError();
  1136         -    return winLogError(SQLITE_IOERR_READ, "winRead", pFile->zPath);
         1638  +  while( !osReadFile(pFile->h, pBuf, amt, &nRead, 0) ){
         1639  +    DWORD lastErrno;
         1640  +    if( retryIoerr(&nRetry, &lastErrno) ) continue;
         1641  +    pFile->lastErrno = lastErrno;
         1642  +    return winLogError(SQLITE_IOERR_READ, pFile->lastErrno,
         1643  +             "winRead", pFile->zPath);
  1137   1644     }
  1138   1645     logIoerr(nRetry);
  1139   1646     if( nRead<(DWORD)amt ){
  1140   1647       /* Unread parts of the buffer must be zero-filled */
  1141   1648       memset(&((char*)pBuf)[nRead], 0, amt-nRead);
  1142   1649       return SQLITE_IOERR_SHORT_READ;
  1143   1650     }
................................................................................
  1167   1674     OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
  1168   1675   
  1169   1676     rc = seekWinFile(pFile, offset);
  1170   1677     if( rc==0 ){
  1171   1678       u8 *aRem = (u8 *)pBuf;        /* Data yet to be written */
  1172   1679       int nRem = amt;               /* Number of bytes yet to be written */
  1173   1680       DWORD nWrite;                 /* Bytes written by each WriteFile() call */
         1681  +    DWORD lastErrno = NO_ERROR;   /* Value returned by GetLastError() */
  1174   1682   
  1175   1683       while( nRem>0 ){
  1176         -      if( !WriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
  1177         -        if( retryIoerr(&nRetry) ) continue;
         1684  +      if( !osWriteFile(pFile->h, aRem, nRem, &nWrite, 0) ){
         1685  +        if( retryIoerr(&nRetry, &lastErrno) ) continue;
  1178   1686           break;
  1179   1687         }
  1180   1688         if( nWrite<=0 ) break;
  1181   1689         aRem += nWrite;
  1182   1690         nRem -= nWrite;
  1183   1691       }
  1184   1692       if( nRem>0 ){
  1185         -      pFile->lastErrno = GetLastError();
         1693  +      pFile->lastErrno = lastErrno;
  1186   1694         rc = 1;
  1187   1695       }
  1188   1696     }
  1189   1697   
  1190   1698     if( rc ){
  1191   1699       if(   ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
  1192   1700          || ( pFile->lastErrno==ERROR_DISK_FULL )){
  1193   1701         return SQLITE_FULL;
  1194   1702       }
  1195         -    return winLogError(SQLITE_IOERR_WRITE, "winWrite", pFile->zPath);
         1703  +    return winLogError(SQLITE_IOERR_WRITE, pFile->lastErrno,
         1704  +             "winWrite", pFile->zPath);
  1196   1705     }else{
  1197   1706       logIoerr(nRetry);
  1198   1707     }
  1199   1708     return SQLITE_OK;
  1200   1709   }
  1201   1710   
  1202   1711   /*
................................................................................
  1218   1727     */
  1219   1728     if( pFile->szChunk>0 ){
  1220   1729       nByte = ((nByte + pFile->szChunk - 1)/pFile->szChunk) * pFile->szChunk;
  1221   1730     }
  1222   1731   
  1223   1732     /* SetEndOfFile() returns non-zero when successful, or zero when it fails. */
  1224   1733     if( seekWinFile(pFile, nByte) ){
  1225         -    rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate1", pFile->zPath);
  1226         -  }else if( 0==SetEndOfFile(pFile->h) ){
  1227         -    pFile->lastErrno = GetLastError();
  1228         -    rc = winLogError(SQLITE_IOERR_TRUNCATE, "winTruncate2", pFile->zPath);
         1734  +    rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
         1735  +             "winTruncate1", pFile->zPath);
         1736  +  }else if( 0==osSetEndOfFile(pFile->h) ){
         1737  +    pFile->lastErrno = osGetLastError();
         1738  +    rc = winLogError(SQLITE_IOERR_TRUNCATE, pFile->lastErrno,
         1739  +             "winTruncate2", pFile->zPath);
  1229   1740     }
  1230   1741   
  1231   1742     OSTRACE(("TRUNCATE %d %lld %s\n", pFile->h, nByte, rc ? "failed" : "ok"));
  1232   1743     return rc;
  1233   1744   }
  1234   1745   
  1235   1746   #ifdef SQLITE_TEST
................................................................................
  1286   1797   
  1287   1798     /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
  1288   1799     ** no-op
  1289   1800     */
  1290   1801   #ifdef SQLITE_NO_SYNC
  1291   1802     return SQLITE_OK;
  1292   1803   #else
  1293         -  rc = FlushFileBuffers(pFile->h);
         1804  +  rc = osFlushFileBuffers(pFile->h);
  1294   1805     SimulateIOError( rc=FALSE );
  1295   1806     if( rc ){
  1296   1807       return SQLITE_OK;
  1297   1808     }else{
  1298         -    pFile->lastErrno = GetLastError();
  1299         -    return winLogError(SQLITE_IOERR_FSYNC, "winSync", pFile->zPath);
         1809  +    pFile->lastErrno = osGetLastError();
         1810  +    return winLogError(SQLITE_IOERR_FSYNC, pFile->lastErrno,
         1811  +             "winSync", pFile->zPath);
  1300   1812     }
  1301   1813   #endif
  1302   1814   }
  1303   1815   
  1304   1816   /*
  1305   1817   ** Determine the current size of a file in bytes
  1306   1818   */
  1307   1819   static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
  1308   1820     DWORD upperBits;
  1309   1821     DWORD lowerBits;
  1310   1822     winFile *pFile = (winFile*)id;
  1311         -  DWORD error;
         1823  +  DWORD lastErrno;
  1312   1824   
  1313   1825     assert( id!=0 );
  1314   1826     SimulateIOError(return SQLITE_IOERR_FSTAT);
  1315         -  lowerBits = GetFileSize(pFile->h, &upperBits);
         1827  +  lowerBits = osGetFileSize(pFile->h, &upperBits);
  1316   1828     if(   (lowerBits == INVALID_FILE_SIZE)
  1317         -     && ((error = GetLastError()) != NO_ERROR) )
         1829  +     && ((lastErrno = osGetLastError())!=NO_ERROR) )
  1318   1830     {
  1319         -    pFile->lastErrno = error;
  1320         -    return winLogError(SQLITE_IOERR_FSTAT, "winFileSize", pFile->zPath);
         1831  +    pFile->lastErrno = lastErrno;
         1832  +    return winLogError(SQLITE_IOERR_FSTAT, pFile->lastErrno,
         1833  +             "winFileSize", pFile->zPath);
  1321   1834     }
  1322   1835     *pSize = (((sqlite3_int64)upperBits)<<32) + lowerBits;
  1323   1836     return SQLITE_OK;
  1324   1837   }
  1325   1838   
  1326   1839   /*
  1327   1840   ** LOCKFILE_FAIL_IMMEDIATELY is undefined on some Windows systems.
................................................................................
  1329   1842   #ifndef LOCKFILE_FAIL_IMMEDIATELY
  1330   1843   # define LOCKFILE_FAIL_IMMEDIATELY 1
  1331   1844   #endif
  1332   1845   
  1333   1846   /*
  1334   1847   ** Acquire a reader lock.
  1335   1848   ** Different API routines are called depending on whether or not this
  1336         -** is Win95 or WinNT.
         1849  +** is Win9x or WinNT.
  1337   1850   */
  1338   1851   static int getReadLock(winFile *pFile){
  1339   1852     int res;
  1340   1853     if( isNT() ){
  1341   1854       OVERLAPPED ovlp;
  1342   1855       ovlp.Offset = SHARED_FIRST;
  1343   1856       ovlp.OffsetHigh = 0;
  1344   1857       ovlp.hEvent = 0;
  1345         -    res = LockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
  1346         -                     0, SHARED_SIZE, 0, &ovlp);
         1858  +    res = osLockFileEx(pFile->h, LOCKFILE_FAIL_IMMEDIATELY,
         1859  +                       0, SHARED_SIZE, 0, &ovlp);
  1347   1860   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  1348   1861   */
  1349   1862   #if SQLITE_OS_WINCE==0
  1350   1863     }else{
  1351   1864       int lk;
  1352   1865       sqlite3_randomness(sizeof(lk), &lk);
  1353   1866       pFile->sharedLockByte = (short)((lk & 0x7fffffff)%(SHARED_SIZE - 1));
  1354         -    res = LockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
         1867  +    res = osLockFile(pFile->h, SHARED_FIRST+pFile->sharedLockByte, 0, 1, 0);
  1355   1868   #endif
  1356   1869     }
  1357   1870     if( res == 0 ){
  1358         -    pFile->lastErrno = GetLastError();
         1871  +    pFile->lastErrno = osGetLastError();
  1359   1872       /* No need to log a failure to lock */
  1360   1873     }
  1361   1874     return res;
  1362   1875   }
  1363   1876   
  1364   1877   /*
  1365   1878   ** Undo a readlock
  1366   1879   */
  1367   1880   static int unlockReadLock(winFile *pFile){
  1368   1881     int res;
         1882  +  DWORD lastErrno;
  1369   1883     if( isNT() ){
  1370         -    res = UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
         1884  +    res = osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  1371   1885   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  1372   1886   */
  1373   1887   #if SQLITE_OS_WINCE==0
  1374   1888     }else{
  1375         -    res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
         1889  +    res = osUnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0);
  1376   1890   #endif
  1377   1891     }
  1378         -  if( res==0 && GetLastError()!=ERROR_NOT_LOCKED ){
  1379         -    pFile->lastErrno = GetLastError();
  1380         -    winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath);
         1892  +  if( res==0 && ((lastErrno = osGetLastError())!=ERROR_NOT_LOCKED) ){
         1893  +    pFile->lastErrno = lastErrno;
         1894  +    winLogError(SQLITE_IOERR_UNLOCK, pFile->lastErrno,
         1895  +             "unlockReadLock", pFile->zPath);
  1381   1896     }
  1382   1897     return res;
  1383   1898   }
  1384   1899   
  1385   1900   /*
  1386   1901   ** Lock the file with the lock specified by parameter locktype - one
  1387   1902   ** of the following:
................................................................................
  1406   1921   ** This routine will only increase a lock.  The winUnlock() routine
  1407   1922   ** erases all locks at once and returns us immediately to locking level 0.
  1408   1923   ** It is not possible to lower the locking level one step at a time.  You
  1409   1924   ** must go straight to locking level 0.
  1410   1925   */
  1411   1926   static int winLock(sqlite3_file *id, int locktype){
  1412   1927     int rc = SQLITE_OK;    /* Return code from subroutines */
  1413         -  int res = 1;           /* Result of a windows lock call */
         1928  +  int res = 1;           /* Result of a Windows lock call */
  1414   1929     int newLocktype;       /* Set pFile->locktype to this value before exiting */
  1415   1930     int gotPendingLock = 0;/* True if we acquired a PENDING lock this time */
  1416   1931     winFile *pFile = (winFile*)id;
  1417         -  DWORD error = NO_ERROR;
         1932  +  DWORD lastErrno = NO_ERROR;
  1418   1933   
  1419   1934     assert( id!=0 );
  1420   1935     OSTRACE(("LOCK %d %d was %d(%d)\n",
  1421   1936              pFile->h, locktype, pFile->locktype, pFile->sharedLockByte));
  1422   1937   
  1423   1938     /* If there is already a lock of this type or more restrictive on the
  1424   1939     ** OsFile, do nothing. Don't use the end_lock: exit path, as
................................................................................
  1440   1955     */
  1441   1956     newLocktype = pFile->locktype;
  1442   1957     if(   (pFile->locktype==NO_LOCK)
  1443   1958        || (   (locktype==EXCLUSIVE_LOCK)
  1444   1959            && (pFile->locktype==RESERVED_LOCK))
  1445   1960     ){
  1446   1961       int cnt = 3;
  1447         -    while( cnt-->0 && (res = LockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
  1448         -      /* Try 3 times to get the pending lock.  The pending lock might be
  1449         -      ** held by another reader process who will release it momentarily.
         1962  +    while( cnt-->0 && (res = osLockFile(pFile->h, PENDING_BYTE, 0, 1, 0))==0 ){
         1963  +      /* Try 3 times to get the pending lock.  This is needed to work
         1964  +      ** around problems caused by indexing and/or anti-virus software on
         1965  +      ** Windows systems.
         1966  +      ** If you are using this code as a model for alternative VFSes, do not
         1967  +      ** copy this retry logic.  It is a hack intended for Windows only.
  1450   1968         */
  1451   1969         OSTRACE(("could not get a PENDING lock. cnt=%d\n", cnt));
  1452         -      Sleep(1);
         1970  +      if( cnt ) osSleep(1);
  1453   1971       }
  1454   1972       gotPendingLock = res;
  1455   1973       if( !res ){
  1456         -      error = GetLastError();
         1974  +      lastErrno = osGetLastError();
  1457   1975       }
  1458   1976     }
  1459   1977   
  1460   1978     /* Acquire a shared lock
  1461   1979     */
  1462   1980     if( locktype==SHARED_LOCK && res ){
  1463   1981       assert( pFile->locktype==NO_LOCK );
  1464   1982       res = getReadLock(pFile);
  1465   1983       if( res ){
  1466   1984         newLocktype = SHARED_LOCK;
  1467   1985       }else{
  1468         -      error = GetLastError();
         1986  +      lastErrno = osGetLastError();
  1469   1987       }
  1470   1988     }
  1471   1989   
  1472   1990     /* Acquire a RESERVED lock
  1473   1991     */
  1474   1992     if( locktype==RESERVED_LOCK && res ){
  1475   1993       assert( pFile->locktype==SHARED_LOCK );
  1476         -    res = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         1994  +    res = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1477   1995       if( res ){
  1478   1996         newLocktype = RESERVED_LOCK;
  1479   1997       }else{
  1480         -      error = GetLastError();
         1998  +      lastErrno = osGetLastError();
  1481   1999       }
  1482   2000     }
  1483   2001   
  1484   2002     /* Acquire a PENDING lock
  1485   2003     */
  1486   2004     if( locktype==EXCLUSIVE_LOCK && res ){
  1487   2005       newLocktype = PENDING_LOCK;
................................................................................
  1490   2008   
  1491   2009     /* Acquire an EXCLUSIVE lock
  1492   2010     */
  1493   2011     if( locktype==EXCLUSIVE_LOCK && res ){
  1494   2012       assert( pFile->locktype>=SHARED_LOCK );
  1495   2013       res = unlockReadLock(pFile);
  1496   2014       OSTRACE(("unreadlock = %d\n", res));
  1497         -    res = LockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
         2015  +    res = osLockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  1498   2016       if( res ){
  1499   2017         newLocktype = EXCLUSIVE_LOCK;
  1500   2018       }else{
  1501         -      error = GetLastError();
  1502         -      OSTRACE(("error-code = %d\n", error));
         2019  +      lastErrno = osGetLastError();
         2020  +      OSTRACE(("error-code = %d\n", lastErrno));
  1503   2021         getReadLock(pFile);
  1504   2022       }
  1505   2023     }
  1506   2024   
  1507   2025     /* If we are holding a PENDING lock that ought to be released, then
  1508   2026     ** release it now.
  1509   2027     */
  1510   2028     if( gotPendingLock && locktype==SHARED_LOCK ){
  1511         -    UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
         2029  +    osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
  1512   2030     }
  1513   2031   
  1514   2032     /* Update the state of the lock has held in the file descriptor then
  1515   2033     ** return the appropriate result code.
  1516   2034     */
  1517   2035     if( res ){
  1518   2036       rc = SQLITE_OK;
  1519   2037     }else{
  1520   2038       OSTRACE(("LOCK FAILED %d trying for %d but got %d\n", pFile->h,
  1521   2039              locktype, newLocktype));
  1522         -    pFile->lastErrno = error;
         2040  +    pFile->lastErrno = lastErrno;
  1523   2041       rc = SQLITE_BUSY;
  1524   2042     }
  1525   2043     pFile->locktype = (u8)newLocktype;
  1526   2044     return rc;
  1527   2045   }
  1528   2046   
  1529   2047   /*
................................................................................
  1538   2056     SimulateIOError( return SQLITE_IOERR_CHECKRESERVEDLOCK; );
  1539   2057   
  1540   2058     assert( id!=0 );
  1541   2059     if( pFile->locktype>=RESERVED_LOCK ){
  1542   2060       rc = 1;
  1543   2061       OSTRACE(("TEST WR-LOCK %d %d (local)\n", pFile->h, rc));
  1544   2062     }else{
  1545         -    rc = LockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         2063  +    rc = osLockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1546   2064       if( rc ){
  1547         -      UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         2065  +      osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1548   2066       }
  1549   2067       rc = !rc;
  1550   2068       OSTRACE(("TEST WR-LOCK %d %d (remote)\n", pFile->h, rc));
  1551   2069     }
  1552   2070     *pResOut = rc;
  1553   2071     return SQLITE_OK;
  1554   2072   }
................................................................................
  1570   2088     int rc = SQLITE_OK;
  1571   2089     assert( pFile!=0 );
  1572   2090     assert( locktype<=SHARED_LOCK );
  1573   2091     OSTRACE(("UNLOCK %d to %d was %d(%d)\n", pFile->h, locktype,
  1574   2092             pFile->locktype, pFile->sharedLockByte));
  1575   2093     type = pFile->locktype;
  1576   2094     if( type>=EXCLUSIVE_LOCK ){
  1577         -    UnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
         2095  +    osUnlockFile(pFile->h, SHARED_FIRST, 0, SHARED_SIZE, 0);
  1578   2096       if( locktype==SHARED_LOCK && !getReadLock(pFile) ){
  1579   2097         /* This should never happen.  We should always be able to
  1580   2098         ** reacquire the read lock */
  1581         -      rc = winLogError(SQLITE_IOERR_UNLOCK, "winUnlock", pFile->zPath);
         2099  +      rc = winLogError(SQLITE_IOERR_UNLOCK, osGetLastError(),
         2100  +               "winUnlock", pFile->zPath);
  1582   2101       }
  1583   2102     }
  1584   2103     if( type>=RESERVED_LOCK ){
  1585         -    UnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
         2104  +    osUnlockFile(pFile->h, RESERVED_BYTE, 0, 1, 0);
  1586   2105     }
  1587   2106     if( locktype==NO_LOCK && type>=SHARED_LOCK ){
  1588   2107       unlockReadLock(pFile);
  1589   2108     }
  1590   2109     if( type>=PENDING_LOCK ){
  1591         -    UnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
         2110  +    osUnlockFile(pFile->h, PENDING_BYTE, 0, 1, 0);
  1592   2111     }
  1593   2112     pFile->locktype = (u8)locktype;
  1594   2113     return rc;
  1595   2114   }
  1596   2115   
  1597   2116   /*
  1598   2117   ** Control and query of the open file handle.
................................................................................
  1830   2349     if( lockType == _SHM_WRLCK ) dwFlags |= LOCKFILE_EXCLUSIVE_LOCK;
  1831   2350   
  1832   2351     memset(&ovlp, 0, sizeof(OVERLAPPED));
  1833   2352     ovlp.Offset = ofst;
  1834   2353   
  1835   2354     /* Release/Acquire the system-level lock */
  1836   2355     if( lockType==_SHM_UNLCK ){
  1837         -    rc = UnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
         2356  +    rc = osUnlockFileEx(pFile->hFile.h, 0, nByte, 0, &ovlp);
  1838   2357     }else{
  1839         -    rc = LockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
         2358  +    rc = osLockFileEx(pFile->hFile.h, dwFlags, 0, nByte, 0, &ovlp);
  1840   2359     }
  1841   2360     
  1842   2361     if( rc!= 0 ){
  1843   2362       rc = SQLITE_OK;
  1844   2363     }else{
  1845         -    pFile->lastErrno =  GetLastError();
         2364  +    pFile->lastErrno =  osGetLastError();
  1846   2365       rc = SQLITE_BUSY;
  1847   2366     }
  1848   2367   
  1849   2368     OSTRACE(("SHM-LOCK %d %s %s 0x%08lx\n", 
  1850   2369              pFile->hFile.h,
  1851   2370              rc==SQLITE_OK ? "ok" : "failed",
  1852   2371              lockType==_SHM_UNLCK ? "UnlockFileEx" : "LockFileEx",
................................................................................
  1872   2391     assert( winShmMutexHeld() );
  1873   2392     pp = &winShmNodeList;
  1874   2393     while( (p = *pp)!=0 ){
  1875   2394       if( p->nRef==0 ){
  1876   2395         int i;
  1877   2396         if( p->mutex ) sqlite3_mutex_free(p->mutex);
  1878   2397         for(i=0; i<p->nRegion; i++){
  1879         -        bRc = UnmapViewOfFile(p->aRegion[i].pMap);
         2398  +        bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
  1880   2399           OSTRACE(("SHM-PURGE pid-%d unmap region=%d %s\n",
  1881         -                 (int)GetCurrentProcessId(), i,
         2400  +                 (int)osGetCurrentProcessId(), i,
  1882   2401                    bRc ? "ok" : "failed"));
  1883         -        bRc = CloseHandle(p->aRegion[i].hMap);
         2402  +        bRc = osCloseHandle(p->aRegion[i].hMap);
  1884   2403           OSTRACE(("SHM-PURGE pid-%d close region=%d %s\n",
  1885         -                 (int)GetCurrentProcessId(), i,
         2404  +                 (int)osGetCurrentProcessId(), i,
  1886   2405                    bRc ? "ok" : "failed"));
  1887   2406         }
  1888   2407         if( p->hFile.h != INVALID_HANDLE_VALUE ){
  1889   2408           SimulateIOErrorBenign(1);
  1890   2409           winClose((sqlite3_file *)&p->hFile);
  1891   2410           SimulateIOErrorBenign(0);
  1892   2411         }
................................................................................
  1920   2439   
  1921   2440     assert( pDbFd->pShm==0 );    /* Not previously opened */
  1922   2441   
  1923   2442     /* Allocate space for the new sqlite3_shm object.  Also speculatively
  1924   2443     ** allocate space for a new winShmNode and filename.
  1925   2444     */
  1926   2445     p = sqlite3_malloc( sizeof(*p) );
  1927         -  if( p==0 ) return SQLITE_NOMEM;
         2446  +  if( p==0 ) return SQLITE_IOERR_NOMEM;
  1928   2447     memset(p, 0, sizeof(*p));
  1929   2448     nName = sqlite3Strlen30(pDbFd->zPath);
  1930   2449     pNew = sqlite3_malloc( sizeof(*pShmNode) + nName + 15 );
  1931   2450     if( pNew==0 ){
  1932   2451       sqlite3_free(p);
  1933         -    return SQLITE_NOMEM;
         2452  +    return SQLITE_IOERR_NOMEM;
  1934   2453     }
  1935   2454     memset(pNew, 0, sizeof(*pNew));
  1936   2455     pNew->zFilename = (char*)&pNew[1];
  1937   2456     sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath);
  1938   2457     sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); 
  1939   2458   
  1940   2459     /* Look to see if there is an existing winShmNode that can be used.
................................................................................
  1954   2473       pNew = 0;
  1955   2474       ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
  1956   2475       pShmNode->pNext = winShmNodeList;
  1957   2476       winShmNodeList = pShmNode;
  1958   2477   
  1959   2478       pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
  1960   2479       if( pShmNode->mutex==0 ){
  1961         -      rc = SQLITE_NOMEM;
         2480  +      rc = SQLITE_IOERR_NOMEM;
  1962   2481         goto shm_open_err;
  1963   2482       }
  1964   2483   
  1965   2484       rc = winOpen(pDbFd->pVfs,
  1966   2485                    pShmNode->zFilename,             /* Name of the file (UTF-8) */
  1967   2486                    (sqlite3_file*)&pShmNode->hFile,  /* File handle here */
  1968   2487                    SQLITE_OPEN_WAL | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, /* Mode flags */
................................................................................
  1974   2493   
  1975   2494       /* Check to see if another process is holding the dead-man switch.
  1976   2495       ** If not, truncate the file to zero length. 
  1977   2496       */
  1978   2497       if( winShmSystemLock(pShmNode, _SHM_WRLCK, WIN_SHM_DMS, 1)==SQLITE_OK ){
  1979   2498         rc = winTruncate((sqlite3_file *)&pShmNode->hFile, 0);
  1980   2499         if( rc!=SQLITE_OK ){
  1981         -        rc = winLogError(SQLITE_IOERR_SHMOPEN, "winOpenShm", pDbFd->zPath);
         2500  +        rc = winLogError(SQLITE_IOERR_SHMOPEN, osGetLastError(),
         2501  +                 "winOpenShm", pDbFd->zPath);
  1982   2502         }
  1983   2503       }
  1984   2504       if( rc==SQLITE_OK ){
  1985   2505         winShmSystemLock(pShmNode, _SHM_UNLCK, WIN_SHM_DMS, 1);
  1986   2506         rc = winShmSystemLock(pShmNode, _SHM_RDLCK, WIN_SHM_DMS, 1);
  1987   2507       }
  1988   2508       if( rc ) goto shm_open_err;
................................................................................
  2159   2679           assert( (p->sharedMask & mask)==0 );
  2160   2680           p->exclMask |= mask;
  2161   2681         }
  2162   2682       }
  2163   2683     }
  2164   2684     sqlite3_mutex_leave(pShmNode->mutex);
  2165   2685     OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x %s\n",
  2166         -           p->id, (int)GetCurrentProcessId(), p->sharedMask, p->exclMask,
         2686  +           p->id, (int)osGetCurrentProcessId(), p->sharedMask, p->exclMask,
  2167   2687              rc ? "failed" : "ok"));
  2168   2688     return rc;
  2169   2689   }
  2170   2690   
  2171   2691   /*
  2172   2692   ** Implement a memory barrier or memory fence on shared memory.  
  2173   2693   **
................................................................................
  2233   2753   
  2234   2754       /* The requested region is not mapped into this processes address space.
  2235   2755       ** Check to see if it has been allocated (i.e. if the wal-index file is
  2236   2756       ** large enough to contain the requested region).
  2237   2757       */
  2238   2758       rc = winFileSize((sqlite3_file *)&pShmNode->hFile, &sz);
  2239   2759       if( rc!=SQLITE_OK ){
  2240         -      rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap1", pDbFd->zPath);
         2760  +      rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
         2761  +               "winShmMap1", pDbFd->zPath);
  2241   2762         goto shmpage_out;
  2242   2763       }
  2243   2764   
  2244   2765       if( sz<nByte ){
  2245   2766         /* The requested memory region does not exist. If isWrite is set to
  2246   2767         ** zero, exit early. *pp will be set to NULL and SQLITE_OK returned.
  2247   2768         **
  2248   2769         ** Alternatively, if isWrite is non-zero, use ftruncate() to allocate
  2249   2770         ** the requested memory region.
  2250   2771         */
  2251   2772         if( !isWrite ) goto shmpage_out;
  2252   2773         rc = winTruncate((sqlite3_file *)&pShmNode->hFile, nByte);
  2253   2774         if( rc!=SQLITE_OK ){
  2254         -        rc = winLogError(SQLITE_IOERR_SHMSIZE, "winShmMap2", pDbFd->zPath);
         2775  +        rc = winLogError(SQLITE_IOERR_SHMSIZE, osGetLastError(),
         2776  +                 "winShmMap2", pDbFd->zPath);
  2255   2777           goto shmpage_out;
  2256   2778         }
  2257   2779       }
  2258   2780   
  2259   2781       /* Map the requested memory region into this processes address space. */
  2260   2782       apNew = (struct ShmRegion *)sqlite3_realloc(
  2261   2783           pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
................................................................................
  2266   2788       }
  2267   2789       pShmNode->aRegion = apNew;
  2268   2790   
  2269   2791       while( pShmNode->nRegion<=iRegion ){
  2270   2792         HANDLE hMap;                /* file-mapping handle */
  2271   2793         void *pMap = 0;             /* Mapped memory region */
  2272   2794        
  2273         -      hMap = CreateFileMapping(pShmNode->hFile.h, 
         2795  +      hMap = osCreateFileMapping(pShmNode->hFile.h, 
  2274   2796             NULL, PAGE_READWRITE, 0, nByte, NULL
  2275   2797         );
  2276   2798         OSTRACE(("SHM-MAP pid-%d create region=%d nbyte=%d %s\n",
  2277         -               (int)GetCurrentProcessId(), pShmNode->nRegion, nByte,
         2799  +               (int)osGetCurrentProcessId(), pShmNode->nRegion, nByte,
  2278   2800                  hMap ? "ok" : "failed"));
  2279   2801         if( hMap ){
  2280   2802           int iOffset = pShmNode->nRegion*szRegion;
  2281   2803           int iOffsetShift = iOffset % winSysInfo.dwAllocationGranularity;
  2282         -        pMap = MapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
         2804  +        pMap = osMapViewOfFile(hMap, FILE_MAP_WRITE | FILE_MAP_READ,
  2283   2805               0, iOffset - iOffsetShift, szRegion + iOffsetShift
  2284   2806           );
  2285   2807           OSTRACE(("SHM-MAP pid-%d map region=%d offset=%d size=%d %s\n",
  2286         -                 (int)GetCurrentProcessId(), pShmNode->nRegion, iOffset, szRegion,
  2287         -                 pMap ? "ok" : "failed"));
         2808  +                 (int)osGetCurrentProcessId(), pShmNode->nRegion, iOffset,
         2809  +                 szRegion, pMap ? "ok" : "failed"));
  2288   2810         }
  2289   2811         if( !pMap ){
  2290         -        pShmNode->lastErrno = GetLastError();
  2291         -        rc = winLogError(SQLITE_IOERR_SHMMAP, "winShmMap3", pDbFd->zPath);
  2292         -        if( hMap ) CloseHandle(hMap);
         2812  +        pShmNode->lastErrno = osGetLastError();
         2813  +        rc = winLogError(SQLITE_IOERR_SHMMAP, pShmNode->lastErrno,
         2814  +                 "winShmMap3", pDbFd->zPath);
         2815  +        if( hMap ) osCloseHandle(hMap);
  2293   2816           goto shmpage_out;
  2294   2817         }
  2295   2818   
  2296   2819         pShmNode->aRegion[pShmNode->nRegion].pMap = pMap;
  2297   2820         pShmNode->aRegion[pShmNode->nRegion].hMap = hMap;
  2298   2821         pShmNode->nRegion++;
  2299   2822       }
................................................................................
  2396   2919     SimulateIOError( return SQLITE_IOERR );
  2397   2920   
  2398   2921     if( sqlite3_temp_directory ){
  2399   2922       sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
  2400   2923     }else if( isNT() ){
  2401   2924       char *zMulti;
  2402   2925       WCHAR zWidePath[MAX_PATH];
  2403         -    GetTempPathW(MAX_PATH-30, zWidePath);
         2926  +    osGetTempPathW(MAX_PATH-30, zWidePath);
  2404   2927       zMulti = unicodeToUtf8(zWidePath);
  2405   2928       if( zMulti ){
  2406   2929         sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
  2407         -      free(zMulti);
         2930  +      sqlite3_free(zMulti);
  2408   2931       }else{
  2409         -      return SQLITE_NOMEM;
         2932  +      return SQLITE_IOERR_NOMEM;
  2410   2933       }
  2411   2934   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2412         -** Since the ASCII version of these Windows API do not exist for WINCE,
         2935  +** Since the ANSI version of these Windows API do not exist for WINCE,
  2413   2936   ** it's important to not reference them for WINCE builds.
  2414   2937   */
  2415   2938   #if SQLITE_OS_WINCE==0
  2416   2939     }else{
  2417   2940       char *zUtf8;
  2418   2941       char zMbcsPath[MAX_PATH];
  2419         -    GetTempPathA(MAX_PATH-30, zMbcsPath);
         2942  +    osGetTempPathA(MAX_PATH-30, zMbcsPath);
  2420   2943       zUtf8 = sqlite3_win32_mbcs_to_utf8(zMbcsPath);
  2421   2944       if( zUtf8 ){
  2422   2945         sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
  2423         -      free(zUtf8);
         2946  +      sqlite3_free(zUtf8);
  2424   2947       }else{
  2425         -      return SQLITE_NOMEM;
         2948  +      return SQLITE_IOERR_NOMEM;
  2426   2949       }
  2427   2950   #endif
  2428   2951     }
  2429   2952   
  2430   2953     /* Check that the output buffer is large enough for the temporary file 
  2431   2954     ** name. If it is not, return SQLITE_ERROR.
  2432   2955     */
................................................................................
  2457   2980     sqlite3_vfs *pVfs,        /* Not used */
  2458   2981     const char *zName,        /* Name of the file (UTF-8) */
  2459   2982     sqlite3_file *id,         /* Write the SQLite file handle here */
  2460   2983     int flags,                /* Open mode flags */
  2461   2984     int *pOutFlags            /* Status return flags */
  2462   2985   ){
  2463   2986     HANDLE h;
         2987  +  DWORD lastErrno;
  2464   2988     DWORD dwDesiredAccess;
  2465   2989     DWORD dwShareMode;
  2466   2990     DWORD dwCreationDisposition;
  2467   2991     DWORD dwFlagsAndAttributes = 0;
  2468   2992   #if SQLITE_OS_WINCE
  2469   2993     int isTemp = 0;
  2470   2994   #endif
................................................................................
  2541   3065       }
  2542   3066       zUtf8Name = zTmpname;
  2543   3067     }
  2544   3068   
  2545   3069     /* Convert the filename to the system encoding. */
  2546   3070     zConverted = convertUtf8Filename(zUtf8Name);
  2547   3071     if( zConverted==0 ){
  2548         -    return SQLITE_NOMEM;
         3072  +    return SQLITE_IOERR_NOMEM;
  2549   3073     }
  2550   3074   
  2551   3075     if( isReadWrite ){
  2552   3076       dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
  2553   3077     }else{
  2554   3078       dwDesiredAccess = GENERIC_READ;
  2555   3079     }
................................................................................
  2587   3111     /* Reports from the internet are that performance is always
  2588   3112     ** better if FILE_FLAG_RANDOM_ACCESS is used.  Ticket #2699. */
  2589   3113   #if SQLITE_OS_WINCE
  2590   3114     dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS;
  2591   3115   #endif
  2592   3116   
  2593   3117     if( isNT() ){
  2594         -    while( (h = CreateFileW((WCHAR*)zConverted,
  2595         -                            dwDesiredAccess,
  2596         -                            dwShareMode, NULL,
  2597         -                            dwCreationDisposition,
  2598         -                            dwFlagsAndAttributes,
  2599         -                            NULL))==INVALID_HANDLE_VALUE &&
  2600         -                            retryIoerr(&cnt) ){}
         3118  +    while( (h = osCreateFileW((LPCWSTR)zConverted,
         3119  +                              dwDesiredAccess,
         3120  +                              dwShareMode, NULL,
         3121  +                              dwCreationDisposition,
         3122  +                              dwFlagsAndAttributes,
         3123  +                              NULL))==INVALID_HANDLE_VALUE &&
         3124  +                              retryIoerr(&cnt, &lastErrno) ){}
  2601   3125   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2602         -** Since the ASCII version of these Windows API do not exist for WINCE,
         3126  +** Since the ANSI version of these Windows API do not exist for WINCE,
  2603   3127   ** it's important to not reference them for WINCE builds.
  2604   3128   */
  2605   3129   #if SQLITE_OS_WINCE==0
  2606   3130     }else{
  2607         -    while( (h = CreateFileA((char*)zConverted,
  2608         -                            dwDesiredAccess,
  2609         -                            dwShareMode, NULL,
  2610         -                            dwCreationDisposition,
  2611         -                            dwFlagsAndAttributes,
  2612         -                            NULL))==INVALID_HANDLE_VALUE &&
  2613         -                            retryIoerr(&cnt) ){}
         3131  +    while( (h = osCreateFileA((LPCSTR)zConverted,
         3132  +                              dwDesiredAccess,
         3133  +                              dwShareMode, NULL,
         3134  +                              dwCreationDisposition,
         3135  +                              dwFlagsAndAttributes,
         3136  +                              NULL))==INVALID_HANDLE_VALUE &&
         3137  +                              retryIoerr(&cnt, &lastErrno) ){}
  2614   3138   #endif
  2615   3139     }
  2616   3140   
  2617   3141     logIoerr(cnt);
  2618   3142   
  2619   3143     OSTRACE(("OPEN %d %s 0x%lx %s\n", 
  2620   3144              h, zName, dwDesiredAccess, 
  2621   3145              h==INVALID_HANDLE_VALUE ? "failed" : "ok"));
  2622   3146   
  2623   3147     if( h==INVALID_HANDLE_VALUE ){
  2624         -    pFile->lastErrno = GetLastError();
  2625         -    winLogError(SQLITE_CANTOPEN, "winOpen", zUtf8Name);
  2626         -    free(zConverted);
         3148  +    pFile->lastErrno = lastErrno;
         3149  +    winLogError(SQLITE_CANTOPEN, pFile->lastErrno, "winOpen", zUtf8Name);
         3150  +    sqlite3_free(zConverted);
  2627   3151       if( isReadWrite && !isExclusive ){
  2628   3152         return winOpen(pVfs, zName, id, 
  2629   3153                ((flags|SQLITE_OPEN_READONLY)&~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE)), pOutFlags);
  2630   3154       }else{
  2631   3155         return SQLITE_CANTOPEN_BKPT;
  2632   3156       }
  2633   3157     }
................................................................................
  2649   3173     pFile->zPath = zName;
  2650   3174     pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
  2651   3175   
  2652   3176   #if SQLITE_OS_WINCE
  2653   3177     if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
  2654   3178          && !winceCreateLock(zName, pFile)
  2655   3179     ){
  2656         -    CloseHandle(h);
  2657         -    free(zConverted);
         3180  +    osCloseHandle(h);
         3181  +    sqlite3_free(zConverted);
  2658   3182       return SQLITE_CANTOPEN_BKPT;
  2659   3183     }
  2660   3184     if( isTemp ){
  2661   3185       pFile->zDeleteOnClose = zConverted;
  2662   3186     }else
  2663   3187   #endif
  2664   3188     {
  2665         -    free(zConverted);
         3189  +    sqlite3_free(zConverted);
  2666   3190     }
  2667   3191   
  2668   3192     OpenCounter(+1);
  2669   3193     return rc;
  2670   3194   }
  2671   3195   
  2672   3196   /*
  2673   3197   ** Delete the named file.
  2674   3198   **
  2675         -** Note that windows does not allow a file to be deleted if some other
         3199  +** Note that Windows does not allow a file to be deleted if some other
  2676   3200   ** process has it open.  Sometimes a virus scanner or indexing program
  2677   3201   ** will open a journal file shortly after it is created in order to do
  2678   3202   ** whatever it does.  While this other process is holding the
  2679   3203   ** file open, we will be unable to delete it.  To work around this
  2680   3204   ** problem, we delay 100 milliseconds and try to delete again.  Up
  2681   3205   ** to MX_DELETION_ATTEMPTs deletion attempts are run before giving
  2682   3206   ** up and returning an error.
................................................................................
  2684   3208   static int winDelete(
  2685   3209     sqlite3_vfs *pVfs,          /* Not used on win32 */
  2686   3210     const char *zFilename,      /* Name of file to delete */
  2687   3211     int syncDir                 /* Not used on win32 */
  2688   3212   ){
  2689   3213     int cnt = 0;
  2690   3214     int rc;
         3215  +  DWORD lastErrno;
  2691   3216     void *zConverted;
  2692   3217     UNUSED_PARAMETER(pVfs);
  2693   3218     UNUSED_PARAMETER(syncDir);
  2694   3219   
  2695   3220     SimulateIOError(return SQLITE_IOERR_DELETE);
  2696   3221     zConverted = convertUtf8Filename(zFilename);
  2697   3222     if( zConverted==0 ){
  2698         -    return SQLITE_NOMEM;
         3223  +    return SQLITE_IOERR_NOMEM;
  2699   3224     }
  2700   3225     if( isNT() ){
  2701   3226       rc = 1;
  2702         -    while( GetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES &&
  2703         -           (rc = DeleteFileW(zConverted))==0 && retryIoerr(&cnt) ){}
         3227  +    while( osGetFileAttributesW(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         3228  +         (rc = osDeleteFileW(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){}
  2704   3229       rc = rc ? SQLITE_OK : SQLITE_ERROR;
  2705   3230   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2706         -** Since the ASCII version of these Windows API do not exist for WINCE,
         3231  +** Since the ANSI version of these Windows API do not exist for WINCE,
  2707   3232   ** it's important to not reference them for WINCE builds.
  2708   3233   */
  2709   3234   #if SQLITE_OS_WINCE==0
  2710   3235     }else{
  2711   3236       rc = 1;
  2712         -    while( GetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES &&
  2713         -           (rc = DeleteFileA(zConverted))==0 && retryIoerr(&cnt) ){}
         3237  +    while( osGetFileAttributesA(zConverted)!=INVALID_FILE_ATTRIBUTES &&
         3238  +         (rc = osDeleteFileA(zConverted))==0 && retryIoerr(&cnt, &lastErrno) ){}
  2714   3239       rc = rc ? SQLITE_OK : SQLITE_ERROR;
  2715   3240   #endif
  2716   3241     }
  2717   3242     if( rc ){
  2718         -    rc = winLogError(SQLITE_IOERR_DELETE, "winDelete", zFilename);
         3243  +    rc = winLogError(SQLITE_IOERR_DELETE, lastErrno,
         3244  +             "winDelete", zFilename);
  2719   3245     }else{
  2720   3246       logIoerr(cnt);
  2721   3247     }
  2722         -  free(zConverted);
         3248  +  sqlite3_free(zConverted);
  2723   3249     OSTRACE(("DELETE \"%s\" %s\n", zFilename, (rc ? "failed" : "ok" )));
  2724   3250     return rc;
  2725   3251   }
  2726   3252   
  2727   3253   /*
  2728   3254   ** Check the existance and status of a file.
  2729   3255   */
................................................................................
  2731   3257     sqlite3_vfs *pVfs,         /* Not used on win32 */
  2732   3258     const char *zFilename,     /* Name of file to check */
  2733   3259     int flags,                 /* Type of test to make on this file */
  2734   3260     int *pResOut               /* OUT: Result */
  2735   3261   ){
  2736   3262     DWORD attr;
  2737   3263     int rc = 0;
         3264  +  DWORD lastErrno;
  2738   3265     void *zConverted;
  2739   3266     UNUSED_PARAMETER(pVfs);
  2740   3267   
  2741   3268     SimulateIOError( return SQLITE_IOERR_ACCESS; );
  2742   3269     zConverted = convertUtf8Filename(zFilename);
  2743   3270     if( zConverted==0 ){
  2744         -    return SQLITE_NOMEM;
         3271  +    return SQLITE_IOERR_NOMEM;
  2745   3272     }
  2746   3273     if( isNT() ){
  2747   3274       int cnt = 0;
  2748   3275       WIN32_FILE_ATTRIBUTE_DATA sAttrData;
  2749   3276       memset(&sAttrData, 0, sizeof(sAttrData));
  2750         -    while( !(rc = GetFileAttributesExW((WCHAR*)zConverted,
         3277  +    while( !(rc = osGetFileAttributesExW((LPCWSTR)zConverted,
  2751   3278                                GetFileExInfoStandard, 
  2752         -                             &sAttrData)) && retryIoerr(&cnt) ){}
         3279  +                             &sAttrData)) && retryIoerr(&cnt, &lastErrno) ){}
  2753   3280       if( rc ){
  2754   3281         /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
  2755   3282         ** as if it does not exist.
  2756   3283         */
  2757   3284         if(    flags==SQLITE_ACCESS_EXISTS
  2758   3285             && sAttrData.nFileSizeHigh==0 
  2759   3286             && sAttrData.nFileSizeLow==0 ){
  2760   3287           attr = INVALID_FILE_ATTRIBUTES;
  2761   3288         }else{
  2762   3289           attr = sAttrData.dwFileAttributes;
  2763   3290         }
  2764   3291       }else{
  2765   3292         logIoerr(cnt);
  2766         -      if( GetLastError()!=ERROR_FILE_NOT_FOUND ){
  2767         -        winLogError(SQLITE_IOERR_ACCESS, "winAccess", zFilename);
  2768         -        free(zConverted);
         3293  +      if( lastErrno!=ERROR_FILE_NOT_FOUND ){
         3294  +        winLogError(SQLITE_IOERR_ACCESS, lastErrno, "winAccess", zFilename);
         3295  +        sqlite3_free(zConverted);
  2769   3296           return SQLITE_IOERR_ACCESS;
  2770   3297         }else{
  2771   3298           attr = INVALID_FILE_ATTRIBUTES;
  2772   3299         }
  2773   3300       }
  2774   3301   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2775         -** Since the ASCII version of these Windows API do not exist for WINCE,
         3302  +** Since the ANSI version of these Windows API do not exist for WINCE,
  2776   3303   ** it's important to not reference them for WINCE builds.
  2777   3304   */
  2778   3305   #if SQLITE_OS_WINCE==0
  2779   3306     }else{
  2780         -    attr = GetFileAttributesA((char*)zConverted);
         3307  +    attr = osGetFileAttributesA((char*)zConverted);
  2781   3308   #endif
  2782   3309     }
  2783         -  free(zConverted);
         3310  +  sqlite3_free(zConverted);
  2784   3311     switch( flags ){
  2785   3312       case SQLITE_ACCESS_READ:
  2786   3313       case SQLITE_ACCESS_EXISTS:
  2787   3314         rc = attr!=INVALID_FILE_ATTRIBUTES;
  2788   3315         break;
  2789   3316       case SQLITE_ACCESS_READWRITE:
  2790   3317         rc = attr!=INVALID_FILE_ATTRIBUTES &&
................................................................................
  2841   3368     ** using the io-error infrastructure to test that SQLite handles this
  2842   3369     ** function failing. This function could fail if, for example, the
  2843   3370     ** current working directory has been unlinked.
  2844   3371     */
  2845   3372     SimulateIOError( return SQLITE_ERROR );
  2846   3373     UNUSED_PARAMETER(nFull);
  2847   3374     zConverted = convertUtf8Filename(zRelative);
         3375  +  if( zConverted==0 ){
         3376  +    return SQLITE_IOERR_NOMEM;
         3377  +  }
  2848   3378     if( isNT() ){
  2849         -    WCHAR *zTemp;
  2850         -    nByte = GetFullPathNameW((WCHAR*)zConverted, 0, 0, 0) + 3;
  2851         -    zTemp = malloc( nByte*sizeof(zTemp[0]) );
         3379  +    LPWSTR zTemp;
         3380  +    nByte = osGetFullPathNameW((LPCWSTR)zConverted, 0, 0, 0) + 3;
         3381  +    zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
  2852   3382       if( zTemp==0 ){
  2853         -      free(zConverted);
  2854         -      return SQLITE_NOMEM;
         3383  +      sqlite3_free(zConverted);
         3384  +      return SQLITE_IOERR_NOMEM;
  2855   3385       }
  2856         -    GetFullPathNameW((WCHAR*)zConverted, nByte, zTemp, 0);
  2857         -    free(zConverted);
         3386  +    osGetFullPathNameW((LPCWSTR)zConverted, nByte, zTemp, 0);
         3387  +    sqlite3_free(zConverted);
  2858   3388       zOut = unicodeToUtf8(zTemp);
  2859         -    free(zTemp);
         3389  +    sqlite3_free(zTemp);
  2860   3390   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2861         -** Since the ASCII version of these Windows API do not exist for WINCE,
         3391  +** Since the ANSI version of these Windows API do not exist for WINCE,
  2862   3392   ** it's important to not reference them for WINCE builds.
  2863   3393   */
  2864   3394   #if SQLITE_OS_WINCE==0
  2865   3395     }else{
  2866   3396       char *zTemp;
  2867         -    nByte = GetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
  2868         -    zTemp = malloc( nByte*sizeof(zTemp[0]) );
         3397  +    nByte = osGetFullPathNameA((char*)zConverted, 0, 0, 0) + 3;
         3398  +    zTemp = sqlite3_malloc( nByte*sizeof(zTemp[0]) );
  2869   3399       if( zTemp==0 ){
  2870         -      free(zConverted);
  2871         -      return SQLITE_NOMEM;
         3400  +      sqlite3_free(zConverted);
         3401  +      return SQLITE_IOERR_NOMEM;
  2872   3402       }
  2873         -    GetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
  2874         -    free(zConverted);
         3403  +    osGetFullPathNameA((char*)zConverted, nByte, zTemp, 0);
         3404  +    sqlite3_free(zConverted);
  2875   3405       zOut = sqlite3_win32_mbcs_to_utf8(zTemp);
  2876         -    free(zTemp);
         3406  +    sqlite3_free(zTemp);
  2877   3407   #endif
  2878   3408     }
  2879   3409     if( zOut ){
  2880   3410       sqlite3_snprintf(pVfs->mxPathname, zFull, "%s", zOut);
  2881         -    free(zOut);
         3411  +    sqlite3_free(zOut);
  2882   3412       return SQLITE_OK;
  2883   3413     }else{
  2884         -    return SQLITE_NOMEM;
         3414  +    return SQLITE_IOERR_NOMEM;
  2885   3415     }
  2886   3416   #endif
  2887   3417   }
  2888   3418   
  2889   3419   /*
  2890   3420   ** Get the sector size of the device used to store
  2891   3421   ** file.
................................................................................
  2907   3437   
  2908   3438     /*
  2909   3439     ** We need to get the full path name of the file
  2910   3440     ** to get the drive letter to look up the sector
  2911   3441     ** size.
  2912   3442     */
  2913   3443     SimulateIOErrorBenign(1);
         3444  +  sqlite3BeginBenignMalloc();
  2914   3445     rc = winFullPathname(pVfs, zRelative, MAX_PATH, zFullpath);
         3446  +  sqlite3EndBenignMalloc();
  2915   3447     SimulateIOErrorBenign(0);
  2916   3448     if( rc == SQLITE_OK )
  2917   3449     {
  2918         -    void *zConverted = convertUtf8Filename(zFullpath);
         3450  +    void *zConverted;
         3451  +    sqlite3BeginBenignMalloc();
         3452  +    zConverted = convertUtf8Filename(zFullpath);
         3453  +    sqlite3EndBenignMalloc();
  2919   3454       if( zConverted ){
  2920   3455         if( isNT() ){
  2921   3456           /* trim path to just drive reference */
  2922         -        WCHAR *p = zConverted;
         3457  +        LPWSTR p = zConverted;
  2923   3458           for(;*p;p++){
  2924   3459             if( *p == '\\' ){
  2925   3460               *p = '\0';
  2926   3461               break;
  2927   3462             }
  2928   3463           }
  2929         -        dwRet = GetDiskFreeSpaceW((WCHAR*)zConverted,
  2930         -                                  &dwDummy,
  2931         -                                  &bytesPerSector,
  2932         -                                  &dwDummy,
  2933         -                                  &dwDummy);
         3464  +        dwRet = osGetDiskFreeSpaceW((LPCWSTR)zConverted,
         3465  +                                    &dwDummy,
         3466  +                                    &bytesPerSector,
         3467  +                                    &dwDummy,
         3468  +                                    &dwDummy);
  2934   3469         }else{
  2935   3470           /* trim path to just drive reference */
  2936   3471           char *p = (char *)zConverted;
  2937   3472           for(;*p;p++){
  2938   3473             if( *p == '\\' ){
  2939   3474               *p = '\0';
  2940   3475               break;
  2941   3476             }
  2942   3477           }
  2943         -        dwRet = GetDiskFreeSpaceA((char*)zConverted,
  2944         -                                  &dwDummy,
  2945         -                                  &bytesPerSector,
  2946         -                                  &dwDummy,
  2947         -                                  &dwDummy);
         3478  +        dwRet = osGetDiskFreeSpaceA((char*)zConverted,
         3479  +                                    &dwDummy,
         3480  +                                    &bytesPerSector,
         3481  +                                    &dwDummy,
         3482  +                                    &dwDummy);
  2948   3483         }
  2949         -      free(zConverted);
         3484  +      sqlite3_free(zConverted);
  2950   3485       }
  2951   3486       if( !dwRet ){
  2952   3487         bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE;
  2953   3488       }
  2954   3489     }
  2955   3490   #endif
  2956   3491     return (int) bytesPerSector; 
................................................................................
  2969   3504     HANDLE h;
  2970   3505     void *zConverted = convertUtf8Filename(zFilename);
  2971   3506     UNUSED_PARAMETER(pVfs);
  2972   3507     if( zConverted==0 ){
  2973   3508       return 0;
  2974   3509     }
  2975   3510     if( isNT() ){
  2976         -    h = LoadLibraryW((WCHAR*)zConverted);
         3511  +    h = osLoadLibraryW((LPCWSTR)zConverted);
  2977   3512   /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. 
  2978         -** Since the ASCII version of these Windows API do not exist for WINCE,
         3513  +** Since the ANSI version of these Windows API do not exist for WINCE,
  2979   3514   ** it's important to not reference them for WINCE builds.
  2980   3515   */
  2981   3516   #if SQLITE_OS_WINCE==0
  2982   3517     }else{
  2983         -    h = LoadLibraryA((char*)zConverted);
         3518  +    h = osLoadLibraryA((char*)zConverted);
  2984   3519   #endif
  2985   3520     }
  2986         -  free(zConverted);
         3521  +  sqlite3_free(zConverted);
  2987   3522     return (void*)h;
  2988   3523   }
  2989   3524   static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
  2990   3525     UNUSED_PARAMETER(pVfs);
  2991         -  getLastErrorMsg(nBuf, zBufOut);
         3526  +  getLastErrorMsg(osGetLastError(), nBuf, zBufOut);
  2992   3527   }
  2993   3528   static void (*winDlSym(sqlite3_vfs *pVfs, void *pHandle, const char *zSymbol))(void){
  2994   3529     UNUSED_PARAMETER(pVfs);
  2995         -#if SQLITE_OS_WINCE
  2996         -  /* The GetProcAddressA() routine is only available on wince. */
  2997         -  return (void(*)(void))GetProcAddressA((HANDLE)pHandle, zSymbol);
  2998         -#else
  2999         -  /* All other windows platforms expect GetProcAddress() to take
  3000         -  ** an Ansi string regardless of the _UNICODE setting */
  3001         -  return (void(*)(void))GetProcAddress((HANDLE)pHandle, zSymbol);
  3002         -#endif
         3530  +  return (void(*)(void))osGetProcAddressA((HANDLE)pHandle, zSymbol);
  3003   3531   }
  3004   3532   static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
  3005   3533     UNUSED_PARAMETER(pVfs);
  3006         -  FreeLibrary((HANDLE)pHandle);
         3534  +  osFreeLibrary((HANDLE)pHandle);
  3007   3535   }
  3008   3536   #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
  3009   3537     #define winDlOpen  0
  3010   3538     #define winDlError 0
  3011   3539     #define winDlSym   0
  3012   3540     #define winDlClose 0
  3013   3541   #endif
................................................................................
  3021   3549     UNUSED_PARAMETER(pVfs);
  3022   3550   #if defined(SQLITE_TEST)
  3023   3551     n = nBuf;
  3024   3552     memset(zBuf, 0, nBuf);
  3025   3553   #else
  3026   3554     if( sizeof(SYSTEMTIME)<=nBuf-n ){
  3027   3555       SYSTEMTIME x;
  3028         -    GetSystemTime(&x);
         3556  +    osGetSystemTime(&x);
  3029   3557       memcpy(&zBuf[n], &x, sizeof(x));
  3030   3558       n += sizeof(x);
  3031   3559     }
  3032   3560     if( sizeof(DWORD)<=nBuf-n ){
  3033         -    DWORD pid = GetCurrentProcessId();
         3561  +    DWORD pid = osGetCurrentProcessId();
  3034   3562       memcpy(&zBuf[n], &pid, sizeof(pid));
  3035   3563       n += sizeof(pid);
  3036   3564     }
  3037   3565     if( sizeof(DWORD)<=nBuf-n ){
  3038         -    DWORD cnt = GetTickCount();
         3566  +    DWORD cnt = osGetTickCount();
  3039   3567       memcpy(&zBuf[n], &cnt, sizeof(cnt));
  3040   3568       n += sizeof(cnt);
  3041   3569     }
  3042   3570     if( sizeof(LARGE_INTEGER)<=nBuf-n ){
  3043   3571       LARGE_INTEGER i;
  3044         -    QueryPerformanceCounter(&i);
         3572  +    osQueryPerformanceCounter(&i);
  3045   3573       memcpy(&zBuf[n], &i, sizeof(i));
  3046   3574       n += sizeof(i);
  3047   3575     }
  3048   3576   #endif
  3049   3577     return n;
  3050   3578   }
  3051   3579   
  3052   3580   
  3053   3581   /*
  3054   3582   ** Sleep for a little while.  Return the amount of time slept.
  3055   3583   */
  3056   3584   static int winSleep(sqlite3_vfs *pVfs, int microsec){
  3057         -  Sleep((microsec+999)/1000);
         3585  +  osSleep((microsec+999)/1000);
  3058   3586     UNUSED_PARAMETER(pVfs);
  3059   3587     return ((microsec+999)/1000)*1000;
  3060   3588   }
  3061   3589   
  3062   3590   /*
  3063   3591   ** The following variable, if set to a non-zero value, is interpreted as
  3064   3592   ** the number of seconds since 1970 and is used to set the result of
................................................................................
  3089   3617   #endif
  3090   3618     /* 2^32 - to avoid use of LL and warnings in gcc */
  3091   3619     static const sqlite3_int64 max32BitValue = 
  3092   3620         (sqlite3_int64)2000000000 + (sqlite3_int64)2000000000 + (sqlite3_int64)294967296;
  3093   3621   
  3094   3622   #if SQLITE_OS_WINCE
  3095   3623     SYSTEMTIME time;
  3096         -  GetSystemTime(&time);
         3624  +  osGetSystemTime(&time);
  3097   3625     /* if SystemTimeToFileTime() fails, it returns zero. */
  3098         -  if (!SystemTimeToFileTime(&time,&ft)){
         3626  +  if (!osSystemTimeToFileTime(&time,&ft)){
  3099   3627       return SQLITE_ERROR;
  3100   3628     }
  3101   3629   #else
  3102         -  GetSystemTimeAsFileTime( &ft );
         3630  +  osGetSystemTimeAsFileTime( &ft );
  3103   3631   #endif
  3104   3632   
  3105   3633     *piNow = winFiletimeEpoch +
  3106   3634               ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) + 
  3107   3635                  (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000;
  3108   3636   
  3109   3637   #ifdef SQLITE_TEST
................................................................................
  3128   3656       *prNow = i/86400000.0;
  3129   3657     }
  3130   3658     return rc;
  3131   3659   }
  3132   3660   
  3133   3661   /*
  3134   3662   ** The idea is that this function works like a combination of
  3135         -** GetLastError() and FormatMessage() on windows (or errno and
  3136         -** strerror_r() on unix). After an error is returned by an OS
         3663  +** GetLastError() and FormatMessage() on Windows (or errno and
         3664  +** strerror_r() on Unix). After an error is returned by an OS
  3137   3665   ** function, SQLite calls this function with zBuf pointing to
  3138   3666   ** a buffer of nBuf bytes. The OS layer should populate the
  3139   3667   ** buffer with a nul-terminated UTF-8 encoded error message
  3140   3668   ** describing the last IO error to have occurred within the calling
  3141   3669   ** thread.
  3142   3670   **
  3143   3671   ** If the error message is too large for the supplied buffer,
................................................................................
  3158   3686   **
  3159   3687   ** However if an error message is supplied, it will be incorporated
  3160   3688   ** by sqlite into the error message available to the user using
  3161   3689   ** sqlite3_errmsg(), possibly making IO errors easier to debug.
  3162   3690   */
  3163   3691   static int winGetLastError(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
  3164   3692     UNUSED_PARAMETER(pVfs);
  3165         -  return getLastErrorMsg(nBuf, zBuf);
         3693  +  return getLastErrorMsg(osGetLastError(), nBuf, zBuf);
  3166   3694   }
  3167         -
  3168         -
  3169   3695   
  3170   3696   /*
  3171   3697   ** Initialize and deinitialize the operating system interface.
  3172   3698   */
  3173   3699   int sqlite3_os_init(void){
  3174   3700     static sqlite3_vfs winVfs = {
  3175   3701       3,                   /* iVersion */
................................................................................
  3187   3713       winDlSym,            /* xDlSym */
  3188   3714       winDlClose,          /* xDlClose */
  3189   3715       winRandomness,       /* xRandomness */
  3190   3716       winSleep,            /* xSleep */
  3191   3717       winCurrentTime,      /* xCurrentTime */
  3192   3718       winGetLastError,     /* xGetLastError */
  3193   3719       winCurrentTimeInt64, /* xCurrentTimeInt64 */
  3194         -    0,                   /* xSetSystemCall */
  3195         -    0,                   /* xGetSystemCall */
  3196         -    0,                   /* xNextSystemCall */
         3720  +    winSetSystemCall,    /* xSetSystemCall */
         3721  +    winGetSystemCall,    /* xGetSystemCall */
         3722  +    winNextSystemCall,   /* xNextSystemCall */
  3197   3723     };
         3724  +
         3725  +  /* Double-check that the aSyscall[] array has been constructed
         3726  +  ** correctly.  See ticket [bb3a86e890c8e96ab] */
         3727  +  assert( ArraySize(aSyscall)==60 );
  3198   3728   
  3199   3729   #ifndef SQLITE_OMIT_WAL
  3200   3730     /* get memory map allocation granularity */
  3201   3731     memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
  3202         -  GetSystemInfo(&winSysInfo);
         3732  +  osGetSystemInfo(&winSysInfo);
  3203   3733     assert(winSysInfo.dwAllocationGranularity > 0);
  3204   3734   #endif
  3205   3735   
  3206   3736     sqlite3_vfs_register(&winVfs, 1);
  3207   3737     return SQLITE_OK; 
  3208   3738   }
         3739  +
  3209   3740   int sqlite3_os_end(void){ 
  3210   3741     return SQLITE_OK;
  3211   3742   }
  3212   3743   
  3213   3744   #endif /* SQLITE_OS_WIN */

Changes to src/pager.c.

  3297   3297   
  3298   3298   /*
  3299   3299   ** Change the maximum number of in-memory pages that are allowed.
  3300   3300   */
  3301   3301   void sqlite3PagerSetCachesize(Pager *pPager, int mxPage){
  3302   3302     sqlite3PcacheSetCachesize(pPager->pPCache, mxPage);
  3303   3303   }
         3304  +
         3305  +/*
         3306  +** Free as much memory as possible from the pager.
         3307  +*/
         3308  +void sqlite3PagerShrink(Pager *pPager){
         3309  +  sqlite3PcacheShrink(pPager->pPCache);
         3310  +}
  3304   3311   
  3305   3312   /*
  3306   3313   ** Adjust the robustness of the database to damage due to OS crashes
  3307   3314   ** or power failures by changing the number of syncs()s when writing
  3308   3315   ** the rollback journal.  There are three levels:
  3309   3316   **
  3310   3317   **    OFF       sqlite3OsSync() is never called.  This is the default
................................................................................
  6682   6689   ** in backup.c maintains the content of this variable. This module
  6683   6690   ** uses it opaquely as an argument to sqlite3BackupRestart() and
  6684   6691   ** sqlite3BackupUpdate() only.
  6685   6692   */
  6686   6693   sqlite3_backup **sqlite3PagerBackupPtr(Pager *pPager){
  6687   6694     return &pPager->pBackup;
  6688   6695   }
         6696  +
         6697  +#ifndef SQLITE_OMIT_VACUUM
         6698  +/*
         6699  +** Unless this is an in-memory or temporary database, clear the pager cache.
         6700  +*/
         6701  +void sqlite3PagerClearCache(Pager *pPager){
         6702  +  if( !MEMDB && pPager->tempFile==0 ) pager_reset(pPager);
         6703  +}
         6704  +#endif
  6689   6705   
  6690   6706   #ifndef SQLITE_OMIT_WAL
  6691   6707   /*
  6692   6708   ** This function is called when the user invokes "PRAGMA wal_checkpoint",
  6693   6709   ** "PRAGMA wal_blocking_checkpoint" or calls the sqlite3_wal_checkpoint()
  6694   6710   ** or wal_blocking_checkpoint() API functions.
  6695   6711   **
................................................................................
  6863   6879                              pPager->pageSize, (u8*)pPager->pTmpSpace);
  6864   6880         pPager->pWal = 0;
  6865   6881       }
  6866   6882     }
  6867   6883     return rc;
  6868   6884   }
  6869   6885   
  6870         -/*
  6871         -** Unless this is an in-memory or temporary database, clear the pager cache.
  6872         -*/
  6873         -void sqlite3PagerClearCache(Pager *pPager){
  6874         -  if( !MEMDB && pPager->tempFile==0 ) pager_reset(pPager);
  6875         -}
  6876         -
  6877   6886   #ifdef SQLITE_HAS_CODEC
  6878   6887   /*
  6879   6888   ** This function is called by the wal module when writing page content
  6880   6889   ** into the log file.
  6881   6890   **
  6882   6891   ** This function returns a pointer to a buffer containing the encrypted
  6883   6892   ** page content. If a malloc fails, this function may return NULL.

Changes to src/pager.h.

    99     99   int sqlite3PagerReadFileheader(Pager*, int, unsigned char*);
   100    100   
   101    101   /* Functions used to configure a Pager object. */
   102    102   void sqlite3PagerSetBusyhandler(Pager*, int(*)(void *), void *);
   103    103   int sqlite3PagerSetPagesize(Pager*, u32*, int);
   104    104   int sqlite3PagerMaxPageCount(Pager*, int);
   105    105   void sqlite3PagerSetCachesize(Pager*, int);
          106  +void sqlite3PagerShrink(Pager*);
   106    107   void sqlite3PagerSetSafetyLevel(Pager*,int,int,int);
   107    108   int sqlite3PagerLockingMode(Pager *, int);
   108    109   int sqlite3PagerSetJournalMode(Pager *, int);
   109    110   int sqlite3PagerGetJournalMode(Pager*);
   110    111   int sqlite3PagerOkToChangeJournalMode(Pager*);
   111    112   i64 sqlite3PagerJournalSizeLimit(Pager *, i64);
   112    113   sqlite3_backup **sqlite3PagerBackupPtr(Pager*);

Changes to src/parse.y.

    29     29   
    30     30   // This code runs whenever there is a syntax error
    31     31   //
    32     32   %syntax_error {
    33     33     UNUSED_PARAMETER(yymajor);  /* Silence some compiler warnings */
    34     34     assert( TOKEN.z[0] );  /* The tokenizer always gives us a token */
    35     35     sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
    36         -  pParse->parseError = 1;
    37     36   }
    38     37   %stack_overflow {
    39     38     UNUSED_PARAMETER(yypMinor); /* Silence some compiler warnings */
    40     39     sqlite3ErrorMsg(pParse, "parser stack overflow");
    41         -  pParse->parseError = 1;
    42     40   }
    43     41   
    44     42   // The name of the generated procedure that implements the parser
    45     43   // is as follows:
    46     44   %name sqlite3Parser
    47     45   
    48     46   // The following text is included near the beginning of the C source

Changes to src/pcache.c.

    16     16   /*
    17     17   ** A complete page cache is an instance of this structure.
    18     18   */
    19     19   struct PCache {
    20     20     PgHdr *pDirty, *pDirtyTail;         /* List of dirty pages in LRU order */
    21     21     PgHdr *pSynced;                     /* Last synced page in dirty page list */
    22     22     int nRef;                           /* Number of referenced pages */
    23         -  int nMax;                           /* Configured cache size */
           23  +  int szCache;                        /* Configured cache size */
    24     24     int szPage;                         /* Size of every page in this cache */
    25     25     int szExtra;                        /* Size of extra space for each page */
    26     26     int bPurgeable;                     /* True if pages are on backing store */
    27     27     int (*xStress)(void*,PgHdr*);       /* Call to try make a page clean */
    28     28     void *pStress;                      /* Argument to xStress */
    29     29     sqlite3_pcache *pCache;             /* Pluggable cache module */
    30     30     PgHdr *pPage1;                      /* Reference to page 1 */
................................................................................
   127    127   */
   128    128   static void pcacheUnpin(PgHdr *p){
   129    129     PCache *pCache = p->pCache;
   130    130     if( pCache->bPurgeable ){
   131    131       if( p->pgno==1 ){
   132    132         pCache->pPage1 = 0;
   133    133       }
   134         -    sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 0);
          134  +    sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 0);
   135    135     }
   136    136   }
   137    137   
   138    138   /*************************************************** General Interfaces ******
   139    139   **
   140    140   ** Initialize and shutdown the page cache subsystem. Neither of these 
   141    141   ** functions are threadsafe.
   142    142   */
   143    143   int sqlite3PcacheInitialize(void){
   144         -  if( sqlite3GlobalConfig.pcache.xInit==0 ){
          144  +  if( sqlite3GlobalConfig.pcache2.xInit==0 ){
   145    145       /* IMPLEMENTATION-OF: R-26801-64137 If the xInit() method is NULL, then the
   146    146       ** built-in default page cache is used instead of the application defined
   147    147       ** page cache. */
   148    148       sqlite3PCacheSetDefault();
   149    149     }
   150         -  return sqlite3GlobalConfig.pcache.xInit(sqlite3GlobalConfig.pcache.pArg);
          150  +  return sqlite3GlobalConfig.pcache2.xInit(sqlite3GlobalConfig.pcache2.pArg);
   151    151   }
   152    152   void sqlite3PcacheShutdown(void){
   153         -  if( sqlite3GlobalConfig.pcache.xShutdown ){
          153  +  if( sqlite3GlobalConfig.pcache2.xShutdown ){
   154    154       /* IMPLEMENTATION-OF: R-26000-56589 The xShutdown() method may be NULL. */
   155         -    sqlite3GlobalConfig.pcache.xShutdown(sqlite3GlobalConfig.pcache.pArg);
          155  +    sqlite3GlobalConfig.pcache2.xShutdown(sqlite3GlobalConfig.pcache2.pArg);
   156    156     }
   157    157   }
   158    158   
   159    159   /*
   160    160   ** Return the size in bytes of a PCache object.
   161    161   */
   162    162   int sqlite3PcacheSize(void){ return sizeof(PCache); }
................................................................................
   177    177   ){
   178    178     memset(p, 0, sizeof(PCache));
   179    179     p->szPage = szPage;
   180    180     p->szExtra = szExtra;
   181    181     p->bPurgeable = bPurgeable;
   182    182     p->xStress = xStress;
   183    183     p->pStress = pStress;
   184         -  p->nMax = 100;
          184  +  p->szCache = 100;
   185    185   }
   186    186   
   187    187   /*
   188    188   ** Change the page size for PCache object. The caller must ensure that there
   189    189   ** are no outstanding page references when this function is called.
   190    190   */
   191    191   void sqlite3PcacheSetPageSize(PCache *pCache, int szPage){
   192    192     assert( pCache->nRef==0 && pCache->pDirty==0 );
   193    193     if( pCache->pCache ){
   194         -    sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
          194  +    sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
   195    195       pCache->pCache = 0;
   196    196       pCache->pPage1 = 0;
   197    197     }
   198    198     pCache->szPage = szPage;
   199    199   }
          200  +
          201  +/*
          202  +** Compute the number of pages of cache requested.
          203  +*/
          204  +static int numberOfCachePages(PCache *p){
          205  +  if( p->szCache>=0 ){
          206  +    return p->szCache;
          207  +  }else{
          208  +    return (-1024*p->szCache)/(p->szPage+p->szExtra);
          209  +  }
          210  +}
   200    211   
   201    212   /*
   202    213   ** Try to obtain a page from the cache.
   203    214   */
   204    215   int sqlite3PcacheFetch(
   205    216     PCache *pCache,       /* Obtain the page from this cache */
   206    217     Pgno pgno,            /* Page number to obtain */
   207    218     int createFlag,       /* If true, create page if it does not exist already */
   208    219     PgHdr **ppPage        /* Write the page here */
   209    220   ){
   210         -  PgHdr *pPage = 0;
          221  +  sqlite3_pcache_page *pPage = 0;
          222  +  PgHdr *pPgHdr = 0;
   211    223     int eCreate;
   212    224   
   213    225     assert( pCache!=0 );
   214    226     assert( createFlag==1 || createFlag==0 );
   215    227     assert( pgno>0 );
   216    228   
   217    229     /* If the pluggable cache (sqlite3_pcache*) has not been allocated,
   218    230     ** allocate it now.
   219    231     */
   220    232     if( !pCache->pCache && createFlag ){
   221    233       sqlite3_pcache *p;
   222         -    int nByte;
   223         -    nByte = pCache->szPage + pCache->szExtra + sizeof(PgHdr);
   224         -    p = sqlite3GlobalConfig.pcache.xCreate(nByte, pCache->bPurgeable);
          234  +    p = sqlite3GlobalConfig.pcache2.xCreate(
          235  +        pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
          236  +    );
   225    237       if( !p ){
   226    238         return SQLITE_NOMEM;
   227    239       }
   228         -    sqlite3GlobalConfig.pcache.xCachesize(p, pCache->nMax);
          240  +    sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
   229    241       pCache->pCache = p;
   230    242     }
   231    243   
   232    244     eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
   233    245     if( pCache->pCache ){
   234         -    pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, eCreate);
          246  +    pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
   235    247     }
   236    248   
   237    249     if( !pPage && eCreate==1 ){
   238    250       PgHdr *pPg;
   239    251   
   240    252       /* Find a dirty page to write-out and recycle. First try to find a 
   241    253       ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
................................................................................
   254    266       if( pPg ){
   255    267         int rc;
   256    268   #ifdef SQLITE_LOG_CACHE_SPILL
   257    269         sqlite3_log(SQLITE_FULL, 
   258    270                     "spill page %d making room for %d - cache used: %d/%d",
   259    271                     pPg->pgno, pgno,
   260    272                     sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
   261         -                  pCache->nMax);
          273  +                  numberOfCachePages(pCache));
   262    274   #endif
   263    275         rc = pCache->xStress(pCache->pStress, pPg);
   264    276         if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
   265    277           return rc;
   266    278         }
   267    279       }
   268    280   
   269         -    pPage = sqlite3GlobalConfig.pcache.xFetch(pCache->pCache, pgno, 2);
          281  +    pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
   270    282     }
   271    283   
   272    284     if( pPage ){
   273         -    if( !pPage->pData ){
   274         -      memset(pPage, 0, sizeof(PgHdr));
   275         -      pPage->pData = (void *)&pPage[1];
   276         -      pPage->pExtra = (void*)&((char *)pPage->pData)[pCache->szPage];
   277         -      memset(pPage->pExtra, 0, pCache->szExtra);
   278         -      pPage->pCache = pCache;
   279         -      pPage->pgno = pgno;
          285  +    pPgHdr = (PgHdr *)pPage->pExtra;
          286  +
          287  +    if( !pPgHdr->pPage ){
          288  +      memset(pPgHdr, 0, sizeof(PgHdr));
          289  +      pPgHdr->pPage = pPage;
          290  +      pPgHdr->pData = pPage->pBuf;
          291  +      pPgHdr->pExtra = (void *)&pPgHdr[1];
          292  +      memset(pPgHdr->pExtra, 0, pCache->szExtra);
          293  +      pPgHdr->pCache = pCache;
          294  +      pPgHdr->pgno = pgno;
   280    295       }
   281         -    assert( pPage->pCache==pCache );
   282         -    assert( pPage->pgno==pgno );
   283         -    assert( pPage->pData==(void *)&pPage[1] );
   284         -    assert( pPage->pExtra==(void *)&((char *)&pPage[1])[pCache->szPage] );
          296  +    assert( pPgHdr->pCache==pCache );
          297  +    assert( pPgHdr->pgno==pgno );
          298  +    assert( pPgHdr->pData==pPage->pBuf );
          299  +    assert( pPgHdr->pExtra==(void *)&pPgHdr[1] );
   285    300   
   286         -    if( 0==pPage->nRef ){
          301  +    if( 0==pPgHdr->nRef ){
   287    302         pCache->nRef++;
   288    303       }
   289         -    pPage->nRef++;
          304  +    pPgHdr->nRef++;
   290    305       if( pgno==1 ){
   291         -      pCache->pPage1 = pPage;
          306  +      pCache->pPage1 = pPgHdr;
   292    307       }
   293    308     }
   294         -  *ppPage = pPage;
   295         -  return (pPage==0 && eCreate) ? SQLITE_NOMEM : SQLITE_OK;
          309  +  *ppPage = pPgHdr;
          310  +  return (pPgHdr==0 && eCreate) ? SQLITE_NOMEM : SQLITE_OK;
   296    311   }
   297    312   
   298    313   /*
   299    314   ** Decrement the reference count on a page. If the page is clean and the
   300    315   ** reference count drops to 0, then it is made elible for recycling.
   301    316   */
   302    317   void sqlite3PcacheRelease(PgHdr *p){
................................................................................
   335    350       pcacheRemoveFromDirtyList(p);
   336    351     }
   337    352     pCache = p->pCache;
   338    353     pCache->nRef--;
   339    354     if( p->pgno==1 ){
   340    355       pCache->pPage1 = 0;
   341    356     }
   342         -  sqlite3GlobalConfig.pcache.xUnpin(pCache->pCache, p, 1);
          357  +  sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, p->pPage, 1);
   343    358   }
   344    359   
   345    360   /*
   346    361   ** Make sure the page is marked as dirty. If it isn't dirty already,
   347    362   ** make it so.
   348    363   */
   349    364   void sqlite3PcacheMakeDirty(PgHdr *p){
................................................................................
   393    408   /*
   394    409   ** Change the page number of page p to newPgno. 
   395    410   */
   396    411   void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
   397    412     PCache *pCache = p->pCache;
   398    413     assert( p->nRef>0 );
   399    414     assert( newPgno>0 );
   400         -  sqlite3GlobalConfig.pcache.xRekey(pCache->pCache, p, p->pgno, newPgno);
          415  +  sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
   401    416     p->pgno = newPgno;
   402    417     if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
   403    418       pcacheRemoveFromDirtyList(p);
   404    419       pcacheAddToDirtyList(p);
   405    420     }
   406    421   }
   407    422   
................................................................................
   430    445           sqlite3PcacheMakeClean(p);
   431    446         }
   432    447       }
   433    448       if( pgno==0 && pCache->pPage1 ){
   434    449         memset(pCache->pPage1->pData, 0, pCache->szPage);
   435    450         pgno = 1;
   436    451       }
   437         -    sqlite3GlobalConfig.pcache.xTruncate(pCache->pCache, pgno+1);
          452  +    sqlite3GlobalConfig.pcache2.xTruncate(pCache->pCache, pgno+1);
   438    453     }
   439    454   }
   440    455   
   441    456   /*
   442    457   ** Close a cache.
   443    458   */
   444    459   void sqlite3PcacheClose(PCache *pCache){
   445    460     if( pCache->pCache ){
   446         -    sqlite3GlobalConfig.pcache.xDestroy(pCache->pCache);
          461  +    sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache);
   447    462     }
   448    463   }
   449    464   
   450    465   /* 
   451    466   ** Discard the contents of the cache.
   452    467   */
   453    468   void sqlite3PcacheClear(PCache *pCache){
................................................................................
   551    566   
   552    567   /* 
   553    568   ** Return the total number of pages in the cache.
   554    569   */
   555    570   int sqlite3PcachePagecount(PCache *pCache){
   556    571     int nPage = 0;
   557    572     if( pCache->pCache ){
   558         -    nPage = sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache);
          573  +    nPage = sqlite3GlobalConfig.pcache2.xPagecount(pCache->pCache);
   559    574     }
   560    575     return nPage;
   561    576   }
   562    577   
   563    578   #ifdef SQLITE_TEST
   564    579   /*
   565    580   ** Get the suggested cache-size value.
   566    581   */
   567    582   int sqlite3PcacheGetCachesize(PCache *pCache){
   568         -  return pCache->nMax;
          583  +  return numberOfCachePages(pCache);
   569    584   }
   570    585   #endif
   571    586   
   572    587   /*
   573    588   ** Set the suggested cache-size value.
   574    589   */
   575    590   void sqlite3PcacheSetCachesize(PCache *pCache, int mxPage){
   576         -  pCache->nMax = mxPage;
          591  +  pCache->szCache = mxPage;
          592  +  if( pCache->pCache ){
          593  +    sqlite3GlobalConfig.pcache2.xCachesize(pCache->pCache,
          594  +                                           numberOfCachePages(pCache));
          595  +  }
          596  +}
          597  +
          598  +/*
          599  +** Free up as much memory as possible from the page cache.
          600  +*/
          601  +void sqlite3PcacheShrink(PCache *pCache){
   577    602     if( pCache->pCache ){
   578         -    sqlite3GlobalConfig.pcache.xCachesize(pCache->pCache, mxPage);
          603  +    sqlite3GlobalConfig.pcache2.xShrink(pCache->pCache);
   579    604     }
   580    605   }
   581    606   
   582    607   #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
   583    608   /*
   584    609   ** For all dirty pages currently in the cache, invoke the specified
   585    610   ** callback. This is only used if the SQLITE_CHECK_PAGES macro is

Changes to src/pcache.h.

    19     19   typedef struct PCache PCache;
    20     20   
    21     21   /*
    22     22   ** Every page in the cache is controlled by an instance of the following
    23     23   ** structure.
    24     24   */
    25     25   struct PgHdr {
    26         -  void *pData;                   /* Content of this page */
           26  +  sqlite3_pcache_page *pPage;    /* Pcache object page handle */
           27  +  void *pData;                   /* Page data */
    27     28     void *pExtra;                  /* Extra content */
    28     29     PgHdr *pDirty;                 /* Transient list of dirty pages */
    29     30     Pgno pgno;                     /* Page number for this page */
    30     31     Pager *pPager;                 /* The pager this page is part of */
    31     32   #ifdef SQLITE_CHECK_PAGES
    32     33     u32 pageHash;                  /* Hash of page content */
    33     34   #endif
................................................................................
   136    137   ** the total number of pages cached by purgeable pager-caches to the sum
   137    138   ** of the suggested cache-sizes.
   138    139   */
   139    140   void sqlite3PcacheSetCachesize(PCache *, int);
   140    141   #ifdef SQLITE_TEST
   141    142   int sqlite3PcacheGetCachesize(PCache *);
   142    143   #endif
          144  +
          145  +/* Free up as much memory as possible from the page cache */
          146  +void sqlite3PcacheShrink(PCache*);
   143    147   
   144    148   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   145    149   /* Try to return memory used by the pcache module to the main memory heap */
   146    150   int sqlite3PcacheReleaseMemory(int);
   147    151   #endif
   148    152   
   149    153   #ifdef SQLITE_TEST
   150    154   void sqlite3PcacheStats(int*,int*,int*,int*);
   151    155   #endif
   152    156   
   153    157   void sqlite3PCacheSetDefault(void);
   154    158   
   155    159   #endif /* _PCACHE_H_ */

Changes to src/pcache1.c.

    20     20   #include "sqliteInt.h"
    21     21   
    22     22   typedef struct PCache1 PCache1;
    23     23   typedef struct PgHdr1 PgHdr1;
    24     24   typedef struct PgFreeslot PgFreeslot;
    25     25   typedef struct PGroup PGroup;
    26     26   
    27         -
    28     27   /* Each page cache (or PCache) belongs to a PGroup.  A PGroup is a set 
    29     28   ** of one or more PCaches that are able to recycle each others unpinned
    30     29   ** pages when they are under memory pressure.  A PGroup is an instance of
    31     30   ** the following object.
    32     31   **
    33     32   ** This page cache implementation works in one of two modes:
    34     33   **
................................................................................
    68     67     /* Cache configuration parameters. Page size (szPage) and the purgeable
    69     68     ** flag (bPurgeable) are set when the cache is created. nMax may be 
    70     69     ** modified at any time by a call to the pcache1CacheSize() method.
    71     70     ** The PGroup mutex must be held when accessing nMax.
    72     71     */
    73     72     PGroup *pGroup;                     /* PGroup this cache belongs to */
    74     73     int szPage;                         /* Size of allocated pages in bytes */
           74  +  int szExtra;                        /* Size of extra space in bytes */
    75     75     int bPurgeable;                     /* True if cache is purgeable */
    76     76     unsigned int nMin;                  /* Minimum number of pages reserved */
    77     77     unsigned int nMax;                  /* Configured "cache_size" value */
    78     78     unsigned int n90pct;                /* nMax*9/10 */
    79     79   
    80     80     /* Hash table of all pages. The following variables may only be accessed
    81     81     ** when the accessor is holding the PGroup mutex.
................................................................................
    86     86     PgHdr1 **apHash;                    /* Hash table for fast lookup by key */
    87     87   
    88     88     unsigned int iMaxKey;               /* Largest key seen since xTruncate() */
    89     89   };
    90     90   
    91     91   /*
    92     92   ** Each cache entry is represented by an instance of the following 
    93         -** structure. A buffer of PgHdr1.pCache->szPage bytes is allocated 
    94         -** directly before this structure in memory (see the PGHDR1_TO_PAGE() 
    95         -** macro below).
           93  +** structure. Unless SQLITE_PCACHE_SEPARATE_HEADER is defined, a buffer of
           94  +** PgHdr1.pCache->szPage bytes is allocated directly before this structure 
           95  +** in memory.
    96     96   */
    97     97   struct PgHdr1 {
           98  +  sqlite3_pcache_page page;
    98     99     unsigned int iKey;             /* Key value (page number) */
    99    100     PgHdr1 *pNext;                 /* Next in hash table chain */
   100    101     PCache1 *pCache;               /* Cache that currently owns this page */
   101    102     PgHdr1 *pLruNext;              /* Next in LRU list of unpinned pages */
   102    103     PgHdr1 *pLruPrev;              /* Previous in LRU list of unpinned pages */
   103    104   };
   104    105   
................................................................................
   140    141   /*
   141    142   ** All code in this file should access the global structure above via the
   142    143   ** alias "pcache1". This ensures that the WSD emulation is used when
   143    144   ** compiling for systems that do not support real WSD.
   144    145   */
   145    146   #define pcache1 (GLOBAL(struct PCacheGlobal, pcache1_g))
   146    147   
   147         -/*
   148         -** When a PgHdr1 structure is allocated, the associated PCache1.szPage
   149         -** bytes of data are located directly before it in memory (i.e. the total
   150         -** size of the allocation is sizeof(PgHdr1)+PCache1.szPage byte). The
   151         -** PGHDR1_TO_PAGE() macro takes a pointer to a PgHdr1 structure as
   152         -** an argument and returns a pointer to the associated block of szPage
   153         -** bytes. The PAGE_TO_PGHDR1() macro does the opposite: its argument is
   154         -** a pointer to a block of szPage bytes of data and the return value is
   155         -** a pointer to the associated PgHdr1 structure.
   156         -**
   157         -**   assert( PGHDR1_TO_PAGE(PAGE_TO_PGHDR1(pCache, X))==X );
   158         -*/
   159         -#define PGHDR1_TO_PAGE(p)    (void*)(((char*)p) - p->pCache->szPage)
   160         -#define PAGE_TO_PGHDR1(c, p) (PgHdr1*)(((char*)p) + c->szPage)
   161         -
   162    148   /*
   163    149   ** Macros to enter and leave the PCache LRU mutex.
   164    150   */
   165    151   #define pcache1EnterMutex(X) sqlite3_mutex_enter((X)->mutex)
   166    152   #define pcache1LeaveMutex(X) sqlite3_mutex_leave((X)->mutex)
   167    153   
   168    154   /******************************************************************************/
................................................................................
   237    223     }
   238    224     return p;
   239    225   }
   240    226   
   241    227   /*
   242    228   ** Free an allocated buffer obtained from pcache1Alloc().
   243    229   */
   244         -static void pcache1Free(void *p){
   245         -  if( p==0 ) return;
          230  +static int pcache1Free(void *p){
          231  +  int nFreed = 0;
          232  +  if( p==0 ) return 0;
   246    233     if( p>=pcache1.pStart && p<pcache1.pEnd ){
   247    234       PgFreeslot *pSlot;
   248    235       sqlite3_mutex_enter(pcache1.mutex);
   249    236       sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_USED, -1);
   250    237       pSlot = (PgFreeslot*)p;
   251    238       pSlot->pNext = pcache1.pFree;
   252    239       pcache1.pFree = pSlot;
   253    240       pcache1.nFreeSlot++;
   254    241       pcache1.bUnderPressure = pcache1.nFreeSlot<pcache1.nReserve;
   255    242       assert( pcache1.nFreeSlot<=pcache1.nSlot );
   256    243       sqlite3_mutex_leave(pcache1.mutex);
   257    244     }else{
   258         -    int iSize;
   259    245       assert( sqlite3MemdebugHasType(p, MEMTYPE_PCACHE) );
   260    246       sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
   261         -    iSize = sqlite3MallocSize(p);
          247  +    nFreed = sqlite3MallocSize(p);
   262    248       sqlite3_mutex_enter(pcache1.mutex);
   263         -    sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -iSize);
          249  +    sqlite3StatusAdd(SQLITE_STATUS_PAGECACHE_OVERFLOW, -nFreed);
   264    250       sqlite3_mutex_leave(pcache1.mutex);
   265    251       sqlite3_free(p);
   266    252     }
          253  +  return nFreed;
   267    254   }
   268    255   
   269    256   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   270    257   /*
   271    258   ** Return the size of a pcache allocation
   272    259   */
   273    260   static int pcache1MemSize(void *p){
................................................................................
   284    271   }
   285    272   #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */
   286    273   
   287    274   /*
   288    275   ** Allocate a new page object initially associated with cache pCache.
   289    276   */
   290    277   static PgHdr1 *pcache1AllocPage(PCache1 *pCache){
   291         -  int nByte = sizeof(PgHdr1) + pCache->szPage;
   292    278     PgHdr1 *p = 0;
   293    279     void *pPg;
   294    280   
   295    281     /* The group mutex must be released before pcache1Alloc() is called. This
   296    282     ** is because it may call sqlite3_release_memory(), which assumes that 
   297    283     ** this mutex is not held. */
   298    284     assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
   299    285     pcache1LeaveMutex(pCache->pGroup);
   300         -  pPg = pcache1Alloc(nByte);
          286  +#ifdef SQLITE_PCACHE_SEPARATE_HEADER
          287  +  pPg = pcache1Alloc(pCache->szPage);
          288  +  p = sqlite3Malloc(sizeof(PgHdr1) + pCache->szExtra);
          289  +  if( !pPg || !p ){
          290  +    pcache1Free(pPg);
          291  +    sqlite3_free(p);
          292  +    pPg = 0;
          293  +  }
          294  +#else
          295  +  pPg = pcache1Alloc(sizeof(PgHdr1) + pCache->szPage + pCache->szExtra);
          296  +  p = (PgHdr1 *)&((u8 *)pPg)[pCache->szPage];
          297  +#endif
   301    298     pcache1EnterMutex(pCache->pGroup);
   302    299   
   303    300     if( pPg ){
   304         -    p = PAGE_TO_PGHDR1(pCache, pPg);
          301  +    p->page.pBuf = pPg;
          302  +    p->page.pExtra = &p[1];
   305    303       if( pCache->bPurgeable ){
   306    304         pCache->pGroup->nCurrentPage++;
   307    305       }
          306  +    return p;
   308    307     }
   309         -  return p;
          308  +  return 0;
   310    309   }
   311    310   
   312    311   /*
   313    312   ** Free a page object allocated by pcache1AllocPage().
   314    313   **
   315    314   ** The pointer is allowed to be NULL, which is prudent.  But it turns out
   316    315   ** that the current implementation happens to never call this routine
   317    316   ** with a NULL pointer, so we mark the NULL test with ALWAYS().
   318    317   */
   319    318   static void pcache1FreePage(PgHdr1 *p){
   320    319     if( ALWAYS(p) ){
   321    320       PCache1 *pCache = p->pCache;
   322    321       assert( sqlite3_mutex_held(p->pCache->pGroup->mutex) );
   323         -    pcache1Free(PGHDR1_TO_PAGE(p));
          322  +    pcache1Free(p->page.pBuf);
          323  +#ifdef SQLITE_PCACHE_SEPARATE_HEADER
          324  +    sqlite3_free(p);
          325  +#endif
   324    326       if( pCache->bPurgeable ){
   325    327         pCache->pGroup->nCurrentPage--;
   326    328       }
   327    329     }
   328    330   }
   329    331   
   330    332   /*
................................................................................
   357    359   **
   358    360   ** Or, the heap is used for all page cache memory put the heap is
   359    361   ** under memory pressure, then again it is desirable to avoid
   360    362   ** allocating a new page cache entry in order to avoid stressing
   361    363   ** the heap even further.
   362    364   */
   363    365   static int pcache1UnderMemoryPressure(PCache1 *pCache){
   364         -  if( pcache1.nSlot && pCache->szPage<=pcache1.szSlot ){
          366  +  if( pcache1.nSlot && (pCache->szPage+pCache->szExtra)<=pcache1.szSlot ){
   365    367       return pcache1.bUnderPressure;
   366    368     }else{
   367    369       return sqlite3HeapNearlyFull();
   368    370     }
   369    371   }
   370    372   
   371    373   /******************************************************************************/
................................................................................
   548    550   }
   549    551   
   550    552   /*
   551    553   ** Implementation of the sqlite3_pcache.xCreate method.
   552    554   **
   553    555   ** Allocate a new cache.
   554    556   */
   555         -static sqlite3_pcache *pcache1Create(int szPage, int bPurgeable){
          557  +static sqlite3_pcache *pcache1Create(int szPage, int szExtra, int bPurgeable){
   556    558     PCache1 *pCache;      /* The newly created page cache */
   557    559     PGroup *pGroup;       /* The group the new page cache will belong to */
   558    560     int sz;               /* Bytes of memory required to allocate the new cache */
   559    561   
   560    562     /*
   561    563     ** The seperateCache variable is true if each PCache has its own private
   562    564     ** PGroup.  In other words, separateCache is true for mode (1) where no
................................................................................
   570    572     **      use separate caches (mode-1)
   571    573     */
   572    574   #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) || SQLITE_THREADSAFE==0
   573    575     const int separateCache = 0;
   574    576   #else
   575    577     int separateCache = sqlite3GlobalConfig.bCoreMutex>0;
   576    578   #endif
          579  +
          580  +  assert( (szPage & (szPage-1))==0 && szPage>=512 && szPage<=65536 );
          581  +  assert( szExtra < 300 );
   577    582   
   578    583     sz = sizeof(PCache1) + sizeof(PGroup)*separateCache;
   579    584     pCache = (PCache1 *)sqlite3_malloc(sz);
   580    585     if( pCache ){
   581    586       memset(pCache, 0, sz);
   582    587       if( separateCache ){
   583    588         pGroup = (PGroup*)&pCache[1];
   584    589         pGroup->mxPinned = 10;
   585    590       }else{
   586    591         pGroup = &pcache1.grp;
   587    592       }
   588    593       pCache->pGroup = pGroup;
   589    594       pCache->szPage = szPage;
          595  +    pCache->szExtra = szExtra;
   590    596       pCache->bPurgeable = (bPurgeable ? 1 : 0);
   591    597       if( bPurgeable ){
   592    598         pCache->nMin = 10;
   593    599         pcache1EnterMutex(pGroup);
   594    600         pGroup->nMinPage += pCache->nMin;
   595    601         pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
   596    602         pcache1LeaveMutex(pGroup);
................................................................................
   613    619       pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
   614    620       pCache->nMax = nMax;
   615    621       pCache->n90pct = pCache->nMax*9/10;
   616    622       pcache1EnforceMaxPage(pGroup);
   617    623       pcache1LeaveMutex(pGroup);
   618    624     }
   619    625   }
          626  +
          627  +/*
          628  +** Implementation of the sqlite3_pcache.xShrink method. 
          629  +**
          630  +** Free up as much memory as possible.
          631  +*/
          632  +static void pcache1Shrink(sqlite3_pcache *p){
          633  +  PCache1 *pCache = (PCache1*)p;
          634  +  if( pCache->bPurgeable ){
          635  +    PGroup *pGroup = pCache->pGroup;
          636  +    int savedMaxPage;
          637  +    pcache1EnterMutex(pGroup);
          638  +    savedMaxPage = pGroup->nMaxPage;
          639  +    pGroup->nMaxPage = 0;
          640  +    pcache1EnforceMaxPage(pGroup);
          641  +    pGroup->nMaxPage = savedMaxPage;
          642  +    pcache1LeaveMutex(pGroup);
          643  +  }
          644  +}
   620    645   
   621    646   /*
   622    647   ** Implementation of the sqlite3_pcache.xPagecount method. 
   623    648   */
   624    649   static int pcache1Pagecount(sqlite3_pcache *p){
   625    650     int n;
   626    651     PCache1 *pCache = (PCache1*)p;
................................................................................
   680    705   **
   681    706   **      then attempt to recycle a page from the LRU list. If it is the right
   682    707   **      size, return the recycled buffer. Otherwise, free the buffer and
   683    708   **      proceed to step 5. 
   684    709   **
   685    710   **   5. Otherwise, allocate and return a new page buffer.
   686    711   */
   687         -static void *pcache1Fetch(sqlite3_pcache *p, unsigned int iKey, int createFlag){
          712  +static sqlite3_pcache_page *pcache1Fetch(
          713  +  sqlite3_pcache *p, 
          714  +  unsigned int iKey, 
          715  +  int createFlag
          716  +){
   688    717     int nPinned;
   689    718     PCache1 *pCache = (PCache1 *)p;
   690    719     PGroup *pGroup;
   691    720     PgHdr1 *pPage = 0;
   692    721   
   693    722     assert( pCache->bPurgeable || createFlag!=1 );
   694    723     assert( pCache->bPurgeable || pCache->nMin==0 );
................................................................................
   715    744     ** optimization:  The common case is to exit the module before reaching
   716    745     ** this point.
   717    746     */
   718    747   #ifdef SQLITE_MUTEX_OMIT
   719    748     pGroup = pCache->pGroup;
   720    749   #endif
   721    750   
   722         -
   723    751     /* Step 3: Abort if createFlag is 1 but the cache is nearly full */
   724    752     nPinned = pCache->nPage - pCache->nRecyclable;
   725    753     assert( nPinned>=0 );
   726    754     assert( pGroup->mxPinned == pGroup->nMaxPage + 10 - pGroup->nMinPage );
   727    755     assert( pCache->n90pct == pCache->nMax*9/10 );
   728    756     if( createFlag==1 && (
   729    757           nPinned>=pGroup->mxPinned
................................................................................
   739    767   
   740    768     /* Step 4. Try to recycle a page. */
   741    769     if( pCache->bPurgeable && pGroup->pLruTail && (
   742    770            (pCache->nPage+1>=pCache->nMax)
   743    771         || pGroup->nCurrentPage>=pGroup->nMaxPage
   744    772         || pcache1UnderMemoryPressure(pCache)
   745    773     )){
   746         -    PCache1 *pOtherCache;
          774  +    PCache1 *pOther;
   747    775       pPage = pGroup->pLruTail;
   748    776       pcache1RemoveFromHash(pPage);
   749    777       pcache1PinPage(pPage);
   750         -    if( (pOtherCache = pPage->pCache)->szPage!=pCache->szPage ){
          778  +    pOther = pPage->pCache;
          779  +
          780  +    /* We want to verify that szPage and szExtra are the same for pOther
          781  +    ** and pCache.  Assert that we can verify this by comparing sums. */
          782  +    assert( (pCache->szPage & (pCache->szPage-1))==0 && pCache->szPage>=512 );
          783  +    assert( pCache->szExtra<512 );
          784  +    assert( (pOther->szPage & (pOther->szPage-1))==0 && pOther->szPage>=512 );
          785  +    assert( pOther->szExtra<512 );
          786  +
          787  +    if( pOther->szPage+pOther->szExtra != pCache->szPage+pCache->szExtra ){
   751    788         pcache1FreePage(pPage);
   752    789         pPage = 0;
   753    790       }else{
   754         -      pGroup->nCurrentPage -= 
   755         -               (pOtherCache->bPurgeable - pCache->bPurgeable);
          791  +      pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
   756    792       }
   757    793     }
   758    794   
   759    795     /* Step 5. If a usable page buffer has still not been found, 
   760    796     ** attempt to allocate a new one. 
   761    797     */
   762    798     if( !pPage ){
................................................................................
   769    805       unsigned int h = iKey % pCache->nHash;
   770    806       pCache->nPage++;
   771    807       pPage->iKey = iKey;
   772    808       pPage->pNext = pCache->apHash[h];
   773    809       pPage->pCache = pCache;
   774    810       pPage->pLruPrev = 0;
   775    811       pPage->pLruNext = 0;
   776         -    *(void **)(PGHDR1_TO_PAGE(pPage)) = 0;
          812  +    *(void **)pPage->page.pExtra = 0;
   777    813       pCache->apHash[h] = pPage;
   778    814     }
   779    815   
   780    816   fetch_out:
   781    817     if( pPage && iKey>pCache->iMaxKey ){
   782    818       pCache->iMaxKey = iKey;
   783    819     }
   784    820     pcache1LeaveMutex(pGroup);
   785         -  return (pPage ? PGHDR1_TO_PAGE(pPage) : 0);
          821  +  return &pPage->page;
   786    822   }
   787    823   
   788    824   
   789    825   /*
   790    826   ** Implementation of the sqlite3_pcache.xUnpin method.
   791    827   **
   792    828   ** Mark a page as unpinned (eligible for asynchronous recycling).
   793    829   */
   794         -static void pcache1Unpin(sqlite3_pcache *p, void *pPg, int reuseUnlikely){
          830  +static void pcache1Unpin(
          831  +  sqlite3_pcache *p, 
          832  +  sqlite3_pcache_page *pPg, 
          833  +  int reuseUnlikely
          834  +){
   795    835     PCache1 *pCache = (PCache1 *)p;
   796         -  PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
          836  +  PgHdr1 *pPage = (PgHdr1 *)pPg;
   797    837     PGroup *pGroup = pCache->pGroup;
   798    838    
   799    839     assert( pPage->pCache==pCache );
   800    840     pcache1EnterMutex(pGroup);
   801    841   
   802    842     /* It is an error to call this function if the page is already 
   803    843     ** part of the PGroup LRU list.
................................................................................
   825    865   }
   826    866   
   827    867   /*
   828    868   ** Implementation of the sqlite3_pcache.xRekey method. 
   829    869   */
   830    870   static void pcache1Rekey(
   831    871     sqlite3_pcache *p,
   832         -  void *pPg,
          872  +  sqlite3_pcache_page *pPg,
   833    873     unsigned int iOld,
   834    874     unsigned int iNew
   835    875   ){
   836    876     PCache1 *pCache = (PCache1 *)p;
   837         -  PgHdr1 *pPage = PAGE_TO_PGHDR1(pCache, pPg);
          877  +  PgHdr1 *pPage = (PgHdr1 *)pPg;
   838    878     PgHdr1 **pp;
   839    879     unsigned int h; 
   840    880     assert( pPage->iKey==iOld );
   841    881     assert( pPage->pCache==pCache );
   842    882   
   843    883     pcache1EnterMutex(pCache->pGroup);
   844    884   
................................................................................
   899    939   
   900    940   /*
   901    941   ** This function is called during initialization (sqlite3_initialize()) to
   902    942   ** install the default pluggable cache module, assuming the user has not
   903    943   ** already provided an alternative.
   904    944   */
   905    945   void sqlite3PCacheSetDefault(void){
   906         -  static const sqlite3_pcache_methods defaultMethods = {
          946  +  static const sqlite3_pcache_methods2 defaultMethods = {
          947  +    1,                       /* iVersion */
   907    948       0,                       /* pArg */
   908    949       pcache1Init,             /* xInit */
   909    950       pcache1Shutdown,         /* xShutdown */
   910    951       pcache1Create,           /* xCreate */
   911    952       pcache1Cachesize,        /* xCachesize */
   912    953       pcache1Pagecount,        /* xPagecount */
   913    954       pcache1Fetch,            /* xFetch */
   914    955       pcache1Unpin,            /* xUnpin */
   915    956       pcache1Rekey,            /* xRekey */
   916    957       pcache1Truncate,         /* xTruncate */
   917         -    pcache1Destroy           /* xDestroy */
          958  +    pcache1Destroy,          /* xDestroy */
          959  +    pcache1Shrink            /* xShrink */
   918    960     };
   919         -  sqlite3_config(SQLITE_CONFIG_PCACHE, &defaultMethods);
          961  +  sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultMethods);
   920    962   }
   921    963   
   922    964   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
   923    965   /*
   924    966   ** This function is called to free superfluous dynamically allocated memory
   925    967   ** held by the pager system. Memory in use by any SQLite pager allocated
   926    968   ** by the current thread may be sqlite3_free()ed.
................................................................................
   933    975     int nFree = 0;
   934    976     assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
   935    977     assert( sqlite3_mutex_notheld(pcache1.mutex) );
   936    978     if( pcache1.pStart==0 ){
   937    979       PgHdr1 *p;
   938    980       pcache1EnterMutex(&pcache1.grp);
   939    981       while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){
   940         -      nFree += pcache1MemSize(PGHDR1_TO_PAGE(p));
          982  +      nFree += pcache1MemSize(p->page.pBuf);
          983  +#ifdef SQLITE_PCACHE_SEPARATE_HEADER
          984  +      nFree += sqlite3MemSize(p);
          985  +#endif
   941    986         pcache1PinPage(p);
   942    987         pcache1RemoveFromHash(p);
   943    988         pcache1FreePage(p);
   944    989       }
   945    990       pcache1LeaveMutex(&pcache1.grp);
   946    991     }
   947    992     return nFree;

Changes to src/pragma.c.

   343    343   
   344    344     assert( pId2 );
   345    345     zDb = pId2->n>0 ? pDb->zName : 0;
   346    346     if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
   347    347       goto pragma_out;
   348    348     }
   349    349    
   350         -#ifndef SQLITE_OMIT_PAGER_PRAGMAS
          350  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   351    351     /*
   352    352     **  PRAGMA [database.]default_cache_size
   353    353     **  PRAGMA [database.]default_cache_size=N
   354    354     **
   355    355     ** The first form reports the current persistent setting for the
   356    356     ** page cache size.  The value returned is the maximum number of
   357    357     ** pages in the page cache.  The second form sets both the current
................................................................................
   392    392         sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
   393    393         sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
   394    394         assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   395    395         pDb->pSchema->cache_size = size;
   396    396         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   397    397       }
   398    398     }else
          399  +#endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
   399    400   
          401  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   400    402     /*
   401    403     **  PRAGMA [database.]page_size
   402    404     **  PRAGMA [database.]page_size=N
   403    405     **
   404    406     ** The first form reports the current setting for the
   405    407     ** database page size in bytes.  The second form sets the
   406    408     ** database page size value.  The value can only be set if
................................................................................
   413    415         i64 size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
   414    416         returnSingleInt(pParse, "page_size", &size);
   415    417       }else{
   416    418         /* Malloc may fail when setting the page-size, as there is an internal
   417    419         ** buffer that the pager module resizes using sqlite3_realloc().
   418    420         */
   419    421         db->nextPagesize = sqlite3Atoi(zRight);
   420         -      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
          422  +      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize,-1,0) ){
   421    423           db->mallocFailed = 1;
   422    424         }
   423    425       }
   424    426     }else
   425    427   
   426    428     /*
   427    429     **  PRAGMA [database.]secure_delete
................................................................................
   453    455     **  PRAGMA [database.]max_page_count=N
   454    456     **
   455    457     ** The first form reports the current setting for the
   456    458     ** maximum number of pages in the database file.  The 
   457    459     ** second form attempts to change this setting.  Both
   458    460     ** forms return the current setting.
   459    461     **
          462  +  ** The absolute value of N is used.  This is undocumented and might
          463  +  ** change.  The only purpose is to provide an easy way to test
          464  +  ** the sqlite3AbsInt32() function.
          465  +  **
   460    466     **  PRAGMA [database.]page_count
   461    467     **
   462    468     ** Return the number of pages in the specified database.
   463    469     */
   464    470     if( sqlite3StrICmp(zLeft,"page_count")==0
   465    471      || sqlite3StrICmp(zLeft,"max_page_count")==0
   466    472     ){
................................................................................
   467    473       int iReg;
   468    474       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   469    475       sqlite3CodeVerifySchema(pParse, iDb);
   470    476       iReg = ++pParse->nMem;
   471    477       if( sqlite3Tolower(zLeft[0])=='p' ){
   472    478         sqlite3VdbeAddOp2(v, OP_Pagecount, iDb, iReg);
   473    479       }else{
   474         -      sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, sqlite3Atoi(zRight));
          480  +      sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg, 
          481  +                        sqlite3AbsInt32(sqlite3Atoi(zRight)));
   475    482       }
   476    483       sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
   477    484       sqlite3VdbeSetNumCols(v, 1);
   478    485       sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
   479    486     }else
   480    487   
   481    488     /*
................................................................................
   695    702   
   696    703   #ifndef SQLITE_OMIT_PAGER_PRAGMAS
   697    704     /*
   698    705     **  PRAGMA [database.]cache_size
   699    706     **  PRAGMA [database.]cache_size=N
   700    707     **
   701    708     ** The first form reports the current local setting for the
   702         -  ** page cache size.  The local setting can be different from
   703         -  ** the persistent cache size value that is stored in the database
   704         -  ** file itself.  The value returned is the maximum number of
   705         -  ** pages in the page cache.  The second form sets the local
   706         -  ** page cache size value.  It does not change the persistent
   707         -  ** cache size stored on the disk so the cache size will revert
   708         -  ** to its default value when the database is closed and reopened.
   709         -  ** N should be a positive integer.
          709  +  ** page cache size. The second form sets the local
          710  +  ** page cache size value.  If N is positive then that is the
          711  +  ** number of pages in the cache.  If N is negative, then the
          712  +  ** number of pages is adjusted so that the cache uses -N kibibytes
          713  +  ** of memory.
   710    714     */
   711    715     if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
   712    716       if( sqlite3ReadSchema(pParse) ) goto pragma_out;
   713    717       assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   714    718       if( !zRight ){
   715    719         i64 cacheSize = pDb->pSchema->cache_size;
   716    720         returnSingleInt(pParse, "cache_size", &cacheSize);
   717    721       }else{
   718         -      int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
          722  +      int size = sqlite3Atoi(zRight);
   719    723         pDb->pSchema->cache_size = size;
   720    724         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   721    725       }
   722    726     }else
   723    727   
   724    728     /*
   725    729     **   PRAGMA temp_store
................................................................................
  1452   1456       if( db->xWalCallback==sqlite3WalDefaultHook ){
  1453   1457         walArg = SQLITE_PTR_TO_INT(db->pWalArg);
  1454   1458       }
  1455   1459       returnSingleInt(pParse, "wal_autocheckpoint", &walArg);
  1456   1460     }else
  1457   1461   #endif
  1458   1462   
         1463  +  /*
         1464  +  **  PRAGMA shrink_memory
         1465  +  **
         1466  +  ** This pragma attempts to free as much memory as possible from the
         1467  +  ** current database connection.
         1468  +  */
         1469  +  if( sqlite3StrICmp(zLeft, "shrink_memory")==0 ){
         1470  +    sqlite3_db_release_memory(db);
         1471  +  }else
         1472  +
  1459   1473   #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
  1460   1474     /*
  1461   1475     ** Report the current state of file logs for all databases
  1462   1476     */
  1463   1477     if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
  1464   1478       static const char *const azLockName[] = {
  1465   1479         "unlocked", "shared", "reserved", "pending", "exclusive"

Changes to src/prepare.c.

   277    277       }
   278    278     }else{
   279    279       DbSetProperty(db, iDb, DB_Empty);
   280    280     }
   281    281     pDb->pSchema->enc = ENC(db);
   282    282   
   283    283     if( pDb->pSchema->cache_size==0 ){
          284  +#ifndef SQLITE_OMIT_DEPRECATED
   284    285       size = sqlite3AbsInt32(meta[BTREE_DEFAULT_CACHE_SIZE-1]);
   285    286       if( size==0 ){ size = SQLITE_DEFAULT_CACHE_SIZE; }
   286    287       pDb->pSchema->cache_size = size;
          288  +#else
          289  +    pDb->pSchema->cache_size = SQLITE_DEFAULT_CACHE_SIZE;
          290  +#endif
   287    291       sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   288    292     }
   289    293   
   290    294     /*
   291    295     ** file_format==1    Version 3.0.0.
   292    296     ** file_format==2    Version 3.1.3.  // ALTER TABLE ADD COLUMN
   293    297     ** file_format==3    Version 3.1.4.  // ditto but with non-NULL defaults

Changes to src/select.c.

  3856   3856         explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
  3857   3857         sqlite3Select(pParse, pSub, &dest);
  3858   3858         pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
  3859   3859         if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
  3860   3860         retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
  3861   3861         VdbeComment((v, "end %s", pItem->pTab->zName));
  3862   3862         sqlite3VdbeChangeP1(v, topAddr, retAddr);
  3863         -
         3863  +      sqlite3ClearTempRegCache(pParse);
  3864   3864       }
  3865   3865       if( /*pParse->nErr ||*/ db->mallocFailed ){
  3866   3866         goto select_end;
  3867   3867       }
  3868   3868       pParse->nHeight -= sqlite3SelectExprHeight(p);
  3869   3869       pTabList = p->pSrc;
  3870   3870       if( !IgnorableOrderby(pDest) ){

Changes to src/shell.c.

  2081   2081         }else{
  2082   2082           zShellStatic = azArg[1];
  2083   2083           rc = sqlite3_exec(p->db,
  2084   2084             "SELECT sql FROM "
  2085   2085             "  (SELECT sql sql, type type, tbl_name tbl_name, name name"
  2086   2086             "     FROM sqlite_master UNION ALL"
  2087   2087             "   SELECT sql, type, tbl_name, name FROM sqlite_temp_master) "
  2088         -          "WHERE tbl_name LIKE shellstatic() AND type!='meta' AND sql NOTNULL "
         2088  +          "WHERE lower(tbl_name) LIKE shellstatic()"
         2089  +          "  AND type!='meta' AND sql NOTNULL "
  2089   2090             "ORDER BY substr(type,2,1), name",
  2090   2091             callback, &data, &zErrMsg);
  2091   2092           zShellStatic = 0;
  2092   2093         }
  2093   2094       }else{
  2094   2095         rc = sqlite3_exec(p->db,
  2095   2096            "SELECT sql FROM "
................................................................................
  2215   2216         { "benign_malloc_hooks",   SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS    },
  2216   2217         { "pending_byte",          SQLITE_TESTCTRL_PENDING_BYTE           },
  2217   2218         { "assert",                SQLITE_TESTCTRL_ASSERT                 },
  2218   2219         { "always",                SQLITE_TESTCTRL_ALWAYS                 },
  2219   2220         { "reserve",               SQLITE_TESTCTRL_RESERVE                },
  2220   2221         { "optimizations",         SQLITE_TESTCTRL_OPTIMIZATIONS          },
  2221   2222         { "iskeyword",             SQLITE_TESTCTRL_ISKEYWORD              },
  2222         -      { "pghdrsz",               SQLITE_TESTCTRL_PGHDRSZ                },
  2223   2223         { "scratchmalloc",         SQLITE_TESTCTRL_SCRATCHMALLOC          },
  2224   2224       };
  2225   2225       int testctrl = -1;
  2226   2226       int rc = 0;
  2227   2227       int i, n;
  2228   2228       open_db(p);
  2229   2229   
................................................................................
  2260   2260             }
  2261   2261             break;
  2262   2262   
  2263   2263           /* sqlite3_test_control(int) */
  2264   2264           case SQLITE_TESTCTRL_PRNG_SAVE:           
  2265   2265           case SQLITE_TESTCTRL_PRNG_RESTORE:        
  2266   2266           case SQLITE_TESTCTRL_PRNG_RESET:
  2267         -        case SQLITE_TESTCTRL_PGHDRSZ:             
  2268   2267             if( nArg==2 ){
  2269   2268               rc = sqlite3_test_control(testctrl);
  2270   2269               printf("%d (0x%08x)\n", rc, rc);
  2271   2270             } else {
  2272   2271               fprintf(stderr,"Error: testctrl %s takes no options\n", azArg[1]);
  2273   2272             }
  2274   2273             break;

Changes to src/sqlite.h.in.

  1370   1370   ** scratch memory beyond what is provided by this configuration option, then 
  1371   1371   ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
  1372   1372   **
  1373   1373   ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1374   1374   ** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1375   1375   ** the database page cache with the default page cache implementation.  
  1376   1376   ** This configuration should not be used if an application-define page
  1377         -** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
         1377  +** cache implementation is loaded using the SQLITE_CONFIG_PCACHE2 option.
  1378   1378   ** There are three arguments to this option: A pointer to 8-byte aligned
  1379   1379   ** memory, the size of each page buffer (sz), and the number of pages (N).
  1380   1380   ** The sz argument should be the size of the largest database page
  1381   1381   ** (a power of two between 512 and 32768) plus a little extra for each
  1382   1382   ** page header.  ^The page header size is 20 to 40 bytes depending on
  1383   1383   ** the host architecture.  ^It is harmless, apart from the wasted memory,
  1384   1384   ** to make sz a little too large.  The first
................................................................................
  1439   1439   ** [database connection].  The first argument is the
  1440   1440   ** size of each lookaside buffer slot and the second is the number of
  1441   1441   ** slots allocated to each database connection.)^  ^(This option sets the
  1442   1442   ** <i>default</i> lookaside size. The [SQLITE_DBCONFIG_LOOKASIDE]
  1443   1443   ** verb to [sqlite3_db_config()] can be used to change the lookaside
  1444   1444   ** configuration on individual connections.)^ </dd>
  1445   1445   **
  1446         -** [[SQLITE_CONFIG_PCACHE]] <dt>SQLITE_CONFIG_PCACHE</dt>
         1446  +** [[SQLITE_CONFIG_PCACHE2]] <dt>SQLITE_CONFIG_PCACHE2</dt>
  1447   1447   ** <dd> ^(This option takes a single argument which is a pointer to
  1448         -** an [sqlite3_pcache_methods] object.  This object specifies the interface
         1448  +** an [sqlite3_pcache_methods2] object.  This object specifies the interface
  1449   1449   ** to a custom page cache implementation.)^  ^SQLite makes a copy of the
  1450   1450   ** object and uses it for page cache memory allocations.</dd>
  1451   1451   **
  1452         -** [[SQLITE_CONFIG_GETPCACHE]] <dt>SQLITE_CONFIG_GETPCACHE</dt>
         1452  +** [[SQLITE_CONFIG_GETPCACHE2]] <dt>SQLITE_CONFIG_GETPCACHE2</dt>
  1453   1453   ** <dd> ^(This option takes a single argument which is a pointer to an
  1454         -** [sqlite3_pcache_methods] object.  SQLite copies of the current
         1454  +** [sqlite3_pcache_methods2] object.  SQLite copies of the current
  1455   1455   ** page cache implementation into that object.)^ </dd>
  1456   1456   **
  1457   1457   ** [[SQLITE_CONFIG_LOG]] <dt>SQLITE_CONFIG_LOG</dt>
  1458   1458   ** <dd> ^The SQLITE_CONFIG_LOG option takes two arguments: a pointer to a
  1459   1459   ** function with a call signature of void(*)(void*,int,const char*), 
  1460   1460   ** and a pointer to void. ^If the function pointer is not NULL, it is
  1461   1461   ** invoked by [sqlite3_log()] to process each logging event.  ^If the
................................................................................
  1480   1480   ** specified as part of [ATTACH] commands are interpreted as URIs, regardless
  1481   1481   ** of whether or not the [SQLITE_OPEN_URI] flag is set when the database
  1482   1482   ** connection is opened. If it is globally disabled, filenames are
  1483   1483   ** only interpreted as URIs if the SQLITE_OPEN_URI flag is set when the
  1484   1484   ** database connection is opened. By default, URI handling is globally
  1485   1485   ** disabled. The default value may be changed by compiling with the
  1486   1486   ** [SQLITE_USE_URI] symbol defined.
         1487  +**
         1488  +** [[SQLITE_CONFIG_PCACHE]] [[SQLITE_CONFIG_GETPCACHE]]
         1489  +** <dt>SQLITE_CONFIG_PCACHE and SQLITE_CONFNIG_GETPCACHE
         1490  +** <dd> These options are obsolete and should not be used by new code.
         1491  +** They are retained for backwards compatibility but are now no-ops.
  1487   1492   ** </dl>
  1488   1493   */
  1489   1494   #define SQLITE_CONFIG_SINGLETHREAD  1  /* nil */
  1490   1495   #define SQLITE_CONFIG_MULTITHREAD   2  /* nil */
  1491   1496   #define SQLITE_CONFIG_SERIALIZED    3  /* nil */
  1492   1497   #define SQLITE_CONFIG_MALLOC        4  /* sqlite3_mem_methods* */
  1493   1498   #define SQLITE_CONFIG_GETMALLOC     5  /* sqlite3_mem_methods* */
................................................................................
  1495   1500   #define SQLITE_CONFIG_PAGECACHE     7  /* void*, int sz, int N */
  1496   1501   #define SQLITE_CONFIG_HEAP          8  /* void*, int nByte, int min */
  1497   1502   #define SQLITE_CONFIG_MEMSTATUS     9  /* boolean */
  1498   1503   #define SQLITE_CONFIG_MUTEX        10  /* sqlite3_mutex_methods* */
  1499   1504   #define SQLITE_CONFIG_GETMUTEX     11  /* sqlite3_mutex_methods* */
  1500   1505   /* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ 
  1501   1506   #define SQLITE_CONFIG_LOOKASIDE    13  /* int int */
  1502         -#define SQLITE_CONFIG_PCACHE       14  /* sqlite3_pcache_methods* */
  1503         -#define SQLITE_CONFIG_GETPCACHE    15  /* sqlite3_pcache_methods* */
         1507  +#define SQLITE_CONFIG_PCACHE       14  /* no-op */
         1508  +#define SQLITE_CONFIG_GETPCACHE    15  /* no-op */
  1504   1509   #define SQLITE_CONFIG_LOG          16  /* xFunc, void* */
  1505   1510   #define SQLITE_CONFIG_URI          17  /* int */
         1511  +#define SQLITE_CONFIG_PCACHE2      18  /* sqlite3_pcache_methods2* */
         1512  +#define SQLITE_CONFIG_GETPCACHE2   19  /* sqlite3_pcache_methods2* */
  1506   1513   
  1507   1514   /*
  1508   1515   ** CAPI3REF: Database Connection Configuration Options
  1509   1516   **
  1510   1517   ** These constants are the available integer configuration options that
  1511   1518   ** can be passed as the second argument to the [sqlite3_db_config()] interface.
  1512   1519   **
................................................................................
  2927   2934   ** database.  ^The [ATTACH] and [DETACH] statements also cause
  2928   2935   ** sqlite3_stmt_readonly() to return true since, while those statements
  2929   2936   ** change the configuration of a database connection, they do not make 
  2930   2937   ** changes to the content of the database files on disk.
  2931   2938   */
  2932   2939   int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
  2933   2940   
         2941  +/*
         2942  +** CAPI3REF: Determine If A Prepared Statement Has Been Reset
         2943  +**
         2944  +** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
         2945  +** [prepared statement] S has been stepped at least once using 
         2946  +** [sqlite3_step(S)] but has not run to completion and/or has not 
         2947  +** been reset using [sqlite3_reset(S)].  ^The sqlite3_stmt_busy(S)
         2948  +** interface returns false if S is a NULL pointer.  If S is not a 
         2949  +** NULL pointer and is not a pointer to a valid [prepared statement]
         2950  +** object, then the behavior is undefined and probably undesirable.
         2951  +**
         2952  +** This interface can be used in combination [sqlite3_next_stmt()]
         2953  +** to locate all prepared statements associated with a database 
         2954  +** connection that are in need of being reset.  This can be used,
         2955  +** for example, in diagnostic routines to search for prepared 
         2956  +** statements that are holding a transaction open.
         2957  +*/
         2958  +int sqlite3_stmt_busy(sqlite3_stmt*);
         2959  +
  2934   2960   /*
  2935   2961   ** CAPI3REF: Dynamically Typed Value Object
  2936   2962   ** KEYWORDS: {protected sqlite3_value} {unprotected sqlite3_value}
  2937   2963   **
  2938   2964   ** SQLite uses the sqlite3_value object to represent all values
  2939   2965   ** that can be stored in a database table. SQLite uses dynamic typing
  2940   2966   ** for the values it stores.  ^Values stored in sqlite3_value objects
................................................................................
  4368   4394   ** returned by sqlite3_db_handle is the same [database connection]
  4369   4395   ** that was the first argument
  4370   4396   ** to the [sqlite3_prepare_v2()] call (or its variants) that was used to
  4371   4397   ** create the statement in the first place.
  4372   4398   */
  4373   4399   sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  4374   4400   
         4401  +/*
         4402  +** CAPI3REF: Return The Filename For A Database Connection
         4403  +**
         4404  +** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
         4405  +** associated with database N of connection D.  ^The main database file
         4406  +** has the name "main".  If there is no attached database N on the database
         4407  +** connection D, or if database N is a temporary or in-memory database, then
         4408  +** a NULL pointer is returned.
         4409  +**
         4410  +** ^The filename returned by this function is the output of the
         4411  +** xFullPathname method of the [VFS].  ^In other words, the filename
         4412  +** will be an absolute pathname, even if the filename used
         4413  +** to open the database originally was a URI or relative pathname.
         4414  +*/
         4415  +const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
         4416  +
  4375   4417   /*
  4376   4418   ** CAPI3REF: Find the next prepared statement
  4377   4419   **
  4378   4420   ** ^This interface returns a pointer to the next [prepared statement] after
  4379   4421   ** pStmt associated with the [database connection] pDb.  ^If pStmt is NULL
  4380   4422   ** then this interface returns a pointer to the first prepared statement
  4381   4423   ** associated with the database connection pDb.  ^If no prepared statement
................................................................................
  4403   4445   ** then the commit is converted into a rollback.
  4404   4446   **
  4405   4447   ** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
  4406   4448   ** return the P argument from the previous call of the same function
  4407   4449   ** on the same [database connection] D, or NULL for
  4408   4450   ** the first call for each function on D.
  4409   4451   **
         4452  +** The commit and rollback hook callbacks are not reentrant.
  4410   4453   ** The callback implementation must not do anything that will modify
  4411   4454   ** the database connection that invoked the callback.  Any actions
  4412   4455   ** to modify the database connection must be deferred until after the
  4413   4456   ** completion of the [sqlite3_step()] call that triggered the commit
  4414   4457   ** or rollback hook in the first place.
  4415         -** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
  4416         -** database connections for the meaning of "modify" in this paragraph.
         4458  +** Note that running any other SQL statements, including SELECT statements,
         4459  +** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
         4460  +** the database connections for the meaning of "modify" in this paragraph.
  4417   4461   **
  4418   4462   ** ^Registering a NULL function disables the callback.
  4419   4463   **
  4420   4464   ** ^When the commit hook callback routine returns zero, the [COMMIT]
  4421   4465   ** operation is allowed to continue normally.  ^If the commit hook
  4422   4466   ** returns non-zero, then the [COMMIT] is converted into a [ROLLBACK].
  4423   4467   ** ^The rollback hook is invoked on a rollback that results from a commit
................................................................................
  4527   4571   ** of heap memory by deallocating non-essential memory allocations
  4528   4572   ** held by the database library.   Memory used to cache database
  4529   4573   ** pages to improve performance is an example of non-essential memory.
  4530   4574   ** ^sqlite3_release_memory() returns the number of bytes actually freed,
  4531   4575   ** which might be more or less than the amount requested.
  4532   4576   ** ^The sqlite3_release_memory() routine is a no-op returning zero
  4533   4577   ** if SQLite is not compiled with [SQLITE_ENABLE_MEMORY_MANAGEMENT].
         4578  +**
         4579  +** See also: [sqlite3_db_release_memory()]
  4534   4580   */
  4535   4581   int sqlite3_release_memory(int);
  4536   4582   
         4583  +/*
         4584  +** CAPI3REF: Free Memory Used By A Database Connection
         4585  +**
         4586  +** ^The sqlite3_db_shrink(D) interface attempts to free as much heap
         4587  +** memory as possible from database connection D. Unlike the
         4588  +** [sqlite3_release_memory()] interface, this interface is effect even
         4589  +** when then [SQLITE_ENABLE_MEMORY_MANAGEMENT] compile-time option is
         4590  +** omitted.
         4591  +**
         4592  +** See also: [sqlite3_release_memory()]
         4593  +*/
         4594  +int sqlite3_db_release_memory(sqlite3*);
         4595  +
  4537   4596   /*
  4538   4597   ** CAPI3REF: Impose A Limit On Heap Size
  4539   4598   **
  4540   4599   ** ^The sqlite3_soft_heap_limit64() interface sets and/or queries the
  4541   4600   ** soft limit on the amount of heap memory that may be allocated by SQLite.
  4542   4601   ** ^SQLite strives to keep heap memory utilization below the soft heap
  4543   4602   ** limit by reducing the number of pages held in the page cache
................................................................................
  4560   4619   **
  4561   4620   ** <ul>
  4562   4621   ** <li> The soft heap limit is set to zero.
  4563   4622   ** <li> Memory accounting is disabled using a combination of the
  4564   4623   **      [sqlite3_config]([SQLITE_CONFIG_MEMSTATUS],...) start-time option and
  4565   4624   **      the [SQLITE_DEFAULT_MEMSTATUS] compile-time option.
  4566   4625   ** <li> An alternative page cache implementation is specified using
  4567         -**      [sqlite3_config]([SQLITE_CONFIG_PCACHE],...).
         4626  +**      [sqlite3_config]([SQLITE_CONFIG_PCACHE2],...).
  4568   4627   ** <li> The page cache allocates from its own memory pool supplied
  4569   4628   **      by [sqlite3_config]([SQLITE_CONFIG_PAGECACHE],...) rather than
  4570   4629   **      from the heap.
  4571   4630   ** </ul>)^
  4572   4631   **
  4573   4632   ** Beginning with SQLite version 3.7.3, the soft heap limit is enforced
  4574   4633   ** regardless of whether or not the [SQLITE_ENABLE_MEMORY_MANAGEMENT]
................................................................................
  5628   5687   #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
  5629   5688   #define SQLITE_TESTCTRL_PENDING_BYTE            11
  5630   5689   #define SQLITE_TESTCTRL_ASSERT                  12
  5631   5690   #define SQLITE_TESTCTRL_ALWAYS                  13
  5632   5691   #define SQLITE_TESTCTRL_RESERVE                 14
  5633   5692   #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  5634   5693   #define SQLITE_TESTCTRL_ISKEYWORD               16
  5635         -#define SQLITE_TESTCTRL_PGHDRSZ                 17
  5636         -#define SQLITE_TESTCTRL_SCRATCHMALLOC           18
  5637         -#define SQLITE_TESTCTRL_LOCALTIME_FAULT         19
  5638         -#define SQLITE_TESTCTRL_LAST                    19
         5694  +#define SQLITE_TESTCTRL_SCRATCHMALLOC           17
         5695  +#define SQLITE_TESTCTRL_LOCALTIME_FAULT         18
         5696  +#define SQLITE_TESTCTRL_LAST                    18
  5639   5697   
  5640   5698   /*
  5641   5699   ** CAPI3REF: SQLite Runtime Status
  5642   5700   **
  5643   5701   ** ^This interface is used to retrieve runtime status information
  5644   5702   ** about the performance of SQLite, and optionally to reset various
  5645   5703   ** highwater marks.  ^The first argument is an integer code for
................................................................................
  5933   5991   **
  5934   5992   ** The sqlite3_pcache type is opaque.  It is implemented by
  5935   5993   ** the pluggable module.  The SQLite core has no knowledge of
  5936   5994   ** its size or internal structure and never deals with the
  5937   5995   ** sqlite3_pcache object except by holding and passing pointers
  5938   5996   ** to the object.
  5939   5997   **
  5940         -** See [sqlite3_pcache_methods] for additional information.
         5998  +** See [sqlite3_pcache_methods2] for additional information.
  5941   5999   */
  5942   6000   typedef struct sqlite3_pcache sqlite3_pcache;
         6001  +
         6002  +/*
         6003  +** CAPI3REF: Custom Page Cache Object
         6004  +**
         6005  +** The sqlite3_pcache_page object represents a single page in the
         6006  +** page cache.  The page cache will allocate instances of this
         6007  +** object.  Various methods of the page cache use pointers to instances
         6008  +** of this object as parameters or as their return value.
         6009  +**
         6010  +** See [sqlite3_pcache_methods2] for additional information.
         6011  +*/
         6012  +typedef struct sqlite3_pcache_page sqlite3_pcache_page;
         6013  +struct sqlite3_pcache_page {
         6014  +  void *pBuf;        /* The content of the page */
         6015  +  void *pExtra;      /* Extra information associated with the page */
         6016  +};
  5943   6017   
  5944   6018   /*
  5945   6019   ** CAPI3REF: Application Defined Page Cache.
  5946   6020   ** KEYWORDS: {page cache}
  5947   6021   **
  5948         -** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE], ...) interface can
         6022  +** ^(The [sqlite3_config]([SQLITE_CONFIG_PCACHE2], ...) interface can
  5949   6023   ** register an alternative page cache implementation by passing in an 
  5950         -** instance of the sqlite3_pcache_methods structure.)^
         6024  +** instance of the sqlite3_pcache_methods2 structure.)^
  5951   6025   ** In many applications, most of the heap memory allocated by 
  5952   6026   ** SQLite is used for the page cache.
  5953   6027   ** By implementing a 
  5954   6028   ** custom page cache using this API, an application can better control
  5955   6029   ** the amount of memory consumed by SQLite, the way in which 
  5956   6030   ** that memory is allocated and released, and the policies used to 
  5957   6031   ** determine exactly which parts of a database file are cached and for 
  5958   6032   ** how long.
  5959   6033   **
  5960   6034   ** The alternative page cache mechanism is an
  5961   6035   ** extreme measure that is only needed by the most demanding applications.
  5962   6036   ** The built-in page cache is recommended for most uses.
  5963   6037   **
  5964         -** ^(The contents of the sqlite3_pcache_methods structure are copied to an
         6038  +** ^(The contents of the sqlite3_pcache_methods2 structure are copied to an
  5965   6039   ** internal buffer by SQLite within the call to [sqlite3_config].  Hence
  5966   6040   ** the application may discard the parameter after the call to
  5967   6041   ** [sqlite3_config()] returns.)^
  5968   6042   **
  5969   6043   ** [[the xInit() page cache method]]
  5970   6044   ** ^(The xInit() method is called once for each effective 
  5971   6045   ** call to [sqlite3_initialize()])^
................................................................................
  5992   6066   ** ^SQLite will never invoke xInit() more than once without an intervening
  5993   6067   ** call to xShutdown().
  5994   6068   **
  5995   6069   ** [[the xCreate() page cache methods]]
  5996   6070   ** ^SQLite invokes the xCreate() method to construct a new cache instance.
  5997   6071   ** SQLite will typically create one cache instance for each open database file,
  5998   6072   ** though this is not guaranteed. ^The
  5999         -** first parameter, szPage, is the size in bytes of the pages that must
  6000         -** be allocated by the cache.  ^szPage will not be a power of two.  ^szPage
  6001         -** will the page size of the database file that is to be cached plus an
  6002         -** increment (here called "R") of less than 250.  SQLite will use the
  6003         -** extra R bytes on each page to store metadata about the underlying
  6004         -** database page on disk.  The value of R depends
         6073  +** parameter parameter, szPage, is the size in bytes of the pages that must
         6074  +** be allocated by the cache.  ^szPage will always a power of two.  ^The
         6075  +** second parameter szExtra is a number of bytes of extra storage 
         6076  +** associated with each page cache entry.  ^The szExtra parameter will
         6077  +** a number less than 250.  SQLite will use the
         6078  +** extra szExtra bytes on each page to store metadata about the underlying
         6079  +** database page on disk.  The value passed into szExtra depends
  6005   6080   ** on the SQLite version, the target platform, and how SQLite was compiled.
  6006         -** ^(R is constant for a particular build of SQLite. Except, there are two
  6007         -** distinct values of R when SQLite is compiled with the proprietary
  6008         -** ZIPVFS extension.)^  ^The second argument to
  6009         -** xCreate(), bPurgeable, is true if the cache being created will
  6010         -** be used to cache database pages of a file stored on disk, or
         6081  +** ^The third argument to xCreate(), bPurgeable, is true if the cache being
         6082  +** created will be used to cache database pages of a file stored on disk, or
  6011   6083   ** false if it is used for an in-memory database. The cache implementation
  6012   6084   ** does not have to do anything special based with the value of bPurgeable;
  6013   6085   ** it is purely advisory.  ^On a cache where bPurgeable is false, SQLite will
  6014   6086   ** never invoke xUnpin() except to deliberately delete a page.
  6015   6087   ** ^In other words, calls to xUnpin() on a cache with bPurgeable set to
  6016   6088   ** false will always have the "discard" flag set to true.  
  6017   6089   ** ^Hence, a cache created with bPurgeable false will
................................................................................
  6027   6099   **
  6028   6100   ** [[the xPagecount() page cache methods]]
  6029   6101   ** The xPagecount() method must return the number of pages currently
  6030   6102   ** stored in the cache, both pinned and unpinned.
  6031   6103   ** 
  6032   6104   ** [[the xFetch() page cache methods]]
  6033   6105   ** The xFetch() method locates a page in the cache and returns a pointer to 
  6034         -** the page, or a NULL pointer.
  6035         -** A "page", in this context, means a buffer of szPage bytes aligned at an
  6036         -** 8-byte boundary. The page to be fetched is determined by the key. ^The
  6037         -** minimum key value is 1.  After it has been retrieved using xFetch, the page 
  6038         -** is considered to be "pinned".
         6106  +** an sqlite3_pcache_page object associated with that page, or a NULL pointer.
         6107  +** The pBuf element of the returned sqlite3_pcache_page object will be a
         6108  +** pointer to a buffer of szPage bytes used to store the content of a 
         6109  +** single database page.  The pExtra element of sqlite3_pcache_page will be
         6110  +** a pointer to the szExtra bytes of extra storage that SQLite has requested
         6111  +** for each entry in the page cache.
         6112  +**
         6113  +** The page to be fetched is determined by the key. ^The minimum key value
         6114  +** is 1.  After it has been retrieved using xFetch, the page is considered
         6115  +** to be "pinned".
  6039   6116   **
  6040   6117   ** If the requested page is already in the page cache, then the page cache
  6041   6118   ** implementation must return a pointer to the page buffer with its content
  6042   6119   ** intact.  If the requested page is not already in the cache, then the
  6043   6120   ** cache implementation should use the value of the createFlag
  6044   6121   ** parameter to help it determined what action to take:
  6045   6122   **
................................................................................
  6086   6163   **
  6087   6164   ** [[the xDestroy() page cache method]]
  6088   6165   ** ^The xDestroy() method is used to delete a cache allocated by xCreate().
  6089   6166   ** All resources associated with the specified cache should be freed. ^After
  6090   6167   ** calling the xDestroy() method, SQLite considers the [sqlite3_pcache*]
  6091   6168   ** handle invalid, and will not use it with any other sqlite3_pcache_methods
  6092   6169   ** functions.
         6170  +**
         6171  +** [[the xShrink() page cache method]]
         6172  +** ^SQLite invokes the xShrink() method when it wants the page cache to
         6173  +** free up as much of heap memory as possible.  The page cache implementation
         6174  +** is not obligated to free any memory, but well-behaved implementions should
         6175  +** do their best.
         6176  +*/
         6177  +typedef struct sqlite3_pcache_methods2 sqlite3_pcache_methods2;
         6178  +struct sqlite3_pcache_methods2 {
         6179  +  int iVersion;
         6180  +  void *pArg;
         6181  +  int (*xInit)(void*);
         6182  +  void (*xShutdown)(void*);
         6183  +  sqlite3_pcache *(*xCreate)(int szPage, int szExtra, int bPurgeable);
         6184  +  void (*xCachesize)(sqlite3_pcache*, int nCachesize);
         6185  +  int (*xPagecount)(sqlite3_pcache*);
         6186  +  sqlite3_pcache_page *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
         6187  +  void (*xUnpin)(sqlite3_pcache*, sqlite3_pcache_page*, int discard);
         6188  +  void (*xRekey)(sqlite3_pcache*, sqlite3_pcache_page*, 
         6189  +      unsigned oldKey, unsigned newKey);
         6190  +  void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
         6191  +  void (*xDestroy)(sqlite3_pcache*);
         6192  +  void (*xShrink)(sqlite3_pcache*);
         6193  +};
         6194  +
         6195  +/*
         6196  +** This is the obsolete pcache_methods object that has now been replaced
         6197  +** by sqlite3_pcache_methods2.  This object is not used by SQLite.  It is
         6198  +** retained in the header file for backwards compatibility only.
  6093   6199   */
  6094   6200   typedef struct sqlite3_pcache_methods sqlite3_pcache_methods;
  6095   6201   struct sqlite3_pcache_methods {
  6096   6202     void *pArg;
  6097   6203     int (*xInit)(void*);
  6098   6204     void (*xShutdown)(void*);
  6099   6205     sqlite3_pcache *(*xCreate)(int szPage, int bPurgeable);
................................................................................
  6101   6207     int (*xPagecount)(sqlite3_pcache*);
  6102   6208     void *(*xFetch)(sqlite3_pcache*, unsigned key, int createFlag);
  6103   6209     void (*xUnpin)(sqlite3_pcache*, void*, int discard);
  6104   6210     void (*xRekey)(sqlite3_pcache*, void*, unsigned oldKey, unsigned newKey);
  6105   6211     void (*xTruncate)(sqlite3_pcache*, unsigned iLimit);
  6106   6212     void (*xDestroy)(sqlite3_pcache*);
  6107   6213   };
         6214  +
  6108   6215   
  6109   6216   /*
  6110   6217   ** CAPI3REF: Online Backup Object
  6111   6218   **
  6112   6219   ** The sqlite3_backup object records state information about an ongoing
  6113   6220   ** online backup operation.  ^The sqlite3_backup object is created by
  6114   6221   ** a call to [sqlite3_backup_init()] and is destroyed by a call to

Changes to src/sqliteInt.h.

   342    342   ** The "file format" number is an integer that is incremented whenever
   343    343   ** the VDBE-level file format changes.  The following macros define the
   344    344   ** the default file format for new databases and the maximum file format
   345    345   ** that the library can read.
   346    346   */
   347    347   #define SQLITE_MAX_FILE_FORMAT 4
   348    348   #ifndef SQLITE_DEFAULT_FILE_FORMAT
   349         -# define SQLITE_DEFAULT_FILE_FORMAT 1
          349  +# define SQLITE_DEFAULT_FILE_FORMAT 4
   350    350   #endif
   351    351   
   352    352   /*
   353    353   ** Determine whether triggers are recursive by default.  This can be
   354    354   ** changed at run-time using a pragma.
   355    355   */
   356    356   #ifndef SQLITE_DEFAULT_RECURSIVE_TRIGGERS
................................................................................
  1150   1150   ** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the
  1151   1151   ** collating sequence is undefined.  Indices built on an undefined
  1152   1152   ** collating sequence may not be read or written.
  1153   1153   */
  1154   1154   struct CollSeq {
  1155   1155     char *zName;          /* Name of the collating sequence, UTF-8 encoded */
  1156   1156     u8 enc;               /* Text encoding handled by xCmp() */
  1157         -  u8 type;              /* One of the SQLITE_COLL_... values below */
  1158   1157     void *pUser;          /* First argument to xCmp() */
  1159   1158     int (*xCmp)(void*,int, const void*, int, const void*);
  1160   1159     void (*xDel)(void*);  /* Destructor for pUser */
  1161   1160   };
  1162   1161   
  1163         -/*
  1164         -** Allowed values of CollSeq.type:
  1165         -*/
  1166         -#define SQLITE_COLL_BINARY  1  /* The default memcmp() collating sequence */
  1167         -#define SQLITE_COLL_NOCASE  2  /* The built-in NOCASE collating sequence */
  1168         -#define SQLITE_COLL_REVERSE 3  /* The built-in REVERSE collating sequence */
  1169         -#define SQLITE_COLL_USER    0  /* Any other user-defined collating sequence */
  1170         -
  1171   1162   /*
  1172   1163   ** A sort order can be either ASC or DESC.
  1173   1164   */
  1174   1165   #define SQLITE_SO_ASC       0  /* Sort in ascending order */
  1175   1166   #define SQLITE_SO_DESC      1  /* Sort in ascending order */
  1176   1167   
  1177   1168   /*
................................................................................
  1449   1440   **
  1450   1441   ** This structure holds a record that has already been disassembled
  1451   1442   ** into its constituent fields.
  1452   1443   */
  1453   1444   struct UnpackedRecord {
  1454   1445     KeyInfo *pKeyInfo;  /* Collation and sort-order information */
  1455   1446     u16 nField;         /* Number of entries in apMem[] */
  1456         -  u16 flags;          /* Boolean settings.  UNPACKED_... below */
         1447  +  u8 flags;           /* Boolean settings.  UNPACKED_... below */
  1457   1448     i64 rowid;          /* Used by UNPACKED_PREFIX_SEARCH */
  1458   1449     Mem *aMem;          /* Values */
  1459   1450   };
  1460   1451   
  1461   1452   /*
  1462   1453   ** Allowed values of UnpackedRecord.flags
  1463   1454   */
  1464         -#define UNPACKED_NEED_FREE     0x0001  /* Memory is from sqlite3Malloc() */
  1465         -#define UNPACKED_NEED_DESTROY  0x0002  /* apMem[]s should all be destroyed */
  1466         -#define UNPACKED_IGNORE_ROWID  0x0004  /* Ignore trailing rowid on key1 */
  1467         -#define UNPACKED_INCRKEY       0x0008  /* Make this key an epsilon larger */
  1468         -#define UNPACKED_PREFIX_MATCH  0x0010  /* A prefix match is considered OK */
  1469         -#define UNPACKED_PREFIX_SEARCH 0x0020  /* A prefix match is considered OK */
         1455  +#define UNPACKED_INCRKEY       0x01  /* Make this key an epsilon larger */
         1456  +#define UNPACKED_PREFIX_MATCH  0x02  /* A prefix match is considered OK */
         1457  +#define UNPACKED_PREFIX_SEARCH 0x04  /* Ignore final (rowid) field */
  1470   1458   
  1471   1459   /*
  1472   1460   ** Each SQL index is represented in memory by an
  1473   1461   ** instance of the following structure.
  1474   1462   **
  1475   1463   ** The columns of the table that are to be indexed are described
  1476   1464   ** by the aiColumn[] field of this structure.  For example, suppose
................................................................................
  2090   2078     double nSelectRow;     /* Estimated number of result rows */
  2091   2079   };
  2092   2080   
  2093   2081   /*
  2094   2082   ** Allowed values for Select.selFlags.  The "SF" prefix stands for
  2095   2083   ** "Select Flag".
  2096   2084   */
  2097         -#define SF_Distinct        0x0001  /* Output should be DISTINCT */
  2098         -#define SF_Resolved        0x0002  /* Identifiers have been resolved */
  2099         -#define SF_Aggregate       0x0004  /* Contains aggregate functions */
  2100         -#define SF_UsesEphemeral   0x0008  /* Uses the OpenEphemeral opcode */
  2101         -#define SF_Expanded        0x0010  /* sqlite3SelectExpand() called on this */
  2102         -#define SF_HasTypeInfo     0x0020  /* FROM subqueries have Table metadata */
  2103         -#define SF_UseSorter       0x0040  /* Sort using a sorter */
         2085  +#define SF_Distinct        0x01  /* Output should be DISTINCT */
         2086  +#define SF_Resolved        0x02  /* Identifiers have been resolved */
         2087  +#define SF_Aggregate       0x04  /* Contains aggregate functions */
         2088  +#define SF_UsesEphemeral   0x08  /* Uses the OpenEphemeral opcode */
         2089  +#define SF_Expanded        0x10  /* sqlite3SelectExpand() called on this */
         2090  +#define SF_HasTypeInfo     0x20  /* FROM subqueries have Table metadata */
         2091  +#define SF_UseSorter       0x40  /* Sort using a sorter */
  2104   2092   
  2105   2093   
  2106   2094   /*
  2107   2095   ** The results of a select can be distributed in several ways.  The
  2108   2096   ** "SRT" prefix means "SELECT Result Type".
  2109   2097   */
  2110   2098   #define SRT_Union        1  /* Store result as keys in an index */
................................................................................
  2211   2199   */
  2212   2200   struct Parse {
  2213   2201     sqlite3 *db;         /* The main database structure */
  2214   2202     int rc;              /* Return code from execution */
  2215   2203     char *zErrMsg;       /* An error message */
  2216   2204     Vdbe *pVdbe;         /* An engine for executing database bytecode */
  2217   2205     u8 colNamesSet;      /* TRUE after OP_ColumnName has been issued to pVdbe */
  2218         -  u8 nameClash;        /* A permanent table name clashes with temp table name */
  2219   2206     u8 checkSchema;      /* Causes schema cookie check after an error */
  2220   2207     u8 nested;           /* Number of nested calls to the parser/code generator */
  2221         -  u8 parseError;       /* True after a parsing error.  Ticket #1794 */
  2222   2208     u8 nTempReg;         /* Number of temporary registers in aTempReg[] */
  2223   2209     u8 nTempInUse;       /* Number of aTempReg[] currently checked out */
  2224   2210     int aTempReg[8];     /* Holding area for temporary registers */
  2225   2211     int nRangeReg;       /* Size of the temporary register block */
  2226   2212     int iRangeReg;       /* First register in temporary register block */
  2227   2213     int nErr;            /* Number of errors seen */
  2228   2214     int nTab;            /* Number of previously allocated VDBE cursors */
  2229   2215     int nMem;            /* Number of memory cells used so far */
  2230   2216     int nSet;            /* Number of sets used so far */
  2231   2217     int ckBase;          /* Base register of data during check constraints */
  2232   2218     int iCacheLevel;     /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
  2233   2219     int iCacheCnt;       /* Counter used to generate aColCache[].lru values */
  2234         -  u8 nColCache;        /* Number of entries in the column cache */
  2235         -  u8 iColCache;        /* Next entry of the cache to replace */
         2220  +  u8 nColCache;        /* Number of entries in aColCache[] */
         2221  +  u8 iColCache;        /* Next entry in aColCache[] to replace */
  2236   2222     struct yColCache {
  2237   2223       int iTable;           /* Table cursor number */
  2238   2224       int iColumn;          /* Table column number */
  2239   2225       u8 tempReg;           /* iReg is a temp register that needs to be freed */
  2240   2226       int iLevel;           /* Nesting level */
  2241   2227       int iReg;             /* Reg with value of this column. 0 means none. */
  2242   2228       int lru;              /* Least recently used entry has the smallest value */
................................................................................
  2270   2256     ** each recursion */
  2271   2257   
  2272   2258     int nVar;            /* Number of '?' variables seen in the SQL so far */
  2273   2259     int nzVar;           /* Number of available slots in azVar[] */
  2274   2260     char **azVar;        /* Pointers to names of parameters */
  2275   2261     Vdbe *pReprepare;    /* VM being reprepared (sqlite3Reprepare()) */
  2276   2262     int nAlias;          /* Number of aliased result set columns */
  2277         -  int nAliasAlloc;     /* Number of allocated slots for aAlias[] */
  2278   2263     int *aAlias;         /* Register used to hold aliased result */
  2279   2264     u8 explain;          /* True if the EXPLAIN flag is found on the query */
  2280   2265     Token sNameToken;    /* Token with unqualified schema object name */
  2281   2266     Token sLastToken;    /* The last token parsed */
  2282   2267     const char *zTail;   /* All SQL text past the last semicolon parsed */
  2283   2268     Table *pNewTable;    /* A table being constructed by CREATE TABLE */
  2284   2269     Trigger *pNewTrigger;     /* Trigger under construct by a CREATE TRIGGER */
................................................................................
  2465   2450     int bFullMutex;                   /* True to enable full mutexing */
  2466   2451     int bOpenUri;                     /* True to interpret filenames as URIs */
  2467   2452     int mxStrlen;                     /* Maximum string length */
  2468   2453     int szLookaside;                  /* Default lookaside buffer size */
  2469   2454     int nLookaside;                   /* Default lookaside buffer count */
  2470   2455     sqlite3_mem_methods m;            /* Low-level memory allocation interface */
  2471   2456     sqlite3_mutex_methods mutex;      /* Low-level mutex interface */
  2472         -  sqlite3_pcache_methods pcache;    /* Low-level page-cache interface */
         2457  +  sqlite3_pcache_methods2 pcache2;  /* Low-level page-cache interface */
  2473   2458     void *pHeap;                      /* Heap storage space */
  2474   2459     int nHeap;                        /* Size of pHeap[] */
  2475   2460     int mnReq, mxReq;                 /* Min and max heap requests sizes */
  2476   2461     void *pScratch;                   /* Scratch memory */
  2477   2462     int szScratch;                    /* Size of each scratch buffer */
  2478   2463     int nScratch;                     /* Number of scratch buffers */
  2479   2464     void *pPage;                      /* Page cache memory */
................................................................................
  2681   2666   int sqlite3KeywordCode(const unsigned char*, int);
  2682   2667   int sqlite3RunParser(Parse*, const char*, char **);
  2683   2668   void sqlite3FinishCoding(Parse*);
  2684   2669   int sqlite3GetTempReg(Parse*);
  2685   2670   void sqlite3ReleaseTempReg(Parse*,int);
  2686   2671   int sqlite3GetTempRange(Parse*,int);
  2687   2672   void sqlite3ReleaseTempRange(Parse*,int,int);
         2673  +void sqlite3ClearTempRegCache(Parse*);
  2688   2674   Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
  2689   2675   Expr *sqlite3Expr(sqlite3*,int,const char*);
  2690   2676   void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
  2691   2677   Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
  2692   2678   Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  2693   2679   Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  2694   2680   void sqlite3ExprAssignVarNumber(Parse*, Expr*);

Changes to src/test1.c.

  2325   2325     }
  2326   2326   
  2327   2327     if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  2328   2328     rc = sqlite3_stmt_readonly(pStmt);
  2329   2329     Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc));
  2330   2330     return TCL_OK;
  2331   2331   }
         2332  +
         2333  +/*
         2334  +** Usage:  sqlite3_stmt_busy  STMT
         2335  +**
         2336  +** Return true if STMT is a non-NULL pointer to a statement
         2337  +** that has been stepped but not to completion.
         2338  +*/
         2339  +static int test_stmt_busy(
         2340  +  void * clientData,
         2341  +  Tcl_Interp *interp,
         2342  +  int objc,
         2343  +  Tcl_Obj *CONST objv[]
         2344  +){
         2345  +  sqlite3_stmt *pStmt;
         2346  +  int rc;
         2347  +
         2348  +  if( objc!=2 ){
         2349  +    Tcl_AppendResult(interp, "wrong # args: should be \"",
         2350  +        Tcl_GetStringFromObj(objv[0], 0), " STMT", 0);
         2351  +    return TCL_ERROR;
         2352  +  }
         2353  +
         2354  +  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
         2355  +  rc = sqlite3_stmt_busy(pStmt);
         2356  +  Tcl_SetObjResult(interp, Tcl_NewBooleanObj(rc));
         2357  +  return TCL_OK;
         2358  +}
  2332   2359   
  2333   2360   /*
  2334   2361   ** Usage:  uses_stmt_journal  STMT
  2335   2362   **
  2336   2363   ** Return true if STMT uses a statement journal.
  2337   2364   */
  2338   2365   static int uses_stmt_journal(
................................................................................
  4607   4634     }
  4608   4635     amt = sqlite3_release_memory(N);
  4609   4636     Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
  4610   4637   #endif
  4611   4638     return TCL_OK;
  4612   4639   }
  4613   4640   
         4641  +
         4642  +/*
         4643  +** Usage:  sqlite3_db_release_memory DB
         4644  +**
         4645  +** Attempt to release memory currently held by database DB.  Return the
         4646  +** result code (which in the current implementation is always zero).
         4647  +*/
         4648  +static int test_db_release_memory(
         4649  +  void * clientData,
         4650  +  Tcl_Interp *interp,
         4651  +  int objc,
         4652  +  Tcl_Obj *CONST objv[]
         4653  +){
         4654  +  sqlite3 *db;
         4655  +  int rc;
         4656  +  if( objc!=2 ){
         4657  +    Tcl_WrongNumArgs(interp, 1, objv, "DB");
         4658  +    return TCL_ERROR;
         4659  +  }
         4660  +  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
         4661  +  rc = sqlite3_db_release_memory(db);
         4662  +  Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
         4663  +  return TCL_OK;
         4664  +}
         4665  +
         4666  +/*
         4667  +** Usage:  sqlite3_db_filename DB DBNAME
         4668  +**
         4669  +** Return the name of a file associated with a database.
         4670  +*/
         4671  +static int test_db_filename(
         4672  +  void * clientData,
         4673  +  Tcl_Interp *interp,
         4674  +  int objc,
         4675  +  Tcl_Obj *CONST objv[]
         4676  +){
         4677  +  sqlite3 *db;
         4678  +  const char *zDbName;
         4679  +  if( objc!=3 ){
         4680  +    Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME");
         4681  +    return TCL_ERROR;
         4682  +  }
         4683  +  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
         4684  +  zDbName = Tcl_GetString(objv[2]);
         4685  +  Tcl_AppendResult(interp, sqlite3_db_filename(db, zDbName), (void*)0);
         4686  +  return TCL_OK;
         4687  +}
         4688  +
  4614   4689   /*
  4615   4690   ** Usage:  sqlite3_soft_heap_limit ?N?
  4616   4691   **
  4617   4692   ** Query or set the soft heap limit for the current thread.  The
  4618   4693   ** limit is only changed if the N is present.  The previous limit
  4619   4694   ** is returned.
  4620   4695   */
................................................................................
  6097   6172        { "sqlite3_expired",               test_expired       ,0 },
  6098   6173        { "sqlite3_transfer_bindings",     test_transfer_bind ,0 },
  6099   6174        { "sqlite3_changes",               test_changes       ,0 },
  6100   6175        { "sqlite3_step",                  test_step          ,0 },
  6101   6176        { "sqlite3_sql",                   test_sql           ,0 },
  6102   6177        { "sqlite3_next_stmt",             test_next_stmt     ,0 },
  6103   6178        { "sqlite3_stmt_readonly",         test_stmt_readonly ,0 },
         6179  +     { "sqlite3_stmt_busy",             test_stmt_busy     ,0 },
  6104   6180        { "uses_stmt_journal",             uses_stmt_journal ,0 },
  6105   6181   
  6106   6182        { "sqlite3_release_memory",        test_release_memory,     0},
         6183  +     { "sqlite3_db_release_memory",     test_db_release_memory,  0},
         6184  +     { "sqlite3_db_filename",           test_db_filename,        0},
  6107   6185        { "sqlite3_soft_heap_limit",       test_soft_heap_limit,    0},
  6108   6186        { "sqlite3_thread_cleanup",        test_thread_cleanup,     0},
  6109   6187        { "sqlite3_pager_refcounts",       test_pager_refcounts,    0},
  6110   6188   
  6111   6189        { "sqlite3_load_extension",        test_load_extension,     0},
  6112   6190        { "sqlite3_enable_load_extension", test_enable_load,        0},
  6113   6191        { "sqlite3_extended_result_codes", test_extended_result_codes, 0},

Changes to src/test_config.c.

    33     33   
    34     34   /*
    35     35   ** This routine sets entries in the global ::sqlite_options() array variable
    36     36   ** according to the compile-time configuration of the database.  Test
    37     37   ** procedures use this to determine when tests should be omitted.
    38     38   */
    39     39   static void set_options(Tcl_Interp *interp){
           40  +#ifdef HAVE_MALLOC_USABLE_SIZE
           41  +  Tcl_SetVar2(interp, "sqlite_options", "malloc_usable_size", "1",
           42  +              TCL_GLOBAL_ONLY);
           43  +#else
           44  +  Tcl_SetVar2(interp, "sqlite_options", "malloc_usable_size", "0",
           45  +              TCL_GLOBAL_ONLY);
           46  +#endif
           47  +
    40     48   #ifdef SQLITE_32BIT_ROWID
    41     49     Tcl_SetVar2(interp, "sqlite_options", "rowid32", "1", TCL_GLOBAL_ONLY);
    42     50   #else
    43     51     Tcl_SetVar2(interp, "sqlite_options", "rowid32", "0", TCL_GLOBAL_ONLY);
    44     52   #endif
    45     53   
    46     54   #ifdef SQLITE_CASE_SENSITIVE_LIKE

Changes to src/test_init.c.

    26     26   */
    27     27   
    28     28   #include "sqliteInt.h"
    29     29   #include <string.h>
    30     30   #include <tcl.h>
    31     31   
    32     32   static struct Wrapped {
    33         -  sqlite3_pcache_methods pcache;
    34         -  sqlite3_mem_methods    mem;
    35         -  sqlite3_mutex_methods  mutex;
           33  +  sqlite3_pcache_methods2 pcache;
           34  +  sqlite3_mem_methods     mem;
           35  +  sqlite3_mutex_methods   mutex;
    36     36   
    37     37     int mem_init;                /* True if mem subsystem is initalized */
    38     38     int mem_fail;                /* True to fail mem subsystem inialization */
    39     39     int mutex_init;              /* True if mutex subsystem is initalized */
    40     40     int mutex_fail;              /* True to fail mutex subsystem inialization */
    41     41     int pcache_init;             /* True if pcache subsystem is initalized */
    42     42     int pcache_fail;             /* True to fail pcache subsystem inialization */
................................................................................
   119    119     return rc;
   120    120   }
   121    121   static void wrPCacheShutdown(void *pArg){
   122    122     wrapped.pcache.xShutdown(wrapped.pcache.pArg);
   123    123     wrapped.pcache_init = 0;
   124    124   }
   125    125   
   126         -static sqlite3_pcache *wrPCacheCreate(int a, int b){
   127         -  return wrapped.pcache.xCreate(a, b);
          126  +static sqlite3_pcache *wrPCacheCreate(int a, int b, int c){
          127  +  return wrapped.pcache.xCreate(a, b, c);
   128    128   }  
   129    129   static void wrPCacheCachesize(sqlite3_pcache *p, int n){
   130    130     wrapped.pcache.xCachesize(p, n);
   131    131   }  
   132    132   static int wrPCachePagecount(sqlite3_pcache *p){
   133    133     return wrapped.pcache.xPagecount(p);
   134    134   }  
   135         -static void *wrPCacheFetch(sqlite3_pcache *p, unsigned a, int b){
          135  +static sqlite3_pcache_page *wrPCacheFetch(sqlite3_pcache *p, unsigned a, int b){
   136    136     return wrapped.pcache.xFetch(p, a, b);
   137    137   }  
   138         -static void wrPCacheUnpin(sqlite3_pcache *p, void *a, int b){
          138  +static void wrPCacheUnpin(sqlite3_pcache *p, sqlite3_pcache_page *a, int b){
   139    139     wrapped.pcache.xUnpin(p, a, b);
   140    140   }  
   141         -static void wrPCacheRekey(sqlite3_pcache *p, void *a, unsigned b, unsigned c){
          141  +static void wrPCacheRekey(
          142  +  sqlite3_pcache *p, 
          143  +  sqlite3_pcache_page *a, 
          144  +  unsigned b, 
          145  +  unsigned c
          146  +){
   142    147     wrapped.pcache.xRekey(p, a, b, c);
   143    148   }  
   144    149   static void wrPCacheTruncate(sqlite3_pcache *p, unsigned a){
   145    150     wrapped.pcache.xTruncate(p, a);
   146    151   }  
   147    152   static void wrPCacheDestroy(sqlite3_pcache *p){
   148    153     wrapped.pcache.xDestroy(p);
................................................................................
   150    155   
   151    156   static void installInitWrappers(void){
   152    157     sqlite3_mutex_methods mutexmethods = {
   153    158       wrMutexInit,  wrMutexEnd,   wrMutexAlloc,
   154    159       wrMutexFree,  wrMutexEnter, wrMutexTry,
   155    160       wrMutexLeave, wrMutexHeld,  wrMutexNotheld
   156    161     };
   157         -  sqlite3_pcache_methods pcachemethods = {
   158         -    0,
          162  +  sqlite3_pcache_methods2 pcachemethods = {
          163  +    1, 0,
   159    164       wrPCacheInit,      wrPCacheShutdown,  wrPCacheCreate, 
   160    165       wrPCacheCachesize, wrPCachePagecount, wrPCacheFetch,
   161    166       wrPCacheUnpin,     wrPCacheRekey,     wrPCacheTruncate,  
   162    167       wrPCacheDestroy
   163    168     };
   164    169     sqlite3_mem_methods memmethods = {
   165    170       wrMemMalloc,   wrMemFree,    wrMemRealloc,
................................................................................
   169    174     };
   170    175   
   171    176     memset(&wrapped, 0, sizeof(wrapped));
   172    177   
   173    178     sqlite3_shutdown();
   174    179     sqlite3_config(SQLITE_CONFIG_GETMUTEX, &wrapped.mutex);
   175    180     sqlite3_config(SQLITE_CONFIG_GETMALLOC, &wrapped.mem);
   176         -  sqlite3_config(SQLITE_CONFIG_GETPCACHE, &wrapped.pcache);
          181  +  sqlite3_config(SQLITE_CONFIG_GETPCACHE2, &wrapped.pcache);
   177    182     sqlite3_config(SQLITE_CONFIG_MUTEX, &mutexmethods);
   178    183     sqlite3_config(SQLITE_CONFIG_MALLOC, &memmethods);
   179         -  sqlite3_config(SQLITE_CONFIG_PCACHE, &pcachemethods);
          184  +  sqlite3_config(SQLITE_CONFIG_PCACHE2, &pcachemethods);
   180    185   }
   181    186   
   182    187   static int init_wrapper_install(
   183    188     ClientData clientData, /* Unused */
   184    189     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   185    190     int objc,              /* Number of arguments */
   186    191     Tcl_Obj *CONST objv[]  /* Command arguments */
................................................................................
   214    219       return TCL_ERROR;
   215    220     }
   216    221   
   217    222     memset(&wrapped, 0, sizeof(&wrapped));
   218    223     sqlite3_shutdown();
   219    224     sqlite3_config(SQLITE_CONFIG_MUTEX, &wrapped.mutex);
   220    225     sqlite3_config(SQLITE_CONFIG_MALLOC, &wrapped.mem);
   221         -  sqlite3_config(SQLITE_CONFIG_PCACHE, &wrapped.pcache);
          226  +  sqlite3_config(SQLITE_CONFIG_PCACHE2, &wrapped.pcache);
   222    227     return TCL_OK;
   223    228   }
   224    229   
   225    230   static int init_wrapper_clear(
   226    231     ClientData clientData, /* Unused */
   227    232     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   228    233     int objc,              /* Number of arguments */

Changes to src/test_multiplex.c.

    92     92   ** the xFileControl() interface.  It will be rounded up to a 
    93     93   ** multiple of MAX_PAGE_SIZE.  We default it here to 2GiB less 64KiB.
    94     94   */
    95     95   #ifndef SQLITE_MULTIPLEX_CHUNK_SIZE
    96     96   # define SQLITE_MULTIPLEX_CHUNK_SIZE 2147418112
    97     97   #endif
    98     98   
    99         -/* Default limit on number of chunks.  Care should be taken
   100         -** so that values for chunks numbers fit in the SQLITE_MULTIPLEX_EXT_FMT
   101         -** format specifier. It may be changed by calling
   102         -** the xFileControl() interface.
           99  +/* This used to be the default limit on number of chunks, but
          100  +** it is no longer enforced.  There is currently no limit to the
          101  +** number of chunks.
          102  +**
          103  +** May be changed by calling the xFileControl() interface.
   103    104   */
   104    105   #ifndef SQLITE_MULTIPLEX_MAX_CHUNKS
   105         -# define SQLITE_MULTIPLEX_MAX_CHUNKS 32
          106  +# define SQLITE_MULTIPLEX_MAX_CHUNKS 12
   106    107   #endif
   107    108   
   108         -/* If SQLITE_MULTIPLEX_EXT_OVWR is defined, the 
   109         -** last SQLITE_MULTIPLEX_EXT_SZ characters of the 
   110         -** filename will be overwritten, otherwise, the 
   111         -** multiplex extension is simply appended to the filename.
   112         -** Ex.  (undefined) test.db -> test.db01
   113         -**      (defined)   test.db -> test.01
   114         -** Chunk 0 does not have a modified extension.
   115         -*/
   116         -#define SQLITE_MULTIPLEX_EXT_FMT    "%02d"
   117         -#define SQLITE_MULTIPLEX_EXT_SZ     2
   118         -
   119    109   /************************ Object Definitions ******************************/
   120    110   
   121    111   /* Forward declaration of all object types */
   122    112   typedef struct multiplexGroup multiplexGroup;
   123    113   typedef struct multiplexConn multiplexConn;
   124    114   
   125    115   /*
................................................................................
   300    290       memset(&p[pGroup->nReal], 0, sizeof(p[0])*(iChunk+1-pGroup->nReal));
   301    291       pGroup->aReal = p;
   302    292       pGroup->nReal = iChunk+1;
   303    293     }
   304    294     if( pGroup->aReal[iChunk].z==0 ){
   305    295       char *z;
   306    296       int n = pGroup->nName;
   307         -    pGroup->aReal[iChunk].z = z = sqlite3_malloc( n+3 );
          297  +    pGroup->aReal[iChunk].z = z = sqlite3_malloc( n+4 );
   308    298       if( z==0 ){
   309    299         return SQLITE_NOMEM;
   310    300       }
   311    301       memcpy(z, pGroup->zName, n+1);
   312    302       if( iChunk>0 ){
   313    303   #ifdef SQLITE_ENABLE_8_3_NAMES
   314         -      if( n>3 && z[n-3]=='.' ){
   315         -        n--;
   316         -      }else if( n>4 && z[n-4]=='.' ){
   317         -        n -= 2;
   318         -      }
          304  +      int i;
          305  +      for(i=n-1; i>0 && i>=n-4 && z[i]!='.'; i--){}
          306  +      if( i>=n-4 ) n = i+1;
   319    307   #endif
   320         -      sqlite3_snprintf(3,&z[n],"%02d",iChunk);
          308  +      sqlite3_snprintf(4,&z[n],"%03d",iChunk);
   321    309       }
   322    310     }
   323    311     return SQLITE_OK;
   324    312   }
   325    313   
   326    314   /* Translate an sqlite3_file* that is really a multiplexGroup* into
   327    315   ** the sqlite3_file* for the underlying original VFS.

Changes to src/test_pcache.c.

    96     96   
    97     97   /*
    98     98   ** Private implementation of a page cache.
    99     99   */
   100    100   typedef struct testpcache testpcache;
   101    101   struct testpcache {
   102    102     int szPage;               /* Size of each page.  Multiple of 8. */
          103  +  int szExtra;              /* Size of extra data that accompanies each page */
   103    104     int bPurgeable;           /* True if the page cache is purgeable */
   104    105     int nFree;                /* Number of unused slots in a[] */
   105    106     int nPinned;              /* Number of pinned slots in a[] */
   106    107     unsigned iRand;           /* State of the PRNG */
   107    108     unsigned iMagic;          /* Magic number for sanity checking */
   108    109     struct testpcachePage {
          110  +    sqlite3_pcache_page page;  /* Base class */
   109    111       unsigned key;              /* The key for this page. 0 means unallocated */
   110    112       int isPinned;              /* True if the page is pinned */
   111         -    void *pData;               /* Data for this page */
   112    113     } a[TESTPCACHE_NPAGE];    /* All pages in the cache */
   113    114   };
   114    115   
   115    116   /*
   116    117   ** Get a random number using the PRNG in the given page cache.
   117    118   */
   118    119   static unsigned testpcacheRandom(testpcache *p){
................................................................................
   125    126     return x;
   126    127   }
   127    128   
   128    129   
   129    130   /*
   130    131   ** Allocate a new page cache instance.
   131    132   */
   132         -static sqlite3_pcache *testpcacheCreate(int szPage, int bPurgeable){
          133  +static sqlite3_pcache *testpcacheCreate(
          134  +  int szPage, 
          135  +  int szExtra, 
          136  +  int bPurgeable
          137  +){
   133    138     int nMem;
   134    139     char *x;
   135    140     testpcache *p;
   136    141     int i;
   137    142     assert( testpcacheGlobal.pDummy!=0 );
   138    143     szPage = (szPage+7)&~7;
   139         -  nMem = sizeof(testpcache) + TESTPCACHE_NPAGE*szPage;
          144  +  nMem = sizeof(testpcache) + TESTPCACHE_NPAGE*(szPage+szExtra);
   140    145     p = sqlite3_malloc( nMem );
   141    146     if( p==0 ) return 0;
   142    147     x = (char*)&p[1];
   143    148     p->szPage = szPage;
          149  +  p->szExtra = szExtra;
   144    150     p->nFree = TESTPCACHE_NPAGE;
   145    151     p->nPinned = 0;
   146    152     p->iRand = testpcacheGlobal.prngSeed;
   147    153     p->bPurgeable = bPurgeable;
   148    154     p->iMagic = TESTPCACHE_VALID;
   149         -  for(i=0; i<TESTPCACHE_NPAGE; i++, x += szPage){
          155  +  for(i=0; i<TESTPCACHE_NPAGE; i++, x += (szPage+szExtra)){
   150    156       p->a[i].key = 0;
   151    157       p->a[i].isPinned = 0;
   152         -    p->a[i].pData = (void*)x;
          158  +    p->a[i].page.pBuf = (void*)x;
          159  +    p->a[i].page.pExtra = (void*)&x[szPage];
   153    160     }
   154    161     testpcacheGlobal.nInstance++;
   155    162     return (sqlite3_pcache*)p;
   156    163   }
   157    164   
   158    165   /*
   159    166   ** Set the cache size
   160    167   */
   161    168   static void testpcacheCachesize(sqlite3_pcache *pCache, int newSize){
   162    169     testpcache *p = (testpcache*)pCache;
   163    170     assert( p->iMagic==TESTPCACHE_VALID );
   164         -  assert( newSize>=1 );
   165    171     assert( testpcacheGlobal.pDummy!=0 );
   166    172     assert( testpcacheGlobal.nInstance>0 );
   167    173   }
   168    174   
   169    175   /*
   170    176   ** Return the number of pages in the cache that are being used.
   171    177   ** This includes both pinned and unpinned pages.
................................................................................
   177    183     assert( testpcacheGlobal.nInstance>0 );
   178    184     return TESTPCACHE_NPAGE - p->nFree;
   179    185   }
   180    186   
   181    187   /*
   182    188   ** Fetch a page.
   183    189   */
   184         -static void *testpcacheFetch(
          190  +static sqlite3_pcache_page *testpcacheFetch(
   185    191     sqlite3_pcache *pCache,
   186    192     unsigned key,
   187    193     int createFlag
   188    194   ){
   189    195     testpcache *p = (testpcache*)pCache;
   190    196     int i, j;
   191    197     assert( p->iMagic==TESTPCACHE_VALID );
................................................................................
   196    202     for(i=0; i<TESTPCACHE_NPAGE; i++){
   197    203       if( p->a[i].key==key ){
   198    204         if( !p->a[i].isPinned ){
   199    205           p->nPinned++;
   200    206           assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
   201    207           p->a[i].isPinned = 1;
   202    208         }
   203         -      return p->a[i].pData;
          209  +      return &p->a[i].page;
   204    210       }
   205    211     }
   206    212   
   207    213     /* If createFlag is 0, never allocate a new page */
   208    214     if( createFlag==0 ){
   209    215       return 0;
   210    216     }
................................................................................
   233    239     */
   234    240     if( p->nFree>TESTPCACHE_RESERVE || (createFlag==2 && p->nFree>0) ){
   235    241       j = testpcacheRandom(p) % TESTPCACHE_NPAGE;
   236    242       for(i=0; i<TESTPCACHE_NPAGE; i++, j = (j+1)%TESTPCACHE_NPAGE){
   237    243         if( p->a[j].key==0 ){
   238    244           p->a[j].key = key;
   239    245           p->a[j].isPinned = 1;
   240         -        memset(p->a[j].pData, 0, p->szPage);
          246  +        memset(p->a[j].page.pBuf, 0, p->szPage);
          247  +        memset(p->a[j].page.pExtra, 0, p->szExtra);
   241    248           p->nPinned++;
   242    249           p->nFree--;
   243    250           assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
   244         -        return p->a[j].pData;
          251  +        return &p->a[j].page;
   245    252         }
   246    253       }
   247    254   
   248    255       /* The prior loop always finds a freepage to allocate */
   249    256       assert( 0 );
   250    257     }
   251    258   
................................................................................
   259    266     ** recycle is selected at random from all unpinned pages.
   260    267     */
   261    268     j = testpcacheRandom(p) % TESTPCACHE_NPAGE;
   262    269     for(i=0; i<TESTPCACHE_NPAGE; i++, j = (j+1)%TESTPCACHE_NPAGE){
   263    270       if( p->a[j].key>0 && p->a[j].isPinned==0 ){
   264    271         p->a[j].key = key;
   265    272         p->a[j].isPinned = 1;
   266         -      memset(p->a[j].pData, 0, p->szPage);
          273  +      memset(p->a[j].page.pBuf, 0, p->szPage);
          274  +      memset(p->a[j].page.pExtra, 0, p->szExtra);
   267    275         p->nPinned++;
   268    276         assert( p->nPinned <= TESTPCACHE_NPAGE - p->nFree );
   269         -      return p->a[j].pData;
          277  +      return &p->a[j].page;
   270    278       }
   271    279     }
   272    280   
   273    281     /* The previous loop always finds a page to recycle. */
   274    282     assert(0);
   275    283     return 0;
   276    284   }
   277    285   
   278    286   /*
   279    287   ** Unpin a page.
   280    288   */
   281    289   static void testpcacheUnpin(
   282    290     sqlite3_pcache *pCache,
   283         -  void *pOldPage,
          291  +  sqlite3_pcache_page *pOldPage,
   284    292     int discard
   285    293   ){
   286    294     testpcache *p = (testpcache*)pCache;
   287    295     int i;
   288    296     assert( p->iMagic==TESTPCACHE_VALID );
   289    297     assert( testpcacheGlobal.pDummy!=0 );
   290    298     assert( testpcacheGlobal.nInstance>0 );
................................................................................
   296    304     if( p->bPurgeable
   297    305     && (100-testpcacheGlobal.discardChance) <= (testpcacheRandom(p)%100)
   298    306     ){
   299    307       discard = 1;
   300    308     }
   301    309   
   302    310     for(i=0; i<TESTPCACHE_NPAGE; i++){
   303         -    if( p->a[i].pData==pOldPage ){
          311  +    if( &p->a[i].page==pOldPage ){
   304    312         /* The pOldPage pointer always points to a pinned page */
   305    313         assert( p->a[i].isPinned );
   306    314         p->a[i].isPinned = 0;
   307    315         p->nPinned--;
   308    316         assert( p->nPinned>=0 );
   309    317         if( discard ){
   310    318           p->a[i].key = 0;
................................................................................
   321    329   
   322    330   
   323    331   /*
   324    332   ** Rekey a single page.
   325    333   */
   326    334   static void testpcacheRekey(
   327    335     sqlite3_pcache *pCache,
   328         -  void *pOldPage,
          336  +  sqlite3_pcache_page *pOldPage,
   329    337     unsigned oldKey,
   330    338     unsigned newKey
   331    339   ){
   332    340     testpcache *p = (testpcache*)pCache;
   333    341     int i;
   334    342     assert( p->iMagic==TESTPCACHE_VALID );
   335    343     assert( testpcacheGlobal.pDummy!=0 );
................................................................................
   350    358     }
   351    359   
   352    360     /* Find the page to be rekeyed and rekey it.
   353    361     */
   354    362     for(i=0; i<TESTPCACHE_NPAGE; i++){
   355    363       if( p->a[i].key==oldKey ){
   356    364         /* The oldKey and pOldPage parameters match */
   357         -      assert( p->a[i].pData==pOldPage );
          365  +      assert( &p->a[i].page==pOldPage );
   358    366         /* Page to be rekeyed must be pinned */
   359    367         assert( p->a[i].isPinned );
   360    368         p->a[i].key = newKey;
   361    369         return;
   362    370       }
   363    371     }
   364    372   
................................................................................
   418    426   */
   419    427   void installTestPCache(
   420    428     int installFlag,            /* True to install.  False to uninstall. */
   421    429     unsigned discardChance,     /* 0-100.  Chance to discard on unpin */
   422    430     unsigned prngSeed,          /* Seed for the PRNG */
   423    431     unsigned highStress         /* Call xStress agressively */
   424    432   ){
   425         -  static const sqlite3_pcache_methods testPcache = {
          433  +  static const sqlite3_pcache_methods2 testPcache = {
          434  +    1,
   426    435       (void*)&testpcacheGlobal,
   427    436       testpcacheInit,
   428    437       testpcacheShutdown,
   429    438       testpcacheCreate,
   430    439       testpcacheCachesize,
   431    440       testpcachePagecount,
   432    441       testpcacheFetch,
   433    442       testpcacheUnpin,
   434    443       testpcacheRekey,
   435    444       testpcacheTruncate,
   436    445       testpcacheDestroy,
   437    446     };
   438         -  static sqlite3_pcache_methods defaultPcache;
          447  +  static sqlite3_pcache_methods2 defaultPcache;
   439    448     static int isInstalled = 0;
   440    449   
   441    450     assert( testpcacheGlobal.nInstance==0 );
   442    451     assert( testpcacheGlobal.pDummy==0 );
   443    452     assert( discardChance<=100 );
   444    453     testpcacheGlobal.discardChance = discardChance;
   445    454     testpcacheGlobal.prngSeed = prngSeed ^ (prngSeed<<16);
   446    455     testpcacheGlobal.highStress = highStress;
   447    456     if( installFlag!=isInstalled ){
   448    457       if( installFlag ){
   449         -      sqlite3_config(SQLITE_CONFIG_GETPCACHE, &defaultPcache);
          458  +      sqlite3_config(SQLITE_CONFIG_GETPCACHE2, &defaultPcache);
   450    459         assert( defaultPcache.xCreate!=testpcacheCreate );
   451         -      sqlite3_config(SQLITE_CONFIG_PCACHE, &testPcache);
          460  +      sqlite3_config(SQLITE_CONFIG_PCACHE2, &testPcache);
   452    461       }else{
   453    462         assert( defaultPcache.xCreate!=0 );
   454         -      sqlite3_config(SQLITE_CONFIG_PCACHE, &defaultPcache);
          463  +      sqlite3_config(SQLITE_CONFIG_PCACHE2, &defaultPcache);
   455    464       }
   456    465       isInstalled = installFlag;
   457    466     }
   458    467   }

Changes to src/test_vfs.c.

   984    984       return TCL_ERROR;
   985    985     }
   986    986     Tcl_ResetResult(interp);
   987    987   
   988    988     switch( aSubcmd[i].eCmd ){
   989    989       case CMD_SHM: {
   990    990         Tcl_Obj *pObj;
   991         -      int i;
          991  +      int i, rc;
   992    992         TestvfsBuffer *pBuffer;
   993    993         char *zName;
   994    994         if( objc!=3 && objc!=4 ){
   995    995           Tcl_WrongNumArgs(interp, 2, objv, "FILE ?VALUE?");
   996    996           return TCL_ERROR;
   997    997         }
   998    998         zName = ckalloc(p->pParent->mxPathname);
   999         -      p->pParent->xFullPathname(
          999  +      rc = p->pParent->xFullPathname(
  1000   1000             p->pParent, Tcl_GetString(objv[2]), 
  1001   1001             p->pParent->mxPathname, zName
  1002   1002         );
         1003  +      if( rc!=SQLITE_OK ){
         1004  +        Tcl_AppendResult(interp, "failed to get full path: ",
         1005  +                         Tcl_GetString(objv[2]), 0);
         1006  +        ckfree(zName);
         1007  +        return TCL_ERROR;
         1008  +      }
  1003   1009         for(pBuffer=p->pBuffer; pBuffer; pBuffer=pBuffer->pNext){
  1004   1010           if( 0==strcmp(pBuffer->zFile, zName) ) break;
  1005   1011         }
  1006   1012         ckfree(zName);
  1007   1013         if( !pBuffer ){
  1008   1014           Tcl_AppendResult(interp, "no such file: ", Tcl_GetString(objv[2]), 0);
  1009   1015           return TCL_ERROR;

Changes to src/util.c.

  1176   1176     zOk = sqlite3_uri_parameter(zBaseFilename, "8_3_names");
  1177   1177     if( zOk && sqlite3GetBoolean(zOk) )
  1178   1178   #endif
  1179   1179     {
  1180   1180       int i, sz;
  1181   1181       sz = sqlite3Strlen30(z);
  1182   1182       for(i=sz-1; i>0 && z[i]!='/' && z[i]!='.'; i--){}
  1183         -    if( z[i]=='.' && ALWAYS(sz>i+4) ) memcpy(&z[i+1], &z[sz-3], 4);
         1183  +    if( z[i]=='.' && ALWAYS(sz>i+4) ) memmove(&z[i+1], &z[sz-3], 4);
  1184   1184     }
  1185   1185   }
  1186   1186   #endif

Changes to src/vdbe.c.

  4612   4612     if( ALWAYS(pC->pCursor!=0) ){
  4613   4613       assert( pC->deferredMoveto==0 );
  4614   4614       assert( pOp->p5==0 || pOp->p5==1 );
  4615   4615       assert( pOp->p4type==P4_INT32 );
  4616   4616       r.pKeyInfo = pC->pKeyInfo;
  4617   4617       r.nField = (u16)pOp->p4.i;
  4618   4618       if( pOp->p5 ){
  4619         -      r.flags = UNPACKED_INCRKEY | UNPACKED_IGNORE_ROWID;
         4619  +      r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
  4620   4620       }else{
  4621         -      r.flags = UNPACKED_IGNORE_ROWID;
         4621  +      r.flags = UNPACKED_PREFIX_MATCH;
  4622   4622       }
  4623   4623       r.aMem = &aMem[pOp->p3];
  4624   4624   #ifdef SQLITE_DEBUG
  4625   4625       { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
  4626   4626   #endif
  4627   4627       rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
  4628   4628       if( pOp->opcode==OP_IdxLT ){

Changes to src/vdbeapi.c.

  1316   1316   /*
  1317   1317   ** Return true if the prepared statement is guaranteed to not modify the
  1318   1318   ** database.
  1319   1319   */
  1320   1320   int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
  1321   1321     return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
  1322   1322   }
         1323  +
         1324  +/*
         1325  +** Return true if the prepared statement is in need of being reset.
         1326  +*/
         1327  +int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
         1328  +  Vdbe *v = (Vdbe*)pStmt;
         1329  +  return v!=0 && v->pc>0 && v->magic==VDBE_MAGIC_RUN;
         1330  +}
  1323   1331   
  1324   1332   /*
  1325   1333   ** Return a pointer to the next prepared statement after pStmt associated
  1326   1334   ** with database connection pDb.  If pStmt is NULL, return the first
  1327   1335   ** prepared statement for the database connection.  Return NULL if there
  1328   1336   ** are no more.
  1329   1337   */

Changes to src/vdbeaux.c.

  2941   2941   ** Key1 and Key2 do not have to contain the same number of fields.
  2942   2942   ** The key with fewer fields is usually compares less than the 
  2943   2943   ** longer key.  However if the UNPACKED_INCRKEY flags in pPKey2 is set
  2944   2944   ** and the common prefixes are equal, then key1 is less than key2.
  2945   2945   ** Or if the UNPACKED_MATCH_PREFIX flag is set and the prefixes are
  2946   2946   ** equal, then the keys are considered to be equal and
  2947   2947   ** the parts beyond the common prefix are ignored.
  2948         -**
  2949         -** If the UNPACKED_IGNORE_ROWID flag is set, then the last byte of
  2950         -** the header of pKey1 is ignored.  It is assumed that pKey1 is
  2951         -** an index key, and thus ends with a rowid value.  The last byte
  2952         -** of the header will therefore be the serial type of the rowid:
  2953         -** one of 1, 2, 3, 4, 5, 6, 8, or 9 - the integer serial types.
  2954         -** The serial type of the final rowid will always be a single byte.
  2955         -** By ignoring this last byte of the header, we force the comparison
  2956         -** to ignore the rowid at the end of key1.
  2957   2948   */
  2958   2949   int sqlite3VdbeRecordCompare(
  2959   2950     int nKey1, const void *pKey1, /* Left key */
  2960   2951     UnpackedRecord *pPKey2        /* Right key */
  2961   2952   ){
  2962   2953     int d1;            /* Offset into aKey[] of next data element */
  2963   2954     u32 idx1;          /* Offset into aKey[] of next header element */
................................................................................
  2982   2973     ** impact, since this routine is a very high runner.  And so, we choose
  2983   2974     ** to ignore the compiler warnings and leave this variable uninitialized.
  2984   2975     */
  2985   2976     /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
  2986   2977     
  2987   2978     idx1 = getVarint32(aKey1, szHdr1);
  2988   2979     d1 = szHdr1;
  2989         -  if( pPKey2->flags & UNPACKED_IGNORE_ROWID ){
  2990         -    szHdr1--;
  2991         -  }
  2992   2980     nField = pKeyInfo->nField;
  2993   2981     while( idx1<szHdr1 && i<pPKey2->nField ){
  2994   2982       u32 serial_type1;
  2995   2983   
  2996   2984       /* Read the serial types for the next element in each key. */
  2997   2985       idx1 += getVarint32( aKey1+idx1, serial_type1 );
  2998   2986       if( d1>=nKey1 && sqlite3VdbeSerialTypeLen(serial_type1)>0 ) break;
................................................................................
  3164   3152       return SQLITE_CORRUPT_BKPT;
  3165   3153     }
  3166   3154     memset(&m, 0, sizeof(m));
  3167   3155     rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m);
  3168   3156     if( rc ){
  3169   3157       return rc;
  3170   3158     }
  3171         -  assert( pUnpacked->flags & UNPACKED_IGNORE_ROWID );
         3159  +  assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
  3172   3160     *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
  3173   3161     sqlite3VdbeMemRelease(&m);
  3174   3162     return SQLITE_OK;
  3175   3163   }
  3176   3164   
  3177   3165   /*
  3178   3166   ** This routine sets the value to be returned by subsequent calls to

Changes to src/wal.c.

  1781   1781       }
  1782   1782     }
  1783   1783   
  1784   1784    walcheckpoint_out:
  1785   1785     walIteratorFree(pIter);
  1786   1786     return rc;
  1787   1787   }
         1788  +
         1789  +/*
         1790  +** Attempt to limit the WAL size to the size limit defined by
         1791  +** PRAGMA journal_size_limit.
         1792  +*/
         1793  +static void walLimitSize(Wal *pWal){
         1794  +  if( pWal->mxWalSize>=0 ){
         1795  +    i64 sz;
         1796  +    int rx;
         1797  +    sqlite3BeginBenignMalloc();
         1798  +    rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
         1799  +    if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
         1800  +      rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
         1801  +    }
         1802  +    sqlite3EndBenignMalloc();
         1803  +    if( rx ){
         1804  +      sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
         1805  +    }
         1806  +  }
         1807  +}
  1788   1808   
  1789   1809   /*
  1790   1810   ** Close a connection to a log file.
  1791   1811   */
  1792   1812   int sqlite3WalClose(
  1793   1813     Wal *pWal,                      /* Wal to close */
  1794   1814     int sync_flags,                 /* Flags to pass to OsSync() (or 0) */
................................................................................
  1815   1835         }
  1816   1836         rc = sqlite3WalCheckpoint(
  1817   1837             pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
  1818   1838         );
  1819   1839         sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersistWal);
  1820   1840         if( rc==SQLITE_OK && bPersistWal!=1 ){
  1821   1841           isDelete = 1;
         1842  +      }else{
         1843  +        walLimitSize(pWal);
  1822   1844         }
  1823   1845       }
  1824   1846   
  1825   1847       walIndexClose(pWal, isDelete);
  1826   1848       sqlite3OsClose(pWal->pWalFd);
  1827   1849       if( isDelete ){
  1828   1850         sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
................................................................................
  2314   2336       if( rc!=SQLITE_OK ){
  2315   2337         return rc;
  2316   2338       }
  2317   2339       nCollide = HASHTABLE_NSLOT;
  2318   2340       for(iKey=walHash(pgno); aHash[iKey]; iKey=walNextHash(iKey)){
  2319   2341         u32 iFrame = aHash[iKey] + iZero;
  2320   2342         if( iFrame<=iLast && aPgno[aHash[iKey]]==pgno ){
  2321         -        assert( iFrame>iRead );
         2343  +        /* assert( iFrame>iRead ); -- not true if there is corruption */
  2322   2344           iRead = iFrame;
  2323   2345         }
  2324   2346         if( (nCollide--)==0 ){
  2325   2347           return SQLITE_CORRUPT_BKPT;
  2326   2348         }
  2327   2349       }
  2328   2350     }
................................................................................
  2521   2543       pWal->hdr.aFrameCksum[0] = aWalData[1];
  2522   2544       pWal->hdr.aFrameCksum[1] = aWalData[2];
  2523   2545       walCleanupHash(pWal);
  2524   2546     }
  2525   2547   
  2526   2548     return rc;
  2527   2549   }
         2550  +
  2528   2551   
  2529   2552   /*
  2530   2553   ** This function is called just before writing a set of frames to the log
  2531   2554   ** file (see sqlite3WalFrames()). It checks to see if, instead of appending
  2532   2555   ** to the current log file, it is possible to overwrite the start of the
  2533   2556   ** existing log file with the new frames (i.e. "reset" the log). If so,
  2534   2557   ** it sets pWal->hdr.mxFrame to 0. Otherwise, pWal->hdr.mxFrame is left
................................................................................
  2559   2582           ** at this point. But updating the actual wal-index header is also
  2560   2583           ** safe and means there is no special case for sqlite3WalUndo()
  2561   2584           ** to handle if this transaction is rolled back.
  2562   2585           */
  2563   2586           int i;                    /* Loop counter */
  2564   2587           u32 *aSalt = pWal->hdr.aSalt;       /* Big-endian salt values */
  2565   2588   
  2566         -        /* Limit the size of WAL file if the journal_size_limit PRAGMA is
  2567         -        ** set to a non-negative value.  Log errors encountered
  2568         -        ** during the truncation attempt. */
  2569         -        if( pWal->mxWalSize>=0 ){
  2570         -          i64 sz;
  2571         -          int rx;
  2572         -          sqlite3BeginBenignMalloc();
  2573         -          rx = sqlite3OsFileSize(pWal->pWalFd, &sz);
  2574         -          if( rx==SQLITE_OK && (sz > pWal->mxWalSize) ){
  2575         -            rx = sqlite3OsTruncate(pWal->pWalFd, pWal->mxWalSize);
  2576         -          }
  2577         -          sqlite3EndBenignMalloc();
  2578         -          if( rx ){
  2579         -            sqlite3_log(rx, "cannot limit WAL size: %s", pWal->zWalName);
  2580         -          }
  2581         -        }
  2582         -
         2589  +        walLimitSize(pWal);
  2583   2590           pWal->nCkpt++;
  2584   2591           pWal->hdr.mxFrame = 0;
  2585   2592           sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
  2586   2593           aSalt[1] = salt1;
  2587   2594           walIndexWriteHdr(pWal);
  2588   2595           pInfo->nBackfill = 0;
  2589   2596           for(i=1; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;

Changes to src/where.c.

   600    600     for(; pWC; pWC=pWC->pOuter){
   601    601       for(pTerm=pWC->a, k=pWC->nTerm; k; k--, pTerm++){
   602    602         if( pTerm->leftCursor==iCur
   603    603            && (pTerm->prereqRight & notReady)==0
   604    604            && pTerm->u.leftColumn==iColumn
   605    605            && (pTerm->eOperator & op)!=0
   606    606         ){
   607         -        if( pIdx && pTerm->eOperator!=WO_ISNULL ){
          607  +        if( iColumn>=0 && pIdx && pTerm->eOperator!=WO_ISNULL ){
   608    608             Expr *pX = pTerm->pExpr;
   609    609             CollSeq *pColl;
   610    610             char idxaff;
   611    611             int j;
   612    612             Parse *pParse = pWC->pParse;
   613    613     
   614    614             idxaff = pIdx->pTable->aCol[iColumn].affinity;
................................................................................
  3048   3048           wsFlags |= WHERE_COLUMN_NULL;
  3049   3049         }
  3050   3050   #ifdef SQLITE_ENABLE_STAT3
  3051   3051         if( nEq==0 && pProbe->aSample ) pFirstTerm = pTerm;
  3052   3052   #endif
  3053   3053         used |= pTerm->prereqRight;
  3054   3054       }
  3055         -
  3056         -    /* Determine the value of rangeDiv */
  3057         -    if( nEq<pProbe->nColumn && pProbe->bUnordered==0 ){
  3058         -      int j = pProbe->aiColumn[nEq];
         3055  + 
         3056  +    /* If the index being considered is UNIQUE, and there is an equality 
         3057  +    ** constraint for all columns in the index, then this search will find
         3058  +    ** at most a single row. In this case set the WHERE_UNIQUE flag to 
         3059  +    ** indicate this to the caller.
         3060  +    **
         3061  +    ** Otherwise, if the search may find more than one row, test to see if
         3062  +    ** there is a range constraint on indexed column (nEq+1) that can be 
         3063  +    ** optimized using the index. 
         3064  +    */
         3065  +    if( nEq==pProbe->nColumn && pProbe->onError!=OE_None ){
         3066  +      testcase( wsFlags & WHERE_COLUMN_IN );
         3067  +      testcase( wsFlags & WHERE_COLUMN_NULL );
         3068  +      if( (wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_NULL))==0 ){
         3069  +        wsFlags |= WHERE_UNIQUE;
         3070  +      }
         3071  +    }else if( pProbe->bUnordered==0 ){
         3072  +      int j = (nEq==pProbe->nColumn ? -1 : pProbe->aiColumn[nEq]);
  3059   3073         if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pIdx) ){
  3060   3074           WhereTerm *pTop = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pIdx);
  3061   3075           WhereTerm *pBtm = findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pIdx);
  3062   3076           whereRangeScanEst(pParse, pProbe, nEq, pBtm, pTop, &rangeDiv);
  3063   3077           if( pTop ){
  3064   3078             nBound = 1;
  3065   3079             wsFlags |= WHERE_TOP_LIMIT;
................................................................................
  3070   3084             nBound++;
  3071   3085             wsFlags |= WHERE_BTM_LIMIT;
  3072   3086             used |= pBtm->prereqRight;
  3073   3087             testcase( pBtm->pWC!=pWC );
  3074   3088           }
  3075   3089           wsFlags |= (WHERE_COLUMN_RANGE|WHERE_ROWID_RANGE);
  3076   3090         }
  3077         -    }else if( pProbe->onError!=OE_None ){
  3078         -      testcase( wsFlags & WHERE_COLUMN_IN );
  3079         -      testcase( wsFlags & WHERE_COLUMN_NULL );
  3080         -      if( (wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_NULL))==0 ){
  3081         -        wsFlags |= WHERE_UNIQUE;
  3082         -      }
  3083   3091       }
  3084   3092   
  3085   3093       /* If there is an ORDER BY clause and the index being considered will
  3086   3094       ** naturally scan rows in the required order, set the appropriate flags
  3087   3095       ** in wsFlags. Otherwise, if there is an ORDER BY clause but the index
  3088   3096       ** will scan rows in a different order, set the bSort variable.  */
  3089   3097       if( isSortingIndex(
................................................................................
  3686   3694     sqlite3StrAccumAppend(&txt, " (", 2);
  3687   3695     for(i=0; i<nEq; i++){
  3688   3696       explainAppendTerm(&txt, i, aCol[aiColumn[i]].zName, "=");
  3689   3697     }
  3690   3698   
  3691   3699     j = i;
  3692   3700     if( pPlan->wsFlags&WHERE_BTM_LIMIT ){
  3693         -    explainAppendTerm(&txt, i++, aCol[aiColumn[j]].zName, ">");
         3701  +    char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
         3702  +    explainAppendTerm(&txt, i++, z, ">");
  3694   3703     }
  3695   3704     if( pPlan->wsFlags&WHERE_TOP_LIMIT ){
  3696         -    explainAppendTerm(&txt, i, aCol[aiColumn[j]].zName, "<");
         3705  +    char *z = (j==pIndex->nColumn ) ? "rowid" : aCol[aiColumn[j]].zName;
         3706  +    explainAppendTerm(&txt, i, z, "<");
  3697   3707     }
  3698   3708     sqlite3StrAccumAppend(&txt, ")", 1);
  3699   3709     return sqlite3StrAccumFinish(&txt);
  3700   3710   }
  3701   3711   
  3702   3712   /*
  3703   3713   ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
................................................................................
  4047   4057       int nExtraReg = 0;           /* Number of extra registers needed */
  4048   4058       int op;                      /* Instruction opcode */
  4049   4059       char *zStartAff;             /* Affinity for start of range constraint */
  4050   4060       char *zEndAff;               /* Affinity for end of range constraint */
  4051   4061   
  4052   4062       pIdx = pLevel->plan.u.pIdx;
  4053   4063       iIdxCur = pLevel->iIdxCur;
  4054         -    k = pIdx->aiColumn[nEq];     /* Column for inequality constraints */
         4064  +    k = (nEq==pIdx->nColumn ? -1 : pIdx->aiColumn[nEq]);
  4055   4065   
  4056   4066       /* If this loop satisfies a sort order (pOrderBy) request that 
  4057   4067       ** was passed to this function to implement a "SELECT min(x) ..." 
  4058   4068       ** query, then the caller will only allow the loop to run for
  4059   4069       ** a single iteration. This means that the first row returned
  4060   4070       ** should not have a NULL value stored in 'x'. If column 'x' is
  4061   4071       ** the first one after the nEq equality constraints in the index,
................................................................................
  4093   4103       zEndAff = sqlite3DbStrDup(pParse->db, zStartAff);
  4094   4104       addrNxt = pLevel->addrNxt;
  4095   4105   
  4096   4106       /* If we are doing a reverse order scan on an ascending index, or
  4097   4107       ** a forward order scan on a descending index, interchange the 
  4098   4108       ** start and end terms (pRangeStart and pRangeEnd).
  4099   4109       */
  4100         -    if( nEq<pIdx->nColumn && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC) ){
         4110  +    if( (nEq<pIdx->nColumn && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
         4111  +     || (bRev && pIdx->nColumn==nEq)
         4112  +    ){
  4101   4113         SWAP(WhereTerm *, pRangeEnd, pRangeStart);
  4102   4114       }
  4103   4115   
  4104   4116       testcase( pRangeStart && pRangeStart->eOperator & WO_LE );
  4105   4117       testcase( pRangeStart && pRangeStart->eOperator & WO_GE );
  4106   4118       testcase( pRangeEnd && pRangeEnd->eOperator & WO_LE );
  4107   4119       testcase( pRangeEnd && pRangeEnd->eOperator & WO_GE );

Changes to test/attach.test.

    47     47   } {1 x 2 y}
    48     48   do_test attach-1.3 {
    49     49     execsql {
    50     50       ATTACH DATABASE 'test2.db' AS two;
    51     51       SELECT * FROM two.t2;
    52     52     }
    53     53   } {1 x 2 y}
           54  +
           55  +# Tests for the sqlite3_db_filename interface
           56  +#
           57  +do_test attach-1.3.1 {
           58  +  file tail [sqlite3_db_filename db main]
           59  +} {test.db}
           60  +do_test attach-1.3.2 {
           61  +  file tail [sqlite3_db_filename db MAIN]
           62  +} {test.db}
           63  +do_test attach-1.3.3 {
           64  +  file tail [sqlite3_db_filename db temp]
           65  +} {}
           66  +do_test attach-1.3.4 {
           67  +  file tail [sqlite3_db_filename db two]
           68  +} {test2.db}
           69  +do_test attach-1.3.5 {
           70  +  file tail [sqlite3_db_filename db three]
           71  +} {}
           72  +
    54     73   do_test attach-1.4 {
    55     74     execsql {
    56     75       SELECT * FROM t2;
    57     76     }
    58     77   } {1 x 2 y}
    59     78   do_test attach-1.5 {
    60     79     execsql {

Changes to test/capi3d.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  
    12     12   #
    13     13   # This file is devoted to testing the sqlite3_next_stmt and
    14         -# sqlite3_stmt_readonly interfaces.
           14  +# sqlite3_stmt_readonly and sqlite3_stmt_busy interfaces.
    15     15   #
    16     16   # $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
................................................................................
   108    108   test_is_readonly capi3d-2.3 {INSERT INTO t1 VALUES(5)} 0
   109    109   test_is_readonly capi3d-2.4 {UPDATE t1 SET x=x+1 WHERE x<0} 0
   110    110   test_is_readonly capi3d-2.5 {SELECT * FROM t1} 1
   111    111   do_test capi3-2.99 {
   112    112     sqlite3_stmt_readonly 0
   113    113   } 1
   114    114   
          115  +# Tests for sqlite3_stmt_busy
          116  +#
          117  +do_test capi3d-3.1 {
          118  +  db eval {INSERT INTO t1 VALUES(6); INSERT INTO t1 VALUES(7);}
          119  +  set STMT [sqlite3_prepare db {SELECT * FROM t1} -1 TAIL]
          120  +  sqlite3_stmt_busy $STMT
          121  +} {0}
          122  +do_test capi3d-3.2 {
          123  +  sqlite3_step $STMT
          124  +  sqlite3_stmt_busy $STMT
          125  +} {1}
          126  +do_test capi3d-3.3 {
          127  +  sqlite3_step $STMT
          128  +  sqlite3_stmt_busy $STMT
          129  +} {1}
          130  +do_test capi3d-3.4 {
          131  +  sqlite3_reset $STMT
          132  +  sqlite3_stmt_busy $STMT
          133  +} {0}
          134  +
          135  +do_test capi3d-3.99 {
          136  +  sqlite3_finalize $STMT
          137  +  sqlite3_stmt_busy 0
          138  +} {0}
   115    139   
   116    140   finish_test

Changes to test/dbstatus.test.

    57     57   }
    58     58   
    59     59   ifcapable stat3 {
    60     60     set STAT3 1
    61     61   } else {
    62     62     set STAT3 0
    63     63   }
           64  +
           65  +ifcapable malloc_usable_size {
           66  +  finish_test
           67  +  return
           68  +}
    64     69   
    65     70   #---------------------------------------------------------------------------
    66     71   # Run the dbstatus-2 and dbstatus-3 tests with several of different
    67     72   # lookaside buffer sizes.
    68     73   #
    69     74   foreach ::lookaside_buffer_size {0 64 120} {
    70     75   

Changes to test/insert4.test.

   381    381         SELECT * FROM t7b;
   382    382       }
   383    383     } {123}
   384    384     do_test insert4-7.8 {
   385    385       set ::sqlite3_xferopt_count
   386    386     } {1}
   387    387   }
          388  +
          389  +# Ticket [676bc02b87176125635cb174d110b431581912bb]
          390  +# Make sure INTEGER PRIMARY KEY ON CONFLICT ... works with the xfer
          391  +# optimization.
          392  +#
          393  +do_test insert4-8.1 {
          394  +  execsql {
          395  +    DROP TABLE IF EXISTS t1;
          396  +    DROP TABLE IF EXISTS t2;
          397  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
          398  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT REPLACE, y);
          399  +    INSERT INTO t1 VALUES(1,2);
          400  +    INSERT INTO t2 VALUES(1,3);
          401  +    INSERT INTO t1 SELECT * FROM t2;
          402  +    SELECT * FROM t1;
          403  +  }
          404  +} {1 3}
          405  +do_test insert4-8.2 {
          406  +  execsql {
          407  +    DROP TABLE IF EXISTS t1;
          408  +    DROP TABLE IF EXISTS t2;
          409  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
          410  +    CREATE TABLE t2(x, y);
          411  +    INSERT INTO t1 VALUES(1,2);
          412  +    INSERT INTO t2 VALUES(1,3);
          413  +    INSERT INTO t1 SELECT * FROM t2;
          414  +    SELECT * FROM t1;
          415  +  }
          416  +} {1 3}
          417  +do_test insert4-8.3 {
          418  +  execsql {
          419  +    DROP TABLE IF EXISTS t1;
          420  +    DROP TABLE IF EXISTS t2;
          421  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
          422  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT IGNORE, y);
          423  +    INSERT INTO t1 VALUES(1,2);
          424  +    INSERT INTO t2 VALUES(1,3);
          425  +    INSERT INTO t1 SELECT * FROM t2;
          426  +    SELECT * FROM t1;
          427  +  }
          428  +} {1 2}
          429  +do_test insert4-8.4 {
          430  +  execsql {
          431  +    DROP TABLE IF EXISTS t1;
          432  +    DROP TABLE IF EXISTS t2;
          433  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
          434  +    CREATE TABLE t2(x, y);
          435  +    INSERT INTO t1 VALUES(1,2);
          436  +    INSERT INTO t2 VALUES(1,3);
          437  +    INSERT INTO t1 SELECT * FROM t2;
          438  +    SELECT * FROM t1;
          439  +  }
          440  +} {1 2}
          441  +do_test insert4-8.5 {
          442  +  execsql {
          443  +    DROP TABLE IF EXISTS t1;
          444  +    DROP TABLE IF EXISTS t2;
          445  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT FAIL, b);
          446  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT FAIL, y);
          447  +    INSERT INTO t1 VALUES(1,2);
          448  +    INSERT INTO t2 VALUES(-99,100);
          449  +    INSERT INTO t2 VALUES(1,3);
          450  +    SELECT * FROM t1;
          451  +  }
          452  +  catchsql {
          453  +    INSERT INTO t1 SELECT * FROM t2;
          454  +  }
          455  +} {1 {PRIMARY KEY must be unique}}
          456  +do_test insert4-8.6 {
          457  +  execsql {
          458  +    SELECT * FROM t1;
          459  +  }
          460  +} {-99 100 1 2} 
          461  +do_test insert4-8.7 {
          462  +  execsql {
          463  +    DROP TABLE IF EXISTS t1;
          464  +    DROP TABLE IF EXISTS t2;
          465  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ABORT, b);
          466  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ABORT, y);
          467  +    INSERT INTO t1 VALUES(1,2);
          468  +    INSERT INTO t2 VALUES(-99,100);
          469  +    INSERT INTO t2 VALUES(1,3);
          470  +    SELECT * FROM t1;
          471  +  }
          472  +  catchsql {
          473  +    INSERT INTO t1 SELECT * FROM t2;
          474  +  }
          475  +} {1 {PRIMARY KEY must be unique}}
          476  +do_test insert4-8.8 {
          477  +  execsql {
          478  +    SELECT * FROM t1;
          479  +  }
          480  +} {1 2} 
          481  +do_test insert4-8.9 {
          482  +  execsql {
          483  +    DROP TABLE IF EXISTS t1;
          484  +    DROP TABLE IF EXISTS t2;
          485  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, b);
          486  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, y);
          487  +    INSERT INTO t1 VALUES(1,2);
          488  +    INSERT INTO t2 VALUES(-99,100);
          489  +    INSERT INTO t2 VALUES(1,3);
          490  +    SELECT * FROM t1;
          491  +  }
          492  +  catchsql {
          493  +    BEGIN;
          494  +    INSERT INTO t1 VALUES(2,3);
          495  +    INSERT INTO t1 SELECT * FROM t2;
          496  +  }
          497  +} {1 {PRIMARY KEY must be unique}}
          498  +do_test insert4-8.10 {
          499  +  catchsql {COMMIT}
          500  +} {1 {cannot commit - no transaction is active}}
          501  +do_test insert4-8.11 {
          502  +  execsql {
          503  +    SELECT * FROM t1;
          504  +  }
          505  +} {1 2} 
          506  +
          507  +do_test insert4-8.21 {
          508  +  execsql {
          509  +    DROP TABLE IF EXISTS t1;
          510  +    DROP TABLE IF EXISTS t2;
          511  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
          512  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT REPLACE, y);
          513  +    INSERT INTO t2 VALUES(1,3);
          514  +    INSERT INTO t1 SELECT * FROM t2;
          515  +    SELECT * FROM t1;
          516  +  }
          517  +} {1 3}
          518  +do_test insert4-8.22 {
          519  +  execsql {
          520  +    DROP TABLE IF EXISTS t1;
          521  +    DROP TABLE IF EXISTS t2;
          522  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
          523  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT IGNORE, y);
          524  +    INSERT INTO t2 VALUES(1,3);
          525  +    INSERT INTO t1 SELECT * FROM t2;
          526  +    SELECT * FROM t1;
          527  +  }
          528  +} {1 3}
          529  +do_test insert4-8.23 {
          530  +  execsql {
          531  +    DROP TABLE IF EXISTS t1;
          532  +    DROP TABLE IF EXISTS t2;
          533  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ABORT, b);
          534  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ABORT, y);
          535  +    INSERT INTO t2 VALUES(1,3);
          536  +    INSERT INTO t1 SELECT * FROM t2;
          537  +    SELECT * FROM t1;
          538  +  }
          539  +} {1 3}
          540  +do_test insert4-8.24 {
          541  +  execsql {
          542  +    DROP TABLE IF EXISTS t1;
          543  +    DROP TABLE IF EXISTS t2;
          544  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT FAIL, b);
          545  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT FAIL, y);
          546  +    INSERT INTO t2 VALUES(1,3);
          547  +    INSERT INTO t1 SELECT * FROM t2;
          548  +    SELECT * FROM t1;
          549  +  }
          550  +} {1 3}
          551  +do_test insert4-8.25 {
          552  +  execsql {
          553  +    DROP TABLE IF EXISTS t1;
          554  +    DROP TABLE IF EXISTS t2;
          555  +    CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, b);
          556  +    CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, y);
          557  +    INSERT INTO t2 VALUES(1,3);
          558  +    INSERT INTO t1 SELECT * FROM t2;
          559  +    SELECT * FROM t1;
          560  +  }
          561  +} {1 3}
          562  +
   388    563   
   389    564   finish_test

Changes to test/memsubsys1.test.

    64     64     sqlite3_status SQLITE_STATUS_PAGECACHE_SIZE 1
    65     65     sqlite3_status SQLITE_STATUS_SCRATCH_USED 1
    66     66     sqlite3_status SQLITE_STATUS_SCRATCH_OVERFLOW 1
    67     67     sqlite3_status SQLITE_STATUS_SCRATCH_SIZE 1
    68     68     sqlite3_status SQLITE_STATUS_PARSER_STACK 1
    69     69   }
    70     70   
    71         -set xtra_size 256
           71  +set xtra_size 290
    72     72   
    73     73   # Test 1:  Both PAGECACHE and SCRATCH are shut down.
    74     74   #
    75     75   db close
    76     76   sqlite3_shutdown
    77     77   sqlite3_config_lookaside 0 0
    78     78   sqlite3_initialize
................................................................................
    93     93   sqlite3_shutdown
    94     94   sqlite3_config_pagecache [expr 1024+$xtra_size] 20
    95     95   sqlite3_initialize
    96     96   reset_highwater_marks
    97     97   build_test_db memsubsys1-2 {PRAGMA page_size=1024}
    98     98   #show_memstats
    99     99   set MEMORY_MANAGEMENT $sqlite_options(memorymanage)
   100         -do_test memsubsys1-2.3 {
   101         -  set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
   102         -} [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024]
          100  +ifcapable !malloc_usable_size {
          101  + do_test memsubsys1-2.3 {
          102  +    set pg_ovfl [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_OVERFLOW 0] 2]
          103  +  } [expr ($TEMP_STORE>1 || $MEMORY_MANAGEMENT==0)*1024]
          104  +}
   103    105   do_test memsubsys1-2.4 {
   104    106     set pg_used [lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 2]
   105    107   } 20
   106    108   do_test memsubsys1-2.5 {
   107    109     set s_used [lindex [sqlite3_status SQLITE_STATUS_SCRATCH_USED 0] 2]
   108    110   } 0
   109    111   

Changes to test/multiplex.test.

    26     26   # This handles appending the chunk number
    27     27   # to the end of the filename.  if 
    28     28   # SQLITE_MULTIPLEX_EXT_OVWR is defined, then
    29     29   # it overwrites the last 2 bytes of the 
    30     30   # file name with the chunk number.
    31     31   proc multiplex_name {name chunk} {
    32     32     if {$chunk==0} { return $name }
    33         -  set num [format "%02d" $chunk]
           33  +  set num [format "%03d" $chunk]
    34     34     ifcapable {multiplex_ext_overwrite} {
    35     35       set name [string range $name 0 [expr [string length $name]-2-1]]
    36     36     }
    37     37     return $name$num
    38     38   }
    39     39   
    40     40   # This saves off the parameters and calls the 

Changes to test/pragma.test.

    95     95   do_test pragma-1.5 {
    96     96     execsql {
    97     97       PRAGMA cache_size=-4321;
    98     98       PRAGMA cache_size;
    99     99       PRAGMA default_cache_size;
   100    100       PRAGMA synchronous;
   101    101     }
   102         -} [list 4321 $DFLT_CACHE_SZ 0]
          102  +} [list -4321 $DFLT_CACHE_SZ 0]
   103    103   do_test pragma-1.6 {
   104    104     execsql {
   105    105       PRAGMA synchronous=ON;
   106    106       PRAGMA cache_size;
   107    107       PRAGMA default_cache_size;
   108    108       PRAGMA synchronous;
   109    109     }
   110         -} [list 4321 $DFLT_CACHE_SZ 1]
          110  +} [list -4321 $DFLT_CACHE_SZ 1]
   111    111   do_test pragma-1.7 {
   112    112     db close
   113    113     sqlite3 db test.db
   114    114     execsql {
   115    115       PRAGMA cache_size;
   116    116       PRAGMA default_cache_size;
   117    117       PRAGMA synchronous;

Added test/shrink.test.

            1  +# 2011 November 16
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# This file contains test cases for sqlite3_db_release_memory and
           13  +# the PRAGMA shrink_memory statement.
           14  +#
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +unset -nocomplain baseline
           20  +do_test shrink-1.1 {
           21  +  db eval {
           22  +    CREATE TABLE t1(x,y);
           23  +    INSERT INTO t1 VALUES(randomblob(1000000),1);
           24  +  }
           25  +  set ::baseline sqlite3_memory_used
           26  +  sqlite3_db_release_memory db
           27  +  expr {$::baseline > [sqlite3_memory_used]+500000}
           28  +} {1}
           29  +do_test shrink-1.2 {
           30  +  set baseline [sqlite3_memory_used]
           31  +  db eval {
           32  +    UPDATE t1 SET y=y+1;
           33  +  }
           34  +  expr {$::baseline+500000 < [sqlite3_memory_used]}
           35  +} {1}
           36  +do_test shrink-1.3 {
           37  +  set baseline [sqlite3_memory_used]
           38  +  db eval {PRAGMA shrink_memory}
           39  +  expr {$::baseline > [sqlite3_memory_used]+500000}
           40  +} {1}
           41  +
           42  +finish_test

Changes to test/syscall.test.

    55     55   
    56     56   #-------------------------------------------------------------------------
    57     57   # Tests for the xNextSystemCall method.
    58     58   #
    59     59   foreach s {
    60     60       open close access getcwd stat fstat ftruncate
    61     61       fcntl read pread write pwrite fchmod fallocate
    62         -    pread64 pwrite64 unlink openDirectory
           62  +    pread64 pwrite64 unlink openDirectory mkdir rmdir
    63     63   } {
    64     64     if {[test_syscall exists $s]} {lappend syscall_list $s}
    65     65   }
    66     66   do_test 3.1 { lsort [test_syscall list] } [lsort $syscall_list]
    67     67   
    68     68   #-------------------------------------------------------------------------
    69     69   # This test verifies that if a call to open() fails and errno is set to

Changes to test/tester.tcl.

    53     53   #      do_test                TESTNAME SCRIPT EXPECTED
    54     54   #      do_execsql_test        TESTNAME SQL EXPECTED
    55     55   #      do_catchsql_test       TESTNAME SQL EXPECTED
    56     56   #
    57     57   # Commands providing a lower level interface to the global test counters:
    58     58   #
    59     59   #      set_test_counter       COUNTER ?VALUE?
    60         -#      omit_test              TESTNAME REASON
           60  +#      omit_test              TESTNAME REASON ?APPEND?
    61     61   #      fail_test              TESTNAME
    62     62   #      incr_ntest
    63     63   #
    64     64   # Command run at the end of each test file:
    65     65   #
    66     66   #      finish_test
    67     67   #
................................................................................
   270    270     #   --malloctrace=N
   271    271     #   --backtrace=N
   272    272     #   --binarylog=N
   273    273     #   --soak=N
   274    274     #   --file-retries=N
   275    275     #   --file-retry-delay=N
   276    276     #   --start=[$permutation:]$testfile
          277  +  #   --match=$pattern
   277    278     #
   278    279     set cmdlinearg(soft-heap-limit)    0
   279    280     set cmdlinearg(maxerror)        1000
   280    281     set cmdlinearg(malloctrace)        0
   281    282     set cmdlinearg(backtrace)         10
   282    283     set cmdlinearg(binarylog)          0
   283    284     set cmdlinearg(soak)               0
   284    285     set cmdlinearg(file-retries)       0
   285    286     set cmdlinearg(file-retry-delay)   0
   286         -  set cmdlinearg(start)             "" 
          287  +  set cmdlinearg(start)             ""
          288  +  set cmdlinearg(match)             ""
   287    289   
   288    290     set leftover [list]
   289    291     foreach a $argv {
   290    292       switch -regexp -- $a {
   291    293         {^-+pause$} {
   292    294           # Wait for user input before continuing. This is to give the user an 
   293    295           # opportunity to connect profiling tools to the process.
................................................................................
   332    334           set ::G(start:file) $cmdlinearg(start)
   333    335           if {[regexp {(.*):(.*)} $cmdlinearg(start) -> s.perm s.file]} {
   334    336             set ::G(start:permutation) ${s.perm}
   335    337             set ::G(start:file)        ${s.file}
   336    338           }
   337    339           if {$::G(start:file) == ""} {unset ::G(start:file)}
   338    340         }
          341  +      {^-+match=.+$} {
          342  +        foreach {dummy cmdlinearg(match)} [split $a =] break
          343  +
          344  +        set ::G(match) $cmdlinearg(match)
          345  +        if {$::G(match) == ""} {unset ::G(match)}
          346  +      }
   339    347         default {
   340    348           lappend leftover $a
   341    349         }
   342    350       }
   343    351     }
   344    352     set argv $leftover
   345    353   
................................................................................
   435    443       }
   436    444       set ::TC($counter)
   437    445     }
   438    446   }
   439    447   
   440    448   # Record the fact that a sequence of tests were omitted.
   441    449   #
   442         -proc omit_test {name reason} {
          450  +proc omit_test {name reason {append 1}} {
   443    451     set omitList [set_test_counter omit_list]
   444         -  lappend omitList [list $name $reason]
          452  +  if {$append} {
          453  +    lappend omitList [list $name $reason]
          454  +  }
   445    455     set_test_counter omit_list $omitList
   446    456   }
   447    457   
   448    458   # Record the fact that a test failed.
   449    459   #
   450    460   proc fail_test {name} {
   451    461     set f [set_test_counter fail_list]
................................................................................
   492    502     if {[info exists ::G(perm:prefix)]} {
   493    503       set name "$::G(perm:prefix)$name"
   494    504     }
   495    505   
   496    506     incr_ntest
   497    507     puts -nonewline $name...
   498    508     flush stdout
   499         -  if {[catch {uplevel #0 "$cmd;\n"} result]} {
   500         -    puts "\nError: $result"
   501         -    fail_test $name
   502         -  } elseif {[string compare $result $expected]} {
   503         -    puts "\nExpected: \[$expected\]\n     Got: \[$result\]"
   504         -    fail_test $name
          509  +
          510  +  if {![info exists ::G(match)] || [string match $::G(match) $name]} {
          511  +    if {[catch {uplevel #0 "$cmd;\n"} result]} {
          512  +      puts "\nError: $result"
          513  +      fail_test $name
          514  +    } elseif {[string compare $result $expected]} {
          515  +      puts "\nExpected: \[$expected\]\n     Got: \[$result\]"
          516  +      fail_test $name
          517  +    } else {
          518  +      puts " Ok"
          519  +    }
   505    520     } else {
   506         -    puts " Ok"
          521  +    puts " Omitted"
          522  +    omit_test $name "pattern mismatch" 0
   507    523     }
   508    524     flush stdout
   509    525   }
   510    526   
   511    527   proc filepath_normalize {p} {
   512    528     # test cases should be written to assume "unix"-like file paths
   513    529     if {$::tcl_platform(platform)!="unix"} {

Added test/tkt-3a77c9714e.test.

            1  +# 2011 December 06
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.
           12  +#
           13  +# This file implements tests to verify that ticket [3a77c9714e] has been
           14  +# fixed.  
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +set testprefix "tkt-3a77c9714e"
           20  +
           21  +do_execsql_test 1.1 {
           22  +  CREATE TABLE t1(t1_id INTEGER PRIMARY KEY, t1_title TEXT);
           23  +  CREATE TABLE t2(t2_id INTEGER PRIMARY KEY, t2_title TEXT);
           24  +  CREATE TABLE t3(t3_id INTEGER PRIMARY KEY, t3_title TEXT);
           25  +
           26  +  INSERT INTO t1 (t1_id, t1_title) VALUES (888, 'ABCDEF');
           27  +  INSERT INTO t2 (t2_id, t2_title) VALUES (999, 'ABCDEF');
           28  +  INSERT INTO t3 (t3_id, t3_title) VALUES (999, 'ABCDEF');
           29  +}
           30  +
           31  +do_execsql_test 1.2 {
           32  +  SELECT t1_title, t2_title
           33  +  FROM t1 LEFT JOIN t2
           34  +  WHERE
           35  +    t2_id = (SELECT t3_id FROM
           36  +     ( SELECT t3_id FROM t3 WHERE t3_title=t1_title LIMIT 500 )
           37  +  )
           38  +} {ABCDEF ABCDEF}
           39  +
           40  +do_execsql_test 2.1 {
           41  +  CREATE TABLE [Beginnings] (
           42  +    [Id] INTEGER PRIMARY KEY AUTOINCREMENT,[Title] TEXT, [EndingId] INTEGER
           43  +  );
           44  +  CREATE TABLE [Endings] (Id INT,Title TEXT,EndingId INT);
           45  +  INSERT INTO Beginnings (Id, Title, EndingId) VALUES (1, 'FACTOR', 18);
           46  +  INSERT INTO Beginnings (Id, Title, EndingId) VALUES (2, 'SWIMM', 18);
           47  +  INSERT INTO Endings (Id, Title, EndingId) VALUES (1, 'ING', 18);
           48  +}
           49  +
           50  +do_execsql_test 2.2 {
           51  +  SELECT
           52  +    SrcWord, Beginnings.Title
           53  +    FROM 
           54  +      (SELECT 'FACTORING' AS SrcWord UNION SELECT 'SWIMMING' AS SrcWord )
           55  +    LEFT JOIN 
           56  +      Beginnings
           57  +    WHERE Beginnings.Id= (
           58  +      SELECT BeginningId FROM (
           59  +        SELECT SrcWord, B.Id as BeginningId, B.Title || E.Title As Connected
           60  +        FROM Beginnings B LEFT JOIN Endings E ON B.EndingId=E.EndingId
           61  +        WHERE Connected=SrcWord LIMIT 1
           62  +      )
           63  +    )
           64  +} {FACTORING FACTOR SWIMMING SWIMM} 
           65  +
           66  +
           67  +finish_test
           68  +

Changes to test/wal.test.

   416    416   
   417    417   # Run some "warm-body" tests to ensure that log-summary files with more
   418    418   # than 256 entries (log summaries that contain index blocks) work Ok.
   419    419   #
   420    420   do_test wal-9.1 {
   421    421     reopen_db
   422    422     execsql {
          423  +    PRAGMA cache_size=2000;
   423    424       CREATE TABLE t1(x PRIMARY KEY);
   424    425       INSERT INTO t1 VALUES(blob(900));
   425    426       INSERT INTO t1 VALUES(blob(900));
   426    427       INSERT INTO t1 SELECT blob(900) FROM t1;       /*  4 */
   427    428       INSERT INTO t1 SELECT blob(900) FROM t1;       /*  8 */
   428    429       INSERT INTO t1 SELECT blob(900) FROM t1;       /* 16 */
   429    430       INSERT INTO t1 SELECT blob(900) FROM t1;       /* 32 */
................................................................................
  1127   1128     sqlite3_simulate_device -sectorsize $sectorsize
  1128   1129     sqlite3 db test.db -vfs devsym
  1129   1130   
  1130   1131     do_test wal-17.$tn.1 {
  1131   1132       execsql {
  1132   1133         PRAGMA auto_vacuum = 0;
  1133   1134         PRAGMA page_size = 512;
         1135  +      PRAGMA cache_size = -2000;
  1134   1136         PRAGMA journal_mode = WAL;
  1135   1137         SELECT * FROM sqlite_master;
  1136   1138         PRAGMA synchronous = FULL;
  1137   1139       }
  1138   1140       execsql {
  1139   1141         BEGIN;
  1140   1142         CREATE TABLE t(x);

Changes to test/walpersist.test.

    63     63     file_control_persist_wal db 1
    64     64   } {0 1}
    65     65   do_test walpersist-1.11 {
    66     66     db close
    67     67     list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm]
    68     68   } {1 1 1}
    69     69   
    70         -  
    71         -
           70  +# Make sure the journal_size_limit works to limit the size of the
           71  +# persisted wal file.
           72  +forcedelete test.db test.db-shm test.db-wal
           73  +do_test walpersist-2.1 {
           74  +  sqlite3 db test.db
           75  +  db eval {
           76  +    PRAGMA journal_mode=WAL;
           77  +    PRAGMA wal_autocheckpoint=OFF;
           78  +    PRAGMA journal_size_limit=12000;
           79  +    CREATE TABLE t1(x);
           80  +    INSERT INTO t1 VALUES(randomblob(50000));
           81  +    UPDATE t1 SET x=randomblob(50000);
           82  +  }
           83  +  expr {[file size test.db-wal]>100000}
           84  +} {1}
           85  +do_test walpersist-2.2 {
           86  +  file_control_persist_wal db 1
           87  +  db close
           88  +  file size test.db-wal
           89  +} {12000}
    72     90   
    73     91   finish_test

Added test/whereC.test.

            1  +# 2011 November 16
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +
           13  +set testdir [file dirname $argv0]
           14  +source $testdir/tester.tcl
           15  +set testprefix whereC
           16  +
           17  +do_execsql_test 1.0 {
           18  +  CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b INTEGER);
           19  +
           20  +  INSERT INTO t1 VALUES(1, 1, 1);
           21  +  INSERT INTO t1 VALUES(2, 1, 1);
           22  +  INSERT INTO t1 VALUES(3, 1, 2);
           23  +  INSERT INTO t1 VALUES(4, 1, 2);
           24  +  INSERT INTO t1 VALUES(5, 1, 2);
           25  +  INSERT INTO t1 VALUES(6, 1, 3);
           26  +  INSERT INTO t1 VALUES(7, 1, 3);
           27  +
           28  +  INSERT INTO t1 VALUES(8, 2, 1);
           29  +  INSERT INTO t1 VALUES(9, 2, 1);
           30  +  INSERT INTO t1 VALUES(10, 2, 2);
           31  +  INSERT INTO t1 VALUES(11, 2, 2);
           32  +  INSERT INTO t1 VALUES(12, 2, 2);
           33  +  INSERT INTO t1 VALUES(13, 2, 3);
           34  +  INSERT INTO t1 VALUES(14, 2, 3);
           35  +
           36  +  INSERT INTO t1 VALUES(15, 2, 1);
           37  +  INSERT INTO t1 VALUES(16, 2, 1);
           38  +  INSERT INTO t1 VALUES(17, 2, 2);
           39  +  INSERT INTO t1 VALUES(18, 2, 2);
           40  +  INSERT INTO t1 VALUES(19, 2, 2);
           41  +  INSERT INTO t1 VALUES(20, 2, 3);
           42  +  INSERT INTO t1 VALUES(21, 2, 3);
           43  +
           44  +  CREATE INDEX i1 ON t1(a, b);
           45  +}
           46  +
           47  +foreach {tn sql res} {
           48  +  1   "SELECT i FROM t1 WHERE a=1 AND b=2 AND i>3"         {4 5}
           49  +  2   "SELECT i FROM t1 WHERE rowid='12'"                  {12}
           50  +  3   "SELECT i FROM t1 WHERE a=1 AND b='2'"               {3 4 5}
           51  +  4   "SELECT i FROM t1 WHERE a=1 AND b='2' AND i>'3'"     {4 5}
           52  +  5   "SELECT i FROM t1 WHERE a=1 AND b='2' AND i<5"       {3 4}
           53  +  6   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i<12"        {10 11}
           54  +  7   "SELECT i FROM t1 WHERE a IN(1, 2) AND b=2 AND i<11" {3 4 5 10}
           55  +  8   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 10 AND 12" {10 11 12}
           56  +  9   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 11 AND 12" {11 12}
           57  + 10   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 10 AND 11" {10 11}
           58  + 11   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i BETWEEN 12 AND 10" {}
           59  + 12   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i<NULL"      {}
           60  + 13   "SELECT i FROM t1 WHERE a=2 AND b=2 AND i>=NULL"     {}
           61  + 14   "SELECT i FROM t1 WHERE a=1 AND b='2' AND i<4.5"     {3 4}
           62  +} {
           63  +  do_execsql_test 1.$tn.1 $sql $res
           64  +  do_execsql_test 1.$tn.2 "$sql ORDER BY i ASC"  [lsort -integer -inc  $res]
           65  +  do_execsql_test 1.$tn.3 "$sql ORDER BY i DESC" [lsort -integer -dec  $res]
           66  +}
           67  +
           68  +
           69  +finish_test
           70  +