Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: samples/sample_extension/sample_extension.cc

Issue 131103025: Fixes ABI bug in MIPS. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/stub_code_mips.cc ('k') | samples/sample_extension/sample_synchronous_extension.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/sample_extension/sample_extension.cc
===================================================================
--- samples/sample_extension/sample_extension.cc (revision 32146)
+++ samples/sample_extension/sample_extension.cc (working copy)
@@ -7,24 +7,34 @@
#include "include/dart_api.h"
#include "include/dart_native_api.h"
+
Dart_NativeFunction ResolveName(Dart_Handle name,
int argc,
bool* auto_setup_scope);
+
DART_EXPORT Dart_Handle sample_extension_Init(Dart_Handle parent_library) {
- if (Dart_IsError(parent_library)) { return parent_library; }
+ if (Dart_IsError(parent_library)) {
+ return parent_library;
+ }
Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName);
- if (Dart_IsError(result_code)) return result_code;
+ if (Dart_IsError(result_code)) {
+ return result_code;
+ }
return Dart_Null();
}
+
Dart_Handle HandleError(Dart_Handle handle) {
- if (Dart_IsError(handle)) Dart_PropagateError(handle);
+ if (Dart_IsError(handle)) {
+ Dart_PropagateError(handle);
+ }
return handle;
}
+
void SystemRand(Dart_NativeArguments arguments) {
Dart_EnterScope();
Dart_Handle result = HandleError(Dart_NewInteger(rand()));
@@ -32,6 +42,7 @@
Dart_ExitScope();
}
+
void SystemSrand(Dart_NativeArguments arguments) {
Dart_EnterScope();
bool success = false;
@@ -50,10 +61,15 @@
Dart_ExitScope();
}
+
uint8_t* randomArray(int seed, int length) {
- if (length <= 0 || length > 10000000) return NULL;
+ if (length <= 0 || length > 10000000) {
+ return NULL;
+ }
uint8_t* values = reinterpret_cast<uint8_t*>(malloc(length));
- if (NULL == values) return NULL;
+ if (NULL == values) {
+ return NULL;
+ }
srand(seed);
for (int i = 0; i < length; ++i) {
values[i] = rand() % 256;
@@ -61,6 +77,7 @@
return values;
}
+
void wrappedRandomArray(Dart_Port dest_port_id,
Dart_CObject* message) {
Dart_Port reply_port_id = ILLEGAL_PORT;
@@ -97,6 +114,7 @@
Dart_PostCObject(reply_port_id, &result);
}
+
void randomArrayServicePort(Dart_NativeArguments arguments) {
Dart_EnterScope();
Dart_SetReturnValue(arguments, Dart_Null());
@@ -115,29 +133,52 @@
Dart_NativeFunction function;
};
+
FunctionLookup function_list[] = {
{"SystemRand", SystemRand},
{"SystemSrand", SystemSrand},
{"RandomArray_ServicePort", randomArrayServicePort},
{NULL, NULL}};
+
+FunctionLookup no_scope_function_list[] = {{"NoScopeSystemRand", SystemRand}};
+
Dart_NativeFunction ResolveName(Dart_Handle name,
int argc,
bool* auto_setup_scope) {
- if (!Dart_IsString(name)) return NULL;
+ if (!Dart_IsString(name)) {
+ return NULL;
+ }
Dart_NativeFunction result = NULL;
- if (auto_setup_scope == NULL) return NULL;
- *auto_setup_scope = true;
+ if (auto_setup_scope == NULL) {
+ return NULL;
+ }
+
Dart_EnterScope();
const char* cname;
HandleError(Dart_StringToCString(name, &cname));
for (int i=0; function_list[i].name != NULL; ++i) {
if (strcmp(function_list[i].name, cname) == 0) {
+ *auto_setup_scope = true;
result = function_list[i].function;
break;
}
}
+
+ if (result != NULL) {
+ Dart_ExitScope();
+ return result;
+ }
+
+ for (int i=0; no_scope_function_list[i].name != NULL; ++i) {
+ if (strcmp(no_scope_function_list[i].name, cname) == 0) {
+ *auto_setup_scope = false;
+ result = no_scope_function_list[i].function;
+ break;
+ }
+ }
+
Dart_ExitScope();
return result;
}
« no previous file with comments | « runtime/vm/stub_code_mips.cc ('k') | samples/sample_extension/sample_synchronous_extension.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698