[foreign-jextract] [Rev 01] RFR: 8241925: jextract should generate simple allocation, access API for C primitive types
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Apr 1 10:28:08 UTC 2020
On Wed, 1 Apr 2020 02:55:42 GMT, Athijegannathan Sundararajan <sundar at openjdk.org> wrote:
>> added static method helper classes to handle allocation, access ot C primitive types and C strings.
>
> Athijegannathan Sundararajan has updated the pull request incrementally with one additional commit since the last
> revision:
> * added static modifier to Cstring.toString method. Added tests for Cstring methods
> * added length accepting allocateArray overloadeds and using the same in samples.
> * using bulk copy for array copy
> * fixed samples to use Cstring method instead of methods from Foreign.
Looks very good - some minor comments
doc/panama_jextract.md line 298:
> 297: try (AllocationScope scope = AllocationScope.unboundedNativeScope()) {
> 298: var a = Cdouble.allocateArray(m*n, scope);
> 299: var x = Cdouble.allocateArray(n, scope);
there are some indentation issues in this example
doc/panama_jextract.md line 303:
> 302: /* The elements of the first column */
> 303: Cdouble.set(a, 0, 1.0);
> 304: Cdouble.set(a, 1, 2.0);
Not sure whether `C_double` would be better than `Cdouble`, but we can tweak later
doc/panama_jextract.md line 330:
> 329: Cdouble.set(y, 2, 0.0);
> 330: Cdouble.set(y, 3, 0.0);
> 331: cblas_dgemv(Layout, transa, m, n, alpha, a, lda, x, incx, beta, y, incy);
We also need an helper that takes a MemorySegment, interprets it as a native double array and turns it into a Java
double array. e.g. double[] toJavaArray(MemorySegment)
Not needed here, but could be handy in other cases
doc/panama_jextract.md line 166:
> 165: // convert char* ptr from readline as Java String & print it
> 166: System.out.println("Hello, " + Cstring.toString(p));
> 167: }
I suggest calling this `toJavaString` to avoid confusion
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/78
More information about the panama-dev
mailing list