-
Bug
-
Resolution: Won't Fix
-
P3
-
repo-panama
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();
}
}
}
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();
}
}
}
- relates to
-
JDK-8214953 jextract behavior should be more transparent
-
- Closed
-
-
JDK-8219042 Cross-header layout resolution does not work
-
- Resolved
-