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

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

Issue 10103031: Refactor URI processing of native extensions directive #import("dart-ext:foo"). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 8 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
« no previous file with comments | « runtime/bin/builtin.dart ('k') | runtime/bin/extensions_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/extensions.h" 5 #include "bin/extensions.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "include/dart_api.h" 9 #include "include/dart_api.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
11 #include "platform/globals.h" 11 #include "platform/globals.h"
12 #include "bin/dartutils.h" 12 #include "bin/dartutils.h"
13 #include "bin/file.h" 13 #include "bin/file.h"
14 14
15 Dart_Handle Extensions::LoadExtension(const char* extension_url, 15 Dart_Handle Extensions::LoadExtension(const char* extension_url,
16 Dart_Handle parent_library) { 16 Dart_Handle parent_library) {
17 ASSERT(DartUtils::IsDartExtensionSchemeURL(extension_url)); 17 char* library_path = strdup(extension_url);
18 // Make a mutable copy of the extension url, without the "dart:" scheme.
19 const char* path_component =
20 extension_url + strlen(DartUtils::kDartExtensionScheme);
21 #ifdef TARGET_OS_WINDOWS
22 // Remove initial '/' from a uri formatted absolute path "/C:/path/to/dll"
23 ASSERT(path_component[0] == '/');
24 path_component++;
25 #endif
26 char* library_path = strdup(path_component);
27 if (!library_path || !File::IsAbsolutePath(library_path)) { 18 if (!library_path || !File::IsAbsolutePath(library_path)) {
28 free(library_path); 19 free(library_path);
29 return Dart_Error("unexpected error in library path"); 20 return Dart_Error("unexpected error in library path");
30 } 21 }
31 // Extract the path and the extension name from the url. 22 // Extract the path and the extension name from the url.
32 char* last_path_separator = strrchr(library_path, '/'); 23 char* last_path_separator = strrchr(library_path, '/');
33 char* extension_name = last_path_separator + 1; 24 char* extension_name = last_path_separator + 1;
34 *last_path_separator = '\0'; // Terminate library_path at last separator. 25 *last_path_separator = '\0'; // Terminate library_path at last separator.
35 26
36 void* library_handle = LoadExtensionLibrary(library_path, extension_name); 27 void* library_handle = LoadExtensionLibrary(library_path, extension_name);
37 if (!library_handle) { 28 if (!library_handle) {
38 free(library_path); 29 free(library_path);
39 return Dart_Error("cannot find extension library"); 30 return Dart_Error("cannot find extension library");
40 } 31 }
41 32
42 const char* strings[3] = { extension_name, "_Init", NULL }; 33 const char* strings[] = { extension_name, "_Init", NULL };
43 char* init_function_name = Concatenate(strings); 34 char* init_function_name = Concatenate(strings);
44 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map); 35 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
45 InitFunctionType fn = reinterpret_cast<InitFunctionType>( 36 InitFunctionType fn = reinterpret_cast<InitFunctionType>(
46 ResolveSymbol(library_handle, init_function_name)); 37 ResolveSymbol(library_handle, init_function_name));
47 free(init_function_name); 38 free(init_function_name);
48 free(library_path); 39 free(library_path);
49 40
50 if (fn == NULL) { 41 if (fn == NULL) {
51 return Dart_Error("cannot find initialization function in extension"); 42 return Dart_Error("cannot find initialization function in extension");
52 } 43 }
(...skipping 10 matching lines...) Expand all
63 } 54 }
64 char* result = reinterpret_cast<char*>(malloc(size)); 55 char* result = reinterpret_cast<char*>(malloc(size));
65 int index = 0; 56 int index = 0;
66 for (int i = 0; strings[i] != NULL; i++) { 57 for (int i = 0; strings[i] != NULL; i++) {
67 index += snprintf(result + index, size - index, "%s", strings[i]); 58 index += snprintf(result + index, size - index, "%s", strings[i]);
68 } 59 }
69 ASSERT(index == size - 1); 60 ASSERT(index == size - 1);
70 ASSERT(result[size - 1] == '\0'); 61 ASSERT(result[size - 1] == '\0');
71 return result; 62 return result;
72 } 63 }
OLDNEW
« no previous file with comments | « runtime/bin/builtin.dart ('k') | runtime/bin/extensions_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698