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

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: 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 const char* library_name =
18 extension_url + strlen(DartUtils::kDartExtensionScheme); 19 extension_url + strlen(DartUtils::kDartExtensionScheme);
19 if (strchr(library_name, '/') != NULL || 20 if (strchr(library_name, '/') != library_name &&
Mads Ager (google) 2012/03/14 10:29:47 Is this because the extension url has been fully e
Bill Hesse 2012/03/14 17:15:04 Eliminated. We now allow paths. Both absolute an
20 strchr(library_name, '\\') != NULL) { 21 strchr(library_name, '\\') != library_name) {
21 return Dart_Error("path components not allowed in extension library name"); 22 return Dart_Error("path components not allowed in extension library name");
22 } 23 }
23 void* library_handle = LoadExtensionLibrary(library_name); 24 void* library_handle = LoadExtensionLibrary(library_name);
24 if (!library_handle) { 25 if (!library_handle) {
25 return Dart_Error("cannot find extension library"); 26 return Dart_Error("cannot find extension library");
26 } 27 }
27 28
28 const char* strings[3] = { library_name, "_Init", NULL }; 29 const char* last_path_separator =
30 strrchr(library_name, File::PathSeparator()[0]);
Mads Ager (google) 2012/03/14 10:29:47 If you are using PathSeparator here, couldn't you
Bill Hesse 2012/03/14 17:15:04 Done.
31 if (last_path_separator == NULL) {
32 return Dart_Error("cannot find path separator in resolved extension name");
33 }
34 const char* extension_name = last_path_separator + 1;
35
36 const char* strings[3] = { extension_name, "_Init", NULL };
29 char* init_function_name = Concatenate(strings); 37 char* init_function_name = Concatenate(strings);
30 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map); 38 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
31 InitFunctionType fn = reinterpret_cast<InitFunctionType>( 39 InitFunctionType fn = reinterpret_cast<InitFunctionType>(
32 ResolveSymbol(library_handle, init_function_name)); 40 ResolveSymbol(library_handle, init_function_name));
33 free(init_function_name); 41 free(init_function_name);
34 42
35 if (fn == NULL) { 43 if (fn == NULL) {
36 return Dart_Error("cannot find initialization function in extension"); 44 return Dart_Error("cannot find initialization function in extension");
37 } 45 }
38 return (*fn)(parent_library); 46 return (*fn)(parent_library);
39 } 47 }
40 48
41 49
42 // Concatenates a NULL terminated array of strings. 50 // Concatenates a NULL terminated array of strings.
43 // The returned string must be freed. 51 // The returned string must be freed.
44 char* Extensions::Concatenate(const char** strings) { 52 char* Extensions::Concatenate(const char** strings) {
45 int size = 1; // null termination. 53 int size = 1; // null termination.
46 for (int i = 0; strings[i] != NULL; i++) { 54 for (int i = 0; strings[i] != NULL; i++) {
47 size += strlen(strings[i]); 55 size += strlen(strings[i]);
48 } 56 }
49 char* result = reinterpret_cast<char*>(malloc(size)); 57 char* result = reinterpret_cast<char*>(malloc(size));
50 int index = 0; 58 int index = 0;
51 for (int i = 0; strings[i] != NULL; i++) { 59 for (int i = 0; strings[i] != NULL; i++) {
52 index += snprintf(result + index, size - index, "%s", strings[i]); 60 index += snprintf(result + index, size - index, "%s", strings[i]);
53 } 61 }
54 ASSERT(index == size - 1); 62 ASSERT(index == size - 1);
55 ASSERT(result[size - 1] == '\0'); 63 ASSERT(result[size - 1] == '\0');
56 return result; 64 return result;
57 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698