Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 576102148
Change-Id: I75fadec5f4323682c599a8582be5ecfc7ea5ad84
  • Loading branch information
josechenf authored and copybara-github committed Oct 24, 2023
1 parent d36d2c5 commit dc8e438
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cpp/controllers_py/pybind_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const MjLib* LoadMjLibFromDmControlDynamically() {

const MjLib* LoadMjLibFromDmControl() {
py::gil_scoped_acquire gil;
return LoadMjLibFromDmControlDynamically();
return LoadMjLibFromDmControlStatically(); // Copybara changes to dynamic.
}

// Helper function for getting an mjModel object from a py::handle.
Expand Down
10 changes: 5 additions & 5 deletions cpp/mujoco/include/dm_robotics/mujoco/mjlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include <string>

// MuJoCo headers must be included in the same order as "mujoco.h".
#include "mujoco/mjdata.h" //NOLINT
#include "mujoco/mjmodel.h" //NOLINT
#include "mujoco/mjrender.h" //NOLINT
#include "mujoco/mjui.h" //NOLINT
#include "mujoco/mjvisualize.h" //NOLINT
#include <mujoco/mjdata.h> //NOLINT
#include <mujoco/mjmodel.h> //NOLINT
#include <mujoco/mjrender.h> //NOLINT
#include <mujoco/mjui.h> //NOLINT
#include <mujoco/mjvisualize.h> //NOLINT

namespace dm_robotics {

Expand Down
8 changes: 4 additions & 4 deletions cpp/mujoco/src/mjlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ using LibMujocoHandle = std::unique_ptr<void, LibMujocoHandleDeleter>;
LibMujocoHandle OpenImpl(const char *path, int dlopen_flags) {
dlerror(); // Clear error state before calling dlopen.
void* handle = dlopen(path, dlopen_flags);
CHECK(handle != nullptr) << "dlopen '" << path << "' failed: " << dlerror();
CHECK_NE(handle, nullptr) << "dlopen '" << path << "' failed: " << dlerror();

// Ensure we close the library with dlclose:
LibMujocoHandle handle_with_close(handle);
Expand All @@ -49,7 +49,7 @@ LibMujocoHandle OpenImpl(const char *path, int dlopen_flags) {
}

LibMujocoHandle DlOpen(const std::string& path, int dlopen_flags) {
return OpenImpl(path.c_str(), dlopen_flags);
return OpenImpl(nullptr, RTLD_NOW); // Changed by Copybara.
}

} // namespace
Expand All @@ -63,14 +63,14 @@ struct MjLib::Impl {
// We terminate the program if any of the symbol handles are null.
#define INIT_WITH_DLSYM(name) \
name(decltype(name)( \
DieIfNull(dlsym(pimpl_->libmujoco_handle.get(), #name))))
ABSL_DIE_IF_NULL(dlsym(pimpl_->libmujoco_handle.get(), #name))))

#define INIT_WITH_DLSYM_NULLABLE(name) \
name(decltype(name)(dlsym(pimpl_->libmujoco_handle.get(), #name)))

#define INIT_CALLBACK_WITH_DLSYM(name) \
name(*(decltype(&name))( \
DieIfNull(dlsym(pimpl_->libmujoco_handle.get(), #name))))
ABSL_DIE_IF_NULL(dlsym(pimpl_->libmujoco_handle.get(), #name))))

MjLib::MjLib(const std::string& libmujoco_path, int dlopen_flags)
: pimpl_(absl::make_unique<Impl>(libmujoco_path, dlopen_flags)),
Expand Down
4 changes: 3 additions & 1 deletion cpp/mujoco/src/test_with_mjlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ namespace dm_robotics::testing {
MjLib* TestWithMjLib::mjlib_ = nullptr;

void TestWithMjLib::SetUpTestSuite() {
mjlib_ = new MjLib(kMujocoLibNoGlPath, RTLD_NOW); // Load MuJoCo.
mjlib_ = new MjLib(
file::JoinPath(absl::GetFlag(FLAGS_test_srcdir), kMujocoLibNoGlPath),
RTLD_NOW);
}

void TestWithMjLib::TearDownTestSuite() {
Expand Down

0 comments on commit dc8e438

Please sign in to comment.