]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Code cleanup: get rid of the sqlite3SetNString utility function. (CVS 1984)
authordrh <drh@noemail.net>
Sat, 25 Sep 2004 14:39:18 +0000 (14:39 +0000)
committerdrh <drh@noemail.net>
Sat, 25 Sep 2004 14:39:18 +0000 (14:39 +0000)
FossilOrigin-Name: 9ef4c24a9acc2128891303de1ffd2ef4509d779c

manifest
manifest.uuid
src/build.c
src/main.c
src/pragma.c
src/select.c
src/sqliteInt.h
src/table.c
src/tokenize.c
src/util.c
src/vdbeaux.c

index 11e1814aef2c1e51b0461e0632a04c985f336a2f..0b0820fad410690b7c4bb73ae0ed7a12802a5e54 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Code\ssimplifications\sand\ssize\sreductions.\s(CVS\s1983)
-D 2004-09-25T13:12:15
+C Code\scleanup:\sget\srid\sof\sthe\ssqlite3SetNString\sutility\sfunction.\s(CVS\s1984)
+D 2004-09-25T14:39:18
 F Makefile.in abdeb5bd9d017822691884935c320037c33f6ee6
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -30,7 +30,7 @@ F src/attach.c e49d09dad9f5f9fb10b4b0c1be5a70ae4c45e689
 F src/auth.c 65408baa7e6621520882478dfa1e6b8c1d6c1850
 F src/btree.c 470e00b08688f065c2e62a6dcd3fb18880e8e309
 F src/btree.h 94dfec0a1722d33359b23e7e310f2b64ffedf029
-F src/build.c c5ecf114af4ebc2963a03142b6bd6f2284ee35fc
+F src/build.c 86318bdcd291919d4f87700385fdb73146436531
 F src/date.c eb8d5fa1a6d5cfc09031c8852d10ff742a94b15b
 F src/delete.c d862b383a9abc0b79f4588783c2619fe52d74ea7
 F src/expr.c f255c5c56c0371cb2955cbc2733621051e4f79f8
@@ -39,7 +39,7 @@ F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c 2c10c001f62cde92e9517ec7516b6584519754d1
 F src/legacy.c d58ea507bce885298a2c8c3cbb0f4bff5d47830b
-F src/main.c 82a952ef3e5f7bacaa1b20060d0588f8767a6774
+F src/main.c b86dacaaa09eb614dec7051a8a006434a7bcaa06
 F src/md5.c 7ae1c39044b95de2f62e066f47bb1deb880a1070
 F src/os.h d1780e0db95cad01f213d48da22ab490eb4fd345
 F src/os_common.h cd7eb025fdab7dc91e0e97bf6310f1648205857f
@@ -54,31 +54,31 @@ F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44
 F src/pager.c 705a61117f05d7dd031762408f9a279834e88c3a
 F src/pager.h 67739fe649f33be55dba522ca8a9cc4e42d14f71
 F src/parse.y 93edda0f1e9b25bee7cdfb5bf624ae85f8e9e5c9
-F src/pragma.c 5fb6647fda4c95edb08447a505e6c98c041e5b31
+F src/pragma.c 45978cc82fdf91f00d024a8e875c2b679fbce488
 F src/printf.c 40770e1f553612d13dfc86d236086e69baa62fe1
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
-F src/select.c 97c5f11b2b456dc6113454e592dbf03dc46e2b9d
+F src/select.c 96b1489111abe9b584be2f2cce26ad6f2d425b4e
 F src/shell.c 0856973c2b94e22664bc43f398ba3fc22d5e080c
 F src/sqlite.h.in e29a526593b806f148017ed8bada760ada84cf2f
-F src/sqliteInt.h 581437ae245e5b8294bfc20c9a06a16bb6b3d281
-F src/table.c 8168c6e824009f8485bff79fc60ea8fea6829b10
+F src/sqliteInt.h 1259d965d61209d35e5fb3704ab5167a8a123a72
+F src/table.c 549f324e3239d3c3658e333e5e422bdcab81b9a0
 F src/tclsqlite.c 0302e3f42f015d132d1291f3388c06e86c24a008
 F src/test1.c 1305825c29575ee55a1c8b98a191669fd78b6287
 F src/test2.c 0f3e0ad7b675a6f3323211ab4ea95490855654c3
 F src/test3.c 5b5b0f3d11b097399c1054fff73d8f3711092301
 F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df
 F src/test5.c b001fa7f1b9e2dc5c2331de62fc641b5ab2bd7a1
-F src/tokenize.c 418ef7ba1149603a30dcf0057e04a3ea0e99edbe
+F src/tokenize.c 85a5b0de4635bc96ec9860274449448ff0d0726d
 F src/trigger.c d1f770ee37a80391dd6d0948ee821b0272f99ae7
 F src/update.c 7157084216c4b02a23cdb23eb6d246aa9034fa4d
 F src/utf.c f4f83acd73389090e32d6589d307fc55d794c7ed
-F src/util.c f9b661a3b80a1469777771776a59a5f0e2f193fc
+F src/util.c 39a6718b221b5c575e09bb9069ec7c7fb539d5a5
 F src/vacuum.c 257de36230cb988842f66eb08dc6c0250b8e05f3
 F src/vdbe.c 0542852785220807feb02b9dee1150ac2e592c8d
 F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181
 F src/vdbeInt.h 6017100adff362b8dfa37a69e3f1431f084bfa5b
 F src/vdbeapi.c 81ab9e84c55f5762f552904e6e5d309269b02017
-F src/vdbeaux.c dc3848209aee05b32636a9c1dd913a56ef8dac79
+F src/vdbeaux.c 598af6c20124a205306475cd9dcee04317d0c622
 F src/vdbemem.c ef9ac7d32acfe4bce5c5b408b1294c8d9e0cdb56
 F src/where.c 04d3ee039d8e66c520e3b6bd5103dc3b8c3eb76b
 F test/all.test 929bfa932b55e75c96fe2203f7650ba451c1862c
@@ -247,7 +247,7 @@ F www/tclsqlite.tcl 560ecd6a916b320e59f2917317398f3d59b7cc25
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P b2f3d4bb8e24212d3cef7615c24da13f29c1440c
-R 7b7549a8227df9a562548ecaa05d3fba
+P cb631a135da92fd689ee40a8b7e2695a510eb765
+R 0e57f8bf788b1fab54d791e8a0ff38cb
 U drh
-Z e21d66c92b9e14b190cf7982b2d07af5
+Z 4e1f4e3ae25eddb22e2a4ce1e3a8ec1c
index b82020422499f46e63dc920ca5778ccc58c50b0c..d7bf2601220134bba031b87458d4e315599a3cee 100644 (file)
@@ -1 +1 @@
-cb631a135da92fd689ee40a8b7e2695a510eb765
\ No newline at end of file
+9ef4c24a9acc2128891303de1ffd2ef4509d779c
\ No newline at end of file
index 26e20db8c4023aef5937915a75800111821d6859..94c63148012f5c6bd5e131d6cc4f7e9bfe797007 100644 (file)
@@ -23,7 +23,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.253 2004/09/15 13:38:11 drh Exp $
+** $Id: build.c,v 1.254 2004/09/25 14:39:18 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -785,8 +785,8 @@ void sqlite3AddColumnType(Parse *pParse, Token *pFirst, Token *pLast){
   pCol = &p->aCol[i];
   pz = &pCol->zType;
   n = pLast->n + Addr(pLast->z) - Addr(pFirst->z);
-  sqlite3SetNString(pz, pFirst->z, n, (char*)0);
-  z = *pz;
+  assert( pCol->zType==0 );
+  z = pCol->zType = sqlite3MPrintf("%.*s", n, pFirst->z);
   if( z==0 ) return;
   for(i=j=0; z[i]; i++){
     int c = z[i];
@@ -808,17 +808,13 @@ void sqlite3AddColumnType(Parse *pParse, Token *pFirst, Token *pLast){
 void sqlite3AddDefaultValue(Parse *pParse, Token *pVal, int minusFlag){
   Table *p;
   int i;
-  char **pz;
+  char *z;
   if( (p = pParse->pNewTable)==0 ) return;
   i = p->nCol-1;
   if( i<0 ) return;
-  pz = &p->aCol[i].zDflt;
-  if( minusFlag ){
-    sqlite3SetNString(pz, "-", 1, pVal->z, pVal->n, (char*)0);
-  }else{
-    sqlite3SetNString(pz, pVal->z, pVal->n, (char*)0);
-  }
-  sqlite3Dequote(*pz);
+  assert( p->aCol[i].zDflt==0 );
+  z = p->aCol[i].zDflt = sqlite3MPrintf("%s%T", minusFlag ? "-" : "", pVal);
+  sqlite3Dequote(z);
 }
 
 /*
@@ -1016,8 +1012,7 @@ static int synthCollSeq(Parse *pParse, CollSeq *pColl){
     }
   }
   if( pParse->nErr==0 ){
-    sqlite3SetNString(&pParse->zErrMsg, "no such collation sequence: ", 
-        -1, z, n, (char*)0);
+    sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", n, z);
   }
   pParse->nErr++;
   return SQLITE_ERROR;
@@ -1082,6 +1077,7 @@ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){
   u8 enc = pParse->db->enc;
   u8 initbusy = pParse->db->init.busy;
   CollSeq *pColl = sqlite3FindCollSeq(pParse->db, enc, zName, nName, initbusy);
+  if( nName<0 ) nName = strlen(zName);
   if( !initbusy && (!pColl || !pColl->xCmp) ){
     /* No collation sequence of this type for this encoding is registered.
     ** Call the collation factory to see if it can supply us with one.
@@ -1101,10 +1097,8 @@ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){
   /* If nothing has been found, write the error message into pParse */
   if( !initbusy && (!pColl || !pColl->xCmp) ){
     if( pParse->nErr==0 ){
-      sqlite3SetNString(&pParse->zErrMsg, "no such collation sequence: ", -1,
-          zName, nName, (char*)0);
+      sqlite3ErrorMsg(pParse, "no such collation sequence: %.*s", nName, zName);
     }
-    pParse->nErr++;
     pColl = 0;
   }
   return pColl;
index 195086f9ca679491cadc35da4d21c53ad440f28c..2b8fe682a493901b3310e38d089a9c831504a226 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.260 2004/09/15 13:38:11 drh Exp $
+** $Id: main.c,v 1.261 2004/09/25 14:39:18 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -669,9 +669,7 @@ void sqlite3_interrupt(sqlite3 *db){
 ** SQLite is a DLL.  For some reason, it does not work to call free()
 ** directly.
 **
-** Note that we need to call free() not sqliteFree() here, since every
-** string that is exported from SQLite should have already passed through
-** sqlite3StrRealloc().
+** Note that we need to call free() not sqliteFree() here.
 */
 void sqlite3_free(char *p){ free(p); }
 
index f862a45c7d5b894c6957bce03e6ac534e1cdb1d7..cf0f92d3f1e466abbceda41b15331a05fc516daf 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the PRAGMA command.
 **
-** $Id: pragma.c,v 1.66 2004/09/17 20:25:25 drh Exp $
+** $Id: pragma.c,v 1.67 2004/09/25 14:39:19 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -207,8 +207,7 @@ void sqlite3Pragma(
   zLeft = sqlite3NameFromToken(pId);
   if( !zLeft ) return;
   if( minusFlag ){
-    zRight = 0;
-    sqlite3SetNString(&zRight, "-", 1, pValue->z, pValue->n, (char*)0);
+    zRight = sqlite3MPrintf("-%T", pValue);
   }else{
     zRight = sqlite3NameFromToken(pValue);
   }
index 97423866318914db7e282567db6877c1f0271fc0..1c6d48f9477632137d0ae21fc76a7f7cc25abf79 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.210 2004/09/25 13:12:16 drh Exp $
+** $Id: select.c,v 1.211 2004/09/25 14:39:19 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -116,13 +116,12 @@ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){
      (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) ||
      (jointype & JT_ERROR)!=0
   ){
-    static Token dummy = { 0, 0 };
-    char *zSp1 = " ", *zSp2 = " ";
-    if( pB==0 ){ pB = &dummy; zSp1 = 0; }
-    if( pC==0 ){ pC = &dummy; zSp2 = 0; }
-    sqlite3SetNString(&pParse->zErrMsg, "unknown or unsupported join type: ", 0,
-       pA->z, pA->n, zSp1, 1, pB->z, pB->n, zSp2, 1, pC->z, pC->n, (char*)0);
-    pParse->nErr++;
+    const char *zSp1 = " ";
+    const char *zSp2 = " ";
+    if( pB==0 ){ zSp1++; }
+    if( pC==0 ){ zSp2++; }
+    sqlite3ErrorMsg(pParse, "unknown or unsupported join type: "
+       "%T%s%T%s%T", pA, zSp1, pB, zSp2, pC);
     jointype = JT_INNER;
   }else if( jointype & JT_RIGHT ){
     sqlite3ErrorMsg(pParse, 
@@ -480,7 +479,6 @@ static int selectInnerLoop(
       if( pOrderBy ){
         pushOntoSorter(pParse, v, pOrderBy);
       }else{
-        char const *affStr;
         char aff = (iParm>>16)&0xFF;
         aff = sqlite3CompareAffinity(pEList->a[0].pExpr, aff);
         sqlite3VdbeOp3(v, OP_MakeRecord, 1, 0, &aff, 1);
index 0babae4ca86f510aafd7301b9ec6ca1a97cb6225..ea7b1a92d759c03ad23edd323c6d7a0964f9b849 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.323 2004/09/25 13:12:16 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.324 2004/09/25 14:39:19 drh Exp $
 */
 #ifndef _SQLITEINT_H_
 #define _SQLITEINT_H_
@@ -197,16 +197,13 @@ struct BusyHandler {
 # define sqliteRealloc(X,Y) sqlite3Realloc_(X,Y,__FILE__,__LINE__)
 # define sqliteStrDup(X)    sqlite3StrDup_(X,__FILE__,__LINE__)
 # define sqliteStrNDup(X,Y) sqlite3StrNDup_(X,Y,__FILE__,__LINE__)
-  void sqlite3StrRealloc(char**);
 #else
 # define sqliteFree          sqlite3FreeX
 # define sqliteMalloc        sqlite3Malloc
 # define sqliteMallocRaw     sqlite3MallocRaw
 # define sqliteRealloc       sqlite3Realloc
-/* # define sqliteRealloc_(X,Y) sqlite3Realloc(X,Y) */
-# define sqlite3StrRealloc(X)
-# define sqliteStrDup         sqlite3StrDup
-# define sqliteStrNDup        sqlite3StrNDup
+# define sqliteStrDup        sqlite3StrDup
+# define sqliteStrNDup       sqlite3StrNDup
 #endif
 
 /*
@@ -1208,7 +1205,6 @@ char *sqlite3VMPrintf(const char*, va_list);
 void sqlite3DebugPrintf(const char*, ...);
 void *sqlite3TextToPtr(const char*);
 void sqlite3SetString(char **, const char *, ...);
-void sqlite3SetNString(char **, ...);
 void sqlite3ErrorMsg(Parse*, const char*, ...);
 void sqlite3Dequote(char*);
 int sqlite3KeywordCode(const char*, int);
index 2725be927279cedbd15da885c0fb1321ddb8dada..e35ca345c5ab77186c81ccf131795074a5f06356 100644 (file)
@@ -150,11 +150,9 @@ int sqlite3_get_table(
     if( res.zErrMsg ){
       if( pzErrMsg ){
         free(*pzErrMsg);
-        *pzErrMsg = res.zErrMsg;
-        sqlite3StrRealloc(pzErrMsg);
-      }else{
-        sqliteFree(res.zErrMsg);
+        *pzErrMsg = sqlite3_mprintf("%s",res.zErrMsg);
       }
+      sqliteFree(res.zErrMsg);
     }
     return res.rc;
   }
index f0865656c06da41e4420ff4928e5881fcb82aaf4..7e2ab6274ac5f0202934a3d746e0ad24c61ed2aa 100644 (file)
@@ -15,7 +15,7 @@
 ** individual tokens and sends those tokens one-by-one over to the
 ** parser for analysis.
 **
-** $Id: tokenize.c,v 1.87 2004/09/08 15:09:41 drh Exp $
+** $Id: tokenize.c,v 1.88 2004/09/25 14:39:19 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -500,8 +500,11 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
         break;
       }
       case TK_ILLEGAL: {
-        sqlite3SetNString(pzErrMsg, "unrecognized token: \"", -1, 
-           pParse->sLastToken.z, pParse->sLastToken.n, "\"", 1, (char*)0);
+        if( pzErrMsg ){
+          sqliteFree(*pzErrMsg);
+          *pzErrMsg = sqlite3MPrintf("unrecognized token: \"%T\"",
+                          &pParse->sLastToken);
+        }
         nErr++;
         goto abort_parse;
       }
index b99f2620983dc9114c4ddb3f010c3c136c333646..6f284d1f47fbef37706e9b0cae965dc64be6fa87 100644 (file)
@@ -14,7 +14,7 @@
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.117 2004/09/08 20:13:06 drh Exp $
+** $Id: util.c,v 1.118 2004/09/25 14:39:19 drh Exp $
 */
 #include "sqliteInt.h"
 #include <stdarg.h>
@@ -214,28 +214,6 @@ void *sqlite3Realloc_(void *oldP, int n, char *zFile, int line){
   return p;
 }
 
-/*
-** Make a duplicate of a string into memory obtained from malloc()
-** Free the original string using sqliteFree().
-**
-** This routine is called on all strings that are passed outside of
-** the SQLite library.  That way clients can free the string using free()
-** rather than having to call sqliteFree().
-*/
-void sqlite3StrRealloc(char **pz){
-  char *zNew;
-  if( pz==0 || *pz==0 ) return;
-  zNew = malloc( strlen(*pz) + 1 );
-  if( zNew==0 ){
-    sqlite3_malloc_failed++;
-    sqliteFree(*pz);
-    *pz = 0;
-  }
-  strcpy(zNew, *pz);
-  sqliteFree(*pz);
-  *pz = zNew;
-}
-
 /*
 ** Make a copy of a string in memory obtained from sqliteMalloc()
 */
@@ -389,48 +367,6 @@ void sqlite3SetString(char **pz, const char *zFirst, ...){
 #endif
 }
 
-/*
-** Works like sqlite3SetString, but each string is now followed by
-** a length integer which specifies how much of the source string 
-** to copy (in bytes).  -1 means use the whole string.  The 1st 
-** argument must either be NULL or point to memory obtained from 
-** sqliteMalloc().
-*/
-void sqlite3SetNString(char **pz, ...){
-  va_list ap;
-  int nByte;
-  const char *z;
-  char *zResult;
-  int n;
-
-  if( pz==0 ) return;
-  nByte = 0;
-  va_start(ap, pz);
-  while( (z = va_arg(ap, const char*))!=0 ){
-    n = va_arg(ap, int);
-    if( n<=0 ) n = strlen(z);
-    nByte += n;
-  }
-  va_end(ap);
-  sqliteFree(*pz);
-  *pz = zResult = sqliteMallocRaw( nByte + 1 );
-  if( zResult==0 ) return;
-  va_start(ap, pz);
-  while( (z = va_arg(ap, const char*))!=0 ){
-    n = va_arg(ap, int);
-    if( n<=0 ) n = strlen(z);
-    memcpy(zResult, z, n);
-    zResult += n;
-  }
-  *zResult = 0;
-#ifdef SQLITE_DEBUG
-#if SQLITE_DEBUG>1
-  fprintf(stderr,"string at 0x%x is %s\n", (int)*pz, *pz);
-#endif
-#endif
-  va_end(ap);
-}
-
 /*
 ** Set the most recent error code and error string for the sqlite
 ** handle "db". The error code is set to "err_code".
index 15a5b57bdda775197cf4ed124db20e9d5ccc7d3c..286ca842383c9924d9900c298846960a7e71634f 100644 (file)
@@ -304,7 +304,8 @@ void sqlite3VdbeChangeP3(Vdbe *p, int addr, const char *zP3, int n){
     pOp->p3 = (char*)zP3;
     pOp->p3type = n;
   }else{
-    sqlite3SetNString(&pOp->p3, zP3, n, (char*)0);
+    if( n==0 ) n = strlen(zP3);
+    pOp->p3 = sqliteStrNDup(zP3, n);
     pOp->p3type = P3_DYNAMIC;
   }
 }