unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* The :protection option for EIEIO slots
@ 2015-01-16  3:00 Stefan Monnier
  2015-01-17  2:56 ` Eric Ludlam
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2015-01-16  3:00 UTC (permalink / raw)
  To: Eric M. Ludlam; +Cc: emacs-devel

Hi Eric,

Can you give me some background on the :protection option for the slots
of EIEIO objects?  This doesn't exist in CLOS, so I'm wondering what
were the motivations to add them.

According to my grepping, the `private' setting is only used in the
eieio-tests.  And the `protected' setting is used at a few places, but
it's been implemented wrong so you can do:

  (defmethod foo ((x class-1))
    (slot-value <any-object> <any-protected-slot>))

and the access will be allowed, even though only protected slots
belonging to class-1 (or its superclasses) should be granted access.
This is because the code was the check was:

         ((and (eq (cdr fsym) 'protected)
               (eieio--scoped-class)
               (or (child-of-class-p class (eieio--scoped-class))
 		   (and (eieio-object-p obj)
                        (child-of-class-p class (eieio--object-class-object obj)))))


Which can be (and has been) rewritten to:

         ((and (eq (cdr fsym) 'protected)
               (eieio--scoped-class)
               (or (child-of-class-p class (eieio--scoped-class))
                   (and (eieio-object-p obj)
                        (progn
                          (cl-assert (eq class (eieio--object-class-object obj)))
                          t))))

Since all callers of the function guarantee that the assertion won't fail.

So I'm tempted to just drop this functionality.  Any thoughts?


        Stefan



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: The :protection option for EIEIO slots
  2015-01-16  3:00 The :protection option for EIEIO slots Stefan Monnier
@ 2015-01-17  2:56 ` Eric Ludlam
  2015-01-17  3:56   ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Ludlam @ 2015-01-17  2:56 UTC (permalink / raw)
  To: Stefan Monnier, Eric M. Ludlam; +Cc: emacs-devel

On 01/15/2015 10:00 PM, Stefan Monnier wrote:
> Hi Eric,
>
> Can you give me some background on the :protection option for the slots
> of EIEIO objects?  This doesn't exist in CLOS, so I'm wondering what
> were the motivations to add them.
>
As far as I remember, I was learning C++ at the time and using Emacs to 
teach myself OO concepts and thought it would be useful.  I didn't 
hesitate much about extending CLOS.

I'm surprised the protected slot doesn't work.  There is a test for that 
throwing an error.

>
> So I'm tempted to just drop this functionality.  Any thoughts?
>

No flags.  I've written a lot of classes and apparently didn't use it 
very much, so feel free.

Eric



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: The :protection option for EIEIO slots
  2015-01-17  2:56 ` Eric Ludlam
@ 2015-01-17  3:56   ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2015-01-17  3:56 UTC (permalink / raw)
  To: Eric Ludlam; +Cc: Eric M. Ludlam, emacs-devel

> I'm surprised the protected slot doesn't work.  There is a test for that
> throwing an error.

The test checks that you can't access a protected slot from outside of
a method.  But as soon as you're inside a method that dispatched on
a class (i.e. when eieio--scoped-class is non-nil), you can access
any protected slot of any object of any class.

> No flags.  I've written a lot of classes and apparently didn't use it very
> much, so feel free.

Good, thanks,


        Stefan



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-17  3:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-16  3:00 The :protection option for EIEIO slots Stefan Monnier
2015-01-17  2:56 ` Eric Ludlam
2015-01-17  3:56   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).