Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion cpp/src/arrow/dataset/file_parquet_encryption_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "arrow/util/thread_pool.h"
#include "parquet/arrow/reader.h"
#include "parquet/encryption/crypto_factory.h"
#include "parquet/encryption/encryption_internal.h"
#include "parquet/encryption/encryption_utils.h"
#include "parquet/encryption/kms_client.h"
#include "parquet/encryption/test_in_memory_kms.h"

Expand Down
20 changes: 20 additions & 0 deletions cpp/src/arrow/util/io_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2296,4 +2296,24 @@ Result<void*> GetSymbol(void* handle, const char* name) {
#endif
}

Status CloseDynamicLibrary(void* handle) {
if (handle == nullptr) {
return Status::Invalid("Attempting to close null library handle");
}
#ifdef _WIN32
if (FreeLibrary(reinterpret_cast<HMODULE>(handle))) {
return Status::OK();
}
// win32 api doc: "If the function fails, the return value is zero."
return IOErrorFromWinError(GetLastError(), "FreeLibrary() failed");
#else
if (dlclose(handle) == 0) {
return Status::OK();
}
// dlclose(3) man page: "On success, dlclose() returns 0; on error, it returns a nonzero value."
auto* error = dlerror();
return Status::IOError("dlclose() failed: ", error ? error : "unknown error");
#endif
}

} // namespace arrow::internal
7 changes: 7 additions & 0 deletions cpp/src/arrow/util/io_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,13 @@ ARROW_EXPORT Result<void*> LoadDynamicLibrary(const char* path);
/// returned; instead an error will be raised.
ARROW_EXPORT Result<void*> GetSymbol(void* handle, const char* name);

/// \brief Close a dynamic library
///
/// This wraps dlclose() except on Windows, where FreeLibrary() is called.
///
/// \return Status::OK() if the library was closed successfully, otherwise an error is returned.
ARROW_EXPORT Status CloseDynamicLibrary(void* handle);

template <typename T>
Result<T*> GetSymbolAs(void* handle, const char* name) {
ARROW_ASSIGN_OR_RAISE(void* sym, GetSymbol(handle, name));
Expand Down
Loading
Loading