Code cleanup: get rid of the sqlite3SetNString utility function. (CVS 1984)
FossilOrigin-Name: 9ef4c24a9acc2128891303de1ffd2ef4509d779c
diff --git a/src/build.c b/src/build.c
index 26e20db..94c6314 100644
--- a/src/build.c
+++ b/src/build.c
@@ -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 @@
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 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 @@
}
}
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 @@
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 @@
/* 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;
diff --git a/src/main.c b/src/main.c
index 195086f..2b8fe68 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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 @@
** 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); }
diff --git a/src/pragma.c b/src/pragma.c
index f862a45..cf0f92d 100644
--- a/src/pragma.c
+++ b/src/pragma.c
@@ -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 @@
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);
}
diff --git a/src/select.c b/src/select.c
index 9742386..1c6d48f 100644
--- a/src/select.c
+++ b/src/select.c
@@ -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 @@
(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 @@
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);
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 0babae4..ea7b1a9 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -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 @@
# 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 @@
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);
diff --git a/src/table.c b/src/table.c
index 2725be9..e35ca34 100644
--- a/src/table.c
+++ b/src/table.c
@@ -150,11 +150,9 @@
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;
}
diff --git a/src/tokenize.c b/src/tokenize.c
index f086565..7e2ab62 100644
--- a/src/tokenize.c
+++ b/src/tokenize.c
@@ -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 @@
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;
}
diff --git a/src/util.c b/src/util.c
index b99f262..6f284d1 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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>
@@ -215,28 +215,6 @@
}
/*
-** 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()
*/
char *sqlite3StrDup_(const char *z, char *zFile, int line){
@@ -390,48 +368,6 @@
}
/*
-** 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".
**
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index 15a5b57..286ca84 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -304,7 +304,8 @@
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;
}
}