Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1472)

Side by Side Diff: third_party/sqlite/sqlite-src-3100200/src/loadext.c

Issue 1610543003: [sql] Import reference version of SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2006 June 7 2 ** 2006 June 7
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 16 matching lines...) Expand all
27 ** excluded from a build of SQLite. Substitute a NULL pointer 27 ** excluded from a build of SQLite. Substitute a NULL pointer
28 ** for any missing APIs. 28 ** for any missing APIs.
29 */ 29 */
30 #ifndef SQLITE_ENABLE_COLUMN_METADATA 30 #ifndef SQLITE_ENABLE_COLUMN_METADATA
31 # define sqlite3_column_database_name 0 31 # define sqlite3_column_database_name 0
32 # define sqlite3_column_database_name16 0 32 # define sqlite3_column_database_name16 0
33 # define sqlite3_column_table_name 0 33 # define sqlite3_column_table_name 0
34 # define sqlite3_column_table_name16 0 34 # define sqlite3_column_table_name16 0
35 # define sqlite3_column_origin_name 0 35 # define sqlite3_column_origin_name 0
36 # define sqlite3_column_origin_name16 0 36 # define sqlite3_column_origin_name16 0
37 # define sqlite3_table_column_metadata 0
38 #endif 37 #endif
39 38
40 #ifdef SQLITE_OMIT_AUTHORIZATION 39 #ifdef SQLITE_OMIT_AUTHORIZATION
41 # define sqlite3_set_authorizer 0 40 # define sqlite3_set_authorizer 0
42 #endif 41 #endif
43 42
44 #ifdef SQLITE_OMIT_UTF16 43 #ifdef SQLITE_OMIT_UTF16
45 # define sqlite3_bind_text16 0 44 # define sqlite3_bind_text16 0
46 # define sqlite3_collation_needed16 0 45 # define sqlite3_collation_needed16 0
47 # define sqlite3_column_decltype16 0 46 # define sqlite3_column_decltype16 0
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 sqlite3_bind_blob64, 395 sqlite3_bind_blob64,
397 sqlite3_bind_text64, 396 sqlite3_bind_text64,
398 sqlite3_cancel_auto_extension, 397 sqlite3_cancel_auto_extension,
399 sqlite3_load_extension, 398 sqlite3_load_extension,
400 sqlite3_malloc64, 399 sqlite3_malloc64,
401 sqlite3_msize, 400 sqlite3_msize,
402 sqlite3_realloc64, 401 sqlite3_realloc64,
403 sqlite3_reset_auto_extension, 402 sqlite3_reset_auto_extension,
404 sqlite3_result_blob64, 403 sqlite3_result_blob64,
405 sqlite3_result_text64, 404 sqlite3_result_text64,
406 sqlite3_strglob 405 sqlite3_strglob,
406 /* Version 3.8.11 and later */
407 (sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
408 sqlite3_value_free,
409 sqlite3_result_zeroblob64,
410 sqlite3_bind_zeroblob64,
411 /* Version 3.9.0 and later */
412 sqlite3_value_subtype,
413 sqlite3_result_subtype,
414 /* Version 3.10.0 and later */
415 sqlite3_status64,
416 sqlite3_strlike,
417 sqlite3_db_cacheflush
407 }; 418 };
408 419
409 /* 420 /*
410 ** Attempt to load an SQLite extension library contained in the file 421 ** Attempt to load an SQLite extension library contained in the file
411 ** zFile. The entry point is zProc. zProc may be 0 in which case a 422 ** zFile. The entry point is zProc. zProc may be 0 in which case a
412 ** default entry point name (sqlite3_extension_init) is used. Use 423 ** default entry point name (sqlite3_extension_init) is used. Use
413 ** of the default name is recommended. 424 ** of the default name is recommended.
414 ** 425 **
415 ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong. 426 ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
416 ** 427 **
417 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 428 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
418 ** error message text. The calling function should free this memory 429 ** error message text. The calling function should free this memory
419 ** by calling sqlite3DbFree(db, ). 430 ** by calling sqlite3DbFree(db, ).
420 */ 431 */
421 static int sqlite3LoadExtension( 432 static int sqlite3LoadExtension(
422 sqlite3 *db, /* Load the extension into this database connection */ 433 sqlite3 *db, /* Load the extension into this database connection */
423 const char *zFile, /* Name of the shared library containing extension */ 434 const char *zFile, /* Name of the shared library containing extension */
424 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */ 435 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
425 char **pzErrMsg /* Put error message here if not 0 */ 436 char **pzErrMsg /* Put error message here if not 0 */
426 ){ 437 ){
427 sqlite3_vfs *pVfs = db->pVfs; 438 sqlite3_vfs *pVfs = db->pVfs;
428 void *handle; 439 void *handle;
429 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); 440 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
430 char *zErrmsg = 0; 441 char *zErrmsg = 0;
431 const char *zEntry; 442 const char *zEntry;
432 char *zAltEntry = 0; 443 char *zAltEntry = 0;
433 void **aHandle; 444 void **aHandle;
434 int nMsg = 300 + sqlite3Strlen30(zFile); 445 u64 nMsg = 300 + sqlite3Strlen30(zFile);
435 int ii; 446 int ii;
436 447
437 /* Shared library endings to try if zFile cannot be loaded as written */ 448 /* Shared library endings to try if zFile cannot be loaded as written */
438 static const char *azEndings[] = { 449 static const char *azEndings[] = {
439 #if SQLITE_OS_WIN 450 #if SQLITE_OS_WIN
440 "dll" 451 "dll"
441 #elif defined(__APPLE__) 452 #elif defined(__APPLE__)
442 "dylib" 453 "dylib"
443 #else 454 #else
444 "so" 455 "so"
(...skipping 22 matching lines...) Expand all
467 #if SQLITE_OS_UNIX || SQLITE_OS_WIN 478 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
468 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){ 479 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
469 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]); 480 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
470 if( zAltFile==0 ) return SQLITE_NOMEM; 481 if( zAltFile==0 ) return SQLITE_NOMEM;
471 handle = sqlite3OsDlOpen(pVfs, zAltFile); 482 handle = sqlite3OsDlOpen(pVfs, zAltFile);
472 sqlite3_free(zAltFile); 483 sqlite3_free(zAltFile);
473 } 484 }
474 #endif 485 #endif
475 if( handle==0 ){ 486 if( handle==0 ){
476 if( pzErrMsg ){ 487 if( pzErrMsg ){
477 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); 488 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
478 if( zErrmsg ){ 489 if( zErrmsg ){
479 sqlite3_snprintf(nMsg, zErrmsg, 490 sqlite3_snprintf(nMsg, zErrmsg,
480 "unable to open shared library [%s]", zFile); 491 "unable to open shared library [%s]", zFile);
481 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); 492 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
482 } 493 }
483 } 494 }
484 return SQLITE_ERROR; 495 return SQLITE_ERROR;
485 } 496 }
486 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) 497 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
487 sqlite3OsDlSym(pVfs, handle, zEntry); 498 sqlite3OsDlSym(pVfs, handle, zEntry);
488 499
489 /* If no entry point was specified and the default legacy 500 /* If no entry point was specified and the default legacy
490 ** entry point name "sqlite3_extension_init" was not found, then 501 ** entry point name "sqlite3_extension_init" was not found, then
491 ** construct an entry point name "sqlite3_X_init" where the X is 502 ** construct an entry point name "sqlite3_X_init" where the X is
492 ** replaced by the lowercase value of every ASCII alphabetic 503 ** replaced by the lowercase value of every ASCII alphabetic
493 ** character in the filename after the last "/" upto the first ".", 504 ** character in the filename after the last "/" upto the first ".",
494 ** and eliding the first three characters if they are "lib". 505 ** and eliding the first three characters if they are "lib".
495 ** Examples: 506 ** Examples:
496 ** 507 **
497 ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init 508 ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
498 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init 509 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
499 */ 510 */
500 if( xInit==0 && zProc==0 ){ 511 if( xInit==0 && zProc==0 ){
501 int iFile, iEntry, c; 512 int iFile, iEntry, c;
502 int ncFile = sqlite3Strlen30(zFile); 513 int ncFile = sqlite3Strlen30(zFile);
503 zAltEntry = sqlite3_malloc(ncFile+30); 514 zAltEntry = sqlite3_malloc64(ncFile+30);
504 if( zAltEntry==0 ){ 515 if( zAltEntry==0 ){
505 sqlite3OsDlClose(pVfs, handle); 516 sqlite3OsDlClose(pVfs, handle);
506 return SQLITE_NOMEM; 517 return SQLITE_NOMEM;
507 } 518 }
508 memcpy(zAltEntry, "sqlite3_", 8); 519 memcpy(zAltEntry, "sqlite3_", 8);
509 for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){} 520 for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){}
510 iFile++; 521 iFile++;
511 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3; 522 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
512 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){ 523 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
513 if( sqlite3Isalpha(c) ){ 524 if( sqlite3Isalpha(c) ){
514 zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c]; 525 zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
515 } 526 }
516 } 527 }
517 memcpy(zAltEntry+iEntry, "_init", 6); 528 memcpy(zAltEntry+iEntry, "_init", 6);
518 zEntry = zAltEntry; 529 zEntry = zAltEntry;
519 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) 530 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
520 sqlite3OsDlSym(pVfs, handle, zEntry); 531 sqlite3OsDlSym(pVfs, handle, zEntry);
521 } 532 }
522 if( xInit==0 ){ 533 if( xInit==0 ){
523 if( pzErrMsg ){ 534 if( pzErrMsg ){
524 nMsg += sqlite3Strlen30(zEntry); 535 nMsg += sqlite3Strlen30(zEntry);
525 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); 536 *pzErrMsg = zErrmsg = sqlite3_malloc64(nMsg);
526 if( zErrmsg ){ 537 if( zErrmsg ){
527 sqlite3_snprintf(nMsg, zErrmsg, 538 sqlite3_snprintf(nMsg, zErrmsg,
528 "no entry point [%s] in shared library [%s]", zEntry, zFile); 539 "no entry point [%s] in shared library [%s]", zEntry, zFile);
529 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); 540 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
530 } 541 }
531 } 542 }
532 sqlite3OsDlClose(pVfs, handle); 543 sqlite3OsDlClose(pVfs, handle);
533 sqlite3_free(zAltEntry); 544 sqlite3_free(zAltEntry);
534 return SQLITE_ERROR; 545 return SQLITE_ERROR;
535 } 546 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 625
615 /* 626 /*
616 ** The following object holds the list of automatically loaded 627 ** The following object holds the list of automatically loaded
617 ** extensions. 628 ** extensions.
618 ** 629 **
619 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER 630 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
620 ** mutex must be held while accessing this list. 631 ** mutex must be held while accessing this list.
621 */ 632 */
622 typedef struct sqlite3AutoExtList sqlite3AutoExtList; 633 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
623 static SQLITE_WSD struct sqlite3AutoExtList { 634 static SQLITE_WSD struct sqlite3AutoExtList {
624 int nExt; /* Number of entries in aExt[] */ 635 u32 nExt; /* Number of entries in aExt[] */
625 void (**aExt)(void); /* Pointers to the extension init functions */ 636 void (**aExt)(void); /* Pointers to the extension init functions */
626 } sqlite3Autoext = { 0, 0 }; 637 } sqlite3Autoext = { 0, 0 };
627 638
628 /* The "wsdAutoext" macro will resolve to the autoextension 639 /* The "wsdAutoext" macro will resolve to the autoextension
629 ** state vector. If writable static data is unsupported on the target, 640 ** state vector. If writable static data is unsupported on the target,
630 ** we have to locate the state vector at run-time. In the more common 641 ** we have to locate the state vector at run-time. In the more common
631 ** case where writable static data is supported, wsdStat can refer directly 642 ** case where writable static data is supported, wsdStat can refer directly
632 ** to the "sqlite3Autoext" state vector declared above. 643 ** to the "sqlite3Autoext" state vector declared above.
633 */ 644 */
634 #ifdef SQLITE_OMIT_WSD 645 #ifdef SQLITE_OMIT_WSD
(...skipping 12 matching lines...) Expand all
647 */ 658 */
648 int sqlite3_auto_extension(void (*xInit)(void)){ 659 int sqlite3_auto_extension(void (*xInit)(void)){
649 int rc = SQLITE_OK; 660 int rc = SQLITE_OK;
650 #ifndef SQLITE_OMIT_AUTOINIT 661 #ifndef SQLITE_OMIT_AUTOINIT
651 rc = sqlite3_initialize(); 662 rc = sqlite3_initialize();
652 if( rc ){ 663 if( rc ){
653 return rc; 664 return rc;
654 }else 665 }else
655 #endif 666 #endif
656 { 667 {
657 int i; 668 u32 i;
658 #if SQLITE_THREADSAFE 669 #if SQLITE_THREADSAFE
659 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); 670 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
660 #endif 671 #endif
661 wsdAutoextInit; 672 wsdAutoextInit;
662 sqlite3_mutex_enter(mutex); 673 sqlite3_mutex_enter(mutex);
663 for(i=0; i<wsdAutoext.nExt; i++){ 674 for(i=0; i<wsdAutoext.nExt; i++){
664 if( wsdAutoext.aExt[i]==xInit ) break; 675 if( wsdAutoext.aExt[i]==xInit ) break;
665 } 676 }
666 if( i==wsdAutoext.nExt ){ 677 if( i==wsdAutoext.nExt ){
667 int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]); 678 u64 nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
668 void (**aNew)(void); 679 void (**aNew)(void);
669 aNew = sqlite3_realloc(wsdAutoext.aExt, nByte); 680 aNew = sqlite3_realloc64(wsdAutoext.aExt, nByte);
670 if( aNew==0 ){ 681 if( aNew==0 ){
671 rc = SQLITE_NOMEM; 682 rc = SQLITE_NOMEM;
672 }else{ 683 }else{
673 wsdAutoext.aExt = aNew; 684 wsdAutoext.aExt = aNew;
674 wsdAutoext.aExt[wsdAutoext.nExt] = xInit; 685 wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
675 wsdAutoext.nExt++; 686 wsdAutoext.nExt++;
676 } 687 }
677 } 688 }
678 sqlite3_mutex_leave(mutex); 689 sqlite3_mutex_leave(mutex);
679 assert( (rc&0xff)==rc ); 690 assert( (rc&0xff)==rc );
(...skipping 11 matching lines...) Expand all
691 ** was not on the list. 702 ** was not on the list.
692 */ 703 */
693 int sqlite3_cancel_auto_extension(void (*xInit)(void)){ 704 int sqlite3_cancel_auto_extension(void (*xInit)(void)){
694 #if SQLITE_THREADSAFE 705 #if SQLITE_THREADSAFE
695 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); 706 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
696 #endif 707 #endif
697 int i; 708 int i;
698 int n = 0; 709 int n = 0;
699 wsdAutoextInit; 710 wsdAutoextInit;
700 sqlite3_mutex_enter(mutex); 711 sqlite3_mutex_enter(mutex);
701 for(i=wsdAutoext.nExt-1; i>=0; i--){ 712 for(i=(int)wsdAutoext.nExt-1; i>=0; i--){
702 if( wsdAutoext.aExt[i]==xInit ){ 713 if( wsdAutoext.aExt[i]==xInit ){
703 wsdAutoext.nExt--; 714 wsdAutoext.nExt--;
704 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt]; 715 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
705 n++; 716 n++;
706 break; 717 break;
707 } 718 }
708 } 719 }
709 sqlite3_mutex_leave(mutex); 720 sqlite3_mutex_leave(mutex);
710 return n; 721 return n;
711 } 722 }
(...skipping 17 matching lines...) Expand all
729 sqlite3_mutex_leave(mutex); 740 sqlite3_mutex_leave(mutex);
730 } 741 }
731 } 742 }
732 743
733 /* 744 /*
734 ** Load all automatic extensions. 745 ** Load all automatic extensions.
735 ** 746 **
736 ** If anything goes wrong, set an error in the database connection. 747 ** If anything goes wrong, set an error in the database connection.
737 */ 748 */
738 void sqlite3AutoLoadExtensions(sqlite3 *db){ 749 void sqlite3AutoLoadExtensions(sqlite3 *db){
739 int i; 750 u32 i;
740 int go = 1; 751 int go = 1;
741 int rc; 752 int rc;
742 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); 753 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
743 754
744 wsdAutoextInit; 755 wsdAutoextInit;
745 if( wsdAutoext.nExt==0 ){ 756 if( wsdAutoext.nExt==0 ){
746 /* Common case: early out without every having to acquire a mutex */ 757 /* Common case: early out without every having to acquire a mutex */
747 return; 758 return;
748 } 759 }
749 for(i=0; go; i++){ 760 for(i=0; go; i++){
(...skipping 12 matching lines...) Expand all
762 sqlite3_mutex_leave(mutex); 773 sqlite3_mutex_leave(mutex);
763 zErrmsg = 0; 774 zErrmsg = 0;
764 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){ 775 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
765 sqlite3ErrorWithMsg(db, rc, 776 sqlite3ErrorWithMsg(db, rc,
766 "automatic extension loading failed: %s", zErrmsg); 777 "automatic extension loading failed: %s", zErrmsg);
767 go = 0; 778 go = 0;
768 } 779 }
769 sqlite3_free(zErrmsg); 780 sqlite3_free(zErrmsg);
770 } 781 }
771 } 782 }
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3100200/src/legacy.c ('k') | third_party/sqlite/sqlite-src-3100200/src/main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698