diff --git a/ChangeLog b/ChangeLog index a68a368ab..8763d9abc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ 2007-12-04 Ludovic Courtès - * NEWS: Mention `accept' bug fix. + * NEWS: Mention `accept' and `scm_c_{read,write}' bug fixes. 2007-12-03 Ludovic Courtès diff --git a/NEWS b/NEWS index 341fefed5..b80b47249 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,7 @@ Changes in 1.8.4 (since 1.8.3) ** Fixed a segmentation fault which occurred when displaying the backtrace of a stack with a promise object (made by `delay') in it. ** Make `accept' leave guile mode while blocking +** `scm_c_read ()' and `scm_c_write ()' now type-check their port argument * New modules (see the manual for details) diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 7a68d5449..3d7856c43 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,5 +1,8 @@ 2007-12-04 Ludovic Courtès + * ports.c (scm_c_read): Validate PORT as an open input port. + (scm_c_write): Validate PORT as an open output port. + * socket.c (scm_accept): Leave guile mode using `scm_std_select ()' before calling `accept(2)'. Reported by dskr . diff --git a/libguile/ports.c b/libguile/ports.c index 6cb77966e..c4ccca3e2 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -1069,10 +1069,14 @@ scm_lfwrite (const char *ptr, size_t size, SCM port) size_t scm_c_read (SCM port, void *buffer, size_t size) +#define FUNC_NAME "scm_c_read" { - scm_t_port *pt = SCM_PTAB_ENTRY (port); + scm_t_port *pt; size_t n_read = 0, n_available; + SCM_VALIDATE_OPINPORT (1, port); + + pt = SCM_PTAB_ENTRY (port); if (pt->rw_active == SCM_PORT_WRITE) scm_ptobs[SCM_PTOBNUM (port)].flush (port); @@ -1109,6 +1113,7 @@ scm_c_read (SCM port, void *buffer, size_t size) return n_read + size; } +#undef FUNC_NAME /* scm_c_write * @@ -1120,11 +1125,17 @@ scm_c_read (SCM port, void *buffer, size_t size) * Warning: Doesn't update port line and column counts! */ -void +void scm_c_write (SCM port, const void *ptr, size_t size) +#define FUNC_NAME "scm_c_write" { - scm_t_port *pt = SCM_PTAB_ENTRY (port); - scm_t_ptob_descriptor *ptob = &scm_ptobs[SCM_PTOBNUM (port)]; + scm_t_port *pt; + scm_t_ptob_descriptor *ptob; + + SCM_VALIDATE_OPOUTPORT (1, port); + + pt = SCM_PTAB_ENTRY (port); + ptob = &scm_ptobs[SCM_PTOBNUM (port)]; if (pt->rw_active == SCM_PORT_READ) scm_end_input (port); @@ -1134,6 +1145,7 @@ scm_c_write (SCM port, const void *ptr, size_t size) if (pt->rw_random) pt->rw_active = SCM_PORT_WRITE; } +#undef FUNC_NAME void scm_flush (SCM port)