From 926a394997eaae55b797a90cb2cd037bbe3c3db4 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 5 May 2019 17:35:05 -0700 Subject: [PATCH] Use simpler way to print function pointers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The module code can’t possibly work on weird platforms where function pointers are wider than data pointers, so there’s no need to bother with the stackoverflow-like approach that is intended only for portability to such platforms. Besides, the stackoverflow-like approach does not work well on weird platforms where CHAR_BIT is not a multiple of 4. * src/lisp.h (pMx): New macro. * src/print.c (data_from_funcptr) [HAVE_MODULES]: New function. (print_vectorlike) [HAVE_MODULES]: Use it. (print_object): Make sure buf is big enough for this. --- src/lisp.h | 2 ++ src/print.c | 47 ++++++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/lisp.h b/src/lisp.h index ca833476c03..61cc20e9d42 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -144,11 +144,13 @@ typedef intmax_t printmax_t; typedef uintmax_t uprintmax_t; # define pMd PRIdMAX # define pMu PRIuMAX +# define pMx PRIxMAX #else typedef EMACS_INT printmax_t; typedef EMACS_UINT uprintmax_t; # define pMd pI"d" # define pMu pI"u" +# define pMx pI"x" #endif /* Use pD to format ptrdiff_t values, which suffice for indexes into diff --git a/src/print.c b/src/print.c index 08c39d34664..406abbf4a3f 100644 --- a/src/print.c +++ b/src/print.c @@ -1361,6 +1361,19 @@ print_prune_string_charset (Lisp_Object string) return string; } +#ifdef HAVE_MODULES +/* Return a data pointer equal to FUNCPTR. */ + +static void const * +data_from_funcptr (void (*funcptr) (void)) +{ + /* The module code, and the POSIX API for dynamic linking, already + assume that function and data pointers are represented + interchangeably, so it's OK to assume that here too. */ + return (void const *) funcptr; +} +#endif + static bool print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, char *buf) @@ -1788,30 +1801,20 @@ print_vectorlike (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag, { print_c_string ("#stack_top = buf; maybe_quit (); -- 2.39.2