Files
sdk/runtime/bin/io_buffer.cc
T
Ryan Macnak cff0e751a5 [vm] Add Dart_NewExternalTypedDataWithFinalizer.
Allows the finalizer to be associated with the correct object when creating ByteData. The finalizer should be associated with the underlying ExternalUint8List, since it can outlive the ByteData via byteData.buffer.asUint8List()

Bug: b/78150644
Change-Id: I3db58792bbe3abf7ed41d2adaf225fa554b8fb25
Reviewed-on: https://dart-review.googlesource.com/52860
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2018-05-01 01:57:41 +00:00

34 lines
859 B
C++

// Copyright (c) 2012, 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 "bin/io_buffer.h"
namespace dart {
namespace bin {
Dart_Handle IOBuffer::Allocate(intptr_t size, uint8_t** buffer) {
uint8_t* data = Allocate(size);
if (data == NULL) {
return Dart_Null();
}
Dart_Handle result = Dart_NewExternalTypedDataWithFinalizer(
Dart_TypedData_kUint8, data, size, data, size, IOBuffer::Finalizer);
if (Dart_IsError(result)) {
Free(data);
Dart_PropagateError(result);
}
if (buffer != NULL) {
*buffer = data;
}
return result;
}
uint8_t* IOBuffer::Allocate(intptr_t size) {
return reinterpret_cast<uint8_t*>(malloc(size));
}
} // namespace bin
} // namespace dart