| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 #if defined(FLETCH_TARGET_OS_POSIX) | 5 #if defined(DARTINO_TARGET_OS_POSIX) |
| 6 | 6 |
| 7 #ifdef FLETCH_ENABLE_FFI | 7 #ifdef DARTINO_ENABLE_FFI |
| 8 | 8 |
| 9 #include "src/vm/ffi.h" | 9 #include "src/vm/ffi.h" |
| 10 | 10 |
| 11 #include <dlfcn.h> | 11 #include <dlfcn.h> |
| 12 #include <errno.h> | 12 #include <errno.h> |
| 13 #include <libgen.h> | 13 #include <libgen.h> |
| 14 #include <sys/param.h> | 14 #include <sys/param.h> |
| 15 | 15 |
| 16 #include "src/shared/platform.h" | 16 #include "src/shared/platform.h" |
| 17 #include "src/shared/utils.h" | 17 #include "src/shared/utils.h" |
| 18 | 18 |
| 19 #include "src/vm/natives.h" | 19 #include "src/vm/natives.h" |
| 20 #include "src/vm/object.h" | 20 #include "src/vm/object.h" |
| 21 #include "src/vm/process.h" | 21 #include "src/vm/process.h" |
| 22 | 22 |
| 23 namespace fletch { | 23 namespace dartino { |
| 24 | 24 |
| 25 char* ForeignUtils::DirectoryName(char* path, char* buffer, size_t len) { | 25 char* ForeignUtils::DirectoryName(char* path, char* buffer, size_t len) { |
| 26 strncpy(buffer, path, len); | 26 strncpy(buffer, path, len); |
| 27 buffer[len - 1] = '\0'; | 27 buffer[len - 1] = '\0'; |
| 28 return dirname(buffer); | 28 return dirname(buffer); |
| 29 } | 29 } |
| 30 | 30 |
| 31 class DefaultLibraryEntry { | 31 class DefaultLibraryEntry { |
| 32 public: | 32 public: |
| 33 DefaultLibraryEntry(void* handle, DefaultLibraryEntry* next) | 33 DefaultLibraryEntry(void* handle, DefaultLibraryEntry* next) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 63 delete current; | 63 delete current; |
| 64 current = next; | 64 current = next; |
| 65 } | 65 } |
| 66 delete mutex_; | 66 delete mutex_; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool ForeignFunctionInterface::AddDefaultSharedLibrary(const char* library) { | 69 bool ForeignFunctionInterface::AddDefaultSharedLibrary(const char* library) { |
| 70 ScopedLock lock(mutex_); | 70 ScopedLock lock(mutex_); |
| 71 void* handle = dlopen(library, RTLD_LOCAL | RTLD_LAZY); | 71 void* handle = dlopen(library, RTLD_LOCAL | RTLD_LAZY); |
| 72 if (handle != NULL) { | 72 if (handle != NULL) { |
| 73 // We have to maintain the insertion order (see fletch_api.h). | 73 // We have to maintain the insertion order (see dartino_api.h). |
| 74 if (libraries_ == NULL) { | 74 if (libraries_ == NULL) { |
| 75 libraries_ = new DefaultLibraryEntry(handle, libraries_); | 75 libraries_ = new DefaultLibraryEntry(handle, libraries_); |
| 76 } else { | 76 } else { |
| 77 libraries_->append(new DefaultLibraryEntry(handle, libraries_)); | 77 libraries_->append(new DefaultLibraryEntry(handle, libraries_)); |
| 78 } | 78 } |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 return false; | 81 return false; |
| 82 } | 82 } |
| 83 | 83 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (wrote > MAXPATHLEN) { | 152 if (wrote > MAXPATHLEN) { |
| 153 return Failure::index_out_of_bounds(); | 153 return Failure::index_out_of_bounds(); |
| 154 } | 154 } |
| 155 return process->NewStringFromAscii(List<const char>(result, strlen(result))); | 155 return process->NewStringFromAscii(List<const char>(result, strlen(result))); |
| 156 } | 156 } |
| 157 END_NATIVE() | 157 END_NATIVE() |
| 158 | 158 |
| 159 BEGIN_NATIVE(ForeignErrno) { return Smi::FromWord(errno); } | 159 BEGIN_NATIVE(ForeignErrno) { return Smi::FromWord(errno); } |
| 160 END_NATIVE() | 160 END_NATIVE() |
| 161 | 161 |
| 162 } // namespace fletch | 162 } // namespace dartino |
| 163 | 163 |
| 164 #endif // FLETCH_ENABLE_FFI | 164 #endif // DARTINO_ENABLE_FFI |
| 165 | 165 |
| 166 #endif // defined(FLETCH_TARGET_OS_POSIX) | 166 #endif // defined(DARTINO_TARGET_OS_POSIX) |
| OLD | NEW |