canonicalize-lgpl: fix compilation error on mingw

2006-12-23 Thread Bruno Haible
This fixes a build error on mingw, if you happen to use the sys_stat module
together with the canonicalize-lgpl module.


2006-12-23  Bruno Haible  [EMAIL PROTECTED]

* lib/canonicalize-lgpl.c (__realpath): Test HAVE_READLINK instead of
S_ISLNK.
Needed because gnulib's sys/stat.h replacement defines S_ISLNK on
mingw.

*** gnulib-20061208/lib/canonicalize-lgpl.c.bak 2006-11-06 19:21:35.0 
+0100
--- gnulib-20061208/lib/canonicalize-lgpl.c 2006-12-23 04:55:49.0 
+0100
***
*** 101,107 
char *rpath, *dest, *extra_buf = NULL;
const char *start, *end, *rpath_limit;
long int path_max;
! #ifdef S_ISLNK
int num_links = 0;
  #endif
  
--- 101,107 
char *rpath, *dest, *extra_buf = NULL;
const char *start, *end, *rpath_limit;
long int path_max;
! #if HAVE_READLINK
int num_links = 0;
  #endif
  
***
*** 231,237 
  #endif
goto error;
  
! #ifdef S_ISLNK
  if (S_ISLNK (st.st_mode))
{
  char *buf;
--- 231,237 
  #endif
goto error;
  
! #if HAVE_READLINK
  if (S_ISLNK (st.st_mode))
{
  char *buf;




make safe_read usable in a mixed C/C++ build

2006-12-23 Thread Bruno Haible
Hi Jim,

For some complicated reasons (too long to explain here), gettext needs to
use safe-read.h with a C++ compiler on mingw and cygwin. Is this patch ok
with you?


2006-12-23  Bruno Haible  [EMAIL PROTECTED]

* lib/safe-read.h [C++]: Wrap declarations in extern C.

*** gnulib-20061208/lib/safe-read.h.bak 2005-05-14 08:03:58.0 +0200
--- gnulib-20061208/lib/safe-read.h 2006-12-23 05:45:53.0 +0100
***
*** 1,5 
  /* An interface to read() that retries after interrupts.
!Copyright (C) 2002 Free Software Foundation, Inc.
  
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
--- 1,5 
  /* An interface to read() that retries after interrupts.
!Copyright (C) 2002, 2006 Free Software Foundation, Inc.
  
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
***
*** 17,25 
--- 17,35 
  
  #include stddef.h
  
+ #ifdef __cplusplus
+ extern C {
+ #endif
+ 
+ 
  #define SAFE_READ_ERROR ((size_t) -1)
  
  /* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted.
 Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR
 upon error.  */
  extern size_t safe_read (int fd, void *buf, size_t count);
+ 
+ 
+ #ifdef __cplusplus
+ }
+ #endif




Re: GCC optimizes integer overflow: bug or feature?

2006-12-23 Thread Denis Vlasenko
On Saturday 23 December 2006 10:06, Rask Ingemann Lambertsen wrote:
No, because you'd read past the end of the array:
 
 #include stdlib.h
 
 int main (int argc, char *argv[])
 {
   char *a;
   if ((a == malloc (sizeof (char
 {
   int r;
 
   a[0] = 1;
   r = f (a);
   free (a);
   return (r);
 }
   return (0);
 }

Good spotting.

We can use  instead of . C standard doesn't
aloow lazy execution of (a  b) IIRC...

int f(char *p)
{
    if ((p[0] == 1)  (p[1] == 2)) return 1;
    return 0;
}

Currently it does this:

.file   t.c
.text
.p2align 2,,3
.globl f
.type   f, @function
f:
movl4(%esp), %edx
cmpb$1, (%edx)
sete%al
cmpb$2, 1(%edx)
sete%dl
andl%edx, %eax
movzbl  %al, %eax
ret
.size   f, .-f
.ident  GCC: (GNU) 4.2.0 20061128 (prerelease)
.section.note.GNU-stack,,@progbits

--
vda




Re: GCC optimizes integer overflow: bug or feature?

2006-12-23 Thread Rask Ingemann Lambertsen
On Fri, Dec 22, 2006 at 01:58:39AM +0100, Denis Vlasenko wrote:
 
 Or this, absolutely typical C code. i386 arch can compare
 16 bits at a time here (luckily, no alighment worries on this arch):
 
 # cat tt.c
 int f(char *p)
 {
 if (p[0] == 1  p[1] == 2) return 1;
 return 0;
 }

   No, because you'd read past the end of the array:

#include stdlib.h

int main (int argc, char *argv[])
{
  char *a;
  if ((a == malloc (sizeof (char
{
  int r;

  a[0] = 1;
  r = f (a);
  free (a);
  return (r);
}
  return (0);
}

-- 
Rask Ingemann Lambertsen




Re: coreutils 6.6 fails to compile on IRIX 5.3

2006-12-23 Thread Paul Eggert
Bruno Haible [EMAIL PROTECTED] writes:

 ! #if HAVE_WCHAR_H
 ! # include wctype.h
 ! #else
 ! # ifndef iswprint
 ! #  define iswprint(wc) 1
 ! # endif
 ! #endif

That should work, but I'd prefer something less intrusive on uses of
the module, so that the source code says only #include wctype.h.

I'm willing to complicate the module implementation a bit to get
there.  The idea is to enable simplifications like the patch proposed in
http://lists.gnu.org/archive/html/bug-gnulib/2006-12/msg00202.html.

How about the following patch instead?  I installed it.

2006-12-23  Paul Eggert  [EMAIL PROTECTED]

Fix bug reported by Bruno Haible in
http://lists.gnu.org/archive/html/bug-gnulib/2006-12/msg00228.html
where quotearg.c didn't compile on Mac OS X 10.2 because it
lacks wchar.h and wint_t.
* lib/wctype_.h (__wctype_wint_t): New type.
Include stdio.h, time.h, wchar.h only if HAVE_WINT_T.
(iswalnum, iswalpha, iswblank, iswcntrl, iswdigit, iswgraph):
(iswlower, iswprint, iswpunct, iswspace, iswupper, ixwxdigit):
Arg is now of type __wctype_wint_t, not wint_t.
* m4/wctype.m4 (gl_WCTYPE_H): Require gt_TYPE_WINT_T, and
substitute HAVE_WINT_T.
* modules/wctype (Files): Add m4/wint_t.m4.
(wctype.h): Substitute HAVE_WINT_T.

Index: lib/wctype_.h
===
RCS file: /cvsroot/gnulib/gnulib/lib/wctype_.h,v
retrieving revision 1.2
diff -u -p -r1.2 wctype_.h
--- lib/wctype_.h   22 Dec 2006 16:27:26 -  1.2
+++ lib/wctype_.h   24 Dec 2006 07:55:05 -
@@ -29,14 +29,19 @@
 #ifndef _GL_WCTYPE_H
 #define _GL_WCTYPE_H

+#if @HAVE_WINT_T@ - 0
 /* Solaris 2.5 has a bug: wchar.h must be included before wctype.h.
Tru64 with Desktop Toolkit C has a bug: stdio.h must be included before
wchar.h.
BSD/OS 4.1 has a bug: stdio.h and time.h must be included before
wchar.h.  */
-#include stdio.h
-#include time.h
-#include wchar.h
+# include stdio.h
+# include time.h
+# include wchar.h
+typedef wint_t __wctype_wint_t;
+#else
+typedef int __wctype_wint_t;
+#endif

 /* Include the original wctype.h if it exists.
BeOS 5 has the functions but no wctype.h.  */
@@ -55,7 +60,7 @@ static wint_t _ctmp_;

 #if !defined iswalnum  !HAVE_ISWCNTRL
 static inline int
-iswalnum (wint_t wc)
+iswalnum (__wctype_wint_t wc)
 {
   return ((wc = '0'  wc = '9')
  || ((wc  ~0x20) = 'A'  (wc  ~0x20) = 'Z'));
@@ -65,7 +70,7 @@ iswalnum (wint_t wc)

 #if !defined iswalpha  !HAVE_ISWCNTRL
 static inline int
-iswalpha (wint_t wc)
+iswalpha (__wctype_wint_t wc)
 {
   return (wc  ~0x20) = 'A'  (wc  ~0x20) = 'Z';
 }
@@ -74,7 +79,7 @@ iswalpha (wint_t wc)

 #if !defined iswblank  !HAVE_ISWCNTRL
 static inline int
-iswblank (wint_t wc)
+iswblank (__wctype_wint_t wc)
 {
   return wc == ' ' || wc == '\t';
 }
@@ -83,7 +88,7 @@ iswblank (wint_t wc)

 #if !defined iswcntrl  !HAVE_ISWCNTRL
 static inline int
-iswcntrl (wint_t wc)
+iswcntrl (__wctype_wint_t wc)
 {
   return (wc  ~0x1f) == 0 || wc == 0x7f;
 }
@@ -92,7 +97,7 @@ iswcntrl (wint_t wc)

 #if !defined iswdigit  !HAVE_ISWCNTRL
 static inline int
-iswdigit (wint_t wc)
+iswdigit (__wctype_wint_t wc)
 {
   return wc = '0'  wc = '9';
 }
@@ -101,7 +106,7 @@ iswdigit (wint_t wc)

 #if !defined iswgraph  !HAVE_ISWCNTRL
 static inline int
-iswgraph (wint_t wc)
+iswgraph (__wctype_wint_t wc)
 {
   return wc = '!'  wc = '~';
 }
@@ -110,7 +115,7 @@ iswgraph (wint_t wc)

 #if !defined iswlower  !HAVE_ISWCNTRL
 static inline int
-iswlower (wint_t wc)
+iswlower (__wctype_wint_t wc)
 {
   return wc = 'a'  wc = 'z';
 }
@@ -119,7 +124,7 @@ iswlower (wint_t wc)

 #if !defined iswprint  !HAVE_ISWCNTRL
 static inline int
-iswprint (wint_t wc)
+iswprint (__wctype_wint_t wc)
 {
   return wc = ' '  wc = '~';
 }
@@ -128,7 +133,7 @@ iswprint (wint_t wc)

 #if !defined iswpunct  !HAVE_ISWCNTRL
 static inline int
-iswpunct (wint_t wc)
+iswpunct (__wctype_wint_t wc)
 {
   return (wc = '!'  wc = '~'
   !((wc = '0'  wc = '9')
@@ -139,7 +144,7 @@ iswpunct (wint_t wc)

 #if !defined iswspace  !HAVE_ISWCNTRL
 static inline int
-iswspace (wint_t wc)
+iswspace (__wctype_wint_t wc)
 {
   return (wc == ' ' || wc == '\t'
  || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
@@ -149,7 +154,7 @@ iswspace (wint_t wc)

 #if !defined iswupper  !HAVE_ISWCNTRL
 static inline int
-iswupper (wint_t wc)
+iswupper (__wctype_wint_t wc)
 {
   return wc = 'A'  wc = 'Z';
 }
@@ -158,7 +163,7 @@ iswupper (wint_t wc)

 #if !defined iswxdigit  !HAVE_ISWCNTRL
 static inline int
-iswxdigit (wint_t wc)
+iswxdigit (__wctype_wint_t wc)
 {
   return ((wc = '0'  wc = '9')
  || ((wc  ~0x20) = 'A'  (wc  ~0x20) = 'F'));
Index: m4/wctype.m4
===
RCS file: /cvsroot/gnulib/gnulib/m4/wctype.m4,v
retrieving revision 1.2
diff -u -p -r1.2 wctype.m4
--- m4/wctype.m422 Dec 2006 16:27:26 -