Replace safe-bool idiom with explicit operator bool() in base::WeakPtr.
Also fixes various call-sites which were using WeakPtr as a bool
return-value, or comparing to NULL to test as a bool.
BUG=605794
Committed: https://crrev.com/b9820d493c42b7e3a4aebcd7956b016232600a1d
Cr-Commit-Position: refs/heads/master@{#401464}
Hey Nico, I tried switching WeakPtr to use explicit operator bool() - as you can ...
4 years, 8 months ago
(2016-04-24 02:37:39 UTC)
#2
Hey Nico,
I tried switching WeakPtr to use explicit operator bool() - as you can see there
are a load of call-sites that still need updating, but I wondered if you had any
input on cases like:
bool IsFoo() {
return static_cast<bool>(foo_ptr_);
}
versus
bool IsFoo() { return foo_ptr_ != nullptr; }
The latter seems less ugly to me; WDYT?
miu
Drive-by comment (this CL triggered a watchlist e-mail to me). How about: bool IsFoo() { ...
4 years, 8 months ago
(2016-04-25 21:02:21 UTC)
#3
Drive-by comment (this CL triggered a watchlist e-mail to me). How about:
bool IsFoo() { return !!foo_ptr_; }
This seems to be used frequently throughout Chromium code. It should be
well-understood that it's a convert-pointer-to-bool expression.
Nico
see discussion in https://codereview.chromium.org/1878253003/ for why not !!. for the change, i'd like to wait ...
4 years, 8 months ago
(2016-04-25 21:36:55 UTC)
#4
Thanks for the pointer to the CL, Nico. I've CC'd that bug & will hold-off ...
4 years, 8 months ago
(2016-04-25 21:47:04 UTC)
#5
Thanks for the pointer to the CL, Nico. I've CC'd that bug & will hold-off
on this til I see a resolution there.
My preference for the pointer-to-bool-return call-sites would be the
bool{pointer} form, for brevity & clarity, but it looks like that's
not-yet-allowed in Chromium?
On 25 April 2016 at 14:36, <thakis@chromium.org> wrote:
> see discussion in https://codereview.chromium.org/1878253003/ for why not
> !!.
>
> for the change, i'd like to wait with changes like this until
> https://bugs.chromium.org/p/chromium/issues/detail?id=605080 is understood
> better
>
> https://codereview.chromium.org/1909263002/
>
--
You received this message because you are subscribed to the Google Groups
"Chromium-reviews" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to chromium-reviews+unsubscribe@chromium.org.
miu
On 2016/04/25 21:36:55, Nico wrote: > see discussion in https://codereview.chromium.org/1878253003/ for why not !!. I'm ...
4 years, 8 months ago
(2016-04-25 22:29:53 UTC)
#6
On 2016/04/25 21:36:55, Nico wrote:
> see discussion in https://codereview.chromium.org/1878253003/ for why not !!.
I'm still not convinced this is a bad pattern. There were only two discussion
points in that CL (and groups discussion):
1. "Bleh, I hate that pattern."
2. Dana mentioned: If you don't put !! in front of a var, the compiler might
generate instructions that leak the pointer value, rather than a 1 (true) or 0
(false) value. I know, from experience this *can* matter: For example, the
value for true/false matters in ObjC BOOLs, and we auto-convert between bool and
BOOL all over the code base.
So, if this is a matter of personal preference, then I don't see why it should
be dismissed. FWIW, I see this all the time throughout the Chromium project, so
I don't think the usual "consistent style" argument would hold here either.
Nico
You understand !! if you've seen it before. It doesn't look like a conversion unless ...
4 years, 8 months ago
(2016-04-25 22:33:27 UTC)
#7
You understand !! if you've seen it before. It doesn't look like a
conversion unless you know that it is one. I don't think that's personal
preference.
On Apr 25, 2016 6:29 PM, <miu@chromium.org> wrote:
> On 2016/04/25 21:36:55, Nico wrote:
> > see discussion in https://codereview.chromium.org/1878253003/ for why
> not !!.
>
> I'm still not convinced this is a bad pattern. There were only two
> discussion
> points in that CL (and groups discussion):
>
> 1. "Bleh, I hate that pattern."
>
> 2. Dana mentioned: If you don't put !! in front of a var, the compiler
> might
> generate instructions that leak the pointer value, rather than a 1 (true)
> or 0
> (false) value. I know, from experience this *can* matter: For example, the
> value for true/false matters in ObjC BOOLs, and we auto-convert between
> bool and
> BOOL all over the code base.
>
> So, if this is a matter of personal preference, then I don't see why it
> should
> be dismissed. FWIW, I see this all the time throughout the Chromium
> project, so
> I don't think the usual "consistent style" argument would hold here either.
>
>
> https://codereview.chromium.org/1909263002/
>
--
You received this message because you are subscribed to the Google Groups
"Chromium-reviews" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to chromium-reviews+unsubscribe@chromium.org.
miu
On 2016/04/25 22:33:27, Nico wrote: > You understand !! if you've seen it before. It ...
4 years, 8 months ago
(2016-04-25 23:08:19 UTC)
#8
On 2016/04/25 22:33:27, Nico wrote:
> You understand !! if you've seen it before. It doesn't look like a
> conversion unless you know that it is one. I don't think that's personal
> preference.
Good point. However, don't most developers come across this often enough to
make it common-sense knowledge? FWIW, this seems to appear in over a thousand
source files:
~/chromium/src$ git grep -l '!!' | grep -E '\.(cc|h|mm|js)$' | wc -l
1143
Wez
On 2016/04/25 23:08:19, miu wrote: > On 2016/04/25 22:33:27, Nico wrote: > > You understand ...
4 years, 7 months ago
(2016-04-27 16:17:53 UTC)
#9
On 2016/04/25 23:08:19, miu wrote:
> On 2016/04/25 22:33:27, Nico wrote:
> > You understand !! if you've seen it before. It doesn't look like a
> > conversion unless you know that it is one. I don't think that's personal
> > preference.
>
> Good point. However, don't most developers come across this often enough to
> make it common-sense knowledge? FWIW, this seems to appear in over a thousand
> source files:
>
> ~/chromium/src$ git grep -l '!!' | grep -E '\.(cc|h|mm|js)$' | wc -l
> 1143
Personally whenever I see '!!' my first thought is "that looks highly suspect, I
wonder if they really meant to do that". I'd much prefer to use the
brace-initializer syntax once that's permitted, or jst take the hit of ugly
static_cast<>()ing.
mmenke
On 2016/04/27 16:17:53, Wez wrote: > On 2016/04/25 23:08:19, miu wrote: > > On 2016/04/25 ...
4 years, 7 months ago
(2016-04-27 16:28:22 UTC)
#10
On 2016/04/27 16:17:53, Wez wrote:
> On 2016/04/25 23:08:19, miu wrote:
> > On 2016/04/25 22:33:27, Nico wrote:
> > > You understand !! if you've seen it before. It doesn't look like a
> > > conversion unless you know that it is one. I don't think that's personal
> > > preference.
> >
> > Good point. However, don't most developers come across this often enough to
> > make it common-sense knowledge? FWIW, this seems to appear in over a
thousand
> > source files:
> >
> > ~/chromium/src$ git grep -l '!!' | grep -E '\.(cc|h|mm|js)$' | wc -l
> > 1143
>
> Personally whenever I see '!!' my first thought is "that looks highly suspect,
I
> wonder if they really meant to do that". I'd much prefer to use the
> brace-initializer syntax once that's permitted, or jst take the hit of ugly
> static_cast<>()ing.
Hrm...I'd go with the !!, myself. Beyond just the hideousness of static_cast
syntax, static_casts have a tendency to mask bugs (As well as implicit casts, of
course).
Looking at net/, there are 3 files that use static_cast<bool>, and 28 that use
!!, so !! seems to better follow existing conventions in net/ as well.
Wez
IIUC the bool{subject} syntax would have the same properties w/ respect to correctness vs static_cast ...
4 years, 7 months ago
(2016-04-27 16:44:17 UTC)
#11
IIUC the bool{subject} syntax would have the same properties w/ respect to
correctness vs static_cast as !!, since it's taking advantage of implicit
ptr->bool conversion rather than explicitly telling the compiler to coerce
the subject?
But yeah, when in net/, let's do as the net/ters do, I suppose.
On 27 April 2016 at 09:28, <mmenke@chromium.org> wrote:
> On 2016/04/27 16:17:53, Wez wrote:
> > On 2016/04/25 23:08:19, miu wrote:
> > > On 2016/04/25 22:33:27, Nico wrote:
> > > > You understand !! if you've seen it before. It doesn't look like a
> > > > conversion unless you know that it is one. I don't think that's
> personal
> > > > preference.
> > >
> > > Good point. However, don't most developers come across this often
> enough to
> > > make it common-sense knowledge? FWIW, this seems to appear in over a
> thousand
> > > source files:
> > >
> > > ~/chromium/src$ git grep -l '!!' | grep -E '\.(cc|h|mm|js)$' | wc -l
> > > 1143
> >
> > Personally whenever I see '!!' my first thought is "that looks highly
> suspect,
> I
> > wonder if they really meant to do that". I'd much prefer to use the
> > brace-initializer syntax once that's permitted, or jst take the hit of
> ugly
> > static_cast<>()ing.
>
> Hrm...I'd go with the !!, myself. Beyond just the hideousness of
> static_cast
> syntax, static_casts have a tendency to mask bugs (As well as implicit
> casts, of
> course).
>
> Looking at net/, there are 3 files that use static_cast<bool>, and 28 that
> use
> !!, so !! seems to better follow existing conventions in net/ as well.
>
> https://codereview.chromium.org/1909263002/
>
--
You received this message because you are subscribed to the Google Groups
"Chromium-reviews" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to chromium-reviews+unsubscribe@chromium.org.
Wez
The CQ bit was checked by wez@chromium.org to run a CQ dry run
4 years, 6 months ago
(2016-05-27 02:20:06 UTC)
#12
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1909263002/20001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1909263002/20001
4 years, 6 months ago
(2016-05-27 02:20:21 UTC)
#13
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1909263002/40001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1909263002/40001
4 years, 6 months ago
(2016-05-28 01:32:33 UTC)
#17
crbug.com/607208 is, according to jbroman@'s investigation, due to some peculiarity in the inlining decisions under ...
4 years, 6 months ago
(2016-06-02 21:19:34 UTC)
#25
crbug.com/607208 is, according to jbroman@'s investigation, due to some
peculiarity in the inlining decisions under ARM gcc specific to WTF::RefPtr
usage in WTF::String::find(). He thinks it's extremely unlikely that
base::WeakPtr would suffer anything similar.
We've already landed crbug.com/610048, so I was assuming that
crbug.com/607208 had been deemed sufficiently specific to warrant blocking
other use-cases being converted.
WDYT?
On 2 June 2016 at 14:03, <thakis@chromium.org> wrote:
> https://bugs.chromium.org/p/chromium/issues/detail?id=607208 isn't
> resolved yet
> afaict
>
> https://codereview.chromium.org/1909263002/
>
--
You received this message because you are subscribed to the Google Groups
"Chromium-reviews" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to chromium-reviews+unsubscribe@chromium.org.
Nico
ok, lgtm with comments addressed based on jbroman's reply on the bug https://codereview.chromium.org/1909263002/diff/60001/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc File chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc ...
4 years, 6 months ago
(2016-06-02 21:31:02 UTC)
#26
https://codereview.chromium.org/1909263002/diff/60001/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc File chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc (right): https://codereview.chromium.org/1909263002/diff/60001/chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc#newcode149 chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc:149: return !!popup_; On 2016/06/02 21:31:02, Nico wrote: > no ...
4 years, 6 months ago
(2016-06-02 21:48:06 UTC)
#27
https://codereview.chromium.org/1909263002/diff/60001/chrome/browser/ui/views...
File chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc (right):
https://codereview.chromium.org/1909263002/diff/60001/chrome/browser/ui/views...
chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc:149: return
!!popup_;
On 2016/06/02 21:31:02, Nico wrote:
> no !! please
Opted to use !! based on mmenke@'s points in comment #10:
- static_cast<>s have a tendency to mask bugs.
- net/ has 28:3 files using !!:static_cast, so !! is more consistent.
This seems sufficiently contentious that we should have an explicit
recommendation for the form to prefer - scheib@ used static_cast<bool>() in his
patch for crbug.com/610048, though I notice use of static_cast<bool> was
seemingly not discussed.
Wez
PTAL I've added two patches, one which adds an is_valid() getter to allow expicit weak_ptr.is_valid(), ...
4 years, 6 months ago
(2016-06-04 01:00:15 UTC)
#28
PTAL
I've added two patches, one which adds an is_valid() getter to allow expicit
weak_ptr.is_valid(), and a second which instead adds a bool
operator!=(nullptr_t), to allow explicit weak_ptr != nullptr checks.
The latter leads to easier-to-understand call-sites, IMO.
WDYT?
Wez
The CQ bit was checked by wez@chromium.org
4 years, 6 months ago
(2016-06-22 00:36:45 UTC)
#29
4 years, 6 months ago
(2016-06-22 23:41:23 UTC)
#41
Message was sent while issue was closed.
Committed patchset #9 (id:160001)
commit-bot: I haz the power
Description was changed from ========== Replace safe-bool idiom with explicit operator bool() in base::WeakPtr. Also ...
4 years, 6 months ago
(2016-06-22 23:43:37 UTC)
#42
Message was sent while issue was closed.
Description was changed from
==========
Replace safe-bool idiom with explicit operator bool() in base::WeakPtr.
Also fixes various call-sites which were using WeakPtr as a bool
return-value, or comparing to NULL to test as a bool.
BUG=605794
==========
to
==========
Replace safe-bool idiom with explicit operator bool() in base::WeakPtr.
Also fixes various call-sites which were using WeakPtr as a bool
return-value, or comparing to NULL to test as a bool.
BUG=605794
Committed: https://crrev.com/b9820d493c42b7e3a4aebcd7956b016232600a1d
Cr-Commit-Position: refs/heads/master@{#401464}
==========
commit-bot: I haz the power
Patchset 9 (id:??) landed as https://crrev.com/b9820d493c42b7e3a4aebcd7956b016232600a1d Cr-Commit-Position: refs/heads/master@{#401464}
4 years, 6 months ago
(2016-06-22 23:43:39 UTC)
#43
Issue 1909263002: Replace safe-bool idiom with explicit WeakPtr::operator bool()
(Closed)
Created 4 years, 8 months ago by Wez
Modified 4 years, 6 months ago
Reviewers: Ken Rockot(use gerrit already), Charlie Reis, Ryan Sleevi, Nico
Base URL: https://chromium.googlesource.com/chromium/src.git@master
Comments: 7