summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authordumi@google.com <dumi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 01:19:55 +0000
committerdumi@google.com <dumi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 01:19:55 +0000
commit80b3fdb134a5c26b5883a741b4c0b90886368abb (patch)
tree35213869515231085f72893424b103b66e18c757 /third_party
parent418ed5ab9cd81a2106893fce7aa121f693c6a98f (diff)
downloadchromium_src-80b3fdb134a5c26b5883a741b4c0b90886368abb.zip
chromium_src-80b3fdb134a5c26b5883a741b4c0b90886368abb.tar.gz
chromium_src-80b3fdb134a5c26b5883a741b4c0b90886368abb.tar.bz2
Change os_unix.c to expose some functions that allows the xDlOpen
method in Chromium's custom Posix VFS implementation to correctly implement the 'unused file descriptors' logic. TEST=none BUG=26041 Review URL: http://codereview.chromium.org/377039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31750 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/sqlite/README.chromium20
-rw-r--r--third_party/sqlite/src/os_unix.c92
2 files changed, 90 insertions, 22 deletions
diff --git a/third_party/sqlite/README.chromium b/third_party/sqlite/README.chromium
index 51a5927..48bdcba 100644
--- a/third_party/sqlite/README.chromium
+++ b/third_party/sqlite/README.chromium
@@ -95,7 +95,7 @@ Chris Evans <cevans@google.com>, Oct 1, 2009
--------------------------------------------
-As of Oct 1, 2009, these are our changes from sqlite_vendor:
+As of Nov 9, 2009, these are our changes from sqlite_vendor:
- A large number of fts2 robustness fixes against corrupt data in its metadata
tables.
@@ -141,6 +141,18 @@ Changes from Chrome:
- Added a new function chromium_sqlite3_initialize_win_sqlite3_file()
at the end of os_win.c. It allows the Windows-specific Chromium VFS
to reuse most of the win32 SQLite VFS.
- - Added a new function initUnixFile() and made fillInUnixFile()
- non-static in os_unix.c. It allows the Linux-specific Chromium VFS
- to reuse most of the unix SQLite VFS.
+ - Added a new function
+ chromium_sqlite3_initialize_unix_sqlite3_file() and made
+ fillInUnixFile() non-static in os_unix.c. It allows the
+ Linux-specific Chromium VFS to reuse most of the unix SQLite VFS.
+ - Exposed three functions that deal with unused file descriptors in
+ os_unix.c, to allow Chromium's Posix VFS implementation in
+ WebKit/WebCore/platform/sql/chromium/SQLiteFileSystemChromiumPosix.cpp
+ to correctly implement the "unused file descriptors" logic in the
+ xDlOpen() method. The new functions are
+ chromium_sqlite3_get_reusable_file_handle(),
+ chromium_sqlite3_update_reusable_file_handle() and
+ chromium_sqlite3_destroy_reusable_file_handle(). Also, added the
+ chromium_sqlite3_fill_in_unix_sqlite3_file() function that calls
+ fillInUnixFile(), which will be made static again as soon as a
+ WebKit patch using the new function lands.
diff --git a/third_party/sqlite/src/os_unix.c b/third_party/sqlite/src/os_unix.c
index caa2070..1eafda1 100644
--- a/third_party/sqlite/src/os_unix.c
+++ b/third_party/sqlite/src/os_unix.c
@@ -3499,10 +3499,26 @@ typedef const sqlite3_io_methods *(*finder_type)(const char*,unixFile*);
/*
** Initializes a unixFile structure with zeros.
*/
-void initUnixFile(sqlite3_file* file) {
+void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file) {
memset(file, 0, sizeof(unixFile));
}
+// TODO(dumi): remove as soon as the WebKit patch is landed
+void initUnixFile(sqlite3_file* file) {
+ chromium_sqlite3_initialize_unix_sqlite3_file(file);
+}
+
+int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs,
+ int fd,
+ int dirfd,
+ sqlite3_file* file,
+ const char* fileName,
+ int noLock,
+ int isDelete) {
+ return fillInUnixFile(vfs, fd, dirfd, file, fileName, noLock, isDelete);
+}
+
+// TODO(dumi): make this function static again as soon as the WebKit patch is landed
/*
** Initialize the contents of the unixFile structure pointed to by pId.
*/
@@ -3820,6 +3836,56 @@ static UnixUnusedFd *findReusableFd(const char *zPath, int flags){
}
/*
+** Search for an unused file descriptor that was opened on the database file.
+** If a suitable file descriptor if found, then it is stored in *fd; otherwise,
+** *fd is not modified.
+**
+** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot
+** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned.
+*/
+int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file,
+ const char* fileName,
+ int flags,
+ int* fd) {
+ unixFile* unixSQLite3File = (unixFile*)file;
+ int fileType = flags & 0xFFFFFF00;
+ if (fileType == SQLITE_OPEN_MAIN_DB) {
+ UnixUnusedFd *unusedFd = findReusableFd(fileName, flags);
+ if (unusedFd) {
+ *fd = unusedFd->fd;
+ } else {
+ unusedFd = sqlite3_malloc(sizeof(*unusedFd));
+ if (!unusedFd) {
+ return SQLITE_NOMEM;
+ }
+ }
+ unixSQLite3File->pUnused = unusedFd;
+ }
+ return SQLITE_OK;
+}
+
+/*
+** Marks 'fd' as the unused file descriptor for 'pFile'.
+*/
+void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file,
+ int fd,
+ int flags) {
+ unixFile* unixSQLite3File = (unixFile*)file;
+ if (unixSQLite3File->pUnused) {
+ unixSQLite3File->pUnused->fd = fd;
+ unixSQLite3File->pUnused->flags = flags;
+ }
+}
+
+/*
+** Destroys pFile's field that keeps track of the unused file descriptor.
+*/
+void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file) {
+ unixFile* unixSQLite3File = (unixFile*)file;
+ sqlite3_free(unixSQLite3File->pUnused);
+}
+
+/*
** Open the file zPath.
**
** Previously, the SQLite OS layer used three functions in place of this
@@ -3901,20 +3967,13 @@ static int unixOpen(
|| eType==SQLITE_OPEN_TRANSIENT_DB
);
- memset(p, 0, sizeof(unixFile));
+ chromium_sqlite3_initialize_unix_sqlite3_file(pFile);
if( eType==SQLITE_OPEN_MAIN_DB ){
- UnixUnusedFd *pUnused;
- pUnused = findReusableFd(zName, flags);
- if( pUnused ){
- fd = pUnused->fd;
- }else{
- pUnused = sqlite3_malloc(sizeof(*pUnused));
- if( !pUnused ){
- return SQLITE_NOMEM;
- }
+ rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd);
+ if( rc!=SQLITE_OK ){
+ return rc;
}
- p->pUnused = pUnused;
}else if( !zName ){
/* If zName is NULL, the upper layer is requesting a temp file. */
assert(isDelete && !isOpenDirectory);
@@ -3957,10 +4016,7 @@ static int unixOpen(
*pOutFlags = flags;
}
- if( p->pUnused ){
- p->pUnused->fd = fd;
- p->pUnused->flags = flags;
- }
+ chromium_sqlite3_update_reusable_file_handle(pFile, fd, flags);
if( isDelete ){
#if OS_VXWORKS
@@ -4032,11 +4088,11 @@ static int unixOpen(
}
}
#endif
-
+
rc = fillInUnixFile(pVfs, fd, dirfd, pFile, zPath, noLock, isDelete);
open_finished:
if( rc!=SQLITE_OK ){
- sqlite3_free(p->pUnused);
+ chromium_sqlite3_destroy_reusable_file_handle(pFile);
}
return rc;
}