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 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 success = isolate->object_store()->PreallocateObjects(); | 158 success = isolate->object_store()->PreallocateObjects(); |
159 if (success) { | 159 if (success) { |
160 return NULL; | 160 return NULL; |
161 } | 161 } |
162 } | 162 } |
163 // Make a copy of the error message as the original message string | 163 // Make a copy of the error message as the original message string |
164 // may get deallocated when we return back from the Dart API call. | 164 // may get deallocated when we return back from the Dart API call. |
165 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); | 165 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); |
166 const char* errmsg = err.ToErrorCString(); | 166 const char* errmsg = err.ToErrorCString(); |
167 intptr_t errlen = strlen(errmsg) + 1; | 167 intptr_t errlen = strlen(errmsg) + 1; |
168 char* msg = reinterpret_cast<char*>(Api::Allocate(isolate, errlen)); | 168 char* msg = Api::TopScope(isolate)->zone()->Alloc<char>(errlen); |
169 OS::SNPrint(msg, errlen, "%s", errmsg); | 169 OS::SNPrint(msg, errlen, "%s", errmsg); |
170 return msg; | 170 return msg; |
171 } | 171 } |
172 | 172 |
173 | 173 |
174 void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) { | 174 void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) { |
175 *handle = Api::NewHandle( | 175 *handle = Api::NewHandle( |
176 isolate, Isolate::Current()->object_store()->sticky_error()); | 176 isolate, Isolate::Current()->object_store()->sticky_error()); |
177 } | 177 } |
178 | 178 |
179 | 179 |
180 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { | 180 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { |
181 ASSERT(isolate != NULL); | 181 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); |
182 ApiState* state = isolate->api_state(); | |
183 ASSERT(state != NULL); | |
184 ApiLocalScope* scope = state->top_scope(); | |
185 ASSERT(scope != NULL); | |
186 LocalHandles* local_handles = scope->local_handles(); | |
187 ASSERT(local_handles != NULL); | 182 ASSERT(local_handles != NULL); |
188 LocalHandle* ref = local_handles->AllocateHandle(); | 183 LocalHandle* ref = local_handles->AllocateHandle(); |
189 ref->set_raw(raw); | 184 ref->set_raw(raw); |
190 return reinterpret_cast<Dart_Handle>(ref); | 185 return reinterpret_cast<Dart_Handle>(ref); |
191 } | 186 } |
192 | 187 |
193 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 188 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
194 #if defined(DEBUG) | 189 #if defined(DEBUG) |
195 Isolate* isolate = Isolate::Current(); | 190 Isolate* isolate = Isolate::Current(); |
196 ASSERT(isolate != NULL); | 191 ASSERT(isolate != NULL); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 261 |
267 Dart_Handle Api::NewError(const char* format, ...) { | 262 Dart_Handle Api::NewError(const char* format, ...) { |
268 Isolate* isolate = Isolate::Current(); | 263 Isolate* isolate = Isolate::Current(); |
269 DARTSCOPE_NOCHECKS(isolate); | 264 DARTSCOPE_NOCHECKS(isolate); |
270 | 265 |
271 va_list args; | 266 va_list args; |
272 va_start(args, format); | 267 va_start(args, format); |
273 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 268 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
274 va_end(args); | 269 va_end(args); |
275 | 270 |
276 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 271 char* buffer = zone.Alloc<char>(len + 1); |
277 va_list args2; | 272 va_list args2; |
278 va_start(args2, format); | 273 va_start(args2, format); |
279 OS::VSNPrint(buffer, (len + 1), format, args2); | 274 OS::VSNPrint(buffer, (len + 1), format, args2); |
280 va_end(args2); | 275 va_end(args2); |
281 | 276 |
282 const String& message = String::Handle(isolate, String::New(buffer)); | 277 const String& message = String::Handle(isolate, String::New(buffer)); |
283 return Api::NewHandle(isolate, ApiError::New(message)); | 278 return Api::NewHandle(isolate, ApiError::New(message)); |
284 } | 279 } |
285 | 280 |
286 | 281 |
(...skipping 17 matching lines...) Expand all Loading... |
304 | 299 |
305 Dart_Handle Api::False(Isolate* isolate) { | 300 Dart_Handle Api::False(Isolate* isolate) { |
306 ASSERT(isolate != NULL); | 301 ASSERT(isolate != NULL); |
307 ApiState* state = isolate->api_state(); | 302 ApiState* state = isolate->api_state(); |
308 ASSERT(state != NULL); | 303 ASSERT(state != NULL); |
309 PersistentHandle* false_handle = state->False(); | 304 PersistentHandle* false_handle = state->False(); |
310 return reinterpret_cast<Dart_Handle>(false_handle); | 305 return reinterpret_cast<Dart_Handle>(false_handle); |
311 } | 306 } |
312 | 307 |
313 | 308 |
314 uword Api::Allocate(Isolate* isolate, intptr_t size) { | 309 ApiLocalScope* Api::TopScope(Isolate* isolate) { |
315 ASSERT(isolate != NULL); | 310 ASSERT(isolate != NULL); |
316 ApiState* state = isolate->api_state(); | 311 ApiState* state = isolate->api_state(); |
317 ASSERT(state != NULL); | 312 ASSERT(state != NULL); |
318 ApiLocalScope* scope = state->top_scope(); | 313 ApiLocalScope* scope = state->top_scope(); |
319 ASSERT(scope != NULL); | 314 ASSERT(scope != NULL); |
320 return scope->zone()->Allocate(size); | 315 return scope; |
321 } | |
322 | |
323 | |
324 uword Api::Reallocate(Isolate* isolate, | |
325 uword ptr, | |
326 intptr_t old_size, | |
327 intptr_t new_size) { | |
328 ASSERT(isolate != NULL); | |
329 ApiState* state = isolate->api_state(); | |
330 ASSERT(state != NULL); | |
331 ApiLocalScope* scope = state->top_scope(); | |
332 ASSERT(scope != NULL); | |
333 return scope->zone()->Reallocate(ptr, old_size, new_size); | |
334 } | 316 } |
335 | 317 |
336 | 318 |
337 void Api::InitOnce() { | 319 void Api::InitOnce() { |
338 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); | 320 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); |
339 api_native_key_ = Thread::CreateThreadLocal(); | 321 api_native_key_ = Thread::CreateThreadLocal(); |
340 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); | 322 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); |
341 } | 323 } |
342 | 324 |
343 | 325 |
(...skipping 26 matching lines...) Expand all Loading... |
370 | 352 |
371 | 353 |
372 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 354 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
373 Isolate* isolate = Isolate::Current(); | 355 Isolate* isolate = Isolate::Current(); |
374 DARTSCOPE(isolate); | 356 DARTSCOPE(isolate); |
375 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 357 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
376 if (obj.IsError()) { | 358 if (obj.IsError()) { |
377 const Error& error = Error::Cast(obj); | 359 const Error& error = Error::Cast(obj); |
378 const char* str = error.ToErrorCString(); | 360 const char* str = error.ToErrorCString(); |
379 intptr_t len = strlen(str) + 1; | 361 intptr_t len = strlen(str) + 1; |
380 char* str_copy = reinterpret_cast<char*>(Api::Allocate(isolate, len)); | 362 char* str_copy = Api::TopScope(isolate)->zone()->Alloc<char>(len); |
381 strncpy(str_copy, str, len); | 363 strncpy(str_copy, str, len); |
382 // Strip a possible trailing '\n'. | 364 // Strip a possible trailing '\n'. |
383 if ((len > 1) && (str_copy[len - 2] == '\n')) { | 365 if ((len > 1) && (str_copy[len - 2] == '\n')) { |
384 str_copy[len - 2] = '\0'; | 366 str_copy[len - 2] = '\0'; |
385 } | 367 } |
386 return str_copy; | 368 return str_copy; |
387 } else { | 369 } else { |
388 return ""; | 370 return ""; |
389 } | 371 } |
390 } | 372 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 // TODO(turnidge): Remove all uses and delete. | 414 // TODO(turnidge): Remove all uses and delete. |
433 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 415 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
434 Isolate* isolate = Isolate::Current(); | 416 Isolate* isolate = Isolate::Current(); |
435 DARTSCOPE(isolate); | 417 DARTSCOPE(isolate); |
436 | 418 |
437 va_list args; | 419 va_list args; |
438 va_start(args, format); | 420 va_start(args, format); |
439 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 421 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
440 va_end(args); | 422 va_end(args); |
441 | 423 |
442 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 424 char* buffer = zone.Alloc<char>(len + 1); |
443 va_list args2; | 425 va_list args2; |
444 va_start(args2, format); | 426 va_start(args2, format); |
445 OS::VSNPrint(buffer, (len + 1), format, args2); | 427 OS::VSNPrint(buffer, (len + 1), format, args2); |
446 va_end(args2); | 428 va_end(args2); |
447 | 429 |
448 const String& message = String::Handle(isolate, String::New(buffer)); | 430 const String& message = String::Handle(isolate, String::New(buffer)); |
449 return Api::NewHandle(isolate, ApiError::New(message)); | 431 return Api::NewHandle(isolate, ApiError::New(message)); |
450 } | 432 } |
451 | 433 |
452 | 434 |
453 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 435 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
454 // fix this but not sure if it available on all of our builds. | 436 // fix this but not sure if it available on all of our builds. |
455 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { | 437 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { |
456 Isolate* isolate = Isolate::Current(); | 438 Isolate* isolate = Isolate::Current(); |
457 DARTSCOPE(isolate); | 439 DARTSCOPE(isolate); |
458 | 440 |
459 va_list args; | 441 va_list args; |
460 va_start(args, format); | 442 va_start(args, format); |
461 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 443 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
462 va_end(args); | 444 va_end(args); |
463 | 445 |
464 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 446 char* buffer = zone.Alloc<char>(len + 1); |
465 va_list args2; | 447 va_list args2; |
466 va_start(args2, format); | 448 va_start(args2, format); |
467 OS::VSNPrint(buffer, (len + 1), format, args2); | 449 OS::VSNPrint(buffer, (len + 1), format, args2); |
468 va_end(args2); | 450 va_end(args2); |
469 | 451 |
470 const String& message = String::Handle(isolate, String::New(buffer)); | 452 const String& message = String::Handle(isolate, String::New(buffer)); |
471 return Api::NewHandle(isolate, ApiError::New(message)); | 453 return Api::NewHandle(isolate, ApiError::New(message)); |
472 } | 454 } |
473 | 455 |
474 | 456 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 | 855 |
874 DART_EXPORT void Dart_ExitIsolate() { | 856 DART_EXPORT void Dart_ExitIsolate() { |
875 CHECK_ISOLATE(Isolate::Current()); | 857 CHECK_ISOLATE(Isolate::Current()); |
876 Isolate::SetCurrent(NULL); | 858 Isolate::SetCurrent(NULL); |
877 } | 859 } |
878 | 860 |
879 | 861 |
880 static uint8_t* ApiReallocate(uint8_t* ptr, | 862 static uint8_t* ApiReallocate(uint8_t* ptr, |
881 intptr_t old_size, | 863 intptr_t old_size, |
882 intptr_t new_size) { | 864 intptr_t new_size) { |
883 uword new_ptr = Api::Reallocate(Isolate::Current(), | 865 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( |
884 reinterpret_cast<uword>(ptr), | 866 ptr, old_size, new_size); |
885 old_size, | |
886 new_size); | |
887 return reinterpret_cast<uint8_t*>(new_ptr); | |
888 } | 867 } |
889 | 868 |
890 | 869 |
891 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, | 870 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, |
892 intptr_t* size) { | 871 intptr_t* size) { |
893 Isolate* isolate = Isolate::Current(); | 872 Isolate* isolate = Isolate::Current(); |
894 DARTSCOPE(isolate); | 873 DARTSCOPE(isolate); |
895 TIMERSCOPE(time_creating_snapshot); | 874 TIMERSCOPE(time_creating_snapshot); |
896 if (buffer == NULL) { | 875 if (buffer == NULL) { |
897 RETURN_NULL_ERROR(buffer); | 876 RETURN_NULL_ERROR(buffer); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 if (isolate != NULL) { | 1157 if (isolate != NULL) { |
1179 ApiState* state = isolate->api_state(); | 1158 ApiState* state = isolate->api_state(); |
1180 if (state == NULL) return NULL; | 1159 if (state == NULL) return NULL; |
1181 ApiLocalScope* scope = state->top_scope(); | 1160 ApiLocalScope* scope = state->top_scope(); |
1182 zone = scope->zone(); | 1161 zone = scope->zone(); |
1183 } else { | 1162 } else { |
1184 ApiNativeScope* scope = ApiNativeScope::Current(); | 1163 ApiNativeScope* scope = ApiNativeScope::Current(); |
1185 if (scope == NULL) return NULL; | 1164 if (scope == NULL) return NULL; |
1186 zone = scope->zone(); | 1165 zone = scope->zone(); |
1187 } | 1166 } |
1188 return reinterpret_cast<uint8_t*>(zone->Allocate(size)); | 1167 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size)); |
1189 } | 1168 } |
1190 | 1169 |
1191 | 1170 |
1192 // --- Objects ---- | 1171 // --- Objects ---- |
1193 | 1172 |
1194 | 1173 |
1195 DART_EXPORT Dart_Handle Dart_Null() { | 1174 DART_EXPORT Dart_Handle Dart_Null() { |
1196 Isolate* isolate = Isolate::Current(); | 1175 Isolate* isolate = Isolate::Current(); |
1197 CHECK_ISOLATE_SCOPE(isolate); | 1176 CHECK_ISOLATE_SCOPE(isolate); |
1198 return Api::Null(isolate); | 1177 return Api::Null(isolate); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 if (BigintOperations::FitsIntoUint64(bigint)) { | 1410 if (BigintOperations::FitsIntoUint64(bigint)) { |
1432 *value = BigintOperations::ToUint64(bigint); | 1411 *value = BigintOperations::ToUint64(bigint); |
1433 return Api::Success(isolate); | 1412 return Api::Success(isolate); |
1434 } | 1413 } |
1435 } | 1414 } |
1436 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 1415 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
1437 CURRENT_FUNC, int_obj.ToCString()); | 1416 CURRENT_FUNC, int_obj.ToCString()); |
1438 } | 1417 } |
1439 | 1418 |
1440 | 1419 |
1441 static uword ApiAllocate(intptr_t size) { | 1420 static uword BigintAllocate(intptr_t size) { |
1442 return Api::Allocate(Isolate::Current(), size); | 1421 return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size); |
1443 } | 1422 } |
1444 | 1423 |
1445 | 1424 |
1446 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 1425 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
1447 const char** value) { | 1426 const char** value) { |
1448 Isolate* isolate = Isolate::Current(); | 1427 Isolate* isolate = Isolate::Current(); |
1449 DARTSCOPE(isolate); | 1428 DARTSCOPE(isolate); |
1450 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1429 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1451 if (int_obj.IsNull()) { | 1430 if (int_obj.IsNull()) { |
1452 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1431 RETURN_TYPE_ERROR(isolate, integer, Integer); |
1453 } | 1432 } |
1454 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1433 if (int_obj.IsSmi() || int_obj.IsMint()) { |
1455 const Bigint& bigint = Bigint::Handle(isolate, | 1434 const Bigint& bigint = Bigint::Handle(isolate, |
1456 BigintOperations::NewFromInt64(int_obj.AsInt64Value())); | 1435 BigintOperations::NewFromInt64(int_obj.AsInt64Value())); |
1457 *value = BigintOperations::ToHexCString(bigint, ApiAllocate); | 1436 *value = BigintOperations::ToHexCString(bigint, BigintAllocate); |
1458 } else { | 1437 } else { |
1459 *value = BigintOperations::ToHexCString(Bigint::Cast(int_obj), ApiAllocate); | 1438 *value = BigintOperations::ToHexCString(Bigint::Cast(int_obj), |
| 1439 BigintAllocate); |
1460 } | 1440 } |
1461 return Api::Success(isolate); | 1441 return Api::Success(isolate); |
1462 } | 1442 } |
1463 | 1443 |
1464 | 1444 |
1465 // --- Booleans ---- | 1445 // --- Booleans ---- |
1466 | 1446 |
1467 | 1447 |
1468 DART_EXPORT Dart_Handle Dart_True() { | 1448 DART_EXPORT Dart_Handle Dart_True() { |
1469 Isolate* isolate = Isolate::Current(); | 1449 Isolate* isolate = Isolate::Current(); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1742 | 1722 |
1743 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 1723 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
1744 const char** result) { | 1724 const char** result) { |
1745 Isolate* isolate = Isolate::Current(); | 1725 Isolate* isolate = Isolate::Current(); |
1746 DARTSCOPE(isolate); | 1726 DARTSCOPE(isolate); |
1747 const String& str_obj = Api::UnwrapStringHandle(isolate, object); | 1727 const String& str_obj = Api::UnwrapStringHandle(isolate, object); |
1748 if (str_obj.IsNull()) { | 1728 if (str_obj.IsNull()) { |
1749 RETURN_TYPE_ERROR(isolate, object, String); | 1729 RETURN_TYPE_ERROR(isolate, object, String); |
1750 } | 1730 } |
1751 intptr_t string_length = Utf8::Length(str_obj); | 1731 intptr_t string_length = Utf8::Length(str_obj); |
1752 char* res = | 1732 char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1); |
1753 reinterpret_cast<char*>(Api::Allocate(isolate, string_length + 1)); | |
1754 if (res == NULL) { | 1733 if (res == NULL) { |
1755 return Api::NewError("Unable to allocate memory"); | 1734 return Api::NewError("Unable to allocate memory"); |
1756 } | 1735 } |
1757 const char* string_value = str_obj.ToCString(); | 1736 const char* string_value = str_obj.ToCString(); |
1758 memmove(res, string_value, string_length + 1); | 1737 memmove(res, string_value, string_length + 1); |
1759 ASSERT(res[string_length] == '\0'); | 1738 ASSERT(res[string_length] == '\0'); |
1760 *result = res; | 1739 *result = res; |
1761 return Api::Success(isolate); | 1740 return Api::Success(isolate); |
1762 } | 1741 } |
1763 | 1742 |
1764 | 1743 |
1765 DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object, | 1744 DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object, |
1766 const uint8_t** bytes, | 1745 const uint8_t** bytes, |
1767 intptr_t *length) { | 1746 intptr_t *length) { |
1768 Isolate* isolate = Isolate::Current(); | 1747 Isolate* isolate = Isolate::Current(); |
1769 DARTSCOPE(isolate); | 1748 DARTSCOPE(isolate); |
1770 const String& str = Api::UnwrapStringHandle(isolate, object); | 1749 const String& str = Api::UnwrapStringHandle(isolate, object); |
1771 if (str.IsNull()) { | 1750 if (str.IsNull()) { |
1772 RETURN_TYPE_ERROR(isolate, object, String); | 1751 RETURN_TYPE_ERROR(isolate, object, String); |
1773 } | 1752 } |
1774 if (bytes == NULL) { | 1753 if (bytes == NULL) { |
1775 RETURN_NULL_ERROR(bytes); | 1754 RETURN_NULL_ERROR(bytes); |
1776 } | 1755 } |
1777 if (length == NULL) { | 1756 if (length == NULL) { |
1778 RETURN_NULL_ERROR(length); | 1757 RETURN_NULL_ERROR(length); |
1779 } | 1758 } |
1780 const char* cstring = str.ToCString(); | 1759 const char* cstring = str.ToCString(); |
1781 *length = Utf8::Length(str); | 1760 *length = Utf8::Length(str); |
1782 uint8_t* result = reinterpret_cast<uint8_t*>(Api::Allocate(isolate, *length)); | 1761 uint8_t* result = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(*length); |
1783 if (result == NULL) { | 1762 if (result == NULL) { |
1784 return Api::NewError("Unable to allocate memory"); | 1763 return Api::NewError("Unable to allocate memory"); |
1785 } | 1764 } |
1786 memmove(result, cstring, *length); | 1765 memmove(result, cstring, *length); |
1787 *bytes = result; | 1766 *bytes = result; |
1788 return Api::Success(isolate); | 1767 return Api::Success(isolate); |
1789 } | 1768 } |
1790 | 1769 |
1791 | 1770 |
1792 // --- Lists --- | 1771 // --- Lists --- |
(...skipping 2360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4153 | 4132 |
4154 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { | 4133 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { |
4155 Isolate* isolate = Isolate::Current(); | 4134 Isolate* isolate = Isolate::Current(); |
4156 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); | 4135 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); |
4157 if (pprof_symbol_generator != NULL) { | 4136 if (pprof_symbol_generator != NULL) { |
4158 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); | 4137 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); |
4159 ASSERT(debug_region != NULL); | 4138 ASSERT(debug_region != NULL); |
4160 pprof_symbol_generator->WriteToMemory(debug_region); | 4139 pprof_symbol_generator->WriteToMemory(debug_region); |
4161 *buffer_size = debug_region->size(); | 4140 *buffer_size = debug_region->size(); |
4162 if (*buffer_size != 0) { | 4141 if (*buffer_size != 0) { |
4163 *buffer = reinterpret_cast<void*>(Api::Allocate(isolate, *buffer_size)); | 4142 ApiZone* zone = Api::TopScope(isolate)->zone(); |
| 4143 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size)); |
4164 memmove(*buffer, debug_region->data(), *buffer_size); | 4144 memmove(*buffer, debug_region->data(), *buffer_size); |
4165 } else { | 4145 } else { |
4166 *buffer = NULL; | 4146 *buffer = NULL; |
4167 } | 4147 } |
4168 delete debug_region; | 4148 delete debug_region; |
4169 } else { | 4149 } else { |
4170 *buffer = NULL; | 4150 *buffer = NULL; |
4171 *buffer_size = 0; | 4151 *buffer_size = 0; |
4172 } | 4152 } |
4173 } | 4153 } |
4174 | 4154 |
4175 | 4155 |
4176 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4156 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
4177 Dart::set_perf_events_writer(function); | 4157 Dart::set_perf_events_writer(function); |
4178 } | 4158 } |
4179 | 4159 |
4180 | 4160 |
4181 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4161 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
4182 Dart::set_flow_graph_writer(function); | 4162 Dart::set_flow_graph_writer(function); |
4183 } | 4163 } |
4184 | 4164 |
4185 } // namespace dart | 4165 } // namespace dart |
OLD | NEW |