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

Use FML_DCHECK in place of assert in codec utils #38365

Merged
merged 1 commit into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand All @@ -60,6 +60,8 @@ source_set("flutter_channels_arc") {
]

public_configs = [ "//flutter:config" ]

deps = [ "//flutter/fml" ]
}

test_fixtures("flutter_channels_fixtures") {
Expand Down
4 changes: 3 additions & 1 deletion shell/platform/darwin/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand All @@ -49,4 +49,6 @@ source_set("framework_shared") {
"//flutter:config",
":framework_relative_headers",
]

deps = [ "//flutter/fml" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
#include "flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h"
#include <stdint.h>

#include <vector>

#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;
Expand All @@ -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<UInt8*>(destination));
*location += length;
}

Expand Down Expand Up @@ -59,7 +69,7 @@ static CFDataRef ReadDataNoCopy(unsigned long* location,
kCFAllocatorDefault, CFDataGetBytePtr(data) + *location, length,
kCFAllocatorNull);
*location += length;
return CFAutorelease(result);
return static_cast<CFDataRef>(CFAutorelease(result));
}

CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location,
Expand All @@ -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<CFStringRef>(CFAutorelease(result));
}

// Peeks ahead to see if we are reading a standard type. If so, recurse
Expand Down Expand Up @@ -161,7 +171,7 @@ CFTypeRef FlutterStandardCodecHelperReadValueOfType(
}
default:
// Malformed message.
assert(false);
FML_DCHECK(false);
}
}

Expand All @@ -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<const UInt8*>(bytes), length);
}

void FlutterStandardCodecHelperWriteSize(CFMutableDataRef data, uint32_t size) {
Expand Down Expand Up @@ -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<UInt8> 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);
}
}

Expand Down Expand Up @@ -259,3 +269,5 @@ bool FlutterStandardCodecHelperWriteNumber(CFMutableDataRef data,
}
return success;
}

// NOLINTEND(google-runtime-int)