From 14e4a52657329314a59e9d2f887259d4ec169bce Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Mon, 20 Feb 2023 11:59:19 +0000 Subject: [PATCH] [vm] Fix `Dart_CObject_Type` breaking change https://dart-review.googlesource.com/c/sdk/+/257925 added a new entry in the middle of the `Dart_CObject_Type` enum, which changed the value of the entries below. However, this enum is part of `dart_api_dl.h` and versioned by `dart_version.h`. New entries to `Dart_CObject_Type` should be added at the end of the enum to avoid making breaking changes to the type. TEST=tests/ffi/vmspecific_handle_dynamically_linked_test.dart Bug: https://github.com/dart-lang/sdk/issues/51459 Change-Id: I367b54f62e59ddf925e255bb56c0f8660be7c227 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284161 Reviewed-by: Martin Kustermann Commit-Queue: Daco Harkes --- runtime/include/dart_native_api.h | 4 +++- runtime/include/dart_version.h | 2 +- samples/ffi/async/sample_async_callback.dart | 2 +- samples/ffi/async/sample_native_port_call.dart | 2 +- samples/ffi/sample_ffi_functions_callbacks_closures.dart | 2 +- tests/ffi/vmspecific_handle_dynamically_linked_test.dart | 7 +++---- tests/ffi_2/vmspecific_handle_dynamically_linked_test.dart | 7 +++---- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/runtime/include/dart_native_api.h b/runtime/include/dart_native_api.h index 4e3cd4d9495..79194e03ba8 100644 --- a/runtime/include/dart_native_api.h +++ b/runtime/include/dart_native_api.h @@ -50,13 +50,15 @@ typedef enum { Dart_CObject_kArray, Dart_CObject_kTypedData, Dart_CObject_kExternalTypedData, - Dart_CObject_kUnmodifiableExternalTypedData, Dart_CObject_kSendPort, Dart_CObject_kCapability, Dart_CObject_kNativePointer, Dart_CObject_kUnsupported, + Dart_CObject_kUnmodifiableExternalTypedData, Dart_CObject_kNumberOfTypes } Dart_CObject_Type; +// This enum is versioned by DART_API_DL_MAJOR_VERSION, only add at the end +// and bump the DART_API_DL_MINOR_VERSION. typedef struct _Dart_CObject { Dart_CObject_Type type; diff --git a/runtime/include/dart_version.h b/runtime/include/dart_version.h index a9b902e3b3e..680fb539bbe 100644 --- a/runtime/include/dart_version.h +++ b/runtime/include/dart_version.h @@ -11,6 +11,6 @@ // On backwards compatible changes the minor version is increased. // The versioning covers the symbols exposed in dart_api_dl.h #define DART_API_DL_MAJOR_VERSION 2 -#define DART_API_DL_MINOR_VERSION 1 +#define DART_API_DL_MINOR_VERSION 2 #endif /* RUNTIME_INCLUDE_DART_VERSION_H_ */ /* NOLINT */ diff --git a/samples/ffi/async/sample_async_callback.dart b/samples/ffi/async/sample_async_callback.dart index e9d300fc4a1..12bdf66b0a0 100644 --- a/samples/ffi/async/sample_async_callback.dart +++ b/samples/ffi/async/sample_async_callback.dart @@ -27,7 +27,7 @@ main() async { print("C = C T1 or C T2."); print("Dart: Setup."); Expect.isTrue(NativeApi.majorVersion == 2); - Expect.isTrue(NativeApi.minorVersion >= 1); + Expect.isTrue(NativeApi.minorVersion >= 2); final initializeApi = dl.lookupFunction), int Function(Pointer)>("InitDartApiDL"); Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0); diff --git a/samples/ffi/async/sample_native_port_call.dart b/samples/ffi/async/sample_native_port_call.dart index fd5fefc72c2..11cf3c98262 100644 --- a/samples/ffi/async/sample_native_port_call.dart +++ b/samples/ffi/async/sample_native_port_call.dart @@ -36,7 +36,7 @@ main() async { print("C = C T1 or C T2."); print("Dart: Setup."); Expect.isTrue(NativeApi.majorVersion == 2); - Expect.isTrue(NativeApi.minorVersion >= 1); + Expect.isTrue(NativeApi.minorVersion >= 2); final initializeApi = dl.lookupFunction), int Function(Pointer)>("InitDartApiDL"); Expect.isTrue(initializeApi(NativeApi.initializeApiDLData) == 0); diff --git a/samples/ffi/sample_ffi_functions_callbacks_closures.dart b/samples/ffi/sample_ffi_functions_callbacks_closures.dart index 5cccf917216..6f96071a226 100644 --- a/samples/ffi/sample_ffi_functions_callbacks_closures.dart +++ b/samples/ffi/sample_ffi_functions_callbacks_closures.dart @@ -54,7 +54,7 @@ final closureCallbackPointer = void doDynamicLinking() { Expect.isTrue(NativeApi.majorVersion == 2); - Expect.isTrue(NativeApi.minorVersion >= 1); + Expect.isTrue(NativeApi.minorVersion >= 2); final initializeApi = testLibrary.lookupFunction< IntPtr Function(Pointer), int Function(Pointer)>("InitDartApiDL"); diff --git a/tests/ffi/vmspecific_handle_dynamically_linked_test.dart b/tests/ffi/vmspecific_handle_dynamically_linked_test.dart index 54535077cbb..77bc40537e2 100644 --- a/tests/ffi/vmspecific_handle_dynamically_linked_test.dart +++ b/tests/ffi/vmspecific_handle_dynamically_linked_test.dart @@ -18,7 +18,7 @@ void main() { void doDynamicLinking() { Expect.isTrue(NativeApi.majorVersion == 2); - Expect.isTrue(NativeApi.minorVersion >= 1); + Expect.isTrue(NativeApi.minorVersion >= 2); final initializeApi = testLibrary.lookupFunction< IntPtr Function(Pointer), int Function(Pointer)>("InitDartApiDL"); @@ -35,9 +35,8 @@ void testHandle() { void testNativeAPIs() { // No need to expect here, `lookupFunction` throws an argument error if lookup fails. - testLibrary.lookupFunction< - Bool Function(Handle), - bool Function(Object)>("Dart_IsNull_DL"); + testLibrary.lookupFunction( + "Dart_IsNull_DL"); } class SomeClass { diff --git a/tests/ffi_2/vmspecific_handle_dynamically_linked_test.dart b/tests/ffi_2/vmspecific_handle_dynamically_linked_test.dart index 1f3c9499fce..950a0234ac0 100644 --- a/tests/ffi_2/vmspecific_handle_dynamically_linked_test.dart +++ b/tests/ffi_2/vmspecific_handle_dynamically_linked_test.dart @@ -20,7 +20,7 @@ void main() { void doDynamicLinking() { Expect.isTrue(NativeApi.majorVersion == 2); - Expect.isTrue(NativeApi.minorVersion >= 1); + Expect.isTrue(NativeApi.minorVersion >= 2); final initializeApi = testLibrary.lookupFunction< IntPtr Function(Pointer), int Function(Pointer)>("InitDartApiDL"); @@ -37,9 +37,8 @@ void testHandle() { void testNativeAPIs() { // No need to expect here, `lookupFunction` throws an argument error if lookup fails. - testLibrary.lookupFunction< - Bool Function(Handle), - bool Function(Object)>("Dart_IsNull_DL"); + testLibrary.lookupFunction( + "Dart_IsNull_DL"); } class SomeClass {