mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] Check MSVC Runtime (#7301)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "wpi/DataLog.h"
|
||||
#include "wpi/FileLogger.h"
|
||||
#include "wpi/RawFrame.h"
|
||||
#include "wpi/RuntimeCheck.h"
|
||||
#include "wpi/Synchronization.h"
|
||||
#include "wpi/jni_util.h"
|
||||
#include "wpi/print.h"
|
||||
@@ -25,13 +26,15 @@ static JException indexOobEx;
|
||||
static JException interruptedEx;
|
||||
static JException ioEx;
|
||||
static JException nullPointerEx;
|
||||
static JException msvcRuntimeEx;
|
||||
|
||||
static const JExceptionInit exceptions[] = {
|
||||
{"java/lang/IllegalArgumentException", &illegalArgEx},
|
||||
{"java/lang/IndexOutOfBoundsException", &indexOobEx},
|
||||
{"java/lang/InterruptedException", &interruptedEx},
|
||||
{"java/io/IOException", &ioEx},
|
||||
{"java/lang/NullPointerException", &nullPointerEx}};
|
||||
{"java/lang/NullPointerException", &nullPointerEx},
|
||||
{"edu/wpi/first/util/MsvcRuntimeException", &msvcRuntimeEx}};
|
||||
|
||||
void wpi::ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg) {
|
||||
illegalArgEx.Throw(env, msg);
|
||||
@@ -78,6 +81,34 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_util_WPIUtilJNI
|
||||
* Method: checkMsvcRuntime
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_util_WPIUtilJNI_checkMsvcRuntime
|
||||
(JNIEnv* env, jclass)
|
||||
{
|
||||
uint32_t foundMajor;
|
||||
uint32_t foundMinor;
|
||||
uint32_t expectedMajor;
|
||||
uint32_t expectedMinor;
|
||||
WPI_String runtimePath;
|
||||
|
||||
if (!WPI_IsRuntimeValid(&foundMajor, &foundMinor, &expectedMajor,
|
||||
&expectedMinor, &runtimePath)) {
|
||||
static jmethodID ctor =
|
||||
env->GetMethodID(msvcRuntimeEx, "<init>", "(IIIILjava/lang/String;)V");
|
||||
jstring jmsvcruntime = MakeJString(env, wpi::to_string_view(&runtimePath));
|
||||
jobject exception =
|
||||
env->NewObject(msvcRuntimeEx, ctor, foundMajor, foundMinor,
|
||||
expectedMajor, expectedMinor, jmsvcruntime);
|
||||
WPI_FreeString(&runtimePath);
|
||||
env->Throw(static_cast<jthrowable>(exception));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: edu_wpi_first_util_WPIUtilJNI
|
||||
* Method: writeStderr
|
||||
|
||||
Reference in New Issue
Block a user