How stewori/jyni works
Project type and purpose
• JyNI is a middleware/library project (open-source tool) bridging Jython (Java-based Python) with native CPython extensions (C libraries).
• It allows users to load standard CPython C-extensions (e.g., ctypes, NumPy) into Jython without recompilation.
File-structure analysis
• Top level:
• JyNI-C – Core C implementation of Python C-API shims and adapters
• JyNI-Java – Java classes (JyNI.jar) exposing native functions to Jython via JNI
• JyNI-Lib – Python-side modules to hook into Jython’s import system, ctypes, sqlite3, etc.
• JyNI-Loader – Low-level C loader that sets up the JNI environment and loads libJyNI
• DemoExtension, JyNI-Demo, JyNI-Java tests – Example/test extensions and scripts
• makefile* – Build scripts for various platforms
• Patterns:
• JNI boundary between Java and C
• Adapter pattern for wrapping/mirroring Jython objects to CPython structures
• Plugin-style loading of native modules via JyNI-Loader
Key points from README
• Architecture overview (Java ⇄ C boundary, Python C API coverage)
• Garbage-collection bridging between reference counting (C) and mark-and-sweep (Java)
• Build and install steps for different OSes
– Operating system / dynamic loader [grey layer under C]
– Python script (in Jython) → Jython core → import hook (JyNI-Lib) → calls into JyNI-Java
– JyNI-Java invokes JNI → JyNI-Loader → loads libJyNI
– libJyNI implements Python C API calls → marshals to Jython via JNI callbacks
– libJyNI loads CPython extension modules → extension code calls PyObject_* → routed back to libJyNI → JNI → Jython
– GC integration: Java GC signals → JyNI-Loader / libJyNI reconciles reference counts
c. Architectural patterns & design principles
– Adapter: wraps CPython API to Jython implementations
– Mirror vs. wrapper modes for built-in types (immutable vs. mutable)
– Plugin/loader abstraction for cross-platform dynamic loading
– Separation of concerns: Python-side, Java-side, C-side layers
d. Key technologies/frameworks
– Java (Jython 2.7.1)
– C (GCC/Clang/MSVC) with JNI headers
– Python (Jython’s import machinery and CPython 2.7 headers)
– Makefiles for cross-platform builds
Detail reminders
• Sub-layer (Loader vs. Core C shim) distinctly
• Demo/test extension as an example plugin
• Build time vs. runtime components if space allows