aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2017-04-07 18:54:40 -0700
committerPaul Eggert2017-04-07 18:54:40 -0700
commita2b3fea957440b8358d3632a4a05e41dee964b5d (patch)
treea6ef4cf0ba807dfad9ae91b4bfde1935dc999a5f
parenta614cd416c5dd71702428a008992589395a722fc (diff)
downloademacs-a2b3fea957440b8358d3632a4a05e41dee964b5d.tar.gz
emacs-a2b3fea957440b8358d3632a4a05e41dee964b5d.zip
Deprecate copy-record in favor of copy-sequence
Since copy-sequence seems to be needed anyway for records, have it work on records, and remove copy-record as being superfluous. * doc/lispref/records.texi (Records, Record Functions): * lisp/emacs-lisp/cl-macs.el (cl-defstruct): * lisp/emacs-lisp/eieio.el (make-instance, clone): * test/src/alloc-tests.el (record-3): Use copy-sequence, not copy-record, to copy records. * doc/lispref/sequences.texi (Sequence Functions) (Array Functions): Document that aref and copy-sequence work on records. * etc/NEWS: Omit copy-record. * src/alloc.c (Fcopy_record): Remove. * src/data.c (Faref): Document that arg can be a record. * src/fns.c (Fcopy_sequence): Copy records, too.
-rw-r--r--doc/lispref/records.texi37
-rw-r--r--doc/lispref/sequences.texi23
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/emacs-lisp/cl-macs.el3
-rw-r--r--lisp/emacs-lisp/eieio.el6
-rw-r--r--src/alloc.c14
-rw-r--r--src/data.c4
-rw-r--r--src/fns.c12
-rw-r--r--test/src/alloc-tests.el2
9 files changed, 33 insertions, 74 deletions
diff --git a/doc/lispref/records.texi b/doc/lispref/records.texi
index 2533a8a4ca1..7cc36f14068 100644
--- a/doc/lispref/records.texi
+++ b/doc/lispref/records.texi
@@ -13,8 +13,9 @@ underlying representation of @code{cl-defstruct} and @code{defclass}
13instances. 13instances.
14 14
15 Internally, a record object is much like a vector; its slots can be 15 Internally, a record object is much like a vector; its slots can be
16accessed using @code{aref}. However, the first slot is used to hold 16accessed using @code{aref} and it can be copied using
17its type as returned by @code{type-of}. Also, in the current 17@code{copy-sequence}. However, the first slot is used to hold its
18type as returned by @code{type-of}. Also, in the current
18implementation records can have at most 4096 slots, whereas vectors 19implementation records can have at most 4096 slots, whereas vectors
19can be much larger. Like arrays, records use zero-origin indexing: 20can be much larger. Like arrays, records use zero-origin indexing:
20the first slot has index 0. 21the first slot has index 0.
@@ -74,38 +75,6 @@ This function returns a new record with type @var{type} and
74@end example 75@end example
75@end defun 76@end defun
76 77
77@defun copy-record record
78This function returns a shallow copy of @var{record}. The copy is the
79same type as the original record, and it has the same slots in the
80same order.
81
82 Storing a new slot into the copy does not affect the original
83@var{record}, and vice versa. However, the slots of the new record
84are not copies; they are identical (@code{eq}) to the slots of the
85original. Therefore, changes made within these slots, as found via
86the copied record, are also visible in the original record.
87
88@example
89@group
90(setq x (record 'foo 1 2))
91 @result{} #s(foo 1 2)
92@end group
93@group
94(setq y (copy-record x))
95 @result{} #s(foo 1 2)
96@end group
97
98@group
99(eq x y)
100 @result{} nil
101@end group
102@group
103(equal x y)
104 @result{} t
105@end group
106@end example
107@end defun
108
109@node Backward Compatibility 78@node Backward Compatibility
110@section Backward Compatibility 79@section Backward Compatibility
111 80
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 2c88ee38cb1..93e8fa8a5fa 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -151,20 +151,19 @@ This function generalizes @code{aref} (@pxref{Array Functions}) and
151@code{nth} (@pxref{Definition of nth}). 151@code{nth} (@pxref{Definition of nth}).
152@end defun 152@end defun
153 153
154@defun copy-sequence sequence 154@defun copy-sequence seqr
155@cindex copying sequences 155@cindex copying sequences
156This function returns a copy of @var{sequence}. The copy is the same 156This function returns a copy of @var{seqr}, which should be either a
157type of object as the original sequence, and it has the same elements 157sequence or a record. The copy is the same type of object as the
158in the same order. 158original, and it has the same elements in the same order.
159 159
160Storing a new element into the copy does not affect the original 160Storing a new element into the copy does not affect the original
161@var{sequence}, and vice versa. However, the elements of the new 161@var{seqr}, and vice versa. However, the elements of the copy
162sequence are not copies; they are identical (@code{eq}) to the elements 162are not copies; they are identical (@code{eq}) to the elements
163of the original. Therefore, changes made within these elements, as 163of the original. Therefore, changes made within these elements, as
164found via the copied sequence, are also visible in the original 164found via the copy, are also visible in the original.
165sequence.
166 165
167If the sequence is a string with text properties, the property list in 166If the argument is a string with text properties, the property list in
168the copy is itself a copy, not shared with the original's property 167the copy is itself a copy, not shared with the original's property
169list. However, the actual values of the properties are shared. 168list. However, the actual values of the properties are shared.
170@xref{Text Properties}. 169@xref{Text Properties}.
@@ -1148,10 +1147,10 @@ vector, a string, a bool-vector or a char-table).
1148@end example 1147@end example
1149@end defun 1148@end defun
1150 1149
1151@defun aref array index 1150@defun aref arr index
1152@cindex array elements 1151@cindex array elements
1153This function returns the @var{index}th element of @var{array}. The 1152This function returns the @var{index}th element of the array or record
1154first element is at index zero. 1153@var{arr}. The first element is at index zero.
1155 1154
1156@example 1155@example
1157@group 1156@group
diff --git a/etc/NEWS b/etc/NEWS
index aaca229d5cd..e351abc159f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -863,9 +863,9 @@ instead of its first.
863 863
864+++ 864+++
865** Emacs now supports records for user-defined types, via the new 865** Emacs now supports records for user-defined types, via the new
866functions 'copy-record', 'make-record', 'record', and 'recordp'. 866functions 'make-record', 'record', and 'recordp'. Records are now
867Records are now used internally to represent cl-defstruct and defclass 867used internally to represent cl-defstruct and defclass instances, for
868instances, for example. 868example.
869 869
870+++ 870+++
871** 'save-some-buffers' now uses 'save-some-buffers-default-predicate' 871** 'save-some-buffers' now uses 'save-some-buffers-default-predicate'
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 25c9f999920..ecb89fd51d7 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2808,8 +2808,7 @@ non-nil value, that slot cannot be set via `setf'.
2808 (setq slots (nreverse slots) 2808 (setq slots (nreverse slots)
2809 defaults (nreverse defaults)) 2809 defaults (nreverse defaults))
2810 (and copier 2810 (and copier
2811 (push `(defalias ',copier 2811 (push `(defalias ',copier #'copy-sequence)
2812 ,(if (null type) '#'copy-record '#'copy-sequence))
2813 forms)) 2812 forms))
2814 (if constructor 2813 (if constructor
2815 (push (list constructor 2814 (push (list constructor
diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el
index 858b2fdaa04..e21d46e5289 100644
--- a/lisp/emacs-lisp/eieio.el
+++ b/lisp/emacs-lisp/eieio.el
@@ -699,8 +699,8 @@ SLOTS are the initialization slots used by `initialize-instance'.
699This static method is called when an object is constructed. 699This static method is called when an object is constructed.
700It allocates the vector used to represent an EIEIO object, and then 700It allocates the vector used to represent an EIEIO object, and then
701calls `initialize-instance' on that object." 701calls `initialize-instance' on that object."
702 (let* ((new-object (copy-record (eieio--class-default-object-cache 702 (let* ((new-object (copy-sequence (eieio--class-default-object-cache
703 (eieio--class-object class))))) 703 (eieio--class-object class)))))
704 (if (and slots 704 (if (and slots
705 (let ((x (car slots))) 705 (let ((x (car slots)))
706 (or (stringp x) (null x)))) 706 (or (stringp x) (null x))))
@@ -804,7 +804,7 @@ first and modify the returned object.")
804 804
805(cl-defmethod clone ((obj eieio-default-superclass) &rest params) 805(cl-defmethod clone ((obj eieio-default-superclass) &rest params)
806 "Make a copy of OBJ, and then apply PARAMS." 806 "Make a copy of OBJ, and then apply PARAMS."
807 (let ((nobj (copy-record obj))) 807 (let ((nobj (copy-sequence obj)))
808 (if (stringp (car params)) 808 (if (stringp (car params))
809 (funcall (if eieio-backward-compatibility #'ignore #'message) 809 (funcall (if eieio-backward-compatibility #'ignore #'message)
810 "Obsolete name %S passed to clone" (pop params))) 810 "Obsolete name %S passed to clone" (pop params)))
diff --git a/src/alloc.c b/src/alloc.c
index fad84b8a0b3..88a1a1ed660 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3440,19 +3440,6 @@ usage: (record TYPE &rest SLOTS) */)
3440} 3440}
3441 3441
3442 3442
3443DEFUN ("copy-record", Fcopy_record, Scopy_record, 1, 1, 0,
3444 doc: /* Return a new record that is a shallow copy of the argument RECORD. */)
3445 (Lisp_Object record)
3446{
3447 CHECK_RECORD (record);
3448 ptrdiff_t size = ASIZE (record) & PSEUDOVECTOR_SIZE_MASK;
3449 struct Lisp_Vector *new = allocate_record (size);
3450 memcpy (new->contents, XVECTOR (record)->contents,
3451 size * sizeof (Lisp_Object));
3452 return make_lisp_ptr (new, Lisp_Vectorlike);
3453}
3454
3455
3456DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, 3443DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
3457 doc: /* Return a newly created vector of length LENGTH, with each element being INIT. 3444 doc: /* Return a newly created vector of length LENGTH, with each element being INIT.
3458See also the function `vector'. */) 3445See also the function `vector'. */)
@@ -7523,7 +7510,6 @@ The time is in seconds as a floating point value. */);
7523 defsubr (&Slist); 7510 defsubr (&Slist);
7524 defsubr (&Svector); 7511 defsubr (&Svector);
7525 defsubr (&Srecord); 7512 defsubr (&Srecord);
7526 defsubr (&Scopy_record);
7527 defsubr (&Sbool_vector); 7513 defsubr (&Sbool_vector);
7528 defsubr (&Smake_byte_code); 7514 defsubr (&Smake_byte_code);
7529 defsubr (&Smake_list); 7515 defsubr (&Smake_list);
diff --git a/src/data.c b/src/data.c
index 3ffca54658d..903e809d235 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2266,8 +2266,8 @@ function chain of symbols. */)
2266/* Extract and set vector and string elements. */ 2266/* Extract and set vector and string elements. */
2267 2267
2268DEFUN ("aref", Faref, Saref, 2, 2, 0, 2268DEFUN ("aref", Faref, Saref, 2, 2, 0,
2269 doc: /* Return the element of ARRAY at index IDX. 2269 doc: /* Return the element of ARG at index IDX.
2270ARRAY may be a vector, a string, a char-table, a bool-vector, 2270ARG may be a vector, a string, a char-table, a bool-vector, a record,
2271or a byte-code object. IDX starts at 0. */) 2271or a byte-code object. IDX starts at 0. */)
2272 (register Lisp_Object array, Lisp_Object idx) 2272 (register Lisp_Object array, Lisp_Object idx)
2273{ 2273{
diff --git a/src/fns.c b/src/fns.c
index 47da5f8b4bc..2f07c2ccfb7 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -475,13 +475,19 @@ usage: (vconcat &rest SEQUENCES) */)
475 475
476 476
477DEFUN ("copy-sequence", Fcopy_sequence, Scopy_sequence, 1, 1, 0, 477DEFUN ("copy-sequence", Fcopy_sequence, Scopy_sequence, 1, 1, 0,
478 doc: /* Return a copy of a list, vector, string or char-table. 478 doc: /* Return a copy of a list, vector, string, char-table or record.
479The elements of a list or vector are not copied; they are shared 479The elements of a list, vector or record are not copied; they are
480with the original. */) 480shared with the original. */)
481 (Lisp_Object arg) 481 (Lisp_Object arg)
482{ 482{
483 if (NILP (arg)) return arg; 483 if (NILP (arg)) return arg;
484 484
485 if (RECORDP (arg))
486 {
487 ptrdiff_t size = ASIZE (arg) & PSEUDOVECTOR_SIZE_MASK;
488 return Frecord (size, XVECTOR (arg)->contents);
489 }
490
485 if (CHAR_TABLE_P (arg)) 491 if (CHAR_TABLE_P (arg))
486 { 492 {
487 return copy_char_table (arg); 493 return copy_char_table (arg);
diff --git a/test/src/alloc-tests.el b/test/src/alloc-tests.el
index 8b4ef8ce7d2..1cf1fc3be5c 100644
--- a/test/src/alloc-tests.el
+++ b/test/src/alloc-tests.el
@@ -47,7 +47,7 @@
47 47
48(ert-deftest record-3 () 48(ert-deftest record-3 ()
49 (let* ((x (record 'foo 1 2 3)) 49 (let* ((x (record 'foo 1 2 3))
50 (y (copy-record x))) 50 (y (copy-sequence x)))
51 (should-not (eq x y)) 51 (should-not (eq x y))
52 (dotimes (i 4) 52 (dotimes (i 4)
53 (should (eql (aref x i) (aref y i)))))) 53 (should (eql (aref x i) (aref y i))))))