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

Unified Diff: runtime/bin/extensions.cc

Issue 9465004: Add native extensions for the Dart shell to mac and windows (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use shared library (dylib) on Mac (and therefore for all platforms). Created 8 years, 9 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/bin/extensions.h ('k') | runtime/bin/extensions_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/extensions.cc
diff --git a/runtime/bin/extensions.cc b/runtime/bin/extensions.cc
new file mode 100644
index 0000000000000000000000000000000000000000..afcb29fdc52a10ba9222e1c0c63e68becdcad562
--- /dev/null
+++ b/runtime/bin/extensions.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "bin/extensions.h"
+
+#include <stdio.h>
+
+#include "include/dart_api.h"
+#include "platform/assert.h"
+#include "platform/globals.h"
+#include "bin/dartutils.h"
+
+Dart_Handle Extensions::LoadExtension(const char* extension_url,
+ Dart_Handle parent_library) {
+ ASSERT(DartUtils::IsDartExtensionSchemeURL(extension_url));
+ const char* library_name =
+ extension_url + strlen(DartUtils::kDartExtensionScheme);
+ if (strchr(library_name, '/') != NULL ||
+ strchr(library_name, '\\') != NULL) {
+ return Dart_Error("path components not allowed in extension library name");
+ }
+ void* library_handle = LoadExtensionLibrary(library_name);
+ if (!library_handle) {
+ return Dart_Error("cannot find extension library");
+ }
+
+ const char* strings[3] = { library_name, "_Init", NULL };
+ char* init_function_name = Concatenate(strings);
+ typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
+ InitFunctionType fn = reinterpret_cast<InitFunctionType>(
+ ResolveSymbol(library_handle, init_function_name));
+ free(init_function_name);
+
+ if (fn == NULL) {
+ return Dart_Error("cannot find initialization function in extension");
+ }
+ return (*fn)(parent_library);
+}
+
+
+// Concatenates a NULL terminated array of strings.
+// The returned string must be freed.
+char* Extensions::Concatenate(const char** strings) {
+ int size = 1; // null termination.
+ for (int i = 0; strings[i] != NULL; i++) {
+ size += strlen(strings[i]);
+ }
+ char* result = reinterpret_cast<char*>(malloc(size));
+ int index = 0;
+ for (int i = 0; strings[i] != NULL; i++) {
+ index += snprintf(result + index, size - index, "%s", strings[i]);
+ }
+ ASSERT(index == size - 1);
+ ASSERT(result[size - 1] == '\0');
+ return result;
+}
« no previous file with comments | « runtime/bin/extensions.h ('k') | runtime/bin/extensions_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698