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

Unified Diff: runtime/bin/extensions_linux.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.cc ('k') | runtime/bin/extensions_macos.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/extensions_linux.cc
diff --git a/runtime/bin/extensions_linux.cc b/runtime/bin/extensions_linux.cc
index ad6c84b9a3b024524f80f963a76e7cd2464f7d44..df4df5895e30641075aff47ad42173554576a4ea 100644
--- a/runtime/bin/extensions_linux.cc
+++ b/runtime/bin/extensions_linux.cc
@@ -2,44 +2,19 @@
// 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 <stdio.h>
-#include <dlfcn.h>
-
-#include "include/dart_api.h"
-#include "platform/assert.h"
-#include "platform/globals.h"
#include "bin/extensions.h"
-#include "bin/dartutils.h"
-
-Dart_Handle Extensions::LoadExtension(const char* extension_url,
- Dart_Handle parent_library) {
- // TODO(whesse): Consider making loading extensions lazy, so the
- // dynamic library is loaded only when first native function is called.
- ASSERT(DartUtils::IsDartExtensionSchemeURL(extension_url));
- const char* library_name =
- extension_url + strlen(DartUtils::kDartExtensionScheme);
- if (strchr(library_name, '/') != NULL) {
- return Dart_Error("path components not allowed in extension library name");
- }
- const int buffer_length = strlen(library_name) + strlen("./lib.so") + 1;
- char* library_path = new char[buffer_length];
- snprintf(library_path, buffer_length, "./lib%s.so", library_name);
+#include <dlfcn.h>
+void* Extensions::LoadExtensionLibrary(const char* library_name) {
+ const char* strings[4] = { "./lib", library_name, ".so", NULL };
+ char* library_path = Concatenate(strings);
void* lib_handle = dlopen(library_path, RTLD_LAZY);
- if (!lib_handle) {
- delete[] library_path;
- return Dart_Error("cannot find extension library");
- }
- // Reuse library_path buffer for intialization function name.
- char* library_init_function = library_path;
- snprintf(library_init_function, buffer_length, "%s_Init", library_name);
- typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
- InitFunctionType fn = reinterpret_cast<InitFunctionType>(
- dlsym(lib_handle, library_init_function));
- delete[] library_path;
- char *error = dlerror();
- if (error != NULL) {
- return Dart_Error(error);
- }
- return (*fn)(parent_library);
+ free(library_path);
+ return lib_handle;
+}
+
+void* Extensions::ResolveSymbol(void* lib_handle, const char* symbol) {
+ void* result = dlsym(lib_handle, symbol);
+ if (dlerror() != NULL) return NULL;
+ return result;
}
« no previous file with comments | « runtime/bin/extensions.cc ('k') | runtime/bin/extensions_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698