Skip to content

Commit

Permalink
Merge branch 'main' into feature/223-db-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
apismensky authored Feb 16, 2024
2 parents 941f460 + ad64f34 commit 3f692d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/gliwka/hyperscan/wrapper/Scanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public Scanner() {

private static class NativeScratch extends hs_scratch_t {
void registerDeallocator() {
hs_scratch_t p = new hs_scratch_t(this);
deallocator(() -> hs_free_scratch(p));
if (deallocator() != null) {
hs_scratch_t p = new hs_scratch_t(this);
deallocator(() -> hs_free_scratch(p));
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions src/test/java/com/gliwka/hyperscan/wrapper/ScannerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.gliwka.hyperscan.wrapper;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertFalse;

public class ScannerTest {

@Test
void oneScannerWithMultipleDatabases() throws Exception {
try (
Database dbA = Database.compile(new Expression("a"));
Database dbB = Database.compile(new Expression("b"));
Scanner scanner = new Scanner()
) {
scanner.allocScratch(dbA);
List<Match> matchesA = scanner.scan(dbA, "a");
assertFalse(matchesA.isEmpty());

scanner.allocScratch(dbB);
List<Match> matchesB = scanner.scan(dbB, "b");
assertFalse(matchesB.isEmpty());
}
}
}

0 comments on commit 3f692d5

Please sign in to comment.