/ Check-in [238e35a4]
Login

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

Overview
Comment:Add the SQLITE_WITHOUT_MSIZE and SQLITE_WITHOUT_ZONEMALLOC macros in mem1.c to disable the use of _msize() on windows and the zone memory allocator on Apple products, respectively.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 238e35a4411a5b2231576254dba39b802947d4f3
User & Date: drh 2012-01-18 12:46:47
Context
2012-01-18
18:22
Avoid overriding the malloc_usable_size symbol using the C preprocessor as this might be confusing the build on some systems. check-in: bbaec351 user: drh tags: trunk
12:46
Add the SQLITE_WITHOUT_MSIZE and SQLITE_WITHOUT_ZONEMALLOC macros in mem1.c to disable the use of _msize() on windows and the zone memory allocator on Apple products, respectively. check-in: 238e35a4 user: drh tags: trunk
01:14
Remove a redundant assignment from the VM. check-in: d0dabe2f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mem1.c.

    11     11   *************************************************************************
    12     12   **
    13     13   ** This file contains low-level memory allocation drivers for when
    14     14   ** SQLite will use the standard C-library malloc/realloc/free interface
    15     15   ** to obtain the memory it needs.
    16     16   **
    17     17   ** This file contains implementations of the low-level memory allocation
    18         -** routines specified in the sqlite3_mem_methods object.
           18  +** routines specified in the sqlite3_mem_methods object.  The content of
           19  +** this file is only used if SQLITE_SYSTEM_MALLOC is defined.  The
           20  +** SQLITE_SYSTEM_MALLOC macro is defined automatically if neither the
           21  +** SQLITE_MEMDEBUG nor the SQLITE_WIN32_MALLOC macros are defined.  The
           22  +** default configuration is to use memory allocation routines in this
           23  +** file.
           24  +**
           25  +** C-preprocessor macro summary:
           26  +**
           27  +**    HAVE_MALLOC_USABLE_SIZE     The configure script sets this symbol if
           28  +**                                the malloc_usable_size() interface exists
           29  +**                                on the target platform.  Or, this symbol
           30  +**                                can be set manually, if desired.
           31  +**                                If an equivalent interface exists by
           32  +**                                a different name, using a separate -D
           33  +**                                option to rename it.  This symbol will
           34  +**                                be enabled automatically on windows
           35  +**                                systems, and malloc_usable_size() will
           36  +**                                be redefined to _msize(), unless the
           37  +**                                SQLITE_WITHOUT_MSIZE macro is defined.
           38  +**    
           39  +**    SQLITE_WITHOUT_ZONEMALLOC   Some older macs lack support for the zone
           40  +**                                memory allocator.  Set this symbol to enable
           41  +**                                building on older macs.
           42  +**
           43  +**    SQLITE_WITHOUT_MSIZE        Set this symbol to disable the use of
           44  +**                                _msize() on windows systems.  This might
           45  +**                                be necessary when compiling for Delphi,
           46  +**                                for example.
    19     47   */
    20     48   #include "sqliteInt.h"
    21     49   
    22     50   /*
    23     51   ** This version of the memory allocator is the default.  It is
    24     52   ** used when no other memory allocator is specified using compile-time
    25     53   ** macros.
    26     54   */
    27     55   #ifdef SQLITE_SYSTEM_MALLOC
    28     56   
    29     57   /*
    30         -** Windows systems have malloc_usable_size() but it is called _msize()
           58  +** Windows systems have malloc_usable_size() but it is called _msize().
           59  +** The use of _msize() is automatic, but can be disabled by compiling
           60  +** with -DSQLITE_WITHOUT_MSIZE
    31     61   */
    32         -#if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN
           62  +#if !defined(HAVE_MALLOC_USABLE_SIZE) && SQLITE_OS_WIN \
           63  +      && !defined(SQLITE_WITHOUT_MSIZE)
    33     64   # define HAVE_MALLOC_USABLE_SIZE 1
    34     65   # define malloc_usable_size _msize
    35     66   #endif
    36     67   
    37         -#if defined(__APPLE__)
           68  +#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
    38     69   
    39     70   /*
    40         -** Use the zone allocator available on apple products
           71  +** Use the zone allocator available on apple products unless the
           72  +** SQLITE_WITHOUT_ZONEMALLOC symbol is defined.
    41     73   */
    42     74   #include <sys/sysctl.h>
    43     75   #include <malloc/malloc.h>
    44     76   #include <libkern/OSAtomic.h>
    45     77   static malloc_zone_t* _sqliteZone_;
    46     78   #define SQLITE_MALLOC(x) malloc_zone_malloc(_sqliteZone_, (x))
    47     79   #define SQLITE_FREE(x) malloc_zone_free(_sqliteZone_, (x));
................................................................................
    48     80   #define SQLITE_REALLOC(x,y) malloc_zone_realloc(_sqliteZone_, (x), (y))
    49     81   #define SQLITE_MALLOCSIZE(x) \
    50     82           (_sqliteZone_ ? _sqliteZone_->size(_sqliteZone_,x) : malloc_size(x))
    51     83   
    52     84   #else /* if not __APPLE__ */
    53     85   
    54     86   /*
    55         -** Use standard C library malloc and free on non-Apple systems.
           87  +** Use standard C library malloc and free on non-Apple systems.  
           88  +** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
    56     89   */
    57     90   #define SQLITE_MALLOC(x)    malloc(x)
    58     91   #define SQLITE_FREE(x)      free(x)
    59     92   #define SQLITE_REALLOC(x,y) realloc((x),(y))
    60     93   
    61     94   #ifdef HAVE_MALLOC_USABLE_SIZE
    62     95   #include <malloc.h>
................................................................................
   180    213     return ROUND8(n);
   181    214   }
   182    215   
   183    216   /*
   184    217   ** Initialize this module.
   185    218   */
   186    219   static int sqlite3MemInit(void *NotUsed){
   187         -#if defined(__APPLE__)
          220  +#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
   188    221     int cpuCount;
   189    222     size_t len;
   190    223     if( _sqliteZone_ ){
   191    224       return SQLITE_OK;
   192    225     }
   193    226     len = sizeof(cpuCount);
   194    227     /* One usually wants to use hw.acctivecpu for MT decisions, but not here */