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

Side by Side Diff: third_party/sqlite/src/test_wsd.c

Issue 3108030: Move bundled copy of sqlite one level deeper to better separate it... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « third_party/sqlite/src/test_thread.c ('k') | third_party/sqlite/src/tokenize.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 ** 2008 September 1
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
10 **
11 *************************************************************************
12 **
13 ** The code in this file contains sample implementations of the
14 ** sqlite3_wsd_init() and sqlite3_wsd_find() functions required if the
15 ** SQLITE_OMIT_WSD symbol is defined at build time.
16 **
17 ** $Id: test_wsd.c,v 1.4 2009/03/23 04:33:33 danielk1977 Exp $
18 */
19
20 #if defined(SQLITE_OMIT_WSD) && defined(SQLITE_TEST)
21
22 #include "sqliteInt.h"
23
24 #define PLS_HASHSIZE 43
25
26 typedef struct ProcessLocalStorage ProcessLocalStorage;
27 typedef struct ProcessLocalVar ProcessLocalVar;
28
29 struct ProcessLocalStorage {
30 ProcessLocalVar *aData[PLS_HASHSIZE];
31 int nFree;
32 u8 *pFree;
33 };
34
35 struct ProcessLocalVar {
36 void *pKey;
37 ProcessLocalVar *pNext;
38 };
39
40 static ProcessLocalStorage *pGlobal = 0;
41
42 int sqlite3_wsd_init(int N, int J){
43 if( !pGlobal ){
44 int nMalloc = N + sizeof(ProcessLocalStorage) + J*sizeof(ProcessLocalVar);
45 pGlobal = (ProcessLocalStorage *)malloc(nMalloc);
46 if( pGlobal ){
47 memset(pGlobal, 0, sizeof(ProcessLocalStorage));
48 pGlobal->nFree = nMalloc - sizeof(ProcessLocalStorage);
49 pGlobal->pFree = (u8 *)&pGlobal[1];
50 }
51 }
52
53 return pGlobal ? SQLITE_OK : SQLITE_NOMEM;
54 }
55
56 void *sqlite3_wsd_find(void *K, int L){
57 int i;
58 int iHash = 0;
59 ProcessLocalVar *pVar;
60
61 /* Calculate a hash of K */
62 for(i=0; i<sizeof(void*); i++){
63 iHash = (iHash<<3) + ((unsigned char *)&K)[i];
64 }
65 iHash = iHash%PLS_HASHSIZE;
66
67 /* Search the hash table for K. */
68 for(pVar=pGlobal->aData[iHash]; pVar && pVar->pKey!=K; pVar=pVar->pNext);
69
70 /* If no entry for K was found, create and populate a new one. */
71 if( !pVar ){
72 int nByte = ROUND8(sizeof(ProcessLocalVar) + L);
73 assert( pGlobal->nFree>=nByte );
74 pVar = (ProcessLocalVar *)pGlobal->pFree;
75 pVar->pKey = K;
76 pVar->pNext = pGlobal->aData[iHash];
77 pGlobal->aData[iHash] = pVar;
78 pGlobal->nFree -= nByte;
79 pGlobal->pFree += nByte;
80 memcpy(&pVar[1], K, L);
81 }
82
83 return (void *)&pVar[1];
84 }
85
86 #endif
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test_thread.c ('k') | third_party/sqlite/src/tokenize.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698