Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 235e7c6

Browse files
committed
Even though the file is pure C code, it's useful to use a C++ or Objective-C++ filename in order to use FML (assertions) in the implementation.
Three implementation changes: * Since the file is now C++, some implicit void* conversions now require an explicit cast. * A malloc/free of a buffer has been replaced with a std::vector. * An `assert()` was changed to `FML_DCHECK` for consistency with the rest of the embedder. No test changes since there are no semantic changes. Existing tests are in: https://github.com/flutter/engine/blob/main/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm
1 parent 42689ea commit 235e7c6

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

ci/licenses_golden/licenses_flutter

+2-2
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterCh
24172417
ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m + ../../../flutter/LICENSE
24182418
ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterCodecs.mm + ../../../flutter/LICENSE
24192419
ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec.mm + ../../../flutter/LICENSE
2420-
ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c + ../../../flutter/LICENSE
2420+
ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc + ../../../flutter/LICENSE
24212421
ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h + ../../../flutter/LICENSE
24222422
ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h + ../../../flutter/LICENSE
24232423
ORIGIN: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h + ../../../flutter/LICENSE
@@ -4874,7 +4874,7 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChan
48744874
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m
48754875
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterCodecs.mm
48764876
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec.mm
4877-
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c
4877+
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc
48784878
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h
48794879
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h
48804880
FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h

shell/platform/darwin/BUILD.gn

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ source_set("flutter_channels_arc") {
4747
"common/framework/Source/FlutterChannels.mm",
4848
"common/framework/Source/FlutterCodecs.mm",
4949
"common/framework/Source/FlutterStandardCodec.mm",
50-
"common/framework/Source/FlutterStandardCodecHelper.c",
50+
"common/framework/Source/FlutterStandardCodecHelper.cc",
5151
"common/framework/Source/FlutterStandardCodec_Internal.h",
5252
]
5353

@@ -60,6 +60,8 @@ source_set("flutter_channels_arc") {
6060
]
6161

6262
public_configs = [ "//flutter:config" ]
63+
64+
deps = [ "//flutter/fml" ]
6365
}
6466

6567
test_fixtures("flutter_channels_fixtures") {

shell/platform/darwin/common/BUILD.gn

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ source_set("framework_shared") {
3737
"framework/Source/FlutterChannels.mm",
3838
"framework/Source/FlutterCodecs.mm",
3939
"framework/Source/FlutterStandardCodec.mm",
40-
"framework/Source/FlutterStandardCodecHelper.c",
40+
"framework/Source/FlutterStandardCodecHelper.cc",
4141
"framework/Source/FlutterStandardCodec_Internal.h",
4242
]
4343

@@ -49,4 +49,6 @@ source_set("framework_shared") {
4949
"//flutter:config",
5050
":framework_relative_headers",
5151
]
52+
53+
deps = [ "//flutter/fml" ]
5254
}

shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c renamed to shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc

+13-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include "flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h"
66
#include <stdint.h>
77

8+
#include <vector>
9+
10+
#include "flutter/fml/logging.h"
11+
812
void FlutterStandardCodecHelperReadAlignment(unsigned long* location,
913
uint8_t alignment) {
1014
uint8_t mod = *location % alignment;
@@ -25,7 +29,7 @@ void FlutterStandardCodecHelperReadBytes(unsigned long* location,
2529
void* destination,
2630
CFDataRef data) {
2731
CFRange range = CFRangeMake(*location, length);
28-
CFDataGetBytes(data, range, destination);
32+
CFDataGetBytes(data, range, static_cast<UInt8*>(destination));
2933
*location += length;
3034
}
3135

@@ -59,7 +63,7 @@ static CFDataRef ReadDataNoCopy(unsigned long* location,
5963
kCFAllocatorDefault, CFDataGetBytePtr(data) + *location, length,
6064
kCFAllocatorNull);
6165
*location += length;
62-
return CFAutorelease(result);
66+
return static_cast<CFDataRef>(CFAutorelease(result));
6367
}
6468

6569
CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location,
@@ -68,7 +72,7 @@ CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location,
6872
CFDataRef bytes = ReadDataNoCopy(location, size, data);
6973
CFStringRef result = CFStringCreateFromExternalRepresentation(
7074
kCFAllocatorDefault, bytes, kCFStringEncodingUTF8);
71-
return CFAutorelease(result);
75+
return static_cast<CFStringRef>(CFAutorelease(result));
7276
}
7377

7478
// Peeks ahead to see if we are reading a standard type. If so, recurse
@@ -161,7 +165,7 @@ CFTypeRef FlutterStandardCodecHelperReadValueOfType(
161165
}
162166
default:
163167
// Malformed message.
164-
assert(false);
168+
FML_DCHECK(false);
165169
}
166170
}
167171

@@ -172,7 +176,7 @@ void FlutterStandardCodecHelperWriteByte(CFMutableDataRef data, uint8_t value) {
172176
void FlutterStandardCodecHelperWriteBytes(CFMutableDataRef data,
173177
const void* bytes,
174178
unsigned long length) {
175-
CFDataAppendBytes(data, bytes, length);
179+
CFDataAppendBytes(data, static_cast<const UInt8*>(bytes), length);
176180
}
177181

178182
void FlutterStandardCodecHelperWriteSize(CFMutableDataRef data, uint32_t size) {
@@ -210,12 +214,12 @@ void FlutterStandardCodecHelperWriteUTF8(CFMutableDataRef data,
210214
CFIndex used_length = 0;
211215
// UTF16 length times 3 will fit all UTF8.
212216
CFIndex buffer_length = length * 3;
213-
UInt8* buffer = (UInt8*)malloc(buffer_length * sizeof(UInt8));
217+
std::vector<UInt8> buffer;
218+
buffer.reserve(buffer_length);
214219
CFStringGetBytes(value, CFRangeMake(0, length), kCFStringEncodingUTF8, 0,
215-
false, buffer, buffer_length, &used_length);
220+
false, buffer.data(), buffer_length, &used_length);
216221
FlutterStandardCodecHelperWriteSize(data, used_length);
217-
FlutterStandardCodecHelperWriteBytes(data, buffer, used_length);
218-
free(buffer);
222+
FlutterStandardCodecHelperWriteBytes(data, buffer.data(), used_length);
219223
}
220224
}
221225

0 commit comments

Comments
 (0)