mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: move DeleteFnPtr into util.h
This is more generally useful than just in a crypto context. PR-URL: https://github.com/nodejs/node/pull/20885 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
1 parent
45adec2616
commit
b4519cac20
2 files changed
+9
-9
No files matched your search
@@ -75,15 +75,6 @@ struct MarkPopErrorOnReturn {
|
||||
~MarkPopErrorOnReturn() { ERR_pop_to_mark(); }
|
||||
};
|
||||
|
||||
template <typename T, void (*function)(T*)>
|
||||
struct FunctionDeleter {
|
||||
void operator()(T* pointer) const { function(pointer); }
|
||||
typedef std::unique_ptr<T, FunctionDeleter> Pointer;
|
||||
};
|
||||
|
||||
template <typename T, void (*function)(T*)>
|
||||
using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
|
||||
|
||||
// Define smart pointers for the most commonly used OpenSSL types:
|
||||
using X509Pointer = DeleteFnPtr<X509, X509_free>;
|
||||
using BIOPointer = DeleteFnPtr<BIO, BIO_free_all>;
|
||||
|
||||
@@ -456,6 +456,15 @@ struct is_callable<T, typename std::enable_if<
|
||||
std::is_same<decltype(void(&T::operator())), void>::value
|
||||
>::type> : std::true_type { };
|
||||
|
||||
template <typename T, void (*function)(T*)>
|
||||
struct FunctionDeleter {
|
||||
void operator()(T* pointer) const { function(pointer); }
|
||||
typedef std::unique_ptr<T, FunctionDeleter> Pointer;
|
||||
};
|
||||
|
||||
template <typename T, void (*function)(T*)>
|
||||
using DeleteFnPtr = typename FunctionDeleter<T, function>::Pointer;
|
||||
|
||||
} // namespace node
|
||||
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
|
||||
Reference in new issue
Block a user