diff options
| author | Paul Eggert | 2019-04-01 11:54:23 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-04-01 12:02:37 -0700 |
| commit | 74b63d27a629db96b73a83f205d8a256911abc1c (patch) | |
| tree | 2c2128596c370b9c05f5e80d7805137426d35be1 /src/lisp.h | |
| parent | 9287813da1ae9076f29be111674d1795bee66447 (diff) | |
| download | emacs-74b63d27a629db96b73a83f205d8a256911abc1c.tar.gz emacs-74b63d27a629db96b73a83f205d8a256911abc1c.zip | |
Make struct Lisp_Objfwd etc. objects read-only
Initialize these objects statically, and make them constants.
This is a bit safer and more efficient.
* src/data.c (XBOOLFWD, XKBOARD_OBJFWD, XFIXNUMFWD, XOBJFWD):
* src/lisp.h (XBUFFER_OBJFWD):
Return a pointer-to-const instead of an unrestricted pointer.
(lispfwd): fwdptr is now a pointer-to-const instead of an
unrestricted pointer. All uses changed.
(SET_SYMBOL_FWD): Accept pointer-to-const instead of an
unrestricted pointer.
(DEFVAR_LISP, DEFVAR_LISP_NOPRO, DEFVAR_BOOL, DEFVAR_INT)
(DEFVAR_KBOARD): Initialize static structures statically
instead of dynamically, and make them const.
* src/lread.c (defvar_int, defvar_bool, defvar_lisp_nopro)
(defvar_lisp, defvar_kboard): Accept pointer-to-const instead
of an unrestricted pointer; it’s now the caller’s
responsibility to initialize the pointed-to storage. No need
for a separate address argument any more. All callers
changed.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/lisp.h b/src/lisp.h index 62c3230a148..a0a7cbdf518 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -803,7 +803,7 @@ INLINE void | |||
| 803 | union of the possible values (struct Lisp_Objfwd, struct | 803 | union of the possible values (struct Lisp_Objfwd, struct |
| 804 | Lisp_Intfwd, etc.). The pointer is packaged inside a struct to | 804 | Lisp_Intfwd, etc.). The pointer is packaged inside a struct to |
| 805 | help static checking. */ | 805 | help static checking. */ |
| 806 | typedef struct { void *fwdptr; } lispfwd; | 806 | typedef struct { void const *fwdptr; } lispfwd; |
| 807 | 807 | ||
| 808 | /* Interned state of a symbol. */ | 808 | /* Interned state of a symbol. */ |
| 809 | 809 | ||
| @@ -2204,7 +2204,7 @@ SET_SYMBOL_BLV (struct Lisp_Symbol *sym, struct Lisp_Buffer_Local_Value *v) | |||
| 2204 | sym->u.s.val.blv = v; | 2204 | sym->u.s.val.blv = v; |
| 2205 | } | 2205 | } |
| 2206 | INLINE void | 2206 | INLINE void |
| 2207 | SET_SYMBOL_FWD (struct Lisp_Symbol *sym, void *v) | 2207 | SET_SYMBOL_FWD (struct Lisp_Symbol *sym, void const *v) |
| 2208 | { | 2208 | { |
| 2209 | eassume (sym->u.s.redirect == SYMBOL_FORWARDED && v); | 2209 | eassume (sym->u.s.redirect == SYMBOL_FORWARDED && v); |
| 2210 | sym->u.s.val.fwd.fwdptr = v; | 2210 | sym->u.s.val.fwd.fwdptr = v; |
| @@ -2759,7 +2759,7 @@ struct Lisp_Kboard_Objfwd | |||
| 2759 | INLINE enum Lisp_Fwd_Type | 2759 | INLINE enum Lisp_Fwd_Type |
| 2760 | XFWDTYPE (lispfwd a) | 2760 | XFWDTYPE (lispfwd a) |
| 2761 | { | 2761 | { |
| 2762 | enum Lisp_Fwd_Type *p = a.fwdptr; | 2762 | enum Lisp_Fwd_Type const *p = a.fwdptr; |
| 2763 | return *p; | 2763 | return *p; |
| 2764 | } | 2764 | } |
| 2765 | 2765 | ||
| @@ -2769,7 +2769,7 @@ BUFFER_OBJFWDP (lispfwd a) | |||
| 2769 | return XFWDTYPE (a) == Lisp_Fwd_Buffer_Obj; | 2769 | return XFWDTYPE (a) == Lisp_Fwd_Buffer_Obj; |
| 2770 | } | 2770 | } |
| 2771 | 2771 | ||
| 2772 | INLINE struct Lisp_Buffer_Objfwd * | 2772 | INLINE struct Lisp_Buffer_Objfwd const * |
| 2773 | XBUFFER_OBJFWD (lispfwd a) | 2773 | XBUFFER_OBJFWD (lispfwd a) |
| 2774 | { | 2774 | { |
| 2775 | eassert (BUFFER_OBJFWDP (a)); | 2775 | eassert (BUFFER_OBJFWDP (a)); |
| @@ -3096,11 +3096,11 @@ enum maxargs | |||
| 3096 | CALLN is overkill for simple usages like 'Finsert (1, &text);'. */ | 3096 | CALLN is overkill for simple usages like 'Finsert (1, &text);'. */ |
| 3097 | #define CALLN(f, ...) CALLMANY (f, ((Lisp_Object []) {__VA_ARGS__})) | 3097 | #define CALLN(f, ...) CALLMANY (f, ((Lisp_Object []) {__VA_ARGS__})) |
| 3098 | 3098 | ||
| 3099 | extern void defvar_lisp (struct Lisp_Objfwd *, const char *, Lisp_Object *); | 3099 | extern void defvar_lisp (struct Lisp_Objfwd const *, char const *); |
| 3100 | extern void defvar_lisp_nopro (struct Lisp_Objfwd *, const char *, Lisp_Object *); | 3100 | extern void defvar_lisp_nopro (struct Lisp_Objfwd const *, char const *); |
| 3101 | extern void defvar_bool (struct Lisp_Boolfwd *, const char *, bool *); | 3101 | extern void defvar_bool (struct Lisp_Boolfwd const *, char const *); |
| 3102 | extern void defvar_int (struct Lisp_Intfwd *, const char *, intmax_t *); | 3102 | extern void defvar_int (struct Lisp_Intfwd const *, char const *); |
| 3103 | extern void defvar_kboard (struct Lisp_Kboard_Objfwd *, const char *, int); | 3103 | extern void defvar_kboard (struct Lisp_Kboard_Objfwd const *, char const *); |
| 3104 | 3104 | ||
| 3105 | /* Macros we use to define forwarded Lisp variables. | 3105 | /* Macros we use to define forwarded Lisp variables. |
| 3106 | These are used in the syms_of_FILENAME functions. | 3106 | These are used in the syms_of_FILENAME functions. |
| @@ -3121,29 +3121,34 @@ extern void defvar_kboard (struct Lisp_Kboard_Objfwd *, const char *, int); | |||
| 3121 | 3121 | ||
| 3122 | #define DEFVAR_LISP(lname, vname, doc) \ | 3122 | #define DEFVAR_LISP(lname, vname, doc) \ |
| 3123 | do { \ | 3123 | do { \ |
| 3124 | static struct Lisp_Objfwd o_fwd; \ | 3124 | static struct Lisp_Objfwd const o_fwd \ |
| 3125 | defvar_lisp (&o_fwd, lname, &globals.f_ ## vname); \ | 3125 | = {Lisp_Fwd_Obj, &globals.f_##vname}; \ |
| 3126 | defvar_lisp (&o_fwd, lname); \ | ||
| 3126 | } while (false) | 3127 | } while (false) |
| 3127 | #define DEFVAR_LISP_NOPRO(lname, vname, doc) \ | 3128 | #define DEFVAR_LISP_NOPRO(lname, vname, doc) \ |
| 3128 | do { \ | 3129 | do { \ |
| 3129 | static struct Lisp_Objfwd o_fwd; \ | 3130 | static struct Lisp_Objfwd const o_fwd \ |
| 3130 | defvar_lisp_nopro (&o_fwd, lname, &globals.f_ ## vname); \ | 3131 | = {Lisp_Fwd_Obj, &globals.f_##vname}; \ |
| 3132 | defvar_lisp_nopro (&o_fwd, lname); \ | ||
| 3131 | } while (false) | 3133 | } while (false) |
| 3132 | #define DEFVAR_BOOL(lname, vname, doc) \ | 3134 | #define DEFVAR_BOOL(lname, vname, doc) \ |
| 3133 | do { \ | 3135 | do { \ |
| 3134 | static struct Lisp_Boolfwd b_fwd; \ | 3136 | static struct Lisp_Boolfwd const b_fwd \ |
| 3135 | defvar_bool (&b_fwd, lname, &globals.f_ ## vname); \ | 3137 | = {Lisp_Fwd_Bool, &globals.f_##vname}; \ |
| 3138 | defvar_bool (&b_fwd, lname); \ | ||
| 3136 | } while (false) | 3139 | } while (false) |
| 3137 | #define DEFVAR_INT(lname, vname, doc) \ | 3140 | #define DEFVAR_INT(lname, vname, doc) \ |
| 3138 | do { \ | 3141 | do { \ |
| 3139 | static struct Lisp_Intfwd i_fwd; \ | 3142 | static struct Lisp_Intfwd const i_fwd \ |
| 3140 | defvar_int (&i_fwd, lname, &globals.f_ ## vname); \ | 3143 | = {Lisp_Fwd_Int, &globals.f_##vname}; \ |
| 3144 | defvar_int (&i_fwd, lname); \ | ||
| 3141 | } while (false) | 3145 | } while (false) |
| 3142 | 3146 | ||
| 3143 | #define DEFVAR_KBOARD(lname, vname, doc) \ | 3147 | #define DEFVAR_KBOARD(lname, vname, doc) \ |
| 3144 | do { \ | 3148 | do { \ |
| 3145 | static struct Lisp_Kboard_Objfwd ko_fwd; \ | 3149 | static struct Lisp_Kboard_Objfwd const ko_fwd \ |
| 3146 | defvar_kboard (&ko_fwd, lname, offsetof (KBOARD, vname ## _)); \ | 3150 | = {Lisp_Fwd_Kboard_Obj, offsetof (KBOARD, vname##_)}; \ |
| 3151 | defvar_kboard (&ko_fwd, lname); \ | ||
| 3147 | } while (false) | 3152 | } while (false) |
| 3148 | 3153 | ||
| 3149 | 3154 | ||