Skip to content

Commit

Permalink
reduce to simple static
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Jul 25, 2023
1 parent 7caf21e commit eb00d0f
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions torchaudio/csrc/sox/stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class StubImpl {
StubImpl(const char* name) : handle(name) {
// check version: we only support 14.4.2
{
auto version = ((const char* (*)(void))handle.sym("sox_version"))();
TORCH_CHECK(
strcmp(version, "14.4.2") == 0,
"Need libsox 14.4.2, but found ",
version);
auto f = (const sox_version_info_t* (*)())handle.sym("sox_version_info");
if (SOX_LIB_VERSION_CODE != f()->version_code) {
auto ver = ((const char* (*)())handle.sym("sox_version"))();
TORCH_CHECK(false, "Need libsox 14.4.2, but found ", ver);
}
}

// Register fanction pointers on public-facing interface
Expand Down Expand Up @@ -60,24 +60,18 @@ class StubImpl {
}
}
};

static std::unique_ptr<StubImpl> _stub;

} // namespace

#if defined(_WIN32)
#define EXT ".lib"
#define EXT "lib"
#elif defined(__APPLE__)
#define EXT ".dylib"
#define EXT "dylib"
#else
#define EXT ".so"
#define EXT "so"
#endif
LibSoxStub& libsox_stub() {
static c10::once_flag init_flag;
c10::call_once(init_flag, [](){
_stub = std::make_unique<StubImpl>("libsox" EXT);
});
return _stub->stub;
static StubImpl s{"libsox." EXT};
return s.stub;
}
#undef EXT

Expand Down

0 comments on commit eb00d0f

Please sign in to comment.