<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>I guess it depends on what you mean by boilerplate.</p>
    <p>In the link you include the Java code just has a single code to
      the "sayHello", so boilerplate-wise seems good :-)</p>
    <p>That said, the goal of Panama is that of (mechanically) binding
      to native libraries (esp. those written in C) w/o the need of
      intermediate C code (unlike JNI). That is, what Panama provides is
      similar to what's been done in other languages, see Python's
      ctypes library [1]. This approach has been used successfully in a
      lot of real world libraries and frameworks (see the links in [2]).
      <br>
    </p>
    <p>Given all this, I think that a better "hello world" for Panama
      would be to call a function in some _existing_ library. One
      obvious, simple enough, example would be the standard library
      function "strlen" (the document I shared in my previous emails
      contains code that does exactly that), which can be done 100% in
      Java (albeit using a low-level API).<br>
    </p>
    <p>Now, it might be that Panama does not 100% satisfy your needs,
      and that's ok too. Maybe you are after something that is
      higher-level than what Panama provides. If that's the case, the
      fact that Panama is low-level is a good thing, because it means
      that a new breed of frameworks can be built on top, providing
      higher-level ways to interact with native code, w/o the need to
      generate JNI glue code. JPassport [3] is one such framework, but I
      believe (and hope!) that JNR and JNA might also, one day, be
      rebuilt on top of Panama and take advantage of the performance
      model provided by it.</p>
    <p>I hope this clarifies what Panama is really about and what you
      can expect from it. Finally, note that, while the jextract tool
      might change, the Foreign Function and Memory API [4] is
      relatively stable now, and we don't expect it to change much at
      this point.</p>
    <p>Cheers<br>
      Maurizio</p>
    <p>[1] - <a class="moz-txt-link-freetext" href="https://docs.python.org/3/library/ctypes.html">https://docs.python.org/3/library/ctypes.html</a><br>
      [2] -
      <a class="moz-txt-link-freetext" href="https://mail.openjdk.org/pipermail/panama-dev/2022-December/018182.html">https://mail.openjdk.org/pipermail/panama-dev/2022-December/018182.html</a><br>
      [3] - <a class="moz-txt-link-freetext" href="https://github.com/boulder-on/JPassport">https://github.com/boulder-on/JPassport</a><br>
      [4] - <a class="moz-txt-link-freetext" href="https://openjdk.org/jeps/442">https://openjdk.org/jeps/442</a><br>
    </p>
    <div class="moz-cite-prefix">On 25/04/2023 20:17, Rebecca Ahlvarsson
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CALRWBvjmMJRcJoKcmhmF3j+pOVon6WfFzUhu+9EGyvDYor-LgA@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">There is a lot of boilerplate still needed. And I
          somehow miss the native method declaration. But I understand
          this is a work in progress and It will improve in terms of
          simplicity.
          <div><br>
          </div>
          <div>See here: <a href="https://urldefense.com/v3/__https://stackoverflow.com/questions/76103402/using-jextract-and-panama-to-call-a-custom-made-c-function-from-java__;!!ACWV5N9M2RV99hQ!PQrjj3CR9v7gdn_FICf8CJtI8UV6w40YznqoQu2VXGjTFWWzIQ430MzpVOtiyeqNbrqXyx6Josesc3S4ANztAEtDYfsH$" moz-do-not-send="true">https://stackoverflow.com/questions/76103402/using-jextract-and-panama-to-call-a-custom-made-c-function-from-java</a><br>
          </div>
          <div><br>
          </div>
          <div><span style="color:rgb(136,136,136)">-Rebecca</span><br>
          </div>
          <div><br>
          </div>
        </div>
        <br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Tue, Apr 25, 2023 at
            3:16 PM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com" moz-do-not-send="true" class="moz-txt-link-freetext">maurizio.cimadamore@oracle.com</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
            <div>
              <p>Hi Rebecca,<br>
                I believe neither JNA nor JNR support C++, so I'm not
                100% what you mean here.</p>
              <p>You would at the very least need to add "extern C" to
                your function declaration, to make sure that no mangling
                occurs.</p>
              <p>Before I answer further, please clarify what you would
                like to achieve - if you really want to call a C++
                library using Panama and jextract, I'm afraid that's not
                possible at the moment (as is the case for the other
                frameworks you mentioned).</p>
              <p>If you are ok adding "extern C" or, if C++ is not
                really central to the question you are asking, I'm happy
                to help further.</p>
              <p>Please also refer to the tutorial here (assuming Java
                20):</p>
              <p><a href="https://urldefense.com/v3/__https://github.com/openjdk/panama-foreign/blob/78d460f04d93f3df8e8f703e78780a152793f44a/doc/panama_ffi.md__;!!ACWV5N9M2RV99hQ!PQrjj3CR9v7gdn_FICf8CJtI8UV6w40YznqoQu2VXGjTFWWzIQ430MzpVOtiyeqNbrqXyx6Josesc3S4ANztAPl_t4Ue$" target="_blank" moz-do-not-send="true">https://github.com/openjdk/panama-foreign/blob/78d460f04d93f3df8e8f703e78780a152793f44a/doc/panama_ffi.md</a></p>
              <p>Maurizio<br>
              </p>
              <div>On 25/04/2023 19:08, Michel Trudeau wrote:<br>
              </div>
              <blockquote type="cite">
                <div>
                  <p class="MsoNormal">[Moving to the right list]</p>
                  <p class="MsoNormal"> </p>
                  <div style="border-width:1pt medium
                    medium;border-style:solid none
                    none;border-color:rgb(181,196,223) currentcolor
                    currentcolor;padding:3pt 0in 0in">
                    <p class="MsoNormal" style="margin-bottom:12pt"><b><span style="font-size:12pt;color:black">From: </span></b><span style="font-size:12pt;color:black">code-tools-dev
                        <a href="mailto:code-tools-dev-retn@openjdk.org" target="_blank" moz-do-not-send="true"><code-tools-dev-retn@openjdk.org></a>
                        on behalf of Rebecca Ahlvarsson <a href="mailto:rahlvarsson@gmail.com" target="_blank" moz-do-not-send="true"><rahlvarsson@gmail.com></a><br>
                        <b>Date: </b>Tuesday, April 25, 2023 at 9:18 AM<br>
                        <b>To: </b><a href="mailto:code-tools-dev@openjdk.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">code-tools-dev@openjdk.org</a>
                        <a href="mailto:code-tools-dev@openjdk.org" target="_blank" moz-do-not-send="true"><code-tools-dev@openjdk.org></a><br>
                        <b>Subject: </b>A very basic HelloWorld with
                        jextract and panama</span></p>
                  </div>
                  <div>
                    <p class="MsoNormal">This question is so basic that
                      I must be missing something. Sorry if that's a
                      dumb rookie question.</p>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal">I have the following C++
                        code:</p>
                    </div>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal">    #include <iostream><br>
                        <br>
                            using namespace std;<br>
                        <br>
                            void sayHello() {<br>
                                cout << "Hello, Panama!" <<
                        endl;<br>
                            }</p>
                    </div>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal">Great!!!</p>
                    </div>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal">Now how do I go about calling
                        the "sayHello()" C++ method from Java using
                        jextract and panama?</p>
                    </div>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal"><b>I can use Linux or Mac,
                          you choose. And I have jextract built on both
                          machines.</b></p>
                    </div>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal">That's easy and
                        straightforward with JNI, JNA and JNR. But not
                        with Panama? :(</p>
                    </div>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal">Your help clarifying this
                        issue will be greatly appreciated!</p>
                    </div>
                    <div>
                      <p class="MsoNormal"> </p>
                    </div>
                    <div>
                      <p class="MsoNormal">-Rebecca<br clear="all">
                      </p>
                      <div>
                        <p class="MsoNormal"> </p>
                      </div>
                    </div>
                  </div>
                </div>
              </blockquote>
            </div>
          </blockquote>
        </div>
        <br clear="all">
        <div><br>
        </div>
        <span class="gmail_signature_prefix">-- </span><br>
        <div dir="ltr" class="gmail_signature">-Becky</div>
      </div>
    </blockquote>
  </body>
</html>