internals: Make a minimal _dbus_test_oom_handling() universally available
authorSimon McVittie <smcv@collabora.com>
Tue, 4 Jul 2017 17:05:53 +0000 (18:05 +0100)
committerSimon McVittie <smcv@collabora.com>
Wed, 5 Jul 2017 12:13:40 +0000 (13:13 +0100)
Previously, it was only available under DBUS_ENABLE_EMBEDDED_TESTS,
because the infrastructure to pretend malloc had failed is only
compiled then. However, I'd like to use it in more modular tests, to
avoid test-dbus continuing to grow. To facilitate that, inline a
trivial version of it when DBUS_ENABLE_EMBEDDED_TESTS is disabled:
it just calls the function, once, without doing any strange things to
the malloc interface.

Similarly, amend the stub implementation of
_dbus_get_malloc_blocks_outstanding() so that references to it are
syntactically valid, and move the DBusTestMemoryFunction typedef so
that it can be used with or without DBUS_ENABLE_EMBEDDED_TESTS.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101568

dbus/dbus-internals.h

index 4af106e..e7649e1 100644 (file)
@@ -301,6 +301,8 @@ void _dbus_set_error_valist (DBusError  *error,
                              const char *format,
                              va_list     args) _DBUS_GNUC_PRINTF (3, 0);
 
+typedef dbus_bool_t (* DBusTestMemoryFunction)  (void *data);
+
 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
 /* Memory debugging */
 void        _dbus_set_fail_alloc_counter        (int  until_next_fail);
@@ -312,7 +314,6 @@ dbus_bool_t _dbus_disable_mem_pools             (void);
 DBUS_PRIVATE_EXPORT
 int         _dbus_get_malloc_blocks_outstanding (void);
 
-typedef dbus_bool_t (* DBusTestMemoryFunction)  (void *data);
 DBUS_PRIVATE_EXPORT
 dbus_bool_t _dbus_test_oom_handling (const char             *description,
                                      DBusTestMemoryFunction  func,
@@ -326,7 +327,9 @@ dbus_bool_t _dbus_test_oom_handling (const char             *description,
  */
 #define _dbus_decrement_fail_alloc_counter() (FALSE)
 #define _dbus_disable_mem_pools()            (FALSE)
-#define _dbus_get_malloc_blocks_outstanding  (0)
+#define _dbus_get_malloc_blocks_outstanding() (0)
+
+#define _dbus_test_oom_handling(description, func, data) ((*func) (data))
 #endif /* !DBUS_ENABLE_EMBEDDED_TESTS */
 
 typedef void (* DBusShutdownFunction) (void *data);