/ Check-in [e059152a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Change the xSetSyscall methods of the VFS so that they do not cast object pointers into function pointers. Fix other unrelated compiler warnings.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e059152adce3a8fb693f082b82b5669a238c8d6f
User & Date: drh 2011-03-23 22:02:23
Context
2011-03-23
22:51
Update the test_vfstrace.c shim to conform to the new VFS interface for xSetSystemCall and xGetSystemCall. check-in: ad4dc7b9 user: drh tags: trunk
22:48
Merge in all the latest changes from the trunk, and especially the interface changes to the SystemCall methods of the VFS. check-in: 9c3a6e47 user: drh tags: sessions
22:02
Change the xSetSyscall methods of the VFS so that they do not cast object pointers into function pointers. Fix other unrelated compiler warnings. check-in: e059152a user: drh tags: trunk
18:22
Increase the upper bound on SQLITE_MAX_ATTACHED from 30 to 62. check-in: 7aaf8772 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

   525    525         static const struct {
   526    526           int op;      /* The opcode */
   527    527           u32 mask;    /* Mask of the bit in sqlite3.flags to set/clear */
   528    528         } aFlagOp[] = {
   529    529           { SQLITE_DBCONFIG_ENABLE_FKEY,    SQLITE_ForeignKeys    },
   530    530           { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger  },
   531    531         };
   532         -      int i;
          532  +      unsigned int i;
   533    533         rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
   534    534         for(i=0; i<ArraySize(aFlagOp); i++){
   535    535           if( aFlagOp[i].op==op ){
   536    536             int onoff = va_arg(ap, int);
   537    537             int *pRes = va_arg(ap, int*);
   538    538             u32 oldFlags = db->flags;
   539    539             if( onoff>0 ){

Changes to src/os_unix.c.

   284    284   /*
   285    285   ** Many system calls are accessed through pointer-to-functions so that
   286    286   ** they may be overridden at runtime to facilitate fault injection during
   287    287   ** testing and sandboxing.  The following array holds the names and pointers
   288    288   ** to all overrideable system calls.
   289    289   */
   290    290   static struct unix_syscall {
   291         -  const char *zName;      /* Name of the sytem call */
   292         -  void *pCurrent;         /* Current value of the system call */
   293         -  void *pDefault;         /* Default value */
          291  +  const char *zName;            /* Name of the sytem call */
          292  +  sqlite3_syscall_ptr pCurrent; /* Current value of the system call */
          293  +  sqlite3_syscall_ptr pDefault; /* Default value */
   294    294   } aSyscall[] = {
   295         -  { "open",         (void*)open,       0  },
          295  +  { "open",         (sqlite3_syscall_ptr)open,       0  },
   296    296   #define osOpen      ((int(*)(const char*,int,int))aSyscall[0].pCurrent)
   297    297   
   298         -  { "close",        (void*)close,      0  },
          298  +  { "close",        (sqlite3_syscall_ptr)close,      0  },
   299    299   #define osClose     ((int(*)(int))aSyscall[1].pCurrent)
   300    300   
   301         -  { "access",       (void*)access,     0  },
          301  +  { "access",       (sqlite3_syscall_ptr)access,     0  },
   302    302   #define osAccess    ((int(*)(const char*,int))aSyscall[2].pCurrent)
   303    303   
   304         -  { "getcwd",       (void*)getcwd,     0  },
          304  +  { "getcwd",       (sqlite3_syscall_ptr)getcwd,     0  },
   305    305   #define osGetcwd    ((char*(*)(char*,size_t))aSyscall[3].pCurrent)
   306    306   
   307         -  { "stat",         (void*)stat,       0  },
          307  +  { "stat",         (sqlite3_syscall_ptr)stat,       0  },
   308    308   #define osStat      ((int(*)(const char*,struct stat*))aSyscall[4].pCurrent)
   309    309   
   310    310   /*
   311    311   ** The DJGPP compiler environment looks mostly like Unix, but it
   312    312   ** lacks the fcntl() system call.  So redefine fcntl() to be something
   313    313   ** that always succeeds.  This means that locking does not occur under
   314    314   ** DJGPP.  But it is DOS - what did you expect?
   315    315   */
   316    316   #ifdef __DJGPP__
   317    317     { "fstat",        0,                 0  },
   318    318   #define osFstat(a,b,c)    0
   319    319   #else     
   320         -  { "fstat",        (void*)fstat,      0  },
          320  +  { "fstat",        (sqlite3_syscall_ptr)fstat,      0  },
   321    321   #define osFstat     ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
   322    322   #endif
   323    323   
   324         -  { "ftruncate",    (void*)ftruncate,  0  },
          324  +  { "ftruncate",    (sqlite3_syscall_ptr)ftruncate,  0  },
   325    325   #define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent)
   326    326   
   327         -  { "fcntl",        (void*)fcntl,      0  },
          327  +  { "fcntl",        (sqlite3_syscall_ptr)fcntl,      0  },
   328    328   #define osFcntl     ((int(*)(int,int,...))aSyscall[7].pCurrent)
   329    329   
   330         -  { "read",         (void*)read,       0  },
          330  +  { "read",         (sqlite3_syscall_ptr)read,       0  },
   331    331   #define osRead      ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
   332    332   
   333    333   #if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
   334         -  { "pread",        (void*)pread,      0  },
          334  +  { "pread",        (sqlite3_syscall_ptr)pread,      0  },
   335    335   #else
   336         -  { "pread",        (void*)0,          0  },
          336  +  { "pread",        (sqlite3_syscall_ptr)0,          0  },
   337    337   #endif
   338    338   #define osPread     ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
   339    339   
   340    340   #if defined(USE_PREAD64)
   341         -  { "pread64",      (void*)pread64,    0  },
          341  +  { "pread64",      (sqlite3_syscall_ptr)pread64,    0  },
   342    342   #else
   343         -  { "pread64",      (void*)0,          0  },
          343  +  { "pread64",      (sqlite3_syscall_ptr)0,          0  },
   344    344   #endif
   345    345   #define osPread64   ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
   346    346   
   347         -  { "write",        (void*)write,      0  },
          347  +  { "write",        (sqlite3_syscall_ptr)write,      0  },
   348    348   #define osWrite     ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
   349    349   
   350    350   #if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
   351         -  { "pwrite",       (void*)pwrite,     0  },
          351  +  { "pwrite",       (sqlite3_syscall_ptr)pwrite,     0  },
   352    352   #else
   353         -  { "pwrite",       (void*)0,          0  },
          353  +  { "pwrite",       (sqlite3_syscall_ptr)0,          0  },
   354    354   #endif
   355    355   #define osPwrite    ((ssize_t(*)(int,const void*,size_t,off_t))\
   356    356                       aSyscall[12].pCurrent)
   357    357   
   358    358   #if defined(USE_PREAD64)
   359         -  { "pwrite64",     (void*)pwrite64,   0  },
          359  +  { "pwrite64",     (sqlite3_syscall_ptr)pwrite64,   0  },
   360    360   #else
   361         -  { "pwrite64",     (void*)0,          0  },
          361  +  { "pwrite64",     (sqlite3_syscall_ptr)0,          0  },
   362    362   #endif
   363    363   #define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off_t))\
   364    364                       aSyscall[13].pCurrent)
   365    365   
   366         -  { "fchmod",       (void*)fchmod,     0  },
          366  +  { "fchmod",       (sqlite3_syscall_ptr)fchmod,     0  },
   367    367   #define osFchmod    ((int(*)(int,mode_t))aSyscall[14].pCurrent)
   368    368   
   369    369   #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
   370         -  { "fallocate",    (void*)posix_fallocate,  0 },
          370  +  { "fallocate",    (sqlite3_syscall_ptr)posix_fallocate,  0 },
   371    371   #else
   372         -  { "fallocate",    (void*)0,                0 },
          372  +  { "fallocate",    (sqlite3_syscall_ptr)0,                0 },
   373    373   #endif
   374    374   #define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent)
   375    375   
   376    376   }; /* End of the overrideable system calls */
   377    377   
   378    378   /*
   379    379   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
   380    380   ** "unix" VFSes.  Return SQLITE_OK opon successfully updating the
   381    381   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
   382    382   ** system call named zName.
   383    383   */
   384    384   static int unixSetSystemCall(
   385         -  sqlite3_vfs *pNotUsed,     /* The VFS pointer.  Not used */
   386         -  const char *zName,         /* Name of system call to override */
   387         -  void *pNewFunc             /* Pointer to new system call value */
          385  +  sqlite3_vfs *pNotUsed,        /* The VFS pointer.  Not used */
          386  +  const char *zName,            /* Name of system call to override */
          387  +  sqlite3_syscall_ptr pNewFunc  /* Pointer to new system call value */
   388    388   ){
   389         -  int i;
          389  +  unsigned int i;
   390    390     int rc = SQLITE_NOTFOUND;
          391  +
          392  +  UNUSED_PARAMETER(pNotUsed);
   391    393     if( zName==0 ){
   392    394       /* If no zName is given, restore all system calls to their default
   393    395       ** settings and return NULL
   394    396       */
   395    397       for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
   396    398         if( aSyscall[i].pDefault ){
   397    399           aSyscall[i].pCurrent = aSyscall[i].pDefault;
................................................................................
   418    420   }
   419    421   
   420    422   /*
   421    423   ** Return the value of a system call.  Return NULL if zName is not a
   422    424   ** recognized system call name.  NULL is also returned if the system call
   423    425   ** is currently undefined.
   424    426   */
   425         -static void *unixGetSystemCall(sqlite3_vfs *pNotUsed, const char *zName){
   426         -  int i;
          427  +static sqlite3_syscall_ptr unixGetSystemCall(
          428  +  sqlite3_vfs *pNotUsed,
          429  +  const char *zName
          430  +){
          431  +  unsigned int i;
          432  +
          433  +  UNUSED_PARAMETER(pNotUsed);
   427    434     for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0]); i++){
   428    435       if( strcmp(zName, aSyscall[i].zName)==0 ) return aSyscall[i].pCurrent;
   429    436     }
   430    437     return 0;
   431    438   }
   432    439   
   433    440   /*
   434    441   ** Return the name of the first system call after zName.  If zName==NULL
   435    442   ** then return the name of the first system call.  Return NULL if zName
   436    443   ** is the last system call or if zName is not the name of a valid
   437    444   ** system call.
   438    445   */
   439    446   static const char *unixNextSystemCall(sqlite3_vfs *p, const char *zName){
   440         -  int i;
          447  +  unsigned int i;
          448  +
          449  +  UNUSED_PARAMETER(p);
   441    450     if( zName==0 ){
   442    451       i = -1;
   443    452     }else{
   444    453       for(i=0; i<sizeof(aSyscall)/sizeof(aSyscall[0])-1; i++){
   445    454         if( strcmp(zName, aSyscall[0].zName)==0 ) break;
   446    455       }
   447    456     }

Changes to src/sqlite.h.in.

   903    903   ** varies from one VFS to another, and from one version of the same VFS to the
   904    904   ** next.  Applications that use these interfaces must be prepared for any
   905    905   ** or all of these interfaces to be NULL or for their behavior to change
   906    906   ** from one release to the next.  Applications must not attempt to access
   907    907   ** any of these methods if the iVersion of the VFS is less than 3.
   908    908   */
   909    909   typedef struct sqlite3_vfs sqlite3_vfs;
          910  +typedef void (*sqlite3_syscall_ptr)(void);
   910    911   struct sqlite3_vfs {
   911    912     int iVersion;            /* Structure version number (currently 3) */
   912    913     int szOsFile;            /* Size of subclassed sqlite3_file */
   913    914     int mxPathname;          /* Maximum file pathname length */
   914    915     sqlite3_vfs *pNext;      /* Next registered VFS */
   915    916     const char *zName;       /* Name of this virtual file system */
   916    917     void *pAppData;          /* Pointer to application-specific data */
................................................................................
   932    933     ** definition.  Those that follow are added in version 2 or later
   933    934     */
   934    935     int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
   935    936     /*
   936    937     ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
   937    938     ** Those below are for version 3 and greater.
   938    939     */
   939         -  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, void *pFunc);
   940         -  void *(*xGetSystemCall)(sqlite3_vfs*, const char *zName);
          940  +  int (*xSetSystemCall)(sqlite3_vfs*, const char *zName, sqlite3_syscall_ptr);
          941  +  sqlite3_syscall_ptr (*xGetSystemCall)(sqlite3_vfs*, const char *zName);
   941    942     const char *(*xNextSystemCall)(sqlite3_vfs*, const char *zName);
   942    943     /*
   943    944     ** The methods above are in versions 1 through 3 of the sqlite_vfs object.
   944    945     ** New fields may be appended in figure versions.  The iVersion
   945    946     ** value will increment whenever this happens. 
   946    947     */
   947    948   };