From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Emacs rewrite in a maintainable language Date: Mon, 12 Oct 2015 15:39:11 -0700 Organization: UCLA Computer Science Department Message-ID: <561C368F.6010306@cs.ucla.edu> References: <561A19AB.5060001@cumego.com> <87io6dl0h0.fsf@wanadoo.es> <87lhb82qxc.fsf@gmail.com> <878u78b3hg.fsf@fencepost.gnu.org> <87h9lwyv33.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------000005040107090007090308" X-Trace: ger.gmane.org 1444689587 28999 80.91.229.3 (12 Oct 2015 22:39:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 12 Oct 2015 22:39:47 +0000 (UTC) Cc: emacs-devel@gnu.org To: Oleh Krehel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 13 00:39:36 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zllkl-0000sn-Ti for ged-emacs-devel@m.gmane.org; Tue, 13 Oct 2015 00:39:36 +0200 Original-Received: from localhost ([::1]:59142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zllkk-0008AO-WA for ged-emacs-devel@m.gmane.org; Mon, 12 Oct 2015 18:39:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40739) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZllkU-0008AF-GG for emacs-devel@gnu.org; Mon, 12 Oct 2015 18:39:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZllkR-0007ln-7u for emacs-devel@gnu.org; Mon, 12 Oct 2015 18:39:18 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:40165) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZllkQ-0007lf-V2 for emacs-devel@gnu.org; Mon, 12 Oct 2015 18:39:15 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B0021160E2B; Mon, 12 Oct 2015 15:39:13 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id A5hbwcYvPoSk; Mon, 12 Oct 2015 15:39:12 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 4A4EC160E34; Mon, 12 Oct 2015 15:39:12 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id sEKyyhEJUSSy; Mon, 12 Oct 2015 15:39:12 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 2C1F8160E2B; Mon, 12 Oct 2015 15:39:12 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 In-Reply-To: <87h9lwyv33.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:191411 Archived-At: This is a multi-part message in MIME format. --------------000005040107090007090308 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 10/12/2015 08:17 AM, Oleh Krehel wrote: > Quoting the Emacs sources: > > # define MIN(a,b) ((a) < (b) ? (a) : (b)) > #define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0) > #define SET_FLAG(F, FLAG) ((F) |= (FLAG)) > #define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0) > #define xnew(n, Type) ((Type *) xmalloc ((n) * sizeof (Type))) > #define xrnew(op, n, Type) ((op) = (Type *) xrealloc (op, (n) * sizeof (Type))) > #define switch_line_buffers() (curndx = 1 - curndx) > #define curlinepos (lbs[curndx].linepos) > #define BVAR(buf, field) ((buf)->field ## _) > > Some of these can be replaced with plain type checked C++ Only BVAR belongs to the Emacs core. The other macros belong to auxiliary executables that presumably would be unaffected by any rewrite of the core. Anyway, for fun I just now replaced streq, SET_FLAG, and HAS_FLAG with functions, in the attached patch. More work needs to be done in this area but one step at a time.... --------------000005040107090007090308 Content-Type: text/x-patch; name="0001-Unmacroize-ebrowse.c-and-etags.c-a-bit.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Unmacroize-ebrowse.c-and-etags.c-a-bit.patch" >From ddeec8ae168382bc16658f6836489ad26d7cf755 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 12 Oct 2015 15:30:18 -0700 Subject: [PATCH] Unmacroize ebrowse.c and etags.c a bit * lib-src/ebrowse.c (READ_CHUNK_SIZE): Now an enum constant. (streq, filename_eq, set_flag, has_flag): Now inline functions. (set_flag): First arg is now an address, not an lvalue. All callers changed. (filename_eq, set_flag, has_flag): Rename from FILENAME_EQ, SET_FLAG, HAS_FLAG. All callers changed. * lib-src/etags.c (streq, strcaseeq, strneq, strncaseeq): Now inline functions. Remove asserts that are unnecessary these days (and in some cases were too-generous anyway). --- lib-src/ebrowse.c | 84 ++++++++++++++++++++++++++++++++----------------------- lib-src/etags.c | 27 +++++++++++++++--- 2 files changed, 72 insertions(+), 39 deletions(-) diff --git a/lib-src/ebrowse.c b/lib-src/ebrowse.c index 09edc7d..f2093ae 100644 --- a/lib-src/ebrowse.c +++ b/lib-src/ebrowse.c @@ -32,27 +32,32 @@ along with GNU Emacs. If not, see . */ #define SEEK_END 2 #endif -/* Conditionalize function prototypes. */ - -/* Value is non-zero if strings X and Y compare equal. */ - -#define streq(X, Y) (*(X) == *(Y) && strcmp ((X) + 1, (Y) + 1) == 0) - #include /* Files are read in chunks of this number of bytes. */ -#define READ_CHUNK_SIZE (100 * 1024) +enum { READ_CHUNK_SIZE = 100 * 1024 }; -#if defined (__MSDOS__) -#define FILENAME_EQ(X,Y) (strcasecmp (X,Y) == 0) -#else -#if defined (WINDOWSNT) -#define FILENAME_EQ(X,Y) (stricmp (X,Y) == 0) +/* Value is true if strings X and Y compare equal. */ + +static bool +streq (char const *x, char const *y) +{ + return strcmp (x, y) == 0; +} + +static bool +filename_eq (char const *x, char const *y) +{ +#ifdef __MSDOS__ + return strcasecmp (x, y) == 0; +#elif defined WINDOWSNT + return stricmp (x, y) == 0; #else -#define FILENAME_EQ(X,Y) (streq (X,Y)) -#endif + return streq (x, y); #endif +} + /* The default output file name. */ #define DEFAULT_OUTFILE "BROWSE" @@ -217,10 +222,19 @@ enum visibility #define F_EXTERNC 256 /* Is declared extern "C". */ #define F_DEFINE 512 /* Is a #define. */ -/* Two macros to set and test a bit in an int. */ +/* Set and test a bit in an int. */ -#define SET_FLAG(F, FLAG) ((F) |= (FLAG)) -#define HAS_FLAG(F, FLAG) (((F) & (FLAG)) != 0) +static void +set_flag (int *f, int flag) +{ + *f |= flag; +} + +static bool +has_flag (int f, int flag) +{ + return (f & flag) != 0; +} /* Structure describing a class member. */ @@ -682,7 +696,7 @@ add_member_decl (struct sym *cls, char *name, char *regexp, int pos, unsigned in m = add_member (cls, name, var, sc, hash); /* Have we seen a new filename? If so record that. */ - if (!cls->filename || !FILENAME_EQ (cls->filename, filename)) + if (!cls->filename || !filename_eq (cls->filename, filename)) m->filename = filename; m->regexp = regexp; @@ -745,7 +759,7 @@ add_member_defn (struct sym *cls, char *name, char *regexp, int pos, unsigned in if (!cls->sfilename) cls->sfilename = filename; - if (!FILENAME_EQ (cls->sfilename, filename)) + if (!filename_eq (cls->sfilename, filename)) m->def_filename = filename; m->def_regexp = regexp; @@ -830,7 +844,7 @@ add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var, if (!found) { if (!global_symbols->filename - || !FILENAME_EQ (global_symbols->filename, filename)) + || !filename_eq (global_symbols->filename, filename)) m->filename = filename; m->regexp = regexp; @@ -931,11 +945,11 @@ mark_virtual (struct sym *r) for (p = r->subs; p; p = p->next) { for (m = r->fns; m; m = m->next) - if (HAS_FLAG (m->flags, F_VIRTUAL)) + if (has_flag (m->flags, F_VIRTUAL)) { for (m2 = p->sym->fns; m2; m2 = m2->next) if (m->param_hash == m2->param_hash && streq (m->name, m2->name)) - SET_FLAG (m2->flags, F_VIRTUAL); + set_flag (&m2->flags, F_VIRTUAL); } mark_virtual (p->sym); @@ -1159,7 +1173,7 @@ sym_scope_1 (struct sym *p) strcpy (scope_buffer + scope_buffer_len, p->name); scope_buffer_len += len; - if (HAS_FLAG (p->flags, F_TEMPLATE)) + if (has_flag (p->flags, F_TEMPLATE)) { ensure_scope_buffer_room (3); strcpy (scope_buffer + scope_buffer_len, "<>"); @@ -2435,7 +2449,7 @@ parm_list (int *flags) { /* We can overload the same function on `const' */ hash = (hash << 1) ^ CONST; - SET_FLAG (*flags, F_CONST); + set_flag (flags, F_CONST); MATCH (); } @@ -2443,7 +2457,7 @@ parm_list (int *flags) { MATCH (); SKIP_MATCHING_IF ('('); - SET_FLAG (*flags, F_THROW); + set_flag (flags, F_THROW); } if (LOOKING_AT ('=')) @@ -2452,7 +2466,7 @@ parm_list (int *flags) if (LOOKING_AT (CINT) && yyival == 0) { MATCH (); - SET_FLAG (*flags, F_PURE); + set_flag (flags, F_PURE); } } } @@ -2505,25 +2519,25 @@ member (struct sym *cls, int vis) /* A function or class may follow. */ case TEMPLATE: MATCH (); - SET_FLAG (flags, F_TEMPLATE); + set_flag (&flags, F_TEMPLATE); /* Skip over template argument list */ SKIP_MATCHING_IF ('<'); break; case EXPLICIT: - SET_FLAG (flags, F_EXPLICIT); + set_flag (&flags, F_EXPLICIT); goto typeseen; case MUTABLE: - SET_FLAG (flags, F_MUTABLE); + set_flag (&flags, F_MUTABLE); goto typeseen; case T_INLINE: - SET_FLAG (flags, F_INLINE); + set_flag (&flags, F_INLINE); goto typeseen; case VIRTUAL: - SET_FLAG (flags, F_VIRTUAL); + set_flag (&flags, F_VIRTUAL); goto typeseen; case '[': @@ -2761,7 +2775,7 @@ parse_classname (void) if (LOOKING_AT ('<')) { skip_matching (); - SET_FLAG (last_class->flags, F_TEMPLATE); + set_flag (&last_class->flags, F_TEMPLATE); } if (!LOOKING_AT (DCOLON)) @@ -3189,7 +3203,7 @@ declaration (int flags) break; case T_INLINE: - SET_FLAG (flags, F_INLINE); + set_flag (&flags, F_INLINE); MATCH (); break; @@ -3335,14 +3349,14 @@ globals (int start_flags) MATCH_IF ('}'); } else - SET_FLAG (flags, F_EXTERNC); + set_flag (&flags, F_EXTERNC); } break; case TEMPLATE: MATCH (); SKIP_MATCHING_IF ('<'); - SET_FLAG (flags, F_TEMPLATE); + set_flag (&flags, F_TEMPLATE); break; case CLASS: case STRUCT: case UNION: diff --git a/lib-src/etags.c b/lib-src/etags.c index 791722d..8b980d3 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -150,10 +150,29 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4"; # define CTAGS false #endif -#define streq(s,t) (assert ((s)!=NULL || (t)!=NULL), !strcmp (s, t)) -#define strcaseeq(s,t) (assert ((s)!=NULL && (t)!=NULL), !c_strcasecmp (s, t)) -#define strneq(s,t,n) (assert ((s)!=NULL || (t)!=NULL), !strncmp (s, t, n)) -#define strncaseeq(s,t,n) (assert ((s)!=NULL && (t)!=NULL), !c_strncasecmp (s, t, n)) +static bool +streq (char const *s, char const *t) +{ + return strcmp (s, t) == 0; +} + +static bool +strcaseeq (char const *s, char const *t) +{ + return c_strcasecmp (s, t) == 0; +} + +static bool +strneq (char const *s, char const *t, size_t n) +{ + return strncmp (s, t, n) == 0; +} + +static bool +strncaseeq (char const *s, char const *t, size_t n) +{ + return c_strncasecmp (s, t, n) == 0; +} /* C is not in a name. */ static bool -- 2.1.0 --------------000005040107090007090308--