unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
To: Jani Nikula <jani@nikula.org>
Cc: Notmuch Mail <notmuch@notmuchmail.org>
Subject: Re: [PATCH 4/4] Explicitly type void* pointers
Date: Thu, 12 Apr 2012 13:57:29 -0400	[thread overview]
Message-ID: <20120412175729.GH13549@mit.edu> (raw)
In-Reply-To: <87aa2hxtrv.fsf@nikula.org>

Quoth Jani Nikula on Apr 12 at  8:02 am:
> On Wed, 11 Apr 2012 17:11:13 -0400, Austin Clements <amdragon@MIT.EDU> wrote:
> > On Mon, 09 Apr 2012, Jani Nikula <jani@nikula.org> wrote:
> > > Vladimir Marek <Vladimir.Marek@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?
> 
> Sure.
> 
> One question: the template must be outside NOTMUCH_{BEGIN,END}_DECLS
> (which are just macros for extern "C" block) but should it be within the
> #pragma GCC visibility push(hidden) and pop directives? I'm not familiar
> with that.

Hmm.  I'm not sure, but it can't hurt to have it inside the visibility
directives.  My guess would be that it will affect the visibility of
the symbols produced when the template is instantiated, which we don't
want to be visible outside the library.  (As long as that doesn't mess
up the linker's handling of weak symbols.)

> Thanks for the review.
> 
> 
> BR,
> Jani.

  reply	other threads:[~2012-04-12 17:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-09 10:17 notmuch on Solaris Vladimir.Marek
2012-04-09 10:17 ` [PATCH 1/4] Make configure use /bin/bash instead of /bin/sh Vladimir.Marek
2012-04-09 11:10   ` Jani Nikula
2012-04-09 12:19     ` Vladimir Marek
2012-04-10 17:26       ` Tomi Ollila
2012-04-11  8:43         ` Vladimir Marek
2012-04-11 18:47           ` Tomi Ollila
2012-04-30 11:58   ` David Bremner
2012-04-30 12:09     ` Tomi Ollila
2012-04-09 10:17 ` [PATCH 2/4] dirent->d_type not available on Soalris Vladimir.Marek
2012-04-09 11:17   ` Jani Nikula
2012-04-09 15:12     ` Vladimir Marek
2012-04-09 15:46       ` Adam Wolfe Gordon
2012-04-09 16:32         ` Vladimir.Marek
2012-04-11 18:57           ` Tomi Ollila
2012-04-11 19:36           ` Austin Clements
2012-04-09 10:17 ` [PATCH 3/4] Private strsep implementation Vladimir.Marek
2012-10-15  5:05   ` Ethan Glasser-Camp
2012-04-09 10:17 ` [PATCH 4/4] Explicitly type void* pointers Vladimir.Marek
2012-04-09 11:04   ` Jani Nikula
2012-04-09 18:15     ` Vladimir Marek
2012-04-09 21:31       ` Jani Nikula
2012-04-10  6:53         ` Vladimir Marek
2012-04-11 21:11         ` Austin Clements
2012-04-12  8:02           ` Jani Nikula
2012-04-12 17:57             ` Austin Clements [this message]
2012-04-15 21:05   ` Jani Nikula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120412175729.GH13549@mit.edu \
    --to=amdragon@mit.edu \
    --cc=jani@nikula.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).