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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 success = isolate->object_store()->PreallocateObjects(); | 169 success = isolate->object_store()->PreallocateObjects(); |
170 if (success) { | 170 if (success) { |
171 return NULL; | 171 return NULL; |
172 } | 172 } |
173 } | 173 } |
174 // Make a copy of the error message as the original message string | 174 // Make a copy of the error message as the original message string |
175 // may get deallocated when we return back from the Dart API call. | 175 // may get deallocated when we return back from the Dart API call. |
176 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); | 176 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); |
177 const char* errmsg = err.ToErrorCString(); | 177 const char* errmsg = err.ToErrorCString(); |
178 intptr_t errlen = strlen(errmsg) + 1; | 178 intptr_t errlen = strlen(errmsg) + 1; |
179 char* msg = reinterpret_cast<char*>(Api::Allocate(isolate, errlen)); | 179 char* msg = Api::TopScope(isolate)->zone()->Alloc<char>(errlen); |
180 OS::SNPrint(msg, errlen, "%s", errmsg); | 180 OS::SNPrint(msg, errlen, "%s", errmsg); |
181 return msg; | 181 return msg; |
182 } | 182 } |
183 | 183 |
184 | 184 |
185 void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) { | 185 void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) { |
186 *handle = Api::NewHandle( | 186 *handle = Api::NewHandle( |
187 isolate, Isolate::Current()->object_store()->sticky_error()); | 187 isolate, Isolate::Current()->object_store()->sticky_error()); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { | 191 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { |
192 ASSERT(isolate != NULL); | 192 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); |
193 ApiState* state = isolate->api_state(); | |
194 ASSERT(state != NULL); | |
195 ApiLocalScope* scope = state->top_scope(); | |
196 ASSERT(scope != NULL); | |
197 LocalHandles* local_handles = scope->local_handles(); | |
198 ASSERT(local_handles != NULL); | 193 ASSERT(local_handles != NULL); |
199 LocalHandle* ref = local_handles->AllocateHandle(); | 194 LocalHandle* ref = local_handles->AllocateHandle(); |
200 ref->set_raw(raw); | 195 ref->set_raw(raw); |
201 return reinterpret_cast<Dart_Handle>(ref); | 196 return reinterpret_cast<Dart_Handle>(ref); |
202 } | 197 } |
203 | 198 |
204 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 199 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
205 #if defined(DEBUG) | 200 #if defined(DEBUG) |
206 Isolate* isolate = Isolate::Current(); | 201 Isolate* isolate = Isolate::Current(); |
207 ASSERT(isolate != NULL); | 202 ASSERT(isolate != NULL); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 272 |
278 Dart_Handle Api::NewError(const char* format, ...) { | 273 Dart_Handle Api::NewError(const char* format, ...) { |
279 Isolate* isolate = Isolate::Current(); | 274 Isolate* isolate = Isolate::Current(); |
280 DARTSCOPE_NOCHECKS(isolate); | 275 DARTSCOPE_NOCHECKS(isolate); |
281 | 276 |
282 va_list args; | 277 va_list args; |
283 va_start(args, format); | 278 va_start(args, format); |
284 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 279 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
285 va_end(args); | 280 va_end(args); |
286 | 281 |
287 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 282 char* buffer = zone.Alloc<char>(len + 1); |
288 va_list args2; | 283 va_list args2; |
289 va_start(args2, format); | 284 va_start(args2, format); |
290 OS::VSNPrint(buffer, (len + 1), format, args2); | 285 OS::VSNPrint(buffer, (len + 1), format, args2); |
291 va_end(args2); | 286 va_end(args2); |
292 | 287 |
293 const String& message = String::Handle(isolate, String::New(buffer)); | 288 const String& message = String::Handle(isolate, String::New(buffer)); |
294 return Api::NewHandle(isolate, ApiError::New(message)); | 289 return Api::NewHandle(isolate, ApiError::New(message)); |
295 } | 290 } |
296 | 291 |
297 | 292 |
(...skipping 17 matching lines...) Expand all Loading... |
315 | 310 |
316 Dart_Handle Api::False(Isolate* isolate) { | 311 Dart_Handle Api::False(Isolate* isolate) { |
317 ASSERT(isolate != NULL); | 312 ASSERT(isolate != NULL); |
318 ApiState* state = isolate->api_state(); | 313 ApiState* state = isolate->api_state(); |
319 ASSERT(state != NULL); | 314 ASSERT(state != NULL); |
320 PersistentHandle* false_handle = state->False(); | 315 PersistentHandle* false_handle = state->False(); |
321 return reinterpret_cast<Dart_Handle>(false_handle); | 316 return reinterpret_cast<Dart_Handle>(false_handle); |
322 } | 317 } |
323 | 318 |
324 | 319 |
325 uword Api::Allocate(Isolate* isolate, intptr_t size) { | 320 ApiLocalScope* Api::TopScope(Isolate* isolate) { |
326 ASSERT(isolate != NULL); | 321 ASSERT(isolate != NULL); |
327 ApiState* state = isolate->api_state(); | 322 ApiState* state = isolate->api_state(); |
328 ASSERT(state != NULL); | 323 ASSERT(state != NULL); |
329 ApiLocalScope* scope = state->top_scope(); | 324 ApiLocalScope* scope = state->top_scope(); |
330 ASSERT(scope != NULL); | 325 ASSERT(scope != NULL); |
331 return scope->zone()->Allocate(size); | 326 return scope; |
332 } | |
333 | |
334 | |
335 uword Api::Reallocate(Isolate* isolate, | |
336 uword ptr, | |
337 intptr_t old_size, | |
338 intptr_t new_size) { | |
339 ASSERT(isolate != NULL); | |
340 ApiState* state = isolate->api_state(); | |
341 ASSERT(state != NULL); | |
342 ApiLocalScope* scope = state->top_scope(); | |
343 ASSERT(scope != NULL); | |
344 return scope->zone()->Reallocate(ptr, old_size, new_size); | |
345 } | 327 } |
346 | 328 |
347 | 329 |
348 void Api::InitOnce() { | 330 void Api::InitOnce() { |
349 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); | 331 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); |
350 api_native_key_ = Thread::CreateThreadLocal(); | 332 api_native_key_ = Thread::CreateThreadLocal(); |
351 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); | 333 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); |
352 } | 334 } |
353 | 335 |
354 | 336 |
(...skipping 26 matching lines...) Expand all Loading... |
381 | 363 |
382 | 364 |
383 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 365 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
384 Isolate* isolate = Isolate::Current(); | 366 Isolate* isolate = Isolate::Current(); |
385 DARTSCOPE(isolate); | 367 DARTSCOPE(isolate); |
386 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 368 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
387 if (obj.IsError()) { | 369 if (obj.IsError()) { |
388 const Error& error = Error::Cast(obj); | 370 const Error& error = Error::Cast(obj); |
389 const char* str = error.ToErrorCString(); | 371 const char* str = error.ToErrorCString(); |
390 intptr_t len = strlen(str) + 1; | 372 intptr_t len = strlen(str) + 1; |
391 char* str_copy = reinterpret_cast<char*>(Api::Allocate(isolate, len)); | 373 char* str_copy = Api::TopScope(isolate)->zone()->Alloc<char>(len); |
392 strncpy(str_copy, str, len); | 374 strncpy(str_copy, str, len); |
393 // Strip a possible trailing '\n'. | 375 // Strip a possible trailing '\n'. |
394 if ((len > 1) && (str_copy[len - 2] == '\n')) { | 376 if ((len > 1) && (str_copy[len - 2] == '\n')) { |
395 str_copy[len - 2] = '\0'; | 377 str_copy[len - 2] = '\0'; |
396 } | 378 } |
397 return str_copy; | 379 return str_copy; |
398 } else { | 380 } else { |
399 return ""; | 381 return ""; |
400 } | 382 } |
401 } | 383 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 // TODO(turnidge): Remove all uses and delete. | 425 // TODO(turnidge): Remove all uses and delete. |
444 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 426 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
445 Isolate* isolate = Isolate::Current(); | 427 Isolate* isolate = Isolate::Current(); |
446 DARTSCOPE(isolate); | 428 DARTSCOPE(isolate); |
447 | 429 |
448 va_list args; | 430 va_list args; |
449 va_start(args, format); | 431 va_start(args, format); |
450 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 432 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
451 va_end(args); | 433 va_end(args); |
452 | 434 |
453 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 435 char* buffer = zone.Alloc<char>(len + 1); |
454 va_list args2; | 436 va_list args2; |
455 va_start(args2, format); | 437 va_start(args2, format); |
456 OS::VSNPrint(buffer, (len + 1), format, args2); | 438 OS::VSNPrint(buffer, (len + 1), format, args2); |
457 va_end(args2); | 439 va_end(args2); |
458 | 440 |
459 const String& message = String::Handle(isolate, String::New(buffer)); | 441 const String& message = String::Handle(isolate, String::New(buffer)); |
460 return Api::NewHandle(isolate, ApiError::New(message)); | 442 return Api::NewHandle(isolate, ApiError::New(message)); |
461 } | 443 } |
462 | 444 |
463 | 445 |
464 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 446 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
465 // fix this but not sure if it available on all of our builds. | 447 // fix this but not sure if it available on all of our builds. |
466 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { | 448 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { |
467 Isolate* isolate = Isolate::Current(); | 449 Isolate* isolate = Isolate::Current(); |
468 DARTSCOPE(isolate); | 450 DARTSCOPE(isolate); |
469 | 451 |
470 va_list args; | 452 va_list args; |
471 va_start(args, format); | 453 va_start(args, format); |
472 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 454 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
473 va_end(args); | 455 va_end(args); |
474 | 456 |
475 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 457 char* buffer = zone.Alloc<char>(len + 1); |
476 va_list args2; | 458 va_list args2; |
477 va_start(args2, format); | 459 va_start(args2, format); |
478 OS::VSNPrint(buffer, (len + 1), format, args2); | 460 OS::VSNPrint(buffer, (len + 1), format, args2); |
479 va_end(args2); | 461 va_end(args2); |
480 | 462 |
481 const String& message = String::Handle(isolate, String::New(buffer)); | 463 const String& message = String::Handle(isolate, String::New(buffer)); |
482 return Api::NewHandle(isolate, ApiError::New(message)); | 464 return Api::NewHandle(isolate, ApiError::New(message)); |
483 } | 465 } |
484 | 466 |
485 | 467 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 | 866 |
885 DART_EXPORT void Dart_ExitIsolate() { | 867 DART_EXPORT void Dart_ExitIsolate() { |
886 CHECK_ISOLATE(Isolate::Current()); | 868 CHECK_ISOLATE(Isolate::Current()); |
887 Isolate::SetCurrent(NULL); | 869 Isolate::SetCurrent(NULL); |
888 } | 870 } |
889 | 871 |
890 | 872 |
891 static uint8_t* ApiReallocate(uint8_t* ptr, | 873 static uint8_t* ApiReallocate(uint8_t* ptr, |
892 intptr_t old_size, | 874 intptr_t old_size, |
893 intptr_t new_size) { | 875 intptr_t new_size) { |
894 uword new_ptr = Api::Reallocate(Isolate::Current(), | 876 return Api::TopScope(Isolate::Current())->zone()->Realloc<uint8_t>( |
895 reinterpret_cast<uword>(ptr), | 877 ptr, old_size, new_size); |
896 old_size, | |
897 new_size); | |
898 return reinterpret_cast<uint8_t*>(new_ptr); | |
899 } | 878 } |
900 | 879 |
901 | 880 |
902 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, | 881 DART_EXPORT Dart_Handle Dart_CreateSnapshot(uint8_t** buffer, |
903 intptr_t* size) { | 882 intptr_t* size) { |
904 Isolate* isolate = Isolate::Current(); | 883 Isolate* isolate = Isolate::Current(); |
905 DARTSCOPE(isolate); | 884 DARTSCOPE(isolate); |
906 TIMERSCOPE(time_creating_snapshot); | 885 TIMERSCOPE(time_creating_snapshot); |
907 if (buffer == NULL) { | 886 if (buffer == NULL) { |
908 RETURN_NULL_ERROR(buffer); | 887 RETURN_NULL_ERROR(buffer); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 if (isolate != NULL) { | 1167 if (isolate != NULL) { |
1189 ApiState* state = isolate->api_state(); | 1168 ApiState* state = isolate->api_state(); |
1190 if (state == NULL) return NULL; | 1169 if (state == NULL) return NULL; |
1191 ApiLocalScope* scope = state->top_scope(); | 1170 ApiLocalScope* scope = state->top_scope(); |
1192 zone = scope->zone(); | 1171 zone = scope->zone(); |
1193 } else { | 1172 } else { |
1194 ApiNativeScope* scope = ApiNativeScope::Current(); | 1173 ApiNativeScope* scope = ApiNativeScope::Current(); |
1195 if (scope == NULL) return NULL; | 1174 if (scope == NULL) return NULL; |
1196 zone = scope->zone(); | 1175 zone = scope->zone(); |
1197 } | 1176 } |
1198 return reinterpret_cast<uint8_t*>(zone->Allocate(size)); | 1177 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size)); |
1199 } | 1178 } |
1200 | 1179 |
1201 | 1180 |
1202 // --- Objects ---- | 1181 // --- Objects ---- |
1203 | 1182 |
1204 | 1183 |
1205 DART_EXPORT Dart_Handle Dart_Null() { | 1184 DART_EXPORT Dart_Handle Dart_Null() { |
1206 Isolate* isolate = Isolate::Current(); | 1185 Isolate* isolate = Isolate::Current(); |
1207 CHECK_ISOLATE_SCOPE(isolate); | 1186 CHECK_ISOLATE_SCOPE(isolate); |
1208 return Api::Null(isolate); | 1187 return Api::Null(isolate); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 if (BigintOperations::FitsIntoUint64(bigint)) { | 1420 if (BigintOperations::FitsIntoUint64(bigint)) { |
1442 *value = BigintOperations::ToUint64(bigint); | 1421 *value = BigintOperations::ToUint64(bigint); |
1443 return Api::Success(isolate); | 1422 return Api::Success(isolate); |
1444 } | 1423 } |
1445 } | 1424 } |
1446 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 1425 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
1447 CURRENT_FUNC, int_obj.ToCString()); | 1426 CURRENT_FUNC, int_obj.ToCString()); |
1448 } | 1427 } |
1449 | 1428 |
1450 | 1429 |
1451 static uword ApiAllocate(intptr_t size) { | 1430 static uword BigintAllocate(intptr_t size) { |
1452 return Api::Allocate(Isolate::Current(), size); | 1431 return Api::TopScope(Isolate::Current())->zone()->AllocUnsafe(size); |
1453 } | 1432 } |
1454 | 1433 |
1455 | 1434 |
1456 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 1435 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
1457 const char** value) { | 1436 const char** value) { |
1458 Isolate* isolate = Isolate::Current(); | 1437 Isolate* isolate = Isolate::Current(); |
1459 DARTSCOPE(isolate); | 1438 DARTSCOPE(isolate); |
1460 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1439 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1461 if (int_obj.IsNull()) { | 1440 if (int_obj.IsNull()) { |
1462 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1441 RETURN_TYPE_ERROR(isolate, integer, Integer); |
1463 } | 1442 } |
1464 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1443 if (int_obj.IsSmi() || int_obj.IsMint()) { |
1465 const Bigint& bigint = Bigint::Handle(isolate, | 1444 const Bigint& bigint = Bigint::Handle(isolate, |
1466 BigintOperations::NewFromInt64(int_obj.AsInt64Value())); | 1445 BigintOperations::NewFromInt64(int_obj.AsInt64Value())); |
1467 *value = BigintOperations::ToHexCString(bigint, ApiAllocate); | 1446 *value = BigintOperations::ToHexCString(bigint, BigintAllocate); |
1468 } else { | 1447 } else { |
1469 *value = BigintOperations::ToHexCString(Bigint::Cast(int_obj), ApiAllocate); | 1448 *value = BigintOperations::ToHexCString(Bigint::Cast(int_obj), |
| 1449 BigintAllocate); |
1470 } | 1450 } |
1471 return Api::Success(isolate); | 1451 return Api::Success(isolate); |
1472 } | 1452 } |
1473 | 1453 |
1474 | 1454 |
1475 // --- Booleans ---- | 1455 // --- Booleans ---- |
1476 | 1456 |
1477 | 1457 |
1478 DART_EXPORT Dart_Handle Dart_True() { | 1458 DART_EXPORT Dart_Handle Dart_True() { |
1479 Isolate* isolate = Isolate::Current(); | 1459 Isolate* isolate = Isolate::Current(); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 | 1735 |
1756 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 1736 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
1757 const char** result) { | 1737 const char** result) { |
1758 Isolate* isolate = Isolate::Current(); | 1738 Isolate* isolate = Isolate::Current(); |
1759 DARTSCOPE(isolate); | 1739 DARTSCOPE(isolate); |
1760 const String& str_obj = Api::UnwrapStringHandle(isolate, object); | 1740 const String& str_obj = Api::UnwrapStringHandle(isolate, object); |
1761 if (str_obj.IsNull()) { | 1741 if (str_obj.IsNull()) { |
1762 RETURN_TYPE_ERROR(isolate, object, String); | 1742 RETURN_TYPE_ERROR(isolate, object, String); |
1763 } | 1743 } |
1764 intptr_t string_length = Utf8::Length(str_obj); | 1744 intptr_t string_length = Utf8::Length(str_obj); |
1765 char* res = | 1745 char* res = Api::TopScope(isolate)->zone()->Alloc<char>(string_length + 1); |
1766 reinterpret_cast<char*>(Api::Allocate(isolate, string_length + 1)); | |
1767 if (res == NULL) { | 1746 if (res == NULL) { |
1768 return Api::NewError("Unable to allocate memory"); | 1747 return Api::NewError("Unable to allocate memory"); |
1769 } | 1748 } |
1770 const char* string_value = str_obj.ToCString(); | 1749 const char* string_value = str_obj.ToCString(); |
1771 memmove(res, string_value, string_length + 1); | 1750 memmove(res, string_value, string_length + 1); |
1772 ASSERT(res[string_length] == '\0'); | 1751 ASSERT(res[string_length] == '\0'); |
1773 *result = res; | 1752 *result = res; |
1774 return Api::Success(isolate); | 1753 return Api::Success(isolate); |
1775 } | 1754 } |
1776 | 1755 |
1777 | 1756 |
1778 DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object, | 1757 DART_EXPORT Dart_Handle Dart_StringToBytes(Dart_Handle object, |
1779 const uint8_t** bytes, | 1758 const uint8_t** bytes, |
1780 intptr_t *length) { | 1759 intptr_t *length) { |
1781 Isolate* isolate = Isolate::Current(); | 1760 Isolate* isolate = Isolate::Current(); |
1782 DARTSCOPE(isolate); | 1761 DARTSCOPE(isolate); |
1783 const String& str = Api::UnwrapStringHandle(isolate, object); | 1762 const String& str = Api::UnwrapStringHandle(isolate, object); |
1784 if (str.IsNull()) { | 1763 if (str.IsNull()) { |
1785 RETURN_TYPE_ERROR(isolate, object, String); | 1764 RETURN_TYPE_ERROR(isolate, object, String); |
1786 } | 1765 } |
1787 if (bytes == NULL) { | 1766 if (bytes == NULL) { |
1788 RETURN_NULL_ERROR(bytes); | 1767 RETURN_NULL_ERROR(bytes); |
1789 } | 1768 } |
1790 if (length == NULL) { | 1769 if (length == NULL) { |
1791 RETURN_NULL_ERROR(length); | 1770 RETURN_NULL_ERROR(length); |
1792 } | 1771 } |
1793 const char* cstring = str.ToCString(); | 1772 const char* cstring = str.ToCString(); |
1794 *length = Utf8::Length(str); | 1773 *length = Utf8::Length(str); |
1795 uint8_t* result = reinterpret_cast<uint8_t*>(Api::Allocate(isolate, *length)); | 1774 uint8_t* result = Api::TopScope(isolate)->zone()->Alloc<uint8_t>(*length); |
1796 if (result == NULL) { | 1775 if (result == NULL) { |
1797 return Api::NewError("Unable to allocate memory"); | 1776 return Api::NewError("Unable to allocate memory"); |
1798 } | 1777 } |
1799 memmove(result, cstring, *length); | 1778 memmove(result, cstring, *length); |
1800 *bytes = result; | 1779 *bytes = result; |
1801 return Api::Success(isolate); | 1780 return Api::Success(isolate); |
1802 } | 1781 } |
1803 | 1782 |
1804 | 1783 |
1805 // --- Lists --- | 1784 // --- Lists --- |
(...skipping 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4178 | 4157 |
4179 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { | 4158 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { |
4180 Isolate* isolate = Isolate::Current(); | 4159 Isolate* isolate = Isolate::Current(); |
4181 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); | 4160 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); |
4182 if (pprof_symbol_generator != NULL) { | 4161 if (pprof_symbol_generator != NULL) { |
4183 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); | 4162 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); |
4184 ASSERT(debug_region != NULL); | 4163 ASSERT(debug_region != NULL); |
4185 pprof_symbol_generator->WriteToMemory(debug_region); | 4164 pprof_symbol_generator->WriteToMemory(debug_region); |
4186 *buffer_size = debug_region->size(); | 4165 *buffer_size = debug_region->size(); |
4187 if (*buffer_size != 0) { | 4166 if (*buffer_size != 0) { |
4188 *buffer = reinterpret_cast<void*>(Api::Allocate(isolate, *buffer_size)); | 4167 ApiZone* zone = Api::TopScope(isolate)->zone(); |
| 4168 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size)); |
4189 memmove(*buffer, debug_region->data(), *buffer_size); | 4169 memmove(*buffer, debug_region->data(), *buffer_size); |
4190 } else { | 4170 } else { |
4191 *buffer = NULL; | 4171 *buffer = NULL; |
4192 } | 4172 } |
4193 delete debug_region; | 4173 delete debug_region; |
4194 } else { | 4174 } else { |
4195 *buffer = NULL; | 4175 *buffer = NULL; |
4196 *buffer_size = 0; | 4176 *buffer_size = 0; |
4197 } | 4177 } |
4198 } | 4178 } |
4199 | 4179 |
4200 | 4180 |
4201 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4181 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
4202 Dart::set_perf_events_writer(function); | 4182 Dart::set_perf_events_writer(function); |
4203 } | 4183 } |
4204 | 4184 |
4205 | 4185 |
4206 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4186 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
4207 Dart::set_flow_graph_writer(function); | 4187 Dart::set_flow_graph_writer(function); |
4208 } | 4188 } |
4209 | 4189 |
4210 } // namespace dart | 4190 } // namespace dart |
OLD | NEW |