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

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

Issue 2480793002: clang-format runtime/bin (Closed)
Patch Set: Created 4 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
« no previous file with comments | « runtime/bin/eventhandler_win.cc ('k') | runtime/bin/fdutils_android.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 "bin/dartutils.h" 9 #include "bin/dartutils.h"
10 #include "bin/file.h" 10 #include "bin/file.h"
(...skipping 10 matching lines...) Expand all
21 const char* sep = File::PathSeparator(); 21 const char* sep = File::PathSeparator();
22 ASSERT(strlen(sep) == 1); 22 ASSERT(strlen(sep) == 1);
23 return sep[0]; 23 return sep[0];
24 } 24 }
25 25
26 26
27 void* Extensions::MakePathAndResolve(const char* dir, const char* name) { 27 void* Extensions::MakePathAndResolve(const char* dir, const char* name) {
28 // First try to find the library with a suffix specifying the architecture. 28 // First try to find the library with a suffix specifying the architecture.
29 { 29 {
30 const char* path_components[] = { 30 const char* path_components[] = {
31 dir, 31 dir,
32 Platform::LibraryPrefix(), 32 Platform::LibraryPrefix(),
33 name, 33 name,
34 "-", 34 "-",
35 Platform::HostArchitecture(), // arm 35 Platform::HostArchitecture(), // arm
36 ".", 36 ".",
37 Platform::LibraryExtension(), // so 37 Platform::LibraryExtension(), // so
38 NULL, 38 NULL,
39 }; 39 };
40 const char* library_file = Concatenate(path_components); 40 const char* library_file = Concatenate(path_components);
41 void* library_handle = LoadExtensionLibrary(library_file); 41 void* library_handle = LoadExtensionLibrary(library_file);
42 if (library_handle != NULL) { 42 if (library_handle != NULL) {
43 return library_handle; 43 return library_handle;
44 } 44 }
45 } 45 }
46 46
47 // Fall back on a library name without the suffix. 47 // Fall back on a library name without the suffix.
48 { 48 {
49 const char* path_components[] = { 49 const char* path_components[] = {
50 dir, 50 dir,
51 Platform::LibraryPrefix(), 51 Platform::LibraryPrefix(),
52 name, 52 name,
53 ".", 53 ".",
54 Platform::LibraryExtension(), // so 54 Platform::LibraryExtension(), // so
55 NULL, 55 NULL,
56 }; 56 };
57 const char* library_file = Concatenate(path_components); 57 const char* library_file = Concatenate(path_components);
58 return LoadExtensionLibrary(library_file); 58 return LoadExtensionLibrary(library_file);
59 } 59 }
60 } 60 }
61 61
62 62
63 // IMPORTANT: In the absolute path case, do not extract the filename and search 63 // IMPORTANT: In the absolute path case, do not extract the filename and search
64 // for that by passing it to LoadExtensionLibrary. That can lead to confusion in 64 // for that by passing it to LoadExtensionLibrary. That can lead to confusion in
65 // which the absolute path is wrong, and a different version of the library is 65 // which the absolute path is wrong, and a different version of the library is
(...skipping 12 matching lines...) Expand all
78 void* Extensions::ResolveExtension(const char* extension_directory, 78 void* Extensions::ResolveExtension(const char* extension_directory,
79 const char* extension_name) { 79 const char* extension_name) {
80 // If the path following dart-ext is an absolute path, then only look for the 80 // If the path following dart-ext is an absolute path, then only look for the
81 // library there. 81 // library there.
82 if (File::IsAbsolutePath(extension_name)) { 82 if (File::IsAbsolutePath(extension_name)) {
83 return ResolveAbsPathExtension(extension_name); 83 return ResolveAbsPathExtension(extension_name);
84 } 84 }
85 85
86 // If the path following dart-ext is just a file name, first look next to 86 // If the path following dart-ext is just a file name, first look next to
87 // the importing Dart library. 87 // the importing Dart library.
88 void* library_handle = MakePathAndResolve(extension_directory, 88 void* library_handle =
89 extension_name); 89 MakePathAndResolve(extension_directory, extension_name);
90 if (library_handle != NULL) { 90 if (library_handle != NULL) {
91 return library_handle; 91 return library_handle;
92 } 92 }
93 93
94 // Then pass the library name down to the platform. E.g. dlopen will do its 94 // Then pass the library name down to the platform. E.g. dlopen will do its
95 // own search in standard search locations. 95 // own search in standard search locations.
96 return MakePathAndResolve("", extension_name); 96 return MakePathAndResolve("", extension_name);
97 } 97 }
98 98
99 99
100 Dart_Handle Extensions::LoadExtension(const char* extension_directory, 100 Dart_Handle Extensions::LoadExtension(const char* extension_directory,
101 const char* extension_name, 101 const char* extension_name,
102 Dart_Handle parent_library) { 102 Dart_Handle parent_library) {
103 void* library_handle = ResolveExtension(extension_directory, extension_name); 103 void* library_handle = ResolveExtension(extension_directory, extension_name);
104 if (library_handle == NULL) { 104 if (library_handle == NULL) {
105 return GetError(); 105 return GetError();
106 } 106 }
107 107
108 const char* extension = extension_name; 108 const char* extension = extension_name;
109 if (File::IsAbsolutePath(extension_name)) { 109 if (File::IsAbsolutePath(extension_name)) {
110 extension = strrchr(extension_name, PathSeparator()) + 1; 110 extension = strrchr(extension_name, PathSeparator()) + 1;
111 } 111 }
112 112
113 const char* strings[] = { extension, "_Init", NULL }; 113 const char* strings[] = {extension, "_Init", NULL};
114 const char* init_function_name = Concatenate(strings); 114 const char* init_function_name = Concatenate(strings);
115 void* init_function = ResolveSymbol(library_handle, init_function_name); 115 void* init_function = ResolveSymbol(library_handle, init_function_name);
116 Dart_Handle result = GetError(); 116 Dart_Handle result = GetError();
117 if (Dart_IsError(result)) { 117 if (Dart_IsError(result)) {
118 return result; 118 return result;
119 } 119 }
120 ASSERT(init_function != NULL); 120 ASSERT(init_function != NULL);
121 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map); 121 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map);
122 InitFunctionType fn = reinterpret_cast<InitFunctionType>(init_function); 122 InitFunctionType fn = reinterpret_cast<InitFunctionType>(init_function);
123 return (*fn)(parent_library); 123 return (*fn)(parent_library);
(...skipping 12 matching lines...) Expand all
136 for (int i = 0; strings[i] != NULL; i++) { 136 for (int i = 0; strings[i] != NULL; i++) {
137 index += snprintf(result + index, size - index, "%s", strings[i]); 137 index += snprintf(result + index, size - index, "%s", strings[i]);
138 } 138 }
139 ASSERT(index == size - 1); 139 ASSERT(index == size - 1);
140 ASSERT(result[size - 1] == '\0'); 140 ASSERT(result[size - 1] == '\0');
141 return result; 141 return result;
142 } 142 }
143 143
144 } // namespace bin 144 } // namespace bin
145 } // namespace dart 145 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/eventhandler_win.cc ('k') | runtime/bin/fdutils_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698