Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ jobs:
run: |
make examples

- name: Check that the generated code and the examples build with -Wall -Werror
run: |
for f in examples/*/*.cpp; do
echo "Checking $f"
g++ -Wall -Werror -fsyntax-only \
-I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" \
-I"$(dirname "$f")" "$f"
done

package:
runs-on: ubuntu-latest
strategy:
Expand Down
17 changes: 15 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
giws (3.1.0)
giws (4.0.0)

* Generated code: the exception check after the Java call was only
emitted for static methods. Non-static methods now detect a pending
Expand All @@ -14,13 +14,26 @@ giws (3.1.0)
* Generated GiwsException: check for pending exceptions after each
CallObjectMethod (fixes -Xcheck:jni warnings while building the
C++ exception)
* Generated GiwsException: release the JNI local references on the
early-return paths too (they leaked when embedding the JVM, as
local references are only freed when the thread detaches)
* Generated code: boolean arrays with --disable-return-size-array
wrote the array length through an uninitialized pointer
(undefined behavior); use a local variable like the other types
* Generated classes: make the destructor virtual (the class has
virtual methods; deleting through it was flagged by
-Wdelete-non-virtual-dtor)
* Examples: fix the -Wall warnings in the hand-written sources
(unused variables, VLA, catching a polymorphic type by value)
* CI: check that the generated code and the examples build with
-Wall -Werror
* Add a test suite (tests/) run by CI; no JDK needed
* New example bug_nonstatic_exception demonstrating the exception
fix on non-static methods
* Modernize the Python code (f-strings, type hints, with-statement)
* Add a pre-commit configuration running ruff

-- Sylvestre Ledru <sylvestre@debian.org> Thu, 06 Aug 2026 22:23:44 +0200
-- Sylvestre Ledru <sylvestre@debian.org> Fri, 07 Aug 2026 10:43:07 +0200

giws (2.0.3)

Expand Down
12 changes: 10 additions & 2 deletions CXXException.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ def generateCXXBody(self, config):

// retrieve information from the exception.
// get method id
jmethodID getLocalizedMessageId = curEnv->GetMethodID(curEnv->GetObjectClass(javaException),
jclass javaExceptionClass = curEnv->GetObjectClass(javaException);
jmethodID getLocalizedMessageId = curEnv->GetMethodID(javaExceptionClass,
"getLocalizedMessage",
"()Ljava/lang/String;");

Expand All @@ -413,18 +414,21 @@ def generateCXXBody(self, config):
if (curEnv->ExceptionCheck())
{
curEnv->ExceptionClear();
curEnv->DeleteLocalRef(javaExceptionClass);
return "";
}

if (description == NULL)
{
curEnv->DeleteLocalRef(javaExceptionClass);
return "";
}

std::string res = convertJavaString(curEnv, description);

// release java resources
curEnv->DeleteLocalRef(description);
curEnv->DeleteLocalRef(javaExceptionClass);

return res;
}
Expand All @@ -441,9 +445,11 @@ def generateCXXBody(self, config):
// retrieve information from the exception.
// get method id
// getStackTrace returns an array of StackTraceElement
jmethodID getStackTraceId = curEnv->GetMethodID(curEnv->GetObjectClass(javaException),
jclass javaExceptionClass = curEnv->GetObjectClass(javaException);
jmethodID getStackTraceId = curEnv->GetMethodID(javaExceptionClass,
"getStackTrace",
"()[Ljava/lang/StackTraceElement;");
curEnv->DeleteLocalRef(javaExceptionClass);

// call getStackTrace
jobjectArray stackTrace = (jobjectArray) curEnv->CallObjectMethod(javaException, getStackTraceId);
Expand Down Expand Up @@ -536,6 +542,8 @@ def generateCXXBody(self, config):

if (javaName == NULL)
{
curEnv->DeleteLocalRef(exceptionClass);
curEnv->DeleteLocalRef(classClass);
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion classRepresentation/objectGiws.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def generateCXXHeader(self, packageName):

%s
// Destructor
~%s();
virtual ~%s();

// Generic method
// Synchronization methods
Expand Down
2 changes: 1 addition & 1 deletion configGiws.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

"""Configuration of the Env"""

__version__ = "3.1.0"
__version__ = "4.0.0"


class configGiws:
Expand Down
35 changes: 24 additions & 11 deletions datatypes/booleanDataGiws.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ def specificPostProcessing(self, detachThread):
if self.isArray():
str = JNIFrameWork().getExceptionCheckProfile(detachThread)
strCommon = ""
strDeclaration = ""
if configGiws().getDisableReturnSize() is True:
strCommon += "int *lenRow;"
strCommon += "int lenRow;"
else:
# The size of the array is returned as output argument of the
# function
strDeclaration = "*"
strCommon += """
*lenRow = curEnv->GetArrayLength(res);
%s lenRow = curEnv->GetArrayLength(res);
jboolean isCopy = JNI_FALSE;
"""
""" % (strDeclaration)

if self.getDimensionArray() == 1:
return (
Expand All @@ -122,37 +127,45 @@ def specificPostProcessing(self, detachThread):

/* faster than getXXXArrayElements */
jboolean *resultsArray = static_cast<jboolean *>(curEnv->GetPrimitiveArrayCritical(res, &isCopy));
bool * myArray= new bool[*lenRow];
bool * myArray= new bool[%s lenRow];

for (jsize i = 0; i < *lenRow; i++){
for (jsize i = 0; i < %s lenRow; i++){
myArray[i]=(resultsArray[i] == JNI_TRUE);
}
curEnv->ReleasePrimitiveArrayCritical(res, resultsArray, JNI_ABORT);

curEnv->DeleteLocalRef(res);
"""
% (strDeclaration, strDeclaration)
)
else:
if configGiws().getDisableReturnSize() is True:
str += "int *lenCol;"
str += "int lenCol;"
return (
str
+ strCommon
+ """
bool ** myArray = new bool*[*lenRow];
for(int i=0; i<*lenRow; i++) {
bool ** myArray = new bool*[%s lenRow];
for(int i=0; i<%s lenRow; i++) {
jbooleanArray oneDim = (jbooleanArray)curEnv->GetObjectArrayElement(res, i);
*lenCol=curEnv->GetArrayLength(oneDim);
%s lenCol=curEnv->GetArrayLength(oneDim);
bool *resultsArray = static_cast<bool *>(curEnv->GetPrimitiveArrayCritical(oneDim, &isCopy));
myArray[i] = new bool[*lenCol];
for(int j=0; j<*lenCol; j++) {
myArray[i] = new bool[%s lenCol];
for(int j=0; j<%s lenCol; j++) {
myArray[i][j]=(resultsArray[j] == JNI_TRUE);
}
curEnv->ReleasePrimitiveArrayCritical(res, resultsArray, JNI_ABORT);
}

curEnv->DeleteLocalRef(res);
"""
% (
strDeclaration,
strDeclaration,
strDeclaration,
strDeclaration,
strDeclaration,
)
)

else:
Expand Down
3 changes: 2 additions & 1 deletion examples/bug_disable_return/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Plop.hxx"
#include <jni.h>
/*
Copyright or © or Copr. INRIA/Scilab - Sylvestre LEDRU
Copyright or � or Copr. INRIA/Scilab - Sylvestre LEDRU
#
Sylvestre LEDRU - <sylvestre.ledru@inria.fr> <sylvestre@ledru.info>

Expand Down Expand Up @@ -64,5 +64,6 @@ int main(){
JavaVM* jvm = create_vm();
Plop *plop = new Plop(jvm);
cout << "Does nothing. It is just to test the bug." << endl;
delete plop;
return 0;
}
3 changes: 2 additions & 1 deletion examples/bug_no_param_int_array/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "Bar.hxx"
#include <jni.h>
/*
Copyright or © or Copr. INRIA/Scilab - Sylvestre LEDRU
Copyright or � or Copr. INRIA/Scilab - Sylvestre LEDRU
#
Sylvestre LEDRU - <sylvestre.ledru@inria.fr> <sylvestre@ledru.info>

Expand Down Expand Up @@ -64,5 +64,6 @@ int main(){
JavaVM* jvm = create_vm();
Bar *plop = new Bar(jvm);
cout << "Does nothing" << endl;
delete plop;
return 0;
}
4 changes: 2 additions & 2 deletions examples/example2/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright or © or Copr. INRIA/Scilab - Sylvestre LEDRU
Copyright or � or Copr. INRIA/Scilab - Sylvestre LEDRU
#
Sylvestre LEDRU - <sylvestre.ledru@inria.fr> <sylvestre@ledru.info>

Expand Down Expand Up @@ -61,7 +61,7 @@ using namespace example2;
using namespace std;

int main(){
int sizeArray=3;
const int sizeArray=3;
JavaVM* jvm = create_vm();
MyObjectWithArray *plop = new MyObjectWithArray(jvm);
int myArrayOfLong[sizeArray];
Expand Down
13 changes: 6 additions & 7 deletions examples/example3/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright or © or Copr. INRIA/Scilab - Sylvestre LEDRU
Copyright or � or Copr. INRIA/Scilab - Sylvestre LEDRU
#
Sylvestre LEDRU - <sylvestre.ledru@inria.fr> <sylvestre@ledru.info>

Expand Down Expand Up @@ -63,7 +63,6 @@ using namespace example3;
using namespace std;

int main(){
int sizeArray=3;
JavaVM* jvm = create_vm();
MyObjectWhichReturnsExceptions *plop = new MyObjectWhichReturnsExceptions(jvm);

Expand All @@ -74,9 +73,9 @@ int main(){

cout << "Exception caught:" << endl;
try {
int myIntsWithExceptionCatched = plop->getIntFromArrayOfSizeThree(22);
plop->getIntFromArrayOfSizeThree(22);

}catch(GiwsException::JniException e) {
}catch(const GiwsException::JniException & e) {
cout << "getJavaDescription: " << e.getJavaDescription() << endl;
cout << "getJavaStackTrace: " << e.getJavaStackTrace() << endl;
cout << "getJavaExceptionName: " << e.getJavaExceptionName() << endl;
Expand All @@ -86,8 +85,8 @@ int main(){

cout << "Exception will be trigger. This will display the message of the exception" << endl;
try {
int value = plop->thisMethodWillFailWithMessage();
}catch(GiwsException::JniException e) {
plop->thisMethodWillFailWithMessage();
}catch(const GiwsException::JniException & e) {
cout << "getJavaDescription: " << e.getJavaDescription() << endl;
cout << "getJavaStackTrace: " << e.getJavaStackTrace() << endl;
cout << "getJavaExceptionName: " << e.getJavaExceptionName() << endl;
Expand All @@ -96,7 +95,7 @@ int main(){
cout << "========================" << endl;

cout << "Exception not caught:" << endl;
int myIntsWithException = plop->getIntFromArrayOfSizeThree(223);
plop->getIntFromArrayOfSizeThree(223);
cout << "Value from the Java with good pos : " << myInts <<endl;

return 0;
Expand Down
1 change: 1 addition & 0 deletions examples/inherit/showcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class Son : public Father {
int main(){

Son *son = new Son();
delete son;
return 0;
}
Loading