/ Check-in [adedd697]
Login

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

Overview
Comment:Fix harmless compiler warnings. Improved comments in the query optimizer. (CVS 5982)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:adedd697b475dadaa2eeae0d0413603195c955cf
User & Date: drh 2008-12-05 17:17:08
Context
2008-12-05
20:01
Make sure the nOverflow flag in MemPage is reset to zero after every insert. (CVS 5983) check-in: bfde3dae user: drh tags: trunk
17:17
Fix harmless compiler warnings. Improved comments in the query optimizer. (CVS 5982) check-in: adedd697 user: drh tags: trunk
15:24
Make use of sqlite3DbMallocSize to maximize the size of growable buffers after each reallocation. Added new comments and testcase() macros to where.c. (CVS 5981) check-in: 46f2d089 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mem2.c.

    15     15   ** to obtain the memory it needs while adding lots of additional debugging
    16     16   ** information to each allocation in order to help detect and fix memory
    17     17   ** leaks and memory usage errors.
    18     18   **
    19     19   ** This file contains implementations of the low-level memory allocation
    20     20   ** routines specified in the sqlite3_mem_methods object.
    21     21   **
    22         -** $Id: mem2.c,v 1.40 2008/10/28 18:58:20 drh Exp $
           22  +** $Id: mem2.c,v 1.41 2008/12/05 17:17:08 drh Exp $
    23     23   */
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** This version of the memory allocator is used only if the
    28     28   ** SQLITE_MEMDEBUG macro is defined
    29     29   */
................................................................................
   154    154     struct MemBlockHdr *p;
   155    155     int *pInt;
   156    156     u8 *pU8;
   157    157     int nReserve;
   158    158   
   159    159     p = (struct MemBlockHdr*)pAllocation;
   160    160     p--;
   161         -  assert( p->iForeGuard==FOREGUARD );
          161  +  assert( p->iForeGuard==(int)FOREGUARD );
   162    162     nReserve = (p->iSize+7)&~7;
   163    163     pInt = (int*)pAllocation;
   164    164     pU8 = (u8*)pAllocation;
   165         -  assert( pInt[nReserve/sizeof(int)]==REARGUARD );
          165  +  assert( pInt[nReserve/sizeof(int)]==(int)REARGUARD );
   166    166     assert( (nReserve-0)<=p->iSize || pU8[nReserve-1]==0x65 );
   167    167     assert( (nReserve-1)<=p->iSize || pU8[nReserve-2]==0x65 );
   168    168     assert( (nReserve-2)<=p->iSize || pU8[nReserve-3]==0x65 );
   169    169     return p;
   170    170   }
   171    171   
   172    172   /*
................................................................................
   181    181     return pHdr->iSize;
   182    182   }
   183    183   
   184    184   /*
   185    185   ** Initialize the memory allocation subsystem.
   186    186   */
   187    187   static int sqlite3MemInit(void *NotUsed){
          188  +  UNUSED_PARAMETER(NotUsed);
   188    189     if( !sqlite3GlobalConfig.bMemstat ){
   189    190       /* If memory status is enabled, then the malloc.c wrapper will already
   190    191       ** hold the STATIC_MEM mutex when the routines here are invoked. */
   191    192       mem.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
   192    193     }
   193    194     return SQLITE_OK;
   194    195   }
   195    196   
   196    197   /*
   197    198   ** Deinitialize the memory allocation subsystem.
   198    199   */
   199    200   static void sqlite3MemShutdown(void *NotUsed){
          201  +  UNUSED_PARAMETER(NotUsed);
   200    202     mem.mutex = 0;
   201    203   }
   202    204   
   203    205   /*
   204    206   ** Round up a request size to the next valid allocation size.
   205    207   */
   206    208   static int sqlite3MemRoundup(int n){
................................................................................
   357    359     mem.xBacktrace = xBacktrace;
   358    360   }
   359    361   
   360    362   /*
   361    363   ** Set the title string for subsequent allocations.
   362    364   */
   363    365   void sqlite3MemdebugSettitle(const char *zTitle){
   364         -  int n = strlen(zTitle) + 1;
          366  +  unsigned int n = strlen(zTitle) + 1;
   365    367     sqlite3_mutex_enter(mem.mutex);
   366    368     if( n>=sizeof(mem.zTitle) ) n = sizeof(mem.zTitle)-1;
   367    369     memcpy(mem.zTitle, zTitle, n);
   368    370     mem.zTitle[n] = 0;
   369    371     mem.nTitle = (n+7)&~7;
   370    372     sqlite3_mutex_leave(mem.mutex);
   371    373   }

Changes to src/mutex_noop.c.

    21     21   **
    22     22   ** interface.
    23     23   **
    24     24   ** If compiled with SQLITE_DEBUG, then additional logic is inserted
    25     25   ** that does error checking on mutexes to make sure they are being
    26     26   ** called correctly.
    27     27   **
    28         -** $Id: mutex_noop.c,v 1.2 2008/10/15 19:03:03 drh Exp $
           28  +** $Id: mutex_noop.c,v 1.3 2008/12/05 17:17:08 drh Exp $
    29     29   */
    30     30   #include "sqliteInt.h"
    31     31   
    32     32   
    33     33   #if defined(SQLITE_MUTEX_NOOP) && !defined(SQLITE_DEBUG)
    34     34   /*
    35     35   ** Stub routines for all mutex methods.
................................................................................
   112    112           pNew->id = id;
   113    113           pNew->cnt = 0;
   114    114         }
   115    115         break;
   116    116       }
   117    117       default: {
   118    118         assert( id-2 >= 0 );
   119         -      assert( id-2 < sizeof(aStatic)/sizeof(aStatic[0]) );
          119  +      assert( id-2 < (int)(sizeof(aStatic)/sizeof(aStatic[0])) );
   120    120         pNew = &aStatic[id-2];
   121    121         pNew->id = id;
   122    122         break;
   123    123       }
   124    124     }
   125    125     return pNew;
   126    126   }

Changes to src/shell.c.

     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   ** This file contains code to implement the "sqlite" command line
    13     13   ** utility for accessing SQLite databases.
    14     14   **
    15         -** $Id: shell.c,v 1.189 2008/12/04 12:26:01 drh Exp $
           15  +** $Id: shell.c,v 1.190 2008/12/05 17:17:08 drh Exp $
    16     16   */
    17     17   #include <stdlib.h>
    18     18   #include <string.h>
    19     19   #include <stdio.h>
    20     20   #include <assert.h>
    21     21   #include "sqlite3.h"
    22     22   #include <ctype.h>
................................................................................
    61     61    */
    62     62   #define isatty(x) 1
    63     63   #endif
    64     64   
    65     65   #if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__) && !defined(__RTP__) && !defined(_WRS_KERNEL)
    66     66   #include <sys/time.h>
    67     67   #include <sys/resource.h>
           68  +
           69  +/*
           70  +** Used to prevent warnings about unused parameters
           71  +*/
           72  +#define UNUSED_PARAMETER(x) (void)(x)
           73  +
    68     74   
    69     75   /* Saved resource information for the beginning of an operation */
    70     76   static struct rusage sBegin;
    71     77   
    72     78   /* True if the timer is enabled */
    73     79   static int enableTimer = 0;
    74     80   
................................................................................
   212    218   static void shellstaticFunc(
   213    219     sqlite3_context *context,
   214    220     int argc,
   215    221     sqlite3_value **argv
   216    222   ){
   217    223     assert( 0==argc );
   218    224     assert( zShellStatic );
          225  +  UNUSED_PARAMETER(argv);
   219    226     sqlite3_result_text(context, zShellStatic, -1, SQLITE_STATIC);
   220    227   }
   221    228   
   222    229   
   223    230   /*
   224    231   ** This routine reads a line of text from FILE in, stores
   225    232   ** the text in memory obtained from malloc() and returns a pointer
................................................................................
   351    358     "csv",
   352    359     "explain",
   353    360   };
   354    361   
   355    362   /*
   356    363   ** Number of elements in an array
   357    364   */
   358         -#define ArraySize(X)  (sizeof(X)/sizeof(X[0]))
          365  +#define ArraySize(X)  (int)(sizeof(X)/sizeof(X[0]))
   359    366   
   360    367   /*
   361    368   ** Output the given string as a quoted string using SQL quoting conventions.
   362    369   */
   363    370   static void output_quoted_string(FILE *out, const char *z){
   364    371     int i;
   365    372     int nSingle = 0;
................................................................................
   498    505   }
   499    506   
   500    507   #ifdef SIGINT
   501    508   /*
   502    509   ** This routine runs when the user presses Ctrl-C
   503    510   */
   504    511   static void interrupt_handler(int NotUsed){
          512  +  UNUSED_PARAMETER(NotUsed);
   505    513     seenInterrupt = 1;
   506    514     if( db ) sqlite3_interrupt(db);
   507    515   }
   508    516   #endif
   509    517   
   510    518   /*
   511    519   ** This is the callback routine that the SQLite library
................................................................................
   570    578         for(i=0; i<nArg; i++){
   571    579           int w;
   572    580           if( i<ArraySize(p->actualWidth) ){
   573    581              w = p->actualWidth[i];
   574    582           }else{
   575    583              w = 10;
   576    584           }
   577         -        if( p->mode==MODE_Explain && azArg[i] && strlen(azArg[i])>w ){
          585  +        if( p->mode==MODE_Explain && azArg[i] && strlen(azArg[i])>(unsigned)w ){
   578    586             w = strlen(azArg[i]);
   579    587           }
   580    588           fprintf(p->out,"%-*.*s%s",w,w,
   581    589               azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": "  ");
   582    590         }
   583    591         break;
   584    592       }
................................................................................
   789    797   static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){
   790    798     int rc;
   791    799     const char *zTable;
   792    800     const char *zType;
   793    801     const char *zSql;
   794    802     struct callback_data *p = (struct callback_data *)pArg;
   795    803   
          804  +  UNUSED_PARAMETER(azCol);
   796    805     if( nArg!=3 ) return 1;
   797    806     zTable = azArg[0];
   798    807     zType = azArg[1];
   799    808     zSql = azArg[2];
   800    809     
   801    810     if( strcmp(zTable, "sqlite_sequence")==0 ){
   802    811       fprintf(p->out, "DELETE FROM sqlite_sequence;\n");

Changes to src/sqliteInt.h.

     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.801 2008/12/05 02:36:34 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.802 2008/12/05 17:17:08 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Include the configuration header output by 'configure' if we're using the
    21     21   ** autoconf-based build
................................................................................
  1513   1513   ** index information for the i-th loop of the join.  pBestInfo is always
  1514   1514   ** either NULL or a copy of some pIdxInfo.  So for cleanup it is 
  1515   1515   ** sufficient to free all of the pIdxInfo pointers.
  1516   1516   ** 
  1517   1517   */
  1518   1518   struct WhereLevel {
  1519   1519     int iFrom;            /* Which entry in the FROM clause */
  1520         -  int wsFlags;          /* "Where-Scan Flags" associated with this level */
         1520  +  int wsFlags;          /* "Where-Scan" flags show the choosen scan strategy */
  1521   1521     int iMem;             /* First memory cell used by this level */
  1522   1522     int iLeftJoin;        /* Memory cell used to implement LEFT OUTER JOIN */
  1523   1523     Index *pIdx;          /* Index used.  NULL if no index */
  1524   1524     int iTabCur;          /* The VDBE cursor used to access the table */
  1525   1525     int iIdxCur;          /* The VDBE cursor used to access pIdx */
  1526   1526     int brk;              /* Jump here to break out of the loop */
  1527   1527     int nxt;              /* Jump here to start the next IN combination */

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing all sorts of SQLite interfaces.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.335 2008/12/03 22:32:45 drh Exp $
           16  +** $Id: test1.c,v 1.336 2008/12/05 17:17:08 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
    22     22   
    23     23   /*
................................................................................
  3911   3911       db->magic = SQLITE_MAGIC_OPEN;
  3912   3912     }else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){
  3913   3913       db->magic = SQLITE_MAGIC_CLOSED;
  3914   3914     }else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){
  3915   3915       db->magic = SQLITE_MAGIC_BUSY;
  3916   3916     }else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){
  3917   3917       db->magic = SQLITE_MAGIC_ERROR;
  3918         -  }else if( Tcl_GetInt(interp, argv[2], &db->magic) ){
         3918  +  }else if( Tcl_GetInt(interp, argv[2], (int*)&db->magic) ){
  3919   3919       return TCL_ERROR;
  3920   3920     }
  3921   3921     return TCL_OK;
  3922   3922   }
  3923   3923   
  3924   3924   /*
  3925   3925   ** Usage:  sqlite3_interrupt  DB 
................................................................................
  4512   4512   */
  4513   4513   static int file_control_lockproxy_test(
  4514   4514     ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
  4515   4515     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  4516   4516     int objc,              /* Number of arguments */
  4517   4517     Tcl_Obj *CONST objv[]  /* Command arguments */
  4518   4518   ){
  4519         -  int iArg = 0;
  4520   4519     sqlite3 *db;
  4521         -  int rc;
  4522   4520     
  4523   4521     if( objc!=2 ){
  4524   4522       Tcl_AppendResult(interp, "wrong # args: should be \"",
  4525   4523                        Tcl_GetStringFromObj(objv[0], 0), " DB", 0);
  4526   4524       return TCL_ERROR;
  4527   4525     }
  4528   4526     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;

Changes to src/where.c.

    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  This module is responsible for
    14     14   ** generating the code that loops through a table looking for applicable
    15     15   ** rows.  Indices are selected and used to speed the search when doing
    16     16   ** so is applicable.  Because this module is responsible for selecting
    17     17   ** indices, you might also think of this module as the "query optimizer".
    18     18   **
    19         -** $Id: where.c,v 1.332 2008/12/05 15:24:17 drh Exp $
           19  +** $Id: where.c,v 1.333 2008/12/05 17:17:08 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** Trace output macros
    25     25   */
    26     26   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
................................................................................
   276    276   **           \________/     \_______________/     \________________/
   277    277   **            slot[0]            slot[1]               slot[2]
   278    278   **
   279    279   ** The original WHERE clause in pExpr is unaltered.  All this routine
   280    280   ** does is make slot[] entries point to substructure within pExpr.
   281    281   **
   282    282   ** In the previous sentence and in the diagram, "slot[]" refers to
   283         -** the WhereClause.a[] array.  This array grows as needed to contain
          283  +** the WhereClause.a[] array.  The slot[] array grows as needed to contain
   284    284   ** all terms of the WHERE clause.
   285    285   */
   286    286   static void whereSplit(WhereClause *pWC, Expr *pExpr, int op){
   287    287     if( pExpr==0 ) return;
   288    288     if( pExpr->op!=op ){
   289    289       whereClauseInsert(pWC, pExpr, 0);
   290    290     }else{
................................................................................
   387    387     assert( TK_LT>TK_EQ && TK_LT<TK_GE );
   388    388     assert( TK_LE>TK_EQ && TK_LE<TK_GE );
   389    389     assert( TK_GE==TK_EQ+4 );
   390    390     return op==TK_IN || (op>=TK_EQ && op<=TK_GE) || op==TK_ISNULL;
   391    391   }
   392    392   
   393    393   /*
   394         -** Swap two objects of type T.
          394  +** Swap two objects of type TYPE.
   395    395   */
   396    396   #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;}
   397    397   
   398    398   /*
   399    399   ** Commute a comparison operator.  Expressions of the form "X op Y"
   400    400   ** are converted into "Y op X".
   401    401   **