Skip to content

Getting Started Guide

Calum Freeman edited this page Sep 12, 2018 · 3 revisions

The first thing to do is read the How to set up a development environment page. That will get you a built developer's codebase.

You should also read the Code Style and Conventions page before adding any code.

There are a number of useful Utility functions and macros in the JyNI.c file, the wiki page on these is a work in progress. Finding out about these can save you a lot of time trying to write the code to, for instance, convert a jstring into a char *.

When you want to add to the codebase it may also be worth looking over the other wiki pages on how to add to the codebase. At the moment the only one is How to access java from C

When you encounter bugs with difficult error messages, it may be useful to check the Frequently Encountered Bugs section to see if the bug is already there, if you add to that page, try to make it as generally applicable as possible. (ie "When calling (*env)->Call<type>Method(), the arguments passed must be of type j<type>" not "When calling (*env)->CallIntMethod(), the arguments passed must be of type jint")

Misc notes

Memory management

PyObject's are malloc'd and kept track of with Py_INCREF(); and Py_DECREF(); they start with a single reference, so if an object is created and you are finished with it, you need to call Py_DECREF(); on it. If the object has been "borrowed" (ie it's been passed to a function as an argument) then it doesn't need to have Py_DECREF(); called (in the function it's passed to). jobjects are always local to the native block of code (or maybe the env pointer).
native C code will be local unless it is created with malloc.