From: drh Date: Fri, 30 Jun 2017 23:46:16 +0000 (+0000) Subject: Update the carray() and remember() extension functions so that they user X-Git-Tag: version-3.20.0~62^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3561dd4afe53f07ececf28e4a46f31925f188de8;p=thirdparty%2Fsqlite.git Update the carray() and remember() extension functions so that they user the new sqlite3_value_pointer() interface. FossilOrigin-Name: a99fa94db7185b8eaf3c9b184cb1479f8b3d5781f71f1717a4b3f2dd1d184fe4 --- diff --git a/ext/misc/carray.c b/ext/misc/carray.c index 025eb5db2c..7c12067e5a 100644 --- a/ext/misc/carray.c +++ b/ext/misc/carray.c @@ -73,7 +73,7 @@ typedef struct carray_cursor carray_cursor; struct carray_cursor { sqlite3_vtab_cursor base; /* Base class - must be first */ sqlite3_int64 iRowid; /* The rowid */ - sqlite3_int64 iPtr; /* Pointer to array of values */ + void *pPtr; /* Pointer to the array of values */ sqlite3_int64 iCnt; /* Number of integers in the array */ unsigned char eType; /* One of the CARRAY_type values */ }; @@ -167,7 +167,7 @@ static int carrayColumn( carray_cursor *pCur = (carray_cursor*)cur; sqlite3_int64 x = 0; switch( i ){ - case CARRAY_COLUMN_POINTER: x = pCur->iPtr; break; + case CARRAY_COLUMN_POINTER: return SQLITE_OK; case CARRAY_COLUMN_COUNT: x = pCur->iCnt; break; case CARRAY_COLUMN_CTYPE: { sqlite3_result_text(ctx, azType[pCur->eType], -1, SQLITE_STATIC); @@ -176,22 +176,22 @@ static int carrayColumn( default: { switch( pCur->eType ){ case CARRAY_INT32: { - int *p = (int*)pCur->iPtr; + int *p = (int*)pCur->pPtr; sqlite3_result_int(ctx, p[pCur->iRowid-1]); return SQLITE_OK; } case CARRAY_INT64: { - sqlite3_int64 *p = (sqlite3_int64*)pCur->iPtr; + sqlite3_int64 *p = (sqlite3_int64*)pCur->pPtr; sqlite3_result_int64(ctx, p[pCur->iRowid-1]); return SQLITE_OK; } case CARRAY_DOUBLE: { - double *p = (double*)pCur->iPtr; + double *p = (double*)pCur->pPtr; sqlite3_result_double(ctx, p[pCur->iRowid-1]); return SQLITE_OK; } case CARRAY_TEXT: { - const char **p = (const char**)pCur->iPtr; + const char **p = (const char**)pCur->pPtr; sqlite3_result_text(ctx, p[pCur->iRowid-1], -1, SQLITE_TRANSIENT); return SQLITE_OK; } @@ -232,8 +232,8 @@ static int carrayFilter( ){ carray_cursor *pCur = (carray_cursor *)pVtabCursor; if( idxNum ){ - pCur->iPtr = sqlite3_value_int64(argv[0]); - pCur->iCnt = sqlite3_value_int64(argv[1]); + pCur->pPtr = sqlite3_value_pointer(argv[0]); + pCur->iCnt = pCur->pPtr ? sqlite3_value_int64(argv[1]) : 0; if( idxNum<3 ){ pCur->eType = CARRAY_INT32; }else{ @@ -251,7 +251,7 @@ static int carrayFilter( } } }else{ - pCur->iPtr = 0; + pCur->pPtr = 0; pCur->iCnt = 0; } pCur->iRowid = 1; @@ -345,6 +345,34 @@ static sqlite3_module carrayModule = { 0, /* xRename */ }; +/* +** For testing purpose in the TCL test harness, we need a method for +** setting the pointer value. The inttoptr(X) SQL function accomplishes +** this. Tcl script will bind an integer to X and the inttoptr() SQL +** function will use sqlite3_result_pointer() to convert that integer into +** a pointer. +** +** This is for testing on TCL only. +*/ +#ifdef SQLITE_TEST +static void inttoptrFunc( + sqlite3_context *context, + 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)); + } + sqlite3_result_pointer(context, p); +} +#endif /* SQLITE_TEST */ + #endif /* SQLITE_OMIT_VIRTUALTABLE */ #ifdef _WIN32 @@ -359,6 +387,12 @@ int sqlite3_carray_init( SQLITE_EXTENSION_INIT2(pApi); #ifndef SQLITE_OMIT_VIRTUALTABLE rc = sqlite3_create_module(db, "carray", &carrayModule, 0); -#endif +#ifdef SQLITE_TEST + if( rc==SQLITE_OK ){ + rc = sqlite3_create_function(db, "inttoptr", 1, SQLITE_UTF8, 0, + inttoptrFunc, 0, 0); + } +#endif /* SQLITE_TEST */ +#endif /* SQLITE_OMIT_VIRTUALTABLE */ return rc; } diff --git a/ext/misc/remember.c b/ext/misc/remember.c index aa3eff8a3f..587d44a12c 100644 --- a/ext/misc/remember.c +++ b/ext/misc/remember.c @@ -44,11 +44,11 @@ static void rememberFunc( sqlite3_value **argv ){ sqlite3_int64 v; - sqlite3_int64 ptr; + sqlite3_int64 *ptr; assert( argc==2 ); v = sqlite3_value_int64(argv[0]); - ptr = sqlite3_value_int64(argv[1]); - *((sqlite3_int64*)ptr) = v; + ptr = sqlite3_value_pointer(argv[1]); + if( ptr ) *ptr = v; sqlite3_result_int64(pCtx, v); } diff --git a/manifest b/manifest index 7bacb1143e..9c7fc3fcfe 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sAPIs\sfor\sbinding\spointers\sthat\scan\sbe\sused\sby\sapp-defined\sfunctions. -D 2017-06-30T23:09:03.695 +C Update\sthe\scarray()\sand\sremember()\sextension\sfunctions\sso\sthat\sthey\suser\nthe\snew\ssqlite3_value_pointer()\sinterface. +D 2017-06-30T23:46:16.781 F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 4ebb1d257cac7fb1bcb4ba59278416d410ff1c4bf59447a9c37a415f3516056a @@ -254,7 +254,7 @@ F ext/lsm1/lsm_win32.c 69eb9fd25197432b084037efd69b365d8182ab1e4372a9c45a9c47e54 F ext/misc/README.md 8e008c8d2b02e09096b31dfba033253ac27c6c06a18aa5826e299fa7601d90b2 F ext/misc/amatch.c 6db4607cb17c54b853a2d7c7c36046d004853f65b9b733e6f019d543d5dfae87 F ext/misc/anycollseq.c 5ffdfde9829eeac52219136ad6aa7cd9a4edb3b15f4f2532de52f4a22525eddb -F ext/misc/carray.c 40c27641010a4dc67e3690bdb7c9d36ca58b3c2d +F ext/misc/carray.c 1fbaf9ada5b1919c07a5e76e260a41c13a20fe6d399411e41f1e9cc4a559479f F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704 F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83 F ext/misc/csv.c d91c0388445b08f6e373dd0e8fc024d4551b1fcaf64e876a1c3f4fac8a63adc2 @@ -268,7 +268,7 @@ F ext/misc/memvfs.c e5225bc22e79dde6b28380f3a068ddf600683a33 F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342 F ext/misc/percentile.c 92699c8cd7d517ff610e6037e56506f8904dae2e F ext/misc/regexp.c a68d25c659bd2d893cd1215667bbf75ecb9dc7d4 -F ext/misc/remember.c 8440f8d0b452c5cdefb62b57135ccd1267aa729d +F ext/misc/remember.c bee7963ddfa5b0633f4ac13f01cb471ae712f323a87978c9a9a47108b555598f F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a F ext/misc/scrub.c 1c5bfb8b0cd18b602fcb55755e84abf0023ac2fb F ext/misc/series.c b0f5f346aca9b7ff7caaf0da2efb4ad462441abd4dcd92a460cb573b3ea2370b @@ -1228,7 +1228,7 @@ F test/sync.test 2f84bdbc2b2df1fcb0220575b4b9f8cea94b7529 F test/sync2.test 6be8ed007fa063b147773c1982b5bdba97a32badc536bdc6077eff5cf8710ece F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 -F test/tabfunc01.test 699251cb99651415218a891384510a685c7ab012 +F test/tabfunc01.test c47171c36b3d411df2bd49719dcaa5d034f8d277477fd41d253940723b969a51 F test/table.test b708f3e5fa2542fa51dfab21fc07b36ea445cb2f F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 @@ -1628,10 +1628,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 0db20efe201736b3ebb177948f6a440ce28e62454536a8496fae64a3b55cb702 -R ba965b8e14ab1010e011e2c12b1e3073 -T *branch * bind-pointer -T *sym-bind-pointer * -T -sym-trunk * +P d9f4a831ba957ead3890b36d0e33e30cfa4c79b7de6400e623b9746a0a5a02d0 +R b4c2909e137aa3ef17d38c2e54e31341 U drh -Z 294aa6db3d1ac71c2ec90e0da2e36fa3 +Z 8bdfe5f6d40ad5cfb9816549ee2c5181 diff --git a/manifest.uuid b/manifest.uuid index c596f52ada..3149df671b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d9f4a831ba957ead3890b36d0e33e30cfa4c79b7de6400e623b9746a0a5a02d0 \ No newline at end of file +a99fa94db7185b8eaf3c9b184cb1479f8b3d5781f71f1717a4b3f2dd1d184fe4 \ No newline at end of file diff --git a/test/tabfunc01.test b/test/tabfunc01.test index dcaafa420c..7e6a4b10be 100644 --- a/test/tabfunc01.test +++ b/test/tabfunc01.test @@ -150,62 +150,63 @@ do_execsql_test tabfunc01-600 { do_test tabfunc01-700 { set PTR1 [intarray_addr 5 7 13 17 23] db eval { - SELECT b FROM t600, carray($PTR1,5) WHERE a=value; + SELECT b FROM t600, carray(inttoptr($PTR1),5) WHERE a=value; } } {(005) (007) (013) (017) (023)} do_test tabfunc01-701 { db eval { - SELECT b FROM t600 WHERE a IN carray($PTR1,5,'int32'); + SELECT b FROM t600 WHERE a IN carray(inttoptr($PTR1),5,'int32'); } } {(005) (007) (013) (017) (023)} do_test tabfunc01-702 { db eval { - SELECT b FROM t600 WHERE a IN carray($PTR1,4,'int32'); + SELECT b FROM t600 WHERE a IN carray(inttoptr($PTR1),4,'int32'); } } {(005) (007) (013) (017)} do_catchsql_test tabfunc01-710 { - SELECT b FROM t600 WHERE a IN carray($PTR1,5,'int33'); + SELECT b FROM t600 WHERE a IN carray(inttoptr($PTR1),5,'int33'); } {1 {unknown datatype: 'int33'}} do_test tabfunc01-720 { set PTR2 [int64array_addr 5 7 13 17 23] db eval { - SELECT b FROM t600, carray($PTR2,5,'int64') WHERE a=value; + SELECT b FROM t600, carray(inttoptr($PTR2),5,'int64') WHERE a=value; } } {(005) (007) (013) (017) (023)} do_test tabfunc01-721 { db eval { - SELECT remember(123,$PTR2); - SELECT value FROM carray($PTR2,5,'int64'); + SELECT remember(123,inttoptr($PTR2)); + SELECT value FROM carray(inttoptr($PTR2),5,'int64'); } } {123 123 7 13 17 23} do_test tabfunc01-722 { set PTR3 [expr {$PTR2+16}] db eval { - SELECT remember(987,$PTR3); - SELECT value FROM carray($PTR2,5,'int64'); + SELECT remember(987,inttoptr($PTR3)); + SELECT value FROM carray(inttoptr($PTR2),5,'int64'); } } {987 123 7 987 17 23} do_test tabfunc01-730 { set PTR4 [doublearray_addr 5.0 7.0 13.0 17.0 23.0] db eval { - SELECT b FROM t600, carray($PTR4,5,'double') WHERE a=value; + SELECT b FROM t600, carray(inttoptr($PTR4),5,'double') WHERE a=value; } } {(005) (007) (013) (017) (023)} do_test tabfunc01-740 { set PTR5 [textarray_addr x5 x7 x13 x17 x23] db eval { - SELECT b FROM t600, carray($PTR5,5,'char*') WHERE a=trim(value,'x'); + SELECT b FROM t600, carray(inttoptr($PTR5),5,'char*') + WHERE a=trim(value,'x'); } } {(005) (007) (013) (017) (023)} do_test tabfunc01-750 { db eval { SELECT aa.value, bb.value, '|' - FROM carray($PTR4,5,'double') AS aa - JOIN carray($PTR5,5,'char*') AS bb ON aa.rowid=bb.rowid; + FROM carray(inttoptr($PTR4),5,'double') AS aa + JOIN carray(inttoptr($PTR5),5,'char*') AS bb ON aa.rowid=bb.rowid; } } {5.0 x5 | 7.0 x7 | 13.0 x13 | 17.0 x17 | 23.0 x23 |}