From 584f6434d4472156d0a70624318a3c48327b3f05 Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Mon, 10 Dec 2018 23:43:37 -0800 Subject: [PATCH] review suggestions --- node.gyp | 1 - src/env.cc | 2 +- src/env.h | 2 +- src/node.cc | 2 +- src/node_api.cc | 2 +- src/node_binding-inl.h | 59 ------------------------------------------ src/node_binding.cc | 47 ++++++++++++++++++++++++++++++++- src/node_binding.h | 2 +- src/node_internals.h | 2 +- 9 files changed, 52 insertions(+), 67 deletions(-) delete mode 100644 src/node_binding-inl.h diff --git a/node.gyp b/node.gyp index 265ca01945a46e..7e8867e971aec3 100644 --- a/node.gyp +++ b/node.gyp @@ -421,7 +421,6 @@ 'src/node_api.h', 'src/node_api_types.h', 'src/node_binding.h', - 'src/node_binding-inl.h', 'src/node_buffer.h', 'src/node_constants.h', 'src/node_context_data.h', diff --git a/src/env.cc b/src/env.cc index 8e28cdeb2143b6..66ce46b58426fa 100644 --- a/src/env.cc +++ b/src/env.cc @@ -269,7 +269,7 @@ Environment::~Environment() { TRACING_CATEGORY_NODE1(environment), "Environment", this); // Dereference all addons that were loaded into this environment. - for (auto& addon : loaded_addons_) { + for (binding::DLib& addon : loaded_addons_) { addon.Close(); } } diff --git a/src/env.h b/src/env.h index 67ea5f2b6247ea..475c6063a3b0f4 100644 --- a/src/env.h +++ b/src/env.h @@ -30,7 +30,7 @@ #endif #include "handle_wrap.h" #include "node.h" -#include "node_binding-inl.h" +#include "node_binding.h" #include "node_http2_state.h" #include "node_options.h" #include "req_wrap.h" diff --git a/src/node.cc b/src/node.cc index e0db703d8890d3..ad0afd437dd4b5 100644 --- a/src/node.cc +++ b/src/node.cc @@ -19,7 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -#include "node_binding-inl.h" +#include "node_binding.h" #include "node_buffer.h" #include "node_constants.h" #include "node_context_data.h" diff --git a/src/node_api.cc b/src/node_api.cc index 894d10b61e1d04..7d843c08f5a69d 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -3,7 +3,7 @@ #define NAPI_EXPERIMENTAL #include "js_native_api_v8.h" #include "node_api.h" -#include "node_binding-inl.h" +#include "node_binding.h" #include "node_errors.h" #include "node_internals.h" diff --git a/src/node_binding-inl.h b/src/node_binding-inl.h deleted file mode 100644 index 0c74236969be1e..00000000000000 --- a/src/node_binding-inl.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SRC_NODE_BINDING_INL_H_ -#define SRC_NODE_BINDING_INL_H_ - -#include "node_binding.h" - -namespace node { - -namespace binding { - -inline DLib::DLib(const char* filename, int flags) - : filename_(filename), flags_(flags), handle_(nullptr) {} - -#ifdef __POSIX__ -inline bool DLib::Open() { - handle_ = dlopen(filename_.c_str(), flags_); - if (handle_ != nullptr) return true; - errmsg_ = dlerror(); - return false; -} - -inline void DLib::Close() { - if (handle_ == nullptr) return; - dlclose(handle_); - handle_ = nullptr; -} - -inline void* DLib::GetSymbolAddress(const char* name) { - return dlsym(handle_, name); -} -#else // !__POSIX__ -inline bool DLib::Open() { - int ret = uv_dlopen(filename_.c_str(), &lib_); - if (ret == 0) { - handle_ = static_cast(lib_.handle); - return true; - } - errmsg_ = uv_dlerror(&lib_); - uv_dlclose(&lib_); - return false; -} - -inline void DLib::Close() { - if (handle_ == nullptr) return; - uv_dlclose(&lib_); - handle_ = nullptr; -} - -inline void* DLib::GetSymbolAddress(const char* name) { - void* address; - if (0 == uv_dlsym(&lib_, name, &address)) return address; - return nullptr; -} -#endif // !__POSIX__ - -} // end of namespace binding - -} // end of namespace node - -#endif // SRC_NODE_BINDING_INL_H_ diff --git a/src/node_binding.cc b/src/node_binding.cc index 79d1c42a67e081..85d7f98452c132 100644 --- a/src/node_binding.cc +++ b/src/node_binding.cc @@ -1,4 +1,4 @@ -#include "node_binding-inl.h" +#include "node_binding.h" #include "node_internals.h" #include "node_native_module.h" @@ -122,6 +122,51 @@ extern "C" void node_module_register(void* m) { namespace binding { +DLib::DLib(const char* filename, int flags) + : filename_(filename), flags_(flags), handle_(nullptr) {} + +#ifdef __POSIX__ +bool DLib::Open() { + handle_ = dlopen(filename_.c_str(), flags_); + if (handle_ != nullptr) return true; + errmsg_ = dlerror(); + return false; +} + +void DLib::Close() { + if (handle_ == nullptr) return; + dlclose(handle_); + handle_ = nullptr; +} + +void* DLib::GetSymbolAddress(const char* name) { + return dlsym(handle_, name); +} +#else // !__POSIX__ +bool DLib::Open() { + int ret = uv_dlopen(filename_.c_str(), &lib_); + if (ret == 0) { + handle_ = static_cast(lib_.handle); + return true; + } + errmsg_ = uv_dlerror(&lib_); + uv_dlclose(&lib_); + return false; +} + +void DLib::Close() { + if (handle_ == nullptr) return; + uv_dlclose(&lib_); + handle_ = nullptr; +} + +void* DLib::GetSymbolAddress(const char* name) { + void* address; + if (0 == uv_dlsym(&lib_, name, &address)) return address; + return nullptr; +} +#endif // !__POSIX__ + using InitializerCallback = void (*)(Local exports, Local module, Local context); diff --git a/src/node_binding.h b/src/node_binding.h index 8d56dcacfdb19e..7d79dae80d8e39 100644 --- a/src/node_binding.h +++ b/src/node_binding.h @@ -92,7 +92,7 @@ void DLOpen(const v8::FunctionCallbackInfo& args); } // namespace node -#include "node_binding-inl.h" +#include "node_binding.h" #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_BINDING_H_ diff --git a/src/node_internals.h b/src/node_internals.h index 803172b8570908..1d43d4b1419b9c 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -26,7 +26,7 @@ #include "env-inl.h" #include "node.h" -#include "node_binding-inl.h" +#include "node_binding.h" #include "node_mutex.h" #include "node_persistent.h" #include "tracing/trace_event.h"