From: dan Date: Thu, 23 Jul 2026 20:04:20 +0000 (+0000) Subject: Change the way pointers are passed between C code and Tcl test scripts. This allows... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6f9ef2245ed01524d27ad903fed4a9e9844c956c;p=thirdparty%2Fsqlite.git Change the way pointers are passed between C code and Tcl test scripts. This allows tests to be run with Fil-C builds. FossilOrigin-Name: ba919ea1d4fe84526a4c844b3f901e5e8b1650dcdee647e4d46da2d33ced1710 --- diff --git a/manifest b/manifest index aa9388367d..29e83f74c6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C CLI\simprovement:\s\sNew\scommand-line\soption\s"--cmdline-edit\sBOOLEAN"\sto\nenable/disable\scommand-line\sediting.\s\sCommand-line\sediting\sis\sdisabled\nby\sdefault\sif\seither\sstdin\sor\sstdout\sis\snot\sa\stty. -D 2026-07-23T12:12:37.978 +C Change\sthe\sway\spointers\sare\spassed\sbetween\sC\scode\sand\sTcl\stest\sscripts.\sThis\sallows\stests\sto\sbe\srun\swith\sFil-C\sbuilds. +D 2026-07-23T20:04:20.962 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -747,15 +747,15 @@ F src/shell.c.in 0df571dd1eae1a15577361902eb5487a072d3290ea94e1e72e757050b641f87 F src/sqlite.h.in 2101a2b494cbc282d0dc1c3f631c4fb83060c52876cc9d7615b091ad66d932b1 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 0efd4723bad9124ea1f581d9f1ea0254ac1c6f3e5fb29e4f3dcf36c72485a456 -F src/sqliteInt.h 2637dcfb389e48068388146940e541da7c90cb799d42effe9f4f3215fa73618c +F src/sqliteInt.h 0ecebadd18de3a6e1df36f64cca5daedd772aa1f152380e80979c14932900fce F src/sqliteLimit.h 7617f2ee673dab382046beba4552283f442cf1a181bb169ac38eb908135dd8da F src/status.c 7565d63a79aa2f326339a24a0461a60096d0bd2bce711fefb50b5c89335f3592 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 -F src/tclsqlite.c fac4e166b90c1e8c4cac76c1339dfb9d94646debda2cdf8026120a7e19a822ff +F src/tclsqlite.c dce1b8217ed34545d8ce04375f22dc05b3f04e124994bd110969d6267480c1b8 F src/tclsqlite.h 614b3780a62522bc9f8f2b9fb22689e8009958e7aa77e572d0f3149050af348a -F src/test1.c b31e8058ed730be6242745c94fe2ae82e076c2b3ad3267e947ffd391f5b87ab3 -F src/test2.c 2b9ab96bba63a1c369d5769390475259ad210f144a877805f2e32e563f9e93c1 -F src/test3.c 432646f581d8af1bb495e58fc98234380250954f5d5535e507fc785eccc3987a +F src/test1.c 35eab319190cb9dda4823d62a38296824de7a3e020207df11207c3df6606f773 +F src/test2.c a61ed01d9264a1db74ab42fbc981fc66165f85d5e3947e92be61a73e79ec4f2d +F src/test3.c e3e5a073c516295ee33d8d7482b6a87b7f2073867478441efc35928ee0eb97a7 F src/test4.c 0ac87fc13cdb334ab3a71823f99b6c32a6bebe5d603cd6a71d84c823d43a25a0 F src/test5.c 38fa635a70a94f2aa8b47ecbab15d821386205d27ad4159c3551ab3ba45efa11 F src/test6.c 9722054d37257459f1b8988e59e7db1dd630bfb291f16b2759764e778a9d1899 @@ -764,7 +764,7 @@ F src/test9.c df9ddc7db6ef1b8cf745866ee229090779728bcbe660c7f297d3127ab21d92af F src/test_autoext.c 14d4bbd3d0bd1eec0f6d16b29e28cf1e2d0b020d454835f0721a5f68121ac10f F src/test_backup.c a2bfd90d2ff2511b8635507bdb30fa9b605ade19c16b533066cae3077f5bdb72 F src/test_bestindex.c d75fad21369d80910238032bcf8d9ca1f2bffda13c1ceec63bfbb7f704448b15 -F src/test_blob.c 77b994e17f2c87055f44fd96c9a206c5a7155bae2cda2769af60c2f3582f962c +F src/test_blob.c 3a946319c1b062a58d249c67be099c3bc1ec52f2e6ba23b1867699f0b8189ac2 F src/test_btree.c 28283787d32b8fa953eb77412ad0de2c9895260e4e5bd5a94b3c7411664f90d5 F src/test_config.c ac3e4e5e3f5d23a3b604f64b98920a18411f9aa38d58ccd1f5be21103237b2e5 F src/test_delete.c d0e8f6dc55cfc98a7c27c057fb88d512260564bf0b611482656c68b8f7f401ed @@ -778,15 +778,15 @@ F src/test_intarray.c 3fcf8ca7bb5c8776ea83f6aa9b66f8df0d1f37a99207b0097c8486f9c1 F src/test_intarray.h 6c3534641108cd1bea517a8e117dcba237081310a29a4c35bd2190caa8972293 F src/test_journal.c a0b9709b2f12b1ec819eea8a1176f283bca6d688a6d4a502bd6fd79786f4e287 F src/test_loadext.c 337056bae59f80b9eb00ba82088b39d0f4fe6dfd -F src/test_malloc.c 55e2b5398f6e184300d91278b8a84768f6a740735adc030411181945d5276da0 +F src/test_malloc.c 8c31c25f1981daeb1552fa2eb725dab0ccede59e4856c35b6030eca24785e8bc F src/test_md5.c 811a45330c9391933360f998156a8907ee29909c828ab83ac05d329942cbea8f F src/test_multiplex.c 82f0aa8eee629b6949782cfab8782ed35a9b56dc80d12877af52147f304d22b8 F src/test_multiplex.h f0ff5b6f4462bfd46dac165d6375b9530d08089b7bcbe75e88e0926110db5363 -F src/test_mutex.c dacae6790956c0d4e705aaed2090227792e291b0496cccd688e9994c1e21f740 +F src/test_mutex.c 1812af07063458b2509cbba644761a4cfcafcb30957429aff8dc8c9753997c60 F src/test_onefile.c f31e52e891c5fef6709b9fcef54ce660648a34172423a9cbdf4cbce3ba0049f4 F src/test_osinst.c 269039d9c0820a02ee928014c30860d57ee757ecda54df42e463d0ca1377b835 F src/test_pcache.c 496da3f7e2ca66aefbc36bbf22138b1eff43ba0dff175c228b760fa020a37bd0 -F src/test_quota.c 5bb44452b9c6c248bb3c82d2466a20915aa6d12801f6c1784b6499aaa04d9811 +F src/test_quota.c fd911442d21e456209474cde240d51ccf8bce215470344764f4749b069d41879 F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d F src/test_rtree.c d844d746a3cc027247318b970025a927f14772339c991f40e7911583ea5ed0d9 F src/test_schema.c b06d3ddc3edc173c143878f3edb869dd200d57d918ae2f38820534f9a5e3d7d9 @@ -1329,7 +1329,7 @@ F test/insert5.test 79f6b6efd0d3db5f4e3ff442300b7d9e7185adb345b29aacc3ea5a9c58ab F test/insertfault.test ac63d14ea3b49c573673a572f4014b9117383a03e497c58f308b5c776e4a7f74 F test/instr.test 67ba309e9697c24a304e98a7c8f372456177dd4e32237d2a305e1e05f7bb79c2 F test/instrfault.test 95e28efade652e6d51ae11b377088fe523a581a07ec428009e152a4dd0e0f44c -F test/intarray.test bb976b0b3df0ebb6a2eddfb61768280440e672beba5460ed49679ea984ccf440 +F test/intarray.test 8e736961513f9d6298587402c03a15aa5fdfd2dc8e4543c30d1678cd38eb7f57 F test/intck01.sql cc67c49bb0dbffd8ede29d3e095ba2b758eaa3907eeeca3fd44048a01c4071d3 F test/interrupt.test ac1ef50ec9ab8e4f0e17c47629f82539d4b22558904e321ed5abea2e6187da7a F test/interrupt2.test 7eaa40a975d950826cd56e6c37f0f0629adfa2d1a8d3333aff0ff7cf86069963 @@ -1594,7 +1594,7 @@ F test/savepoint6.test 48a645a7bb3a59a6fcf06a7364cfe5b655c336760de39068f7c241b0f F test/savepoint7.test 24c69af86d750c80d51cf6500fde9270717f2b6e5658f055b5e75af75d5af179 F test/savepointfault.test f044eac64b59f09746c7020ee261734de82bf9b2 F test/scanstatus.test b249328caf4d317e71058006872b8012598a5fa045b30bf24a81eeff650ab49e -F test/scanstatus2.test d85d17f2b0b4c013dde95232f7beab749f11f0ef847f5ecffb9486d2f5ecf9f9 +F test/scanstatus2.test 7bf3c01a0c4078a25bc1dc4c4dcb005dbd025182bc35265d5faec0879da43b44 F test/schema.test e615575f2d756df4629596523f11d9322384ecf9f980e58c774cff80ff041c33 F test/schema2.test 906408621ea881fdb496d878b1822572a34e32c5 F test/schema3.test 8ed4ae66e082cdd8b1b1f22d8549e1e7a0db4527a8e6ee8b6193053ee1e5c9ce @@ -1718,7 +1718,7 @@ F test/sync.test a619e407ede58a7b6e3e44375328628559fc9695a9c24c47cb5690a866b0031 F test/sync2.test 06152269ed73128782c450c355988fe8dd794d305833af75e1a5e79edd4dae47 F test/syscall.test a067468b43b8cb2305e9f9fe414e5f40c875bb5d2cba5f00b8154396e95fcf37 F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 -F test/tabfunc01.test 23d1f92fbbbaaef4cb3a1ee15fd5b44e70bde1f3ee1a6b9df9ce43b05cf0b630 +F test/tabfunc01.test b2582f73ab1971265e66f3e98b5ff66eb79084d01987978bf3a228ed6f4638ed F test/table.test e87294bf1c80bfd7792142b84ab32ea5beb4f3f71e535d7fb263a6b2068377bf F test/tableapi.test e37c33e6be2276e3a96bb54b00eea7f321277115d10e5b30fdb52a112b432750 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 @@ -1899,7 +1899,7 @@ F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/tpch01.test 4479008f85f6f8f25f7ab2cb305d665752b4727fa28a8df3d8e0ad46520c62ff F test/trace.test a659a9862957f4789e37a92b3bf6d2caf5c86b02cdeefc41e850ae53acf6992a F test/trace2.test f5cb67ad3bc09e0c58e8cca78dfd0b5639259983 -F test/trace3.test 2deeac66359c9f007f0fc9fb6336994a5d68fc1a65129f322a9e9546fd537d0a +F test/trace3.test dfc937a317884667cf292cf099cec7db506441f5d362c38e2b55d82048948cda F test/trans.test 45f6f9ab6f66a7b5744f1caac06b558f95da62501916906cf55586a896f9f439 F test/trans2.test 62bd045bfc7a1c14c5ba83ba64d21ade31583f76 F test/trans3.test 91a100e5412b488e22a655fe423a14c26403ab94 @@ -2217,8 +2217,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P f8c408f66257881937ed18b77e274f71dba2d97dd44546372fa0b0a9629efbd2 -R bad555b624f4fd2230e93ef522552de4 -U drh -Z 924a5276b6b3c8953d98d053fbac0712 +P 675ed9a486fecc734a6aad2e80fd800183c33f72dce1435a193f0e4cf4ede944 +R 039d4cbeaa72e84bb2afb658548c69cd +U dan +Z edd2aa8bdc90ca19c0485db80790b5cb # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 6a72c5b573..bde90fd78c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -675ed9a486fecc734a6aad2e80fd800183c33f72dce1435a193f0e4cf4ede944 +ba919ea1d4fe84526a4c844b3f901e5e8b1650dcdee647e4d46da2d33ced1710 diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 40c9ea3608..9cb06f708a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4920,6 +4920,7 @@ char *sqlite3VMPrintf(sqlite3*,const char*, va_list); #endif #if defined(SQLITE_TEST) void *sqlite3TestTextToPtr(const char*); + const char *sqlite3TestPtrToText(void*); #endif #if defined(SQLITE_DEBUG) diff --git a/src/tclsqlite.c b/src/tclsqlite.c index cd13358012..eb72aa7bae 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -4209,10 +4209,9 @@ deserialize_error: ** most recent sqlite3_stmt in the statement cache. */ if( strcmp(zArg, "-last-stmt-ptr")==0 ){ - char zBuf[100]; - sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", - pDb->stmtList ? pDb->stmtList->pStmt: 0); - Tcl_SetResult(interp, zBuf, TCL_VOLATILE); + extern const char *sqlite3TestPtrToText(void*); + void *ptr = (void*)(pDb->stmtList ? pDb->stmtList->pStmt: 0); + Tcl_SetResult(interp, (char*)sqlite3TestPtrToText(ptr), TCL_VOLATILE); }else #endif /* SQLITE_TEST */ { diff --git a/src/test1.c b/src/test1.c index fbaaac467d..420988d55b 100644 --- a/src/test1.c +++ b/src/test1.c @@ -30,6 +30,81 @@ #include #include + +/* +** Global hash table mapping from string to pointer value. +** +** Sometimes the SQLite Tcl test scripts manipulate pointer values directly +** (e.g. (sqlite3_stmt*) pointers). This used to be accomplished by converting +** the pointer to a string containing hex digits (e.g. using printf("%p")) +** before handing it to a Tcl script, then converting it back to the original +** pointer value when the script passed it to a C routine. But this doesn't +** work for safe compilers like filcc, which does not allow pointers decoded +** from strings or integers to be dereferenced. +** +** To work around this restriction, each time a pointer is to be passed to a +** Tcl script, an entry is added to this hash table, and the string key +** passed to Tcl. Later on, when the string key is passed back to a C +** routine, that routine retrieves the original pointer from this hash table. +** +** There is currently no way to remove elements from this hash table. +*/ +static struct Test1Global { + int isInit; + Tcl_Mutex m; + Tcl_HashTable h; +} g; + +/* +** Convert a pointer to a string, and return a pointer to a buffer containing +** a copy of that string. The buffer belongs to the global hash table and +** should not be disposed of or modified in any way by the caller. +*/ +static const char *testPointerToString(void *pPtr){ + char aKey[64]; + Tcl_HashEntry *pEntry = 0; + int dummy = 0; + const char *zRet = 0; + + if( pPtr==0 ){ + zRet = "0"; + }else{ + Tcl_MutexLock(&g.m); + if( g.isInit==0 ){ + Tcl_InitHashTable(&g.h, TCL_STRING_KEYS); + g.isInit = 1; + } + sprintf(aKey, "ptr:%p", pPtr); + pEntry = Tcl_CreateHashEntry(&g.h, aKey, &dummy); + Tcl_SetHashValue(pEntry, pPtr); + zRet = Tcl_GetHashKey(&g.h, pEntry); + Tcl_MutexUnlock(&g.m); + } + + return zRet; +} + +/* +** Convert a string returned by an earlier call to testPointerToString() +** back to the original pointer. +*/ +static void *testStringToPointer(const char *zStr){ + void *pRet = 0; + + if( zStr[0]!='0' ){ + Tcl_MutexLock(&g.m); + if( g.isInit ){ + Tcl_HashEntry *pEntry = Tcl_FindHashEntry(&g.h, zStr); + if( pEntry ){ + pRet = Tcl_GetHashValue(pEntry); + } + } + Tcl_MutexUnlock(&g.m); + } + + return pRet; +} + /* ** This is a copy of the first part of the SqliteDb structure in ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine @@ -54,26 +129,12 @@ static int testHexToInt(int h){ return h - 'A' + 10; } } + void *sqlite3TestTextToPtr(const char *z){ - void *p; - u64 v; - u32 v2; - if( z[0]=='0' && z[1]=='x' ){ - z += 2; - } - v = 0; - while( *z ){ - v = (v<<4) + testHexToInt(*z); - z++; - } - if( sizeof(p)==sizeof(v) ){ - memcpy(&p, &v, sizeof(p)); - }else{ - assert( sizeof(p)==sizeof(v2) ); - v2 = (u32)v; - memcpy(&p, &v2, sizeof(p)); - } - return p; + return testStringToPointer(z); +} +const char* sqlite3TestPtrToText(void *p){ + return testPointerToString(p); } @@ -90,7 +151,6 @@ static int SQLITE_TCLAPI get_sqlite_pointer( ){ struct SqliteDb *p; Tcl_CmdInfo cmdInfo; - char zBuf[100]; if( objc!=2 ){ Tcl_WrongNumArgs(interp, 1, objv, "SQLITE-CONNECTION"); return TCL_ERROR; @@ -101,8 +161,7 @@ static int SQLITE_TCLAPI get_sqlite_pointer( return TCL_ERROR; } p = (struct SqliteDb*)cmdInfo.objClientData; - sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", p->db); - Tcl_AppendResult(interp, zBuf, NULL); + Tcl_AppendResult(interp, sqlite3TestPtrToText(p->db), NULL); return TCL_OK; } @@ -116,7 +175,7 @@ int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){ p = (struct SqliteDb*)cmdInfo.objClientData; *ppDb = p->db; }else{ - *ppDb = (sqlite3*)sqlite3TestTextToPtr(zA); + *ppDb = (sqlite3*)testStringToPointer(zA); } return TCL_OK; } @@ -126,7 +185,7 @@ int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){ ** Decode a Win32 HANDLE object. */ int getWin32Handle(Tcl_Interp *interp, const char *zA, LPHANDLE phFile){ - *phFile = (HANDLE)sqlite3TestTextToPtr(zA); + *phFile = (HANDLE)testStringToPointer(zA); return TCL_OK; } #endif @@ -167,25 +226,16 @@ static int getStmtPointer( const char *zArg, sqlite3_stmt **ppStmt ){ - *ppStmt = (sqlite3_stmt*)sqlite3TestTextToPtr(zArg); + *ppStmt = (sqlite3_stmt*)testStringToPointer(zArg); return TCL_OK; } /* ** Generate a text representation of a pointer that can be understood ** by the getDbPointer and getVmPointer routines above. -** -** The problem is, on some machines (Solaris) if you do a printf with -** "%p" you cannot turn around and do a scanf with the same "%p" and -** get your pointer back. You have to prepend a "0x" before it will -** work. Or at least that is what is reported to me (drh). But this -** behavior varies from machine to machine. The solution used her is -** to test the string right after it is generated to see if it can be -** understood by scanf, and if not, try prepending an "0x" to see if -** that helps. If nothing works, a fatal error is generated. */ int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p){ - sqlite3_snprintf(100, zPtr, "%p", p); + sqlite3_snprintf(100, zPtr, "%s", testPointerToString(p)); return TCL_OK; } @@ -283,6 +333,10 @@ static int SQLITE_TCLAPI clang_sanitize_address( #endif #ifdef __SANITIZE_ADDRESS__ res = 1; +#endif +#ifdef __PIZLONATOR_WAS_HERE__ + /* Fil-C */ + res = 1; #endif if( res==0 && getenv("OMIT_MISUSE")!=0 ) res = 1; Tcl_SetObjResult(interp, Tcl_NewIntObj(res)); @@ -1073,14 +1127,9 @@ static void inttoptrFunc( int argc, sqlite3_value **argv ){ - void *p; - sqlite3_int64 i64; - i64 = sqlite3_value_int64(argv[0]); - if( sizeof(i64)==sizeof(p) ){ - memcpy(&p, &i64, sizeof(p)); - }else{ - int i32 = i64 & 0xffffffff; - memcpy(&p, &i32, sizeof(p)); + void *p = testStringToPointer((const char*)sqlite3_value_text(argv[0])); + if( argc==2 ){ + p += sqlite3_value_int(argv[1]); } sqlite3_result_pointer(context, p, "carray", 0); } @@ -1198,6 +1247,10 @@ static int SQLITE_TCLAPI test_create_function( rc = sqlite3_create_function(db, "inttoptr", 1, SQLITE_UTF8, 0, inttoptrFunc, 0, 0); } + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "inttoptr", 2, SQLITE_UTF8, 0, + inttoptrFunc, 0, 0); + } #ifndef SQLITE_OMIT_UTF16 /* Use the sqlite3_create_function16() API here. Mainly for fun, but also @@ -2683,7 +2736,7 @@ static int SQLITE_TCLAPI test_snapshot_open( } if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; zName = Tcl_GetString(objv[2]); - pSnapshot = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[3])); + pSnapshot = (sqlite3_snapshot*)testStringToPointer(Tcl_GetString(objv[3])); rc = sqlite3_snapshot_open(db, zName, pSnapshot); if( rc!=SQLITE_OK ){ @@ -2711,7 +2764,7 @@ static int SQLITE_TCLAPI test_snapshot_free( Tcl_WrongNumArgs(interp, 1, objv, "SNAPSHOT"); return TCL_ERROR; } - pSnapshot = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); + pSnapshot = (sqlite3_snapshot*)testStringToPointer(Tcl_GetString(objv[1])); sqlite3_snapshot_free(pSnapshot); return TCL_OK; } @@ -2734,8 +2787,8 @@ static int SQLITE_TCLAPI test_snapshot_cmp( Tcl_WrongNumArgs(interp, 1, objv, "SNAPSHOT1 SNAPSHOT2"); return TCL_ERROR; } - p1 = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[1])); - p2 = (sqlite3_snapshot*)sqlite3TestTextToPtr(Tcl_GetString(objv[2])); + p1 = (sqlite3_snapshot*)testStringToPointer(Tcl_GetString(objv[1])); + p2 = (sqlite3_snapshot*)testStringToPointer(Tcl_GetString(objv[2])); res = sqlite3_snapshot_cmp(p1, p2); Tcl_SetObjResult(interp, Tcl_NewIntObj(res)); return TCL_OK; @@ -3855,7 +3908,7 @@ static int SQLITE_TCLAPI test_intarray_addr( } } } - Tcl_SetObjResult(interp, Tcl_NewWideIntObj((uptr)p)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3TestPtrToText(p), -1)); return TCL_OK; } /* @@ -3891,7 +3944,7 @@ static int SQLITE_TCLAPI test_int64array_addr( p[i] = v; } } - Tcl_SetObjResult(interp, Tcl_NewWideIntObj((uptr)p)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(testPointerToString(p), -1)); return TCL_OK; } /* @@ -3925,7 +3978,7 @@ static int SQLITE_TCLAPI test_doublearray_addr( } } } - Tcl_SetObjResult(interp, Tcl_NewWideIntObj((uptr)p)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(testPointerToString(p), -1)); return TCL_OK; } /* @@ -3958,7 +4011,7 @@ static int SQLITE_TCLAPI test_textarray_addr( } } n = objc-1; - Tcl_SetObjResult(interp, Tcl_NewWideIntObj((uptr)p)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(testPointerToString(p), -1)); return TCL_OK; } @@ -7096,7 +7149,6 @@ static int file_control_win32_get_handle( sqlite3 *db; int rc; HANDLE hFile = NULL; - char z[100]; if( objc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", @@ -7108,8 +7160,7 @@ static int file_control_win32_get_handle( } rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_GET_HANDLE, (void*)&hFile); - sqlite3_snprintf(sizeof(z), z, "%d %p", rc, (void*)hFile); - Tcl_AppendResult(interp, z, (char*)0); + Tcl_AppendResult(interp, sqlite3TestPtrToText((void*)hFile), (char*)0); return TCL_OK; } diff --git a/src/test2.c b/src/test2.c index 9afce7b7af..b3dd295500 100644 --- a/src/test2.c +++ b/src/test2.c @@ -48,7 +48,6 @@ static int SQLITE_TCLAPI pager_open( Pager *pPager; int nPage; int rc; - char zBuf[100]; if( argc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " FILENAME N-PAGE\"", NULL); @@ -65,8 +64,7 @@ static int SQLITE_TCLAPI pager_open( sqlite3PagerSetCachesize(pPager, nPage); pageSize = test_pagesize; sqlite3PagerSetPagesize(pPager, &pageSize, -1); - sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPager); - Tcl_AppendResult(interp, zBuf, NULL); + Tcl_AppendResult(interp, sqlite3TestPtrToText(pPager), NULL); return TCL_OK; } @@ -309,7 +307,6 @@ static int SQLITE_TCLAPI page_get( const char **argv /* Text of each argument */ ){ Pager *pPager; - char zBuf[100]; DbPage *pPage = 0; int pgno; int rc; @@ -328,8 +325,7 @@ static int SQLITE_TCLAPI page_get( Tcl_AppendResult(interp, sqlite3ErrName(rc), NULL); return TCL_ERROR; } - sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage); - Tcl_AppendResult(interp, zBuf, NULL); + Tcl_AppendResult(interp, sqlite3TestPtrToText(pPage), NULL); return TCL_OK; } @@ -346,7 +342,6 @@ static int SQLITE_TCLAPI page_lookup( const char **argv /* Text of each argument */ ){ Pager *pPager; - char zBuf[100]; DbPage *pPage; int pgno; if( argc!=3 ){ @@ -358,8 +353,7 @@ static int SQLITE_TCLAPI page_lookup( if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR; pPage = sqlite3PagerLookup(pPager, pgno); if( pPage ){ - sqlite3_snprintf(sizeof(zBuf),zBuf,"%p",pPage); - Tcl_AppendResult(interp, zBuf, NULL); + Tcl_AppendResult(interp, sqlite3TestPtrToText(pPage), NULL); } return TCL_OK; } diff --git a/src/test3.c b/src/test3.c index 8fbb96a80d..112327abfd 100644 --- a/src/test3.c +++ b/src/test3.c @@ -41,7 +41,6 @@ static int SQLITE_TCLAPI btree_open( ){ Btree *pBt; int rc, nCache; - char zBuf[100]; int n; char *zFilename; if( argc!=3 ){ @@ -70,8 +69,7 @@ static int SQLITE_TCLAPI btree_open( return TCL_ERROR; } sqlite3BtreeSetCacheSize(pBt, nCache); - sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pBt); - Tcl_AppendResult(interp, zBuf, NULL); + Tcl_AppendResult(interp, sqlite3TestPtrToText(pBt), NULL); return TCL_OK; } @@ -205,7 +203,6 @@ static int SQLITE_TCLAPI btree_cursor( BtCursor *pCur; int rc = SQLITE_OK; int wrFlag; - char zBuf[30]; if( argc!=4 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], @@ -233,8 +230,7 @@ static int SQLITE_TCLAPI btree_cursor( Tcl_AppendResult(interp, sqlite3ErrName(rc), NULL); return TCL_ERROR; } - sqlite3_snprintf(sizeof(zBuf), zBuf,"%p", pCur); - Tcl_AppendResult(interp, zBuf, NULL); + Tcl_AppendResult(interp, sqlite3TestPtrToText(pCur), NULL); return SQLITE_OK; } @@ -516,7 +512,6 @@ static int SQLITE_TCLAPI btree_from_db( int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ - char zBuf[100]; Tcl_CmdInfo info; sqlite3 *db; Btree *pBt; @@ -540,8 +535,7 @@ static int SQLITE_TCLAPI btree_from_db( assert( db ); pBt = db->aDb[iDb].pBt; - sqlite3_snprintf(sizeof(zBuf), zBuf, "%p", pBt); - Tcl_SetResult(interp, zBuf, TCL_VOLATILE); + Tcl_SetResult(interp, (char*)sqlite3TestPtrToText(pBt), TCL_VOLATILE); return TCL_OK; } diff --git a/src/test_blob.c b/src/test_blob.c index ae5a734179..89e52ab6ef 100644 --- a/src/test_blob.c +++ b/src/test_blob.c @@ -25,17 +25,6 @@ extern const char *sqlite3ErrName(int); extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb); extern void *sqlite3TestTextToPtr(const char *z); -/* -** Return a pointer to a buffer containing a text representation of the -** pointer passed as the only argument. The original pointer may be extracted -** from the text using sqlite3TestTextToPtr(). -*/ -static char *ptrToText(void *p){ - static char buf[100]; - sqlite3_snprintf(sizeof(buf)-1, buf, "%p", p); - return buf; -} - /* ** Attempt to extract a blob handle (type sqlite3_blob*) from the Tcl ** object passed as the second argument. If successful, set *ppBlob to @@ -128,7 +117,7 @@ static int SQLITE_TCLAPI test_blob_open( if( nVarname>0 ){ rc = sqlite3_blob_open(db, zDb, zTable, zColumn, iRowid, flags, &pBlob); - Tcl_SetVar(interp, zVarname, ptrToText(pBlob), 0); + Tcl_SetVar(interp, zVarname, sqlite3TestPtrToText(pBlob), 0); }else{ rc = sqlite3_blob_open(db, zDb, zTable, zColumn, iRowid, flags, 0); } diff --git a/src/test_malloc.c b/src/test_malloc.c index 68b2c367da..20b7d07302 100644 --- a/src/test_malloc.c +++ b/src/test_malloc.c @@ -235,56 +235,11 @@ extern const char *sqlite3ErrName(int); ** Transform pointers to text and back again */ static void pointerToText(void *p, char *z){ - static const char zHex[] = "0123456789abcdef"; - int i, k; - unsigned int u; - sqlite3_uint64 n; - if( p==0 ){ - strcpy(z, "0"); - return; - } - if( sizeof(n)==sizeof(p) ){ - memcpy(&n, &p, sizeof(p)); - }else if( sizeof(u)==sizeof(p) ){ - memcpy(&u, &p, sizeof(u)); - n = u; - }else{ - assert( 0 ); - } - for(i=0, k=sizeof(p)*2-1; i>= 4; - } - z[sizeof(p)*2] = 0; -} -static int hexToInt(int h){ - if( h>='0' && h<='9' ){ - return h - '0'; - }else if( h>='a' && h<='f' ){ - return h - 'a' + 10; - }else{ - return -1; - } + const char *zRet = sqlite3TestPtrToText(p); + sprintf(z, "%s", zRet); } static int textToPointer(const char *z, void **pp){ - sqlite3_uint64 n = 0; - int i; - unsigned int u; - for(i=0; i