forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: unload addons when environment quits
This is an alternative to nodejs#23319 which attaches the loaded addons to the environment and closes them when the environment is destroyed.
- Loading branch information
Gabriel Schulhof
committed
Dec 6, 2018
1 parent
c991280
commit 005cbc9
Showing
12 changed files
with
154 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#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<void*>(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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.