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_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1257 return Api::Success(); | 1257 return Api::Success(); |
1258 } | 1258 } |
1259 | 1259 |
1260 | 1260 |
1261 // --- Initialization and Globals --- | 1261 // --- Initialization and Globals --- |
1262 | 1262 |
1263 DART_EXPORT const char* Dart_VersionString() { | 1263 DART_EXPORT const char* Dart_VersionString() { |
1264 return Version::String(); | 1264 return Version::String(); |
1265 } | 1265 } |
1266 | 1266 |
1267 DART_EXPORT bool Dart_Initialize( | 1267 DART_EXPORT char* Dart_Initialize( |
1268 const uint8_t* vm_isolate_snapshot, | 1268 const uint8_t* vm_isolate_snapshot, |
1269 Dart_IsolateCreateCallback create, | 1269 Dart_IsolateCreateCallback create, |
1270 Dart_IsolateInterruptCallback interrupt, | 1270 Dart_IsolateInterruptCallback interrupt, |
1271 Dart_IsolateUnhandledExceptionCallback unhandled, | 1271 Dart_IsolateUnhandledExceptionCallback unhandled, |
1272 Dart_IsolateShutdownCallback shutdown, | 1272 Dart_IsolateShutdownCallback shutdown, |
1273 Dart_FileOpenCallback file_open, | 1273 Dart_FileOpenCallback file_open, |
1274 Dart_FileReadCallback file_read, | 1274 Dart_FileReadCallback file_read, |
1275 Dart_FileWriteCallback file_write, | 1275 Dart_FileWriteCallback file_write, |
1276 Dart_FileCloseCallback file_close, | 1276 Dart_FileCloseCallback file_close, |
1277 Dart_EntropySource entropy_source) { | 1277 Dart_EntropySource entropy_source) { |
1278 const char* err_msg = Dart::InitOnce(vm_isolate_snapshot, | 1278 const char* err_msg = Dart::InitOnce(vm_isolate_snapshot, |
1279 create, interrupt, unhandled, shutdown, | 1279 create, interrupt, unhandled, shutdown, |
1280 file_open, file_read, file_write, | 1280 file_open, file_read, file_write, |
1281 file_close, entropy_source); | 1281 file_close, entropy_source); |
1282 if (err_msg != NULL) { | 1282 if (err_msg != NULL) { |
1283 OS::PrintErr("Dart_Initialize: %s\n", err_msg); | 1283 return strdup(err_msg); |
Florian Schneider
2015/08/19 09:02:03
What the reason for strdup here? Could you just pa
| |
1284 return false; | |
1285 } | 1284 } |
1286 return true; | 1285 return NULL; |
1287 } | 1286 } |
1288 | 1287 |
1289 | 1288 |
1290 DART_EXPORT bool Dart_Cleanup() { | 1289 DART_EXPORT char* Dart_Cleanup() { |
1291 CHECK_NO_ISOLATE(Isolate::Current()); | 1290 CHECK_NO_ISOLATE(Isolate::Current()); |
1292 const char* err_msg = Dart::Cleanup(); | 1291 const char* err_msg = Dart::Cleanup(); |
1293 if (err_msg != NULL) { | 1292 if (err_msg != NULL) { |
1294 OS::PrintErr("Dart_Cleanup: %s\n", err_msg); | 1293 return strdup(err_msg); |
1295 return false; | |
1296 } | 1294 } |
1297 return true; | 1295 return NULL; |
1298 } | 1296 } |
1299 | 1297 |
1300 | 1298 |
1301 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { | 1299 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { |
1302 return Flags::ProcessCommandLineFlags(argc, argv); | 1300 return Flags::ProcessCommandLineFlags(argc, argv); |
1303 } | 1301 } |
1304 | 1302 |
1305 | 1303 |
1306 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name) { | 1304 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name) { |
1307 return Flags::IsSet(flag_name); | 1305 return Flags::IsSet(flag_name); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1358 | 1356 |
1359 // Setup default flags in case none were passed. | 1357 // Setup default flags in case none were passed. |
1360 Dart_IsolateFlags api_flags; | 1358 Dart_IsolateFlags api_flags; |
1361 if (flags == NULL) { | 1359 if (flags == NULL) { |
1362 Isolate::Flags vm_flags; | 1360 Isolate::Flags vm_flags; |
1363 vm_flags.CopyTo(&api_flags); | 1361 vm_flags.CopyTo(&api_flags); |
1364 flags = &api_flags; | 1362 flags = &api_flags; |
1365 } | 1363 } |
1366 Isolate* isolate = Dart::CreateIsolate(isolate_name, *flags); | 1364 Isolate* isolate = Dart::CreateIsolate(isolate_name, *flags); |
1367 free(isolate_name); | 1365 free(isolate_name); |
1366 if (isolate == NULL) { | |
1367 *error = strdup("Isolate creation failed"); | |
Florian Schneider
2015/08/19 09:02:03
Same here.
Ivan Posva
2015/08/19 09:21:49
Needs the strdup because of the contract about err
| |
1368 return reinterpret_cast<Dart_Isolate>(NULL); | |
1369 } | |
1368 { | 1370 { |
1369 StackZone zone(isolate); | 1371 StackZone zone(isolate); |
1370 HANDLESCOPE(isolate); | 1372 HANDLESCOPE(isolate); |
1371 // We enter an API scope here as InitializeIsolate could compile some | 1373 // We enter an API scope here as InitializeIsolate could compile some |
1372 // bootstrap library files which call out to a tag handler that may create | 1374 // bootstrap library files which call out to a tag handler that may create |
1373 // Api Handles when an error is encountered. | 1375 // Api Handles when an error is encountered. |
1374 Dart_EnterScope(); | 1376 Dart_EnterScope(); |
1375 const Error& error_obj = | 1377 const Error& error_obj = |
1376 Error::Handle(isolate, | 1378 Error::Handle(isolate, |
1377 Dart::InitializeIsolate(snapshot, callback_data)); | 1379 Dart::InitializeIsolate(snapshot, callback_data)); |
1378 if (error_obj.IsNull()) { | 1380 if (error_obj.IsNull()) { |
1379 #if defined(DART_NO_SNAPSHOT) | 1381 #if defined(DART_NO_SNAPSHOT) |
1380 if (FLAG_check_function_fingerprints) { | 1382 if (FLAG_check_function_fingerprints) { |
1381 Library::CheckFunctionFingerprints(); | 1383 Library::CheckFunctionFingerprints(); |
1382 } | 1384 } |
1383 #endif // defined(DART_NO_SNAPSHOT). | 1385 #endif // defined(DART_NO_SNAPSHOT). |
1384 // We exit the API scope entered above. | 1386 // We exit the API scope entered above. |
1385 Dart_ExitScope(); | 1387 Dart_ExitScope(); |
1386 START_TIMER(isolate, time_total_runtime); | 1388 START_TIMER(isolate, time_total_runtime); |
1387 return Api::CastIsolate(isolate); | 1389 return Api::CastIsolate(isolate); |
1388 } | 1390 } |
1389 *error = strdup(error_obj.ToErrorCString()); | 1391 *error = strdup(error_obj.ToErrorCString()); |
Florian Schneider
2015/08/19 09:02:03
Same here.
If I see this correctly, error_obj.ToE
Ivan Posva
2015/08/19 09:21:49
We pack it into a malloc'd string since that is th
| |
1390 // We exit the API scope entered above. | 1392 // We exit the API scope entered above. |
1391 Dart_ExitScope(); | 1393 Dart_ExitScope(); |
1392 } | 1394 } |
1393 Dart::ShutdownIsolate(); | 1395 Dart::ShutdownIsolate(); |
1394 return reinterpret_cast<Dart_Isolate>(NULL); | 1396 return reinterpret_cast<Dart_Isolate>(NULL); |
1395 } | 1397 } |
1396 | 1398 |
1397 | 1399 |
1398 DART_EXPORT void Dart_ShutdownIsolate() { | 1400 DART_EXPORT void Dart_ShutdownIsolate() { |
1399 Isolate* isolate = Isolate::Current(); | 1401 Isolate* isolate = Isolate::Current(); |
(...skipping 4617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6017 ASSERT(stream != NULL); | 6019 ASSERT(stream != NULL); |
6018 TimelineEvent* event = stream->StartEvent(); | 6020 TimelineEvent* event = stream->StartEvent(); |
6019 if (event != NULL) { | 6021 if (event != NULL) { |
6020 event->AsyncEnd(label, async_id); | 6022 event->AsyncEnd(label, async_id); |
6021 event->Complete(); | 6023 event->Complete(); |
6022 } | 6024 } |
6023 return Api::Success(); | 6025 return Api::Success(); |
6024 } | 6026 } |
6025 | 6027 |
6026 } // namespace dart | 6028 } // namespace dart |
OLD | NEW |