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 | |
| 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')
| -rw-r--r-- | src/data.c | 8 | ||||
| -rw-r--r-- | src/lisp.h | 43 | ||||
| -rw-r--r-- | src/lread.c | 42 |
3 files changed, 40 insertions, 53 deletions
diff --git a/src/data.c b/src/data.c index 936bb74f69a..11cd598ed85 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -62,25 +62,25 @@ OBJFWDP (lispfwd a) | |||
| 62 | return XFWDTYPE (a) == Lisp_Fwd_Obj; | 62 | return XFWDTYPE (a) == Lisp_Fwd_Obj; |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | static struct Lisp_Boolfwd * | 65 | static struct Lisp_Boolfwd const * |
| 66 | XBOOLFWD (lispfwd a) | 66 | XBOOLFWD (lispfwd a) |
| 67 | { | 67 | { |
| 68 | eassert (BOOLFWDP (a)); | 68 | eassert (BOOLFWDP (a)); |
| 69 | return a.fwdptr; | 69 | return a.fwdptr; |
| 70 | } | 70 | } |
| 71 | static struct Lisp_Kboard_Objfwd * | 71 | static struct Lisp_Kboard_Objfwd const * |
| 72 | XKBOARD_OBJFWD (lispfwd a) | 72 | XKBOARD_OBJFWD (lispfwd a) |
| 73 | { | 73 | { |
| 74 | eassert (KBOARD_OBJFWDP (a)); | 74 | eassert (KBOARD_OBJFWDP (a)); |
| 75 | return a.fwdptr; | 75 | return a.fwdptr; |
| 76 | } | 76 | } |
| 77 | static struct Lisp_Intfwd * | 77 | static struct Lisp_Intfwd const * |
| 78 | XFIXNUMFWD (lispfwd a) | 78 | XFIXNUMFWD (lispfwd a) |
| 79 | { | 79 | { |
| 80 | eassert (INTFWDP (a)); | 80 | eassert (INTFWDP (a)); |
| 81 | return a.fwdptr; | 81 | return a.fwdptr; |
| 82 | } | 82 | } |
| 83 | static struct Lisp_Objfwd * | 83 | static struct Lisp_Objfwd const * |
| 84 | XOBJFWD (lispfwd a) | 84 | XOBJFWD (lispfwd a) |
| 85 | { | 85 | { |
| 86 | eassert (OBJFWDP (a)); | 86 | eassert (OBJFWDP (a)); |
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 | ||
diff --git a/src/lread.c b/src/lread.c index dd35cf9063e..5f33fcd6957 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -4425,28 +4425,19 @@ defalias (struct Lisp_Subr *sname, char *string) | |||
| 4425 | C variable of type intmax_t. Sample call (with "xx" to fool make-docfile): | 4425 | C variable of type intmax_t. Sample call (with "xx" to fool make-docfile): |
| 4426 | DEFxxVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */ | 4426 | DEFxxVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */ |
| 4427 | void | 4427 | void |
| 4428 | defvar_int (struct Lisp_Intfwd *i_fwd, | 4428 | defvar_int (struct Lisp_Intfwd const *i_fwd, char const *namestring) |
| 4429 | const char *namestring, intmax_t *address) | ||
| 4430 | { | 4429 | { |
| 4431 | Lisp_Object sym; | 4430 | Lisp_Object sym = intern_c_string (namestring); |
| 4432 | sym = intern_c_string (namestring); | ||
| 4433 | i_fwd->type = Lisp_Fwd_Int; | ||
| 4434 | i_fwd->intvar = address; | ||
| 4435 | XSYMBOL (sym)->u.s.declared_special = true; | 4431 | XSYMBOL (sym)->u.s.declared_special = true; |
| 4436 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; | 4432 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; |
| 4437 | SET_SYMBOL_FWD (XSYMBOL (sym), i_fwd); | 4433 | SET_SYMBOL_FWD (XSYMBOL (sym), i_fwd); |
| 4438 | } | 4434 | } |
| 4439 | 4435 | ||
| 4440 | /* Similar but define a variable whose value is t if address contains 1, | 4436 | /* Similar but define a variable whose value is t if 1, nil if 0. */ |
| 4441 | nil if address contains 0. */ | ||
| 4442 | void | 4437 | void |
| 4443 | defvar_bool (struct Lisp_Boolfwd *b_fwd, | 4438 | defvar_bool (struct Lisp_Boolfwd const *b_fwd, char const *namestring) |
| 4444 | const char *namestring, bool *address) | ||
| 4445 | { | 4439 | { |
| 4446 | Lisp_Object sym; | 4440 | Lisp_Object sym = intern_c_string (namestring); |
| 4447 | sym = intern_c_string (namestring); | ||
| 4448 | b_fwd->type = Lisp_Fwd_Bool; | ||
| 4449 | b_fwd->boolvar = address; | ||
| 4450 | XSYMBOL (sym)->u.s.declared_special = true; | 4441 | XSYMBOL (sym)->u.s.declared_special = true; |
| 4451 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; | 4442 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; |
| 4452 | SET_SYMBOL_FWD (XSYMBOL (sym), b_fwd); | 4443 | SET_SYMBOL_FWD (XSYMBOL (sym), b_fwd); |
| @@ -4459,37 +4450,28 @@ defvar_bool (struct Lisp_Boolfwd *b_fwd, | |||
| 4459 | gc-marked for some other reason, since marking the same slot twice | 4450 | gc-marked for some other reason, since marking the same slot twice |
| 4460 | can cause trouble with strings. */ | 4451 | can cause trouble with strings. */ |
| 4461 | void | 4452 | void |
| 4462 | defvar_lisp_nopro (struct Lisp_Objfwd *o_fwd, | 4453 | defvar_lisp_nopro (struct Lisp_Objfwd const *o_fwd, char const *namestring) |
| 4463 | const char *namestring, Lisp_Object *address) | ||
| 4464 | { | 4454 | { |
| 4465 | Lisp_Object sym; | 4455 | Lisp_Object sym = intern_c_string (namestring); |
| 4466 | sym = intern_c_string (namestring); | ||
| 4467 | o_fwd->type = Lisp_Fwd_Obj; | ||
| 4468 | o_fwd->objvar = address; | ||
| 4469 | XSYMBOL (sym)->u.s.declared_special = true; | 4456 | XSYMBOL (sym)->u.s.declared_special = true; |
| 4470 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; | 4457 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; |
| 4471 | SET_SYMBOL_FWD (XSYMBOL (sym), o_fwd); | 4458 | SET_SYMBOL_FWD (XSYMBOL (sym), o_fwd); |
| 4472 | } | 4459 | } |
| 4473 | 4460 | ||
| 4474 | void | 4461 | void |
| 4475 | defvar_lisp (struct Lisp_Objfwd *o_fwd, | 4462 | defvar_lisp (struct Lisp_Objfwd const *o_fwd, char const *namestring) |
| 4476 | const char *namestring, Lisp_Object *address) | ||
| 4477 | { | 4463 | { |
| 4478 | defvar_lisp_nopro (o_fwd, namestring, address); | 4464 | defvar_lisp_nopro (o_fwd, namestring); |
| 4479 | staticpro (address); | 4465 | staticpro (o_fwd->objvar); |
| 4480 | } | 4466 | } |
| 4481 | 4467 | ||
| 4482 | /* Similar but define a variable whose value is the Lisp Object stored | 4468 | /* Similar but define a variable whose value is the Lisp Object stored |
| 4483 | at a particular offset in the current kboard object. */ | 4469 | at a particular offset in the current kboard object. */ |
| 4484 | 4470 | ||
| 4485 | void | 4471 | void |
| 4486 | defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd, | 4472 | defvar_kboard (struct Lisp_Kboard_Objfwd const *ko_fwd, char const *namestring) |
| 4487 | const char *namestring, int offset) | ||
| 4488 | { | 4473 | { |
| 4489 | Lisp_Object sym; | 4474 | Lisp_Object sym = intern_c_string (namestring); |
| 4490 | sym = intern_c_string (namestring); | ||
| 4491 | ko_fwd->type = Lisp_Fwd_Kboard_Obj; | ||
| 4492 | ko_fwd->offset = offset; | ||
| 4493 | XSYMBOL (sym)->u.s.declared_special = true; | 4475 | XSYMBOL (sym)->u.s.declared_special = true; |
| 4494 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; | 4476 | XSYMBOL (sym)->u.s.redirect = SYMBOL_FORWARDED; |
| 4495 | SET_SYMBOL_FWD (XSYMBOL (sym), ko_fwd); | 4477 | SET_SYMBOL_FWD (XSYMBOL (sym), ko_fwd); |