Skip to content

[jni] Upgrade package:jni's ffigen #1954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions pkgs/jni/lib/src/accessors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ extension JniResultMethods on JniResult {
return value.l;
}

JObjectRefType get referenceType {
check();
return JObjectRefType.fromValue(value.i);
}

JReference get reference {
final pointer = objectPointer;
return pointer == nullptr ? jNullReference : JGlobalReference(pointer);
Expand Down
19 changes: 9 additions & 10 deletions pkgs/jni/lib/src/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,24 @@ final class DoubleReleaseError extends StateError {
DoubleReleaseError() : super('Double release error');
}

/// Represents JNI errors that might be returned by methods like
/// `JNI_CreateJavaVM`.
/// Represents JNI errors that might be returned by methods like `CreateJavaVM`.
sealed class JniError extends Error {
static const _errors = {
JniErrorCode.JNI_ERR: JniGenericError.new,
JniErrorCode.JNI_EDETACHED: JniThreadDetachedError.new,
JniErrorCode.JNI_EVERSION: JniVersionError.new,
JniErrorCode.JNI_ENOMEM: JniOutOfMemoryError.new,
JniErrorCode.JNI_EEXIST: JniVmExistsError.new,
JniErrorCode.JNI_EINVAL: JniArgumentError.new,
JniErrorCode.ERR: JniGenericError.new,
JniErrorCode.EDETACHED: JniThreadDetachedError.new,
JniErrorCode.EVERSION: JniVersionError.new,
JniErrorCode.ENOMEM: JniOutOfMemoryError.new,
JniErrorCode.EEXIST: JniVmExistsError.new,
JniErrorCode.EINVAL: JniArgumentError.new,
};

final String message;

JniError(this.message);

factory JniError.of(int status) {
factory JniError.of(JniErrorCode status) {
if (!_errors.containsKey(status)) {
status = JniErrorCode.JNI_ERR;
status = JniErrorCode.ERR;
}
return _errors[status]!();
}
Expand Down
14 changes: 7 additions & 7 deletions pkgs/jni/lib/src/jni.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ abstract final class Jni {
List<String> jvmOptions = const [],
List<String> classPath = const [],
bool ignoreUnrecognized = false,
int jniVersion = JniVersions.JNI_VERSION_1_6,
JniVersions jniVersion = JniVersions.VERSION_1_6,
}) {
final status = spawnIfNotExists(
dylibDir: dylibDir,
Expand All @@ -109,7 +109,7 @@ abstract final class Jni {
List<String> jvmOptions = const [],
List<String> classPath = const [],
bool ignoreUnrecognized = false,
int jniVersion = JniVersions.JNI_VERSION_1_6,
JniVersions jniVersion = JniVersions.VERSION_1_6,
}) =>
using((arena) {
_dylibDir = dylibDir ?? _dylibDir;
Expand All @@ -122,9 +122,9 @@ abstract final class Jni {
allocator: arena,
);
final status = _bindings.SpawnJvm(jvmArgs);
if (status == JniErrorCode.JNI_OK) {
if (status == JniErrorCode.OK) {
return true;
} else if (status == DART_JNI_SINGLETON_EXISTS) {
} else if (status == JniErrorCode.SINGLETON_EXISTS) {
return false;
} else {
throw JniError.of(status);
Expand All @@ -136,7 +136,7 @@ abstract final class Jni {
List<String> classPath = const [],
String? dylibPath,
bool ignoreUnrecognized = false,
int version = JniVersions.JNI_VERSION_1_6,
JniVersions version = JniVersions.VERSION_1_6,
required Allocator allocator,
}) {
final args = allocator<JavaVMInitArgs>();
Expand All @@ -163,7 +163,7 @@ abstract final class Jni {
args.ref.nOptions = count;
}
args.ref.ignoreUnrecognized = ignoreUnrecognized ? 1 : 0;
args.ref.version = version;
args.ref.version = version.value;
return args;
}

Expand Down Expand Up @@ -288,7 +288,7 @@ extension ProtectedJniExtensions on Jni {
static Dart_FinalizableHandle newJObjectFinalizableHandle(
Object object,
Pointer<Void> reference,
int refType,
JObjectRefType refType,
) {
ensureInitialized();
return Jni._bindings
Expand Down
Loading
Loading