guile-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

guile/guile-core/libguile ChangeLog validate.h ...


From: Gary Houston
Subject: guile/guile-core/libguile ChangeLog validate.h ...
Date: Mon, 08 Jan 2001 15:10:07 -0800

CVSROOT:        /cvs
Module name:    guile
Changes by:     Gary Houston <address@hidden>   01/01/08 15:10:06

Modified files:
        guile-core/libguile: ChangeLog validate.h ioext.c socket.c 

Log message:
        * validate.h (SCM_VALIDATE_SUBSTRING_SPEC_COPY): new macro.
        * ioext.c (scm_read_string_x_partial, scm_read_delimited_x),
        socket.c (scm_recvfrom): use the new macro, plus minor docstring
        changes.
        * ioext.c (scm_read_string_x_partial): don't crash if -1 is supplied
        for fdes.  if current input port is used, check that it's a file
        port.

CVSWeb URLs:
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-core/libguile/ChangeLog.diff?r1=1.1230&r2=1.1231
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-core/libguile/validate.h.diff?r1=1.23&r2=1.24
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-core/libguile/ioext.c.diff?r1=1.74&r2=1.75
http://subversions.gnu.org/cgi-bin/cvsweb/guile/guile-core/libguile/socket.c.diff?r1=1.58&r2=1.59

Patches:
Index: guile/guile-core/libguile/ChangeLog
diff -u guile/guile-core/libguile/ChangeLog:1.1230 
guile/guile-core/libguile/ChangeLog:1.1231
--- guile/guile-core/libguile/ChangeLog:1.1230  Sat Jan  6 14:03:07 2001
+++ guile/guile-core/libguile/ChangeLog Mon Jan  8 15:10:06 2001
@@ -1,3 +1,13 @@
+2001-01-08  Gary Houston  <address@hidden>
+
+       * validate.h (SCM_VALIDATE_SUBSTRING_SPEC_COPY): new macro.
+       * ioext.c (scm_read_string_x_partial, scm_read_delimited_x),
+       socket.c (scm_recvfrom): use the new macro, plus minor docstring
+       changes.
+       * ioext.c (scm_read_string_x_partial): don't crash if -1 is supplied
+       for fdes.  if current input port is used, check that it's a file
+       port.
+
 2001-01-06  Gary Houston  <address@hidden>
 
        * ioext.c (scm_read_string_x_partial): new procedure, implements
Index: guile/guile-core/libguile/ioext.c
diff -u guile/guile-core/libguile/ioext.c:1.74 
guile/guile-core/libguile/ioext.c:1.75
--- guile/guile-core/libguile/ioext.c:1.74      Sat Jan  6 14:03:07 2001
+++ guile/guile-core/libguile/ioext.c   Mon Jan  8 15:10:06 2001
@@ -105,51 +105,38 @@
   char *dest;
   long read_len;
   long chars_read = 0;
-  int fdes = -1;
-  SCM port = SCM_BOOL_F;
+  int fdes;
 
-  SCM_VALIDATE_STRING_COPY (1, str, dest);
-  if (SCM_UNBNDP (port_or_fdes))
-    port = scm_cur_inp;
-  else if (SCM_INUMP (port_or_fdes))
-    fdes = SCM_INUM (port_or_fdes);
-  else
-    {
-      SCM_VALIDATE_OPFPORT (2, port_or_fdes);
-      SCM_VALIDATE_INPUT_PORT (2, port_or_fdes);
-      port = port_or_fdes;
-    }
-
   {
-    long string_len = SCM_STRING_LENGTH (str);
-    long offset = SCM_NUM2LONG_DEF (3, start, 0);
-    long last = SCM_NUM2LONG_DEF (4, end, string_len);
-
-    if (offset < 0 || offset > string_len)
-      SCM_OUT_OF_RANGE (3, start);
-    if (last < offset || last > string_len)
-      SCM_OUT_OF_RANGE (4, end);
+    long offset;
+    long last;
 
+    SCM_VALIDATE_SUBSTRING_SPEC_COPY (1, str, dest, 3, start, offset,
+                                     4, end, last);
     dest += offset;
     read_len = last - offset;
   }
 
-  if (fdes == -1)
+  if (SCM_INUMP (port_or_fdes))
+    fdes = SCM_INUM (port_or_fdes);
+  else
     {
-      /* if there's anything in the port buffers, use it.  but if
-        something is read from the buffers, don't touch the file
-        descriptor.  otherwise the "return immediately if something
-        is available" rule may be violated.  */
-      chars_read = scm_take_from_input_buffers (port, dest, read_len);
+      SCM port = SCM_UNBNDP (port_or_fdes) ? scm_cur_inp : port_or_fdes;
 
+      SCM_VALIDATE_OPFPORT (2, port);
+      SCM_VALIDATE_INPUT_PORT (2, port);
+
+      /* if there's anything in the port buffers, use it, but then
+        don't touch the file descriptor.  otherwise the
+        "return immediately if something is available" rule may
+        be violated.  */
+      chars_read = scm_take_from_input_buffers (port, dest, read_len);
+      fdes = SCM_FPORT_FDES (port);
     }
 
   if (chars_read == 0 && read_len > 0) /* don't confuse read_len == 0 with
                                          EOF.  */
     {
-      if (fdes == -1)
-       fdes = SCM_FPORT_FDES (port);
-      
       SCM_SYSCALL (chars_read = read (fdes, dest, read_len));
       if (chars_read == -1)
        {
@@ -174,46 +161,39 @@
 #undef FUNC_NAME
 
 SCM_DEFINE (scm_read_delimited_x, "%read-delimited!", 3, 3, 0,
-            (SCM delims, SCM buf, SCM gobble, SCM port, SCM start, SCM end),
-           "Read characters from @var{port} into @var{buf} until one of the\n"
-           "characters in the @var{delims} string is encountered.  If 
@var{gobble?}\n"
-           "is true, store the delimiter character in @var{buf} as well; 
otherwise,\n"
-           "discard it.  If @var{port} is not specified, use the value of\n"
+            (SCM delims, SCM str, SCM gobble, SCM port, SCM start, SCM end),
+           "Read characters from @var{port} into @var{str} until one of the\n"
+           "characters in the @var{delims} string is encountered.  If 
@var{gobble}\n"
+           "is true, discard the delimiter character; otherwise, leave it\n"
+           "in the input stream for the next read.\n"
+           "If @var{port} is not specified, use the value of\n"
            "@code{(current-input-port)}.  If @var{start} or @var{end} are 
specified,\n"
-           "store data only into the substring of @var{buf} bounded by 
@var{start}\n"
-           "and @var{end} (which default to the beginning and end of the 
buffer,\n"
+           "store data only into the substring of @var{str} bounded by 
@var{start}\n"
+           "and @var{end} (which default to the beginning and end of the 
string,\n"
            "respectively).\n\n"
            "Return a pair consisting of the delimiter that terminated the 
string and\n"
            "the number of characters read.  If reading stopped at the end of 
file,\n"
-           "the delimiter returned is the @var{eof-object}; if the buffer was 
filled\n"
+           "the delimiter returned is the @var{eof-object}; if the string was 
filled\n"
            "without encountering a delimiter, this value is @var{#f}.")
 #define FUNC_NAME s_scm_read_delimited_x
 {
   long j;
-  char *cbuf;
+  char *buf;
   long cstart;
-  long cend, tend;
+  long cend;
   int c;
   char *cdelims;
   int num_delims;
 
   SCM_VALIDATE_STRING_COPY (1, delims, cdelims);
   num_delims = SCM_STRING_LENGTH (delims);
-  SCM_VALIDATE_STRING_COPY (2,buf,cbuf);
-  cend = SCM_STRING_LENGTH (buf);
+  SCM_VALIDATE_SUBSTRING_SPEC_COPY (2, str, buf, 5, start, cstart,
+                                   6, end, cend);
   if (SCM_UNBNDP (port))
     port = scm_cur_inp;
   else
     SCM_VALIDATE_OPINPORT (4,port);
 
-  SCM_VALIDATE_INUM_DEF_COPY (5,start,0,cstart);
-  SCM_ASSERT_RANGE(5, start, cstart >= 0 && cstart < cend);
-
-  SCM_VALIDATE_INUM_DEF_COPY (6,end,cend,tend);
-  SCM_ASSERT_RANGE(6, end, tend > cstart && tend <= cend);
-
-  cend = tend;
-
   for (j = cstart; j < cend; j++)
     {  
       int k;
@@ -234,7 +214,7 @@
        return scm_cons (SCM_EOF_VAL, 
                         scm_long2num (j - cstart));
 
-      cbuf[j] = c;
+      buf[j] = c;
     }
   return scm_cons (SCM_BOOL_F, scm_long2num (j - cstart));
 }
Index: guile/guile-core/libguile/socket.c
diff -u guile/guile-core/libguile/socket.c:1.58 
guile/guile-core/libguile/socket.c:1.59
--- guile/guile-core/libguile/socket.c:1.58     Wed Nov 22 03:20:03 2000
+++ guile/guile-core/libguile/socket.c  Mon Jan  8 15:10:06 2001
@@ -746,12 +746,12 @@
 #undef FUNC_NAME
 
 SCM_DEFINE (scm_recvfrom, "recvfrom!", 2, 3, 0,
-            (SCM sock, SCM buf, SCM flags, SCM start, SCM end),
+            (SCM sock, SCM str, SCM flags, SCM start, SCM end),
            "Returns data from the socket port @var{socket} and also 
information about\n"
            "where the data was received from.  @var{socket} must already\n"
            "be bound to the address from which data is to be received.\n"
-           "@code{buf}, is a string into which\n"
-           "the data will be written.  The size of @var{buf} limits the amount 
of\n"
+           "@code{str}, is a string into which\n"
+           "the data will be written.  The size of @var{str} limits the amount 
of\n"
            "data which can be received: in the case of packet\n"
            "protocols, if a packet larger than this limit is encountered then 
some data\n"
            "will be irrevocably lost.\n\n"
@@ -760,7 +760,7 @@
            "The value returned is a pair: the CAR is the number of bytes read 
from\n"
            "the socket and the CDR an address object in the same form as 
returned by\n"
            "@code{accept}.\n\n"
-           "The @var{start} and @var{end} arguments specify a substring of 
@var{buf}\n"
+           "The @var{start} and @var{end} arguments specify a substring of 
@var{str}\n"
            "to which the data should be written.\n\n"
            "Note that the data is read directly from the socket file 
descriptor:\n"
            "any unread buffered port data is ignored.")
@@ -769,44 +769,23 @@
   int rv;
   int fd;
   int flg;
-  int offset = 0;
+  char *buf;
+  int offset;
   int cend;
   size_t tmp_size;
   SCM address;
 
   SCM_VALIDATE_OPFPORT (1,sock);
-  SCM_VALIDATE_STRING (2,buf);
-  cend = SCM_STRING_LENGTH (buf);
-  
+  fd = SCM_FPORT_FDES (sock);
+  SCM_VALIDATE_SUBSTRING_SPEC_COPY (2, str, buf, 4, start, offset,
+                                   5, end, cend);
   if (SCM_UNBNDP (flags))
     flg = 0;
   else
-    {
-      flg = SCM_NUM2ULONG (3,flags);
-
-      if (!SCM_UNBNDP (start))
-       {
-         offset = (int) SCM_NUM2LONG (4,start);
-         
-         if (offset < 0 || offset >= cend)
-           SCM_OUT_OF_RANGE (4, start);
-
-         if (!SCM_UNBNDP (end))
-           {
-             int tend = (int) SCM_NUM2LONG (5,end);
-      
-             if (tend <= offset || tend > cend)
-               SCM_OUT_OF_RANGE (5, end);
-
-             cend = tend;
-           }
-       }
-    }
-
-  fd = SCM_FPORT_FDES (sock);
+    SCM_VALIDATE_ULONG_COPY (3, flags, flg);
 
   tmp_size = scm_addr_buffer_size;
-  SCM_SYSCALL (rv = recvfrom (fd, SCM_STRING_CHARS (buf) + offset,
+  SCM_SYSCALL (rv = recvfrom (fd, buf + offset,
                              cend - offset, flg,
                              (struct sockaddr *) scm_addr_buffer,
                              &tmp_size));
Index: guile/guile-core/libguile/validate.h
diff -u guile/guile-core/libguile/validate.h:1.23 
guile/guile-core/libguile/validate.h:1.24
--- guile/guile-core/libguile/validate.h:1.23   Sat Jan  6 10:46:48 2001
+++ guile/guile-core/libguile/validate.h        Mon Jan  8 15:10:06 2001
@@ -1,4 +1,4 @@
-/* $Id: validate.h,v 1.23 2001/01/06 18:46:48 mvo Exp $ */
+/* $Id: validate.h,v 1.24 2001/01/08 23:10:06 ghouston Exp $ */
 /*     Copyright (C) 1999, 2000 Free Software Foundation, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
@@ -133,6 +133,22 @@
   do { \
     SCM_ASSERT (SCM_STRINGP (str), str, pos, FUNC_NAME); \
     cvar = SCM_STRING_CHARS(str); \
+  } while (0)
+
+/* validate a string and optional start/end arguments which default to
+   0/string-len.  this is unrelated to the old shared substring
+   support, so please do not deprecate it :) */
+#define SCM_VALIDATE_SUBSTRING_SPEC_COPY(pos_str, str, c_str, \
+                                         pos_start, start, c_start,\
+                                         pos_end, end, c_end) \
+  do {\
+    SCM_VALIDATE_STRING_COPY (pos_str, str, c_str);\
+    SCM_VALIDATE_INUM_DEF_COPY (pos_start, start, 0, c_start);\
+    SCM_VALIDATE_INUM_DEF_COPY (pos_end, end, SCM_STRING_LENGTH (str), c_end);\
+    SCM_ASSERT_RANGE (pos_start, start,\
+                      0 <= c_start && c_start <= SCM_STRING_LENGTH (str));\
+    SCM_ASSERT_RANGE (pos_end, end,\
+                     c_start <= c_end && c_end <= SCM_STRING_LENGTH (str));\
   } while (0)
 
 #define SCM_VALIDATE_REAL(pos, z) SCM_MAKE_VALIDATE (pos, z, REALP)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]