Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Update to ffi 0.3.0-nullsafety.1 (#3513)
Browse files Browse the repository at this point in the history
ffi 0.3.0 supports the new memory allocation model in Dart 2.12.0-259 and later.
  • Loading branch information
Tim Sneath authored Feb 5, 2021
1 parent 7f5696c commit ad308e5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
4 changes: 4 additions & 0 deletions packages/path_provider/path_provider_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ add_custom_command(
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
"${FLUTTER_LIBRARY}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class VersionInfoQuerier {
}
const kEnUsLanguageCode = '040904e4';
final keyPath = TEXT('\\StringFileInfo\\$kEnUsLanguageCode\\$key');
final length = allocate<Uint32>();
final valueAddress = allocate<Pointer<Utf16>>();
final length = calloc<Uint32>();
final valueAddress = calloc<Pointer<Utf16>>();
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);
}
}
}
Expand All @@ -54,7 +54,7 @@ class PathProviderWindows extends PathProviderPlatform {
/// This is typically the same as the TMP environment variable.
@override
Future<String?> getTemporaryPath() async {
final buffer = allocate<Uint16>(count: MAX_PATH + 1).cast<Utf16>();
final buffer = calloc<Uint16>(MAX_PATH + 1).cast<Utf16>();
String path;

try {
Expand Down Expand Up @@ -82,7 +82,7 @@ class PathProviderWindows extends PathProviderPlatform {

return Future.value(path);
} finally {
free(buffer);
calloc.free(buffer);
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ class PathProviderWindows extends PathProviderPlatform {
/// folderID is a GUID that represents a specific known folder ID, drawn from
/// [WindowsKnownFolder].
Future<String> getPath(String folderID) {
final pathPtrPtr = allocate<Pointer<Utf16>>();
final pathPtrPtr = calloc<Pointer<Utf16>>();
final Pointer<GUID> knownFolderID = calloc<GUID>()..ref.setGUID(folderID);

try {
Expand All @@ -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);
}
}

Expand All @@ -155,8 +155,8 @@ class PathProviderWindows extends PathProviderPlatform {
String? productName;

final Pointer<Utf16> moduleNameBuffer =
allocate<Uint16>(count: MAX_PATH + 1).cast<Utf16>();
final Pointer<Uint32> unused = allocate<Uint32>();
calloc<Uint16>(MAX_PATH + 1).cast<Utf16>();
final Pointer<Uint32> unused = calloc<Uint32>();
Pointer<Uint8>? infoBuffer;
try {
// Get the module name.
Expand All @@ -169,10 +169,10 @@ class PathProviderWindows extends PathProviderPlatform {
// From that, load the VERSIONINFO resource
int infoSize = GetFileVersionInfoSize(moduleNameBuffer, unused);
if (infoSize != 0) {
infoBuffer = allocate<Uint8>(count: infoSize);
infoBuffer = calloc<Uint8>(infoSize);
if (GetFileVersionInfo(moduleNameBuffer, 0, infoSize, infoBuffer) ==
0) {
free(infoBuffer);
calloc.free(infoBuffer);
infoBuffer = null;
}
}
Expand All @@ -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);
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions packages/path_provider/path_provider_windows/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -16,14 +16,15 @@ 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:
sdk: flutter
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"

0 comments on commit ad308e5

Please sign in to comment.