Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PSA: NS_IMPL_ISUPPORTS and friends are now variadic

114 views
Skip to first unread message

Birunthan Mohanathas

unread,
Apr 28, 2014, 12:18:17 AM4/28/14
to dev-pl...@lists.mozilla.org
Bugs 900903 and 900908 introduced variadic variants of
NS_IMPL_ISUPPORTS, NS_IMPL_QUERY_INTERFACE, NS_IMPL_CYCLE_COLLECTION,
etc. and removed the old numbered macros. So, instead of e.g.
NS_IMPL_ISUPPORTS2(nsFoo, nsIBar, nsIBaz), simply use
NS_IMPL_ISUPPORTS(nsFoo, nsIBar, nsIBaz) instead. Right now, the new
macros support up to 50 variadic arguments.

Note that due to technical details, the new macros will reject uses
with zero variadic arguments. In such cases, you will want to continue
to use the zero-numbered macro, e.g. NS_IMPL_ISUPPORTS0(nsFoo).

Cheers,
Biru

Boris Zbarsky

unread,
Apr 28, 2014, 12:29:17 AM4/28/14
to
On 4/28/14, 12:18 AM, Birunthan Mohanathas wrote:
> Right now, the new macros support up to 50 variadic arguments.

If someone uses more than that, will that fail to compile or silently
ignore the extra args?

-Boris

P.S. I know, the right answer is "they need fewer interfaces"... ;)

Birunthan Mohanathas

unread,
Apr 28, 2014, 12:38:17 AM4/28/14
to Boris Zbarsky, dev-pl...@lists.mozilla.org
On 28 April 2014 07:29, Boris Zbarsky <bzba...@mit.edu> wrote:
> On 4/28/14, 12:18 AM, Birunthan Mohanathas wrote:
>>
>> Right now, the new macros support up to 50 variadic arguments.
>
>
> If someone uses more than that, will that fail to compile or silently ignore
> the extra args?

It will fail to compile.

Justin Dolske

unread,
Apr 28, 2014, 12:45:05 AM4/28/14
to
On 4/27/14 9:18 PM, Birunthan Mohanathas wrote:
> Bugs 900903 and 900908 introduced variadic variants of
> NS_IMPL_ISUPPORTS, NS_IMPL_QUERY_INTERFACE, NS_IMPL_CYCLE_COLLECTION,
> etc. and removed the old numbered macros. So, instead of e.g.
> NS_IMPL_ISUPPORTS2(nsFoo, nsIBar, nsIBaz), simply use
> NS_IMPL_ISUPPORTS(nsFoo, nsIBar, nsIBaz) instead. Right now, the new
> macros support up to 50 variadic arguments.

Woah, awesome!

Justin

Boris Zbarsky

unread,
Apr 28, 2014, 12:45:16 AM4/28/14
to
On 4/28/14, 12:38 AM, Birunthan Mohanathas wrote:
> It will fail to compile.

Excellent!

-Boris

Henri Sivonen

unread,
Apr 28, 2014, 5:07:27 AM4/28/14
to Birunthan Mohanathas, dev-platform
On Mon, Apr 28, 2014 at 7:18 AM, Birunthan Mohanathas
<biru...@mohanathas.com> wrote:
> Bugs 900903 and 900908 introduced variadic variants of
> NS_IMPL_ISUPPORTS, NS_IMPL_QUERY_INTERFACE, NS_IMPL_CYCLE_COLLECTION,
> etc. and removed the old numbered macros.

Cool. Is there a script that rewrites mq patches whose context has
numbered macros to not expect numbered macros?

--
Henri Sivonen
hsiv...@hsivonen.fi
https://hsivonen.fi/

Neil

unread,
Apr 28, 2014, 5:11:48 AM4/28/14
to
Birunthan Mohanathas wrote:

>Note that due to technical details, the new macros will reject uses with zero variadic arguments. In such cases, you will want to continue to use the zero-numbered macro, e.g. NS_IMPL_ISUPPORTS0(nsFoo).
>
>
I can't help wondering who would need to implement only nsISupports. It
can't be for the refcounting, because you can just use inline
refcounting. And you've got no way of telling whether an arbitrary
nsISupports is your object or not.

For example, nsMemoryReporterManager creates an object, hands it out,
and assumes the one it got back was the one it handed out. (I picked
that as an easy example that could technically be written safely using
an nsSupportsPRInt64.)

--
Warning: May contain traces of nuts.

Benoit Jacob

unread,
Apr 28, 2014, 7:18:22 AM4/28/14
to Birunthan Mohanathas, dev-platform
2014-04-28 0:18 GMT-04:00 Birunthan Mohanathas <biru...@mohanathas.com>:

> Bugs 900903 and 900908 introduced variadic variants of
> NS_IMPL_ISUPPORTS, NS_IMPL_QUERY_INTERFACE, NS_IMPL_CYCLE_COLLECTION,
> etc. and removed the old numbered macros. So, instead of e.g.
> NS_IMPL_ISUPPORTS2(nsFoo, nsIBar, nsIBaz), simply use
> NS_IMPL_ISUPPORTS(nsFoo, nsIBar, nsIBaz) instead. Right now, the new
> macros support up to 50 variadic arguments.
>

Awesome, congrats, and thanks!

Question: is there a plan to switch to an implementation based on variadic
templates when we will stop supporting compilers that don't support them?
Do you know when that would be (of the compilers that we currently support,
which ones don't support variadic templates?)

Benoit


>
> Note that due to technical details, the new macros will reject uses
> with zero variadic arguments. In such cases, you will want to continue
> to use the zero-numbered macro, e.g. NS_IMPL_ISUPPORTS0(nsFoo).
>
> Cheers,
> Biru
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>

Mike Hommey

unread,
Apr 28, 2014, 1:27:50 AM4/28/14
to Birunthan Mohanathas, dev-pl...@lists.mozilla.org
On Mon, Apr 28, 2014 at 07:18:17AM +0300, Birunthan Mohanathas wrote:
> Bugs 900903 and 900908 introduced variadic variants of
> NS_IMPL_ISUPPORTS, NS_IMPL_QUERY_INTERFACE, NS_IMPL_CYCLE_COLLECTION,
> etc. and removed the old numbered macros. So, instead of e.g.
> NS_IMPL_ISUPPORTS2(nsFoo, nsIBar, nsIBaz), simply use
> NS_IMPL_ISUPPORTS(nsFoo, nsIBar, nsIBaz) instead. Right now, the new
> macros support up to 50 variadic arguments.
>
> Note that due to technical details, the new macros will reject uses
> with zero variadic arguments. In such cases, you will want to continue
> to use the zero-numbered macro, e.g. NS_IMPL_ISUPPORTS0(nsFoo).

Mmmmm maybe the reason I failed doing the same thing earlier is because
I did try to support NS_IMPL_ISUPPORTS(nsFoo).

Mike

Birunthan Mohanathas

unread,
Apr 28, 2014, 12:17:14 PM4/28/14
to Henri Sivonen, Benoit Jacob, dev-platform
On 28 April 2014 14:18, Benoit Jacob <jacob.b...@gmail.com> wrote:
> Question: is there a plan to switch to an implementation based on variadic
> templates when we will stop supporting compilers that don't support them? Do
> you know when that would be (of the compilers that we currently support,
> which ones don't support variadic templates?)

I don't think a purely variadic template based solution is possible
(e.g. due to argument stringification employed by NS_IMPL_ADDREF and
others).

As for compiler support, I believe our current MSVC version is the
only one lacking variadic templates. I don't know if/when we are going
to switch to VS2013.

On 28 April 2014 12:07, Henri Sivonen <hsiv...@hsivonen.fi> wrote:
> Cool. Is there a script that rewrites mq patches whose context has
> numbered macros to not expect numbered macros?

Something like this should work (please use with caution because it's
Perl and because I only did a quick test):

perl -i.bak -0777 -pe '
$names = join("|", (
"NS_IMPL_CI_INTERFACE_GETTER#",
"NS_IMPL_CYCLE_COLLECTION_#",
"NS_IMPL_CYCLE_COLLECTION_INHERITED_#",
"NS_IMPL_ISUPPORTS#",
"NS_IMPL_ISUPPORTS#_CI",
"NS_IMPL_ISUPPORTS_INHERITED#",
"NS_IMPL_QUERY_INTERFACE#",
"NS_IMPL_QUERY_INTERFACE#_CI",
"NS_IMPL_QUERY_INTERFACE_INHERITED#",
"NS_INTERFACE_TABLE#",
"NS_INTERFACE_TABLE_INHERITED#",
)) =~ s/#/[1-9]\\d?/gr;

sub rep {
my ($name, $args) = @_;
my $unnumbered_name = $name =~ s/_?\d+//r;
my $spaces_to_remove = length($name) - length($unnumbered_name);
$args =~ s/^(. {16}) {$spaces_to_remove}/\1/gm;
return $unnumbered_name . $args;
}

s/($names)(\(.*?\))/rep($1, $2)/ges;
' some-patch.diff

Ehsan Akhgari

unread,
Apr 28, 2014, 12:46:58 PM4/28/14
to Birunthan Mohanathas, Henri Sivonen, Benoit Jacob, dev-platform
On 2014-04-28, 12:17 PM, Birunthan Mohanathas wrote:
> On 28 April 2014 14:18, Benoit Jacob <jacob.b...@gmail.com> wrote:
>> Question: is there a plan to switch to an implementation based on variadic
>> templates when we will stop supporting compilers that don't support them? Do
>> you know when that would be (of the compilers that we currently support,
>> which ones don't support variadic templates?)
>
> I don't think a purely variadic template based solution is possible
> (e.g. due to argument stringification employed by NS_IMPL_ADDREF and
> others).
>
> As for compiler support, I believe our current MSVC version is the
> only one lacking variadic templates. I don't know if/when we are going
> to switch to VS2013.

We're working on it! :-)

Cheers,
Ehsan

Benoit Jacob

unread,
Apr 28, 2014, 2:07:07 PM4/28/14
to Birunthan Mohanathas, Henri Sivonen, dev-platform
2014-04-28 12:17 GMT-04:00 Birunthan Mohanathas <biru...@mohanathas.com>:

> On 28 April 2014 14:18, Benoit Jacob <jacob.b...@gmail.com> wrote:
> > Question: is there a plan to switch to an implementation based on
> variadic
> > templates when we will stop supporting compilers that don't support
> them? Do
> > you know when that would be (of the compilers that we currently support,
> > which ones don't support variadic templates?)
>
> I don't think a purely variadic template based solution is possible
> (e.g. due to argument stringification employed by NS_IMPL_ADDREF and
> others).
>

Would it be possible to have a variadic macro that takes N arguments,
stringifies them, and passes all 2N resulting values (the original N
arguments and their N stringifications) to a variadic template?

Benoit


>
> As for compiler support, I believe our current MSVC version is the
> only one lacking variadic templates. I don't know if/when we are going
> to switch to VS2013.
>

Trevor Saunders

unread,
Apr 28, 2014, 2:18:15 PM4/28/14
to dev-pl...@lists.mozilla.org
On Mon, Apr 28, 2014 at 02:07:07PM -0400, Benoit Jacob wrote:
> 2014-04-28 12:17 GMT-04:00 Birunthan Mohanathas <biru...@mohanathas.com>:
>
> > On 28 April 2014 14:18, Benoit Jacob <jacob.b...@gmail.com> wrote:
> > > Question: is there a plan to switch to an implementation based on
> > variadic
> > > templates when we will stop supporting compilers that don't support
> > them? Do
> > > you know when that would be (of the compilers that we currently support,
> > > which ones don't support variadic templates?)
> >
> > I don't think a purely variadic template based solution is possible
> > (e.g. due to argument stringification employed by NS_IMPL_ADDREF and
> > others).
> >
>
> Would it be possible to have a variadic macro that takes N arguments,
> stringifies them, and passes all 2N resulting values (the original N
> arguments and their N stringifications) to a variadic template?

Well, the bigger problem is that those macros are defining member
functions, so I don't see how you could do that with a variatic
template, accept perhaps for cycle collection if we can have a struct
that takes a variatic template, and then use the variatic template args
in member functions.

Trev
signature.asc

Benoit Jacob

unread,
Apr 28, 2014, 2:23:36 PM4/28/14
to Trevor Saunders, dev-platform
2014-04-28 14:18 GMT-04:00 Trevor Saunders <trev.s...@gmail.com>:

> On Mon, Apr 28, 2014 at 02:07:07PM -0400, Benoit Jacob wrote:
> > 2014-04-28 12:17 GMT-04:00 Birunthan Mohanathas <
> biru...@mohanathas.com>:
> >
> > > On 28 April 2014 14:18, Benoit Jacob <jacob.b...@gmail.com> wrote:
> > > > Question: is there a plan to switch to an implementation based on
> > > variadic
> > > > templates when we will stop supporting compilers that don't support
> > > them? Do
> > > > you know when that would be (of the compilers that we currently
> support,
> > > > which ones don't support variadic templates?)
> > >
> > > I don't think a purely variadic template based solution is possible
> > > (e.g. due to argument stringification employed by NS_IMPL_ADDREF and
> > > others).
> > >
> >
> > Would it be possible to have a variadic macro that takes N arguments,
> > stringifies them, and passes all 2N resulting values (the original N
> > arguments and their N stringifications) to a variadic template?
>
> Well, the bigger problem is that those macros are defining member
> functions, so I don't see how you could do that with a variatic
> template, accept perhaps for cycle collection if we can have a struct
> that takes a variatic template, and then use the variatic template args
> in member functions.
>

Right, NS_IMPL_CYCLE_COLLECTION and its variants are what I have in mind
here.

Benoit

Blake Kaplan

unread,
Apr 28, 2014, 4:52:13 PM4/28/14
to
Neil <ne...@parkwaycc.co.uk> wrote:
> I can't help wondering who would need to implement only nsISupports. It
> can't be for the refcounting, because you can just use inline
> refcounting. And you've got no way of telling whether an arbitrary
> nsISupports is your object or not.

Well, except that in the case of callbacks and "context" arguments you do know
what object you're getting, however, you do have to play by XPCOM rules. The
nsMemoryReporterManager case could use an nsSupportsPRInt64, but if that was a
real object with more than just an int64_t, it'd need its own class.
--
Blake Kaplan
0 new messages