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/lread.c | |
| 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/lread.c')
| -rw-r--r-- | src/lread.c | 42 |
1 files changed, 12 insertions, 30 deletions
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); |