|
| 1 | +// Copyright 2023 DeepMind Technologies Limited |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef MUJOCO_MJMACRO_H_ |
| 16 | +#define MUJOCO_MJMACRO_H_ |
| 17 | + |
| 18 | +// include asan interface header, or provide stubs for poison/unpoison macros when not using asan |
| 19 | +#ifdef ADDRESS_SANITIZER |
| 20 | + #include <sanitizer/asan_interface.h> |
| 21 | +#elif defined(_MSC_VER) |
| 22 | + #define ASAN_POISON_MEMORY_REGION(addr, size) |
| 23 | + #define ASAN_UNPOISON_MEMORY_REGION(addr, size) |
| 24 | +#else |
| 25 | + #define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) |
| 26 | + #define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) |
| 27 | +#endif |
| 28 | + |
| 29 | +// max and min (use only for primitive types) |
| 30 | +#define mjMAX(a, b) (((a) > (b)) ? (a) : (b)) |
| 31 | +#define mjMIN(a, b) (((a) < (b)) ? (a) : (b)) |
| 32 | + |
| 33 | +// return current value of mjOption enable/disable flags |
| 34 | +#define mjDISABLED(x) (m->opt.disableflags & (x)) |
| 35 | +#define mjENABLED(x) (m->opt.enableflags & (x)) |
| 36 | + |
| 37 | +// is actuator disabled |
| 38 | +#define mjACTUATORDISABLED(i) (m->opt.disableactuator & (1 << m->actuator_group[i])) |
| 39 | + |
| 40 | +// annotation for functions that accept printf-like variadic arguments |
| 41 | +#ifndef mjPRINTFLIKE |
| 42 | + #if defined(__GNUC__) |
| 43 | + #define mjPRINTFLIKE(n, m) __attribute__((format(printf, n, m))) |
| 44 | + #else |
| 45 | + #define mjPRINTFLIKE(n, m) |
| 46 | + #endif |
| 47 | +#endif |
| 48 | + |
| 49 | +#endif // MUJOCO_MJMACRO_H_ |
0 commit comments