[foreign-jextract] RFR: 8241925: jextract should generate simple allocation, access API for C primitive types

Athijegannathan Sundararajan sundar at openjdk.java.net
Wed Apr 1 02:41:29 UTC 2020


On Tue, 31 Mar 2020 16:00:10 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> added static method helper classes to handle allocation, access ot C primitive types and C strings.
>
> src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/tool/resources/Cstring.java.template line 59:
> 
>> 58:
>> 59:     public String toString(MemoryAddress addr) {
>> 60:         StringBuilder buf = new StringBuilder();
> 
> This should be static

Yes, bug. Will fix and add test.

> test/jdk/tools/jextract/test8241925/LibTest8241925Test.java line 44:
> 
>> 43:     public void test() {
>> 44:         try (var scope = AllocationScope.unboundedNativeScope()) {
>> 45:             var addr = Cint.allocate(12, scope);
> 
> This looks really neat!

thanks!

> src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/tool/resources/C-X.java.template line 73:
> 
>> 72:     private static void copy(MemoryAddress addr, ${CARRIER}[] arr) {
>> 73:         for (int i = 0 ; i < arr.length; i++) {
>> 74:             arrayHandle.set(addr, (long)i, arr[i]);
> 
> This should use bulk copy (see my suggestion on CString::copy)

Will fix using bulk copy.

> doc/panama_jextract.md line 329:
> 
>> 328:         try (AllocationScope scope = AllocationScope.unboundedNativeScope()) {
>> 329:             var aPtr = Cdouble.allocateArray(a, scope);
>> 330:             var xPtr = Cdouble.allocateArray(x, scope);
> 
> Should we allocate arrays directly off heap and avoid the copy? To do that we might need another helper to create
> 'empty' arrays.

Yes, will add length accepting allocateArray utility and modify sample to use the same.

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/78


More information about the panama-dev mailing list