SQLite

Check-in [a2f375fffb]
Login

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

Overview
Comment:Patch to mkfunction to try and detect miscompiles. Add an unimportant assert back to pcache.c. (CVS 5577)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a2f375fffb49b6f6adbfd59d24e9c6a170fd5ebb
User & Date: drh 2008-08-21 12:32:12.000
Context
2008-08-21
14:15
Reinsert an SCopy operation that was removed in (5523) because coverage testing indicated that it was dead code. Ticket #3324 shows that the code was not as dead as we thought it was. (CVS 5578) (check-in: 6855711595 user: drh tags: trunk)
12:32
Patch to mkfunction to try and detect miscompiles. Add an unimportant assert back to pcache.c. (CVS 5577) (check-in: a2f375fffb user: drh tags: trunk)
12:19
Fix the functionality associated with sqlite3_release_memory() and sqlite3_soft_heap_limit(). It is automatically disabled if the SQLITE_CONFIG_PAGECACHE option is used. (CVS 5576) (check-in: d025866b09 user: danielk1977 tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pcache.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2008 August 05
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements that page cache.
**
** @(#) $Id: pcache.c,v 1.4 2008/08/21 12:19:44 danielk1977 Exp $
*/
#include "sqliteInt.h"

/*
** A complete page cache is an instance of this structure.
*/
struct PCache {













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2008 August 05
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file implements that page cache.
**
** @(#) $Id: pcache.c,v 1.5 2008/08/21 12:32:12 drh Exp $
*/
#include "sqliteInt.h"

/*
** A complete page cache is an instance of this structure.
*/
struct PCache {
1054
1055
1056
1057
1058
1059
1060

1061
1062
1063
1064
1065
1066
1067

1068
1069
1070
1071
1072
1073
1074
** This is used by the pager module to implement the xStress callback.
*/
PgHdr *sqlite3PcacheDirtyPage(PCache *pCache){
  PgHdr *p = 0;
#if 1
  PgHdr *pIter;
  Pgno min_pgno;

  for(pIter=pCache->pDirty; pIter; pIter=pIter->pNext){
    if( pIter->nRef==0 && (p==0 || pIter->pgno<min_pgno) ){
      p = pIter;
      min_pgno = pIter->pgno;
    }
  }
#else

  for(p=pCache->pDirty; p && p->nRef; p=p->pNext);
#endif
  assert( pCache->iInUseMM );
  if( p ){
    p->pDirty = 0;
  }
  return p;







>







>







1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
** This is used by the pager module to implement the xStress callback.
*/
PgHdr *sqlite3PcacheDirtyPage(PCache *pCache){
  PgHdr *p = 0;
#if 1
  PgHdr *pIter;
  Pgno min_pgno;
  assert( pCache->iInUseMM );
  for(pIter=pCache->pDirty; pIter; pIter=pIter->pNext){
    if( pIter->nRef==0 && (p==0 || pIter->pgno<min_pgno) ){
      p = pIter;
      min_pgno = pIter->pgno;
    }
  }
#else
  assert( pCache->iInUseMM );
  for(p=pCache->pDirty; p && p->nRef; p=p->pNext);
#endif
  assert( pCache->iInUseMM );
  if( p ){
    p->pDirty = 0;
  }
  return p;
Changes to tool/mkfunction.c.
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
static void printarray(const char *zName, u8 *aArray, int nArray){
  int ii;
  printf("  static u8 %s[%d] = {", zName, nArray);
  for(ii=0; ii<nArray; ii++){
    if( (ii%16)==0 ){
      printf("\n    ");
    }
    printf("%d, ", aArray[ii]);
  }
  printf("\n  };\n");
}


int main(int argc, char **argv){
  int nFunc;              /* Number of entries in the aBuiltinFunc array */







|







78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
static void printarray(const char *zName, u8 *aArray, int nArray){
  int ii;
  printf("  static u8 %s[%d] = {", zName, nArray);
  for(ii=0; ii<nArray; ii++){
    if( (ii%16)==0 ){
      printf("\n    ");
    }
    printf("%2d, ", aArray[ii]);
  }
  printf("\n  };\n");
}


int main(int argc, char **argv){
  int nFunc;              /* Number of entries in the aBuiltinFunc array */
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162





163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
      aNext[iNext] = ii;
    }else{
      aHash[iHash] = ii;
    }
  }

  printf(

  "int sqlite3GetBuiltinFunction(\n"
  "  const char *zName,   \n"
  "  int nName, \n"
  "  FuncDef **paFunc\n"
  "){\n"
  );

  printarray("aHash", aHash, HASHSIZE);
  printarray("anFunc", anFunc, nFunc);
  printarray("aNext", aNext, nFunc);
  printf("  FuncDef *pNoFunc = &aBuiltinFunc[%d];\n", nFunc);

  printf(
  "  unsigned int iKey = 0;  /* Hash of case-insensitive string zName. */\n"
  "  int ii;\n"
  "  FuncDef *pFunc;\n"
  "\n"





  "  /* Generate the hash of zName */\n"
  "  for(ii=0; ii<nName; ii++){\n"
  "    iKey = (iKey<<3) + (u8)sqlite3UpperToLower[(u8)zName[ii]];\n"
  "  }\n"
  "  iKey = iKey%%127;\n"
  "\n"
  "  pFunc = &aBuiltinFunc[iKey = aHash[iKey]];\n"
  "  while( pFunc!=pNoFunc && sqlite3StrNICmp(pFunc->zName, zName, nName) ){\n"
  "    pFunc = &aBuiltinFunc[iKey = aNext[iKey]];\n"
  "  }\n"
  "\n"
  "  *paFunc = pFunc;\n"
  "  return anFunc[iKey];\n"
  "}\n"
  );

  return 0;
}








>

















>
>
>
>
>


















<
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

      aNext[iNext] = ii;
    }else{
      aHash[iHash] = ii;
    }
  }

  printf(
  "/******* Automatically Generated code - do not edit **************/\n"
  "int sqlite3GetBuiltinFunction(\n"
  "  const char *zName,   \n"
  "  int nName, \n"
  "  FuncDef **paFunc\n"
  "){\n"
  );

  printarray("aHash", aHash, HASHSIZE);
  printarray("anFunc", anFunc, nFunc);
  printarray("aNext", aNext, nFunc);
  printf("  FuncDef *pNoFunc = &aBuiltinFunc[%d];\n", nFunc);

  printf(
  "  unsigned int iKey = 0;  /* Hash of case-insensitive string zName. */\n"
  "  int ii;\n"
  "  FuncDef *pFunc;\n"
  "\n"
  );
  printf(
  "  assert( (sizeof(aBuiltinFunc)/sizeof(aBuiltinFunc[0]))==%d );\n", nFunc
  );
  printf(
  "  /* Generate the hash of zName */\n"
  "  for(ii=0; ii<nName; ii++){\n"
  "    iKey = (iKey<<3) + (u8)sqlite3UpperToLower[(u8)zName[ii]];\n"
  "  }\n"
  "  iKey = iKey%%127;\n"
  "\n"
  "  pFunc = &aBuiltinFunc[iKey = aHash[iKey]];\n"
  "  while( pFunc!=pNoFunc && sqlite3StrNICmp(pFunc->zName, zName, nName) ){\n"
  "    pFunc = &aBuiltinFunc[iKey = aNext[iKey]];\n"
  "  }\n"
  "\n"
  "  *paFunc = pFunc;\n"
  "  return anFunc[iKey];\n"
  "}\n"
  );

  return 0;
}