From: dan Date: Sat, 17 Feb 2018 19:38:02 +0000 (+0000) Subject: Add support for compression types "lz4" and "lz4hc" to the zonefile module. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aac12cb868fa07ddc10e4d45535cb08beada2cf7;p=thirdparty%2Fsqlite.git Add support for compression types "lz4" and "lz4hc" to the zonefile module. FossilOrigin-Name: bbe5b21ffab3cd312680ca9f179c5847790c17fb91d4174985153c6c398d48e3 --- diff --git a/ext/zonefile/zonefile.c b/ext/zonefile/zonefile.c index 371971f9c9..e2c1bc467f 100644 --- a/ext/zonefile/zonefile.c +++ b/ext/zonefile/zonefile.c @@ -132,10 +132,7 @@ static int zfZstdCompress( *pnDest = (int)rc; return SQLITE_OK; } -static int zfZstdUncompressSize( - void *p, - const u8 *aSrc, int nSrc -){ +static int zfZstdUncompressSize(void *p, const u8 *aSrc, int nSrc){ return (int)ZSTD_getFrameContentSize(aSrc, (size_t)nSrc); } static int zfZstdUncompress( @@ -219,10 +216,7 @@ static int zfZstddictCompress( *pnDest = (int)rc; return SQLITE_OK; } -static int zfZstddictUncompressSize( - void *p, - const u8 *aSrc, int nSrc -){ +static int zfZstddictUncompressSize(void *p, const u8 *aSrc, int nSrc){ return (int)ZSTD_getFrameContentSize(aSrc, (size_t)nSrc); } static int zfZstddictUncompress( @@ -239,6 +233,57 @@ static int zfZstddictUncompress( } #endif +#ifdef SQLITE_HAVE_LZ4 +#include +#include +static int zfLz4Open(void **pp, u8 *aDict, int nDict){ + *pp = 0; + return SQLITE_OK; +} +static void zfLz4Close(void *p){ +} +static int zfLz4CompressBound(void *p, int nSrc){ + return (int)LZ4_compressBound((uLong)nSrc) + 4; +} +static int zfLz4Uncompress( + void *p, + u8 *aDest, int nDest, + const u8 *aSrc, int nSrc +){ + int rc = LZ4_decompress_safe( + (const char*)&aSrc[4], (char*)aDest, nSrc-4, nDest + ); + return rc==nDest ? SQLITE_OK : SQLITE_ERROR; +} +static int zfLz4Compress( + void *p, + u8 *aDest, int *pnDest, + const u8 *aSrc, int nSrc +){ + int rc = LZ4_compress_default( + (const char*)aSrc, (char*)&aDest[4], nSrc, (*pnDest - 4) + ); + *pnDest = rc+4; + zonefilePut32(aDest, nSrc); + return rc==0 ? SQLITE_ERROR : SQLITE_OK; +} +static int zfLz4UncompressSize(void *p, const u8 *aSrc, int nSrc){ + return (int)zonefileGet32(aSrc); +} +static int zfLz4hcCompress( + void *p, + u8 *aDest, int *pnDest, + const u8 *aSrc, int nSrc +){ + int rc = LZ4_compress_HC( + (const char*)aSrc, (char*)&aDest[4], nSrc, *pnDest, 0 + ); + *pnDest = rc+4; + zonefilePut32(aDest, nSrc); + return rc==0 ? SQLITE_ERROR : SQLITE_OK; +} +#endif + typedef struct ZonefileCompress ZonefileCompress; static struct ZonefileCompress { int eType; @@ -283,10 +328,16 @@ static struct ZonefileCompress { #endif /* SQLITE_HAVE_BROTLI */ #ifdef SQLITE_HAVE_LZ4 { ZONEFILE_COMPRESSION_LZ4, "lz4", - 0, 0, 0, 0, 0, 0, 0 + zfLz4Open, zfLz4Close, + 0, + zfLz4CompressBound, zfLz4Compress, + zfLz4UncompressSize, zfLz4Uncompress }, { ZONEFILE_COMPRESSION_LZ4HC, "lz4hc", - 0, 0, 0, 0, 0, 0, 0 + zfLz4Open, zfLz4Close, + 0, + zfLz4CompressBound, zfLz4hcCompress, + zfLz4UncompressSize, zfLz4Uncompress }, #endif /* SQLITE_HAVE_LZ4 */ }; @@ -634,19 +685,21 @@ static int zonefileAppendCompressed( ZonefileBuffer *pFrom /* Input buffer */ ){ int rc = SQLITE_OK; - if( pMethod->eType==ZONEFILE_COMPRESSION_NONE ){ - if( zonefileBufferGrow(pCtx, pTo, pFrom->n) ){ - rc = SQLITE_ERROR; + if( pFrom->n ){ + if( pMethod->eType==ZONEFILE_COMPRESSION_NONE ){ + if( zonefileBufferGrow(pCtx, pTo, pFrom->n) ){ + rc = SQLITE_ERROR; + }else{ + zonefileAppendBlob(pTo, pFrom->a, pFrom->n); + } }else{ - zonefileAppendBlob(pTo, pFrom->a, pFrom->n); - } - }else{ - int nReq = pMethod->xCompressBound(pCmp, pFrom->n); - if( zonefileBufferGrow(pCtx, pTo, nReq) ) return SQLITE_ERROR; - rc = pMethod->xCompress(pCmp, &pTo->a[pTo->n], &nReq, pFrom->a, pFrom->n); - pTo->n += nReq; - if( rc!=SQLITE_OK ){ - return rc; + int nReq = pMethod->xCompressBound(pCmp, pFrom->n); + if( zonefileBufferGrow(pCtx, pTo, nReq) ) return SQLITE_ERROR; + rc = pMethod->xCompress(pCmp, &pTo->a[pTo->n], &nReq, pFrom->a, pFrom->n); + pTo->n += nReq; + if( rc!=SQLITE_OK ){ + return rc; + } } } return SQLITE_OK; @@ -1282,7 +1335,7 @@ static int zonefileLoadIndex( *paIdx = aIdx; *pnIdx = nIdx; - return SQLITE_OK; + return rc; } diff --git a/manifest b/manifest index 544b0d61ff..20b7231d08 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\scompression\smethods\s"zstd"\sand\s"zstd_global_dict". -D 2018-02-17T18:33:43.145 +C Add\ssupport\sfor\scompression\stypes\s"lz4"\sand\s"lz4hc"\sto\sthe\szonefile\smodule. +D 2018-02-17T19:38:02.757 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7a3f714b4fcf793108042b7b0a5c720b0b310ec84314d61ba7f3f49f27e550ea @@ -409,7 +409,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F ext/zonefile/README.md 387ad2b748e98eeea21fd4dbb609fefe313263fadb3fc6c01c512b4c95e55ae4 -F ext/zonefile/zonefile.c 3954cdaeae3ce5018be5e75022cbd5d142245828a8396ae35db64c2b379f3205 +F ext/zonefile/zonefile.c cb0e2d294bc064bd995e9df7737636395e3101b17de688b2cf0e2159e561482c F ext/zonefile/zonefile1.test 0f84e56cd4f7b2c05443d1a2632c20ef635cc7f92de2868d92a2a6c09a9258ad F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 @@ -1708,7 +1708,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 72b8a7ef98d84460718378b9d17477599df39b4216015f8967674dd02b54b406 -R 3137d370c8b0ed559bfb7417aaf06af5 +P a993a50bb8d5a3bf7cf79e09204814e172ba0bf9b3949e81912ef83f0d4bb44e +R 446a2537d684855afb526eb1141b7e7d U dan -Z cfd4dcc32b639975b3448fc063f18d5e +Z 61481f5925196a4938887596830579d3 diff --git a/manifest.uuid b/manifest.uuid index b20cc577b1..cfb2a80aef 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a993a50bb8d5a3bf7cf79e09204814e172ba0bf9b3949e81912ef83f0d4bb44e \ No newline at end of file +bbe5b21ffab3cd312680ca9f179c5847790c17fb91d4174985153c6c398d48e3 \ No newline at end of file