/ Check-in [38df91c2]
Login

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

Overview
Comment:Add the SQLITE_TESTCTRL_ASSERT and SQLITE_TESTCTRL_ALWAYS codes for the sqlite3_test_control() interface. (CVS 6623)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:38df91c2edebee22d02b5f84260ee9e5e14db48e
User & Date: drh 2009-05-09 18:59:42
Context
2009-05-09
23:29
Convert an always-true condition in hash.c into an assert(). (CVS 6624) check-in: 42372999 user: drh tags: trunk
18:59
Add the SQLITE_TESTCTRL_ASSERT and SQLITE_TESTCTRL_ALWAYS codes for the sqlite3_test_control() interface. (CVS 6623) check-in: 38df91c2 user: drh tags: trunk
15:17
Change sqlite_blob_open() so that it zeros the output pBlob pointer when it fails. The other sqlite3_blob interfaces accept a NULL pointer as input. (CVS 6622) check-in: 999d507b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.549 2009/05/07 13:43:49 drh Exp $
           17  +** $Id: main.c,v 1.550 2009/05/09 18:59:42 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   
    21     21   #ifdef SQLITE_ENABLE_FTS3
    22     22   # include "fts3.h"
    23     23   #endif
    24     24   #ifdef SQLITE_ENABLE_RTREE
................................................................................
  2172   2172         xBenignBegin = va_arg(ap, void_function);
  2173   2173         xBenignEnd = va_arg(ap, void_function);
  2174   2174         sqlite3BenignMallocHooks(xBenignBegin, xBenignEnd);
  2175   2175         break;
  2176   2176       }
  2177   2177   
  2178   2178       /*
  2179         -    **  sqlite3_test_control(PENDING_BYTE, unsigned int X)
         2179  +    **  sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, unsigned int X)
  2180   2180       **
  2181   2181       ** Set the PENDING byte to the value in the argument, if X>0.
  2182   2182       ** Make no changes if X==0.  Return the value of the pending byte
  2183   2183       ** as it existing before this routine was called.
  2184   2184       **
  2185   2185       ** IMPORTANT:  Changing the PENDING byte from 0x40000000 results in
  2186   2186       ** an incompatible database file format.  Changing the PENDING byte
................................................................................
  2189   2189       */
  2190   2190       case SQLITE_TESTCTRL_PENDING_BYTE: {
  2191   2191         unsigned int newVal = va_arg(ap, unsigned int);
  2192   2192         rc = sqlite3PendingByte;
  2193   2193         if( newVal ) sqlite3PendingByte = newVal;
  2194   2194         break;
  2195   2195       }
         2196  +
         2197  +    /*
         2198  +    **  sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, int X)
         2199  +    **
         2200  +    ** This action provides a run-time test to see whether or not
         2201  +    ** assert() was enabled at compile-time.  If X is true and assert()
         2202  +    ** is enabled, then the return value is true.  If X is true and
         2203  +    ** assert() is disabled, then the return value is zero.  If X is
         2204  +    ** false and assert() is enabled, then the assertion fires and the
         2205  +    ** process aborts.  If X is false and assert() is disabled, then the
         2206  +    ** return value is zero.
         2207  +    */
         2208  +    case SQLITE_TESTCTRL_ASSERT: {
         2209  +      volatile int x = 0;
         2210  +      assert( (x = va_arg(ap,int))!=0 );
         2211  +      rc = x;
         2212  +      break;
         2213  +    }
         2214  +
         2215  +
         2216  +    /*
         2217  +    **  sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, int X)
         2218  +    **
         2219  +    ** This action provides a run-time test to see how the ALWAYS and
         2220  +    ** NEVER macros were defined at compile-time.
         2221  +    **
         2222  +    ** The return value is ALWAYS(X).  
         2223  +    **
         2224  +    ** The recommended test is X==2.  If the return value is 2, that means
         2225  +    ** ALWAYS() and NEVER() are both no-op pass-through macros, which is the
         2226  +    ** default setting.  If the return value is 1, then ALWAYS() is either
         2227  +    ** hard-coded to true or else it asserts if its argument is false.
         2228  +    ** The first behavior (hard-coded to true) is the case if
         2229  +    ** SQLITE_TESTCTRL_ASSERT shows that assert() is disabled and the second
         2230  +    ** behavior (assert if the argument to ALWAYS() is false) is the case if
         2231  +    ** SQLITE_TESTCTRL_ASSERT shows that assert() is enabled.
         2232  +    **
         2233  +    ** The run-time test procedure might look something like this:
         2234  +    **
         2235  +    **    if( sqlite3_test_control(SQLITE_TESTCTRL_ALWAYS, 2)==2 ){
         2236  +    **      // ALWAYS() and NEVER() are no-op pass-through macros
         2237  +    **    }else if( sqlite3_test_control(SQLITE_TESTCTRL_ASSERT, 1) ){
         2238  +    **      // ALWAYS(x) asserts that x is true. NEVER(x) asserts x is false.
         2239  +    **    }else{
         2240  +    **      // ALWAYS(x) is a constant 1.  NEVER(x) is a constant 0.
         2241  +    **    }
         2242  +    */
         2243  +    case SQLITE_TESTCTRL_ALWAYS: {
         2244  +      int x = va_arg(ap,int);
         2245  +      rc = ALWAYS(x);
         2246  +      break;
         2247  +    }
  2196   2248     }
  2197   2249     va_end(ap);
  2198   2250   #endif /* SQLITE_OMIT_BUILTIN_TEST */
  2199   2251     return rc;
  2200   2252   }

Changes to src/sqlite.h.in.

    26     26   ** on how SQLite interfaces are suppose to operate.
    27     27   **
    28     28   ** The name of this file under configuration management is "sqlite.h.in".
    29     29   ** The makefile makes some minor changes to this file (such as inserting
    30     30   ** the version number) and changes its name to "sqlite3.h" as
    31     31   ** part of the build process.
    32     32   **
    33         -** @(#) $Id: sqlite.h.in,v 1.447 2009/04/30 15:59:56 drh Exp $
           33  +** @(#) $Id: sqlite.h.in,v 1.448 2009/05/09 18:59:42 drh Exp $
    34     34   */
    35     35   #ifndef _SQLITE3_H_
    36     36   #define _SQLITE3_H_
    37     37   #include <stdarg.h>     /* Needed for the definition of va_list */
    38     38   
    39     39   /*
    40     40   ** Make sure we can call this stuff from C++.
................................................................................
  4848   4848   #define SQLITE_TESTCTRL_PRNG_SAVE                5
  4849   4849   #define SQLITE_TESTCTRL_PRNG_RESTORE             6
  4850   4850   #define SQLITE_TESTCTRL_PRNG_RESET               7
  4851   4851   #define SQLITE_TESTCTRL_BITVEC_TEST              8
  4852   4852   #define SQLITE_TESTCTRL_FAULT_INSTALL            9
  4853   4853   #define SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS     10
  4854   4854   #define SQLITE_TESTCTRL_PENDING_BYTE            11
         4855  +#define SQLITE_TESTCTRL_ASSERT                  12
         4856  +#define SQLITE_TESTCTRL_ALWAYS                  13
  4855   4857   
  4856   4858   /*
  4857   4859   ** CAPI3REF: SQLite Runtime Status {H17200} <S60200>
  4858   4860   ** EXPERIMENTAL
  4859   4861   **
  4860   4862   ** This interface is used to retrieve runtime status information
  4861   4863   ** about the preformance of SQLite, and optionally to reset various