scm_print_state *pstate;
/* Create a string port used for adaptation of printing parameters. */
- sport = scm_mkstrport (SCM_INUM0,
- scm_make_string (scm_from_int (240),
- SCM_UNDEFINED),
+ sport = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
SCM_OPN | SCM_WRTNG,
FUNC_NAME);
SCM_ASSERT (n > 0, a->depth, SCM_ARG4, s_display_backtrace);
/* Create a string port used for adaptation of printing parameters. */
- sport = scm_mkstrport (SCM_INUM0,
- scm_make_string (scm_from_int (240), SCM_UNDEFINED),
+ sport = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
SCM_OPN | SCM_WRTNG,
FUNC_NAME);
/* GDB interface for Guile
- * Copyright (C) 1996,1997,1999,2000,2001,2002,2004,2009
+ * Copyright (C) 1996,1997,1999,2000,2001,2002,2004,2009,2011
* Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
SCM port;
scm_print_carefully_p = 0;
-
- port = scm_mkstrport (SCM_INUM0,
- scm_c_make_string (0, SCM_UNDEFINED),
+
+ port = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
SCM_OPN | SCM_WRTNG,
s);
gdb_output_port = scm_permanent_object (port);
-
- port = scm_mkstrport (SCM_INUM0,
- scm_c_make_string (0, SCM_UNDEFINED),
+
+ port = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
SCM_OPN | SCM_RDNG | SCM_WRTNG,
s);
gdb_input_port = scm_permanent_object (port);
pt->write_pos = pt->read_end;
}
+/* The initial size in bytes of a string port's buffer. */
+#define INITIAL_BUFFER_SIZE 128
+
+/* Return a new string port with MODES. If STR is #f, a new backing
+ buffer is allocated; otherwise STR must be a string and a copy of it
+ serves as the buffer for the new port. */
SCM
scm_mkstrport (SCM pos, SCM str, long modes, const char *caller)
{
z = scm_new_port_table_entry (scm_tc16_strport);
pt = SCM_PTAB_ENTRY(z);
- {
- /* STR is a string. */
- char *copy;
+ if (scm_is_false (str))
+ {
+ /* Allocate a new buffer to write to. */
+ str_len = INITIAL_BUFFER_SIZE;
+ buf = scm_c_make_bytevector (str_len);
+ c_buf = (char *) SCM_BYTEVECTOR_CONTENTS (buf);
+
+ /* Reset `read_buf_size'. It will contain the actual number of
+ bytes written to PT. */
+ pt->read_buf_size = 0;
+ c_pos = 0;
+ }
+ else
+ {
+ /* STR is a string. */
+ char *copy;
- SCM_ASSERT (scm_is_string (str), str, SCM_ARG1, caller);
+ SCM_ASSERT (scm_is_string (str), str, SCM_ARG1, caller);
- /* Create a copy of STR in the encoding of PT. */
- copy = scm_to_stringn (str, &str_len, pt->encoding,
- SCM_FAILED_CONVERSION_ERROR);
- buf = scm_c_make_bytevector (str_len);
- c_buf = (char *) SCM_BYTEVECTOR_CONTENTS (buf);
- memcpy (c_buf, copy, str_len);
- free (copy);
+ /* Create a copy of STR in the encoding of PT. */
+ copy = scm_to_stringn (str, &str_len, pt->encoding,
+ SCM_FAILED_CONVERSION_ERROR);
+ buf = scm_c_make_bytevector (str_len);
+ c_buf = (char *) SCM_BYTEVECTOR_CONTENTS (buf);
+ memcpy (c_buf, copy, str_len);
+ free (copy);
- c_pos = scm_to_unsigned_integer (pos, 0, str_len);
- pt->read_buf_size = str_len;
- }
+ c_pos = scm_to_unsigned_integer (pos, 0, str_len);
+ pt->read_buf_size = str_len;
+ }
SCM_SETSTREAM (z, SCM_UNPACK (buf));
SCM_SET_CELL_TYPE (z, scm_tc16_strport | modes);
"argument @var{printer} (default: @code{write}).")
#define FUNC_NAME s_scm_object_to_string
{
- SCM str, port;
+ SCM port;
if (!SCM_UNBNDP (printer))
SCM_VALIDATE_PROC (2, printer);
- str = scm_c_make_string (0, SCM_UNDEFINED);
- port = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_WRTNG, FUNC_NAME);
+ port = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
+ SCM_OPN | SCM_WRTNG, FUNC_NAME);
if (SCM_UNBNDP (printer))
scm_write (obj, port);
{
SCM p;
- p = scm_mkstrport (SCM_INUM0,
- scm_make_string (SCM_INUM0, SCM_UNDEFINED),
+ p = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
SCM_OPN | SCM_WRTNG,
FUNC_NAME);
scm_call_1 (proc, p);
{
SCM p;
- p = scm_mkstrport (SCM_INUM0,
- scm_make_string (SCM_INUM0, SCM_UNDEFINED),
+ p = scm_mkstrport (SCM_INUM0, SCM_BOOL_F,
SCM_OPN | SCM_WRTNG,
FUNC_NAME);
return p;
SCM
scm_c_read_string (const char *expr)
{
- /* FIXME: the c string gets packed into a string, only to get
- immediately unpacked in scm_mkstrport. */
SCM port = scm_mkstrport (SCM_INUM0,
scm_from_locale_string (expr),
SCM_OPN | SCM_RDNG,