diff --git a/manifest b/manifest index 6ca560a16e..7885389d50 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C add\sall\ssqlite3_\sfunctions\sin\scapi\sreference\sto\sdll\sexports\s(CVS\s1684) -D 2004-06-24T15:09:45 +C Fix\ssigned\sinteger\sproblems\sin\svxprintf.\s\sTicket\s#778.\s\sAlso\sremove\ssome\ndead\scode\sfrom\sutil.c.\s(CVS\s1685) +D 2004-06-25T01:10:48 F Makefile.in cb7a9889c38723f72b2506c4236ff30a05ff172b F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -54,7 +54,7 @@ F src/pager.c ec34fbae1a23228cb3743cf7cd8eba1af8e4cd5c F src/pager.h bc58d32a9dee464f7268fb68652c130a4216e438 F src/parse.y 097438674976355a10cf177bd97326c548820b86 F src/pragma.c 0750e1c360647dbe0a991f16133b0fe5e42e5039 -F src/printf.c b6490067bb19e2c9a9e0eb09dbb205d90ca72899 +F src/printf.c 3090c8ff397d549bc0de09b16d8ab7fd37a0c3f7 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/select.c f02a65af34231031896e8442161cb5251e191e75 F src/shell.c 24b641700c9d90f361fcfa4f432c5b4aff704e6d @@ -62,7 +62,7 @@ F src/sqlite.h.in 1f400a561fca3b1df73677d2d97046425d47cae4 F src/sqliteInt.h dd796b6abc6d50505fe33c54f0143d7000681a41 F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2 F src/tclsqlite.c 8d093146332b2f0cbf2a8ebe8597d481619308a3 -F src/test1.c 2504259e29a250190581aaac73d31e71e155df4b +F src/test1.c fcf1a914c27f50d93a41e0b90890008c3ea28cbc F src/test2.c dafd8bd314a554bf376c6d3a8c83fd69219f5a40 F src/test3.c 7247090d15a5a43823079b6fd8dad1ed3cccdedf F src/test4.c a921a69821fd30209589228e64f94e9f715b6fe2 @@ -71,7 +71,7 @@ F src/tokenize.c 900374b6b37f04748bcd48c2d29a41c251542935 F src/trigger.c 296e888ae931e9774e1761996b2b66db40f7d216 F src/update.c b66b1896c9da54678ba3eff2bf0b4d291a95986a F src/utf.c a8fb39c94ae4ef6606d5216b6f05d9b86f6901b2 -F src/util.c e31e35d3d76cab7a02045095064897eca49cbce3 +F src/util.c 43d0289d49f43c66847ebbeddfb85a2a0d1ddd2d F src/vacuum.c fcb930215a3f6c50087300782555f61ad11dd80c F src/vdbe.c 0d8f2fea386c173997fb8eab555ab999497591fe F src/vdbe.h 2d87155e31e84bb00cdc48cc1ce6987a3a484250 @@ -142,7 +142,7 @@ F test/null.test 64730a1c32955e5cc510b7632fed6b9929a4029a F test/pager.test 059cc5c58d3b5a851343dff8c56cf7286425d03a F test/pager2.test 55469c7c1c1a54d6b32d7b3cc99001e90101a1ce F test/pragma.test e09ac12edbdac81d21ca88084fef376c7667f5b0 -F test/printf.test 31ac25b4f85fbc7fb507be34c6c0731adbefcf80 +F test/printf.test 1eb584b7272d1abdfe117b2ef7cf3376ae8e4e06 F test/progress.test 7542a6ac7894a1b7730c1f9a27f3f8b9388a4d25 x F test/quick.test 4c0b3eabe2e0e606622d63d7d61ef6efb3ce156b F test/quote.test 08f23385c685d3dc7914ec760d492cacea7f6e3d @@ -229,7 +229,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/version3.tcl 563ba3ac02f64da27ab17f3edbe8e56bfd0293fb F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P 6c6a84b5641f676d2bd1791863c1be849fbfbee4 -R 43f46ba6948f2e628c3bf85b1531987c -U dougcurrie -Z 198e3137d2a170c09621256ad6052ddf +P b6ca51e47a6f6551058d529662abe113399b38e9 +R 3468467315cfe0b753d39bdb01a2711a +U drh +Z 8c08c5bad4608b351f6e608cfc6f2f71 diff --git a/manifest.uuid b/manifest.uuid index 69d88ecb46..72c32a5f1e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b6ca51e47a6f6551058d529662abe113399b38e9 \ No newline at end of file +200cd3baf60e6cfad9fa3971834367821456ae30 \ No newline at end of file diff --git a/src/printf.c b/src/printf.c index 40af67e37a..a190a10170 100644 --- a/src/printf.c +++ b/src/printf.c @@ -345,35 +345,27 @@ static int vxprintf( */ switch( xtype ){ case etRADIX: - if( flag_longlong ) longvalue = va_arg(ap,sqlite_int64); - else if( flag_long ) longvalue = va_arg(ap,long int); - else longvalue = va_arg(ap,int); -#if 1 - /* For the format %#x, the value zero is printed "0" not "0x0". - ** I think this is stupid. */ - if( longvalue==0 ) flag_alternateform = 0; -#else - /* More sensible: turn off the prefix for octal (to prevent "00"), - ** but leave the prefix for hex. */ - if( longvalue==0 && infop->base==8 ) flag_alternateform = 0; -#endif if( infop->flags & FLAG_SIGNED ){ - if( flag_longlong ){ - if( *(i64*)&longvalue<0 ){ - longvalue = -*(i64*)&longvalue; - prefix = '-'; - }else if( flag_plussign ) prefix = '+'; - else if( flag_blanksign ) prefix = ' '; - else prefix = 0; + i64 v; + if( flag_longlong ) v = va_arg(ap,i64); + else if( flag_long ) v = va_arg(ap,long int); + else v = va_arg(ap,int); + if( v<0 ){ + longvalue = -v; + prefix = '-'; }else{ - if( *(long*)&longvalue<0 ){ - longvalue = -*(long*)&longvalue; - prefix = '-'; - }else if( flag_plussign ) prefix = '+'; + longvalue = v; + if( flag_plussign ) prefix = '+'; else if( flag_blanksign ) prefix = ' '; else prefix = 0; } - }else prefix = 0; + }else{ + if( flag_longlong ) longvalue = va_arg(ap,u64); + else if( flag_long ) longvalue = va_arg(ap,unsigned long int); + else longvalue = va_arg(ap,unsigned int); + prefix = 0; + } + if( longvalue==0 ) flag_alternateform = 0; if( flag_zeropad && precision -** -** This function is used to test that SQLite selects the correct user -** function callback when multiple versions (for different text encodings) -** are available. -** -** Calling this routine registers up to three versions of the user function -** "test_function" with database handle . If the second argument is -** true, then a version of test_function is registered for UTF-8, if the -** third is true, a version is registered for UTF-16le, if the fourth is -** true, a UTF-16be version is available. Previous versions of -** test_function are deleted. -** -** The user function is implemented by calling the following TCL script: -** -** "test_function " -** -** Where is one of UTF-8, UTF-16LE or UTF16BE, and is the -** single argument passed to the SQL function. The value returned by -** the TCL script is used as the return value of the SQL function. It -** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8 -** for a UTF-16LE test_function(), and UTF-16LE for an implementation that -** prefers UTF-16BE. -*/ -static void test_function_utf8( - sqlite3_context *pCtx, - int nArg, - sqlite3_value **argv -){ - Tcl_Interp *interp; - Tcl_Obj *pX; - sqlite3_value *pVal; - interp = (Tcl_Interp *)sqlite3_user_data(pCtx); - pX = Tcl_NewStringObj("test_function", -1); - Tcl_IncrRefCount(pX); - Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1)); - Tcl_ListObjAppendElement(interp, pX, - Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1)); - Tcl_EvalObjEx(interp, pX, 0); - Tcl_DecrRefCount(pX); - sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT); - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), - SQLITE_UTF8, SQLITE_STATIC); - sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal), - -1, SQLITE_TRANSIENT); - sqlite3ValueFree(pVal); -} -static void test_function_utf16le( - sqlite3_context *pCtx, - int nArg, - sqlite3_value **argv -){ - Tcl_Interp *interp; - Tcl_Obj *pX; - sqlite3_value *pVal; - interp = (Tcl_Interp *)sqlite3_user_data(pCtx); - pX = Tcl_NewStringObj("test_function", -1); - Tcl_IncrRefCount(pX); - Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1)); - Tcl_ListObjAppendElement(interp, pX, - Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1)); - Tcl_EvalObjEx(interp, pX, 0); - Tcl_DecrRefCount(pX); - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), - SQLITE_UTF8, SQLITE_STATIC); - sqlite3_result_text(pCtx,sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT); - sqlite3ValueFree(pVal); -} -static void test_function_utf16be( - sqlite3_context *pCtx, - int nArg, - sqlite3_value **argv -){ - Tcl_Interp *interp; - Tcl_Obj *pX; - sqlite3_value *pVal; - interp = (Tcl_Interp *)sqlite3_user_data(pCtx); - pX = Tcl_NewStringObj("test_function", -1); - Tcl_IncrRefCount(pX); - Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1)); - Tcl_ListObjAppendElement(interp, pX, - Tcl_NewStringObj(sqlite3_value_text(argv[0]), -1)); - Tcl_EvalObjEx(interp, pX, 0); - Tcl_DecrRefCount(pX); - pVal = sqlite3ValueNew(); - sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp), - SQLITE_UTF8, SQLITE_STATIC); - sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal), - -1, SQLITE_TRANSIENT); - sqlite3ValueFree(pVal); -} -static int test_function( - void * clientData, - Tcl_Interp *interp, - int objc, - Tcl_Obj *CONST objv[] -){ - sqlite3 *db; - int val; - - if( objc!=5 ) goto bad_args; - if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; - - if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR; - if( val ){ - sqlite3_create_function(db, "test_function", 1, SQLITE_UTF8, - interp, test_function_utf8, 0, 0); - } - if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR; - if( val ){ - sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16LE, - interp, test_function_utf16le, 0, 0); - } - if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR; - if( val ){ - sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16BE, - interp, test_function_utf16be, 0, 0); - } - - return TCL_OK; -bad_args: - Tcl_AppendResult(interp, "wrong # args: should be \"", - Tcl_GetStringFromObj(objv[0], 0), " ", 0); - return TCL_ERROR; -} - -static int sqlite3_crashparams( +static int sqlite3_crashseed( void * clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[] ){ #ifdef OS_TEST - int delay; - if( objc!=3 ) goto bad_args; - if( Tcl_GetIntFromObj(interp, objv[1], &delay) ) return TCL_ERROR; - sqlite3SetCrashParams(delay, Tcl_GetString(objv[2])); + int seed; + if( objc!=2 ) goto bad_args; + if( Tcl_GetIntFromObj(interp, objv[1], &seed) ) return TCL_ERROR; + sqlite3SetCrashseed(seed); #endif return TCL_OK; #ifdef OS_TEST bad_args: Tcl_AppendResult(interp, "wrong # args: should be \"", - Tcl_GetStringFromObj(objv[0], 0), " ", 0); + Tcl_GetStringFromObj(objv[0], 0), "", 0); return TCL_ERROR; #endif } @@ -2130,6 +2032,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ Tcl_CmdProc *xProc; } aCmd[] = { { "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int }, + { "sqlite3_mprintf_int64", (Tcl_CmdProc*)sqlite3_mprintf_int64 }, { "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str }, { "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double }, { "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled }, @@ -2197,8 +2100,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3OsLock", test_sqlite3OsLock, 0 }, { "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 }, { "add_test_collate", test_collate, 0 }, - { "add_test_function", test_function, 0 }, - { "sqlite3_crashparams", sqlite3_crashparams, 0 }, + { "sqlite3_crashseed", sqlite3_crashseed, 0 }, }; int i; diff --git a/src/util.c b/src/util.c index aaf198bc36..5f934a6bcf 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.106 2004/06/21 08:18:55 danielk1977 Exp $ +** $Id: util.c,v 1.107 2004/06/25 01:10:48 drh Exp $ */ #include "sqliteInt.h" #include @@ -774,152 +774,6 @@ int sqlite3GetInt64(const char *zNum, i64 *pValue){ return 0; } -/* This comparison routine is what we use for comparison operations -** between numeric values in an SQL expression. "Numeric" is a little -** bit misleading here. What we mean is that the strings have a -** type of "numeric" from the point of view of SQL. The strings -** do not necessarily contain numbers. They could contain text. -** -** If the input strings both look like actual numbers then they -** compare in numerical order. Numerical strings are always less -** than non-numeric strings so if one input string looks like a -** number and the other does not, then the one that looks like -** a number is the smaller. Non-numeric strings compare in -** lexigraphical order (the same order as strcmp()). -*/ -int sqlite3Compare(const char *atext, const char *btext){ - int result; - int isNumA, isNumB; - if( atext==0 ){ - return -1; - }else if( btext==0 ){ - return 1; - } - isNumA = sqlite3IsNumber(atext, 0, SQLITE_UTF8); - isNumB = sqlite3IsNumber(btext, 0, SQLITE_UTF8); - if( isNumA ){ - if( !isNumB ){ - result = -1; - }else{ - double rA, rB; - rA = sqlite3AtoF(atext, 0); - rB = sqlite3AtoF(btext, 0); - if( rArB ){ - result = +1; - }else{ - result = 0; - } - } - }else if( isNumB ){ - result = +1; - }else { - result = strcmp(atext, btext); - } - return result; -} - -/* -** This routine is used for sorting. Each key is a list of one or more -** null-terminated elements. The list is terminated by two nulls in -** a row. For example, the following text is a key with three elements -** -** Aone\000Dtwo\000Athree\000\000 -** -** All elements begin with one of the characters "+-AD" and end with "\000" -** with zero or more text elements in between. Except, NULL elements -** consist of the special two-character sequence "N\000". -** -** Both arguments will have the same number of elements. This routine -** returns negative, zero, or positive if the first argument is less -** than, equal to, or greater than the first. (Result is a-b). -** -** Each element begins with one of the characters "+", "-", "A", "D". -** This character determines the sort order and collating sequence: -** -** + Sort numerically in ascending order -** - Sort numerically in descending order -** A Sort as strings in ascending order -** D Sort as strings in descending order. -** -** For the "+" and "-" sorting, pure numeric strings (strings for which the -** isNum() function above returns TRUE) always compare less than strings -** that are not pure numerics. Non-numeric strings compare in memcmp() -** order. This is the same sort order as the sqlite3Compare() function -** above generates. -** -** The last point is a change from version 2.6.3 to version 2.7.0. In -** version 2.6.3 and earlier, substrings of digits compare in numerical -** and case was used only to break a tie. -** -** Elements that begin with 'A' or 'D' compare in memcmp() order regardless -** of whether or not they look like a number. -** -** Note that the sort order imposed by the rules above is the same -** from the ordering defined by the "<", "<=", ">", and ">=" operators -** of expressions and for indices. This was not the case for version -** 2.6.3 and earlier. -*/ -int sqlite3SortCompare(const char *a, const char *b){ - int res = 0; - int isNumA, isNumB; - int dir = 0; - - while( res==0 && *a && *b ){ - if( a[0]=='N' || b[0]=='N' ){ - if( a[0]==b[0] ){ - a += 2; - b += 2; - continue; - } - if( a[0]=='N' ){ - dir = b[0]; - res = -1; - }else{ - dir = a[0]; - res = +1; - } - break; - } - assert( a[0]==b[0] ); - if( (dir=a[0])=='A' || a[0]=='D' ){ - res = strcmp(&a[1],&b[1]); - if( res ) break; - }else{ - isNumA = sqlite3IsNumber(&a[1], 0, SQLITE_UTF8); - isNumB = sqlite3IsNumber(&b[1], 0, SQLITE_UTF8); - if( isNumA ){ - double rA, rB; - if( !isNumB ){ - res = -1; - break; - } - rA = sqlite3AtoF(&a[1], 0); - rB = sqlite3AtoF(&b[1], 0); - if( rArB ){ - res = +1; - break; - } - }else if( isNumB ){ - res = +1; - break; - }else{ - res = strcmp(&a[1],&b[1]); - if( res ) break; - } - } - a += strlen(&a[1]) + 2; - b += strlen(&b[1]) + 2; - } - if( dir=='-' || dir=='D' ) res = -res; - return res; -} - #if 1 /* We are now always UTF-8 */ /* ** X is a pointer to the first byte of a UTF-8 character. Increment diff --git a/test/printf.test b/test/printf.test index 6c09328646..727bf2dbff 100644 --- a/test/printf.test +++ b/test/printf.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the sqlite_*_printf() interface. # -# $Id: printf.test,v 1.9 2004/06/14 23:46:48 danielk1977 Exp $ +# $Id: printf.test,v 1.10 2004/06/25 01:10:48 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -20,22 +20,22 @@ set n 1 foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} { do_test printf-1.$n.1 [subst { sqlite3_mprintf_int {Three integers: %d %x %o} $v $v $v - }] [format {Three integers: %d %lx %lo} $v $v $v] + }] [format {Three integers: %d %x %o} $v $v $v] do_test printf-1.$n.2 [subst { sqlite3_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v - }] [format {Three integers: (%6d) (%6lx) (%6lo)} $v $v $v] + }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v] do_test printf-1.$n.3 [subst { sqlite3_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v - }] [format {Three integers: (%-6d) (%-6lx) (%-6lo)} $v $v $v] + }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v] do_test printf-1.$n.4 [subst { sqlite3_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v - }] [format {Three integers: (%+6d) (%+6lx) (%+6lo)} $v $v $v] + }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v] do_test printf-1.$n.5 [subst { sqlite3_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v - }] [format {Three integers: (%06d) (%06lx) (%06lo)} $v $v $v] + }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v] do_test printf-1.$n.6 [subst { sqlite3_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v - }] [format {Three integers: (% 6d) (% 6lx) (% 6lo)} $v $v $v] + }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v] incr n } @@ -123,4 +123,23 @@ do_test printf-7.3 { sqlite3_mprintf_scaled {A double: %g} 1.0e307 100.0 } {A double: NaN} +do_test printf-8.1 { + sqlite3_mprintf_int {%u %u %u} 0x7fffffff 0x80000000 0xffffffff +} {2147483647 2147483648 4294967295} +do_test printf-8.2 { + sqlite3_mprintf_int {%lu %lu %lu} 0x7fffffff 0x80000000 0xffffffff +} {2147483647 2147483648 4294967295} +do_test printf-8.3 { + sqlite3_mprintf_int64 {%llu %llu %llu} 2147483647 2147483648 4294967296 +} {2147483647 2147483648 4294967296} +do_test printf-8.4 { + sqlite3_mprintf_int64 {%lld %lld %lld} 2147483647 2147483648 4294967296 +} {2147483647 2147483648 4294967296} +do_test printf-8.5 { + sqlite3_mprintf_int64 {%llx %llx %llx} 2147483647 2147483648 4294967296 +} {7fffffff 80000000 100000000} +do_test printf-8.6 { + sqlite3_mprintf_int64 {%llx %llo %lld} -1 -1 -1 +} {ffffffffffffffff 1777777777777777777777 -1} + finish_test