Posts

Showing posts from August, 2017

Final report: ctypes and NumPy work with JyNI on Windows

After the last report, where I managed to run DemoExtension with JyNI on Windows, I investigated workability of ctypes.
Linking msvcrt The first thing I discovered was that it didn't work:

Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\workspace\linux\JyNI\build\JyNI.dll\python27.dll: Can't find dependent libraries

And further – that DemoExtension also was not working when built using setup.py rather than by my makefile. That was a drawback, but remember that DemoExtension was working fine with CPython, even if built with the makefile.
After carefully studying the difference between the build commands I found out that setup.py would add the /MD flag. Beneath several other options, e.g. /nologo /Ox /W3 /GS- /DNDEBUG, /MD was the one that made the difference. It tells MSVC to link msvcrt.dll, precisely speaking msvcr90.dll for Python 2.7.
I guess the DemoExtension build without explicit /MD worked, because it still linked libcmt.lib. However, after adding…

Major milestone achieved: JyNI builds successfully on Windows, DemoExtension is workable

After fixing the remaining symbol errors MSVC successfully created JyNI.dll for the very first time – what a historical moment!
Unfortunately the euphoria didn't last long, because when loading DemoExtension, it directly crashed.
After some investigation I found out that JyNI.dll was successfully loaded by the JVM and I also verified that code in the dll was actually accessed and properly run. Even the initial call into DemoExtension.pyd worked. However, the call to Py_InitModule4 crashed:
It seemed like symbols from JyNI.dll were not exported for access by DemoExtension.pyd. Strangely, the error message wasn't like one would expect for this. It rather looked like DemoExtension.pyd was calling into CPython's python27.dll, i.e. the one installed on the system.

The definite proof of concept After some reading in MSDN docs I learned that the names of dll dependencies are hard coded at compile time, which means that DemoExtension.pyd will insist on loading python27.dll, no mat…