bug-m4
[Top][All Lists]
Advanced

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

Re: Intel C++ compiler for Linux 11.1 doesn't build m4 1.4.13 on NetBSD


From: Eric Blake
Subject: Re: Intel C++ compiler for Linux 11.1 doesn't build m4 1.4.13 on NetBSD
Date: Wed, 16 Dec 2009 05:58:37 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 11/17/2009 6:12 AM:
> According to Alexander Nasonov on 11/17/2009 2:37 AM:
>> it fails here:
> 
>> fflush.c(95): error: a value of type "__off_t={__int64_t={long long}}" 
>> cannot be assigned to an entity of type "fpos_t"
>>     fp_->_offset = pos;
>>                  ^
>> compilation aborted for fflush.c (code 2)
>> *** [fflush.o] Error code 2
>> 1 error
> 
> Thanks for the report.  This is a gnulib problem, so I'm adding that list.

> Actually, the real fix is to make gnulib realize how to properly assign to
> fpos_t, even when it is a struct.  But this is something that Bruno may be
> more familiar with, since he wrote the code in this file.
>

Sorry for the delay, and thanks again for the report.  I finally took time
on a NetBSD machine, and reproduced the problem by using CC='gcc -ansi'.
This patch fixed the issue for me, so I'm applying it.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkso2X0ACgkQ84KuGfSFAYANcACfbZSQYRxaRMId5DiAeuLwdn/g
RtAAoM4FvYSTCGxSrVokyPlebRQ+1JfF
=IKTc
-----END PGP SIGNATURE-----
>From 826b1b3ba7eb47ac22741eb32a623831b9e50b7f Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 14 Dec 2009 15:42:13 -0700
Subject: [PATCH] fflush: avoid compilation error on NetBSD

On NetBSD, the system <stdio.h> header contains:
|#if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)
|typedef __off_t fpos_t;
|#else
|typedef struct __sfpos {
|    __off_t _pos;
|} fpos_t;
|#endif

Thus, based on compiler flags (such as using 'gcc -ansi' or the
Intel compiler), it is an error to directly set fpos_t=off_t.

* lib/fflush.c (update_fpos_cache): Use a union to safely convert
between off_t and fpos_t, since the latter is sometimes a struct.
* lib/fseeko.c (rpl_fseeko): Likewise.
Reported by Alexander Nasonov <address@hidden>.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog    |    8 ++++++++
 lib/fflush.c |   11 ++++++++++-
 lib/fseeko.c |   13 ++++++++++++-
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 13a4e60..b75ed74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-12-16  Eric Blake  <address@hidden>
+
+       fflush: avoid compilation error on NetBSD
+       * lib/fflush.c (update_fpos_cache): Use a union to safely convert
+       between off_t and fpos_t, since the latter is sometimes a struct.
+       * lib/fseeko.c (rpl_fseeko): Likewise.
+       Reported by Alexander Nasonov <address@hidden>.
+
 2009-12-15  Eric Blake  <address@hidden>

        cloexec, dup3, fchdir: rely on fcntl
diff --git a/lib/fflush.c b/lib/fflush.c
index 0af1703..d823a34 100644
--- a/lib/fflush.c
+++ b/lib/fflush.c
@@ -91,7 +91,16 @@ static inline void
 update_fpos_cache (FILE *fp, off_t pos)
 {
 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, 
DragonFly, MacOS X, Cygwin */
-  fp_->_offset = pos;
+  /* Use a union, since on NetBSD, the compilation flags determine
+     whether fpos_t is typedef'd to off_t or a struct containing a
+     single off_t member.  */
+  union
+    {
+      fpos_t f;
+      off_t o;
+    } u;
+  u.o = pos;
+  fp_->_offset = u.f;
   fp_->_flags |= __SOFF;
 #endif
 }
diff --git a/lib/fseeko.c b/lib/fseeko.c
index 8887f24..91b853d 100644
--- a/lib/fseeko.c
+++ b/lib/fseeko.c
@@ -110,7 +110,18 @@ rpl_fseeko (FILE *fp, off_t offset, int whence)
 #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, 
Linux libc5 */
       fp->_flags &= ~_IO_EOF_SEEN;
 #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, 
DragonFly, MacOS X, Cygwin */
-      fp_->_offset = pos;
+      {
+        /* Use a union, since on NetBSD, the compilation flags
+           determine whether fpos_t is typedef'd to off_t or a struct
+           containing a single off_t member.  */
+        union
+          {
+            fpos_t f;
+            off_t o;
+          } u;
+        u.o = pos;
+        fp_->_offset = u.f;
+      }
       fp_->_flags |= __SOFF;
       fp_->_flags &= ~__SEOF;
 #elif defined __EMX__               /* emx+gcc */
-- 
1.6.5.rc1


reply via email to

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