diff options
| author | Stefan Monnier | 2019-09-08 18:41:43 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-09-08 18:41:43 -0400 |
| commit | 69db930c7ecb821df7183204cef576557659e92f (patch) | |
| tree | a8ff1ef997ba9b8c35012a3c016bfc50012ebf64 | |
| parent | e94d01f1aceba364f8b55978eed854127a08264b (diff) | |
| download | emacs-69db930c7ecb821df7183204cef576557659e92f.tar.gz emacs-69db930c7ecb821df7183204cef576557659e92f.zip | |
* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Define setter functions.
When :noinline is specified one can't rely on setf expanding the
inlinable function to construct the setter.
Fixes bug#37283.
| -rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 1ae72666244..34d36067d4f 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el | |||
| @@ -2906,7 +2906,16 @@ Supported keywords for slots are: | |||
| 2906 | (error "Duplicate slots named %s in %s" slot name)) | 2906 | (error "Duplicate slots named %s in %s" slot name)) |
| 2907 | (let ((accessor (intern (format "%s%s" conc-name slot))) | 2907 | (let ((accessor (intern (format "%s%s" conc-name slot))) |
| 2908 | (default-value (pop desc)) | 2908 | (default-value (pop desc)) |
| 2909 | (doc (plist-get desc :documentation))) | 2909 | (doc (plist-get desc :documentation)) |
| 2910 | (access-body | ||
| 2911 | `(progn | ||
| 2912 | ,@(and pred-check | ||
| 2913 | (list `(or ,pred-check | ||
| 2914 | (signal 'wrong-type-argument | ||
| 2915 | (list ',name cl-x))))) | ||
| 2916 | ,(if (memq type '(nil vector)) `(aref cl-x ,pos) | ||
| 2917 | (if (= pos 0) '(car cl-x) | ||
| 2918 | `(nth ,pos cl-x)))))) | ||
| 2910 | (push slot slots) | 2919 | (push slot slots) |
| 2911 | (push default-value defaults) | 2920 | (push default-value defaults) |
| 2912 | ;; The arg "cl-x" is referenced by name in eg pred-form | 2921 | ;; The arg "cl-x" is referenced by name in eg pred-form |
| @@ -2916,13 +2925,7 @@ Supported keywords for slots are: | |||
| 2916 | slot name | 2925 | slot name |
| 2917 | (if doc (concat "\n" doc) "")) | 2926 | (if doc (concat "\n" doc) "")) |
| 2918 | (declare (side-effect-free t)) | 2927 | (declare (side-effect-free t)) |
| 2919 | ,@(and pred-check | 2928 | ,access-body) |
| 2920 | (list `(or ,pred-check | ||
| 2921 | (signal 'wrong-type-argument | ||
| 2922 | (list ',name cl-x))))) | ||
| 2923 | ,(if (memq type '(nil vector)) `(aref cl-x ,pos) | ||
| 2924 | (if (= pos 0) '(car cl-x) | ||
| 2925 | `(nth ,pos cl-x)))) | ||
| 2926 | forms) | 2929 | forms) |
| 2927 | (when (cl-oddp (length desc)) | 2930 | (when (cl-oddp (length desc)) |
| 2928 | (push | 2931 | (push |
| @@ -2942,11 +2945,18 @@ Supported keywords for slots are: | |||
| 2942 | forms) | 2945 | forms) |
| 2943 | (push kw desc) | 2946 | (push kw desc) |
| 2944 | (setcar defaults nil)))) | 2947 | (setcar defaults nil)))) |
| 2945 | (if (plist-get desc ':read-only) | 2948 | (cond |
| 2946 | (push `(gv-define-expander ,accessor | 2949 | ((eq defsym 'defun) |
| 2947 | (lambda (_cl-do _cl-x) | 2950 | (unless (plist-get desc ':read-only) |
| 2948 | (error "%s is a read-only slot" ',accessor))) | 2951 | (push `(defun ,(gv-setter accessor) (val cl-x) |
| 2949 | forms) | 2952 | (setf ,access-body val)) |
| 2953 | forms))) | ||
| 2954 | ((plist-get desc ':read-only) | ||
| 2955 | (push `(gv-define-expander ,accessor | ||
| 2956 | (lambda (_cl-do _cl-x) | ||
| 2957 | (error "%s is a read-only slot" ',accessor))) | ||
| 2958 | forms)) | ||
| 2959 | (t | ||
| 2950 | ;; For normal slots, we don't need to define a setf-expander, | 2960 | ;; For normal slots, we don't need to define a setf-expander, |
| 2951 | ;; since gv-get can use the compiler macro to get the | 2961 | ;; since gv-get can use the compiler macro to get the |
| 2952 | ;; same result. | 2962 | ;; same result. |
| @@ -2964,7 +2974,7 @@ Supported keywords for slots are: | |||
| 2964 | ;; ,(and pred-check `',pred-check) | 2974 | ;; ,(and pred-check `',pred-check) |
| 2965 | ;; ,pos))) | 2975 | ;; ,pos))) |
| 2966 | ;; forms) | 2976 | ;; forms) |
| 2967 | ) | 2977 | )) |
| 2968 | (if print-auto | 2978 | (if print-auto |
| 2969 | (nconc print-func | 2979 | (nconc print-func |
| 2970 | (list `(princ ,(format " %s" slot) cl-s) | 2980 | (list `(princ ,(format " %s" slot) cl-s) |