From: Pedro Alves <palves@redhat.com>
To: Yao Qi <qiyaoltc@gmail.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 5/6] Use copy ctor in regcache_dup
Date: Fri, 28 Apr 2017 09:51:00 -0000 [thread overview]
Message-ID: <ed2a07b5-5686-2a48-8f4d-e5dfef5840f0@redhat.com> (raw)
In-Reply-To: <86shksc2xb.fsf@gmail.com>
On 04/28/2017 10:11 AM, Yao Qi wrote:
> Pedro Alves <palves@redhat.com> writes:
>
>> This one doesn't look right to me. This isn't a copy in the
>> normal C++ object copy sense. The new object isn't semantically the
>> same as the source. One can't use the new object the same way as the
>> source regcache, they're not interchangeable. This is bound to generate
>> confusion and problems.
>
> I thought about this. The reason I still do this is that I can't think
> of a case that we need to copy a read-write regcache to another
> read-write regcache. So far, we only use copy(or transform) a
> read-write regcache to a read-only regcache. However, I agree with you,
> it is not a normal "copy ctor".
>
>>
>> Considering patch #6, it'd make more sense to me to
>> make that a separate constructor with tag dispatching, like:
>>
>> struct regcache
>> {
>> struct readonly_t {};
>> static constexpr readonly_t readonly {};
>>
>> regcache (readonly_t, const regcache &src); // old regcache_dup
>> };
>>
>> Then used like:
>>
>> regcache ro_copy (regcache::readonly, src);
>>
>> or if you want, you could make that tag-based ctor private and
>> add a factory function:
>>
>
> I have a different design on this, that is, put readonly regcache and
> readwrite regcache to two classes. readwrite regcache inherits readonly
> regcache, and readonly regcache has a constructor whose argument is a
> readwrite regcache.
*nod* I had seen it in the series' intro, but was going with the
idea of avoid that work. If we can get it nicely expressed in
the type system, then it's even better.
>
> class readonly_regcache
> {
> public:
> explicit readonly_regcache (const regcache &);
> }
>
> class regcache : public readonly_regcache
> {
> }
>
> What do you think?
I think that that's too incomplete to evaluate. :-)
Why regcache on top of readonly_regcache and not the other
way around? Off hand, I'd think that
struct regcache_base;
struct readonly_regcache : regcache_base {};
struct regcache : regcache_base {};
would be the "obvious" first choice.
What happens to all the "regcache->readonly_p" checks in
spread around in multiple functions? Do they disappear?
I think that if the design ends up with that flag still present
and functions exposing interfaces that work with
a "struct regcache *" that can either be readonly
or write-through, then it's likely that the design
isn't complete. [But replacing a single boolean
checked in a few select places by virtual methods and a
full blown vtable and a bunch of dispatching makes me
cringe a bit too. :-) But OTOH, I suspect you want
to add virtual methods for unit testing.]
I'm totally not against this direction, to be clear,
but it'd still suggest adding the tag dispatch ctor
first (the simple version with no factory, just adds two
lines of code compared to the copy ctor version), which
allows getting rid of the heap allocation and the cleanups
as you're doing in patch #6, and then consider changing
the hierarchy in a follow up patch.
>
>>
>> In any case, I think we should make sure to disable
>> the regular copy methods since the type doesn't really
>> support normal copy:
>>
>> regcache(const regcache &) = delete;
>> void operator= (const regcache &) = delete;
>
> I agree. I'll add it.
Thanks.
--
Pedro Alves
next prev parent reply other threads:[~2017-04-28 9:51 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-25 20:28 [PATCH 0/6] Class-fy regcache in GDB Yao Qi
2017-04-25 20:28 ` [PATCH 4/6] Simplify regcache_dup Yao Qi
2017-04-25 20:28 ` [PATCH 1/6 OBV] Change readonly_p to bool Yao Qi
2017-04-25 20:28 ` [PATCH 6/6] Remove cleanup in get_return_value Yao Qi
2017-04-25 20:28 ` [PATCH 2/6] Add constructor and destructor to regcache Yao Qi
2017-04-27 17:34 ` Pedro Alves
2017-04-28 13:42 ` Yao Qi
2017-04-25 20:29 ` [PATCH 5/6] Use copy ctor in regcache_dup Yao Qi
2017-04-27 17:37 ` Pedro Alves
2017-04-28 9:11 ` Yao Qi
2017-04-28 9:51 ` Pedro Alves [this message]
2017-04-28 13:20 ` Yao Qi
2017-04-25 20:29 ` [PATCH 3/6] Class-fy regcache Yao Qi
2017-04-27 17:35 ` Pedro Alves
2017-04-28 14:26 ` [PATCH 0/4 v2] Class-fy regcache in GDB Yao Qi
2017-04-28 14:26 ` [PATCH 3/4] Use tag dispatch regcache ctor in regcache_dup Yao Qi
2017-04-28 15:04 ` Pedro Alves
2017-04-28 14:26 ` [PATCH 1/4] Class-fy regcache Yao Qi
2017-04-28 15:03 ` Pedro Alves
2017-04-28 21:44 ` Yao Qi
2017-04-28 14:26 ` [PATCH 2/4] Simplify regcache_dup Yao Qi
2017-04-28 15:03 ` Pedro Alves
2017-04-28 14:26 ` [PATCH 4/4] Remove cleanup in get_return_value Yao Qi
2017-04-28 15:05 ` Pedro Alves
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ed2a07b5-5686-2a48-8f4d-e5dfef5840f0@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=qiyaoltc@gmail.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox