Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8208199

Revisit one interface per header file approach

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • repo-panama
    • repo-panama
    • tools

      Typically C programmer includes a top-level header file of a C API to use it. For example, Python C embedding program would include "Python.h". The API header itself would include multiple header files in the same dir - but that is considered "implementation detail" per API usage guides.

      With Panama approach of interface-per-header-file, user has to know which interface to be bind to invoke a specific API. This does not mirror C programmer workflow.

      For example, to use Python with Panama, we need to bind more than one interface.

      Example:

      import java.foreign.*;
      import java.foreign.memory.*;
      import java.lang.invoke.*;

      public class PythonMain {
        public static void main(String[] args) throws Exception {
            // this is generated for the main API header file "Python.h"
            Python py = Libraries.bind(MethodHandles.lookup(), Python.class);
            // pythonrun is generated for pythonrun.h header
            pythonrun pr = Libraries.bind(MethodHandles.lookup(), pythonrun.class);

            try (Scope s = Scope.newNativeScope()) {
                pr.Py_Initialize();
                pr.Py_AtExit(() -> System.out.println("Good bye!"));
                pr.PyRun_SimpleStringFlags(s.toCString("print('hello')\nexit()\n"), Pointer.nullPointer());
                pr.Py_Finalize();
            }
        }
      }

            sundar Sundararajan Athijegannathan
            sundar Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: