diff options
author | Andy Wingo <wingo@pobox.com> | 2013-10-24 10:19:07 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-10-26 13:13:17 +0200 |
commit | db071766650d10c67524b3ddb00decfd60c55741 (patch) | |
tree | 3ee6cc0468fde846cd431a3bfce2d19230dee588 | |
parent | 0f676d8725ebc79cd166047203c5400d8c639a25 (diff) | |
download | guile-db071766650d10c67524b3ddb00decfd60c55741.tar.gz |
Add stringbuf printer
* libguile/strings.h:
* libguile/strings.c (scm_i_print_stringbuf):
* libguile/print.c (iprin1): Add a printer for stringbufs. The
disassembler can print a stringbuf.
-rw-r--r-- | libguile/print.c | 3 | ||||
-rw-r--r-- | libguile/strings.c | 17 | ||||
-rw-r--r-- | libguile/strings.h | 2 |
3 files changed, 22 insertions, 0 deletions
diff --git a/libguile/print.c b/libguile/print.c index dbc6e96ed..a77f1a8b4 100644 --- a/libguile/print.c +++ b/libguile/print.c @@ -609,6 +609,9 @@ iprin1 (SCM exp, SCM port, scm_print_state *pstate) break; } break; + case scm_tc7_stringbuf: + scm_i_print_stringbuf (exp, port, pstate); + break; case scm_tc7_string: if (SCM_WRITINGP (pstate)) { diff --git a/libguile/strings.c b/libguile/strings.c index 8ee909bca..1f492bd0c 100644 --- a/libguile/strings.c +++ b/libguile/strings.c @@ -261,6 +261,23 @@ scm_i_pthread_mutex_t stringbuf_write_mutex = SCM_I_PTHREAD_MUTEX_INITIALIZER; #define IS_SH_STRING(str) (SCM_CELL_TYPE(str)==SH_STRING_TAG) +void +scm_i_print_stringbuf (SCM exp, SCM port, scm_print_state *pstate) +{ + SCM str; + + scm_i_pthread_mutex_lock (&stringbuf_write_mutex); + SET_STRINGBUF_SHARED (exp); + scm_i_pthread_mutex_unlock (&stringbuf_write_mutex); + + str = scm_double_cell (RO_STRING_TAG, SCM_UNPACK(exp), + 0, STRINGBUF_LENGTH (exp)); + + scm_puts ("#<stringbuf ", port); + scm_iprin1 (str, port, pstate); + scm_puts (">", port); +} + SCM scm_nullstr; /* Create a scheme string with space for LEN 8-bit Latin-1-encoded diff --git a/libguile/strings.h b/libguile/strings.h index 445d9c878..130c436a6 100644 --- a/libguile/strings.h +++ b/libguile/strings.h @@ -179,6 +179,8 @@ SCM_API SCM scm_makfromstrs (int argc, char **argv); #define SCM_I_STRINGBUF_F_SHARED 0x100 #define SCM_I_STRINGBUF_F_WIDE 0x400 +SCM_INTERNAL void scm_i_print_stringbuf (SCM exp, SCM port, + scm_print_state *pstate); /* internal accessor functions. Arguments must be valid. */ |