* Private data members
@ 2009-07-29 8:45 Vladimir Prus
2009-07-29 13:39 ` Daniel Jacobowitz
2009-07-29 15:32 ` Tom Tromey
0 siblings, 2 replies; 9+ messages in thread
From: Vladimir Prus @ 2009-07-29 8:45 UTC (permalink / raw)
To: gdb
I have run into a case when it's desirable that all modifications
of a certain structure field in GDB codebase go via function that
can enforce necessary invariants. Specifically, the ignore_count
in struct breakpoint does not make any sense for tracepoint, therefore
I want to introduce a function that will throw if non-zero ignore count
is ever set for a tracepoint.
At the moment, there are at least 3 places that directly assign
a value to that field, and while I can convert them easily, nothing
will prevent a direct assignment to appear in future. In C++,
one would use 'private' visibility for that member, but it's not
available in C. So, how about introducing a small convention --
that members with names ending in '_' are 'private' and should
never be accessed by outside code. Another alternative is to
modify the comment on ignore_count, but that is much more likely
to be ignored.
Comments?
- Volodya
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 8:45 Private data members Vladimir Prus
@ 2009-07-29 13:39 ` Daniel Jacobowitz
2009-07-29 13:41 ` Vladimir Prus
2009-07-29 15:32 ` Tom Tromey
1 sibling, 1 reply; 9+ messages in thread
From: Daniel Jacobowitz @ 2009-07-29 13:39 UTC (permalink / raw)
To: Vladimir Prus; +Cc: gdb
On Wed, Jul 29, 2009 at 12:45:32PM +0400, Vladimir Prus wrote:
> At the moment, there are at least 3 places that directly assign
> a value to that field, and while I can convert them easily, nothing
> will prevent a direct assignment to appear in future. In C++,
> one would use 'private' visibility for that member, but it's not
> available in C. So, how about introducing a small convention --
> that members with names ending in '_' are 'private' and should
> never be accessed by outside code. Another alternative is to
> modify the comment on ignore_count, but that is much more likely
> to be ignored.
How about struct { int ignore_count; } private; ? I don't think
ignore_count_ is clear.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 13:39 ` Daniel Jacobowitz
@ 2009-07-29 13:41 ` Vladimir Prus
2009-07-29 16:18 ` Samuel Bronson
0 siblings, 1 reply; 9+ messages in thread
From: Vladimir Prus @ 2009-07-29 13:41 UTC (permalink / raw)
To: gdb
Daniel Jacobowitz wrote:
> On Wed, Jul 29, 2009 at 12:45:32PM +0400, Vladimir Prus wrote:
>> At the moment, there are at least 3 places that directly assign
>> a value to that field, and while I can convert them easily, nothing
>> will prevent a direct assignment to appear in future. In C++,
>> one would use 'private' visibility for that member, but it's not
>> available in C. So, how about introducing a small convention --
>> that members with names ending in '_' are 'private' and should
>> never be accessed by outside code. Another alternative is to
>> modify the comment on ignore_count, but that is much more likely
>> to be ignored.
>
> How about struct { int ignore_count; } private; ?
Might work.
> I don't think ignore_count_ is clear.
Well, it's a convention for naming private variables used by roughly
half of C++ developers, so I expect many current and future contributors
know it already.
- Volodya
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 8:45 Private data members Vladimir Prus
2009-07-29 13:39 ` Daniel Jacobowitz
@ 2009-07-29 15:32 ` Tom Tromey
2009-07-29 17:30 ` Michael Snyder
1 sibling, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2009-07-29 15:32 UTC (permalink / raw)
To: Vladimir Prus; +Cc: gdb
>>>>> "Volodya" == Vladimir Prus <vladimir@codesourcery.com> writes:
Volodya> I have run into a case when it's desirable that all
Volodya> modifications of a certain structure field in GDB codebase go
Volodya> via function that can enforce necessary invariants.
Volodya> At the moment, there are at least 3 places that directly assign
Volodya> a value to that field, and while I can convert them easily,
Volodya> nothing will prevent a direct assignment to appear in future.
In the past somebody solved this same problem for struct value by
putting the struct definition into value.c and adding a bunch of
accessors.
I'm lukewarm about this technique, but it can be made to work.
Daniel's suggested approach would also be fine with me.
If you want a real guarantee, you could write an spatch script to detect
assignments to this field, and run it periodically.
Tom
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 13:41 ` Vladimir Prus
@ 2009-07-29 16:18 ` Samuel Bronson
2009-07-29 16:50 ` Vladimir Prus
0 siblings, 1 reply; 9+ messages in thread
From: Samuel Bronson @ 2009-07-29 16:18 UTC (permalink / raw)
To: Vladimir Prus; +Cc: gdb
At Wed, 29 Jul 2009 17:41:20 +0400,
Vladimir Prus wrote:
>
> Daniel Jacobowitz wrote:
> >
> > I don't think ignore_count_ is clear.
>
> Well, it's a convention for naming private variables used by roughly
> half of C++ developers, so I expect many current and future contributors
> know it already.
Hmm. I'm only familiar with the _ignore_count convention that's used
in e.g. Python (and sometimes in C, even though it's not really
allowed in user code there).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 16:18 ` Samuel Bronson
@ 2009-07-29 16:50 ` Vladimir Prus
0 siblings, 0 replies; 9+ messages in thread
From: Vladimir Prus @ 2009-07-29 16:50 UTC (permalink / raw)
To: Samuel Bronson; +Cc: gdb
On Wednesday 29 July 2009 Samuel Bronson wrote:
> At Wed, 29 Jul 2009 17:41:20 +0400,
> Vladimir Prus wrote:
> >
> > Daniel Jacobowitz wrote:
> > >
> > > I don't think ignore_count_ is clear.
> >
> > Well, it's a convention for naming private variables used by roughly
> > half of C++ developers, so I expect many current and future contributors
> > know it already.
>
> Hmm. I'm only familiar with the _ignore_count convention that's used
> in e.g. Python (and sometimes in C, even though it's not really
> allowed in user code there).
That's why I've said "half". Though I actually expected the other
half to be familiar with the m_foo convention :-)
- Volodya
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 15:32 ` Tom Tromey
@ 2009-07-29 17:30 ` Michael Snyder
2009-07-29 21:56 ` Andreas Schwab
0 siblings, 1 reply; 9+ messages in thread
From: Michael Snyder @ 2009-07-29 17:30 UTC (permalink / raw)
To: tromey; +Cc: Vladimir Prus, gdb
Tom Tromey wrote:
>>>>>> "Volodya" == Vladimir Prus <vladimir@codesourcery.com> writes:
>
> Volodya> I have run into a case when it's desirable that all
> Volodya> modifications of a certain structure field in GDB codebase go
> Volodya> via function that can enforce necessary invariants.
>
> Volodya> At the moment, there are at least 3 places that directly assign
> Volodya> a value to that field, and while I can convert them easily,
> Volodya> nothing will prevent a direct assignment to appear in future.
>
> In the past somebody solved this same problem for struct value by
> putting the struct definition into value.c and adding a bunch of
> accessors.
>
> I'm lukewarm about this technique, but it can be made to work.
>
> Daniel's suggested approach would also be fine with me.
How about combining the two?
Define struct breakpoint in breakpoint.h, put any public members
in there, and then include a member "struct breakpoint_private"
that is only a forward declaration.
Then define "struct breakpoint_private" in breakpoint.c, so that
its members will be invisible outside of that module.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 17:30 ` Michael Snyder
@ 2009-07-29 21:56 ` Andreas Schwab
2009-07-29 22:39 ` Michael Snyder
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2009-07-29 21:56 UTC (permalink / raw)
To: Michael Snyder; +Cc: tromey, Vladimir Prus, gdb
Michael Snyder <msnyder@vmware.com> writes:
> Define struct breakpoint in breakpoint.h, put any public members
> in there, and then include a member "struct breakpoint_private"
> that is only a forward declaration.
That only works if this member is a pointer. You cannot have struct
members with incomplete types.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Private data members
2009-07-29 21:56 ` Andreas Schwab
@ 2009-07-29 22:39 ` Michael Snyder
0 siblings, 0 replies; 9+ messages in thread
From: Michael Snyder @ 2009-07-29 22:39 UTC (permalink / raw)
To: Andreas Schwab; +Cc: tromey, Vladimir Prus, gdb
Andreas Schwab wrote:
> Michael Snyder <msnyder@vmware.com> writes:
>
>> Define struct breakpoint in breakpoint.h, put any public members
>> in there, and then include a member "struct breakpoint_private"
>> that is only a forward declaration.
>
> That only works if this member is a pointer. You cannot have struct
> members with incomplete types.
Right. But that can still be done, because we have a local allocator.
Breakpoint structs are created by set_raw_breakpoint_without_location,
a static function, and the exported interface is set_raw_breakpoint.
As long as nobody outside of breakpoint.c allocates a struct bp,
I don't see why it shouldn't work.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2009-07-29 22:39 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-29 8:45 Private data members Vladimir Prus
2009-07-29 13:39 ` Daniel Jacobowitz
2009-07-29 13:41 ` Vladimir Prus
2009-07-29 16:18 ` Samuel Bronson
2009-07-29 16:50 ` Vladimir Prus
2009-07-29 15:32 ` Tom Tromey
2009-07-29 17:30 ` Michael Snyder
2009-07-29 21:56 ` Andreas Schwab
2009-07-29 22:39 ` Michael Snyder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox