Skip to content

Commit ad308e5

Browse files
author
Tim Sneath
authored
Update to ffi 0.3.0-nullsafety.1 (flutter#3513)
ffi 0.3.0 supports the new memory allocation model in Dart 2.12.0-259 and later.
1 parent 7f5696c commit ad308e5

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

packages/path_provider/path_provider_windows/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.0-nullsafety.2
2+
3+
* Bump ffi dependency to 0.3.0-nullsafety.1
4+
15
## 0.1.0-nullsafety.1
26

37
* Bump win32 dependency to latest version.

packages/path_provider/path_provider_windows/example/windows/flutter/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ add_custom_command(
9191
${FLUTTER_TOOL_ENVIRONMENT}
9292
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
9393
windows-x64 $<CONFIG>
94+
VERBATIM
9495
)
9596
add_custom_target(flutter_assemble DEPENDS
9697
"${FLUTTER_LIBRARY}"

packages/path_provider/path_provider_windows/lib/src/path_provider_windows_real.dart

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ class VersionInfoQuerier {
2828
}
2929
const kEnUsLanguageCode = '040904e4';
3030
final keyPath = TEXT('\\StringFileInfo\\$kEnUsLanguageCode\\$key');
31-
final length = allocate<Uint32>();
32-
final valueAddress = allocate<Pointer<Utf16>>();
31+
final length = calloc<Uint32>();
32+
final valueAddress = calloc<Pointer<Utf16>>();
3333
try {
3434
if (VerQueryValue(versionInfo, keyPath, valueAddress, length) == 0) {
3535
return null;
3636
}
3737
return valueAddress.value.unpackString(length.value);
3838
} finally {
39-
free(keyPath);
40-
free(length);
41-
free(valueAddress);
39+
calloc.free(keyPath);
40+
calloc.free(length);
41+
calloc.free(valueAddress);
4242
}
4343
}
4444
}
@@ -54,7 +54,7 @@ class PathProviderWindows extends PathProviderPlatform {
5454
/// This is typically the same as the TMP environment variable.
5555
@override
5656
Future<String?> getTemporaryPath() async {
57-
final buffer = allocate<Uint16>(count: MAX_PATH + 1).cast<Utf16>();
57+
final buffer = calloc<Uint16>(MAX_PATH + 1).cast<Utf16>();
5858
String path;
5959

6060
try {
@@ -82,7 +82,7 @@ class PathProviderWindows extends PathProviderPlatform {
8282

8383
return Future.value(path);
8484
} finally {
85-
free(buffer);
85+
calloc.free(buffer);
8686
}
8787
}
8888

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

121121
try {
@@ -135,8 +135,8 @@ class PathProviderWindows extends PathProviderPlatform {
135135
final path = pathPtrPtr.value.unpackString(MAX_PATH);
136136
return Future.value(path);
137137
} finally {
138-
free(pathPtrPtr);
139-
free(knownFolderID);
138+
calloc.free(pathPtrPtr);
139+
calloc.free(knownFolderID);
140140
}
141141
}
142142

@@ -155,8 +155,8 @@ class PathProviderWindows extends PathProviderPlatform {
155155
String? productName;
156156

157157
final Pointer<Utf16> moduleNameBuffer =
158-
allocate<Uint16>(count: MAX_PATH + 1).cast<Utf16>();
159-
final Pointer<Uint32> unused = allocate<Uint32>();
158+
calloc<Uint16>(MAX_PATH + 1).cast<Utf16>();
159+
final Pointer<Uint32> unused = calloc<Uint32>();
160160
Pointer<Uint8>? infoBuffer;
161161
try {
162162
// Get the module name.
@@ -169,10 +169,10 @@ class PathProviderWindows extends PathProviderPlatform {
169169
// From that, load the VERSIONINFO resource
170170
int infoSize = GetFileVersionInfoSize(moduleNameBuffer, unused);
171171
if (infoSize != 0) {
172-
infoBuffer = allocate<Uint8>(count: infoSize);
172+
infoBuffer = calloc<Uint8>(infoSize);
173173
if (GetFileVersionInfo(moduleNameBuffer, 0, infoSize, infoBuffer) ==
174174
0) {
175-
free(infoBuffer);
175+
calloc.free(infoBuffer);
176176
infoBuffer = null;
177177
}
178178
}
@@ -191,10 +191,10 @@ class PathProviderWindows extends PathProviderPlatform {
191191
? path.join(companyName, productName)
192192
: productName;
193193
} finally {
194-
free(moduleNameBuffer);
195-
free(unused);
194+
calloc.free(moduleNameBuffer);
195+
calloc.free(unused);
196196
if (infoBuffer != null) {
197-
free(infoBuffer);
197+
calloc.free(infoBuffer);
198198
}
199199
}
200200
}

packages/path_provider/path_provider_windows/pubspec.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: path_provider_windows
22
description: Windows implementation of the path_provider plugin
33
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_windows
4-
version: 0.1.0-nullsafety.1
4+
version: 0.1.0-nullsafety.2
55

66
flutter:
77
plugin:
@@ -16,14 +16,15 @@ dependencies:
1616
path: ^1.8.0-nullsafety.3
1717
flutter:
1818
sdk: flutter
19-
ffi: ^0.2.0-nullsafety.1
20-
win32: ^2.0.0-nullsafety.9
19+
ffi: '>=0.3.0-nullsafety.1 <2.0.0'
20+
win32: ^2.0.0-nullsafety.10
2121

2222
dev_dependencies:
2323
flutter_test:
2424
sdk: flutter
2525
pedantic: ^1.10.0-nullsafety.3
2626

2727
environment:
28-
sdk: '>=2.12.0-0 <3.0.0'
28+
sdk: '>=2.12.0-259.8.beta <3.0.0'
2929
flutter: ">=1.12.13+hotfix.4"
30+

0 commit comments

Comments
 (0)