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

Side by Side Diff: runtime/bin/extensions_linux.cc

Issue 9430051: Add native extensions to the Dart shell, on the linux platform. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove stray edits. Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 #include <stdio.h>
6 #include <dlfcn.h>
7
8 #include "bin/file.h"
Mads Ager (google) 2012/02/23 09:26:56 Is anything from file used in this file?
9 #include "include/dart_api.h"
10 #include "platform/assert.h"
11 #include "platform/globals.h"
12 #include "bin/extensions.h"
13 #include "bin/dartutils.h"
14
15 // The current implementation allows names only, not paths, and
Mads Ager (google) 2012/02/23 09:26:56 I would get rid of the fixed-size buffer here and
16 // PATH_MAX is too large (it may be a huge number).
17 const int kBufferLength = 101;
18 char library_path[kBufferLength];
19 char library_init_function[kBufferLength];
20
21 Dart_Handle Extensions::LoadExtension(const char* extension_url,
22 Dart_Handle parent_library) {
23 // TODO(whesse): Make loading extensions lazy, so dynamic library is loaded
24 // only when first native function is called.
25 ASSERT(DartUtils::IsDartExtensionSchemeURL(extension_url));
26 const char* library_name =
27 extension_url + strlen(DartUtils::kDartExtensionScheme);
28 if (strlen(library_name) > kBufferLength - 1 - strlen("./lib.so")) {
29 return Dart_Error("extension library name too long");
30 }
31 if (strchr(library_name, '/') != NULL) {
32 return Dart_Error("path components not allowed in extension library name");
33 }
34 snprintf(library_path, kBufferLength, "./lib%s.so", library_name);
35
36 void* lib_handle = dlopen(library_path, RTLD_LAZY);
37 if (!lib_handle) {
38 return Dart_Error("cannot find extension library");
39 }
40 snprintf(library_init_function, kBufferLength, "%s_Init", library_name);
41 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
42 InitFunctionType fn = reinterpret_cast<InitFunctionType>(
43 dlsym(lib_handle, library_init_function));
44 char *error = dlerror();
45 if (error != NULL) {
46 return Dart_Error(error);
47 }
48 return (*fn)(parent_library);
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698