From 77e74a758d6c4a78d9b44b73f94362dbb95432ec Mon Sep 17 00:00:00 2001 From: Luben Karavelov Date: Wed, 27 Mar 2024 22:08:45 +0000 Subject: [PATCH] Fix registerSequenceProducer and re-enable to Sequence API --- src/main/java/com/github/luben/zstd/Zstd.java | 5 ++--- .../java/com/github/luben/zstd/ZstdCompressCtx.java | 2 -- src/main/native/jni_zstd.c | 8 +------- src/test/scala/Zstd.scala | 10 ++++------ 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/github/luben/zstd/Zstd.java b/src/main/java/com/github/luben/zstd/Zstd.java index 8d819a8..c15c2e0 100644 --- a/src/main/java/com/github/luben/zstd/Zstd.java +++ b/src/main/java/com/github/luben/zstd/Zstd.java @@ -590,9 +590,8 @@ public static long decompressDirectByteBufferFastDict(ByteBuffer dst, int dstOff public static native int loadFastDictDecompress(long stream, ZstdDictDecompress dict); public static native int loadDictCompress(long stream, byte[] dict, int dict_size); public static native int loadFastDictCompress(long stream, ZstdDictCompress dict); - // TODO: Fix native compilation - //public static native void registerSequenceProducer(long stream, long seqProdState, long seqProdFunction); - // static native long getBuiltinSequenceProducer(); // Used in tests + public static native void registerSequenceProducer(long stream, long seqProdState, long seqProdFunction); + static native long getBuiltinSequenceProducer(); // Used in tests static native void generateSequences(long stream, long outSeqs, long outSeqsSize, long src, long srcSize); static native long getStubSequenceProducer(); // Used in tests public static native int setCompressionChecksums(long stream, boolean useChecksums); diff --git a/src/main/java/com/github/luben/zstd/ZstdCompressCtx.java b/src/main/java/com/github/luben/zstd/ZstdCompressCtx.java index ee9f345..ad34735 100644 --- a/src/main/java/com/github/luben/zstd/ZstdCompressCtx.java +++ b/src/main/java/com/github/luben/zstd/ZstdCompressCtx.java @@ -280,7 +280,6 @@ public ZstdCompressCtx setLong(int windowLog) { * Register an external sequence producer * @param producer the user-defined {@link SequenceProducer} to register. */ - /* TODO: fix compilation public ZstdCompressCtx registerSequenceProducer(SequenceProducer producer) { ensureOpen(); acquireSharedLock(); @@ -306,7 +305,6 @@ public ZstdCompressCtx registerSequenceProducer(SequenceProducer producer) { } return this; } - */ /** * Enable or disable sequence producer fallback diff --git a/src/main/native/jni_zstd.c b/src/main/native/jni_zstd.c index 85e145f..6e84701 100644 --- a/src/main/native/jni_zstd.c +++ b/src/main/native/jni_zstd.c @@ -293,7 +293,6 @@ JNIEXPORT jint JNICALL Java_com_github_luben_zstd_Zstd_loadFastDictCompress return ZSTD_CCtx_refCDict((ZSTD_CCtx *)(intptr_t) stream, cdict); } -/* size_t builtinSequenceProducer( void* sequenceProducerState, ZSTD_Sequence* outSeqs, size_t outSeqsCapacity, @@ -313,7 +312,6 @@ size_t builtinSequenceProducer( size_t numSeqs = ZSTD_generateSequences((ZSTD_CCtx *)sequenceProducerState, outSeqs, outSeqsCapacity, src, srcSize); return ZSTD_isError(numSeqs) ? ZSTD_SEQUENCE_PRODUCER_ERROR : numSeqs; } -*/ size_t stubSequenceProducer( void* sequenceProducerState, @@ -331,12 +329,10 @@ size_t stubSequenceProducer( * Method: getBuiltinSequenceProducer * Signature: ()J */ -/* TODO: fix error JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_Zstd_getBuiltinSequenceProducer (JNIEnv *env, jclass obj) { return (jlong)(intptr_t)&builtinSequenceProducer; } -*/ /* * Class: com_github_luben_zstd_Zstd @@ -353,14 +349,12 @@ JNIEXPORT jlong JNICALL Java_com_github_luben_zstd_Zstd_getStubSequenceProducer * Method: registerSequenceProducer * Signature: (JJJ)V */ -/* TODO: fix error JNIEXPORT void JNICALL Java_com_github_luben_zstd_Zstd_registerSequenceProducer (JNIEnv *env, jclass obj, jlong stream, jlong seqProdState, jlong seqProdFunction) { ZSTD_registerSequenceProducer((ZSTD_CCtx *)(intptr_t) stream, (void *)(intptr_t) seqProdState, - (ZSTD_sequenceProducer_F *)(intptr_t) seqProdFunction); + (ZSTD_sequenceProducer_F)(intptr_t) seqProdFunction); } -*/ /* * Class: com_github_luben_zstd_Zstd diff --git a/src/test/scala/Zstd.scala b/src/test/scala/Zstd.scala index 540b1ca..31d68ea 100644 --- a/src/test/scala/Zstd.scala +++ b/src/test/scala/Zstd.scala @@ -1237,7 +1237,6 @@ class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks { } }.get - /* TODO: fix getBuiltinSequenceProd it should "be able to use a sequence producer" in { Using.Manager { use => val cctx = use(new ZstdCompressCtx()) @@ -1323,8 +1322,8 @@ class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks { Zstd.getStubSequenceProducer() } - def createState(): Long = { 0 } - def freeState(@unused state: Long) = { 0 } + def createState(): Long = 0 + def freeState(@unused state: Long) {} } cctx.registerSequenceProducer(seqProd) @@ -1367,8 +1366,8 @@ class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks { Zstd.getStubSequenceProducer() } - def createState(): Long = { 0 } - def freeState(@unused state: Long) = { 0 } + def createState(): Long = 0 + def freeState(@unused state: Long) {} } cctx.registerSequenceProducer(seqProd) @@ -1413,5 +1412,4 @@ class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks { } }.get } - */ }