aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/select.c7
-rw-r--r--src/util.c15
-rw-r--r--src/vdbe.c50
3 files changed, 54 insertions, 18 deletions
diff --git a/src/select.c b/src/select.c
index 2171ead1b..73d766227 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.108 2002/08/24 18:24:54 drh Exp $
+** $Id: select.c,v 1.109 2002/08/25 18:29:12 drh Exp $
*/
#include "sqliteInt.h"
@@ -808,6 +808,7 @@ static int fillInColumnList(Parse *pParse, Select *p){
if( sqliteViewGetColumnNames(pParse, pTab) ){
return 1;
}
+ sqliteSelectDelete(pTabList->a[i].pSelect);
pTabList->a[i].pSelect = sqliteSelectDup(pTab->pSelect);
}
}
@@ -1309,8 +1310,11 @@ static void substExpr(Expr *pExpr, int iTable, ExprList *pEList, int iSub){
pNew = pEList->a[pExpr->iColumn].pExpr;
assert( pNew!=0 );
pExpr->op = pNew->op;
+ assert( pExpr->pLeft==0 );
pExpr->pLeft = sqliteExprDup(pNew->pLeft);
+ assert( pExpr->pRight==0 );
pExpr->pRight = sqliteExprDup(pNew->pRight);
+ assert( pExpr->pList==0 );
pExpr->pList = sqliteExprListDup(pNew->pList);
pExpr->iTable = pNew->iTable;
pExpr->iColumn = pNew->iColumn;
@@ -1495,6 +1499,7 @@ int flattenSubquery(Select *p, int iFrom, int isAgg, int subqueryIsAgg){
}
pSrc->a[iFrom].pTab = pSubSrc->a[0].pTab;
pSubSrc->a[0].pTab = 0;
+ assert( pSrc->a[iFrom].pSelect==pSub );
pSrc->a[iFrom].pSelect = pSubSrc->a[0].pSelect;
pSubSrc->a[0].pSelect = 0;
sqliteSelectDelete(pSub);
diff --git a/src/util.c b/src/util.c
index 11f9f752e..200a14c37 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.48 2002/08/13 23:02:57 drh Exp $
+** $Id: util.c,v 1.49 2002/08/25 18:29:12 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
@@ -39,6 +39,9 @@ int sqlite_malloc_failed = 0;
int sqlite_nMalloc; /* Number of sqliteMalloc() calls */
int sqlite_nFree; /* Number of sqliteFree() calls */
int sqlite_iMallocFail; /* Fail sqliteMalloc() after this many calls */
+#if MEMORY_DEBUG>1
+static int memcnt = 0;
+#endif
/*
@@ -75,7 +78,8 @@ void *sqliteMalloc_(int n, char *zFile, int line){
p = &pi[2];
memset(p, 0, n);
#if MEMORY_DEBUG>1
- fprintf(stderr,"malloc %d bytes at 0x%x from %s:%d\n", n, (int)p, zFile,line);
+ fprintf(stderr,"%06d malloc %d bytes at 0x%x from %s:%d\n",
+ ++memcnt, n, (int)p, zFile,line);
#endif
return p;
}
@@ -101,7 +105,8 @@ void sqliteFree_(void *p, char *zFile, int line){
}
memset(pi, 0xff, (k+3)*sizeof(int));
#if MEMORY_DEBUG>1
- fprintf(stderr,"free %d bytes at 0x%x from %s:%d\n", n, (int)p, zFile,line);
+ fprintf(stderr,"%06d free %d bytes at 0x%x from %s:%d\n",
+ ++memcnt, n, (int)p, zFile,line);
#endif
free(pi);
}
@@ -151,8 +156,8 @@ void *sqliteRealloc_(void *oldP, int n, char *zFile, int line){
memset(oldPi, 0, (oldK+3)*sizeof(int));
free(oldPi);
#if MEMORY_DEBUG>1
- fprintf(stderr,"realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n", oldN, n,
- (int)oldP, (int)p, zFile, line);
+ fprintf(stderr,"%06d realloc %d to %d bytes at 0x%x to 0x%x at %s:%d\n",
+ ++memcnt, oldN, n, (int)oldP, (int)p, zFile, line);
#endif
return p;
}
diff --git a/src/vdbe.c b/src/vdbe.c
index 6923951f9..4a7e2de91 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -30,7 +30,7 @@
** But other routines are also provided to help in building up
** a program instruction by instruction.
**
-** $Id: vdbe.c,v 1.169 2002/08/15 01:26:10 drh Exp $
+** $Id: vdbe.c,v 1.170 2002/08/25 18:29:13 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -253,6 +253,16 @@ struct Vdbe {
};
/*
+** When debugging the code generator in a symbolic debugger, on can
+** set the sqlite_vdbe_addop_trace to 1 and all opcodes will be printed
+** as they are added to the instruction stream.
+*/
+#ifndef NDEBUG
+int sqlite_vdbe_addop_trace = 0;
+static void vdbePrintOp(FILE*, int, Op*);
+#endif
+
+/*
** Create a new virtual database engine.
*/
Vdbe *sqliteVdbeCreate(sqlite *db){
@@ -312,6 +322,9 @@ int sqliteVdbeAddOp(Vdbe *p, int op, int p1, int p2){
p->aOp[i].p2 = p2;
p->aOp[i].p3 = 0;
p->aOp[i].p3type = P3_NOTUSED;
+#ifndef NDEBUG
+ if( sqlite_vdbe_addop_trace ) vdbePrintOp(0, i, &p->aOp[i]);
+#endif
return i;
}
@@ -397,6 +410,9 @@ int sqliteVdbeAddOpList(Vdbe *p, int nOp, VdbeOp const *aOp){
p->aOp[i+addr] = aOp[i];
if( p2<0 ) p->aOp[i+addr].p2 = addr + ADDR(p2);
p->aOp[i+addr].p3type = aOp[i].p3 ? P3_STATIC : P3_NOTUSED;
+#ifndef NDEBUG
+ if( sqlite_vdbe_addop_trace ) vdbePrintOp(0, i+addr, &p->aOp[i+addr]);
+#endif
}
p->nOp += nOp;
}
@@ -1266,6 +1282,26 @@ static char *vdbe_fgets(char *zBuf, int nBuf, FILE *in){
return i>0 ? zBuf : 0;
}
+#ifndef NDEBUG
+/*
+** Print a single opcode. This routine is used for debugging only.
+*/
+static void vdbePrintOp(FILE *pOut, int pc, Op *pOp){
+ char *zP3;
+ char zPtr[40];
+ if( pOp->p3type==P3_POINTER ){
+ sprintf(zPtr, "ptr(%#x)", (int)pOp->p3);
+ zP3 = zPtr;
+ }else{
+ zP3 = pOp->p3;
+ }
+ if( pOut==0 ) pOut = stdout;
+ fprintf(pOut,"%4d %-12s %4d %4d %s\n",
+ pc, zOpName[pOp->opcode], pOp->p1, pOp->p2, zP3 ? zP3 : "");
+ fflush(pOut);
+}
+#endif
+
/*
** Execute the program in the VDBE.
**
@@ -1358,17 +1394,7 @@ int sqliteVdbeExec(
*/
#ifndef NDEBUG
if( p->trace ){
- char *zP3;
- char zPtr[40];
- if( pOp->p3type==P3_POINTER ){
- sprintf(zPtr, "ptr(%#x)", (int)pOp->p3);
- zP3 = zPtr;
- }else{
- zP3 = pOp->p3;
- }
- fprintf(p->trace,"%4d %-12s %4d %4d %s\n",
- pc, zOpName[pOp->opcode], pOp->p1, pOp->p2, zP3 ? zP3 : "");
- fflush(p->trace);
+ vdbePrintOp(p->trace, pc, pOp);
}
#endif