From 5e2327cf928d947328b01c87baa79cdaa18c823b Mon Sep 17 00:00:00 2001 From: Dan Nicolaescu Date: Fri, 6 Nov 2009 06:07:46 +0000 Subject: [PATCH] * process.c (socket_options): Make it const. (set_socket_option, init_process): Use a const pointer. * lread.c (intern_c_string): New function. (defvar_kboard, defvar_lisp, defvar_lisp_nopro, defvar_bool) (defvar_int): Uset it. Make the name const char*. * lisp.h (defvar_kboard, defvar_lisp, defvar_lisp_nopro, defvar_bool) (defvar_int): Update prototypes. (DEFUN, EXFUN): Support for prototypes is now required. (intern_c_string): New prototype. (struct Lisp_Subr): Make symbol_name constant. * font.c (struct table_entry): Remove unused member. Make NAMES constant. (weight_table, slant_table, width_table): Make constant. * emacs.c (struct standard_args): Make name and longname constant. * character.h (DEFSYM): Use intern_c_string. --- src/ChangeLog | 23 ++++++++++++++++++++++ src/character.h | 2 +- src/emacs.c | 6 +++--- src/font.c | 9 ++++----- src/lisp.h | 32 ++++++++----------------------- src/lread.c | 51 +++++++++++++++++++++++++++++++------------------ src/process.c | 6 +++--- 7 files changed, 74 insertions(+), 55 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f79489fe4fa..cde49c410b9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,26 @@ +2009-11-06 Dan Nicolaescu + + * process.c (socket_options): Make it const. + (set_socket_option, init_process): Use a const pointer. + + * lread.c (intern_c_string): New function. + (defvar_kboard, defvar_lisp, defvar_lisp_nopro, defvar_bool) + (defvar_int): Uset it. Make the name const char*. + + * lisp.h (defvar_kboard, defvar_lisp, defvar_lisp_nopro, defvar_bool) + (defvar_int): Update prototypes. + (DEFUN, EXFUN): Support for prototypes is now required. + (intern_c_string): New prototype. + (struct Lisp_Subr): Make symbol_name constant. + + * font.c (struct table_entry): Remove unused member. Make NAMES + constant. + (weight_table, slant_table, width_table): Make constant. + + * emacs.c (struct standard_args): Make name and longname constant. + + * character.h (DEFSYM): Use intern_c_string. + 2009-11-06 Stefan Monnier * alloc.c (make_pure_c_string): New function. diff --git a/src/character.h b/src/character.h index 7b6bcd1a5ae..78065597532 100644 --- a/src/character.h +++ b/src/character.h @@ -672,7 +672,7 @@ extern Lisp_Object Vscript_representative_chars; } while (0) #define DEFSYM(sym, name) \ - do { (sym) = intern ((name)); staticpro (&(sym)); } while (0) + do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (0) #endif /* EMACS_CHARACTER_H */ diff --git a/src/emacs.c b/src/emacs.c index 3f43904fa0c..ce34f11591b 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1836,13 +1836,13 @@ main (int argc, char **argv) struct standard_args { - char *name; - char *longname; + const char *name; + const char *longname; int priority; int nargs; }; -struct standard_args standard_args[] = +const struct standard_args standard_args[] = { { "-version", "--version", 150, 0 }, #ifdef HAVE_SHM diff --git a/src/font.c b/src/font.c index 6e33b9bec55..dd9b6d374be 100644 --- a/src/font.c +++ b/src/font.c @@ -79,14 +79,13 @@ struct table_entry int numeric; /* The first one is a valid name as a face attribute. The second one (if any) is a typical name in XLFD field. */ - char *names[5]; - Lisp_Object *symbols; + const char *names[5]; }; /* Table of weight numeric values and their names. This table must be sorted by numeric values in ascending order. */ -static struct table_entry weight_table[] = +static const struct table_entry weight_table[] = { { 0, { "thin" }}, { 20, { "ultra-light", "ultralight" }}, @@ -103,7 +102,7 @@ static struct table_entry weight_table[] = /* Table of slant numeric values and their names. This table must be sorted by numeric values in ascending order. */ -static struct table_entry slant_table[] = +static const struct table_entry slant_table[] = { { 0, { "reverse-oblique", "ro" }}, { 10, { "reverse-italic", "ri" }}, @@ -115,7 +114,7 @@ static struct table_entry slant_table[] = /* Table of width numeric values and their names. This table must be sorted by numeric values in ascending order. */ -static struct table_entry width_table[] = +static const struct table_entry width_table[] = { { 50, { "ultra-condensed", "ultracondensed" }}, { 63, { "extra-condensed", "extracondensed" }}, diff --git a/src/lisp.h b/src/lisp.h index 19950f79055..95759c18f51 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -922,7 +922,7 @@ struct Lisp_Subr EMACS_UINT size; Lisp_Object (*function) (); short min_args, max_args; - char *symbol_name; + const char *symbol_name; char *intspec; char *doc; }; @@ -1701,17 +1701,6 @@ typedef struct { A null string means call interactively with no arguments. `doc' is documentation for the user. */ -#if (!defined (__STDC__) && !defined (PROTOTYPES)) - -#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ - Lisp_Object fnname (); \ - DECL_ALIGN (struct Lisp_Subr, sname) = \ - { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ - fnname, minargs, maxargs, lname, intspec, 0}; \ - Lisp_Object fnname - -#else - /* This version of DEFUN declares a function prototype with the right arguments, so we can catch errors with maxargs at compile-time. */ #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ @@ -1738,8 +1727,6 @@ typedef struct { Lisp_Object, Lisp_Object, Lisp_Object) #define DEFUN_ARGS_8 (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, \ Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object) -#endif - /* Non-zero if OBJ is a Lisp function. */ #define FUNCTIONP(OBJ) \ @@ -1755,11 +1742,11 @@ extern void defsubr P_ ((struct Lisp_Subr *)); #define MANY -2 #define UNEVALLED -1 -extern void defvar_lisp P_ ((char *, Lisp_Object *)); -extern void defvar_lisp_nopro P_ ((char *, Lisp_Object *)); -extern void defvar_bool P_ ((char *, int *)); -extern void defvar_int P_ ((char *, EMACS_INT *)); -extern void defvar_kboard P_ ((char *, int)); +extern void defvar_lisp (const char *, Lisp_Object *); +extern void defvar_lisp_nopro (const char *, Lisp_Object *); +extern void defvar_bool (const char *, int *); +extern void defvar_int (const char *, EMACS_INT *); +extern void defvar_kboard (const char *, int); /* Macros we use to define forwarded Lisp variables. These are used in the syms_of_FILENAME functions. */ @@ -2185,15 +2172,10 @@ void staticpro P_ ((Lisp_Object *)); /* Declare a Lisp-callable function. The MAXARGS parameter has the same meaning as in the DEFUN macro, and is used to construct a prototype. */ -#if (!defined (__STDC__) && !defined (PROTOTYPES)) -#define EXFUN(fnname, maxargs) \ - extern Lisp_Object fnname () -#else /* We can use the same trick as in the DEFUN macro to generate the appropriate prototype. */ #define EXFUN(fnname, maxargs) \ extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs -#endif /* Forward declarations for prototypes. */ struct window; @@ -2654,6 +2636,7 @@ extern Lisp_Object make_string_from_bytes P_ ((const char *, int, int)); extern Lisp_Object make_specified_string P_ ((const char *, int, int, int)); EXFUN (Fpurecopy, 1); extern Lisp_Object make_pure_string P_ ((char *, int, int, int)); +extern Lisp_Object make_pure_c_string (const char *data); extern Lisp_Object pure_cons P_ ((Lisp_Object, Lisp_Object)); extern Lisp_Object make_pure_vector P_ ((EMACS_INT)); EXFUN (Fgarbage_collect, 0); @@ -2752,6 +2735,7 @@ extern Lisp_Object read_filtered_event P_ ((int, int, int, int, Lisp_Object)); EXFUN (Feval_region, 4); extern Lisp_Object check_obarray P_ ((Lisp_Object)); extern Lisp_Object intern P_ ((const char *)); +extern Lisp_Object intern_c_string (const char *); extern Lisp_Object make_symbol P_ ((char *)); extern Lisp_Object oblookup P_ ((Lisp_Object, const char *, int, int)); #define LOADHIST_ATTACH(x) \ diff --git a/src/lread.c b/src/lread.c index ada447f7c50..517f14baf56 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3622,6 +3622,29 @@ intern (str) return Fintern (make_string (str, len), obarray); } +Lisp_Object +intern_c_string (const char *str) +{ + Lisp_Object tem; + int len = strlen (str); + Lisp_Object obarray; + + obarray = Vobarray; + if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0) + obarray = check_obarray (obarray); + tem = oblookup (obarray, str, len, len); + if (SYMBOLP (tem)) + return tem; + + if (NILP (Vpurify_flag)) + /* Creating a non-pure string from a string literal not + implemented yet. We could just use make_string here and live + with the extra copy. */ + abort (); + + return Fintern (make_pure_c_string (str), obarray); +} + /* Create an uninterned symbol with name STR. */ Lisp_Object @@ -3956,12 +3979,10 @@ defalias (sname, string) to a C variable of type int. Sample call: DEFVAR_INT ("emacs-priority", &emacs_priority, "Documentation"); */ void -defvar_int (namestring, address) - char *namestring; - EMACS_INT *address; +defvar_int (const char *namestring, EMACS_INT *address) { Lisp_Object sym, val; - sym = intern (namestring); + sym = intern_c_string (namestring); val = allocate_misc (); XMISCTYPE (val) = Lisp_Misc_Intfwd; XINTFWD (val)->intvar = address; @@ -3971,12 +3992,10 @@ defvar_int (namestring, address) /* Similar but define a variable whose value is t if address contains 1, nil if address contains 0. */ void -defvar_bool (namestring, address) - char *namestring; - int *address; +defvar_bool (const char *namestring, int *address) { Lisp_Object sym, val; - sym = intern (namestring); + sym = intern_c_string (namestring); val = allocate_misc (); XMISCTYPE (val) = Lisp_Misc_Boolfwd; XBOOLFWD (val)->boolvar = address; @@ -3990,12 +4009,10 @@ defvar_bool (namestring, address) gc-marked for some other reason, since marking the same slot twice can cause trouble with strings. */ void -defvar_lisp_nopro (namestring, address) - char *namestring; - Lisp_Object *address; +defvar_lisp_nopro (const char *namestring, Lisp_Object *address) { Lisp_Object sym, val; - sym = intern (namestring); + sym = intern_c_string (namestring); val = allocate_misc (); XMISCTYPE (val) = Lisp_Misc_Objfwd; XOBJFWD (val)->objvar = address; @@ -4003,9 +4020,7 @@ defvar_lisp_nopro (namestring, address) } void -defvar_lisp (namestring, address) - char *namestring; - Lisp_Object *address; +defvar_lisp (const char *namestring, Lisp_Object *address) { defvar_lisp_nopro (namestring, address); staticpro (address); @@ -4015,12 +4030,10 @@ defvar_lisp (namestring, address) at a particular offset in the current kboard object. */ void -defvar_kboard (namestring, offset) - char *namestring; - int offset; +defvar_kboard (const char *namestring, int offset) { Lisp_Object sym, val; - sym = intern (namestring); + sym = intern_c_string (namestring); val = allocate_misc (); XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd; XKBOARD_OBJFWD (val)->offset = offset; diff --git a/src/process.c b/src/process.c index c2fe343ee2d..7cb85d73aad 100644 --- a/src/process.c +++ b/src/process.c @@ -2607,7 +2607,7 @@ Returns nil upon error setting address, ADDRESS otherwise. */) #endif -static struct socket_options { +static const struct socket_options { /* The name of this option. Should be lowercase version of option name without SO_ prefix. */ char *name; @@ -2658,7 +2658,7 @@ set_socket_option (s, opt, val) Lisp_Object opt, val; { char *name; - struct socket_options *sopt; + const struct socket_options *sopt; int ret = 0; CHECK_SYMBOL (opt); @@ -7314,7 +7314,7 @@ init_process () #ifdef HAVE_SOCKETS { Lisp_Object subfeatures = Qnil; - struct socket_options *sopt; + const struct socket_options *sopt; #define ADD_SUBFEATURE(key, val) \ subfeatures = Fcons (Fcons (key, Fcons (val, Qnil)), subfeatures) -- 2.39.2