bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#44155: Print integers as characters


From: Eli Zaretskii
Subject: bug#44155: Print integers as characters
Date: Sun, 25 Oct 2020 19:22:46 +0200

> From: Juri Linkov <juri@linkov.net>
> Date: Sat, 24 Oct 2020 22:53:44 +0300
> Cc: 44155@debbugs.gnu.org
> 
> +        EMACS_INT c = XFIXNUM (obj);

There's no need to use EMACS_INT, a character code is at most 22 bits,
so it always fits into an 'int'.

> +        if (EQ (Vinteger_output_format, Qt) && CHARACTERP (obj) && c < 
> 4194176)
                                                                          
^^^^^^^

Please use MAX_5_BYTE_CHAR here.  Or, better yet, CHAR_BYTE8_P.

And, btw, why not allow raw bytes here as well? is there some problem?

> +          {
> +            printchar ('?', printcharfun);
> +
> +            if (escapeflag
> +                && (c == ';' || c == '(' || c == ')' || c == '{' || c == '}'
> +                    || c == '[' || c == ']' || c == '\"' || c == '\'' || c 
> == '\\'))
> +              printchar ('\\', printcharfun);
> +            print_string (Fchar_to_string (obj), printcharfun);

Why are you using print_string here instead of printchar?  IOW, what
is the difference between printing a backslash and printing any other
character, that you can use printchar for the former, but not for the
latter?

> +        else if (INTEGERP (Vinteger_output_format)
> +                 && XFIXNUM (Vinteger_output_format) == 16 && c >= 0)

If you really want to allow Vinteger_output_format to be a bignum, you
cannot use XFIXNUM with it, you need to use integer_to_intmax or
somesuch.  Otherwise, you should use FIXNUMP instead of INTEGERP.

> +  DEFVAR_LISP ("integer-output-format", Vinteger_output_format,
> +            doc: /* The format used to print integers.
> +When 't', print integers as characters.
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But only integers that are small enough, yes?

> +When a number 16, print numbers in hex format.

This immediately begs the question: why cannot the value be 8 or 2?

Thanks.

P.S. This will eventually need a NEWS entry.





reply via email to

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