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

Side by Side Diff: third_party/sqlite/patches/0006-Modify-default-VFS-to-support-WebDatabase.patch

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. 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
(Empty)
1 From 25f1f784320aa0e32b69f78098b652b30df40865 Mon Sep 17 00:00:00 2001
2 From: dumi <dumi@chromium.org>
3 Date: Mon, 20 Jul 2009 23:40:51 +0000
4 Subject: [PATCH 06/23] Modify default VFS to support WebDatabase.
5
6 The renderer WebDatabase implementation needs to broker certain requests
7 to the browser. This modifies SQLite to allow monkey-patching the VFS
8 to support this.
9
10 NOTE(shess): This patch relies on core SQLite implementation details
11 remaining unchanged. When importing a new version of SQLite, pay very
12 close attention to whether the change is still doing what is intended.
13
14 Original review URLs:
15 https://codereview.chromium.org/159044
16 https://codereview.chromium.org/384075
17 https://codereview.chromium.org/377039
18 [Possibly not a complete list.]
19 ---
20 third_party/sqlite/src/src/os_unix.c | 98 +++++++++++++++++++++++++++++-------
21 third_party/sqlite/src/src/os_win.c | 7 +++
22 2 files changed, 88 insertions(+), 17 deletions(-)
23
24 diff --git a/third_party/sqlite/src/src/os_unix.c b/third_party/sqlite/src/src/o s_unix.c
25 index 998e353..766b52a 100644
26 --- a/third_party/sqlite/src/src/os_unix.c
27 +++ b/third_party/sqlite/src/src/os_unix.c
28 @@ -4418,9 +4418,16 @@ typedef const sqlite3_io_methods *(*finder_type)(const ch ar*,unixFile*);
29 */
30
31 /*
32 +** Initializes a unixFile structure with zeros.
33 +*/
34 +void initUnixFile(sqlite3_file* file) {
35 + memset(file, 0, sizeof(unixFile));
36 +}
37 +
38 +/*
39 ** Initialize the contents of the unixFile structure pointed to by pId.
40 */
41 -static int fillInUnixFile(
42 +int fillInUnixFile(
43 sqlite3_vfs *pVfs, /* Pointer to vfs object */
44 int h, /* Open file descriptor of file being opened */
45 int dirfd, /* Directory file descriptor */
46 @@ -4834,6 +4841,73 @@ static int findCreateFileMode(
47 }
48
49 /*
50 +** Initializes a unixFile structure with zeros.
51 +*/
52 +void chromium_sqlite3_initialize_unix_sqlite3_file(sqlite3_file* file) {
53 + memset(file, 0, sizeof(unixFile));
54 +}
55 +
56 +int chromium_sqlite3_fill_in_unix_sqlite3_file(sqlite3_vfs* vfs,
57 + int fd,
58 + int dirfd,
59 + sqlite3_file* file,
60 + const char* fileName,
61 + int noLock,
62 + int isDelete) {
63 + return fillInUnixFile(vfs, fd, dirfd, file, fileName, noLock, isDelete, 0);
64 +}
65 +
66 +/*
67 +** Search for an unused file descriptor that was opened on the database file.
68 +** If a suitable file descriptor if found, then it is stored in *fd; otherwise,
69 +** *fd is not modified.
70 +**
71 +** If a reusable file descriptor is not found, and a new UnixUnusedFd cannot
72 +** be allocated, SQLITE_NOMEM is returned. Otherwise, SQLITE_OK is returned.
73 +*/
74 +int chromium_sqlite3_get_reusable_file_handle(sqlite3_file* file,
75 + const char* fileName,
76 + int flags,
77 + int* fd) {
78 + unixFile* unixSQLite3File = (unixFile*)file;
79 + int fileType = flags & 0xFFFFFF00;
80 + if (fileType == SQLITE_OPEN_MAIN_DB) {
81 + UnixUnusedFd *unusedFd = findReusableFd(fileName, flags);
82 + if (unusedFd) {
83 + *fd = unusedFd->fd;
84 + } else {
85 + unusedFd = sqlite3_malloc(sizeof(*unusedFd));
86 + if (!unusedFd) {
87 + return SQLITE_NOMEM;
88 + }
89 + }
90 + unixSQLite3File->pUnused = unusedFd;
91 + }
92 + return SQLITE_OK;
93 +}
94 +
95 +/*
96 +** Marks 'fd' as the unused file descriptor for 'pFile'.
97 +*/
98 +void chromium_sqlite3_update_reusable_file_handle(sqlite3_file* file,
99 + int fd,
100 + int flags) {
101 + unixFile* unixSQLite3File = (unixFile*)file;
102 + if (unixSQLite3File->pUnused) {
103 + unixSQLite3File->pUnused->fd = fd;
104 + unixSQLite3File->pUnused->flags = flags;
105 + }
106 +}
107 +
108 +/*
109 +** Destroys pFile's field that keeps track of the unused file descriptor.
110 +*/
111 +void chromium_sqlite3_destroy_reusable_file_handle(sqlite3_file* file) {
112 + unixFile* unixSQLite3File = (unixFile*)file;
113 + sqlite3_free(unixSQLite3File->pUnused);
114 +}
115 +
116 +/*
117 ** Open the file zPath.
118 **
119 ** Previously, the SQLite OS layer used three functions in place of this
120 @@ -4921,20 +4995,13 @@ static int unixOpen(
121 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
122 );
123
124 - memset(p, 0, sizeof(unixFile));
125 + chromium_sqlite3_initialize_unix_sqlite3_file(pFile);
126
127 if( eType==SQLITE_OPEN_MAIN_DB ){
128 - UnixUnusedFd *pUnused;
129 - pUnused = findReusableFd(zName, flags);
130 - if( pUnused ){
131 - fd = pUnused->fd;
132 - }else{
133 - pUnused = sqlite3_malloc(sizeof(*pUnused));
134 - if( !pUnused ){
135 - return SQLITE_NOMEM;
136 - }
137 + rc = chromium_sqlite3_get_reusable_file_handle(pFile, zName, flags, &fd);
138 + if( rc!=SQLITE_OK ){
139 + return rc;
140 }
141 - p->pUnused = pUnused;
142 }else if( !zName ){
143 /* If zName is NULL, the upper layer is requesting a temp file. */
144 assert(isDelete && !isOpenDirectory);
145 @@ -4984,10 +5051,7 @@ static int unixOpen(
146 *pOutFlags = flags;
147 }
148
149 - if( p->pUnused ){
150 - p->pUnused->fd = fd;
151 - p->pUnused->flags = flags;
152 - }
153 + chromium_sqlite3_update_reusable_file_handle(pFile, fd, flags);
154
155 if( isDelete ){
156 #if OS_VXWORKS
157 @@ -5090,7 +5154,7 @@ static int unixOpen(
158 isDelete, isReadonly);
159 open_finished:
160 if( rc!=SQLITE_OK ){
161 - sqlite3_free(p->pUnused);
162 + chromium_sqlite3_destroy_reusable_file_handle(pFile);
163 }
164 return rc;
165 }
166 diff --git a/third_party/sqlite/src/src/os_win.c b/third_party/sqlite/src/src/os _win.c
167 index c876833..78e58b5 100644
168 --- a/third_party/sqlite/src/src/os_win.c
169 +++ b/third_party/sqlite/src/src/os_win.c
170 @@ -2784,4 +2784,11 @@ int sqlite3_os_end(void){
171 return SQLITE_OK;
172 }
173
174 +void chromium_sqlite3_initialize_win_sqlite3_file(sqlite3_file* file, HANDLE ha ndle) {
175 + winFile* winSQLite3File = (winFile*)file;
176 + memset(file, 0, sizeof(*file));
177 + winSQLite3File->pMethod = &winIoMethod;
178 + winSQLite3File->h = handle;
179 +}
180 +
181 #endif /* SQLITE_OS_WIN */
182 --
183 2.2.1
184
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698