/ Check-in [3d177bde]
Login

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

Overview
Comment:Define the sqliteMalloc() macro differently to avoid a compiler warning. (CVS 2809)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3d177bde71811391f79f4ab3bae054ef1bceb6a0
User & Date: danielk1977 2005-12-09 14:39:04
Context
2005-12-09
20:02
Clean up annoying (and pointless) compiler warnings about differing signedness. (CVS 2810) check-in: 83a59151 user: drh tags: trunk
14:39
Define the sqliteMalloc() macro differently to avoid a compiler warning. (CVS 2809) check-in: 3d177bde user: danielk1977 tags: trunk
14:25
Many small changes to ensure memory is not leaked after malloc() fails. (CVS 2808) check-in: 601c3354 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/sqliteInt.h.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258












259
260
261
262
263
264
265
**    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.431 2005/12/09 14:25:08 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
................................................................................
extern int sqlite3_nMalloc;      /* Number of sqliteMalloc() calls */
extern int sqlite3_nFree;        /* Number of sqliteFree() calls */
extern int sqlite3_iMallocFail;  /* Fail sqliteMalloc() after this many calls */
extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
#define ENTER_MALLOC (\
  sqlite3Tsd()->zFile = __FILE__, sqlite3Tsd()->iLine = __LINE__ \
)
#else
#define ENTER_MALLOC 0
#endif

#define sqliteFree(x)          sqlite3FreeX(x)
#define sqliteMalloc(x)        (ENTER_MALLOC, sqlite3Malloc(x))
#define sqliteMallocRaw(x)     (ENTER_MALLOC, sqlite3MallocRaw(x))
#define sqliteRealloc(x,y)     (ENTER_MALLOC, sqlite3Realloc(x,y))
#define sqliteStrDup(x)        (ENTER_MALLOC, sqlite3StrDup(x))
#define sqliteStrNDup(x,y)     (ENTER_MALLOC, sqlite3StrNDup(x,y))













/*
** 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 NDEBUG







|







 







<
<
<
<
<






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







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
241
242
243
244
245
246
247





248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
**    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.432 2005/12/09 14:39:04 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
................................................................................
extern int sqlite3_nMalloc;      /* Number of sqliteMalloc() calls */
extern int sqlite3_nFree;        /* Number of sqliteFree() calls */
extern int sqlite3_iMallocFail;  /* Fail sqliteMalloc() after this many calls */
extern int sqlite3_iMallocReset; /* Set iMallocFail to this when it reaches 0 */
#define ENTER_MALLOC (\
  sqlite3Tsd()->zFile = __FILE__, sqlite3Tsd()->iLine = __LINE__ \
)





#define sqliteMalloc(x)        (ENTER_MALLOC, sqlite3Malloc(x))
#define sqliteMallocRaw(x)     (ENTER_MALLOC, sqlite3MallocRaw(x))
#define sqliteRealloc(x,y)     (ENTER_MALLOC, sqlite3Realloc(x,y))
#define sqliteStrDup(x)        (ENTER_MALLOC, sqlite3StrDup(x))
#define sqliteStrNDup(x,y)     (ENTER_MALLOC, sqlite3StrNDup(x,y))

#else

#define sqliteMalloc(x)        sqlite3Malloc(x)
#define sqliteMallocRaw(x)     sqlite3MallocRaw(x)
#define sqliteRealloc(x,y)     sqlite3Realloc(x,y)
#define sqliteStrDup(x)        sqlite3StrDup(x)
#define sqliteStrNDup(x,y)     sqlite3StrNDup(x,y)

#endif

#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 NDEBUG

Changes to src/test1.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
....
3217
3218
3219
3220
3221
3222
3223

3224
3225

3226
3227
3228
3229
3230
3231
3232
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the printf() interface to SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.172 2005/12/09 14:25:08 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

................................................................................
      (char*)&sqlite3_interrupt_count, TCL_LINK_INT);
  Tcl_LinkVar(interp, "sqlite_open_file_count", 
      (char*)&sqlite3_open_file_count, TCL_LINK_INT);
  Tcl_LinkVar(interp, "sqlite_current_time", 
      (char*)&sqlite3_current_time, TCL_LINK_INT);
  Tcl_LinkVar(interp, "sqlite_os_trace",
      (char*)&sqlite3_os_trace, TCL_LINK_INT);

  Tcl_LinkVar(interp, "sqlite_malloc_id",
      (char*)&sqlite3_malloc_id, TCL_LINK_STRING);

#if OS_WIN
  Tcl_LinkVar(interp, "sqlite_os_type",
      (char*)&sqlite3_os_type, TCL_LINK_INT);
#endif
#ifdef SQLITE_TEST
  Tcl_LinkVar(interp, "sqlite_query_plan",
      (char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);







|







 







>


>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
....
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the printf() interface to SQLite.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.173 2005/12/09 14:39:04 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

................................................................................
      (char*)&sqlite3_interrupt_count, TCL_LINK_INT);
  Tcl_LinkVar(interp, "sqlite_open_file_count", 
      (char*)&sqlite3_open_file_count, TCL_LINK_INT);
  Tcl_LinkVar(interp, "sqlite_current_time", 
      (char*)&sqlite3_current_time, TCL_LINK_INT);
  Tcl_LinkVar(interp, "sqlite_os_trace",
      (char*)&sqlite3_os_trace, TCL_LINK_INT);
#ifdef SQLITE_MEMDEBUG
  Tcl_LinkVar(interp, "sqlite_malloc_id",
      (char*)&sqlite3_malloc_id, TCL_LINK_STRING);
#endif
#if OS_WIN
  Tcl_LinkVar(interp, "sqlite_os_type",
      (char*)&sqlite3_os_type, TCL_LINK_INT);
#endif
#ifdef SQLITE_TEST
  Tcl_LinkVar(interp, "sqlite_query_plan",
      (char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);

Changes to src/util.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.150 2005/12/09 14:25:09 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** MALLOC WRAPPER ARCHITECTURE
................................................................................
** Return a pointer to the SqliteTsd associated with the calling thread.
*/
static SqliteTsd tsd = {
  0                    /* mallocFailed flag */
#ifndef NDEBUG
  , 1                  /* mallocAllowed flag */
#endif
#ifndef SQLITE_MEMDEBUG
  , 0
  , 0
  , 0
  , 0
#endif
};
SqliteTsd *sqlite3Tsd(){







|







 







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.151 2005/12/09 14:39:04 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** MALLOC WRAPPER ARCHITECTURE
................................................................................
** Return a pointer to the SqliteTsd associated with the calling thread.
*/
static SqliteTsd tsd = {
  0                    /* mallocFailed flag */
#ifndef NDEBUG
  , 1                  /* mallocAllowed flag */
#endif
#ifdef SQLITE_MEMDEBUG
  , 0
  , 0
  , 0
  , 0
#endif
};
SqliteTsd *sqlite3Tsd(){

Changes to test/tester.tcl.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
141
142
143
144
145
146
147

148

149
150
151
152
153
154
155
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.53 2005/12/09 14:25:12 danielk1977 Exp $

# Make sure tclsqlite3 was compiled correctly.  Abort now with an
# error message if not.
#
if {[sqlite3 -tcl-uses-utf]} {
  if {"\u1234"=="u1234"} {
    puts stderr "***** BUILD PROBLEM *****"
................................................................................
  global nTest nErr nProb sqlite_open_file_count
  if {$nErr==0} memleak_check

  catch {db close}
  catch {db2 close}
  catch {db3 close}


pp_check_for_leaks


  puts "$nErr errors out of $nTest tests"
  puts "Failures on these tests: $::failList"
  if {$nProb>0} {
    puts "$nProb probabilistic tests also failed, but this does"
    puts "not necessarily indicate a malfunction."
  }







|







 







>
|
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements some common TCL routines used for regression
# testing the SQLite library
#
# $Id: tester.tcl,v 1.54 2005/12/09 14:39:05 danielk1977 Exp $

# Make sure tclsqlite3 was compiled correctly.  Abort now with an
# error message if not.
#
if {[sqlite3 -tcl-uses-utf]} {
  if {"\u1234"=="u1234"} {
    puts stderr "***** BUILD PROBLEM *****"
................................................................................
  global nTest nErr nProb sqlite_open_file_count
  if {$nErr==0} memleak_check

  catch {db close}
  catch {db2 close}
  catch {db3 close}

  catch {
    pp_check_for_leaks
  }

  puts "$nErr errors out of $nTest tests"
  puts "Failures on these tests: $::failList"
  if {$nProb>0} {
    puts "$nProb probabilistic tests also failed, but this does"
    puts "not necessarily indicate a malfunction."
  }