Re: [PATCH 6/7] Protect 'orig_len' in |recover_unused_bytes| by DBUS_ENABLE_VERBOSE_MODE
Thomas Zimmermann <[email protected]>
| Newsgroups | gmane.comp.freedesktop.dbus |
|---|---|
| Message-ID | <[email protected]> |
Hi!
Some thoughts on this problem: with gcc, one can do something like this:
#ifndef DEBUG
__dbus_assert (condition)
do {
__typeof (!(condition)) val __attribute__((__unused__));
} while (0)
#else
// do debug
#endif
This should use the type of 'condition' without evaluating it. The
declared variable itself is unused. Unfortunately I don't know how to do
this with _dbus_verbose's VA args.
Maybe additional annotation can be used, like
#define DEBUG_OR(expression, default_value) \
(DEBUG ? expression : default_value)
and called like this:
my_debug_value = DEBUG_OR(compute_val(), 0);
Here DEBUG is evaluated by the C compiler, so compute_val() doesn't have
to protected by DEBUG-based preprocessor guards.
Best regards
Thomas
Am 15.08.2016 um 13:17 schrieb Simon McVittie:
> On 10/08/16 16:08, Thiago Macieira wrote:
>> One way I've solved this problem is to "use" the expression in even disabled
>> asserts
>
> That results in the expression's side-effects still happening: for
> instance if it calls a function, we pay the CPU cost of calling that
> function. I don't think we want that here.
>
--
GnuPG: http://tdz.users.sourceforge.net/tdz.asc
Fingerprint: 16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08
_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
signature.asc
(application/pgp-signature, 181 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlex5AYACgkQ2drX1E7x3wivYwCfdwijcs8ZFuzITBoH8sH2TEZe DY8An0jb3fuUByudW/pdD16QoPyT7ia6 =4Q2X -----END PGP SIGNATURE-----