emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-28 9c222b9: Port to C compilers that lack size-0 arrays


From: Paul Eggert
Subject: emacs-28 9c222b9: Port to C compilers that lack size-0 arrays
Date: Thu, 2 Dec 2021 22:03:20 -0500 (EST)

branch: emacs-28
commit 9c222b9c1a7f91497a37567b4d7de3a511fff069
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    Port to C compilers that lack size-0 arrays
    
    The C standard does not allow size-zero arrays, so redo struct
    Lisp_Subr to not use size-zero arrays when native compilation is
    not being used.  Formerly, the code was using size-zero arrays (a
    GNU C extension) to avoid using memory unnecessarily when
    HAVE_NATIVE_COMP is not defined.  Replace this hack with the
    more-traditional hack of putting the relevant members inside
    ‘#ifdef HAVE_NATIVE_COMP’.
    * src/alloc.c (cleanup_vector, mark_object):
    * src/comp.c (make_subr):
    * src/data.c (Fsubr_native_lambda_list, Fsubr_native_comp_unit):
    * src/eval.c (init_eval_once, funcall_lambda):
    * src/lisp.h (SUBR_NATIVE_COMPILEDP, SUBR_NATIVE_COMPILED_DYNP)
    (SUBR_TYPE):
    * src/lread.c (Fload):
    Conditionally compile with ‘#ifdef HAVE_NATIVE_COMP’ instead of
    with ‘if (NATIVE_COMP_FLAG)’.  Redo members like native_comp_u[0]
    to be plain native_comp_u.  Put all uses of these members inside
    ‘#ifdef HAVE_NATIVE_COMP’.
    * src/lisp.h (struct Lisp_Subr): Members native_comp_u,
    native_c_name, lambda_list, type are now all ifdeffed out if
    HAVE_NATIVE_COMP is not defined, instead of being size-zero
    arrays.  All uses changed.
    * src/pdumper.c (dump_subr, dump_cold_native_subr)
    (dump_do_dump_relocation):
    * src/comp.h (NATIVE_COMP_FLAG): Remove; no longer needed.
---
 src/alloc.c   | 20 +++++++++++---------
 src/comp.c    | 18 +++++++++++++-----
 src/comp.h    | 10 ----------
 src/data.c    | 10 ++++++----
 src/eval.c    | 23 +++++++++++------------
 src/lisp.h    | 16 +++++++++-------
 src/lread.c   | 12 +++++++++---
 src/pdumper.c | 40 +++++++++++++++++++---------------------
 8 files changed, 78 insertions(+), 71 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index 0c04d5c..e2184d7 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3152,26 +3152,26 @@ cleanup_vector (struct Lisp_Vector *vector)
       module_finalize_function (function);
     }
 #endif
-  else if (NATIVE_COMP_FLAG
-          && PSEUDOVECTOR_TYPEP (&vector->header, PVEC_NATIVE_COMP_UNIT))
+#ifdef HAVE_NATIVE_COMP
+  else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_NATIVE_COMP_UNIT))
     {
       struct Lisp_Native_Comp_Unit *cu =
        PSEUDOVEC_STRUCT (vector, Lisp_Native_Comp_Unit);
       unload_comp_unit (cu);
     }
-  else if (NATIVE_COMP_FLAG
-          && PSEUDOVECTOR_TYPEP (&vector->header, PVEC_SUBR))
+  else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_SUBR))
     {
       struct Lisp_Subr *subr =
        PSEUDOVEC_STRUCT (vector, Lisp_Subr);
-      if (!NILP (subr->native_comp_u[0]))
+      if (!NILP (subr->native_comp_u))
        {
          /* FIXME Alternative and non invasive solution to this
             cast?  */
          xfree ((char *)subr->symbol_name);
-         xfree (subr->native_c_name[0]);
+         xfree (subr->native_c_name);
        }
     }
+#endif
 }
 
 /* Reclaim space used by unmarked vectors.  */
@@ -6773,15 +6773,17 @@ mark_object (Lisp_Object arg)
            break;
 
          case PVEC_SUBR:
+#ifdef HAVE_NATIVE_COMP
            if (SUBR_NATIVE_COMPILEDP (obj))
              {
                set_vector_marked (ptr);
                struct Lisp_Subr *subr = XSUBR (obj);
                mark_object (subr->native_intspec);
-               mark_object (subr->native_comp_u[0]);
-               mark_object (subr->lambda_list[0]);
-               mark_object (subr->type[0]);
+               mark_object (subr->native_comp_u);
+               mark_object (subr->lambda_list);
+               mark_object (subr->type);
              }
+#endif
            break;
 
          case PVEC_FREE:
diff --git a/src/comp.c b/src/comp.c
index 1381d98..43feac6 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -5154,21 +5154,29 @@ make_subr (Lisp_Object symbol_name, Lisp_Object minarg, 
Lisp_Object maxarg,
   if (CONSP (minarg))
     {
       /* Dynamic code.  */
-      x->s.lambda_list[0] = maxarg;
+#ifdef HAVE_NATIVE_COMP
+      x->s.lambda_list = maxarg;
+#endif
       maxarg = XCDR (minarg);
       minarg = XCAR (minarg);
     }
   else
-    x->s.lambda_list[0] = Qnil;
+    {
+#ifdef HAVE_NATIVE_COMP
+      x->s.lambda_list = Qnil;
+#endif
+    }
   x->s.function.a0 = func;
   x->s.min_args = XFIXNUM (minarg);
   x->s.max_args = FIXNUMP (maxarg) ? XFIXNUM (maxarg) : MANY;
   x->s.symbol_name = xstrdup (SSDATA (symbol_name));
   x->s.native_intspec = intspec;
   x->s.doc = XFIXNUM (doc_idx);
-  x->s.native_comp_u[0] = comp_u;
-  x->s.native_c_name[0] = xstrdup (SSDATA (c_name));
-  x->s.type[0] = type;
+#ifdef HAVE_NATIVE_COMP
+  x->s.native_comp_u = comp_u;
+  x->s.native_c_name = xstrdup (SSDATA (c_name));
+  x->s.type = type;
+#endif
   Lisp_Object tem;
   XSETSUBR (tem, &x->s);
 
diff --git a/src/comp.h b/src/comp.h
index c4af419..96bb52a 100644
--- a/src/comp.h
+++ b/src/comp.h
@@ -20,16 +20,6 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #ifndef COMP_H
 #define COMP_H
 
-/* To keep ifdefs under control.  */
-enum {
-  NATIVE_COMP_FLAG =
-#ifdef HAVE_NATIVE_COMP
-  1
-#else
-  0
-#endif
-};
-
 #include <dynlib.h>
 
 struct Lisp_Native_Comp_Unit
diff --git a/src/data.c b/src/data.c
index 0d3376f..b2c3958 100644
--- a/src/data.c
+++ b/src/data.c
@@ -891,9 +891,11 @@ function or t otherwise.  */)
 {
   CHECK_SUBR (subr);
 
-  return SUBR_NATIVE_COMPILED_DYNP (subr)
-    ? XSUBR (subr)->lambda_list[0]
-    : Qt;
+#ifdef HAVE_NATIVE_COMP
+  if (SUBR_NATIVE_COMPILED_DYNP (subr))
+    return XSUBR (subr)->lambda_list;
+#endif
+  return Qt;
 }
 
 DEFUN ("subr-type", Fsubr_type,
@@ -917,7 +919,7 @@ DEFUN ("subr-native-comp-unit", Fsubr_native_comp_unit,
   (Lisp_Object subr)
 {
   CHECK_SUBR (subr);
-  return XSUBR (subr)->native_comp_u[0];
+  return XSUBR (subr)->native_comp_u;
 }
 
 DEFUN ("native-comp-unit-file", Fnative_comp_unit_file,
diff --git a/src/eval.c b/src/eval.c
index 0f792b4..3ac1afc 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -219,17 +219,14 @@ void
 init_eval_once (void)
 {
   /* Don't forget to update docs (lispref node "Local Variables").  */
-  if (!NATIVE_COMP_FLAG)
-    {
-      max_specpdl_size = 1800; /* See bug#46818.  */
-      max_lisp_eval_depth = 800;
-    }
-  else
-    {
-      /* Original values increased for comp.el.  */
-      max_specpdl_size = 2500;
-      max_lisp_eval_depth = 1600;
-    }
+#ifndef HAVE_NATIVE_COMP
+  max_specpdl_size = 1800; /* See bug#46818.  */
+  max_lisp_eval_depth = 800;
+#else
+  /* Original values increased for comp.el.  */
+  max_specpdl_size = 2500;
+  max_lisp_eval_depth = 1600;
+#endif
   Vrun_hooks = Qnil;
   pdumper_do_now_and_after_load (init_eval_once_for_pdumper);
 }
@@ -3236,11 +3233,13 @@ funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
   else if (MODULE_FUNCTIONP (fun))
     return funcall_module (fun, nargs, arg_vector);
 #endif
+#ifdef HAVE_NATIVE_COMP
   else if (SUBR_NATIVE_COMPILED_DYNP (fun))
     {
-      syms_left = XSUBR (fun)->lambda_list[0];
+      syms_left = XSUBR (fun)->lambda_list;
       lexenv = Qnil;
     }
+#endif
   else
     emacs_abort ();
 
diff --git a/src/lisp.h b/src/lisp.h
index 480c389..af8a845 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2083,10 +2083,12 @@ struct Lisp_Subr
       Lisp_Object native_intspec;
     };
     EMACS_INT doc;
-    Lisp_Object native_comp_u[NATIVE_COMP_FLAG];
-    char *native_c_name[NATIVE_COMP_FLAG];
-    Lisp_Object lambda_list[NATIVE_COMP_FLAG];
-    Lisp_Object type[NATIVE_COMP_FLAG];
+#ifdef HAVE_NATIVE_COMP
+    Lisp_Object native_comp_u;
+    char *native_c_name;
+    Lisp_Object lambda_list;
+    Lisp_Object type;
+#endif
   } GCALIGNED_STRUCT;
 union Aligned_Lisp_Subr
   {
@@ -4773,19 +4775,19 @@ extern char *emacs_root_dir (void);
 INLINE bool
 SUBR_NATIVE_COMPILEDP (Lisp_Object a)
 {
-  return SUBRP (a) && !NILP (XSUBR (a)->native_comp_u[0]);
+  return SUBRP (a) && !NILP (XSUBR (a)->native_comp_u);
 }
 
 INLINE bool
 SUBR_NATIVE_COMPILED_DYNP (Lisp_Object a)
 {
-  return SUBR_NATIVE_COMPILEDP (a) && !NILP (XSUBR (a)->lambda_list[0]);
+  return SUBR_NATIVE_COMPILEDP (a) && !NILP (XSUBR (a)->lambda_list);
 }
 
 INLINE Lisp_Object
 SUBR_TYPE (Lisp_Object a)
 {
-  return XSUBR (a)->type[0];
+  return XSUBR (a)->type;
 }
 
 INLINE struct Lisp_Native_Comp_Unit *
diff --git a/src/lread.c b/src/lread.c
index b3f9e6f..9bb5f66 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1271,7 +1271,10 @@ Return t if the file exists and loads successfully.  */)
               || suffix_p (file, MODULES_SECONDARY_SUFFIX)
 #endif
 #endif
-              || (NATIVE_COMP_FLAG && suffix_p (file, NATIVE_ELISP_SUFFIX)))
+#ifdef HAVE_NATIVE_COMP
+              || suffix_p (file, NATIVE_ELISP_SUFFIX)
+#endif
+             )
            must_suffix = Qnil;
          /* Don't insist on adding a suffix
             if the argument includes a directory name.  */
@@ -1351,8 +1354,11 @@ Return t if the file exists and loads successfully.  */)
   bool is_module = false;
 #endif
 
-  bool is_native_elisp =
-    NATIVE_COMP_FLAG && suffix_p (found, NATIVE_ELISP_SUFFIX) ? true : false;
+#ifdef HAVE_NATIVE_COMP
+  bool is_native_elisp = suffix_p (found, NATIVE_ELISP_SUFFIX);
+#else
+  bool is_native_elisp = false;
+#endif
 
   /* Check if we're stuck in a recursive load cycle.
 
diff --git a/src/pdumper.c b/src/pdumper.c
index a8f8d6f..a655759 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -2859,13 +2859,18 @@ dump_subr (struct dump_context *ctx, const struct 
Lisp_Subr *subr)
   struct Lisp_Subr out;
   dump_object_start (ctx, &out, sizeof (out));
   DUMP_FIELD_COPY (&out, subr, header.size);
-  if (NATIVE_COMP_FLAG && !NILP (subr->native_comp_u[0]))
+#ifdef HAVE_NATIVE_COMP
+  bool native_comp = !NILP (subr->native_comp_u);
+#else
+  bool native_comp = false;
+#endif
+  if (native_comp)
     out.function.a0 = NULL;
   else
     dump_field_emacs_ptr (ctx, &out, subr, &subr->function.a0);
   DUMP_FIELD_COPY (&out, subr, min_args);
   DUMP_FIELD_COPY (&out, subr, max_args);
-  if (NATIVE_COMP_FLAG && !NILP (subr->native_comp_u[0]))
+  if (native_comp)
     {
       dump_field_fixup_later (ctx, &out, subr, &subr->symbol_name);
       dump_remember_cold_op (ctx,
@@ -2879,19 +2884,16 @@ dump_subr (struct dump_context *ctx, const struct 
Lisp_Subr *subr)
       dump_field_emacs_ptr (ctx, &out, subr, &subr->intspec);
     }
   DUMP_FIELD_COPY (&out, subr, doc);
-  if (NATIVE_COMP_FLAG)
-    {
-      dump_field_lv (ctx, &out, subr, &subr->native_comp_u[0], WEIGHT_NORMAL);
-      if (!NILP (subr->native_comp_u[0]))
-       dump_field_fixup_later (ctx, &out, subr, &subr->native_c_name[0]);
+#ifdef HAVE_NATIVE_COMP
+  dump_field_lv (ctx, &out, subr, &subr->native_comp_u, WEIGHT_NORMAL);
+  if (!NILP (subr->native_comp_u))
+    dump_field_fixup_later (ctx, &out, subr, &subr->native_c_name);
 
-      dump_field_lv (ctx, &out, subr, &subr->lambda_list[0], WEIGHT_NORMAL);
-      dump_field_lv (ctx, &out, subr, &subr->type[0], WEIGHT_NORMAL);
-    }
+  dump_field_lv (ctx, &out, subr, &subr->lambda_list, WEIGHT_NORMAL);
+  dump_field_lv (ctx, &out, subr, &subr->type, WEIGHT_NORMAL);
+#endif
   dump_off subr_off = dump_object_finish (ctx, &out, sizeof (out));
-  if (NATIVE_COMP_FLAG
-      && ctx->flags.dump_object_contents
-      && !NILP (subr->native_comp_u[0]))
+  if (native_comp && ctx->flags.dump_object_contents)
     /* We'll do the final addr relocation during VERY_LATE_RELOCS time
        after the compilation units has been loaded. */
     dump_push (&ctx->dump_relocs[VERY_LATE_RELOCS],
@@ -3421,9 +3423,9 @@ dump_cold_native_subr (struct dump_context *ctx, 
Lisp_Object subr)
 
   dump_remember_fixup_ptr_raw
     (ctx,
-     subr_offset + dump_offsetof (struct Lisp_Subr, native_c_name[0]),
+     subr_offset + dump_offsetof (struct Lisp_Subr, native_c_name),
      ctx->offset);
-  const char *c_name = XSUBR (subr)->native_c_name[0];
+  const char *c_name = XSUBR (subr)->native_c_name;
   dump_write (ctx, c_name, 1 + strlen (c_name));
 }
 #endif
@@ -5360,20 +5362,16 @@ dump_do_dump_relocation (const uintptr_t dump_base,
       }
     case RELOC_NATIVE_SUBR:
       {
-       if (!NATIVE_COMP_FLAG)
-         /* This cannot happen.  */
-         emacs_abort ();
-
        /* When resurrecting from a dump given non all the original
           native compiled subrs may be still around we can't rely on
           a 'top_level_run' mechanism, we revive them one-by-one
           here.  */
        struct Lisp_Subr *subr = dump_ptr (dump_base, reloc_offset);
        struct Lisp_Native_Comp_Unit *comp_u =
-         XNATIVE_COMP_UNIT (subr->native_comp_u[0]);
+         XNATIVE_COMP_UNIT (subr->native_comp_u);
        if (!comp_u->handle)
          error ("NULL handle in compilation unit %s", SSDATA (comp_u->file));
-       const char *c_name = subr->native_c_name[0];
+       const char *c_name = subr->native_c_name;
        eassert (c_name);
        void *func = dynlib_sym (comp_u->handle, c_name);
        if (!func)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]