From ad308e54ce39cfa91b6f93e7c407d828fd465ebc Mon Sep 17 00:00:00 2001 From: Tim Sneath Date: Fri, 5 Feb 2021 04:01:57 -0800 Subject: [PATCH] Update to ffi 0.3.0-nullsafety.1 (#3513) ffi 0.3.0 supports the new memory allocation model in Dart 2.12.0-259 and later. --- .../path_provider_windows/CHANGELOG.md | 4 +++ .../example/windows/flutter/CMakeLists.txt | 1 + .../lib/src/path_provider_windows_real.dart | 34 +++++++++---------- .../path_provider_windows/pubspec.yaml | 9 ++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/path_provider/path_provider_windows/CHANGELOG.md b/packages/path_provider/path_provider_windows/CHANGELOG.md index 24304e36dc0c..6190c39457da 100644 --- a/packages/path_provider/path_provider_windows/CHANGELOG.md +++ b/packages/path_provider/path_provider_windows/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.0-nullsafety.2 + +* Bump ffi dependency to 0.3.0-nullsafety.1 + ## 0.1.0-nullsafety.1 * Bump win32 dependency to latest version. diff --git a/packages/path_provider/path_provider_windows/example/windows/flutter/CMakeLists.txt b/packages/path_provider/path_provider_windows/example/windows/flutter/CMakeLists.txt index c7a8c7607d81..744f08a9389b 100644 --- a/packages/path_provider/path_provider_windows/example/windows/flutter/CMakeLists.txt +++ b/packages/path_provider/path_provider_windows/example/windows/flutter/CMakeLists.txt @@ -91,6 +91,7 @@ add_custom_command( ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" windows-x64 $ + VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" diff --git a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart index c104343f2502..c88e10a0f9b3 100644 --- a/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart +++ b/packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart @@ -28,17 +28,17 @@ class VersionInfoQuerier { } const kEnUsLanguageCode = '040904e4'; final keyPath = TEXT('\\StringFileInfo\\$kEnUsLanguageCode\\$key'); - final length = allocate(); - final valueAddress = allocate>(); + final length = calloc(); + final valueAddress = calloc>(); try { if (VerQueryValue(versionInfo, keyPath, valueAddress, length) == 0) { return null; } return valueAddress.value.unpackString(length.value); } finally { - free(keyPath); - free(length); - free(valueAddress); + calloc.free(keyPath); + calloc.free(length); + calloc.free(valueAddress); } } } @@ -54,7 +54,7 @@ class PathProviderWindows extends PathProviderPlatform { /// This is typically the same as the TMP environment variable. @override Future getTemporaryPath() async { - final buffer = allocate(count: MAX_PATH + 1).cast(); + final buffer = calloc(MAX_PATH + 1).cast(); String path; try { @@ -82,7 +82,7 @@ class PathProviderWindows extends PathProviderPlatform { return Future.value(path); } finally { - free(buffer); + calloc.free(buffer); } } @@ -115,7 +115,7 @@ class PathProviderWindows extends PathProviderPlatform { /// folderID is a GUID that represents a specific known folder ID, drawn from /// [WindowsKnownFolder]. Future getPath(String folderID) { - final pathPtrPtr = allocate>(); + final pathPtrPtr = calloc>(); final Pointer knownFolderID = calloc()..ref.setGUID(folderID); try { @@ -135,8 +135,8 @@ class PathProviderWindows extends PathProviderPlatform { final path = pathPtrPtr.value.unpackString(MAX_PATH); return Future.value(path); } finally { - free(pathPtrPtr); - free(knownFolderID); + calloc.free(pathPtrPtr); + calloc.free(knownFolderID); } } @@ -155,8 +155,8 @@ class PathProviderWindows extends PathProviderPlatform { String? productName; final Pointer moduleNameBuffer = - allocate(count: MAX_PATH + 1).cast(); - final Pointer unused = allocate(); + calloc(MAX_PATH + 1).cast(); + final Pointer unused = calloc(); Pointer? infoBuffer; try { // Get the module name. @@ -169,10 +169,10 @@ class PathProviderWindows extends PathProviderPlatform { // From that, load the VERSIONINFO resource int infoSize = GetFileVersionInfoSize(moduleNameBuffer, unused); if (infoSize != 0) { - infoBuffer = allocate(count: infoSize); + infoBuffer = calloc(infoSize); if (GetFileVersionInfo(moduleNameBuffer, 0, infoSize, infoBuffer) == 0) { - free(infoBuffer); + calloc.free(infoBuffer); infoBuffer = null; } } @@ -191,10 +191,10 @@ class PathProviderWindows extends PathProviderPlatform { ? path.join(companyName, productName) : productName; } finally { - free(moduleNameBuffer); - free(unused); + calloc.free(moduleNameBuffer); + calloc.free(unused); if (infoBuffer != null) { - free(infoBuffer); + calloc.free(infoBuffer); } } } diff --git a/packages/path_provider/path_provider_windows/pubspec.yaml b/packages/path_provider/path_provider_windows/pubspec.yaml index 578000682e63..922594a9bd2d 100644 --- a/packages/path_provider/path_provider_windows/pubspec.yaml +++ b/packages/path_provider/path_provider_windows/pubspec.yaml @@ -1,7 +1,7 @@ name: path_provider_windows description: Windows implementation of the path_provider plugin homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_windows -version: 0.1.0-nullsafety.1 +version: 0.1.0-nullsafety.2 flutter: plugin: @@ -16,8 +16,8 @@ dependencies: path: ^1.8.0-nullsafety.3 flutter: sdk: flutter - ffi: ^0.2.0-nullsafety.1 - win32: ^2.0.0-nullsafety.9 + ffi: '>=0.3.0-nullsafety.1 <2.0.0' + win32: ^2.0.0-nullsafety.10 dev_dependencies: flutter_test: @@ -25,5 +25,6 @@ dev_dependencies: pedantic: ^1.10.0-nullsafety.3 environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0-259.8.beta <3.0.0' flutter: ">=1.12.13+hotfix.4" +