Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review suggestions
  • Loading branch information
Gabriel Schulhof committed Dec 11, 2018
commit 584f6434d4472156d0a70624318a3c48327b3f05
1 change: 0 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
59 changes: 0 additions & 59 deletions src/node_binding-inl.h

This file was deleted.

47 changes: 46 additions & 1 deletion src/node_binding.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "node_binding-inl.h"
#include "node_binding.h"
#include "node_internals.h"
#include "node_native_module.h"

Expand Down Expand Up @@ -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<void*>(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<Object> exports,
Local<Value> module,
Local<Context> context);
Expand Down
2 changes: 1 addition & 1 deletion src/node_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& 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_
2 changes: 1 addition & 1 deletion src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down