Skip to content

Commit

Permalink
Addresses #220
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Pismenskiy authored and gliwka committed Feb 11, 2024
1 parent 3c0e478 commit ad64f34
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 ad64f34

Please sign in to comment.