diff --git a/jna/src/main/java/org/pcre4j/jna/Pcre2.java b/jna/src/main/java/org/pcre4j/jna/Pcre2.java index b16a98b..6f52046 100644 --- a/jna/src/main/java/org/pcre4j/jna/Pcre2.java +++ b/jna/src/main/java/org/pcre4j/jna/Pcre2.java @@ -20,6 +20,7 @@ import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.LongByReference; +import com.sun.jna.ptr.PointerByReference; import org.pcre4j.api.IPcre2; import java.lang.reflect.Method; @@ -150,8 +151,10 @@ public int patternInfo(long code, int what, long[] where) { @Override public int patternInfo(long code, int what, ByteBuffer where) { - Pointer wherePtr = Native.getDirectBufferPointer(where); - return library.pcre2_pattern_info(new Pointer(code), what, wherePtr); + PointerByReference whereRef = new PointerByReference(); + int result = library.pcre2_pattern_info(new Pointer(code), what, whereRef.getPointer()); + where.put(whereRef.getValue().getByteArray(0, where.capacity())); + return result; } @Override diff --git a/test/src/main/java/org/pcre4j/test/Pcre2Tests.java b/test/src/main/java/org/pcre4j/test/Pcre2Tests.java index ea51079..90dc9fd 100644 --- a/test/src/main/java/org/pcre4j/test/Pcre2Tests.java +++ b/test/src/main/java/org/pcre4j/test/Pcre2Tests.java @@ -125,4 +125,16 @@ public void plainStringMatchNamedCapture() { }, ovector); } + @Test + public void nameTable() { + final var code = new Pcre2Code( + "(?42)", + EnumSet.noneOf(Pcre2CompileOption.class), + null + ); + final var nameTable = code.nameTable(); + assertEquals(1, nameTable.length); + assertEquals(new Pcre2Code.NameTableEntry(1, "number"), nameTable[0]); + } + }