Fossil SCM
Update the delta_parse() table-valued function to better align with the code in the SQLite source tree.
Commit
921e7c1ec82bf6c68d05ce119ad7092f2cf7454f1cea7850c1590298da979871
Parent
ee6a2f0c21dd1ab…
1 file changed
+12
-11
+12
-11
| --- src/deltafunc.c | ||
| +++ src/deltafunc.c | ||
| @@ -166,15 +166,15 @@ | ||
| 166 | 166 | /* No additional information needed */ |
| 167 | 167 | }; |
| 168 | 168 | struct deltaparsevtab_cursor { |
| 169 | 169 | sqlite3_vtab_cursor base; /* Base class - must be first */ |
| 170 | 170 | 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 */ | |
| 173 | 174 | int eOp; /* Name of current operator */ |
| 174 | 175 | unsigned int a1, a2; /* Arguments to current operator */ |
| 175 | - int iNext; /* Next cursor value */ | |
| 176 | 176 | }; |
| 177 | 177 | |
| 178 | 178 | /* Operator names: |
| 179 | 179 | */ |
| 180 | 180 | static const char *const azOp[] = { |
| @@ -270,11 +270,11 @@ | ||
| 270 | 270 | /* |
| 271 | 271 | ** Constructor for a new deltaparsevtab_cursor object. |
| 272 | 272 | */ |
| 273 | 273 | static int deltaparsevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ |
| 274 | 274 | deltaparsevtab_cursor *pCur; |
| 275 | - pCur = sqlite3_malloc( sizeof(*pCur) ); | |
| 275 | + pCur = sqlite3_malloc64( sizeof(*pCur) ); | |
| 276 | 276 | if( pCur==0 ) return SQLITE_NOMEM; |
| 277 | 277 | memset(pCur, 0, sizeof(*pCur)); |
| 278 | 278 | *ppCursor = &pCur->base; |
| 279 | 279 | return SQLITE_OK; |
| 280 | 280 | } |
| @@ -314,18 +314,18 @@ | ||
| 314 | 314 | pCur->iNext = pCur->nDelta; |
| 315 | 315 | break; |
| 316 | 316 | } |
| 317 | 317 | pCur->a2 = deltaGetInt(&z, &i); |
| 318 | 318 | pCur->eOp = DELTAPARSE_OP_COPY; |
| 319 | - pCur->iNext = (int)(&z[1] - pCur->aDelta); | |
| 319 | + pCur->iNext = (i64)(&z[1] - pCur->aDelta); | |
| 320 | 320 | break; |
| 321 | 321 | } |
| 322 | 322 | case ':': { |
| 323 | 323 | z++; |
| 324 | 324 | pCur->a2 = (unsigned int)(z - pCur->aDelta); |
| 325 | 325 | pCur->eOp = DELTAPARSE_OP_INSERT; |
| 326 | - pCur->iNext = (int)(&z[pCur->a1] - pCur->aDelta); | |
| 326 | + pCur->iNext = (i64)(&z[pCur->a1] - pCur->aDelta); | |
| 327 | 327 | break; |
| 328 | 328 | } |
| 329 | 329 | case ';': { |
| 330 | 330 | pCur->eOp = DELTAPARSE_OP_CHECKSUM; |
| 331 | 331 | pCur->iNext = pCur->nDelta; |
| @@ -365,11 +365,11 @@ | ||
| 365 | 365 | } |
| 366 | 366 | case DELTAPARSEVTAB_A2: { |
| 367 | 367 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 368 | 368 | sqlite3_result_int(ctx, pCur->a2); |
| 369 | 369 | }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 ){ | |
| 371 | 371 | sqlite3_result_zeroblob(ctx, pCur->a1); |
| 372 | 372 | }else{ |
| 373 | 373 | sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, |
| 374 | 374 | SQLITE_TRANSIENT); |
| 375 | 375 | } |
| @@ -441,11 +441,11 @@ | ||
| 441 | 441 | pCur->a1 = pCur->a2 = 0; |
| 442 | 442 | pCur->iNext = pCur->nDelta; |
| 443 | 443 | return SQLITE_OK; |
| 444 | 444 | } |
| 445 | 445 | a++; |
| 446 | - pCur->iNext = (unsigned int)(a - pCur->aDelta); | |
| 446 | + pCur->iNext = (i64)(a - pCur->aDelta); | |
| 447 | 447 | return SQLITE_OK; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | /* |
| 451 | 451 | ** SQLite will invoke this method one or more times while planning a query |
| @@ -509,21 +509,22 @@ | ||
| 509 | 509 | |
| 510 | 510 | /* |
| 511 | 511 | ** Invoke this routine to register the various delta functions. |
| 512 | 512 | */ |
| 513 | 513 | int deltafunc_init(sqlite3 *db){ |
| 514 | + static const int enc = SQLITE_UTF8|SQLITE_INNOCUOUS; | |
| 514 | 515 | 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, | |
| 516 | 517 | deltaCreateFunc, 0, 0); |
| 517 | 518 | 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, | |
| 519 | 520 | deltaApplyFunc, 0, 0); |
| 520 | 521 | } |
| 521 | 522 | 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, | |
| 523 | 524 | deltaOutputSizeFunc, 0, 0); |
| 524 | 525 | } |
| 525 | 526 | if( rc==SQLITE_OK ){ |
| 526 | 527 | rc = sqlite3_create_module(db, "delta_parse", &deltaparsevtabModule, 0); |
| 527 | 528 | } |
| 528 | 529 | return rc; |
| 529 | 530 | } |
| 530 | 531 |
| --- 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 |