Skip to content

Commit

Permalink
QtJambi 6.7.3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
omix committed Oct 8, 2024
1 parent e3ba7ec commit e96281d
Show file tree
Hide file tree
Showing 75 changed files with 2,566 additions and 933 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ to your project:
<version>$VERSION</version>
</dependency>
```
(exchange `$VERSION` either by `6.5.8` or by `6.7.3`).
(exchange `$VERSION` either by `6.5.9` or by `6.7.3`).

Otherwise, download QtJambi JAR file from [Maven Central Repository](https://search.maven.org/artifact/io.qtjambi/qtjambi/).

Expand Down
4 changes: 0 additions & 4 deletions antfiles/autotests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,6 @@
<condition property="Dqtjambi.log-level" value="-Dqtjambi.log-level=${qtjambi.log-level}" else="-Dx">
<isset property="qtjambi.log-level"/>
</condition>
<condition property="Dio.qt.verbose-loading" value="-Dio.qt.verbose-loading=${io.qt.verbose-loading}" else="-Dx">
<isset property="io.qt.verbose-loading"/>
</condition>
<condition property="Dio.qt.enable-dangling-pointer-check" value="-Dio.qt.enable-dangling-pointer-check=${io.qt.enable-dangling-pointer-check}" else="-Dx">
<isset property="io.qt.enable-dangling-pointer-check"/>
</condition>
Expand Down Expand Up @@ -895,7 +892,6 @@
<pathelement path="${outputDir}/${qtjambi.osname}/tests/qtjambi-autotests-${qtjambi.jar.version}.jar" />
</classpath>
<jvmarg value="-Dio.qt.library-path-override=${qtPath}${psep}${qtJambiPath}${psep}${testLibPath}"/>
<jvmarg value="${Dio.qt.verbose-loading}"/>
<jvmarg value="-Dio.qt.debug=${kind}"/><!-- This should not be needed now, it loads default from MANIFEST.MF -->
<jvmarg value="-Dio.qt.log-messages=ALL"/>
<jvmarg value="${Dqtjambi.log-level}"/>
Expand Down
1 change: 1 addition & 0 deletions releases.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
6.5.0=14
6.6.0=17
6.7.0=20
6.8.0=23
current=23
39 changes: 28 additions & 11 deletions src/cpp/QtJambi/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "jobjectwrapper.h"
#include "exception.h"
#include "java_p.h"
#include "threadutils_p.h"
#include "utils_p.h"
#include "qtjambi_cast.h"

Expand Down Expand Up @@ -462,7 +463,7 @@ void JavaException::raiseQThreadAffinityException(JNIEnv* env, QAnyStringView me
}
#endif

JNIEnv *currentJNIEnvironment(bool initializeJavaThread = true);
JNIEnv *currentJNIEnvironment(bool& requiresDetach, bool initializeJavaThread = true);

struct ExceptionContainer{
std::thread::id thread_id;
Expand All @@ -471,7 +472,8 @@ struct ExceptionContainer{
ExceptionContainer() : thread_id(std::this_thread::get_id()), exn(), methodName(nullptr) {}
~ExceptionContainer(){
if(exn){
if(JNIEnv *env = currentJNIEnvironment(false)){
bool requiresDetach = false;
if(JNIEnv *env = currentJNIEnvironment(requiresDetach, false)){
JniLocalFrame frame(env, 200);
try{
jstring msg = methodName ? env->NewStringUTF(methodName) : nullptr;
Expand All @@ -496,6 +498,8 @@ struct ExceptionContainer{
std::string thread_id_str = oss.str();
qCWarning(DebugAPI::internalCategory, "An exception occured in thread %s: %s", thread_id_str.c_str(), exn.what());
}
if(requiresDetach)
EventDispatcherCheck::detach();
}
}
// QThreadStorage is needed because thread_local is deleted after JNI's thread detach and thus cannot treat java exceptions
Expand Down Expand Up @@ -544,12 +548,13 @@ QtJambiExceptionHandler::~QtJambiExceptionHandler(){

void QtJambiExceptionHandler::handle(JNIEnv *env, const JavaException& exn, const char* methodName){
if(data){
bool requiresDetach = false;
ExceptionHandler& exceptionHandler = ExceptionHandler::instance;
exceptionHandler.hasException = true;
ExceptionContainer& exceptionContainer = ExceptionContainer::exception.localData();
if(exceptionContainer.exn){
if(!env){
env = currentJNIEnvironment();
env = currentJNIEnvironment(requiresDetach);
if(!env){
if(methodName){
qCWarning(DebugAPI::internalCategory, "An exception occured in %s: %s", methodName, exn.what());
Expand All @@ -568,6 +573,8 @@ void QtJambiExceptionHandler::handle(JNIEnv *env, const JavaException& exn, cons
exceptionContainer.exn = exn;
exceptionContainer.methodName = methodName;
}
if(requiresDetach)
EventDispatcherCheck::detach();
}else if(exn){
throw JavaException(exn);//JavaException(env, exn.object());
}
Expand All @@ -594,13 +601,14 @@ QtJambiExceptionInhibitor::~QtJambiExceptionInhibitor(){
}

void QtJambiExceptionInhibitor::handle(JNIEnv *env, const JavaException& exn, const char* methodName){
bool requiresDetach = false;
if(!(data & ExceptionHandler::Blocking) || (data & ExceptionHandler::Reraise)){
ExceptionHandler& exceptionHandler = ExceptionHandler::instance;
exceptionHandler.hasException = true;
ExceptionContainer& exceptionContainer = ExceptionContainer::exception.localData();
if(exceptionContainer.exn){
if(!env){
env = currentJNIEnvironment();
env = currentJNIEnvironment(requiresDetach);
if(!env){
if(methodName){
qCWarning(DebugAPI::internalCategory, "An exception occured in %s: %s", methodName, exn.what());
Expand All @@ -621,7 +629,7 @@ void QtJambiExceptionInhibitor::handle(JNIEnv *env, const JavaException& exn, co
}
}else{
if(!env){
env = currentJNIEnvironment();
env = currentJNIEnvironment(requiresDetach);
if(!env){
if(methodName){
qCWarning(DebugAPI::internalCategory, "An exception occured in %s: %s", methodName, exn.what());
Expand All @@ -644,6 +652,8 @@ void QtJambiExceptionInhibitor::handle(JNIEnv *env, const JavaException& exn, co
printf("An exception occured in ExceptionUtility.reportException(...): %s\n", _exn.what());
}
}
if(requiresDetach)
EventDispatcherCheck::detach();
}

QtJambiExceptionBlocker::QtJambiExceptionBlocker()
Expand All @@ -667,6 +677,7 @@ QtJambiExceptionBlocker::~QtJambiExceptionBlocker(){
}

void QtJambiExceptionBlocker::release(JNIEnv *env){
bool requiresDetach = false;
ExceptionHandler& exceptionHandler = ExceptionHandler::instance;
if(exceptionHandler.hasException && !exceptionHandler.keep){
ExceptionContainer& exceptionContainer = ExceptionContainer::exception.localData();
Expand All @@ -681,7 +692,7 @@ void QtJambiExceptionBlocker::release(JNIEnv *env){
const char* methodName = exceptionContainer.methodName;
exceptionContainer.methodName = nullptr;
if(!env){
env = currentJNIEnvironment();
env = currentJNIEnvironment(requiresDetach);
if(!env){
if(methodName){
qCWarning(DebugAPI::internalCategory, "An exception occured in %s: %s", methodName, exn.what());
Expand All @@ -705,6 +716,8 @@ void QtJambiExceptionBlocker::release(JNIEnv *env){
}
}
}
if(requiresDetach)
EventDispatcherCheck::detach();
}

QtJambiExceptionRaiser::QtJambiExceptionRaiser()
Expand Down Expand Up @@ -744,14 +757,14 @@ QtJambiExceptionUnraiser::~QtJambiExceptionUnraiser(){
exceptionHandler.keep = false;
}

JNIEnv* threadLocalEnvironment(ExceptionHandler& exceptionHandler){
JNIEnv* threadLocalEnvironment(bool& requiresDetach, ExceptionHandler& exceptionHandler){
static ResettableBoolFlag useFastEnv("io.qt.experimental.fast-jni-for-overrides");
if(useFastEnv){
if(!exceptionHandler.env)
exceptionHandler.env = currentJNIEnvironment();
exceptionHandler.env = currentJNIEnvironment(requiresDetach);
return exceptionHandler.env;
}else{
return currentJNIEnvironment();
return currentJNIEnvironment(requiresDetach);
}
}

Expand All @@ -770,7 +783,9 @@ JniEnvironmentExceptionHandler::JniEnvironmentExceptionHandler(int capacity)
data |= ExceptionHandler::Keep;
}
exceptionHandler.blocking = false;
initialize(threadLocalEnvironment(exceptionHandler), capacity);
bool requiresDetach = false;
JNIEnv* env = threadLocalEnvironment(requiresDetach, exceptionHandler);
initialize(env, requiresDetach, capacity);
}

JniEnvironmentExceptionHandler::~JniEnvironmentExceptionHandler(){
Expand Down Expand Up @@ -808,7 +823,9 @@ JniEnvironmentExceptionInhibitor::JniEnvironmentExceptionInhibitor(int capacity)
data |= ExceptionHandler::Keep;
}
exceptionHandler.blocking = false;
initialize(threadLocalEnvironment(exceptionHandler), capacity);
bool requiresDetach = false;
JNIEnv* env = threadLocalEnvironment(requiresDetach, exceptionHandler);
initialize(env, requiresDetach, capacity);
}

JniEnvironmentExceptionInhibitor::~JniEnvironmentExceptionInhibitor(){
Expand Down
7 changes: 4 additions & 3 deletions src/cpp/QtJambi/functionpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,15 @@ void unregister_file_by_function(QFunctionPointer fn){

void clearFunctionPointersAtShutdown(){
Libraries libraries;
QHash<void*,void(*)(void*)> functionPointerCleanups;
if(!gLibraries.isDestroyed()){
QMutexLocker locker(gMutex());
gLibraries->swap(libraries);
QHash<void*,void(*)(void*)> functionPointerCleanups;
gFunctionPointerCleanups->swap(functionPointerCleanups);
for(auto iter = functionPointerCleanups.constKeyValueBegin(); iter!=functionPointerCleanups.constKeyValueEnd(); ++iter){
}
for(auto iter = functionPointerCleanups.constKeyValueBegin(); iter!=functionPointerCleanups.constKeyValueEnd(); ++iter){
if(iter->second && iter->first)
iter->second(iter->first);
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/cpp/QtJambi/java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ namespace Internal{
QTJAMBI_REPOSITORY_DEFINE_CLASS(io/qt/core,QCoreApplication,
QTJAMBI_REPOSITORY_DEFINE_STATIC_METHOD(execPreRoutines,()V)
QTJAMBI_REPOSITORY_DEFINE_STATIC_METHOD(execPostRoutines,()V))
QTJAMBI_REPOSITORY_DEFINE_CLASS(io/qt/core,QThread,
QTJAMBI_REPOSITORY_DEFINE_METHOD(setJavaThreadReference,(Ljava/lang/Thread;)V)
QTJAMBI_REPOSITORY_DEFINE_METHOD(getJavaThreadReference,()Ljava/lang/Thread;)
)
}

QTJAMBI_REPOSITORY_DEFINE_CLASS(io/qt/core,QPluginLoader,
Expand All @@ -95,7 +99,7 @@ QTJAMBI_REPOSITORY_DEFINE_CLASS(io/qt/core,QUnhandledException,
QTJAMBI_REPOSITORY_DEFINE_CONSTRUCTOR(Ljava/lang/String;))

QTJAMBI_REPOSITORY_DEFINE_CLASS(io/qt/core,QThread,
QTJAMBI_REPOSITORY_DEFINE_FIELD(javaThread,Ljava/lang/Thread;)
QTJAMBI_REPOSITORY_DEFINE_FIELD(javaThread,Ljava/lang/ref/WeakReference;)
)

QTJAMBI_REPOSITORY_DEFINE_CLASS(io/qt/core,QMetaMethod,
Expand Down Expand Up @@ -1156,6 +1160,7 @@ QTJAMBI_REPOSITORY_DEFINE_CLASS(java/lang,Thread,
QTJAMBI_REPOSITORY_DEFINE_METHOD(getUncaughtExceptionHandler,()Ljava/lang/Thread$UncaughtExceptionHandler;)
QTJAMBI_REPOSITORY_DEFINE_METHOD(getContextClassLoader,()Ljava/lang/ClassLoader;)
QTJAMBI_REPOSITORY_DEFINE_METHOD(setUncaughtExceptionHandler,(Ljava/lang/Thread$UncaughtExceptionHandler;)V)
QTJAMBI_REPOSITORY_DEFINE_METHOD(setName,(Ljava/lang/String;)V)
QTJAMBI_REPOSITORY_DEFINE_METHOD(setContextClassLoader,(Ljava/lang/ClassLoader;)V)
QTJAMBI_REPOSITORY_DEFINE_METHOD(getThreadGroup,()Ljava/lang/ThreadGroup;)
QTJAMBI_REPOSITORY_DEFINE_METHOD(getStackTrace,()[Ljava/lang/StackTraceElement;)
Expand Down
4 changes: 4 additions & 0 deletions src/cpp/QtJambi/java_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ namespace Java{
QTJAMBI_REPOSITORY_DECLARE_STATIC_VOID_METHOD(execPreRoutines)
QTJAMBI_REPOSITORY_DECLARE_STATIC_VOID_METHOD(execPostRoutines)
)
QTJAMBI_REPOSITORY_DECLARE_CLASS(QThread,
QTJAMBI_REPOSITORY_DECLARE_VOID_METHOD(setJavaThreadReference)
QTJAMBI_REPOSITORY_DECLARE_OBJECT_METHOD(getJavaThreadReference))
}
#if defined(QTJAMBI_LIGHTWEIGHT_MODELINDEX)
QTJAMBI_REPOSITORY_DECLARE_CLASS(QModelIndex,
Expand Down Expand Up @@ -318,6 +321,7 @@ namespace Java{
QTJAMBI_REPOSITORY_DECLARE_OBJECTARRAY_METHOD(getStackTrace)
QTJAMBI_REPOSITORY_DECLARE_VOID_METHOD(setContextClassLoader)
QTJAMBI_REPOSITORY_DECLARE_VOID_METHOD(setUncaughtExceptionHandler)
QTJAMBI_REPOSITORY_DECLARE_VOID_METHOD(setName)
QTJAMBI_REPOSITORY_DECLARE_OBJECT_METHOD(getThreadGroup)
QTJAMBI_REPOSITORY_DECLARE_VOID_METHOD(interrupt)
QTJAMBI_REPOSITORY_DECLARE_BOOLEAN_METHOD(isAlive)
Expand Down
10 changes: 7 additions & 3 deletions src/cpp/QtJambi/jni_signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,13 @@ QTJAMBI_FUNCTION_PREFIX(Java_io_qt_internal_SignalUtility_connectNative)
QMetaMethod qt_signalMethod = reinterpret_cast<const QMetaObject*>(senderMetaObjectId)->method(signal);
QObject* deletable = nullptr;
QObject* context = QtJambiAPI::objectFromNativeId<QObject>(contextNativeId);
connectionType = connectionType & ~Qt::UniqueConnection;
int reducedConnectionType = (connectionType & ~Qt::UniqueConnection)
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
& ~Qt::SingleShotConnection
#endif
;
QThread* senderAsThread = dynamic_cast<QThread*>(sender);
if(connectionType==Qt::AutoConnection || connectionType==Qt::DirectConnection){
if(reducedConnectionType==Qt::AutoConnection || reducedConnectionType==Qt::DirectConnection){
if(senderAsThread && !context){
connectionType = Qt::DirectConnection;
deletable = new QObject();
Expand All @@ -573,7 +577,7 @@ QTJAMBI_FUNCTION_PREFIX(Java_io_qt_internal_SignalUtility_connectNative)
}
}else if(senderAsThread && QThreadData::get2(senderAsThread)->isAdopted){
QString _connectionType;
if(connectionType==Qt::BlockingQueuedConnection){
if(reducedConnectionType==Qt::BlockingQueuedConnection){
_connectionType = "BlockingQueuedConnection";
}else{
_connectionType = "QueuedConnection";
Expand Down
Loading

0 comments on commit e96281d

Please sign in to comment.