Convert mju_error and mju_warning to variadic functions, supporting printf-like arguments. The functions mju_error_i, mju_error_s, mju_warning_i, and mju_warning_s are now deprecated.

PiperOrigin-RevId: 515431052
Change-Id: I440de0cb417ce216b6d636a5d86dc9ef6cc1fc06
This commit is contained in:
Kyle Bayes
2023-03-09 13:50:39 -08:00
committed by Copybara-Service
parent 2e6a37e8c5
commit d3d789cf7d
33 changed files with 177 additions and 184 deletions
+14 -6
View File
@@ -47,6 +47,14 @@ extern "C" {
#define mjDISABLED(x) (m->opt.disableflags & (x))
#define mjENABLED(x) (m->opt.enableflags & (x))
#ifndef mjPRINTFLIKE
#if defined(__GNUC__)
#define mjPRINTFLIKE(n, m) __attribute__((format(printf, n, m)))
#else
#define mjPRINTFLIKE(n, m)
#endif // __GNUC__
#endif // mjPRINTFLIKE
// user error and memory handlers
MJAPI extern void (*mju_user_error)(const char*);
@@ -730,21 +738,21 @@ MJAPI void mjui_render(mjUI* ui, const mjuiState* state, const mjrContext* con);
//---------------------------------- Error and memory ----------------------------------------------
// Main error function; does not return to caller.
MJAPI void mju_error(const char* msg);
MJAPI void mju_error(const char* msg, ...) mjPRINTFLIKE(1, 2);
// Error function with int argument; msg is a printf format string.
// Deprecated: use mju_error
MJAPI void mju_error_i(const char* msg, int i);
// Error function with string argument.
// Deprecated: use mju_error
MJAPI void mju_error_s(const char* msg, const char* text);
// Main warning function; returns to caller.
MJAPI void mju_warning(const char* msg);
MJAPI void mju_warning(const char* msg, ...) mjPRINTFLIKE(1, 2);
// Warning function with int argument.
// Deprecated: use mju_warning
MJAPI void mju_warning_i(const char* msg, int i);
// Warning function with string argument.
// Deprecated: use_mju_warning
MJAPI void mju_warning_s(const char* msg, const char* text);
// Clear user error and memory handlers.