| 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 "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 Dart_Handle Extensions::LoadExtension(const char* extension_url, | 15 Dart_Handle Extensions::LoadExtension(const char* extension_url, |
| 16 Dart_Handle parent_library) { | 16 Dart_Handle parent_library) { |
| 17 char* library_path = strdup(extension_url); | 17 char* library_path = strdup(extension_url); |
| 18 if (!library_path || !File::IsAbsolutePath(library_path)) { | 18 |
| 19 free(library_path); | 19 if (library_path == NULL) { |
| 20 return Dart_Error("unexpected error in library path"); | 20 return Dart_Error("Out of memory in LoadExtension"); |
| 21 } | 21 } |
| 22 |
| 22 // Extract the path and the extension name from the url. | 23 // Extract the path and the extension name from the url. |
| 23 char* last_path_separator = strrchr(library_path, '/'); | 24 char* last_path_separator = strrchr(library_path, '/'); |
| 24 char* extension_name = last_path_separator + 1; | 25 char* extension_name = last_path_separator + 1; |
| 25 *last_path_separator = '\0'; // Terminate library_path at last separator. | 26 *last_path_separator = '\0'; // Terminate library_path at last separator. |
| 26 | 27 |
| 27 void* library_handle = LoadExtensionLibrary(library_path, extension_name); | 28 void* library_handle = LoadExtensionLibrary(library_path, extension_name); |
| 28 if (!library_handle) { | 29 if (library_handle == NULL) { |
| 29 free(library_path); | 30 free(library_path); |
| 30 return Dart_Error("cannot find extension library"); | 31 return Dart_Error("cannot find extension library"); |
| 31 } | 32 } |
| 32 | 33 |
| 33 const char* strings[] = { extension_name, "_Init", NULL }; | 34 const char* strings[] = { extension_name, "_Init", NULL }; |
| 34 char* init_function_name = Concatenate(strings); | 35 char* init_function_name = Concatenate(strings); |
| 35 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map); | 36 typedef Dart_Handle (*InitFunctionType)(Dart_Handle import_map); |
| 36 InitFunctionType fn = reinterpret_cast<InitFunctionType>( | 37 InitFunctionType fn = reinterpret_cast<InitFunctionType>( |
| 37 ResolveSymbol(library_handle, init_function_name)); | 38 ResolveSymbol(library_handle, init_function_name)); |
| 38 free(init_function_name); | 39 free(init_function_name); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 } | 55 } |
| 55 char* result = reinterpret_cast<char*>(malloc(size)); | 56 char* result = reinterpret_cast<char*>(malloc(size)); |
| 56 int index = 0; | 57 int index = 0; |
| 57 for (int i = 0; strings[i] != NULL; i++) { | 58 for (int i = 0; strings[i] != NULL; i++) { |
| 58 index += snprintf(result + index, size - index, "%s", strings[i]); | 59 index += snprintf(result + index, size - index, "%s", strings[i]); |
| 59 } | 60 } |
| 60 ASSERT(index == size - 1); | 61 ASSERT(index == size - 1); |
| 61 ASSERT(result[size - 1] == '\0'); | 62 ASSERT(result[size - 1] == '\0'); |
| 62 return result; | 63 return result; |
| 63 } | 64 } |
| OLD | NEW |