guile: fix printing of output to buffer (issue #1098)

The support for Guile 2.2 did not implement the custom port correctly,
and did not configure it to be the default output port. This caused
output from Guile to be printed straight to the TTY, breaking the
WeeChat interface.

Note that the port is unbuffered, so that code like

    (display "test")

immediately results in output, without an explicit call to force-output.
This commit is contained in:
Joram Schrijver 2020-05-22 02:29:31 +02:00 committed by Sébastien Helleu
parent e784a994b5
commit cac45aab46
2 changed files with 7 additions and 6 deletions

View File

@ -4974,7 +4974,9 @@ weechat_guile_api_module_init (void *data)
port_type = scm_make_port_type ("weechat_stdout",
&weechat_guile_port_fill_input,
&weechat_guile_port_write);
guile_port = scm_c_make_port (port_type, 0, 0);
guile_port = scm_c_make_port (port_type, SCM_WRTNG | SCM_BUF0, 0);
scm_set_current_output_port (guile_port);
scm_set_current_error_port (guile_port);
#else
/* Guile < 2.2 */
scm_t_bits port_type;

View File

@ -1151,11 +1151,10 @@ weechat_guile_port_fill_input (SCM port, SCM dst, size_t start, size_t count)
{
/* make C compiler happy */
(void) port;
(void) dst;
(void) start;
(void) count;
return ' ';
memset (SCM_BYTEVECTOR_CONTENTS (dst) + start, ' ', count);
return count;
}
#else
/* Guile < 2.2 */
@ -1184,7 +1183,7 @@ weechat_guile_port_write (SCM port, SCM src, size_t start, size_t count)
/* make C compiler happy */
(void) port;
data = scm_to_locale_string (src);
data = SCM_BYTEVECTOR_CONTENTS (src);
data2 = malloc (count + 1);
if (!data2)