From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Doug Evans Newsgroups: gmane.lisp.guile.devel Subject: port-with-print-state doesn't create a port? Or, when is a port not a port? :-) Date: Sat, 17 May 2014 11:10:26 -0700 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1400350252 22873 80.91.229.3 (17 May 2014 18:10:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 17 May 2014 18:10:52 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat May 17 20:10:45 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wlj4E-0001ng-VU for guile-devel@m.gmane.org; Sat, 17 May 2014 20:10:43 +0200 Original-Received: from localhost ([::1]:41112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wlj4E-0003CG-8T for guile-devel@m.gmane.org; Sat, 17 May 2014 14:10:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wlj45-0003C9-8F for guile-devel@gnu.org; Sat, 17 May 2014 14:10:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wlj3y-0000XO-Mr for guile-devel@gnu.org; Sat, 17 May 2014 14:10:33 -0400 Original-Received: from mail-yh0-x22f.google.com ([2607:f8b0:4002:c01::22f]:39667) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wlj3y-0000XJ-I2 for guile-devel@gnu.org; Sat, 17 May 2014 14:10:26 -0400 Original-Received: by mail-yh0-f47.google.com with SMTP id z6so5489670yhz.6 for ; Sat, 17 May 2014 11:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=3gj8LGx+RxLn5gcm35G5WJ43CJ9XCxIR7NHQNdnUyTg=; b=HMPeQZqbykXO6IZrR3uWmSlJeos17y34+JjX1M3UqbynP0WLjoEEFDRcp66goHFABC 6Xv7jFce6Tgz8wYh1vHbGqy+Q/rvhZOFL1VTC16ARYErQp1t321tgjjdTTwRbz7Stfem IgvyKTW/VPXUYZpRbMpBR0yQXHkl+QPyBEn6h+nMW5KJ5roqPfL4M8AfwZrEmZzKw3Zu LLeHmJNHOlOeW8tBvDePbAvbeU5GcZsB6LYysNUIMYWF/kQbx1VFJQ84hW4LuwPnbekO T1zxG+vbfew+faIoZM9VgiLf81uiB6aHdqMmMA3U23TAl92UbCu2PTBqeKI0AYDFr2+z 6hAg== X-Received: by 10.236.216.73 with SMTP id f69mr36225213yhp.37.1400350226133; Sat, 17 May 2014 11:10:26 -0700 (PDT) Original-Received: by 10.170.150.70 with HTTP; Sat, 17 May 2014 11:10:26 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c01::22f X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17147 Archived-At: Hi. I've been playing with gdb objects implemented as structs and have hit an oddity. The problem can be succinctly represented by the following: scheme@(guile-user)> (port? (port-with-print-state (current-output-port))) $3 = #f I've dug into the implementation of the functions and macros involved. I think I understand why it's printing #f. A port-with-print-state is a scm_tc16_port_with_ps port, not a scm_tc7_port port. This means that any function that accepts a "port" parameter and wishes to call functions like scm_puts has to handle this distinction (because scm_puts only accepts a scm_tc7_port port). Has anyone done an audit of the C API with an eye towards making any function that claims to take a port argument accept either kind of port? The current situation is a bit confusing. E.g., in the docs for scm_set_smob_print, I see this text: It is often best to ignore @var{pstate} and just print to @var{port} with @code{scm_display}, @code{scm_write}, @code{scm_simple_format}, and @code{scm_puts}. scm_display and scm_write are smart enough to handle both kinds of ports, but scm_puts is not. I didn't check scm_simple_format. And I don't see any docs indicating one needs to be aware of this port vs port-with-pstate-port distinction in smob or struct printers. Users can be pretty simplistic when reading documentation, this user included. :-) Words tend to take on meanings that if used in one place are expected to apply everywhere. IOW, a port is a port is a port. In that vein, should port? [et.al.] return #t for a port-with-print-state port? Dunno. I dug around looking for various problems in the guile sources that might be caused by this confusion. I couldn't find any and I think it's because struct printing is the only place that uses scm_printer_apply. Every other object printer I found takes port and pstate as separate arguments and scm_prin1 handles splitting out pstate from the incoming port parameter, thus all printers will only ever see a scm_tc7_port, never a scm_tc16_port_with_ps port (and thus all printers that call scm_puts never trip over this confusion, only struct printers). In the meantime, I can make struct printers be aware of the distinction and handle being passed port-with-print-state ports. P.S. How come scm_put[cs]_unlocked are inlined in ports.h?