[PATCH 4/4] Explicitly type void* pointers
Austin Clements
amdragon at MIT.EDU
Wed Apr 11 14:11:13 PDT 2012
On Mon, 09 Apr 2012, Jani Nikula <jani at nikula.org> wrote:
> Vladimir Marek <Vladimir.Marek at Oracle.COM> writes:
> I'm throwing in a third alternative below. Does it work for you? I think
> it's both prettier and uglier than the above at the same time! ;)
>
> A middle ground would be to change the callers to use
> "notmuch_talloc_steal", and just #define notmuch_talloc_steal
> talloc_steal if __GNUC__ >= 3.
>
> One could argue upstream talloc should have this, but OTOH it's a C
> library.
>
> BR,
> Jani.
>
>
> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
> index ea836f7..83b46e8 100644
> --- a/lib/notmuch-private.h
> +++ b/lib/notmuch-private.h
> @@ -499,4 +499,22 @@ _notmuch_filenames_create (const void *ctx,
>
> NOTMUCH_END_DECLS
>
> +#ifdef __cplusplus
> +/* Implicit typecast from 'void *' to 'T *' is okay in C, but not in
> + * C++. In talloc_steal, an explicit cast is provided for type safety
> + * in some GCC versions. Otherwise, a cast is required. Provide a
> + * template function for this to maintain type safety, and redefine
> + * talloc_steal to use it.
> + */
> +#if !(__GNUC__ >= 3)
> +template <class T>
> +T *notmuch_talloc_steal(const void *new_ctx, const T *ptr)
> +{
> + return static_cast<T*>(talloc_steal(new_ctx, ptr));
> +}
> +#undef talloc_steal
> +#define talloc_steal notmuch_talloc_steal
> +#endif
> +#endif
> +
> #endif
This looks good to me. I was originally concerned that this depended on
talloc_steal being a macro, but I realized that's not actually the case.
Care to roll a real patch?
More information about the notmuch
mailing list