From debbugs-submit-bounces@debbugs.gnu.org Mon May 26 09:56:25 2025 Received: (at submit) by debbugs.gnu.org; 26 May 2025 13:56:25 +0000 Received: from localhost ([127.0.0.1]:57515 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uJYJU-0004AJ-Mp for submit@debbugs.gnu.org; Mon, 26 May 2025 09:56:25 -0400 Received: from lists.gnu.org ([2001:470:142::17]:57954) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uJYJP-00049y-M6 for submit@debbugs.gnu.org; Mon, 26 May 2025 09:56:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uJYJJ-0004GU-4c for bug-gnu-emacs@gnu.org; Mon, 26 May 2025 09:56:13 -0400 Received: from mail-4322.protonmail.ch ([185.70.43.22]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uJYJE-0004TX-8p for bug-gnu-emacs@gnu.org; Mon, 26 May 2025 09:56:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1748267765; x=1748526965; bh=Skm9U+mLqOBFJt3pwP5NYmPOW3I2A7r1YvDKDtJ1B/E=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=Snl5ooDxYr78QumzV21fhnaKMEmOAtAXg93GH7Sj4ZSP5AaIkNjSx1q+1sNRUrcy2 VmD2Pwn38PuIi57Jn5QhrczvxV9gIbRg+Kd6xNaVLcGUrkNL+6VV+ZZrTizlrgduCW GFgpFNG3Qe7dFzVpPNFtJXqTGo+ClUoOo4qyy6fQ11atYm8zDseNjRCK7d7uhxY7Cj kwtYxsDaZfF2RLmJBcnBY14hKTUWtePkZR7ULEqsSndqTKkwKLiUdNuSIk1DpfbUEy XJ7SB1mcnL+WlaL8T6MF8DWouoW2OnFoS6pO7iBwkiPEkkyeBY3pWr6mcoDk0kokdt KQSaIHO0YEhAA== Date: Mon, 26 May 2025 13:56:02 +0000 To: bug-gnu-emacs@gnu.org From: Pip Cet Subject: 31.0.50; recursive print invocations broken Message-ID: <87wma38oi7.fsf@protonmail.com> Feedback-ID: 112775352:user:proton X-Pm-Message-ID: d80a384831cd6776f8f2b21947f9eba98289b223 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.70.43.22; envelope-from=pipcet@protonmail.com; helo=mail-4322.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) There are some comments in print.c about supporting recursive invocations of print. However, the function 'print' sets print_depth to 0, and 'print_object' asserts that print_depth reassumes its original base_depth value when the function is done running, so virtually all attempts to call the printing machinery from either printcharfun or print-unreadable-function will crash. ;; -*- lexical-binding: t; -*- (prin1 "hi" (lambda (x) (princ (string (capitalize x))))) ;; -*- lexical-binding: t; -*- (let ((print-unreadable-function (lambda (&rest args) (prin1-to-string "unreadable")))) (prin1 (make-finalizer (lambda nil nil)))) The fix isn't as simple as removing the print_depth =3D 0 line (a non-local exit would leave print_depth set to a nonzero value for the next invocation of print) or removing the base_depth assertion (print_depth might then become negative while within print_object, with disastrous results). I think the best approach is to expand print_context to capture all of the printing context, including print_depth, being_printed, and print_buffer, but there are some questions: 1. Should circle detection work for print-within-print? If so, we need to "carry over" being_printed and print_depth to the inner invocation. If we don't, we lose the ability to detect circular structures when print-within-print is in use. 2. Should we really assume print-unreadable-function is non-recursive? This code: /* Bind `print-unreadable-function' to nil to avoid accidental =09 infinite recursion in the function called. */ Lisp_Object func =3D Vprint_unreadable_function; specbind (Qprint_unreadable_function, Qnil); makes it so, but as the point of print-unreadable-function is presumably (sometimes) to produce a readable syntax for an unreadable object which describes it, I don't see why sub-objects of that description cannot similarly be made readable. 3. Is there, maybe, a simpler solution? We could arrange to call print-unreadable-function at print_preprocess time, then print to a buffer, and finally call printcharfun on each character. This would mean that print_object itself would never need to call Lisp.