SQLite

Check-in [c1ed79f594]
Login

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

Overview
Comment:Add the sqlite3_os_routine_set()/get() functions. (CVS 2818)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c1ed79f594fb85009c2e9e5e281cbe66a9d2fa17
User & Date: danielk1977 2005-12-15 10:11:31.000
Context
2005-12-15
10:50
Move malloc(), free(), realloc() and allocationSize() into the Os vtbl. (CVS 2819) (check-in: 81a41f6637 user: danielk1977 tags: trunk)
10:11
Add the sqlite3_os_routine_set()/get() functions. (CVS 2818) (check-in: c1ed79f594 user: danielk1977 tags: trunk)
03:04
Fix memory allocation problems on the utf-16 versions of collating function control routines. (CVS 2817) (check-in: ad292e2733 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to main.mk.
129
130
131
132
133
134
135

136
137
138
139
140
141
142
  $(TOP)/src/printf.c \
  $(TOP)/src/test1.c \
  $(TOP)/src/test2.c \
  $(TOP)/src/test3.c \
  $(TOP)/src/test4.c \
  $(TOP)/src/test5.c \
  $(TOP)/src/test6.c \

  $(TOP)/src/utf.c \
  $(TOP)/src/util.c \
  $(TOP)/src/vdbe.c \
  $(TOP)/src/md5.c \
  $(TOP)/src/where.c

# Header files used by all library source files.







>







129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  $(TOP)/src/printf.c \
  $(TOP)/src/test1.c \
  $(TOP)/src/test2.c \
  $(TOP)/src/test3.c \
  $(TOP)/src/test4.c \
  $(TOP)/src/test5.c \
  $(TOP)/src/test6.c \
  $(TOP)/src/test_async.c \
  $(TOP)/src/utf.c \
  $(TOP)/src/util.c \
  $(TOP)/src/vdbe.c \
  $(TOP)/src/md5.c \
  $(TOP)/src/where.c

# Header files used by all library source files.
Changes to src/os.c.
65
66
67
68
69
70
71







































}
int sqlite3OsLockState(OsFile *id){
  return id->pMethod->xLockState(id);
}
int sqlite3OsCheckReservedLock(OsFile *id){
  return id->pMethod->xCheckReservedLock(id);
}














































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
}
int sqlite3OsLockState(OsFile *id){
  return id->pMethod->xLockState(id);
}
int sqlite3OsCheckReservedLock(OsFile *id){
  return id->pMethod->xCheckReservedLock(id);
}

static void**getOsRoutinePtr(int eRoutine){
  switch( eRoutine ){
    case SQLITE_OS_ROUTINE_OPENREADWRITE:
      return (void **)(&sqlite3Os.xOpenReadWrite);
    case SQLITE_OS_ROUTINE_OPENREADONLY:
      return (void **)(&sqlite3Os.xOpenReadOnly);
    case SQLITE_OS_ROUTINE_OPENEXCLUSIVE:
      return (void **)(&sqlite3Os.xOpenExclusive);
    case SQLITE_OS_ROUTINE_DELETE:
      return (void **)(&sqlite3Os.xDelete);
    case SQLITE_OS_ROUTINE_FILEEXISTS:
      return (void **)(&sqlite3Os.xFileExists);
    case SQLITE_OS_ROUTINE_SYNCDIRECTORY:
      return (void **)(&sqlite3Os.xSyncDirectory);
    default:
      assert(!"Illegal eRoutine value");
  }
  return 0;
}

void *sqlite3_os_routine_get(int eRoutine){
  return *getOsRoutinePtr(eRoutine);
}

void *sqlite3_os_routine_set(int eRoutine, void *pRoutine){
  void **ppRet = getOsRoutinePtr(eRoutine);
  void *pRet = *ppRet;
  *ppRet = pRoutine;
  return pRet;
}

void sqlite3_os_enter_mutex(){
  sqlite3Os.xEnterMutex();
}
void sqlite3_os_leave_mutex(){
  sqlite3Os.xLeaveMutex();
}

Changes to src/os.h.
218
219
220
221
222
223
224

225
226





















227
228
229
230
231
232
233
  int (*xTempFileName)(char*);

  int  (*xRandomSeed)(char*);
  int  (*xSleep)(int ms);
  int  (*xCurrentTime)(double*);
  void (*xEnterMutex)(void);
  void (*xLeaveMutex)(void);

} sqlite3Os;






















/*
** Prototypes for routines found in os.c
*/
int sqlite3OsClose(OsFile**);
int sqlite3OsOpenDirectory(OsFile*, const char*);
int sqlite3OsRead(OsFile*, void*, int amt);
int sqlite3OsWrite(OsFile*, const void*, int amt);







>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
  int (*xTempFileName)(char*);

  int  (*xRandomSeed)(char*);
  int  (*xSleep)(int ms);
  int  (*xCurrentTime)(double*);
  void (*xEnterMutex)(void);
  void (*xLeaveMutex)(void);
  void *(*xThreadSpecificData)(int);
} sqlite3Os;


/*
** The semi-published API for setting and getting methods from the 
** global sqlite3OsVtbl structure. Neither sqlite3_os_routine_XXX() function
** is intriniscally thread-safe.
**
** External get/set access is only provided to the routines identified 
** by the hash-defined SQLITE_OS_ROUTINE symbols.
*/
#define SQLITE_OS_ROUTINE_OPENREADWRITE   1
#define SQLITE_OS_ROUTINE_OPENREADONLY    2
#define SQLITE_OS_ROUTINE_OPENEXCLUSIVE   3
#define SQLITE_OS_ROUTINE_DELETE          4
#define SQLITE_OS_ROUTINE_FILEEXISTS      5
#define SQLITE_OS_ROUTINE_SYNCDIRECTORY   6
void *sqlite3_os_routine_get(int);
void *sqlite3_os_routine_set(int, void *);

void sqlite3_os_enter_mutex();
void sqlite3_os_leave_mutex();

/*
** Prototypes for routines found in os.c
*/
int sqlite3OsClose(OsFile**);
int sqlite3OsOpenDirectory(OsFile*, const char*);
int sqlite3OsRead(OsFile*, void*, int amt);
int sqlite3OsWrite(OsFile*, const void*, int amt);
Changes to src/os_unix.c.
1581
1582
1583
1584
1585
1586
1587




























































1588
1589
1590
1591
1592
1593
1594
static void unixLeaveMutex(){
  assert( inMutex );
  inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
  pthread_mutex_unlock(&mutex);
#endif
}





























































/*
** The following variable, if set to a non-zero value, becomes the result
** returned from sqlite3Os.xCurrentTime().  This is used for testing.
*/
#ifdef SQLITE_TEST
int sqlite3_current_time = 0;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
static void unixLeaveMutex(){
  assert( inMutex );
  inMutex = 0;
#ifdef SQLITE_UNIX_THREADS
  pthread_mutex_unlock(&mutex);
#endif
}

/*
** This function is called automatically when a thread exists to delete
** the threads SqliteTsd structure. 
**
** Because the SqliteTsd structure is required by higher level routines
** such as sqliteMalloc() we use OsFree() and OsMalloc() directly to
** allocate the thread specific data.
*/
static void deleteTsd(void *pTsd){
  sqlite3OsFree(pTsd);
}

/* 
** The first time this function is called from a specific thread, nByte 
** bytes of data area are allocated and zeroed. A pointer to the new 
** allocation is returned to the caller. 
**
** Each subsequent call to this function from the thread returns the same
** pointer. The argument is ignored in this case.
*/
static void *unixThreadSpecificData(int nByte){
#ifdef SQLITE_UNIX_THREADS
  static pthread_key_t key;
  static int keyInit = 0;
  void *pTsd;

  if( !keyInit ){
    sqlite3Os.xEnterMutex();
    if( !keyInit ){
      int rc;
      rc = pthread_key_create(&key, deleteTsd);
      if( rc ){
        return 0;
      }
      keyInit = 1;
    }
    sqlite3Os.xLeaveMutex();
  }

  pTsd = (SqliteTsd *)pthread_getspecific(key);
  if( !pTsd ){
    pTsd = sqlite3OsMalloc(sizeof(SqliteTsd));
    if( pTsd ){
      memset(pTsd, 0, sizeof(SqliteTsd));
      pthread_setspecific(key, pTsd);
    }
  }
  return pTsd;
#else
  static char tsd[sizeof(SqliteTsd)];
  static isInit = 0;
  assert( nByte==sizeof(SqliteTsd) );
  if( !isInit ){
    memset(tsd, 0, sizeof(SqliteTsd));
    isInit = 1;
  }
  return (void *)tsd;
#endif
}

/*
** The following variable, if set to a non-zero value, becomes the result
** returned from sqlite3Os.xCurrentTime().  This is used for testing.
*/
#ifdef SQLITE_TEST
int sqlite3_current_time = 0;
1640
1641
1642
1643
1644
1645
1646

1647
1648
1649
1650
1651
  IF_DISKIO( unixSyncDirectory ),
  IF_DISKIO( unixTempFileName ),
  unixRandomSeed,
  unixSleep,
  unixCurrentTime,
  unixEnterMutex,
  unixLeaveMutex,

};



#endif /* OS_UNIX */







>





1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
  IF_DISKIO( unixSyncDirectory ),
  IF_DISKIO( unixTempFileName ),
  unixRandomSeed,
  unixSleep,
  unixCurrentTime,
  unixEnterMutex,
  unixLeaveMutex,
  unixThreadSpecificData
};



#endif /* OS_UNIX */
Changes to src/os_win.c.
1016
1017
1018
1019
1020
1021
1022















1023
1024
1025
1026
1027
1028
1029
  if( sqlite3_current_time ){
    *prNow = sqlite3_current_time/86400.0 + 2440587.5;
  }
#endif
  return 0;
}
















/* Macro used to comment out routines that do not exists when there is
** no disk I/O
*/
#ifdef SQLITE_OMIT_DISKIO
# define IF_DISKIO(X)  0
#else
# define IF_DISKIO(X)  X







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
  if( sqlite3_current_time ){
    *prNow = sqlite3_current_time/86400.0 + 2440587.5;
  }
#endif
  return 0;
}


/*
** Todo: This is a place-holder only
*/
static void *winThreadSpecificData(int nByte){
  static char tsd[sizeof(SqliteTsd)];
  static isInit = 0;
  assert( nByte==sizeof(SqliteTsd) );
  if( !isInit ){
    memset(tsd, 0, sizeof(SqliteTsd));
    isInit = 1;
  }
  return (void *)tsd;
}

/* Macro used to comment out routines that do not exists when there is
** no disk I/O
*/
#ifdef SQLITE_OMIT_DISKIO
# define IF_DISKIO(X)  0
#else
# define IF_DISKIO(X)  X
1043
1044
1045
1046
1047
1048
1049

1050
1051
1052
  IF_DISKIO( winSyncDirectory ),
  IF_DISKIO( winTempFileName ),
  winRandomSeed,
  winSleep,
  winCurrentTime,
  winEnterMutex,
  winLeaveMutex,

};

#endif /* OS_WIN */







>



1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
  IF_DISKIO( winSyncDirectory ),
  IF_DISKIO( winTempFileName ),
  winRandomSeed,
  winSleep,
  winCurrentTime,
  winEnterMutex,
  winLeaveMutex,
  winThreadSpecificData
};

#endif /* OS_WIN */
Changes to src/sqlite.h.in.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.144 2005/12/12 06:53:05 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This header file defines the interface that the SQLite library
** presents to client programs.
**
** @(#) $Id: sqlite.h.in,v 1.145 2005/12/15 10:11:32 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
#include <stdarg.h>     /* Needed for the definition of va_list */

/*
** Make sure we can call this stuff from C++.
1287
1288
1289
1290
1291
1292
1293




1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
** allocated anyway and the current operation proceeds.
**
** This function is only available if the library was compiled without the 
** SQLITE_OMIT_SOFTHEAPLIMIT option set.
*/
void sqlite3_soft_heap_limit(int);





/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/
#ifdef SQLITE_OMIT_FLOATING_POINT
# undef double
#endif

#ifdef __cplusplus
}  /* End of the 'extern "C"' block */
#endif
#endif







>
>
>
>












1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
** allocated anyway and the current operation proceeds.
**
** This function is only available if the library was compiled without the 
** SQLITE_OMIT_SOFTHEAPLIMIT option set.
*/
void sqlite3_soft_heap_limit(int);


int sqlite3_set_io_routine(int, void *);
void *sqlite3_get_io_routine(int);

/*
** Undo the hack that converts floating point types to integer for
** builds on processors without floating point support.
*/
#ifdef SQLITE_OMIT_FLOATING_POINT
# undef double
#endif

#ifdef __cplusplus
}  /* End of the 'extern "C"' block */
#endif
#endif
Changes to src/sqliteInt.h.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** 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.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.435 2005/12/15 03:04:11 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_

/*
** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
** Setting NDEBUG makes the code smaller and run faster.  So the following













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** 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.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.436 2005/12/15 10:11:32 danielk1977 Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_

/*
** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
** Setting NDEBUG makes the code smaller and run faster.  So the following
264
265
266
267
268
269
270

271
272
273
274
275
276
277
#define sqliteFree(x)     sqlite3FreeX(x)

/*
** An instance of this structure is allocated for each thread that uses SQLite.
*/
typedef struct SqliteTsd SqliteTsd;
struct SqliteTsd {

  int mallocFailed;               /* True after a malloc() has failed */
#ifndef SQLITE_OMIT_SOFTHEAPLIMIT
  unsigned int nSoftHeapLimit;    /* (uint)-1 for unlimited */
  unsigned int nAlloc;            /* Number of bytes currently allocated */
#endif

#ifndef NDEBUG







>







264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#define sqliteFree(x)     sqlite3FreeX(x)

/*
** An instance of this structure is allocated for each thread that uses SQLite.
*/
typedef struct SqliteTsd SqliteTsd;
struct SqliteTsd {
  int isInit;                     /* True if structure has been initialised */
  int mallocFailed;               /* True after a malloc() has failed */
#ifndef SQLITE_OMIT_SOFTHEAPLIMIT
  unsigned int nSoftHeapLimit;    /* (uint)-1 for unlimited */
  unsigned int nAlloc;            /* Number of bytes currently allocated */
#endif

#ifndef NDEBUG
Changes to src/tclsqlite.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** 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.
**
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.137 2005/12/12 06:53:05 danielk1977 Exp $
*/
#ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */

#include "sqliteInt.h"
#include "hash.h"
#include "tcl.h"
#include <stdlib.h>













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
** 2001 September 15
**
** 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.
**
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.138 2005/12/15 10:11:32 danielk1977 Exp $
*/
#ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */

#include "sqliteInt.h"
#include "hash.h"
#include "tcl.h"
#include <stdlib.h>
2088
2089
2090
2091
2092
2093
2094

2095
2096
2097
2098
2099
2100
2101
2102
2103

2104
2105
2106
2107
2108
2109
2110
  {
    extern int Sqlitetest1_Init(Tcl_Interp*);
    extern int Sqlitetest2_Init(Tcl_Interp*);
    extern int Sqlitetest3_Init(Tcl_Interp*);
    extern int Sqlitetest4_Init(Tcl_Interp*);
    extern int Sqlitetest5_Init(Tcl_Interp*);
    extern int Sqlitetest6_Init(Tcl_Interp*);

    extern int Md5_Init(Tcl_Interp*);
    extern int Sqlitetestsse_Init(Tcl_Interp*);

    Sqlitetest1_Init(interp);
    Sqlitetest2_Init(interp);
    Sqlitetest3_Init(interp);
    Sqlitetest4_Init(interp);
    Sqlitetest5_Init(interp);
    Sqlitetest6_Init(interp);

    Md5_Init(interp);
#ifdef SQLITE_SSE
    Sqlitetestsse_Init(interp);
#endif
  }
#endif
  if( argc>=2 || TCLSH==2 ){







>









>







2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
  {
    extern int Sqlitetest1_Init(Tcl_Interp*);
    extern int Sqlitetest2_Init(Tcl_Interp*);
    extern int Sqlitetest3_Init(Tcl_Interp*);
    extern int Sqlitetest4_Init(Tcl_Interp*);
    extern int Sqlitetest5_Init(Tcl_Interp*);
    extern int Sqlitetest6_Init(Tcl_Interp*);
    extern int Sqlitetestasync_Init(Tcl_Interp*);
    extern int Md5_Init(Tcl_Interp*);
    extern int Sqlitetestsse_Init(Tcl_Interp*);

    Sqlitetest1_Init(interp);
    Sqlitetest2_Init(interp);
    Sqlitetest3_Init(interp);
    Sqlitetest4_Init(interp);
    Sqlitetest5_Init(interp);
    Sqlitetest6_Init(interp);
    Sqlitetestasync_Init(interp);
    Md5_Init(interp);
#ifdef SQLITE_SSE
    Sqlitetestsse_Init(interp);
#endif
  }
#endif
  if( argc>=2 || TCLSH==2 ){
Changes to src/util.c.
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.152 2005/12/12 06:53:05 danielk1977 Exp $
*/
#include "sqliteInt.h"

#include <stdarg.h>
#include <ctype.h>

/*
** MALLOC WRAPPER ARCHITECTURE
**
** The sqlite code accesses dynamic memory allocation/deallocation by invoking







|


>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.153 2005/12/15 10:11:32 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <stdarg.h>
#include <ctype.h>

/*
** MALLOC WRAPPER ARCHITECTURE
**
** The sqlite code accesses dynamic memory allocation/deallocation by invoking
103
104
105
106
107
108
109




110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#define sqlite3_release_memory(x) 0

#ifdef SQLITE_MEMDEBUG
/*--------------------------------------------------------------------------
** Begin code for memory allocation system test layer.
**
** Memory debugging is turned on by defining the SQLITE_MEMDEBUG macro.




*/

/* Figure out whether or not to store backtrace() information for each malloc.
** The backtrace() function is only used if SQLITE_MEMDEBUG is set to 2 or 
** greater and glibc is in use. If we don't want to use backtrace(), then just
** define it as an empty macro and set the amount of space reserved to 0.
*/
#if defined(__GLIBC__) && SQLITE_MEMDEBUG>1
  extern int backtrace(void **, int);
  #define TESTALLOC_STACKSIZE 128
  #define TESTALLOC_STACKFRAMES ((TESTALLOC_STACKSIZE-8)/sizeof(void*))
#else
  #define backtrace(x, y)
  #define TESTALLOC_STACKSIZE 0
  #define TESTALLOC_STACKFRAMES 0







>
>
>
>







|







104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#define sqlite3_release_memory(x) 0

#ifdef SQLITE_MEMDEBUG
/*--------------------------------------------------------------------------
** Begin code for memory allocation system test layer.
**
** Memory debugging is turned on by defining the SQLITE_MEMDEBUG macro.
**
** SQLITE_MEMDEBUG==1    -> Fence-posting only (thread safe) 
** SQLITE_MEMDEBUG==2    -> Fence-posting + linked list of allocations (not ts)
** SQLITE_MEMDEBUG==3    -> Above + backtraces (not thread safe, req. glibc)
*/

/* Figure out whether or not to store backtrace() information for each malloc.
** The backtrace() function is only used if SQLITE_MEMDEBUG is set to 2 or 
** greater and glibc is in use. If we don't want to use backtrace(), then just
** define it as an empty macro and set the amount of space reserved to 0.
*/
#if defined(__GLIBC__) && SQLITE_MEMDEBUG>2
  extern int backtrace(void **, int);
  #define TESTALLOC_STACKSIZE 128
  #define TESTALLOC_STACKFRAMES ((TESTALLOC_STACKSIZE-8)/sizeof(void*))
#else
  #define backtrace(x, y)
  #define TESTALLOC_STACKSIZE 0
  #define TESTALLOC_STACKFRAMES 0
298
299
300
301
302
303
304


305
306
307
308
309
310
311

static void *getOsPointer(void *p)
{
  char *z = (char *)p;
  return (void *)(&z[-1 * TESTALLOC_OFFSET_DATA(p)]);
}



/*
** The argument points to an Os level allocation. Link it into the threads list
** of allocations.
*/
static void linkAlloc(void *p){
  SqliteTsd *pTsd = sqlite3Tsd();
  void **pp = (void **)p;







>
>







303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

static void *getOsPointer(void *p)
{
  char *z = (char *)p;
  return (void *)(&z[-1 * TESTALLOC_OFFSET_DATA(p)]);
}


#if SQLITE_MEMDEBUG>1
/*
** The argument points to an Os level allocation. Link it into the threads list
** of allocations.
*/
static void linkAlloc(void *p){
  SqliteTsd *pTsd = sqlite3Tsd();
  void **pp = (void **)p;
359
360
361
362
363
364
365





366
367
368
369
370
371
372
    SqliteTsd *pTsd = sqlite3Tsd();
    pTsd->pFirst = p;
  }
  if( pp[1] ){
    ((void **)(pp[1]))[0] = p;
  }
}






/*
** This function sets the result of the Tcl interpreter passed as an argument
** to a list containing an entry for each currently outstanding call made to 
** sqliteMalloc and friends by the current thread. Each list entry is itself a
** list, consisting of the following (in order):
**







>
>
>
>
>







366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
    SqliteTsd *pTsd = sqlite3Tsd();
    pTsd->pFirst = p;
  }
  if( pp[1] ){
    ((void **)(pp[1]))[0] = p;
  }
}
#else
#define linkAlloc(x)
#define relinkAlloc(x)
#define unlinkAlloc(x)
#endif

/*
** This function sets the result of the Tcl interpreter passed as an argument
** to a list containing an entry for each currently outstanding call made to 
** sqliteMalloc and friends by the current thread. Each list entry is itself a
** list, consisting of the following (in order):
**
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256

1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269

1270
1271
1272
1273
1274
1275
1276
1277
  }
  return p;
}
#endif

/*
** Return a pointer to the SqliteTsd associated with the calling thread.
** TODO: Actually return thread-specific-data instead of this global pointer.
*/
SqliteTsd *sqlite3Tsd(){
  static SqliteTsd tsd = {
    0                    /* mallocFailed flag */
  #ifndef SQLITE_OMIT_SOFTHEAPLIMIT

    , 0xFFFFFFFF         /* nSoftHeapLimit */
    , 0                  /* nAlloc */
  #endif
  #ifndef NDEBUG
    , 1                  /* mallocAllowed flag */
  #endif
  #ifdef SQLITE_MEMDEBUG
    , 0
    , 0
    , 0
    , 0
  #endif
  };

  return &tsd;
}

/*
** Clear the "mallocFailed" flag. This should be invoked before exiting any
** entry points that may have called sqliteMalloc().
*/
void sqlite3MallocClearFailed(){







<


|
<
<
>
|
<
<
|
|
|
<
|
<
<
<
<
<
>
|







1256
1257
1258
1259
1260
1261
1262

1263
1264
1265


1266
1267


1268
1269
1270

1271





1272
1273
1274
1275
1276
1277
1278
1279
1280
  }
  return p;
}
#endif

/*
** Return a pointer to the SqliteTsd associated with the calling thread.

*/
SqliteTsd *sqlite3Tsd(){
  SqliteTsd *pTsd = sqlite3Os.xThreadSpecificData(sizeof(SqliteTsd));


  if( pTsd && !pTsd->isInit ){
    pTsd->nSoftHeapLimit = 0xFFFFFFFF;


#ifndef NDEBUG
    pTsd->mallocAllowed = 1;
#endif

    pTsd->isInit = 1;





  }
  return pTsd;
}

/*
** Clear the "mallocFailed" flag. This should be invoked before exiting any
** entry points that may have called sqliteMalloc().
*/
void sqlite3MallocClearFailed(){
Changes to test/all.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2001 September 15
#
# 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 runs all tests.
#
# $Id: all.test,v 1.30 2005/01/17 07:53:44 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
rename finish_test really_finish_test
proc finish_test {} {memleak_check}

if {[file exists ./sqlite_test_count]} {












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2001 September 15
#
# 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 runs all tests.
#
# $Id: all.test,v 1.31 2005/12/15 10:11:32 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
rename finish_test really_finish_test
proc finish_test {} {memleak_check}

if {[file exists ./sqlite_test_count]} {
45
46
47
48
49
50
51

52
53
54
55
56
57
58
# each round of the test.  This number should be constant.  If it
# grows, it may mean there is a memory leak in the library.
#
set LeakList {}

set EXCLUDE {
  all.test

  crash.test
  autovacuum_crash.test
  quick.test
  malloc.test
  misuse.test
  memleak.test
}







>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# each round of the test.  This number should be constant.  If it
# grows, it may mean there is a memory leak in the library.
#
set LeakList {}

set EXCLUDE {
  all.test
  async.test
  crash.test
  autovacuum_crash.test
  quick.test
  malloc.test
  misuse.test
  memleak.test
}
Changes to test/quick.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
#
#    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 runs all tests.
#
# $Id: quick.test,v 1.37 2005/12/07 06:27:45 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
rename finish_test really_finish_test
proc finish_test {} {}
set ISQUICK 1

set EXCLUDE {
  all.test

  btree2.test
  btree3.test
  btree4.test
  btree5.test
  btree6.test
  corrupt.test
  crash.test








|









>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
#    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 runs all tests.
#
# $Id: quick.test,v 1.38 2005/12/15 10:11:32 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
rename finish_test really_finish_test
proc finish_test {} {}
set ISQUICK 1

set EXCLUDE {
  all.test
  async.test
  btree2.test
  btree3.test
  btree4.test
  btree5.test
  btree6.test
  corrupt.test
  crash.test
Changes to test/select1.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
# 2001 September 15
#
# 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 regression tests for SQLite library.  The
# focus of this file is testing the SELECT statement.
#
# $Id: select1.test,v 1.44 2005/12/09 14:25:12 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Try to select on a non-existant table.
#
do_test select1-1.1 {
  set v [catch {execsql {SELECT * FROM test1}} msg]
  lappend v $msg
} {1 {no such table: test1}}


execsql {CREATE TABLE test1(f1 int, f2 int)}

do_test select1-1.2 {
  set v [catch {execsql {SELECT * FROM test1, test2}} msg]
  lappend v $msg
} {1 {no such table: test2}}













|










>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 2001 September 15
#
# 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 regression tests for SQLite library.  The
# focus of this file is testing the SELECT statement.
#
# $Id: select1.test,v 1.45 2005/12/15 10:11:32 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Try to select on a non-existant table.
#
do_test select1-1.1 {
  set v [catch {execsql {SELECT * FROM test1}} msg]
  lappend v $msg
} {1 {no such table: test1}}


execsql {CREATE TABLE test1(f1 int, f2 int)}

do_test select1-1.2 {
  set v [catch {execsql {SELECT * FROM test1, test2}} msg]
  lappend v $msg
} {1 {no such table: test2}}
794
795
796
797
798
799
800
801

802
    execsql2 {
      SELECT z.x FROM (
        SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
      ) AS 'z' ORDER BY x;
    }
  } {x 1 x 3}
} ;# ifcapable compound


finish_test








>

795
796
797
798
799
800
801
802
803
804
    execsql2 {
      SELECT z.x FROM (
        SELECT a,b FROM t3 UNION SELECT a AS 'x', b AS 'y' FROM t4 ORDER BY a,b
      ) AS 'z' ORDER BY x;
    }
  } {x 1 x 3}
} ;# ifcapable compound


finish_test