| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "include/dart_native_api.h" | 5 #include "include/dart_native_api.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_message.h" | 9 #include "vm/dart_api_message.h" |
| 10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
| 11 #include "vm/message.h" | 11 #include "vm/message.h" |
| 12 #include "vm/native_message_handler.h" | 12 #include "vm/native_message_handler.h" |
| 13 #include "vm/port.h" | 13 #include "vm/port.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 // --- Message sending/receiving from native code --- | 17 // --- Message sending/receiving from native code --- |
| 18 | 18 |
| 19 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 19 static uint8_t* malloc_allocator(uint8_t* ptr, |
| 20 intptr_t old_size, |
| 21 intptr_t new_size) { |
| 20 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 22 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 21 return reinterpret_cast<uint8_t*>(new_ptr); | 23 return reinterpret_cast<uint8_t*>(new_ptr); |
| 22 } | 24 } |
| 23 | 25 |
| 24 | 26 |
| 25 class IsolateSaver { | 27 class IsolateSaver { |
| 26 public: | 28 public: |
| 27 explicit IsolateSaver(Isolate* current_isolate) | 29 explicit IsolateSaver(Isolate* current_isolate) |
| 28 : saved_isolate_(current_isolate) { | 30 : saved_isolate_(current_isolate) { |
| 29 if (current_isolate != NULL) { | 31 if (current_isolate != NULL) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 Isolate* saved_isolate_; | 44 Isolate* saved_isolate_; |
| 43 | 45 |
| 44 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); | 46 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 | 49 |
| 48 static bool PostCObjectHelper(Dart_Port port_id, Dart_CObject* message) { | 50 static bool PostCObjectHelper(Dart_Port port_id, Dart_CObject* message) { |
| 49 uint8_t* buffer = NULL; | 51 uint8_t* buffer = NULL; |
| 50 ApiMessageWriter writer(&buffer, allocator); | 52 ApiMessageWriter writer(&buffer, malloc_allocator); |
| 51 bool success = writer.WriteCMessage(message); | 53 bool success = writer.WriteCMessage(message); |
| 52 | 54 |
| 53 if (!success) return success; | 55 if (!success) { |
| 56 free(buffer); |
| 57 return success; |
| 58 } |
| 54 | 59 |
| 55 // Post the message at the given port. | 60 // Post the message at the given port. |
| 56 return PortMap::PostMessage(new Message( | 61 return PortMap::PostMessage(new Message( |
| 57 port_id, buffer, writer.BytesWritten(), Message::kNormalPriority)); | 62 port_id, buffer, writer.BytesWritten(), Message::kNormalPriority)); |
| 58 } | 63 } |
| 59 | 64 |
| 60 | 65 |
| 61 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { | 66 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { |
| 62 return PostCObjectHelper(port_id, message); | 67 return PostCObjectHelper(port_id, message); |
| 63 } | 68 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); | 152 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); |
| 148 if (::Dart_IsError(result)) { | 153 if (::Dart_IsError(result)) { |
| 149 return result; | 154 return result; |
| 150 } | 155 } |
| 151 CHECK_CALLBACK_STATE(T); | 156 CHECK_CALLBACK_STATE(T); |
| 152 ParseAll(T, &result); | 157 ParseAll(T, &result); |
| 153 return result; | 158 return result; |
| 154 } | 159 } |
| 155 | 160 |
| 156 } // namespace dart | 161 } // namespace dart |
| OLD | NEW |