[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] scratch/record 0eaf0e6 05/10: Backward compatibility with
From: |
Lars Brinkhoff |
Subject: |
[Emacs-diffs] scratch/record 0eaf0e6 05/10: Backward compatibility with pre-existing struct instances. |
Date: |
Sun, 19 Mar 2017 05:34:12 -0400 (EDT) |
branch: scratch/record
commit 0eaf0e6735fcfb6cf0e7b4a2a038b4c6732649b7
Author: Lars Brinkhoff <address@hidden>
Commit: Lars Brinkhoff <address@hidden>
Backward compatibility with pre-existing struct instances.
If old-struct-compat is set to `t', `type-of' will make an educated
guess whether a vector is a legacy struct instance. If so, the
returned type will be the contents of slot 0.
* src/data.c (old_struct_prefix, old_struct_prefix_length): New variables.
(vector_struct_p, type_of_vector): New functions.
(Ftype_of): Call type_of_vector.
(old-struct-compat): New variable.
---
old-struct.el | 2 ++
src/data.c | 31 ++++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/old-struct.el b/old-struct.el
index 5f38801..1b89c14 100644
--- a/old-struct.el
+++ b/old-struct.el
@@ -12,3 +12,5 @@
;;(cl-struct-p (foo))
;;(memq (aref (foo) 0) cl-struct-cl-structure-object-tags)
;;(setq old-struct-compat t)
+;;(type-of [old])
+;;(type-of [cl-struct-old])
diff --git a/src/data.c b/src/data.c
index 8e0bccc..5a91d92 100644
--- a/src/data.c
+++ b/src/data.c
@@ -201,6 +201,30 @@ DEFUN ("null", Fnull, Snull, 1, 1, 0,
return Qnil;
}
+static const char *old_struct_prefix = "cl-struct-";
+static int old_struct_prefix_length;
+
+static int
+vector_struct_p (Lisp_Object object)
+{
+ if (! old_struct_compat || ASIZE (object) < 1)
+ return false;
+
+ Lisp_Object type = AREF (object, 0);
+ return SYMBOLP (type)
+ && strncmp (SDATA (SYMBOL_NAME (type)),
+ old_struct_prefix,
+ old_struct_prefix_length) == 0;
+}
+
+static Lisp_Object
+type_of_vector (Lisp_Object object)
+{
+ if (vector_struct_p (object))
+ return AREF (object, 0);
+ return Qvector;
+}
+
DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0,
doc: /* Return a symbol representing the type of OBJECT.
The symbol returned names the object's basic type;
@@ -243,7 +267,7 @@ for example, (type-of 1) returns `integer'. */)
case Lisp_Vectorlike:
switch (PSEUDOVECTOR_TYPE (XVECTOR (object)))
{
- case PVEC_NORMAL_VECTOR: return Qvector;
+ case PVEC_NORMAL_VECTOR: return type_of_vector (object);
case PVEC_WINDOW_CONFIGURATION: return Qwindow_configuration;
case PVEC_PROCESS: return Qprocess;
case PVEC_WINDOW: return Qwindow;
@@ -3873,6 +3897,11 @@ syms_of_data (void)
Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM);
make_symbol_constant (intern_c_string ("most-negative-fixnum"));
+ DEFVAR_BOOL ("old-struct-compat", old_struct_compat,
+ doc: /* Non-nil means hack for old structs is in effect. */);
+ old_struct_compat = 0;
+ old_struct_prefix_length = strlen (old_struct_prefix);
+
DEFSYM (Qwatchers, "watchers");
DEFSYM (Qmakunbound, "makunbound");
DEFSYM (Qunlet, "unlet");
- [Emacs-diffs] branch scratch/record created (now 5369952), Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 050463b 04/10: Test cases., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 7f9b0eb 06/10: Use sizeof to get length of cl-struct prefix., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record f89ce93 09/10: Make it possible to compare records with `equal'., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record b1d61ca 02/10: Update cl-defstruct to use records., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 97215ed 07/10: Better doc string for `old-struct-compat'., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 4c92cb0 03/10: Make EIEIO use records., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 5369952 10/10: Fix cl-print-object to find the object class the new way., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 7dfaded 01/10: Add record objects with user-defined types., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 7f51870 08/10: Better doc strings for `make-record', `record', and `copy-record'., Lars Brinkhoff, 2017/03/19
- [Emacs-diffs] scratch/record 0eaf0e6 05/10: Backward compatibility with pre-existing struct instances.,
Lars Brinkhoff <=