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

Re: [MiNT] mintlib release



Frank Naumann wrote:

I like to make a new release of the mintlib. I have some questions about this:

- as I self used the mintlib not so much in the last time: How many people
  use the current-cvs mintlib? Has anyone noticed a problem/bug?


Hello, Frank !

I have some remarks about the current CVS MiNTLib, here is the list:

1) gets() patch for TOS
There is a problem in gets(), it appears only in plain TOS (without MiNT and without UNIXMODE=b). Simply calling gets() cause an infinite loop ! I posted a patch when you were away, unfortunately it has not been commited. I attach it again to this message. I'm not sure it is 100% correct, however it is better, and it does not affect programs running on MiNT. I really would like this one to be included in the next release.

2) Line A register preservation: some problems appeared with GCC 4 and the frame pointer, we should check that everything is OK (there is a compilation problem on libc_g.a, if I remember)

3) GCC 4 warnings. It would be nice, however not mandatory, to fix the MiNTLib warnings while compiling it with GCC 4.

4) GCC 4.3.0 compatibility. There has been some changes in the include directories in GCC 4.3.0, so the MiNTLib doesn't compile out of the box. I didn't look at it closely, but I think it is very easy to fix.

5) Initial stack problems. There has been some changes about the "initial stack", without a real comprehension about what exactly happened... I thing this is very dangerous, and probably the most important issue in the current MiNTLib...

That's all for now !

--
Vincent Rivière
diff -aurN mintlib-CVS-20080127/stdio/sysd-stdio.c mintlib-CVS-20080127-patch-20080127/stdio/sysd-stdio.c
--- mintlib-CVS-20080127/stdio/sysd-stdio.c	2008-01-27 10:02:19.609375000 +0100
+++ mintlib-CVS-20080127-patch-20080127/stdio/sysd-stdio.c	2008-01-27 10:11:33.890625000 +0100
@@ -77,112 +77,87 @@
   const long int fd = (long int) cookie;
 #endif
 
-#if 1
+  int save = errno;
+  ssize_t nread = 0;
+  char* bufptr = buf;
+  ssize_t read_bytes;
+  ssize_t i;
+  ssize_t skipped = 0;
+
+  if (n == 0)
+    {
+      return 0;
+    }
+
   if (n == 1)
     {
       /* short cut for reading 1 byte.  */
       /* unbuffered -> no conversion at all.  */
       return __read (fd, buf, 1);
     }
-  else
-    {
-  int save = errno;
-  ssize_t nread = 0;
-  char* bufptr = buf;
 
-  n--;
-  while (nread < n) 
+  /* The last read character may be \r.  */
+  /* In that case, we will need to read an additional character.  */
+  /* So read n-1 characters in order to keep room for that special case.  */
+  read_bytes = __read (fd, bufptr, n-1);
+  if (read_bytes < 0) 
     {
-      ssize_t read_bytes = __read (fd, bufptr, (int)(n - nread));
-      ssize_t i;
-      ssize_t skipped = 0;
-
-      if (read_bytes < 0) 
-        {
-          if (nread == 0)
-            return -1;
-          else
-            break;
-        }
-      else if (read_bytes == 0)
-        break;
-      
-      /* Now squeeze \r\n characters into \n.  */
-      read_bytes--;
-      for (i = 0; i < read_bytes; i++)
+      return -1;
+    }
+  
+  if (read_bytes == 0)
+    {
+      __set_errno (save);
+      return 0;
+    }
+  
+  /* Now squeeze \r\n characters into \n.  */
+  read_bytes--;
+  for (i = 0; i < read_bytes; i++)
+    {
+      if (bufptr[i] == '\r')
         {
-          if (bufptr[i] == '\r')
+          if (bufptr[i+1] == '\n')
             {
-              if (bufptr[i+1] == '\n')
-                {
-                  skipped++;
-                  continue;
-                }
+              skipped++;
+              continue;
             }
-          bufptr[i - skipped] = bufptr[i];
         }
-      read_bytes -= skipped;
-      bufptr += read_bytes;
-      nread += read_bytes;
-      
-      /* handle last character */
-      if (bufptr[skipped] == '\r')
+      bufptr[i - skipped] = bufptr[i];
+    }
+  read_bytes -= skipped;
+  bufptr += read_bytes;
+  nread += read_bytes;
+  
+  /* handle last character */
+  if (bufptr[skipped] == '\r')
+    {
+      /* last character is a CR */
+      i = __read (fd, bufptr+skipped+1, 1);
+      if (i == 1)
         {
-          /* last character is a CR */
-          i = __read (fd, bufptr+skipped+1, 1);
-          if (i == 1)
+          if (bufptr[skipped+1] != '\n')
             {
-              if (bufptr[skipped+1] != '\n')
-                {
-                  bufptr[0] = bufptr[skipped];
-                  bufptr[1] = bufptr[skipped+1];
-                  
-                  bufptr += 1;
-                  nread += 1;
-                }
-              else
-                  bufptr[0] = '\n';
+              bufptr[0] = bufptr[skipped];
+              bufptr[1] = bufptr[skipped+1];
+              
+              bufptr += 1;
+              nread += 1;
             }
           else
-            bufptr[0] = bufptr[skipped];
+              bufptr[0] = '\n';
         }
       else
-          bufptr[0] = bufptr[skipped];
-      
-      bufptr++;
-      nread++;
+        bufptr[0] = bufptr[skipped];
     }
+  else
+    bufptr[0] = bufptr[skipped];
+  
+  bufptr++;
+  nread++;
     
-    __set_errno (save);
-    return nread;
-      }
-#else
-/* new implementation from jens */
-
-/* Completly recoded, but I'm not really sure if it is a good idea.
- * But now it is working more compatible to the binary version
- * 'stdio_read' of it, and fgets is now working also on standard
- * TOS systems. fgetc is no longer skipping <CR> keys .... but I'm
- * not sure what may happen in other library functions.
- */
-	
-  int save = errno;
-  ssize_t read_bytes = __read (fd, buf, (int) (n));
-  ssize_t i;
-
-  if (read_bytes < 0)
-    return -1;
-
-  /* Now squeeze '\r' characters out of our buffer.  */
-  for (i = 0; i < read_bytes; i++)
-    {
-      if (buf[i] == '\r')
-	buf[i] = '\n';
-    }
-
   __set_errno (save);
-  return read_bytes;
-#endif
+  return nread;
 }
 
 /* Write N bytes from BUF to COOKIE.  */