[vm] Document ownership of Dart_CreateIsolate's error message.

Change-Id: Icab6f6d169445f66b6ba9469511164e6e21ef49a
Reviewed-on: https://dart-review.googlesource.com/18425
Reviewed-by: Zach Anderson <zra@google.com>
This commit is contained in:
Ryan Macnak 2017-11-03 18:10:53 +00:00
parent c53c2f948d
commit 8753545178
3 changed files with 20 additions and 9 deletions

View file

@ -835,10 +835,11 @@ DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name);
* \param callback_data Embedder data. This data will be passed to
* the Dart_IsolateCreateCallback when new isolates are spawned from
* this parent isolate.
* \param error DOCUMENT
* \param error Returns NULL if creation is successful, an error message
* otherwise. The caller is responsible for calling free() on the error
* message.
*
* \return The new isolate is returned. May be NULL if an error
* occurs during isolate initialization.
* \return The new isolate on success, or NULL if isolate creation failed.
*/
DART_EXPORT Dart_Isolate
Dart_CreateIsolate(const char* script_uri,
@ -869,10 +870,11 @@ Dart_CreateIsolate(const char* script_uri,
* \param callback_data Embedder data. This data will be passed to
* the Dart_IsolateCreateCallback when new isolates are spawned from
* this parent isolate.
* \param error DOCUMENT
* \param error Returns NULL if creation is successful, an error message
* otherwise. The caller is responsible for calling free() on the error
* message.
*
* \return The new isolate is returned. May be NULL if an error
* occurs during isolate initialization.
* \return The new isolate on success, or NULL if isolate creation failed.
*/
DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri,
const char* main,

View file

@ -1135,7 +1135,9 @@ static Dart_Isolate CreateIsolate(const char* script_uri,
Isolate* I = Dart::CreateIsolate(isolate_name, *flags);
free(isolate_name);
if (I == NULL) {
*error = strdup("Isolate creation failed");
if (error != NULL) {
*error = strdup("Isolate creation failed");
}
return reinterpret_cast<Dart_Isolate>(NULL);
}
{
@ -1164,9 +1166,14 @@ static Dart_Isolate CreateIsolate(const char* script_uri,
// outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate.
T->set_execution_state(Thread::kThreadInNative);
T->EnterSafepoint();
if (error != NULL) {
*error = NULL;
}
return Api::CastIsolate(I);
}
*error = strdup(error_obj.ToErrorCString());
if (error != NULL) {
*error = strdup(error_obj.ToErrorCString());
}
// We exit the API scope entered above.
Dart_ExitScope();
}

View file

@ -14,10 +14,12 @@
namespace dart {
VM_UNIT_TEST_CASE(IsolateCurrent) {
char* error;
Dart_Isolate isolate = Dart_CreateIsolate(
NULL, NULL, bin::core_isolate_snapshot_data,
bin::core_isolate_snapshot_instructions, NULL, NULL, NULL);
bin::core_isolate_snapshot_instructions, NULL, NULL, &error);
EXPECT_EQ(isolate, Dart_CurrentIsolate());
EXPECT_EQ(error, static_cast<char*>(NULL));
Dart_ShutdownIsolate();
EXPECT_EQ(reinterpret_cast<Dart_Isolate>(NULL), Dart_CurrentIsolate());
}