Skip to content

Commit

Permalink
Use the 64-bit memory allocator interfaces in extensions, whenever po…
Browse files Browse the repository at this point in the history
…ssible.
  • Loading branch information
D. Richard Hipp committed Apr 13, 2019
1 parent 252913b commit 1db2980
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
7 changes: 4 additions & 3 deletions ext/fts3/fts3_snippet.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ struct StrBuffer {
*/
static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
MatchinfoBuffer *pRet;
int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
int nStr = (int)strlen(zMatchinfo);
sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
+ sizeof(MatchinfoBuffer);
sqlite3_int64 nStr = strlen(zMatchinfo);

pRet = sqlite3_malloc(nByte + nStr+1);
pRet = sqlite3_malloc64(nByte + nStr+1);
if( pRet ){
memset(pRet, 0, nByte);
pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
Expand Down
6 changes: 3 additions & 3 deletions ext/fts3/fts3_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,14 @@ static int testTokenizerNext(
}else{
/* Advance to the end of the token */
const char *pToken = p;
int nToken;
sqlite3_int64 nToken;
while( p<pEnd && testIsTokenChar(*p) ) p++;
nToken = (int)(p-pToken);
nToken = (sqlite3_int64)(p-pToken);

/* Copy the token into the buffer */
if( nToken>pCsr->nBuffer ){
sqlite3_free(pCsr->aBuffer);
pCsr->aBuffer = sqlite3_malloc(nToken);
pCsr->aBuffer = sqlite3_malloc64(nToken);
}
if( pCsr->aBuffer==0 ){
rc = SQLITE_NOMEM;
Expand Down
2 changes: 1 addition & 1 deletion ext/fts3/fts3_tokenize_vtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static int fts3tokFilterMethod(
if( idxNum==1 ){
const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
int nByte = sqlite3_value_bytes(apVal[0]);
pCsr->zInput = sqlite3_malloc(nByte+1);
pCsr->zInput = sqlite3_malloc64(nByte+1);
if( pCsr->zInput==0 ){
rc = SQLITE_NOMEM;
}else{
Expand Down
4 changes: 2 additions & 2 deletions ext/fts3/fts3_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ int sqlite3Fts3InitTokenizer(
int iArg = 0;
z = &z[n+1];
while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
int nNew = sizeof(char *)*(iArg+1);
char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
if( !aNew ){
sqlite3_free(zCopy);
sqlite3_free((void *)aArg);
Expand Down
19 changes: 10 additions & 9 deletions ext/fts3/fts3_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -1752,8 +1752,9 @@ int sqlite3Fts3SegReaderPending(
}

if( nElem>0 ){
int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
pReader = (Fts3SegReader *)sqlite3_malloc(nByte);
sqlite3_int64 nByte;
nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
pReader = (Fts3SegReader *)sqlite3_malloc64(nByte);
if( !pReader ){
rc = SQLITE_NOMEM;
}else{
Expand Down Expand Up @@ -3367,7 +3368,7 @@ static void fts3InsertDocsize(
int rc; /* Result code from subfunctions */

if( *pRC ) return;
pBlob = sqlite3_malloc( 10*p->nColumn );
pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn );
if( pBlob==0 ){
*pRC = SQLITE_NOMEM;
return;
Expand Down Expand Up @@ -3417,7 +3418,7 @@ static void fts3UpdateDocTotals(
const int nStat = p->nColumn+2;

if( *pRC ) return;
a = sqlite3_malloc( (sizeof(u32)+10)*nStat );
a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat );
if( a==0 ){
*pRC = SQLITE_NOMEM;
return;
Expand Down Expand Up @@ -3538,8 +3539,8 @@ static int fts3DoRebuild(Fts3Table *p){
}

if( rc==SQLITE_OK ){
int nByte = sizeof(u32) * (p->nColumn+1)*3;
aSz = (u32 *)sqlite3_malloc(nByte);
sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
aSz = (u32 *)sqlite3_malloc64(nByte);
if( aSz==0 ){
rc = SQLITE_NOMEM;
}else{
Expand Down Expand Up @@ -3605,12 +3606,12 @@ static int fts3IncrmergeCsr(
){
int rc; /* Return Code */
sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
int nByte; /* Bytes allocated at pCsr->apSegment[] */
sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */

/* Allocate space for the Fts3MultiSegReader.aCsr[] array */
memset(pCsr, 0, sizeof(*pCsr));
nByte = sizeof(Fts3SegReader *) * nSeg;
pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte);
pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte);

if( pCsr->apSegment==0 ){
rc = SQLITE_NOMEM;
Expand Down Expand Up @@ -5590,7 +5591,7 @@ int sqlite3Fts3UpdateMethod(
}

/* Allocate space to hold the change in document sizes */
aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 );
aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
if( aSzDel==0 ){
rc = SQLITE_NOMEM;
goto update_out;
Expand Down
2 changes: 1 addition & 1 deletion ext/fts5/fts5_tokenize.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ static int fts5UnicodeCreate(

p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
p->nFold = 64;
p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
p->aFold = sqlite3_malloc64(p->nFold * sizeof(char));
if( p->aFold==0 ){
rc = SQLITE_NOMEM;
}
Expand Down
20 changes: 10 additions & 10 deletions ext/rtree/geopoly.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static GeoPoly *geopolyParseJson(const unsigned char *z, int *pRc){
GeoPoly *pOut;
int x = 1;
s.nVertex--; /* Remove the redundant vertex at the end */
pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) );
pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) );
x = 1;
if( pOut==0 ) goto parse_json_err;
pOut->nVertex = s.nVertex;
Expand Down Expand Up @@ -655,7 +655,7 @@ static GeoPoly *geopolyBBox(
if( pRc ) *pRc = SQLITE_OK;
if( aCoord==0 ){
geopolyBboxFill:
pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4));
if( pOut==0 ){
sqlite3_free(p);
if( context ) sqlite3_result_error_nomem(context);
Expand Down Expand Up @@ -1051,9 +1051,9 @@ static GeoSegment *geopolySortSegmentsByYAndC(GeoSegment *pList){
** Determine the overlap between two polygons
*/
static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
int nVertex = p1->nVertex + p2->nVertex + 2;
sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2;
GeoOverlap *p;
int nByte;
sqlite3_int64 nByte;
GeoEvent *pThisEvent;
double rX;
int rc = 0;
Expand All @@ -1065,7 +1065,7 @@ static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
nByte = sizeof(GeoEvent)*nVertex*2
+ sizeof(GeoSegment)*nVertex
+ sizeof(GeoOverlap);
p = sqlite3_malloc( nByte );
p = sqlite3_malloc64( nByte );
if( p==0 ) return -1;
p->aEvent = (GeoEvent*)&p[1];
p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
Expand Down Expand Up @@ -1224,18 +1224,18 @@ static int geopolyInit(
){
int rc = SQLITE_OK;
Rtree *pRtree;
int nDb; /* Length of string argv[1] */
int nName; /* Length of string argv[2] */
sqlite3_int64 nDb; /* Length of string argv[1] */
sqlite3_int64 nName; /* Length of string argv[2] */
sqlite3_str *pSql;
char *zSql;
int ii;

sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);

/* Allocate the sqlite3_vtab structure */
nDb = (int)strlen(argv[1]);
nName = (int)strlen(argv[2]);
pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
nDb = strlen(argv[1]);
nName = strlen(argv[2]);
pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
if( !pRtree ){
return SQLITE_NOMEM;
}
Expand Down

0 comments on commit 1db2980

Please sign in to comment.