hamchapman / swig-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SWIG test app

This is an Android app that has a single activity and all that's done in that activity is load libdatabase.so and then make some calls through some SWIG- generated JNI glue code into the native binary.

Key components

Problems

  1. SWIG generated JNI glue code generated for %pointer_functions(MyDatabase, MyDatabaseHandle) results in:
public static SWIGTYPE_p_MyDatabase MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase obj) {
  return new SWIGTYPE_p_MyDatabase(databaseJNI.MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase.getCPtr(obj)), true);
}

when really I want something like:

public static MyDatabase MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase obj) {
  return new MyDatabase(databaseJNI.MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase.getCPtr(obj)), true);
}

which is what I've manually edited it to in the committed code.

  1. Unsure how to use the function pointer, SomeFuncPtr fPtr;, defined as part of struct MyDatabase.

The SWIG-generated JNI code lets me do:

SWIGTYPE_p_MyDatabase myDBPtr = database.new_database("testing");
MyDatabase myDB = database.MyDatabaseHandle_value(myDBPtr);

myDB.getFPtr("hello"); // doesn't work - says that no arguments are expected

SWIGTYPE_p_f_p_q_const__char__int myFunc = myDB.getFPtr();
myFunc("hello"); // error about "Method call expected"

but both of the calls involving getFPtr result in an error, as noted in the comments in the code above.

About


Languages

Language:C 64.3%Language:Java 31.3%Language:Shell 4.4%