From: Paul Eggert Date: Mon, 6 May 2019 00:35:05 +0000 (-0700) Subject: Use simpler way to print function pointers X-Git-Tag: emacs-27.0.90~2958 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=926a394997eaae55b797a90cb2cd037bbe3c3db4;p=emacs.git Use simpler way to print function pointers 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. --- 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 ();