--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
I've always preferred #2. Macros that mask C++ syntax always bother me.
One argument in favor of the macros is that it exactly matches the header file and the MSDN documentation. It's a lot easier to spot-check to see that a method you're trying to override is defined as STDMETHODIMP in the docs, rather than trying to remember if STDMETHODIMP returns a LONG or ULONG. Also, LONG isn't very meaningful, it could be anything - to a Windows developer, STDMETHODIMP strongly implies that this is a COM interface that returns an error code (S_OK, etc.).
--
I don't think you can use base/memory/ref_counted.h since AddRef and Release would only differ on the return type, right?
On Mon, Oct 22, 2012 at 6:14 PM, Daniel Cheng <dch...@chromium.org> wrote:I don't think you can use base/memory/ref_counted.h since AddRef and Release would only differ on the return type, right?Reading ref_counted.h, I'm pretty sure a scoped_refptr<> can be used with any object that implements AddRef() and Release() methods, even if those methods' return types differ from those in RefCountedBase.That still leaves my original question: do callers need to consume this as a refcounted object to begin with?
If all implementations of COM interfaces must be refcounted, can we somehow at least not override AddRef() and Release() ourselves, and can we restrict the use of a scoped_refptr<> to an outer class that contains an inner, refcounted class that does the actual implementation?
That still leaves my original question: do callers need to consume this as a refcounted object to begin with?Yes. We have base/win/scoped_comptr.h for this.
In the CL you referenced, if someone QI()'s, then Release()s the object, then OmniboxViewWin is left with a dangling pointer to freed memory.
If all implementations of COM interfaces must be refcounted, can we somehow at least not override AddRef() and Release() ourselves, and can we restrict the use of a scoped_refptr<> to an outer class that contains an inner, refcounted class that does the actual implementation?This is a big part of what ATL's CComObject/CComObjectRootEx provide (see e.g. inheritors of CComObjectRootEx in src/chrome_frame). CComObjectRootEx also makes it easy to specify the threading model of the object being implemented, providing appropriate internal implementations for AddRef/Release for each model.
--
Since COM interfaces can't pass actual scoped_refptr thingies, which make refcounting work like magic in the rest of the Chromium code, you need to manually keep a bunch of rules in mind when writing and reviewing COM code.
+1 for using the macros (STDMETHODIMP et al). They really make the COM code easy to recognize.Since COM interfaces can't pass actual scoped_refptr thingies, which make refcounting work like magic in the rest of the Chromium code, you need to manually keep a bunch of rules in mind when writing and reviewing COM code.This actually is a good thing (in a way). It helps to avoid mixing COM specific code with the rest of code leaving a bit less room for error.
On Tue, Oct 23, 2012 at 8:24 AM, Alex Pakhunov <alex...@google.com> wrote:+1 for using the macros (STDMETHODIMP et al). They really make the COM code easy to recognize.Since COM interfaces can't pass actual scoped_refptr thingies, which make refcounting work like magic in the rest of the Chromium code, you need to manually keep a bunch of rules in mind when writing and reviewing COM code.This actually is a good thing (in a way). It helps to avoid mixing COM specific code with the rest of code leaving a bit less room for error.Hmm... it looks like we've got heavy support from battle-scarred COM developers that using STDMETHODIMP et al is simply what you gotta do when writing COM code. We also now know who to +cc on COM code reviews ;)Darin: is your preference for #2 a mild or strong preference?