/[guile]/guile/guile-core/libguile/rdelim.c
ViewVC logotype

Diff of /guile/guile-core/libguile/rdelim.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by mvo, Thu Jun 14 19:50:43 2001 UTC revision 1.11 by mvo, Mon Feb 11 18:06:49 2002 UTC
# Line 136  scm_do_read_line (SCM port, size_t *len_ Line 136  scm_do_read_line (SCM port, size_t *len_
136      {      {
137        size_t buf_len = (end + 1) - pt->read_pos;        size_t buf_len = (end + 1) - pt->read_pos;
138        /* Allocate a buffer of the perfect size.  */        /* Allocate a buffer of the perfect size.  */
139        unsigned char *buf = scm_must_malloc (buf_len + 1, "%read-line");        unsigned char *buf = scm_malloc (buf_len + 1);
140    
141        memcpy (buf, pt->read_pos, buf_len);        memcpy (buf, pt->read_pos, buf_len);
142        pt->read_pos += buf_len;        pt->read_pos += buf_len;
# Line 155  scm_do_read_line (SCM port, size_t *len_ Line 155  scm_do_read_line (SCM port, size_t *len_
155      size_t buf_size = (len < 50) ? 60 : len * 2;      size_t buf_size = (len < 50) ? 60 : len * 2;
156      /* Invariant: buf always has buf_size + 1 characters allocated;      /* Invariant: buf always has buf_size + 1 characters allocated;
157         the `+ 1' is for the final '\0'.  */         the `+ 1' is for the final '\0'.  */
158      unsigned char *buf = scm_must_malloc (buf_size + 1, "%read-line");      unsigned char *buf = scm_malloc (buf_size + 1);
159      size_t buf_len = 0;      size_t buf_len = 0;
160    
161      for (;;)      for (;;)
# Line 163  scm_do_read_line (SCM port, size_t *len_ Line 163  scm_do_read_line (SCM port, size_t *len_
163          if (buf_len + len > buf_size)          if (buf_len + len > buf_size)
164            {            {
165              size_t new_size = (buf_len + len) * 2;              size_t new_size = (buf_len + len) * 2;
166              buf = scm_must_realloc (buf, buf_size + 1, new_size + 1,              buf = scm_realloc (buf, new_size + 1);
                                     "%read-line");  
167              buf_size = new_size;              buf_size = new_size;
168            }            }
169    
# Line 197  scm_do_read_line (SCM port, size_t *len_ Line 196  scm_do_read_line (SCM port, size_t *len_
196        }        }
197    
198      /* I wonder how expensive this realloc is.  */      /* I wonder how expensive this realloc is.  */
199      buf = scm_must_realloc (buf, buf_size + 1, buf_len + 1, "%read-line");      buf = scm_realloc (buf, buf_len + 1);
200      buf[buf_len] = '\0';      buf[buf_len] = '\0';
201      *len_p = buf_len;      *len_p = buf_len;
202      return buf;      return buf;
203    }    }
204  }    }
205    
206    
207  /*  /*
# Line 247  SCM_DEFINE (scm_read_line, "%read-line", Line 246  SCM_DEFINE (scm_read_line, "%read-line",
246            term = SCM_MAKE_CHAR ('\n');            term = SCM_MAKE_CHAR ('\n');
247            s[slen-1] = '\0';            s[slen-1] = '\0';
248            line = scm_take_str (s, slen-1);            line = scm_take_str (s, slen-1);
           scm_done_free (1);  
249            SCM_INCLINE (port);            SCM_INCLINE (port);
250          }          }
251        else        else
# Line 256  SCM_DEFINE (scm_read_line, "%read-line", Line 254  SCM_DEFINE (scm_read_line, "%read-line",
254            term = SCM_EOF_VAL;            term = SCM_EOF_VAL;
255            line = scm_take_str (s, slen);            line = scm_take_str (s, slen);
256            SCM_COL (port) += slen;            SCM_COL (port) += slen;
257          }                  }
258      }      }
259    
260    if (pt->rw_random)    if (pt->rw_random)

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26