From 2b8ef743af29fd37db9efd0bbde94bd3076d5afa Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 7 Jan 2003 13:55:22 +0000 Subject: [PATCH] In the VDBE, allocate space to hold column names when the VDBE first starts. The ColumnCount opcode now just writes the null terminator into this space. (CVS 818) FossilOrigin-Name: 46d8f5e377bf790c18a7acdd1f3bc20b538d69eb --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 21 ++++++--------------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/manifest b/manifest index 0822737eb6..66305f9453 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sconstructing\srecords\sand\sindex\skeys,\suse\sstatic\sstring\sspace\srather\sthan\nmallocing\s(when\spossible)\sfor\sa\ssmall\sspeed\simprovement.\s(CVS\s817) -D 2003-01-07T13:43:46 +C In\sthe\sVDBE,\sallocate\sspace\sto\shold\scolumn\snames\swhen\sthe\sVDBE\sfirst\sstarts.\nThe\sColumnCount\sopcode\snow\sjust\swrites\sthe\snull\sterminator\sinto\sthis\sspace.\s(CVS\s818) +D 2003-01-07T13:55:23 F Makefile.in 868c17a1ae1c07603d491274cc8f86c04acf2a1e F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -52,7 +52,7 @@ F src/tokenize.c 7ac1c33e0149647c9eb5959c48992df6906d4809 F src/trigger.c 5ba917fc226b96065108da28186c2efaec53e481 F src/update.c 881e4c8e7c786545da4fd2d95da19252b2e31137 F src/util.c e2d108842e02810d3d3242cac0e024b09cdb3c4a -F src/vdbe.c 07570003d3378b668408d8e54f4b137a12ca4df6 +F src/vdbe.c 42577c260b0bba8ff8dce60a0ffd8c71f413ef35 F src/vdbe.h 754eba497cfe0c3e352b9c101ab2f811f10d0a55 F src/where.c af235636b7bc7f7f42ee1c7162d1958ad0102cab F test/all.test 873d30e25a41b3aa48fec5633a7ec1816e107029 @@ -152,7 +152,7 @@ F www/speed.tcl a20a792738475b68756ea7a19321600f23d1d803 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P a362981b20fd33254ad498619eedf75b576682e3 -R 167f2117e4d0226460f1cb7008234b4d +P 657c9fb5133aef93e4edd433912e6942ad9674ec +R 30af34abe888623d0ad22c90d02b73df U drh -Z 09ee972659cfc232fea37abfb187e33e +Z 10b12f5b3cbab70eee4329daa1b839b8 diff --git a/manifest.uuid b/manifest.uuid index 97110e4e59..78111bdaff 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -657c9fb5133aef93e4edd433912e6942ad9674ec \ No newline at end of file +46d8f5e377bf790c18a7acdd1f3bc20b538d69eb \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 4f52d68ef5..655b060ada 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -36,7 +36,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.193 2003/01/07 13:43:46 drh Exp $ +** $Id: vdbe.c,v 1.194 2003/01/07 13:55:23 drh Exp $ */ #include "sqliteInt.h" #include @@ -247,7 +247,6 @@ struct Vdbe { int nLabelAlloc; /* Number of slots allocated in aLabel[] */ int *aLabel; /* Space to hold the labels */ int tos; /* Index of top of stack */ - int nStackAlloc; /* Size of the stack */ Stack *aStack; /* The operand stack, except string values */ char **zStack; /* Text or binary values of the stack */ char **azColName; /* Becomes the 4th parameter to callbacks */ @@ -1034,8 +1033,6 @@ static void SorterReset(Vdbe *p){ static void Cleanup(Vdbe *p){ int i; PopStack(p, p->tos+1); - sqliteFree(p->azColName); - p->azColName = 0; closeAllCursors(p); if( p->aMem ){ for(i=0; inMem; i++){ @@ -1105,7 +1102,6 @@ void sqliteVdbeDelete(Vdbe *p){ sqliteFree(p->aOp); sqliteFree(p->aLabel); sqliteFree(p->aStack); - sqliteFree(p->zStack); sqliteFree(p); } @@ -1410,8 +1406,10 @@ int sqliteVdbeExec( ** Allocation all the stack space we will ever need. */ sqliteVdbeAddOp(p, OP_Halt, 0, 0); - zStack = p->zStack = sqliteMalloc( p->nOp*sizeof(zStack[0]) ); - aStack = p->aStack = sqliteMalloc( p->nOp*sizeof(aStack[0]) ); + aStack = sqliteMalloc( p->nOp*(sizeof(aStack[0]) + 2*sizeof(char*)) ); + p->aStack = aStack; + zStack = p->zStack = (char**)&aStack[p->nOp]; + p->azColName = (char**)&zStack[p->nOp]; p->tos = -1; #ifdef VDBE_PROFILE { @@ -1721,13 +1719,9 @@ case OP_Push: { /* Opcode: ColumnCount P1 * * ** ** Specify the number of column values that will appear in the -** array passed as the 4th parameter to the callback. No checking -** is done. If this value is wrong, a coredump can result. +** array passed as the 4th parameter to the callback. */ case OP_ColumnCount: { - char **az = sqliteRealloc(p->azColName, (pOp->p1+1)*sizeof(char*)); - if( az==0 ){ goto no_mem; } - p->azColName = az; p->azColName[pOp->p1] = 0; p->nCallback = 0; break; @@ -1737,9 +1731,6 @@ case OP_ColumnCount: { ** ** P3 becomes the P1-th column name (first is 0). An array of pointers ** to all column names is passed as the 4th parameter to the callback. -** The ColumnCount opcode must be executed first to allocate space to -** hold the column names. Failure to do this will likely result in -** a coredump. */ case OP_ColumnName: { p->azColName[pOp->p1] = pOp->p3;