| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_BIN_IO_BUFFER_H_ | 5 #ifndef RUNTIME_BIN_IO_BUFFER_H_ |
| 6 #define RUNTIME_BIN_IO_BUFFER_H_ | 6 #define RUNTIME_BIN_IO_BUFFER_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 namespace bin { | 12 namespace bin { |
| 13 | 13 |
| 14 class IOBuffer { | 14 class IOBuffer { |
| 15 public: | 15 public: |
| 16 // Allocate an IO buffer dart object (of type Uint8List) backed by | 16 // Allocate an IO buffer dart object (of type Uint8List) backed by |
| 17 // an external byte array. | 17 // an external byte array. |
| 18 static Dart_Handle Allocate(intptr_t size, uint8_t **buffer); | 18 static Dart_Handle Allocate(intptr_t size, uint8_t** buffer); |
| 19 | 19 |
| 20 // Allocate IO buffer storage. | 20 // Allocate IO buffer storage. |
| 21 static uint8_t* Allocate(intptr_t size); | 21 static uint8_t* Allocate(intptr_t size); |
| 22 | 22 |
| 23 // Function for disposing of IO buffer storage. All backing storage | 23 // Function for disposing of IO buffer storage. All backing storage |
| 24 // for IO buffers must be freed using this function. | 24 // for IO buffers must be freed using this function. |
| 25 static void Free(void* buffer) { | 25 static void Free(void* buffer) { |
| 26 delete[] reinterpret_cast<uint8_t*>(buffer); | 26 delete[] reinterpret_cast<uint8_t*>(buffer); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Function for finalizing external byte arrays used as IO buffers. | 29 // Function for finalizing external byte arrays used as IO buffers. |
| 30 static void Finalizer(void* isolate_callback_data, | 30 static void Finalizer(void* isolate_callback_data, |
| 31 Dart_WeakPersistentHandle handle, | 31 Dart_WeakPersistentHandle handle, |
| 32 void* buffer) { | 32 void* buffer) { |
| 33 Free(buffer); | 33 Free(buffer); |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 DISALLOW_ALLOCATION(); | 37 DISALLOW_ALLOCATION(); |
| 38 DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer); | 38 DISALLOW_IMPLICIT_CONSTRUCTORS(IOBuffer); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 } // namespace bin | 41 } // namespace bin |
| 42 } // namespace dart | 42 } // namespace dart |
| 43 | 43 |
| 44 #endif // RUNTIME_BIN_IO_BUFFER_H_ | 44 #endif // RUNTIME_BIN_IO_BUFFER_H_ |
| OLD | NEW |