You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Daniel Shahaf <d....@daniel.shahaf.name> on 2015/03/04 02:22:47 UTC

Re: svn commit: r1663760 - svn_hash_sets() type checking

julianfoad@apache.org wrote on Tue, Mar 03, 2015 at 18:09:32 -0000:
> Author: julianfoad
> Date: Tue Mar  3 18:09:32 2015
> New Revision: 1663760
> 
> URL: http://svn.apache.org/r1663760
> Log:
> Redefine the svn_hash_gets and svn_hash_sets macros in a way that allows for
> parameter type checking, at least in debug builds.
> 
>  /** Shortcut for apr_hash_set() with a const char * key.
>   *
>   * @since New in 1.8.
>   */
> -#define svn_hash_sets(ht, key, val) \
> -            apr_hash_set(ht, key, APR_HASH_KEY_STRING, val)
> +#define svn_hash_sets(ht, key, val)                                         \
> +  do {                                                                      \
> +    const char *svn_hash__key = (key);                                      \
> +    apr_hash_set(ht, svn_hash__key, APR_HASH_KEY_STRING, val);              \
> +  } while (0)

Strictly speaking, that's a backwards-incompatible change.  Since the
new definition is no longer an rvalue, API consumers' code would break
if they used svn_hash_sets() as part of a statement.  Example:

    /* This works with svn 1.8. */
    #include <subversion-1/svn_hash.h>
    #define my_foo() (svn_hash_sets(h, s), 42)

I think we have to either errata this, or restore svn_hash_gets()'
previous definition and name the do-while version svn_hash_gets2().

Makes sense?

Cheers,

Daniel


Re: svn commit: r1663760 - svn_hash_sets() type checking

Posted by Julian Foad <ju...@btopenworld.com>.
Daniel Shahaf wrote:
>>  URL: http://svn.apache.org/r1663760
[...]
>>  -#define svn_hash_sets(ht, key, val) \
>>  -            apr_hash_set(ht, key, APR_HASH_KEY_STRING, val)
>>  +#define svn_hash_sets(ht, key, val)     \
>>  +  do { [...] } while (0)
> 
> Strictly speaking, that's a backwards-incompatible change.  Since the
> new definition is no longer an rvalue, API consumers' code would break
> if they used svn_hash_sets() as part of a statement.  Example:
> 
>     /* This works with svn 1.8. */
>     #include <subversion-1/svn_hash.h>
>     #define my_foo() (svn_hash_sets(h, s), 42)
> 
> I think we have to either errata this, or restore svn_hash_gets()'
> previous definition and name the do-while version svn_hash_gets2().
> 
> Makes sense?

Yes... but a nicer solution would be to define it the same way as I defined *get* (forward through a private function), wouldn't it? That would restore a symmetry that Brane pointed out was surprisingly missing.

r1663896.

- Julian