diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index fb068a796a759..5b7ab4907fada 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -2417,7 +2417,7 @@ ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterCh ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterCodecs.mm + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec.mm + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h + ../../../flutter/LICENSE @@ -4874,7 +4874,7 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChan FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterCodecs.mm FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec.mm -FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c +FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h FILE: ../../../flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h diff --git a/shell/platform/darwin/BUILD.gn b/shell/platform/darwin/BUILD.gn index 766261c9bab1e..7ff997fa4fced 100644 --- a/shell/platform/darwin/BUILD.gn +++ b/shell/platform/darwin/BUILD.gn @@ -47,7 +47,7 @@ source_set("flutter_channels_arc") { "common/framework/Source/FlutterChannels.mm", "common/framework/Source/FlutterCodecs.mm", "common/framework/Source/FlutterStandardCodec.mm", - "common/framework/Source/FlutterStandardCodecHelper.c", + "common/framework/Source/FlutterStandardCodecHelper.cc", "common/framework/Source/FlutterStandardCodec_Internal.h", ] @@ -60,6 +60,8 @@ source_set("flutter_channels_arc") { ] public_configs = [ "//flutter:config" ] + + deps = [ "//flutter/fml" ] } test_fixtures("flutter_channels_fixtures") { diff --git a/shell/platform/darwin/common/BUILD.gn b/shell/platform/darwin/common/BUILD.gn index 59599e0f4cb0c..a3210bfed4d25 100644 --- a/shell/platform/darwin/common/BUILD.gn +++ b/shell/platform/darwin/common/BUILD.gn @@ -37,7 +37,7 @@ source_set("framework_shared") { "framework/Source/FlutterChannels.mm", "framework/Source/FlutterCodecs.mm", "framework/Source/FlutterStandardCodec.mm", - "framework/Source/FlutterStandardCodecHelper.c", + "framework/Source/FlutterStandardCodecHelper.cc", "framework/Source/FlutterStandardCodec_Internal.h", ] @@ -49,4 +49,6 @@ source_set("framework_shared") { "//flutter:config", ":framework_relative_headers", ] + + deps = [ "//flutter/fml" ] } diff --git a/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c b/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc similarity index 92% rename from shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c rename to shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc index d3cb78c9a1ebc..38b9127f41f0d 100644 --- a/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.c +++ b/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.cc @@ -5,6 +5,16 @@ #include "flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h" #include +#include + +#include "flutter/fml/logging.h" + +// The google-runtime-int lint suggests uint64_t in place of unsigned long, +// however these functions are frequently used with NSUInteger, which is +// defined as an unsigned long. +// +// NOLINTBEGIN(google-runtime-int) + void FlutterStandardCodecHelperReadAlignment(unsigned long* location, uint8_t alignment) { uint8_t mod = *location % alignment; @@ -25,7 +35,7 @@ void FlutterStandardCodecHelperReadBytes(unsigned long* location, void* destination, CFDataRef data) { CFRange range = CFRangeMake(*location, length); - CFDataGetBytes(data, range, destination); + CFDataGetBytes(data, range, static_cast(destination)); *location += length; } @@ -59,7 +69,7 @@ static CFDataRef ReadDataNoCopy(unsigned long* location, kCFAllocatorDefault, CFDataGetBytePtr(data) + *location, length, kCFAllocatorNull); *location += length; - return CFAutorelease(result); + return static_cast(CFAutorelease(result)); } CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location, @@ -68,7 +78,7 @@ CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location, CFDataRef bytes = ReadDataNoCopy(location, size, data); CFStringRef result = CFStringCreateFromExternalRepresentation( kCFAllocatorDefault, bytes, kCFStringEncodingUTF8); - return CFAutorelease(result); + return static_cast(CFAutorelease(result)); } // Peeks ahead to see if we are reading a standard type. If so, recurse @@ -161,7 +171,7 @@ CFTypeRef FlutterStandardCodecHelperReadValueOfType( } default: // Malformed message. - assert(false); + FML_DCHECK(false); } } @@ -172,7 +182,7 @@ void FlutterStandardCodecHelperWriteByte(CFMutableDataRef data, uint8_t value) { void FlutterStandardCodecHelperWriteBytes(CFMutableDataRef data, const void* bytes, unsigned long length) { - CFDataAppendBytes(data, bytes, length); + CFDataAppendBytes(data, static_cast(bytes), length); } void FlutterStandardCodecHelperWriteSize(CFMutableDataRef data, uint32_t size) { @@ -210,12 +220,12 @@ void FlutterStandardCodecHelperWriteUTF8(CFMutableDataRef data, CFIndex used_length = 0; // UTF16 length times 3 will fit all UTF8. CFIndex buffer_length = length * 3; - UInt8* buffer = (UInt8*)malloc(buffer_length * sizeof(UInt8)); + std::vector buffer; + buffer.reserve(buffer_length); CFStringGetBytes(value, CFRangeMake(0, length), kCFStringEncodingUTF8, 0, - false, buffer, buffer_length, &used_length); + false, buffer.data(), buffer_length, &used_length); FlutterStandardCodecHelperWriteSize(data, used_length); - FlutterStandardCodecHelperWriteBytes(data, buffer, used_length); - free(buffer); + FlutterStandardCodecHelperWriteBytes(data, buffer.data(), used_length); } } @@ -259,3 +269,5 @@ bool FlutterStandardCodecHelperWriteNumber(CFMutableDataRef data, } return success; } + +// NOLINTEND(google-runtime-int)