From 777c5386c3f40185db1e23e413d6aff87c8042b5 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Aug 2008 20:21:34 +0000 Subject: [PATCH] Move date+time functions to start-time initialization. Additional start-time function cleanup. (CVS 5585) FossilOrigin-Name: 80d6a31cb3851704c09ac9d99fe4bc241df3c180 --- manifest | 26 ++++++++-------- manifest.uuid | 2 +- src/callback.c | 4 +-- src/date.c | 50 +++++++++++-------------------- src/func.c | 79 ++++++++----------------------------------------- src/global.c | 4 +-- src/main.c | 4 +-- src/pcache.c | 3 +- src/pcache.h | 3 +- src/sqliteInt.h | 39 ++++++++++++++++++++++-- 10 files changed, 88 insertions(+), 126 deletions(-) diff --git a/manifest b/manifest index bc2e939808..958bd0ca3b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sreferences\sto\sOP_MoveTo\sin\scomments\sof\svdbe.c\s-\sthat\sopcode\sno\nlonger\sexists.\s\sTicket\s#3327.\s(CVS\s5584) -D 2008-08-21T19:28:30 +C Move\sdate+time\sfunctions\sto\sstart-time\sinitialization.\s\sAdditional\nstart-time\sfunction\scleanup.\s(CVS\s5585) +D 2008-08-21T20:21:35 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 51b727303f84cf055e29514d8248e5eaf9701379 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -100,14 +100,14 @@ F src/btree.c 3078f7a5c7cde1e74d884dfa57410125d21586fb F src/btree.h 6371c5e599fab391a150c96afbc10062b276d107 F src/btreeInt.h ab18c7b4980314e9e4b402e5dcde09f3c2545576 F src/build.c 160c71acca8f643f436ed6c1ee2f684c88df4dfe -F src/callback.c 26f18b3cb5e44120390a8d2d97907889feb47bc5 +F src/callback.c 27e55dfafc66e97dd8e7343a1d7bb295f3afd736 F src/complete.c cb14e06dbe79dee031031f0d9e686ff306afe07c -F src/date.c 52a54811218a76da6235420f532ece841159a96d +F src/date.c 2373f20a91bec70e20e0e715520c8010d26ebb52 F src/delete.c 5105c67c741f934379722de5e11fdd73ea4d82b5 F src/expr.c 4651d08422474f7e4bcb9a35da00c33ebe719a2d F src/fault.c 3638519d1e0b82bccfafcb9f5ff491918b28f8e1 -F src/func.c f52c6d1b5d08b94ea348059e1bd067580490dd60 -F src/global.c 39350827d0bce0fe10cca8b13c5dfca3438b4f65 +F src/func.c f2e0b55f13e678a5c5ff94f0f225ed0a995acba7 +F src/global.c 239d03b6dbae6c985deb2ffb54ab919debb9f8d7 F src/hash.c eb64e48f3781100e5934f759fbe72a63a8fe78cb F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53 F src/hwtime.h 4a1d45f4cae1f402ea19686acf24acf4f0cb53cb @@ -115,7 +115,7 @@ F src/insert.c 110cca7845ed5a66c08fdd413b02e706ae34455f F src/journal.c cffd2cd214e58c0e99c3ff632b3bee6c7cbb260e F src/legacy.c aac57bd984e666059011ea01ec4383892a253be3 F src/loadext.c eb1fe4f44d7c8ff53fc0c6a4388ab79fbd34cd64 -F src/main.c 2513e9bb233a8ebc4aaa766a37528ef255cde7fb +F src/main.c 69dbacc8c605f19dd380b2eda8c947a2aac19671 F src/malloc.c 7ccc630b359f57a47b6034af54e42eb838eebd46 F src/md5.c 008216bbb5d34c6fbab5357aa68575ad8a31516a F src/mem1.c 3a7fe31d8290baa3bb203af72f7dfd6323966bcd @@ -138,8 +138,8 @@ F src/os_win.c aefe9ee26430678a19a058a874e4e2bd91398142 F src/pager.c 3a4358c72c9c8415e8648001c776857e6952e2b4 F src/pager.h 3778bea71dfb9658b6c94394e18db4a5b27e6ded F src/parse.y d0f76d2cb8d6883d5600dc20beb961a6022b94b8 -F src/pcache.c 4668410008dda89ff5f0eb62b887cfb5e13903eb -F src/pcache.h aef1dedd7ff6186f27052a2509fff437a8906977 +F src/pcache.c f57227003d39d40fa7f9b5a86e36b99f74b93267 +F src/pcache.h d2becbe7255f6bf57fc9e0bf889a9ec73d50ee74 F src/pragma.c f5b271b090af7fcedd308d7c5807a5503f7a853d F src/prepare.c c197041e0c4770672cda75e6bfe10242f885e510 F src/printf.c 2e984b2507291a7e16d89dc9bb60582904f6247d @@ -149,7 +149,7 @@ F src/select.c e71462393fe0f9d2bf41378763b96659e8780e43 F src/shell.c d83b578a8ccdd3e0e7fef4388a0887ce9f810967 F src/sqlite.h.in 54e51c22e2294c5989156b0aec87aa44168ac1f0 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e -F src/sqliteInt.h 15096ac72b783de470c7f89888560e2ddaa83898 +F src/sqliteInt.h ddf6c9eb90b295bcb7c600139227e5e2a16c8063 F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8 F src/status.c 8caa772cd9310bc297280f7cf0ede4d69ed5b801 F src/table.c 22744786199c9195720c15a7a42cb97b2e2728d8 @@ -622,7 +622,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P ef6936e50adb9ebea39c890167403fff01bbb5ed -R 93e8a5c8f5b8731f0168db8793678abe +P 30077ece459b515338723ca0dab11c18b9f09d21 +R e5f18970c2a651995955578eea70a847 U drh -Z fc276d4f825ababf0c32faa8e25a17cd +Z 9729df78d7652ca44708388f5fcbb37d diff --git a/manifest.uuid b/manifest.uuid index 756263beba..4acdf4a45c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -30077ece459b515338723ca0dab11c18b9f09d21 \ No newline at end of file +80d6a31cb3851704c09ac9d99fe4bc241df3c180 \ No newline at end of file diff --git a/src/callback.c b/src/callback.c index d25836b435..336f9a5591 100644 --- a/src/callback.c +++ b/src/callback.c @@ -13,7 +13,7 @@ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.28 2008/08/21 18:49:28 drh Exp $ +** $Id: callback.c,v 1.29 2008/08/21 20:21:35 drh Exp $ */ #include "sqliteInt.h" @@ -357,7 +357,7 @@ FuncDef *sqlite3FindFunction( ** function to use. */ if( !createFlag && !pBest ){ - p = functionSearch(&sqlite3FuncBuiltins, h, zName, nName); + p = functionSearch(&sqlite3GlobalFunctions, h, zName, nName); while( p ){ int score = matchQuality(p, nArg, enc); if( score>bestScore ){ diff --git a/src/date.c b/src/date.c index 08ee30c38a..68f33d7b22 100644 --- a/src/date.c +++ b/src/date.c @@ -16,7 +16,7 @@ ** sqlite3RegisterDateTimeFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: date.c,v 1.87 2008/07/28 19:34:53 drh Exp $ +** $Id: date.c,v 1.88 2008/08/21 20:21:35 drh Exp $ ** ** SQLite processes all times and dates as Julian Day numbers. The ** dates and times are stored as the number of days since noon @@ -1052,42 +1052,26 @@ static void currentTimeFunc( ** functions. This should be the only routine in this file with ** external linkage. */ -void sqlite3RegisterDateTimeFunctions(sqlite3 *db){ +void sqlite3RegisterDateTimeFunctions(void){ + static FuncDef aDateTimeFuncs[] = { #ifndef SQLITE_OMIT_DATETIME_FUNCS - static const struct { - char *zName; - int nArg; - void (*xFunc)(sqlite3_context*,int,sqlite3_value**); - } aFuncs[] = { - { "julianday", -1, juliandayFunc }, - { "date", -1, dateFunc }, - { "time", -1, timeFunc }, - { "datetime", -1, datetimeFunc }, - { "strftime", -1, strftimeFunc }, - { "current_time", 0, ctimeFunc }, - { "current_timestamp", 0, ctimestampFunc }, - { "current_date", 0, cdateFunc }, - }; - int i; - - for(i=0; i #include @@ -1222,7 +1219,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){ #ifndef SQLITE_OMIT_PARSER sqlite3AttachFunctions(db); #endif - sqlite3RegisterDateTimeFunctions(db); if( !db->mallocFailed ){ int rc = sqlite3_overload_function(db, "MATCH", 2); assert( rc==SQLITE_NOMEM || rc==SQLITE_OK ); @@ -1301,65 +1297,12 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){ } /* -** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are -** used to create the literal values used for the FuncDef structures in -** the global aBuiltinFunc[] array (see below). +** The following array holds FuncDef structures for all of the functions +** defined in this file. ** -** FUNCTION(zName, nArg, iArg, bNC, xFunc) -** Used to create a scalar function definition of a function zName -** implemented by C function xFunc that accepts nArg arguments. The -** value passed as iArg is cast to a (void*) and made available -** as the user-data (sqlite3_user_data()) for the function. If -** argument bNC is true, then the FuncDef.needCollate flag is set. -** -** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) -** Used to create an aggregate function definition implemented by -** the C functions xStep and xFinal. The first four parameters -** are interpreted in the same way as the first 4 parameters to -** FUNCTION(). -** -** LIKEFUNC(zName, nArg, pArg, flags) -** Used to create a scalar function definition of a function zName -** that accepts nArg arguments and is implemented by a call to C -** function likeFunc. Argument pArg is cast to a (void *) and made -** available as the function user-data (sqlite3_user_data()). The -** FuncDef.flags variable is set to the value passed as the flags -** parameter. -** -** See below for examples. -*/ -#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ - {nArg, SQLITE_UTF8, bNC, 0, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName} - -#define LIKEFUNC(zName, nArg, arg, flags) \ - {nArg, SQLITE_UTF8, 0, flags, (void *)arg, 0, likeFunc, 0, 0, #zName} - -#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ - {nArg, SQLITE_UTF8, nc, 0, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal, #zName} - -#endif - -/* -** This array of FuncDef structures contains most of the "built-in" functions -** and aggregates. Function users (the other routines in the SQL compiler) -** call the following function to access the FuncDef structures stored in -** this array: -** -** int sqlite3GetBuiltinFunction(const char *z, int n, FuncDef **paFunc); -** -** The caller passes the name of the required function and its length -** in parameters z and n, respectively. The value returned is the number -** of FuncDef structures found in the aBuiltinFunc[] array that match -** the requested name. If no match is found, 0 is returned. *paFunc is -** set to point at a static array containing that subset of aBuiltinFunc[] -** before returning. -** -** The implementation of sqlite3GetBuiltinFunction() is generated by -** the program found in tool/mkfunction.c, which is compiled and executed -** as part of the build process. The routine generated by this program -** assumes that if there are two or more entries in the aBuiltinFunc[] -** array with the same name (i.e. two versions of the "max" function), -** then they must be stored in adjacent slots. +** The array cannot be constant since changes are made to the +** FuncDef.pHash elements at start-time. The elements of this array +** are read-only after initialization is complete. */ static FuncDef aBuiltinFunc[] = { FUNCTION(ltrim, 1, 1, 0, trimFunc ), @@ -1423,12 +1366,16 @@ static FuncDef aBuiltinFunc[] = { }; /* -** Build up the global built-in function table at initialization -** time. +** All all of the FuncDef structures in the aBuiltinFunc[] array above +** to the global function hash table. This occurs at start-time (as +** a consequence of calling sqlite3_initialize()). +** +** After this routine runs */ void sqlite3RegisterGlobalFunctions(void){ int i; for(i=0; i @@ -147,7 +147,7 @@ int sqlite3_initialize(void){ sqlite3_mutex_enter(sqlite3Config.pInitMutex); if( sqlite3Config.isInit==0 && inProgress==0 ){ inProgress = 1; - memset(&sqlite3FuncBuiltins, 0, sizeof(sqlite3FuncBuiltins)); + memset(&sqlite3GlobalFunctions, 0, sizeof(sqlite3GlobalFunctions)); sqlite3RegisterGlobalFunctions(); rc = sqlite3_os_init(); if( rc==SQLITE_OK ){ diff --git a/src/pcache.c b/src/pcache.c index 7778212de6..c93acd18b4 100644 --- a/src/pcache.c +++ b/src/pcache.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file implements that page cache. ** -** @(#) $Id: pcache.c,v 1.6 2008/08/21 15:54:01 danielk1977 Exp $ +** @(#) $Id: pcache.c,v 1.7 2008/08/21 20:21:35 drh Exp $ */ #include "sqliteInt.h" @@ -1213,4 +1213,3 @@ int sqlite3PcacheReleaseMemory(int nReq){ return nFree; } #endif /* SQLITE_ENABLE_MEMORY_MANAGEMENT */ - diff --git a/src/pcache.h b/src/pcache.h index f45d644571..805f8183ba 100644 --- a/src/pcache.h +++ b/src/pcache.h @@ -12,7 +12,7 @@ ** This header file defines the interface that the sqlite page cache ** subsystem. ** -** @(#) $Id: pcache.h,v 1.2 2008/08/21 12:19:44 danielk1977 Exp $ +** @(#) $Id: pcache.h,v 1.3 2008/08/21 20:21:35 drh Exp $ */ #ifndef _PCACHE_H_ @@ -174,4 +174,3 @@ void sqlite3PcacheUnlock(PCache *); int sqlite3PcacheReleaseMemory(int); #endif /* _PCACHE_H_ */ - diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 167b21cf46..a6ff8e1d13 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.758 2008/08/21 18:49:28 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.759 2008/08/21 20:21:35 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -784,6 +784,39 @@ struct FuncDef { #define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */ #define SQLITE_FUNC_EPHEM 0x04 /* Ephermeral. Delete with VDBE */ +/* +** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are +** used to create the initializers for the FuncDef structures. +** +** FUNCTION(zName, nArg, iArg, bNC, xFunc) +** Used to create a scalar function definition of a function zName +** implemented by C function xFunc that accepts nArg arguments. The +** value passed as iArg is cast to a (void*) and made available +** as the user-data (sqlite3_user_data()) for the function. If +** argument bNC is true, then the FuncDef.needCollate flag is set. +** +** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) +** Used to create an aggregate function definition implemented by +** the C functions xStep and xFinal. The first four parameters +** are interpreted in the same way as the first 4 parameters to +** FUNCTION(). +** +** LIKEFUNC(zName, nArg, pArg, flags) +** Used to create a scalar function definition of a function zName +** that accepts nArg arguments and is implemented by a call to C +** function likeFunc. Argument pArg is cast to a (void *) and made +** available as the function user-data (sqlite3_user_data()). The +** FuncDef.flags variable is set to the value passed as the flags +** parameter. +*/ +#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ + {nArg, SQLITE_UTF8, bNC, 0, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName} +#define LIKEFUNC(zName, nArg, arg, flags) \ + {nArg, SQLITE_UTF8, 0, flags, (void *)arg, 0, likeFunc, 0, 0, #zName} +#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ + {nArg, SQLITE_UTF8, nc, 0, SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal, #zName} + + /* ** Each SQLite module (virtual table definition) is defined by an ** instance of the following structure, stored in the sqlite3.aModule @@ -2142,7 +2175,7 @@ Select *sqlite3SelectDup(sqlite3*,Select*); void sqlite3FuncDefInsert(FuncDefHash*, FuncDef*); FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,int,u8,int); void sqlite3RegisterBuiltinFunctions(sqlite3*); -void sqlite3RegisterDateTimeFunctions(sqlite3*); +void sqlite3RegisterDateTimeFunctions(void); void sqlite3RegisterGlobalFunctions(void); int sqlite3GetBuiltinFunction(const char *, int, FuncDef **); #ifdef SQLITE_DEBUG @@ -2282,7 +2315,7 @@ void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); #ifndef SQLITE_AMALGAMATION extern const unsigned char sqlite3UpperToLower[]; extern struct Sqlite3Config sqlite3Config; -extern FuncDefHash sqlite3FuncBuiltins; +extern FuncDefHash sqlite3GlobalFunctions; #endif void sqlite3RootPageMoved(Db*, int, int); void sqlite3Reindex(Parse*, Token*, Token*);