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

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

Issue 883353008: [sql] Import reference version of SQLite 3.8.7.4. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Hold back encoding change which is messing up patch. Created 5 years, 10 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #endif 77 #endif
78 78
79 #ifdef SQLITE_OMIT_PROGRESS_CALLBACK 79 #ifdef SQLITE_OMIT_PROGRESS_CALLBACK
80 # define sqlite3_progress_handler 0 80 # define sqlite3_progress_handler 0
81 #endif 81 #endif
82 82
83 #ifdef SQLITE_OMIT_VIRTUALTABLE 83 #ifdef SQLITE_OMIT_VIRTUALTABLE
84 # define sqlite3_create_module 0 84 # define sqlite3_create_module 0
85 # define sqlite3_create_module_v2 0 85 # define sqlite3_create_module_v2 0
86 # define sqlite3_declare_vtab 0 86 # define sqlite3_declare_vtab 0
87 # define sqlite3_vtab_config 0
88 # define sqlite3_vtab_on_conflict 0
87 #endif 89 #endif
88 90
89 #ifdef SQLITE_OMIT_SHARED_CACHE 91 #ifdef SQLITE_OMIT_SHARED_CACHE
90 # define sqlite3_enable_shared_cache 0 92 # define sqlite3_enable_shared_cache 0
91 #endif 93 #endif
92 94
93 #ifdef SQLITE_OMIT_TRACE 95 #ifdef SQLITE_OMIT_TRACE
94 # define sqlite3_profile 0 96 # define sqlite3_profile 0
95 # define sqlite3_trace 0 97 # define sqlite3_trace 0
96 #endif 98 #endif
97 99
98 #ifdef SQLITE_OMIT_GET_TABLE 100 #ifdef SQLITE_OMIT_GET_TABLE
99 # define sqlite3_free_table 0 101 # define sqlite3_free_table 0
100 # define sqlite3_get_table 0 102 # define sqlite3_get_table 0
101 #endif 103 #endif
102 104
103 #ifdef SQLITE_OMIT_INCRBLOB 105 #ifdef SQLITE_OMIT_INCRBLOB
104 #define sqlite3_bind_zeroblob 0 106 #define sqlite3_bind_zeroblob 0
105 #define sqlite3_blob_bytes 0 107 #define sqlite3_blob_bytes 0
106 #define sqlite3_blob_close 0 108 #define sqlite3_blob_close 0
107 #define sqlite3_blob_open 0 109 #define sqlite3_blob_open 0
108 #define sqlite3_blob_read 0 110 #define sqlite3_blob_read 0
109 #define sqlite3_blob_write 0 111 #define sqlite3_blob_write 0
112 #define sqlite3_blob_reopen 0
110 #endif 113 #endif
111 114
112 /* 115 /*
113 ** The following structure contains pointers to all SQLite API routines. 116 ** The following structure contains pointers to all SQLite API routines.
114 ** A pointer to this structure is passed into extensions when they are 117 ** A pointer to this structure is passed into extensions when they are
115 ** loaded so that the extension can make calls back into the SQLite 118 ** loaded so that the extension can make calls back into the SQLite
116 ** library. 119 ** library.
117 ** 120 **
118 ** When adding new APIs, add them to the bottom of this structure 121 ** When adding new APIs, add them to the bottom of this structure
119 ** in order to preserve backwards compatibility. 122 ** in order to preserve backwards compatibility.
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 #endif 368 #endif
366 #ifndef SQLITE_OMIT_WAL 369 #ifndef SQLITE_OMIT_WAL
367 sqlite3_wal_autocheckpoint, 370 sqlite3_wal_autocheckpoint,
368 sqlite3_wal_checkpoint, 371 sqlite3_wal_checkpoint,
369 sqlite3_wal_hook, 372 sqlite3_wal_hook,
370 #else 373 #else
371 0, 374 0,
372 0, 375 0,
373 0, 376 0,
374 #endif 377 #endif
378 sqlite3_blob_reopen,
379 sqlite3_vtab_config,
380 sqlite3_vtab_on_conflict,
381 sqlite3_close_v2,
382 sqlite3_db_filename,
383 sqlite3_db_readonly,
384 sqlite3_db_release_memory,
385 sqlite3_errstr,
386 sqlite3_stmt_busy,
387 sqlite3_stmt_readonly,
388 sqlite3_stricmp,
389 sqlite3_uri_boolean,
390 sqlite3_uri_int64,
391 sqlite3_uri_parameter,
392 sqlite3_vsnprintf,
393 sqlite3_wal_checkpoint_v2,
394 /* Version 3.8.7 and later */
395 sqlite3_auto_extension,
396 sqlite3_bind_blob64,
397 sqlite3_bind_text64,
398 sqlite3_cancel_auto_extension,
399 sqlite3_load_extension,
400 sqlite3_malloc64,
401 sqlite3_msize,
402 sqlite3_realloc64,
403 sqlite3_reset_auto_extension,
404 sqlite3_result_blob64,
405 sqlite3_result_text64,
406 sqlite3_strglob
375 }; 407 };
376 408
377 /* 409 /*
378 ** Attempt to load an SQLite extension library contained in the file 410 ** Attempt to load an SQLite extension library contained in the file
379 ** zFile. The entry point is zProc. zProc may be 0 in which case a 411 ** zFile. The entry point is zProc. zProc may be 0 in which case a
380 ** default entry point name (sqlite3_extension_init) is used. Use 412 ** default entry point name (sqlite3_extension_init) is used. Use
381 ** of the default name is recommended. 413 ** of the default name is recommended.
382 ** 414 **
383 ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong. 415 ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
384 ** 416 **
385 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 417 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
386 ** error message text. The calling function should free this memory 418 ** error message text. The calling function should free this memory
387 ** by calling sqlite3DbFree(db, ). 419 ** by calling sqlite3DbFree(db, ).
388 */ 420 */
389 static int sqlite3LoadExtension( 421 static int sqlite3LoadExtension(
390 sqlite3 *db, /* Load the extension into this database connection */ 422 sqlite3 *db, /* Load the extension into this database connection */
391 const char *zFile, /* Name of the shared library containing extension */ 423 const char *zFile, /* Name of the shared library containing extension */
392 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */ 424 const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
393 char **pzErrMsg /* Put error message here if not 0 */ 425 char **pzErrMsg /* Put error message here if not 0 */
394 ){ 426 ){
395 sqlite3_vfs *pVfs = db->pVfs; 427 sqlite3_vfs *pVfs = db->pVfs;
396 void *handle; 428 void *handle;
397 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); 429 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
398 char *zErrmsg = 0; 430 char *zErrmsg = 0;
431 const char *zEntry;
432 char *zAltEntry = 0;
399 void **aHandle; 433 void **aHandle;
400 const int nMsg = 300; 434 int nMsg = 300 + sqlite3Strlen30(zFile);
435 int ii;
436
437 /* Shared library endings to try if zFile cannot be loaded as written */
438 static const char *azEndings[] = {
439 #if SQLITE_OS_WIN
440 "dll"
441 #elif defined(__APPLE__)
442 "dylib"
443 #else
444 "so"
445 #endif
446 };
447
401 448
402 if( pzErrMsg ) *pzErrMsg = 0; 449 if( pzErrMsg ) *pzErrMsg = 0;
403 450
404 /* Ticket #1863. To avoid a creating security problems for older 451 /* Ticket #1863. To avoid a creating security problems for older
405 ** applications that relink against newer versions of SQLite, the 452 ** applications that relink against newer versions of SQLite, the
406 ** ability to run load_extension is turned off by default. One 453 ** ability to run load_extension is turned off by default. One
407 ** must call sqlite3_enable_load_extension() to turn on extension 454 ** must call sqlite3_enable_load_extension() to turn on extension
408 ** loading. Otherwise you get the following error. 455 ** loading. Otherwise you get the following error.
409 */ 456 */
410 if( (db->flags & SQLITE_LoadExtension)==0 ){ 457 if( (db->flags & SQLITE_LoadExtension)==0 ){
411 if( pzErrMsg ){ 458 if( pzErrMsg ){
412 *pzErrMsg = sqlite3_mprintf("not authorized"); 459 *pzErrMsg = sqlite3_mprintf("not authorized");
413 } 460 }
414 return SQLITE_ERROR; 461 return SQLITE_ERROR;
415 } 462 }
416 463
417 if( zProc==0 ){ 464 zEntry = zProc ? zProc : "sqlite3_extension_init";
418 zProc = "sqlite3_extension_init";
419 }
420 465
421 handle = sqlite3OsDlOpen(pVfs, zFile); 466 handle = sqlite3OsDlOpen(pVfs, zFile);
467 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
468 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
469 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
470 if( zAltFile==0 ) return SQLITE_NOMEM;
471 handle = sqlite3OsDlOpen(pVfs, zAltFile);
472 sqlite3_free(zAltFile);
473 }
474 #endif
422 if( handle==0 ){ 475 if( handle==0 ){
423 if( pzErrMsg ){ 476 if( pzErrMsg ){
424 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); 477 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
425 if( zErrmsg ){ 478 if( zErrmsg ){
426 sqlite3_snprintf(nMsg, zErrmsg, 479 sqlite3_snprintf(nMsg, zErrmsg,
427 "unable to open shared library [%s]", zFile); 480 "unable to open shared library [%s]", zFile);
428 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); 481 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
429 } 482 }
430 } 483 }
431 return SQLITE_ERROR; 484 return SQLITE_ERROR;
432 } 485 }
433 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) 486 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
434 sqlite3OsDlSym(pVfs, handle, zProc); 487 sqlite3OsDlSym(pVfs, handle, zEntry);
488
489 /* If no entry point was specified and the default legacy
490 ** entry point name "sqlite3_extension_init" was not found, then
491 ** construct an entry point name "sqlite3_X_init" where the X is
492 ** replaced by the lowercase value of every ASCII alphabetic
493 ** character in the filename after the last "/" upto the first ".",
494 ** and eliding the first three characters if they are "lib".
495 ** Examples:
496 **
497 ** /usr/local/lib/libExample5.4.3.so ==> sqlite3_example_init
498 ** C:/lib/mathfuncs.dll ==> sqlite3_mathfuncs_init
499 */
500 if( xInit==0 && zProc==0 ){
501 int iFile, iEntry, c;
502 int ncFile = sqlite3Strlen30(zFile);
503 zAltEntry = sqlite3_malloc(ncFile+30);
504 if( zAltEntry==0 ){
505 sqlite3OsDlClose(pVfs, handle);
506 return SQLITE_NOMEM;
507 }
508 memcpy(zAltEntry, "sqlite3_", 8);
509 for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){}
510 iFile++;
511 if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
512 for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
513 if( sqlite3Isalpha(c) ){
514 zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
515 }
516 }
517 memcpy(zAltEntry+iEntry, "_init", 6);
518 zEntry = zAltEntry;
519 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
520 sqlite3OsDlSym(pVfs, handle, zEntry);
521 }
435 if( xInit==0 ){ 522 if( xInit==0 ){
436 if( pzErrMsg ){ 523 if( pzErrMsg ){
524 nMsg += sqlite3Strlen30(zEntry);
437 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg); 525 *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
438 if( zErrmsg ){ 526 if( zErrmsg ){
439 sqlite3_snprintf(nMsg, zErrmsg, 527 sqlite3_snprintf(nMsg, zErrmsg,
440 "no entry point [%s] in shared library [%s]", zProc,zFile); 528 "no entry point [%s] in shared library [%s]", zEntry, zFile);
441 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg); 529 sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
442 } 530 }
443 sqlite3OsDlClose(pVfs, handle);
444 } 531 }
532 sqlite3OsDlClose(pVfs, handle);
533 sqlite3_free(zAltEntry);
445 return SQLITE_ERROR; 534 return SQLITE_ERROR;
446 }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){ 535 }
536 sqlite3_free(zAltEntry);
537 if( xInit(db, &zErrmsg, &sqlite3Apis) ){
447 if( pzErrMsg ){ 538 if( pzErrMsg ){
448 *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg); 539 *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
449 } 540 }
450 sqlite3_free(zErrmsg); 541 sqlite3_free(zErrmsg);
451 sqlite3OsDlClose(pVfs, handle); 542 sqlite3OsDlClose(pVfs, handle);
452 return SQLITE_ERROR; 543 return SQLITE_ERROR;
453 } 544 }
454 545
455 /* Append the new shared library handle to the db->aExtension array. */ 546 /* Append the new shared library handle to the db->aExtension array. */
456 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1)); 547 aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 wsdAutoext.nExt++; 675 wsdAutoext.nExt++;
585 } 676 }
586 } 677 }
587 sqlite3_mutex_leave(mutex); 678 sqlite3_mutex_leave(mutex);
588 assert( (rc&0xff)==rc ); 679 assert( (rc&0xff)==rc );
589 return rc; 680 return rc;
590 } 681 }
591 } 682 }
592 683
593 /* 684 /*
685 ** Cancel a prior call to sqlite3_auto_extension. Remove xInit from the
686 ** set of routines that is invoked for each new database connection, if it
687 ** is currently on the list. If xInit is not on the list, then this
688 ** routine is a no-op.
689 **
690 ** Return 1 if xInit was found on the list and removed. Return 0 if xInit
691 ** was not on the list.
692 */
693 int sqlite3_cancel_auto_extension(void (*xInit)(void)){
694 #if SQLITE_THREADSAFE
695 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
696 #endif
697 int i;
698 int n = 0;
699 wsdAutoextInit;
700 sqlite3_mutex_enter(mutex);
701 for(i=wsdAutoext.nExt-1; i>=0; i--){
702 if( wsdAutoext.aExt[i]==xInit ){
703 wsdAutoext.nExt--;
704 wsdAutoext.aExt[i] = wsdAutoext.aExt[wsdAutoext.nExt];
705 n++;
706 break;
707 }
708 }
709 sqlite3_mutex_leave(mutex);
710 return n;
711 }
712
713 /*
594 ** Reset the automatic extension loading mechanism. 714 ** Reset the automatic extension loading mechanism.
595 */ 715 */
596 void sqlite3_reset_auto_extension(void){ 716 void sqlite3_reset_auto_extension(void){
597 #ifndef SQLITE_OMIT_AUTOINIT 717 #ifndef SQLITE_OMIT_AUTOINIT
598 if( sqlite3_initialize()==SQLITE_OK ) 718 if( sqlite3_initialize()==SQLITE_OK )
599 #endif 719 #endif
600 { 720 {
601 #if SQLITE_THREADSAFE 721 #if SQLITE_THREADSAFE
602 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); 722 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
603 #endif 723 #endif
604 wsdAutoextInit; 724 wsdAutoextInit;
605 sqlite3_mutex_enter(mutex); 725 sqlite3_mutex_enter(mutex);
606 sqlite3_free(wsdAutoext.aExt); 726 sqlite3_free(wsdAutoext.aExt);
607 wsdAutoext.aExt = 0; 727 wsdAutoext.aExt = 0;
608 wsdAutoext.nExt = 0; 728 wsdAutoext.nExt = 0;
609 sqlite3_mutex_leave(mutex); 729 sqlite3_mutex_leave(mutex);
610 } 730 }
611 } 731 }
612 732
613 /* 733 /*
614 ** Load all automatic extensions. 734 ** Load all automatic extensions.
615 ** 735 **
616 ** If anything goes wrong, set an error in the database connection. 736 ** If anything goes wrong, set an error in the database connection.
617 */ 737 */
618 void sqlite3AutoLoadExtensions(sqlite3 *db){ 738 void sqlite3AutoLoadExtensions(sqlite3 *db){
619 int i; 739 int i;
620 int go = 1; 740 int go = 1;
741 int rc;
621 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); 742 int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
622 743
623 wsdAutoextInit; 744 wsdAutoextInit;
624 if( wsdAutoext.nExt==0 ){ 745 if( wsdAutoext.nExt==0 ){
625 /* Common case: early out without every having to acquire a mutex */ 746 /* Common case: early out without every having to acquire a mutex */
626 return; 747 return;
627 } 748 }
628 for(i=0; go; i++){ 749 for(i=0; go; i++){
629 char *zErrmsg; 750 char *zErrmsg;
630 #if SQLITE_THREADSAFE 751 #if SQLITE_THREADSAFE
631 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); 752 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
632 #endif 753 #endif
633 sqlite3_mutex_enter(mutex); 754 sqlite3_mutex_enter(mutex);
634 if( i>=wsdAutoext.nExt ){ 755 if( i>=wsdAutoext.nExt ){
635 xInit = 0; 756 xInit = 0;
636 go = 0; 757 go = 0;
637 }else{ 758 }else{
638 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*)) 759 xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
639 wsdAutoext.aExt[i]; 760 wsdAutoext.aExt[i];
640 } 761 }
641 sqlite3_mutex_leave(mutex); 762 sqlite3_mutex_leave(mutex);
642 zErrmsg = 0; 763 zErrmsg = 0;
643 if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){ 764 if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
644 sqlite3Error(db, SQLITE_ERROR, 765 sqlite3ErrorWithMsg(db, rc,
645 "automatic extension loading failed: %s", zErrmsg); 766 "automatic extension loading failed: %s", zErrmsg);
646 go = 0; 767 go = 0;
647 } 768 }
648 sqlite3_free(zErrmsg); 769 sqlite3_free(zErrmsg);
649 } 770 }
650 } 771 }
OLDNEW
« no previous file with comments | « third_party/sqlite/sqlite-src-3080704/src/lempar.c ('k') | third_party/sqlite/sqlite-src-3080704/src/main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698