Skip to content

Commit

Permalink
Fix registerSequenceProducer and re-enable to Sequence API
Browse files Browse the repository at this point in the history
  • Loading branch information
luben committed Mar 27, 2024
1 parent 355e64a commit 77e74a7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/github/luben/zstd/Zstd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/github/luben/zstd/ZstdCompressCtx.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -306,7 +305,6 @@ public ZstdCompressCtx registerSequenceProducer(SequenceProducer producer) {
}
return this;
}
*/

/**
* Enable or disable sequence producer fallback
Expand Down
8 changes: 1 addition & 7 deletions src/main/native/jni_zstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/test/scala/Zstd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1413,5 +1412,4 @@ class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks {
}
}.get
}
*/
}

0 comments on commit 77e74a7

Please sign in to comment.