Rename LoadLibrary to avoid conflict with Windows macros

PiperOrigin-RevId: 324939413
Change-Id: I2ad9f90c302f56ba4dfe847da44f9cd104457fbd
This commit is contained in:
A. Unique TensorFlower 2020-08-04 19:20:06 -07:00 committed by TensorFlower Gardener
parent eaa5235e00
commit 77ee5e0272
15 changed files with 27 additions and 27 deletions

View File

@ -213,7 +213,6 @@ void TF_Reset(const TF_SessionOptions* opt, const char** containers,
namespace tensorflow { namespace tensorflow {
Status MessageToBuffer(const tensorflow::protobuf::MessageLite& in, Status MessageToBuffer(const tensorflow::protobuf::MessageLite& in,
TF_Buffer* out) { TF_Buffer* out) {
if (out->data != nullptr) { if (out->data != nullptr) {
@ -306,7 +305,7 @@ void TF_GraphSetOutputHandleShapesAndTypes(TF_Graph* graph, TF_Output output,
} }
// Helpers for loading a TensorFlow plugin (a .so file). // Helpers for loading a TensorFlow plugin (a .so file).
Status LoadLibrary(const char* library_filename, void** result, Status LoadDynamicLibrary(const char* library_filename, void** result,
const void** buf, size_t* len); const void** buf, size_t* len);
// TODO(josh11b,mrry): Change Session to be able to use a Graph* // TODO(josh11b,mrry): Change Session to be able to use a Graph*
@ -552,7 +551,7 @@ void TF_PRun(TF_DeprecatedSession* s, const char* handle,
TF_Library* TF_LoadLibrary(const char* library_filename, TF_Status* status) { TF_Library* TF_LoadLibrary(const char* library_filename, TF_Status* status) {
TF_Library* lib_handle = new TF_Library; TF_Library* lib_handle = new TF_Library;
status->status = tensorflow::LoadLibrary( status->status = tensorflow::LoadDynamicLibrary(
library_filename, &lib_handle->lib_handle, &lib_handle->op_list.data, library_filename, &lib_handle->lib_handle, &lib_handle->op_list.data,
&lib_handle->op_list.length); &lib_handle->op_list.length);
if (!status->status.ok()) { if (!status->status.ok()) {

View File

@ -191,8 +191,8 @@ void* TF_LoadSharedLibrary(const char* library_filename, TF_Status* status) {
void* handle = nullptr; void* handle = nullptr;
TF_SetStatus(status, TF_OK, ""); TF_SetStatus(status, TF_OK, "");
::tensorflow::Set_TF_Status_from_Status( ::tensorflow::Set_TF_Status_from_Status(
status, status, ::tensorflow::Env::Default()->LoadDynamicLibrary(library_filename,
::tensorflow::Env::Default()->LoadLibrary(library_filename, &handle)); &handle));
return handle; return handle;
} }

View File

@ -462,7 +462,7 @@ Status RegisterFilesystemPlugin(const std::string& dso_path) {
// Step 1: Load plugin // Step 1: Load plugin
Env* env = Env::Default(); Env* env = Env::Default();
void* dso_handle; void* dso_handle;
TF_RETURN_IF_ERROR(env->LoadLibrary(dso_path.c_str(), &dso_handle)); TF_RETURN_IF_ERROR(env->LoadDynamicLibrary(dso_path.c_str(), &dso_handle));
// Step 2: Load symbol for `TF_InitPlugin` // Step 2: Load symbol for `TF_InitPlugin`
void* dso_symbol; void* dso_symbol;

View File

@ -33,7 +33,6 @@ limitations under the License.
// Windows defines the following macros to convert foo to fooA or fooW, // Windows defines the following macros to convert foo to fooA or fooW,
// depending on the type of the string argument. We don't use these macros, so // depending on the type of the string argument. We don't use these macros, so
// undefine them here. // undefine them here.
#undef LoadLibrary
#undef CopyFile #undef CopyFile
#undef DeleteFile #undef DeleteFile
#undef TranslateName #undef TranslateName

View File

@ -43,7 +43,7 @@ struct Library {
// and OpList. Ops and kernels are registered as globals when a library is // and OpList. Ops and kernels are registered as globals when a library is
// loaded for the first time. Without caching, every subsequent load would not // loaded for the first time. Without caching, every subsequent load would not
// perform initialization again, so the OpList would be empty. // perform initialization again, so the OpList would be empty.
Status LoadLibrary(const char* library_filename, void** result, Status LoadDynamicLibrary(const char* library_filename, void** result,
const void** buf, size_t* len) { const void** buf, size_t* len) {
static mutex mu(LINKER_INITIALIZED); static mutex mu(LINKER_INITIALIZED);
static std::unordered_map<string, Library> loaded_libs; static std::unordered_map<string, Library> loaded_libs;
@ -76,7 +76,7 @@ Status LoadLibrary(const char* library_filename, void** result,
return s; return s;
})); }));
OpRegistry::Global()->DeferRegistrations(); OpRegistry::Global()->DeferRegistrations();
s = env->LoadLibrary(library_filename, &library.handle); s = env->LoadDynamicLibrary(library_filename, &library.handle);
if (s.ok()) { if (s.ok()) {
s = OpRegistry::Global()->ProcessRegistrations(); s = OpRegistry::Global()->ProcessRegistrations();
} }

View File

@ -1211,7 +1211,8 @@ void LoadDynamicKernelsInternal() {
if (s.ok() || override_abi_check) { if (s.ok() || override_abi_check) {
// TODO(gunan): Store the handles to the opened files. // TODO(gunan): Store the handles to the opened files.
void* unused_filehandle; void* unused_filehandle;
TF_CHECK_OK(env->LoadLibrary(fullpath.c_str(), &unused_filehandle)); TF_CHECK_OK(
env->LoadDynamicLibrary(fullpath.c_str(), &unused_filehandle));
} else { } else {
LOG(WARNING) << "Not loading plugin library " << fullpath << ": " LOG(WARNING) << "Not loading plugin library " << fullpath << ": "
<< s.error_message(); << s.error_message();

View File

@ -185,8 +185,9 @@ class PosixEnv : public Env {
}); });
} }
Status LoadLibrary(const char* library_filename, void** handle) override { Status LoadDynamicLibrary(const char* library_filename,
return tensorflow::internal::LoadLibrary(library_filename, handle); void** handle) override {
return tensorflow::internal::LoadDynamicLibrary(library_filename, handle);
} }
Status GetSymbolFromLibrary(void* handle, const char* symbol_name, Status GetSymbolFromLibrary(void* handle, const char* symbol_name,

View File

@ -23,7 +23,7 @@ namespace tensorflow {
namespace internal { namespace internal {
Status LoadLibrary(const char* library_filename, void** handle) { Status LoadDynamicLibrary(const char* library_filename, void** handle) {
*handle = dlopen(library_filename, RTLD_NOW | RTLD_LOCAL); *handle = dlopen(library_filename, RTLD_NOW | RTLD_LOCAL);
if (!*handle) { if (!*handle) {
return errors::NotFound(dlerror()); return errors::NotFound(dlerror());

View File

@ -334,7 +334,8 @@ class Env {
// OK from the function. // OK from the function.
// Otherwise returns nullptr in "*handle" and an error status from the // Otherwise returns nullptr in "*handle" and an error status from the
// function. // function.
virtual Status LoadLibrary(const char* library_filename, void** handle) = 0; virtual Status LoadDynamicLibrary(const char* library_filename,
void** handle) = 0;
// \brief Get a pointer to a symbol from a dynamic library. // \brief Get a pointer to a symbol from a dynamic library.
// //
@ -411,8 +412,9 @@ class EnvWrapper : public Env {
void SchedClosureAfter(int64 micros, std::function<void()> closure) override { void SchedClosureAfter(int64 micros, std::function<void()> closure) override {
target_->SchedClosureAfter(micros, closure); target_->SchedClosureAfter(micros, closure);
} }
Status LoadLibrary(const char* library_filename, void** handle) override { Status LoadDynamicLibrary(const char* library_filename,
return target_->LoadLibrary(library_filename, handle); void** handle) override {
return target_->LoadDynamicLibrary(library_filename, handle);
} }
Status GetSymbolFromLibrary(void* handle, const char* symbol_name, Status GetSymbolFromLibrary(void* handle, const char* symbol_name,
void** symbol) override { void** symbol) override {

View File

@ -70,7 +70,7 @@ class LibHDFS {
private: private:
void LoadAndBind() { void LoadAndBind() {
auto TryLoadAndBind = [this](const char* name, void** handle) -> Status { auto TryLoadAndBind = [this](const char* name, void** handle) -> Status {
TF_RETURN_IF_ERROR(Env::Default()->LoadLibrary(name, handle)); TF_RETURN_IF_ERROR(Env::Default()->LoadDynamicLibrary(name, handle));
#define BIND_HDFS_FUNC(function) \ #define BIND_HDFS_FUNC(function) \
TF_RETURN_IF_ERROR(BindFunc(*handle, #function, &function)); TF_RETURN_IF_ERROR(BindFunc(*handle, #function, &function));

View File

@ -22,7 +22,7 @@ namespace tensorflow {
namespace internal { namespace internal {
Status LoadLibrary(const char* library_filename, void** handle); Status LoadDynamicLibrary(const char* library_filename, void** handle);
Status GetSymbolFromLibrary(void* handle, const char* symbol_name, Status GetSymbolFromLibrary(void* handle, const char* symbol_name,
void** symbol); void** symbol);
string FormatLibraryFileName(const string& name, const string& version); string FormatLibraryFileName(const string& name, const string& version);

View File

@ -22,7 +22,6 @@ limitations under the License.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#undef LoadLibrary
#undef ERROR #undef ERROR
#include <string> #include <string>
@ -156,8 +155,9 @@ class WindowsEnv : public Env {
SetThreadpoolTimer(timer, &FileDueTime, 0, 0); SetThreadpoolTimer(timer, &FileDueTime, 0, 0);
} }
Status LoadLibrary(const char* library_filename, void** handle) override { Status LoadDynamicLibrary(const char* library_filename,
return tensorflow::internal::LoadLibrary(library_filename, handle); void** handle) override {
return tensorflow::internal::LoadDynamicLibrary(library_filename, handle);
} }
Status GetSymbolFromLibrary(void* handle, const char* symbol_name, Status GetSymbolFromLibrary(void* handle, const char* symbol_name,

View File

@ -22,7 +22,6 @@ limitations under the License.
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <windows.h> #include <windows.h>
#undef LoadLibrary
#undef ERROR #undef ERROR
#include "tensorflow/core/platform/errors.h" #include "tensorflow/core/platform/errors.h"
@ -34,7 +33,7 @@ namespace tensorflow {
namespace internal { namespace internal {
Status LoadLibrary(const char* library_filename, void** handle) { Status LoadDynamicLibrary(const char* library_filename, void** handle) {
string file_name = library_filename; string file_name = library_filename;
std::replace(file_name.begin(), file_name.end(), '/', '\\'); std::replace(file_name.begin(), file_name.end(), '/', '\\');

View File

@ -43,7 +43,7 @@ port::StatusOr<void*> GetDsoHandle(const string& name, const string& version) {
auto filename = port::Env::Default()->FormatLibraryFileName(name, version); auto filename = port::Env::Default()->FormatLibraryFileName(name, version);
void* dso_handle; void* dso_handle;
port::Status status = port::Status status =
port::Env::Default()->LoadLibrary(filename.c_str(), &dso_handle); port::Env::Default()->LoadDynamicLibrary(filename.c_str(), &dso_handle);
if (status.ok()) { if (status.ok()) {
LOG(INFO) << "Successfully opened dynamic library " << filename; LOG(INFO) << "Successfully opened dynamic library " << filename;
return dso_handle; return dso_handle;

View File

@ -11,5 +11,4 @@ inline void sleep(unsigned int seconds) { Sleep(1000*seconds); }
// prevent clashes. // prevent clashes.
#undef DeleteFile #undef DeleteFile
#undef ERROR #undef ERROR
#undef LoadLibrary
#endif // _WIN32 #endif // _WIN32