Subject: Re: bug#78590: 31.0.50; print_object calls strout unsafely

From: Eli Zaretskii <[email-masked]>
Date: Wed, 28 May 2025 14:24:38 +0300

> Date: Tue, 27 May 2025 18:46:24 +0000
> From: Pip Cet <[email-masked]>
> Cc: [email-masked]
> 
> "Eli Zaretskii" <[email-masked]> writes:
> 
> >> How about calling Fmapc (printcharfun, string) at that point, from
> >> print_string?
> >
> > If that works, fine.  But didn't you say below that print_string does
> > something we don't want to do in this case?  Or am I misunderstanding
> > what you mean?
> 
> Sorry, that wasn't quite clear.  I also forgot to include the proposed
> patch:

Ah, okay, there was indeed an misunderstanding, see below.

>    else
>      {
> -      /* Otherwise, string may be relocated by printing one char.
> -	 So re-fetch the string address for each character.  */
> -      ptrdiff_t i;
> -      ptrdiff_t size = SCHARS (string);
> -      ptrdiff_t size_byte = SBYTES (string);
> -      if (size == size_byte)
> -	for (i = 0; i < size; i++)
> -	  printchar (SREF (string, i), printcharfun);
> -      else
> -	for (i = 0; i < size_byte; )
> -	  {
> -	    /* Here, we must convert each multi-byte form to the
> -	       corresponding character code before handing it to PRINTCHAR.  */
> -	    int len, ch = string_char_and_length (SDATA (string) + i, &len);
> -	    printchar (ch, printcharfun);
> -	    i += len;
> -	  }
> +      /* printcharfun is a Lisp function.  */
> +      Fmapc (printcharfun, string);

What is the rationale for calling Fmapc here?  Doesn't it do in this
case what the original code did, but at a price of two additional
levels of function calls?  IOW, why did you want to get rid of the
original code above?

I have no other issues with your suggested patch.