Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove varargs from g_assert and g_assert_not_reachable (save 200+ bytes per frame in wasm interp). #17254

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions mono/eglib/glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
void g_log (const gchar *log_domain, GLogLevelFlags log_level, const gchar *format, ...);
G_EXTERN_C // Used by MonoPosixHelper or MonoSupportW, at least.
void g_assertion_message (const gchar *format, ...) G_GNUC_NORETURN;
void mono_assertion_message_disabled (const char *file, int line) G_GNUC_NORETURN;
void mono_assertion_message (const char *file, int line, const char *condition) G_GNUC_NORETURN;
void mono_assertion_message_unreachable (const char *file, int line) G_GNUC_NORETURN;
const char * g_get_assertion_message (void);

#ifdef HAVE_C99_SUPPORT
Expand Down Expand Up @@ -930,9 +933,10 @@ GUnicodeBreakType g_unichar_break_type (gunichar c);

/* g_assert is a boolean expression; the precise value is not preserved, just true or false. */
#ifdef DISABLE_ASSERT_MESSAGES
#define g_assert(x) (G_LIKELY((x)) ? 1 : (g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, "<disabled>"), 0))
// This is smaller than the equivalent mono_assertion_message (..."disabled");
#define g_assert(x) (G_LIKELY((x)) ? 1 : (mono_assertion_message_disabled (__FILE__, __LINE__), 0))
#else
#define g_assert(x) (G_LIKELY((x)) ? 1 : (g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", __FILE__, __LINE__, #x), 0))
#define g_assert(x) (G_LIKELY((x)) ? 1 : (mono_assertion_message (__FILE__, __LINE__, #x), 0))
#endif

#ifdef __cplusplus
Expand All @@ -941,7 +945,7 @@ GUnicodeBreakType g_unichar_break_type (gunichar c);
#define g_static_assert(x) g_assert (x)
#endif

#define g_assert_not_reached() G_STMT_START { g_assertion_message ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__); eg_unreachable(); } G_STMT_END
#define g_assert_not_reached() G_STMT_START { mono_assertion_message_unreachable (__FILE__, __LINE__); eg_unreachable(); } G_STMT_END

/* f is format -- like printf and scanf
* Where you might have said:
Expand Down
24 changes: 24 additions & 0 deletions mono/eglib/goutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,30 @@ g_assertion_message (const gchar *format, ...)
exit (0);
}

// Emscriptem emulates varargs, and fails to stack pack multiple outgoing varargs areas,
// so this function serves to remove varargs in its caller and conserve stack.
void
mono_assertion_message_disabled (const char *file, int line)
{
mono_assertion_message (file, line, "<disabled>");
}

// Emscriptem emulates varargs, and fails to stack pack multiple outgoing varargs areas,
// so this function serves to remove varargs in its caller and conserve stack.
void
mono_assertion_message (const char *file, int line, const char *condition)
{
g_assertion_message ("* Assertion at %s:%d, condition `%s' not met\n", file, line, condition);
}

// Emscriptem emulates varargs, and fails to stack pack multiple outgoing varargs areas,
// so this function serves to remove varargs in its caller and conserve stack.
void
mono_assertion_message_unreachable (const char *file, int line)
{
g_assertion_message ("* Assertion: should not be reached at %s:%d\n", __FILE__, __LINE__);
}

#if HOST_ANDROID
#include <android/log.h>

Expand Down