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

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

Issue 57923004: Allow Windows network share paths for the script path and the package root. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 #include "bin/file.h"
14 14
15 15
16 namespace dart { 16 namespace dart {
17 namespace bin { 17 namespace bin {
18 18
19 Dart_Handle Extensions::LoadExtension(const char* extension_url, 19 Dart_Handle Extensions::LoadExtension(const char* extension_url,
Søren Gjesse 2013/11/04 16:15:58 With the test for both / and \ below the name of t
20 Dart_Handle parent_library) { 20 Dart_Handle parent_library) {
21 char* library_path = strdup(extension_url); 21 char* library_path = strdup(extension_url);
22 22
23 if (library_path == NULL) { 23 if (library_path == NULL) {
24 return Dart_NewApiError("Out of memory in LoadExtension"); 24 return Dart_NewApiError("Out of memory in LoadExtension");
25 } 25 }
26 26
27 // Extract the path and the extension name from the url. 27 // Extract the path and the extension name from the url.
28 char* last_path_separator = strrchr(library_path, '/'); 28 char* last_path_separator = strrchr(library_path, '/');
29 if (last_path_separator == NULL) {
30 last_path_separator = strrchr(library_path, '\\');
31 }
32 if (last_path_separator == NULL) {
33 free(library_path);
34 return Dart_NewApiError("Cannot find extension library directory");
35 }
29 char* extension_name = last_path_separator + 1; 36 char* extension_name = last_path_separator + 1;
37
30 *last_path_separator = '\0'; // Terminate library_path at last separator. 38 *last_path_separator = '\0'; // Terminate library_path at last separator.
31 39
32 void* library_handle = LoadExtensionLibrary(library_path, extension_name); 40 void* library_handle = LoadExtensionLibrary(library_path, extension_name);
33 if (library_handle == NULL) { 41 if (library_handle == NULL) {
34 free(library_path); 42 free(library_path);
35 return Dart_NewApiError("cannot find extension library"); 43 return Dart_NewApiError("Cannot find extension library");
36 } 44 }
37 45
38 const char* strings[] = { extension_name, "_Init", NULL }; 46 const char* strings[] = { extension_name, "_Init", NULL };
39 char* init_function_name = Concatenate(strings); 47 char* init_function_name = Concatenate(strings);
40 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map); 48 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
41 InitFunctionType fn = reinterpret_cast<InitFunctionType>( 49 InitFunctionType fn = reinterpret_cast<InitFunctionType>(
42 ResolveSymbol(library_handle, init_function_name)); 50 ResolveSymbol(library_handle, init_function_name));
43 free(init_function_name); 51 free(init_function_name);
44 free(library_path); 52 free(library_path);
45 53
46 if (fn == NULL) { 54 if (fn == NULL) {
47 return Dart_NewApiError("cannot find initialization function in extension"); 55 return Dart_NewApiError("Cannot find initialization function in extension");
48 } 56 }
49 return (*fn)(parent_library); 57 return (*fn)(parent_library);
50 } 58 }
51 59
52 60
53 // Concatenates a NULL terminated array of strings. 61 // Concatenates a NULL terminated array of strings.
54 // The returned string must be freed. 62 // The returned string must be freed.
55 char* Extensions::Concatenate(const char** strings) { 63 char* Extensions::Concatenate(const char** strings) {
56 int size = 1; // null termination. 64 int size = 1; // null termination.
57 for (int i = 0; strings[i] != NULL; i++) { 65 for (int i = 0; strings[i] != NULL; i++) {
58 size += strlen(strings[i]); 66 size += strlen(strings[i]);
59 } 67 }
60 char* result = reinterpret_cast<char*>(malloc(size)); 68 char* result = reinterpret_cast<char*>(malloc(size));
61 int index = 0; 69 int index = 0;
62 for (int i = 0; strings[i] != NULL; i++) { 70 for (int i = 0; strings[i] != NULL; i++) {
63 index += snprintf(result + index, size - index, "%s", strings[i]); 71 index += snprintf(result + index, size - index, "%s", strings[i]);
64 } 72 }
65 ASSERT(index == size - 1); 73 ASSERT(index == size - 1);
66 ASSERT(result[size - 1] == '\0'); 74 ASSERT(result[size - 1] == '\0');
67 return result; 75 return result;
68 } 76 }
69 77
70 } // namespace bin 78 } // namespace bin
71 } // namespace dart 79 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698