Files
sdk/runtime/vm/base64_test.cc
T
Martin Kustermann ab6aeaa106 [vm/kernel] Use GC-tracked ExternalTypedData/TypedDataView for kernel buffers
Until now we often leaked kernel buffers (e.g. hot reload buffers) because various
objects were referencing ExternalTypedData objects pointing into the middle of
c-allocated memory. This made it impossible for the GC to determine when the last
reference is gone.

This CL ensures that the actual buffers are *always* made available via
ExternalTypedData and any inner pointers into it are created via TypedDataViews.

The embedder guarantees to the free kernel buffers it has provided to:
    - Dart_CreateIsolateFromKernel
    - Dart_LoadScriptFromKernel
    - Dart_LoadLibraryFromKernel
    - Dart_SetDartLibrarySourcesKernel
on isolate shutdown.

All other kernel buffers will get a finalizer attached, which ensures the
kernel buffers get freed by the GC once they are no longer referenced:
    - Kernel blobs for expression evaluation
    - Kernel blobs for Hot-Reload
    - Kernel blobs for cc tests

Fixes https://github.com/dart-lang/sdk/issues/33973
Fixes https://github.com/dart-lang/sdk/issues/36857
Issue https://github.com/dart-lang/sdk/issues/37030

Change-Id: I1cc410c94c0f4b229413e793728a261afcb10aaf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103130
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2019-05-22 01:23:46 +00:00

32 lines
942 B
C++

// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/base64.h"
#include "platform/assert.h"
#include "vm/unit_test.h"
namespace dart {
TEST_CASE(Base64Decode) {
intptr_t decoded_len;
uint8_t* decoded_bytes = DecodeBase64("SGVsbG8sIHdvcmxkIQo=", &decoded_len);
const char expected_bytes[] = "Hello, world!\n";
intptr_t expected_len = strlen(expected_bytes);
EXPECT(!memcmp(expected_bytes, decoded_bytes, expected_len));
EXPECT_EQ(expected_len, decoded_len);
delete[] decoded_bytes;
}
TEST_CASE(Base64DecodeMalformed) {
intptr_t decoded_len;
EXPECT(DecodeBase64("SomethingMalformed", &decoded_len) == nullptr);
}
TEST_CASE(Base64DecodeEmpty) {
intptr_t decoded_len;
EXPECT(DecodeBase64("", &decoded_len) == nullptr);
}
} // namespace dart