[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: port-with-print-state doesn't create a port? Or, when is a port not
From: |
Ludovic Courtès |
Subject: |
Re: port-with-print-state doesn't create a port? Or, when is a port not a port? :-) |
Date: |
Wed, 21 May 2014 16:24:35 +0200 |
User-agent: |
Gnus/5.130009 (Ma Gnus v0.9) Emacs/24.3 (gnu/linux) |
Hi!
Doug Evans <address@hidden> skribis:
> The problem can be succinctly represented by the following:
>
> scheme@(guile-user)> (port? (port-with-print-state (current-output-port)))
> $3 = #f
I think the short answer is that it’s a very old API that’s essentially
unused internally. For instance, make check passes with this patch:
index 122e035..8f4c969 100644
--- a/libguile/print.c
+++ b/libguile/print.c
@@ -255,6 +255,7 @@ scm_free_print_state (SCM print_state)
SCM
scm_i_port_with_print_state (SCM port, SCM print_state)
{
+ abort ();
if (SCM_UNBNDP (print_state))
{
if (SCM_PORT_WITH_PS_P (port))
@@ -596,8 +597,7 @@ iprin1 (SCM exp, SCM port, scm_print_state *pstate)
SCM pwps, print = pstate->writingp ? g_write : g_display;
if (SCM_UNPACK (print) == 0)
goto print_struct;
- pwps = scm_i_port_with_print_state (port, pstate->handle);
- pstate->revealed = 1;
+ pwps = port;
scm_call_generic_2 (print, exp, pwps);
}
else
@@ -824,6 +824,7 @@ scm_prin1 (SCM exp, SCM port, int writingp)
if (SCM_PORT_WITH_PS_P (port))
{
+ abort ();
pstate_scm = SCM_PORT_WITH_PS_PS (port);
port = SCM_PORT_WITH_PS_PORT (port);
}
@@ -1610,7 +1611,7 @@ scm_printer_apply (SCM proc, SCM exp, SCM port,
scm_print_state *pstate)
{
pstate->revealed = 1;
return scm_call_2 (proc, exp,
- scm_i_port_with_print_state (port, pstate->handle));
+ port);
}
SCM_DEFINE (scm_port_with_print_state, "port-with-print-state", 1, 1, 0,
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 42d7d78..2974ef6 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -1257,11 +1257,6 @@ VALUE."
;;
;; It should print OBJECT to PORT.
-(define (inherit-print-state old-port new-port)
- (if (get-print-state old-port)
- (port-with-print-state new-port (get-print-state old-port))
- new-port))
-
;; 0: type-name, 1: fields, 2: constructor
(define record-type-vtable
(let ((s (make-vtable (string-append standard-vtable-fields "prprpw")
I think the problem it was trying to solve has been solved differently
(by explicitly passing the print state in the print.c code, for
instance), and can easily be solved differently.
> In the meantime, I can make struct printers be aware of the
> distinction and handle being passed port-with-print-state ports.
Do you actually need this associated state?
My first feeling is that we should deprecate and eventually remove this
API, given that it’s essentially unused and non-functional.
What do people think?
> P.S. How come scm_put[cs]_unlocked are inlined in ports.h?
What’s wrong with that? (It probably doesn’t help much because
scm_lfwrite_unlocked isn’t inlined.)
Ludo’.