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

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

Issue 9694045: Change lookup path for Dart native extensions shared libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comments, remove printf statement. 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 unified diff | Download patch | Annotate | Revision Log
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 14
14 Dart_Handle Extensions::LoadExtension(const char* extension_url, 15 Dart_Handle Extensions::LoadExtension(const char* extension_url,
15 Dart_Handle parent_library) { 16 Dart_Handle parent_library) {
16 ASSERT(DartUtils::IsDartExtensionSchemeURL(extension_url)); 17 ASSERT(DartUtils::IsDartExtensionSchemeURL(extension_url));
17 const char* library_name = 18 // Make a mutable copy of the extension url, without the "dart:" scheme.
19 const char* path_component =
18 extension_url + strlen(DartUtils::kDartExtensionScheme); 20 extension_url + strlen(DartUtils::kDartExtensionScheme);
19 if (strchr(library_name, '/') != NULL || 21 const char* path_component_strings[2] = { path_component, NULL };
20 strchr(library_name, '\\') != NULL) { 22 char* library_path = Concatenate(path_component_strings);
Mads Ager (google) 2012/03/15 08:44:09 Instead of these two lines, please use strdup(path
Bill Hesse 2012/03/15 13:08:54 Done.
21 return Dart_Error("path components not allowed in extension library name"); 23 // Extract the path and the extension name from the url.
22 } 24 char* last_path_separator = strrchr(library_path, File::PathSeparator()[0]);
23 void* library_handle = LoadExtensionLibrary(library_name); 25 char* extension_name = last_path_separator + 1;
26 *last_path_separator = '\0'; // Terminate library_path at last separator.
27
28 void* library_handle = LoadExtensionLibrary(library_path, extension_name);
24 if (!library_handle) { 29 if (!library_handle) {
30 free(library_path);
25 return Dart_Error("cannot find extension library"); 31 return Dart_Error("cannot find extension library");
26 } 32 }
27 33
28 const char* strings[3] = { library_name, "_Init", NULL }; 34 const char* strings[3] = { extension_name, "_Init", NULL };
29 char* init_function_name = Concatenate(strings); 35 char* init_function_name = Concatenate(strings);
30 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map); 36 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
31 InitFunctionType fn = reinterpret_cast<InitFunctionType>( 37 InitFunctionType fn = reinterpret_cast<InitFunctionType>(
32 ResolveSymbol(library_handle, init_function_name)); 38 ResolveSymbol(library_handle, init_function_name));
33 free(init_function_name); 39 free(init_function_name);
40 free(library_path);
34 41
35 if (fn == NULL) { 42 if (fn == NULL) {
36 return Dart_Error("cannot find initialization function in extension"); 43 return Dart_Error("cannot find initialization function in extension");
37 } 44 }
38 return (*fn)(parent_library); 45 return (*fn)(parent_library);
39 } 46 }
40 47
41 48
42 // Concatenates a NULL terminated array of strings. 49 // Concatenates a NULL terminated array of strings.
43 // The returned string must be freed. 50 // The returned string must be freed.
44 char* Extensions::Concatenate(const char** strings) { 51 char* Extensions::Concatenate(const char** strings) {
45 int size = 1; // null termination. 52 int size = 1; // null termination.
46 for (int i = 0; strings[i] != NULL; i++) { 53 for (int i = 0; strings[i] != NULL; i++) {
47 size += strlen(strings[i]); 54 size += strlen(strings[i]);
48 } 55 }
49 char* result = reinterpret_cast<char*>(malloc(size)); 56 char* result = reinterpret_cast<char*>(malloc(size));
50 int index = 0; 57 int index = 0;
51 for (int i = 0; strings[i] != NULL; i++) { 58 for (int i = 0; strings[i] != NULL; i++) {
52 index += snprintf(result + index, size - index, "%s", strings[i]); 59 index += snprintf(result + index, size - index, "%s", strings[i]);
53 } 60 }
54 ASSERT(index == size - 1); 61 ASSERT(index == size - 1);
55 ASSERT(result[size - 1] == '\0'); 62 ASSERT(result[size - 1] == '\0');
56 return result; 63 return result;
57 } 64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698