aboutsummaryrefslogtreecommitdiff
path: root/src/malloc.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2014-09-15 15:34:31 +0000
committerdan <dan@noemail.net>2014-09-15 15:34:31 +0000
commitd4a80e6742921478b369a9537302bc586c79d812 (patch)
tree6731ece80e9d8851555cad39c555482f1db1a006 /src/malloc.c
parentee8d0b4111b47bd91e9d3280e8540d3a560b0cc7 (diff)
parent907214c8e83a3d1f35b6cce5768016089193b3c2 (diff)
downloadsqlite-d4a80e6742921478b369a9537302bc586c79d812.tar.gz
sqlite-d4a80e6742921478b369a9537302bc586c79d812.zip
Merge latest trunk changes with this branch.
FossilOrigin-Name: 55b8011d5b455927f5b92a3cb911fd909fb0edab
Diffstat (limited to 'src/malloc.c')
-rw-r--r--src/malloc.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/malloc.c b/src/malloc.c
index b4b70350f..daf646bc3 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -294,11 +294,9 @@ static int mallocWithAlarm(int n, void **pp){
** Allocate memory. This routine is like sqlite3_malloc() except that it
** assumes the memory subsystem has already been initialized.
*/
-void *sqlite3Malloc(int n){
+void *sqlite3Malloc(u64 n){
void *p;
- if( n<=0 /* IMP: R-65312-04917 */
- || n>=0x7fffff00
- ){
+ if( n==0 || n>=0x7fffff00 ){
/* A memory allocation of a number of bytes which is near the maximum
** signed integer value might cause an integer overflow inside of the
** xMalloc(). Hence we limit the maximum size to 0x7fffff00, giving
@@ -310,7 +308,7 @@ void *sqlite3Malloc(int n){
mallocWithAlarm(n, &p);
sqlite3_mutex_leave(mem0.mutex);
}else{
- p = sqlite3GlobalConfig.m.xMalloc(n);
+ p = sqlite3GlobalConfig.m.xMalloc((int)n);
}
assert( EIGHT_BYTE_ALIGNMENT(p) ); /* IMP: R-04675-44850 */
return p;
@@ -325,6 +323,12 @@ void *sqlite3_malloc(int n){
#ifndef SQLITE_OMIT_AUTOINIT
if( sqlite3_initialize() ) return 0;
#endif
+ return n<=0 ? 0 : sqlite3Malloc(n);
+}
+void *sqlite3_malloc64(sqlite3_uint64 n){
+#ifndef SQLITE_OMIT_AUTOINIT
+ if( sqlite3_initialize() ) return 0;
+#endif
return sqlite3Malloc(n);
}
@@ -458,6 +462,9 @@ int sqlite3DbMallocSize(sqlite3 *db, void *p){
return sqlite3GlobalConfig.m.xSize(p);
}
}
+sqlite3_uint64 sqlite3_msize(void *p){
+ return (sqlite3_uint64)sqlite3GlobalConfig.m.xSize(p);
+}
/*
** Free memory previously obtained from sqlite3Malloc().
@@ -519,13 +526,13 @@ void sqlite3DbFree(sqlite3 *db, void *p){
/*
** Change the size of an existing memory allocation
*/
-void *sqlite3Realloc(void *pOld, int nBytes){
+void *sqlite3Realloc(void *pOld, u64 nBytes){
int nOld, nNew, nDiff;
void *pNew;
if( pOld==0 ){
return sqlite3Malloc(nBytes); /* IMP: R-28354-25769 */
}
- if( nBytes<=0 ){
+ if( nBytes==0 ){
sqlite3_free(pOld); /* IMP: R-31593-10574 */
return 0;
}
@@ -537,7 +544,7 @@ void *sqlite3Realloc(void *pOld, int nBytes){
/* IMPLEMENTATION-OF: R-46199-30249 SQLite guarantees that the second
** argument to xRealloc is always a value returned by a prior call to
** xRoundup. */
- nNew = sqlite3GlobalConfig.m.xRoundup(nBytes);
+ nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes);
if( nOld==nNew ){
pNew = pOld;
}else if( sqlite3GlobalConfig.bMemstat ){
@@ -575,6 +582,13 @@ void *sqlite3_realloc(void *pOld, int n){
#ifndef SQLITE_OMIT_AUTOINIT
if( sqlite3_initialize() ) return 0;
#endif
+ if( n<0 ) n = 0;
+ return sqlite3Realloc(pOld, n);
+}
+void *sqlite3_realloc64(void *pOld, sqlite3_uint64 n){
+#ifndef SQLITE_OMIT_AUTOINIT
+ if( sqlite3_initialize() ) return 0;
+#endif
return sqlite3Realloc(pOld, n);
}
@@ -582,7 +596,7 @@ void *sqlite3_realloc(void *pOld, int n){
/*
** Allocate and zero memory.
*/
-void *sqlite3MallocZero(int n){
+void *sqlite3MallocZero(u64 n){
void *p = sqlite3Malloc(n);
if( p ){
memset(p, 0, n);
@@ -594,7 +608,7 @@ void *sqlite3MallocZero(int n){
** Allocate and zero memory. If the allocation fails, make
** the mallocFailed flag in the connection pointer.
*/
-void *sqlite3DbMallocZero(sqlite3 *db, int n){
+void *sqlite3DbMallocZero(sqlite3 *db, u64 n){
void *p = sqlite3DbMallocRaw(db, n);
if( p ){
memset(p, 0, n);
@@ -620,7 +634,7 @@ void *sqlite3DbMallocZero(sqlite3 *db, int n){
** In other words, if a subsequent malloc (ex: "b") worked, it is assumed
** that all prior mallocs (ex: "a") worked too.
*/
-void *sqlite3DbMallocRaw(sqlite3 *db, int n){
+void *sqlite3DbMallocRaw(sqlite3 *db, u64 n){
void *p;
assert( db==0 || sqlite3_mutex_held(db->mutex) );
assert( db==0 || db->pnBytesFreed==0 );
@@ -664,7 +678,7 @@ void *sqlite3DbMallocRaw(sqlite3 *db, int n){
** Resize the block of memory pointed to by p to n bytes. If the
** resize fails, set the mallocFailed flag in the connection object.
*/
-void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
+void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){
void *pNew = 0;
assert( db!=0 );
assert( sqlite3_mutex_held(db->mutex) );
@@ -701,7 +715,7 @@ void *sqlite3DbRealloc(sqlite3 *db, void *p, int n){
** Attempt to reallocate p. If the reallocation fails, then free p
** and set the mallocFailed flag in the database connection.
*/
-void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, int n){
+void *sqlite3DbReallocOrFree(sqlite3 *db, void *p, u64 n){
void *pNew;
pNew = sqlite3DbRealloc(db, p, n);
if( !pNew ){
@@ -731,7 +745,7 @@ char *sqlite3DbStrDup(sqlite3 *db, const char *z){
}
return zNew;
}
-char *sqlite3DbStrNDup(sqlite3 *db, const char *z, int n){
+char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){
char *zNew;
if( z==0 ){
return 0;