1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

scm_c_read instead of scm_c_read_unlock

* libguile/ports.h (scm_c_read_unlocked): Remove.
* libguile/ports.c (scm_c_read): Rename from scm_c_read_unlocked.
  Remove old scm_c_read.  Lock around access to the rw_active flag, and
  call scm_flush instead of scm_flush_unlocked, and scm_fill_input
  instead of scm_fill_input_unlocked.
* libguile/read.c (scm_i_scan_for_encoding): Use scm_c_read instead of
  the _unlocked function.
This commit is contained in:
Andy Wingo 2016-04-22 20:42:24 +02:00
parent fb577b59af
commit 4934b69ddf
3 changed files with 10 additions and 20 deletions

View file

@ -1555,7 +1555,7 @@ scm_c_read_bytes_unlocked (SCM port, SCM dst, size_t start, size_t count)
read buffer. Used by an application when it wants to read into a read buffer. Used by an application when it wants to read into a
memory chunk that's not owned by Guile's GC. */ memory chunk that's not owned by Guile's GC. */
size_t size_t
scm_c_read_unlocked (SCM port, void *buffer, size_t size) scm_c_read (SCM port, void *buffer, size_t size)
#define FUNC_NAME "scm_c_read" #define FUNC_NAME "scm_c_read"
{ {
size_t copied = 0; size_t copied = 0;
@ -1570,15 +1570,20 @@ scm_c_read_unlocked (SCM port, void *buffer, size_t size)
if (pt->rw_random) if (pt->rw_random)
{ {
if (pt->rw_active == SCM_PORT_WRITE) int needs_flush;
scm_flush_unlocked (port); scm_i_pthread_mutex_lock (pt->lock);
needs_flush = pt->rw_active == SCM_PORT_WRITE;
pt->rw_active = SCM_PORT_READ; pt->rw_active = SCM_PORT_READ;
scm_i_pthread_mutex_unlock (pt->lock);
if (needs_flush)
scm_flush (port);
} }
while (copied < size) while (copied < size)
{ {
size_t count; size_t count;
read_buf = scm_fill_input_unlocked (port); read_buf = scm_fill_input (port);
count = scm_port_buffer_take (read_buf, dst + copied, size - copied); count = scm_port_buffer_take (read_buf, dst + copied, size - copied);
copied += count; copied += count;
if (count == 0) if (count == 0)
@ -1607,20 +1612,6 @@ scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t count)
return ret; return ret;
} }
size_t
scm_c_read (SCM port, void *buffer, size_t size)
{
scm_i_pthread_mutex_t *lock;
size_t ret;
scm_c_lock_port (port, &lock);
ret = scm_c_read_unlocked (port, buffer, size);
if (lock)
scm_i_pthread_mutex_unlock (lock);
return ret;
}
/* Update the line and column number of PORT after consumption of C. */ /* Update the line and column number of PORT after consumption of C. */
static inline void static inline void
update_port_lf (scm_t_wchar c, SCM port) update_port_lf (scm_t_wchar c, SCM port)

View file

@ -310,7 +310,6 @@ SCM_INLINE int scm_c_try_lock_port (SCM port, scm_i_pthread_mutex_t **lock);
SCM_API int scm_get_byte_or_eof (SCM port); SCM_API int scm_get_byte_or_eof (SCM port);
SCM_API int scm_peek_byte_or_eof (SCM port); SCM_API int scm_peek_byte_or_eof (SCM port);
SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size); SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size);
SCM_API size_t scm_c_read_unlocked (SCM port, void *buffer, size_t size);
SCM_API size_t scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t count); SCM_API size_t scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t count);
SCM_API scm_t_wchar scm_getc (SCM port); SCM_API scm_t_wchar scm_getc (SCM port);
SCM_API scm_t_wchar scm_getc_unlocked (SCM port); SCM_API scm_t_wchar scm_getc_unlocked (SCM port);

View file

@ -2100,7 +2100,7 @@ scm_i_scan_for_encoding (SCM port)
if (SCM_FPORTP (port) && !SCM_FDES_RANDOM_P (SCM_FPORT_FDES (port))) if (SCM_FPORTP (port) && !SCM_FDES_RANDOM_P (SCM_FPORT_FDES (port)))
return NULL; return NULL;
bytes_read = scm_c_read_unlocked (port, header, SCM_ENCODING_SEARCH_SIZE); bytes_read = scm_c_read (port, header, SCM_ENCODING_SEARCH_SIZE);
header[bytes_read] = '\0'; header[bytes_read] = '\0';
scm_seek (port, scm_from_int (0), scm_from_int (SEEK_SET)); scm_seek (port, scm_from_int (0), scm_from_int (SEEK_SET));
} }