On 7 Nov 2005, at 10:31, Christophe Rhodes wrote:
> Pascal Costanza <pc@...> writes:
>> SBCL doesn't seem to perform any checks on the :allocation kind of a
>> given slot. At least, the following code is accepted without any hint
>> that something might be wrong:
>> (defclass test ()
>> ((slot :allocation :foo)))
>> (defparameter *p* (make-instance 'test))
>> Is this intentional?
> I think so. (Well, it wasn't directly intentional but I think it
> follows as a logical consequence of supporting custom allocation).
> I had to sit and stare a bit before I realised that the make-instance
> not only causes the slot definition to be created with :allocation
> :foo, which is fine, but instantiates a slot, which is less obviously
> fine. On the other hand, what would :allocation :none look like? I
> claim that an implementation of slots with no space for values looks
> much like the above, and an error should be signalled only when
> attempting to read or write such slots.
> If there's something in AMOP which says that standard slot
> definitions' allocation can only be :instance or :class, then
> obviously this has to be revised (and users wishing to implement
> :allocation :none will have to implement a bit more of the protocol
> themselves), but the late-binding nature of the MOP makes it hard to
> say exactly when something is definitely wrong.
I think a good place to check for the :allocation option is in direct-
slot-definition-class, which could look as follows:
((class standard-class) &rest initargs &key allocation)
(when (eq (class-of class) (find-class 'standard-class))
(unless (member allocation '(:class :instance))
(error "Unexpected :allocation option ~S." allocation)))
This should be sufficient for the following reasons:
- The only way to do something useful with new allocation kinds is to
create a new subclass of standard-effective-slot-definition and
define methods on the slot-xxx-using-class functions.
- The only way to ensure that a new effective slot definition class
is used is by defining a method on effective-slot-definition-class
which must be specialized on a new class metaobject class. So a new
class metaobject class is necessary to provide new allocation kinds.
Therefore, it is sufficient when the MOP checks whether the class is
exactly the standard-class, and in that case perform the check
for :class or :instance.
I may be missing something, but I am pretty sure this is sound.
Pascal Costanza, mailto:pc@..., http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium