diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2021-12-02 19:01:33 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2021-12-02 19:03:14 -0800 |
commit | 9c222b9c1a7f91497a37567b4d7de3a511fff069 (patch) | |
tree | a0e9016aac8318734b5e9d744f9cc1502bef72f3 /src/pdumper.c | |
parent | fed35a89517aa4e282273f7e3c75bafd4e698ce4 (diff) | |
download | emacs-9c222b9c1a7f91497a37567b4d7de3a511fff069.tar.gz |
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.
Diffstat (limited to 'src/pdumper.c')
-rw-r--r-- | src/pdumper.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/pdumper.c b/src/pdumper.c index a8f8d6fa00b..a6557599038 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) |