| OLD | NEW |
| 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" |
| 11 #include "bin/platform.h" |
| 11 #include "include/dart_api.h" | 12 #include "include/dart_api.h" |
| 12 #include "platform/assert.h" | 13 #include "platform/assert.h" |
| 13 #include "platform/globals.h" | 14 #include "platform/globals.h" |
| 14 | 15 |
| 15 namespace dart { | 16 namespace dart { |
| 16 namespace bin { | 17 namespace bin { |
| 17 | 18 |
| 18 Dart_Handle Extensions::LoadExtension(const char* extension_directory, | 19 Dart_Handle Extensions::LoadExtension(const char* extension_directory, |
| 19 const char* extension_file, | |
| 20 const char* extension_name, | 20 const char* extension_name, |
| 21 Dart_Handle parent_library) { | 21 Dart_Handle parent_library) { |
| 22 if (strncmp(extension_directory, "http://", 7) == 0 || | 22 if (strncmp(extension_directory, "http://", 7) == 0 || |
| 23 strncmp(extension_directory, "https://", 8) == 0) { | 23 strncmp(extension_directory, "https://", 8) == 0) { |
| 24 return Dart_NewApiError("Cannot load native extensions over http:"); | 24 return Dart_NewApiError("Cannot load native extensions over http:"); |
| 25 } | 25 } |
| 26 const char* library_strings[] = { extension_directory, extension_file, NULL }; | 26 |
| 27 // For example on Linux: directory/libfoo-arm.so |
| 28 const char* library_strings[] = { |
| 29 extension_directory, // directory/ |
| 30 Platform::LibraryPrefix(), // lib |
| 31 extension_name, // foo |
| 32 "-", |
| 33 Platform::HostArchitecture(), // arm |
| 34 ".", |
| 35 Platform::LibraryExtension(), // so |
| 36 NULL, |
| 37 }; |
| 27 const char* library_file = Concatenate(library_strings); | 38 const char* library_file = Concatenate(library_strings); |
| 28 void* library_handle = LoadExtensionLibrary(library_file); | 39 void* library_handle = LoadExtensionLibrary(library_file); |
| 29 if (library_handle == NULL) { | 40 if (library_handle == NULL) { |
| 30 return GetError(); | 41 // Fallback on a library file name that does not specify the host |
| 42 // architecture. For example on Linux: directory/libfoo.so |
| 43 const char* fallback_library_strings[] = { |
| 44 extension_directory, // directory/ |
| 45 Platform::LibraryPrefix(), // lib |
| 46 extension_name, // foo |
| 47 ".", |
| 48 Platform::LibraryExtension(), // so |
| 49 NULL, |
| 50 }; |
| 51 const char* fallback_library_file = Concatenate(fallback_library_strings); |
| 52 library_handle = LoadExtensionLibrary(fallback_library_file); |
| 53 if (library_handle == NULL) { |
| 54 return GetError(); |
| 55 } |
| 31 } | 56 } |
| 32 | 57 |
| 33 const char* strings[] = { extension_name, "_Init", NULL }; | 58 const char* strings[] = { extension_name, "_Init", NULL }; |
| 34 const char* init_function_name = Concatenate(strings); | 59 const char* init_function_name = Concatenate(strings); |
| 35 void* init_function = ResolveSymbol(library_handle, init_function_name); | 60 void* init_function = ResolveSymbol(library_handle, init_function_name); |
| 36 Dart_Handle result = GetError(); | 61 Dart_Handle result = GetError(); |
| 37 if (Dart_IsError(result)) { | 62 if (Dart_IsError(result)) { |
| 38 return result; | 63 return result; |
| 39 } | 64 } |
| 40 ASSERT(init_function != NULL); | 65 ASSERT(init_function != NULL); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 for (int i = 0; strings[i] != NULL; i++) { | 81 for (int i = 0; strings[i] != NULL; i++) { |
| 57 index += snprintf(result + index, size - index, "%s", strings[i]); | 82 index += snprintf(result + index, size - index, "%s", strings[i]); |
| 58 } | 83 } |
| 59 ASSERT(index == size - 1); | 84 ASSERT(index == size - 1); |
| 60 ASSERT(result[size - 1] == '\0'); | 85 ASSERT(result[size - 1] == '\0'); |
| 61 return result; | 86 return result; |
| 62 } | 87 } |
| 63 | 88 |
| 64 } // namespace bin | 89 } // namespace bin |
| 65 } // namespace dart | 90 } // namespace dart |
| OLD | NEW |