emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: testcover: setf-method and treatment of `defcustom'


From: Stefan Monnier
Subject: Re: testcover: setf-method and treatment of `defcustom'
Date: Mon, 10 Sep 2012 23:40:11 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

>       No setf-method known for testcover-after

Does one of the 2 patches work?

> I looked into this and found `defsetf' in `cl-macs'. `testcover-after'
> is a function which has only some side effect.  I think
>   (defsetf testcover-after (idx val) (store)
>     (list 'progn
>         (list 'testcover-after idx val)
>         (list 'setf val store)))
> does the right thing.  At least the error messages described above
> vanish for me.

I'm not sure what we should do, but the above doesn't sound quite right.

> AFAICS the only thing which can go wrong with this setf-method seems
> to be the double evaluation of `val'

In (setf (testcover-after IDX (aref A I)) V), your defsetf will be
called with a `val' that's a temporary variable bound to the value of
(aref A I), so double evaluation is not a problem.  But your `(setf ,val
,store) will end up changing some temporary variable rather than
changing the I'th slot of the A vector.

My 1st patch has the downside that it doesn't call testcover-after at all.
The reason is that I don't know what VAL to set in IDX when we do
things like (push VAL (testcover-after IDX PLACE)): should it be the
value read before pushing VAL onto it, or the value set afterwards?
The second patch chooses to call testcover-after when setting the value.

> I still had another error left, however.
>        Value of form marked with `1value' does vary: ...

I'll let Jonathan comment on this (as well as on my suggested gv-expanders).


        Stefan


=== modified file 'lisp/emacs-lisp/testcover.el'
--- lisp/emacs-lisp/testcover.el        2012-01-19 07:21:25 +0000
+++ lisp/emacs-lisp/testcover.el        2012-09-11 03:09:45 +0000
@@ -447,6 +447,7 @@
 (defun testcover-after (idx val)
   "Internal function for coverage testing.  Returns VAL after installing it in
 `testcover-vector' at offset IDX."
+  (declare (gv-expander (lambda (do) (gv-get val do))))
   (cond
    ((eq (aref testcover-vector idx) 'unknown)
     (aset testcover-vector idx val))



=== modified file 'lisp/emacs-lisp/testcover.el'
--- lisp/emacs-lisp/testcover.el        2012-01-19 07:21:25 +0000
+++ lisp/emacs-lisp/testcover.el        2012-09-11 03:38:33 +0000
@@ -447,6 +447,13 @@
 (defun testcover-after (idx val)
   "Internal function for coverage testing.  Returns VAL after installing it in
 `testcover-vector' at offset IDX."
+  (declare (gv-expander (lambda (do)
+                          (gv-letplace (getter setter) val
+                            (funcall do getter
+                                     (lambda (store)
+                                       (macroexp-let2 nil s store
+                                         `(progn (testcover-after ,idx ,s)
+                                                 ,(funcall setter s)))))))))
   (cond
    ((eq (aref testcover-vector idx) 'unknown)
     (aset testcover-vector idx val))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]