Fossil SCM

Update the delta_parse() table-valued function to better align with the code in the SQLite source tree.

drh 2026-05-19 11:16 UTC trunk
Commit 921e7c1ec82bf6c68d05ce119ad7092f2cf7454f1cea7850c1590298da979871
1 file changed +12 -11
+12 -11
--- src/deltafunc.c
+++ src/deltafunc.c
@@ -166,15 +166,15 @@
166166
/* No additional information needed */
167167
};
168168
struct deltaparsevtab_cursor {
169169
sqlite3_vtab_cursor base; /* Base class - must be first */
170170
char *aDelta; /* The delta being parsed */
171
- int nDelta; /* Number of bytes in the delta */
172
- int iCursor; /* Current cursor location */
171
+ i64 iCursor; /* Current cursor location */
172
+ i64 iNext; /* Next cursor value */
173
+ i64 nDelta; /* Number of bytes in the delta */
173174
int eOp; /* Name of current operator */
174175
unsigned int a1, a2; /* Arguments to current operator */
175
- int iNext; /* Next cursor value */
176176
};
177177
178178
/* Operator names:
179179
*/
180180
static const char *const azOp[] = {
@@ -270,11 +270,11 @@
270270
/*
271271
** Constructor for a new deltaparsevtab_cursor object.
272272
*/
273273
static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
274274
deltaparsevtab_cursor *pCur;
275
- pCur = sqlite3_malloc( sizeof(*pCur) );
275
+ pCur = sqlite3_malloc64( sizeof(*pCur) );
276276
if( pCur==0 ) return SQLITE_NOMEM;
277277
memset(pCur, 0, sizeof(*pCur));
278278
*ppCursor = &pCur->base;
279279
return SQLITE_OK;
280280
}
@@ -314,18 +314,18 @@
314314
pCur->iNext = pCur->nDelta;
315315
break;
316316
}
317317
pCur->a2 = deltaGetInt(&z, &i);
318318
pCur->eOp = DELTAPARSE_OP_COPY;
319
- pCur->iNext = (int)(&z[1] - pCur->aDelta);
319
+ pCur->iNext = (i64)(&z[1] - pCur->aDelta);
320320
break;
321321
}
322322
case ':': {
323323
z++;
324324
pCur->a2 = (unsigned int)(z - pCur->aDelta);
325325
pCur->eOp = DELTAPARSE_OP_INSERT;
326
- pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta);
326
+ pCur->iNext = (i64)(&z[pCur->a1] - pCur->aDelta);
327327
break;
328328
}
329329
case ';': {
330330
pCur->eOp = DELTAPARSE_OP_CHECKSUM;
331331
pCur->iNext = pCur->nDelta;
@@ -365,11 +365,11 @@
365365
}
366366
case DELTAPARSEVTAB_A2: {
367367
if( pCur->eOp==DELTAPARSE_OP_COPY ){
368368
sqlite3_result_int(ctx, pCur->a2);
369369
}else if( pCur->eOp==DELTAPARSE_OP_INSERT ){
370
- if( pCur->a2 + pCur->a1 > pCur->nDelta ){
370
+ if( (i64)pCur->a2 + (i64)pCur->a1 > pCur->nDelta ){
371371
sqlite3_result_zeroblob(ctx, pCur->a1);
372372
}else{
373373
sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1,
374374
SQLITE_TRANSIENT);
375375
}
@@ -441,11 +441,11 @@
441441
pCur->a1 = pCur->a2 = 0;
442442
pCur->iNext = pCur->nDelta;
443443
return SQLITE_OK;
444444
}
445445
a++;
446
- pCur->iNext = (unsigned int)(a - pCur->aDelta);
446
+ pCur->iNext = (i64)(a - pCur->aDelta);
447447
return SQLITE_OK;
448448
}
449449
450450
/*
451451
** SQLite will invoke this method one or more times while planning a query
@@ -509,21 +509,22 @@
509509
510510
/*
511511
** Invoke this routine to register the various delta functions.
512512
*/
513513
int deltafunc_init(sqlite3 *db){
514
+ static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS;
514515
int rc = SQLITE_OK;
515
- rc = sqlite3_create_function(db, "delta_create", 2, SQLITE_UTF8, 0,
516
+ rc = sqlite3_create_function(db, "delta_create", 2, enc, 0,
516517
deltaCreateFunc, 0, 0);
517518
if( rc==SQLITE_OK ){
518
- rc = sqlite3_create_function(db, "delta_apply", 2, SQLITE_UTF8, 0,
519
+ rc = sqlite3_create_function(db, "delta_apply", 2, enc, 0,
519520
deltaApplyFunc, 0, 0);
520521
}
521522
if( rc==SQLITE_OK ){
522
- rc = sqlite3_create_function(db, "delta_output_size", 1, SQLITE_UTF8, 0,
523
+ rc = sqlite3_create_function(db, "delta_output_size", 1, enc, 0,
523524
deltaOutputSizeFunc, 0, 0);
524525
}
525526
if( rc==SQLITE_OK ){
526527
rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0);
527528
}
528529
return rc;
529530
}
530531
--- src/deltafunc.c
+++ src/deltafunc.c
@@ -166,15 +166,15 @@
166 /* No additional information needed */
167 };
168 struct deltaparsevtab_cursor {
169 sqlite3_vtab_cursor base; /* Base class - must be first */
170 char *aDelta; /* The delta being parsed */
171 int nDelta; /* Number of bytes in the delta */
172 int iCursor; /* Current cursor location */
 
173 int eOp; /* Name of current operator */
174 unsigned int a1, a2; /* Arguments to current operator */
175 int iNext; /* Next cursor value */
176 };
177
178 /* Operator names:
179 */
180 static const char *const azOp[] = {
@@ -270,11 +270,11 @@
270 /*
271 ** Constructor for a new deltaparsevtab_cursor object.
272 */
273 static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
274 deltaparsevtab_cursor *pCur;
275 pCur = sqlite3_malloc( sizeof(*pCur) );
276 if( pCur==0 ) return SQLITE_NOMEM;
277 memset(pCur, 0, sizeof(*pCur));
278 *ppCursor = &pCur->base;
279 return SQLITE_OK;
280 }
@@ -314,18 +314,18 @@
314 pCur->iNext = pCur->nDelta;
315 break;
316 }
317 pCur->a2 = deltaGetInt(&z, &i);
318 pCur->eOp = DELTAPARSE_OP_COPY;
319 pCur->iNext = (int)(&z[1] - pCur->aDelta);
320 break;
321 }
322 case ':': {
323 z++;
324 pCur->a2 = (unsigned int)(z - pCur->aDelta);
325 pCur->eOp = DELTAPARSE_OP_INSERT;
326 pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta);
327 break;
328 }
329 case ';': {
330 pCur->eOp = DELTAPARSE_OP_CHECKSUM;
331 pCur->iNext = pCur->nDelta;
@@ -365,11 +365,11 @@
365 }
366 case DELTAPARSEVTAB_A2: {
367 if( pCur->eOp==DELTAPARSE_OP_COPY ){
368 sqlite3_result_int(ctx, pCur->a2);
369 }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){
370 if( pCur->a2 + pCur->a1 > pCur->nDelta ){
371 sqlite3_result_zeroblob(ctx, pCur->a1);
372 }else{
373 sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1,
374 SQLITE_TRANSIENT);
375 }
@@ -441,11 +441,11 @@
441 pCur->a1 = pCur->a2 = 0;
442 pCur->iNext = pCur->nDelta;
443 return SQLITE_OK;
444 }
445 a++;
446 pCur->iNext = (unsigned int)(a - pCur->aDelta);
447 return SQLITE_OK;
448 }
449
450 /*
451 ** SQLite will invoke this method one or more times while planning a query
@@ -509,21 +509,22 @@
509
510 /*
511 ** Invoke this routine to register the various delta functions.
512 */
513 int deltafunc_init(sqlite3 *db){
 
514 int rc = SQLITE_OK;
515 rc = sqlite3_create_function(db, "delta_create", 2, SQLITE_UTF8, 0,
516 deltaCreateFunc, 0, 0);
517 if( rc==SQLITE_OK ){
518 rc = sqlite3_create_function(db, "delta_apply", 2, SQLITE_UTF8, 0,
519 deltaApplyFunc, 0, 0);
520 }
521 if( rc==SQLITE_OK ){
522 rc = sqlite3_create_function(db, "delta_output_size", 1, SQLITE_UTF8, 0,
523 deltaOutputSizeFunc, 0, 0);
524 }
525 if( rc==SQLITE_OK ){
526 rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0);
527 }
528 return rc;
529 }
530
--- src/deltafunc.c
+++ src/deltafunc.c
@@ -166,15 +166,15 @@
166 /* No additional information needed */
167 };
168 struct deltaparsevtab_cursor {
169 sqlite3_vtab_cursor base; /* Base class - must be first */
170 char *aDelta; /* The delta being parsed */
171 i64 iCursor; /* Current cursor location */
172 i64 iNext; /* Next cursor value */
173 i64 nDelta; /* Number of bytes in the delta */
174 int eOp; /* Name of current operator */
175 unsigned int a1, a2; /* Arguments to current operator */
 
176 };
177
178 /* Operator names:
179 */
180 static const char *const azOp[] = {
@@ -270,11 +270,11 @@
270 /*
271 ** Constructor for a new deltaparsevtab_cursor object.
272 */
273 static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
274 deltaparsevtab_cursor *pCur;
275 pCur = sqlite3_malloc64( sizeof(*pCur) );
276 if( pCur==0 ) return SQLITE_NOMEM;
277 memset(pCur, 0, sizeof(*pCur));
278 *ppCursor = &pCur->base;
279 return SQLITE_OK;
280 }
@@ -314,18 +314,18 @@
314 pCur->iNext = pCur->nDelta;
315 break;
316 }
317 pCur->a2 = deltaGetInt(&z, &i);
318 pCur->eOp = DELTAPARSE_OP_COPY;
319 pCur->iNext = (i64)(&z[1] - pCur->aDelta);
320 break;
321 }
322 case ':': {
323 z++;
324 pCur->a2 = (unsigned int)(z - pCur->aDelta);
325 pCur->eOp = DELTAPARSE_OP_INSERT;
326 pCur->iNext = (i64)(&z[pCur->a1] - pCur->aDelta);
327 break;
328 }
329 case ';': {
330 pCur->eOp = DELTAPARSE_OP_CHECKSUM;
331 pCur->iNext = pCur->nDelta;
@@ -365,11 +365,11 @@
365 }
366 case DELTAPARSEVTAB_A2: {
367 if( pCur->eOp==DELTAPARSE_OP_COPY ){
368 sqlite3_result_int(ctx, pCur->a2);
369 }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){
370 if( (i64)pCur->a2 + (i64)pCur->a1 > pCur->nDelta ){
371 sqlite3_result_zeroblob(ctx, pCur->a1);
372 }else{
373 sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1,
374 SQLITE_TRANSIENT);
375 }
@@ -441,11 +441,11 @@
441 pCur->a1 = pCur->a2 = 0;
442 pCur->iNext = pCur->nDelta;
443 return SQLITE_OK;
444 }
445 a++;
446 pCur->iNext = (i64)(a - pCur->aDelta);
447 return SQLITE_OK;
448 }
449
450 /*
451 ** SQLite will invoke this method one or more times while planning a query
@@ -509,21 +509,22 @@
509
510 /*
511 ** Invoke this routine to register the various delta functions.
512 */
513 int deltafunc_init(sqlite3 *db){
514 static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS;
515 int rc = SQLITE_OK;
516 rc = sqlite3_create_function(db, "delta_create", 2, enc, 0,
517 deltaCreateFunc, 0, 0);
518 if( rc==SQLITE_OK ){
519 rc = sqlite3_create_function(db, "delta_apply", 2, enc, 0,
520 deltaApplyFunc, 0, 0);
521 }
522 if( rc==SQLITE_OK ){
523 rc = sqlite3_create_function(db, "delta_output_size", 1, enc, 0,
524 deltaOutputSizeFunc, 0, 0);
525 }
526 if( rc==SQLITE_OK ){
527 rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0);
528 }
529 return rc;
530 }
531

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button