bug-glibc
[Top][All Lists]
Advanced

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

malloc/obstack.h macros no longer work in C++


From: Alexandre Duret-Lutz
Subject: malloc/obstack.h macros no longer work in C++
Date: 04 Jul 2003 17:47:25 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3

Hi Paul and glibc folks,

It seems your last change to obstack.h breaks C++ compilation.

2002-01-03  Paul Eggert  <address@hidden>

        * malloc/obstack.h (__INT_TO_PTR) [__STDC__]: Cast result to
        (void *) to avoid diagnostic with native c89 on SGI IRIX 6.5
        when compiling Bison 1.875's `bitset bset = obstack_alloc
        (bobstack, bytes);'.  Problem reported by Nelson H. F. Beebe.

(The date has a typo: it should read 2003.)

You can see that by compiling glibc's obstack test with g++:

~/projs/cvs/libc/malloc % gcc-3.3 -I. tst-obstack.c -c -o /dev/null
~/projs/cvs/libc/malloc % g++-3.3 -I. tst-obstack.c -c -o /dev/null
tst-obstack.c: In function `int main()':
tst-obstack.c:45: error: invalid conversion from `void*' to `char*'
tst-obstack.c:50: error: invalid conversion from `void*' to `char*'

The reason is that __INT_TO_PTR is used in many places in
obstacks macros where a 'char *' is expected.  So either all
these internal calls to __INT_TO_PTR should be fixed to
explicitely cast the `void *' back to `char *' (that sounds ugly
to me, since __INT_TO_PTR used to return `char *').  Or
__INT_TO_PTR can be reverted to its original definition, and its
result casted to `void *' only when required.  I believe the
following patch does that, but as I don't have access to c89 on
SGI IRIX 6.5 I couldn't test.

New versions of obstack.h seem to have been released on 2001 and 2003,
so I've updated the copyright accordingly.

--- ChangeLog   3 Jul 2003 21:04:45 -0000       1.7761
+++ ChangeLog   4 Jul 2003 12:11:04 -0000
@@ -1,3 +1,10 @@
+2003-07-04  Alexandre Duret-Lutz  <address@hidden>
+
+       * malloc/obstack.h (__INT_TO_PTR): Revert Paul Eggert's change
+       of 2003-01-03, it breaks C++ compilation.
+       [!__GNUC__ || !__STDC__] (obstack_finish): Cast result to
+       void*.
+
 2003-07-03  Ulrich Drepper  <address@hidden>
 
        * configure.in: Also check for .cfi_rel_offset pseudo-op.
@@ -5736,7 +5743,7 @@
 
        * sysdeps/unix/sysv/linux/m68k/bits/stat.h: Add nanosecond fields.
 
-2002-01-03  Paul Eggert  <address@hidden>
+2003-01-03  Paul Eggert  <address@hidden>
 
        * malloc/obstack.h (__INT_TO_PTR) [__STDC__]: Cast result to
        (void *) to avoid diagnostic with native c89 on SGI IRIX 6.5
--- malloc/obstack.h    4 Jan 2003 21:42:30 -0000       1.16
+++ malloc/obstack.h    4 Jul 2003 12:11:05 -0000
@@ -1,5 +1,5 @@
 /* obstack.h - object stack macros
-   Copyright (C) 1988,89,90,91,92,93,94,96,97,98,99 Free Software Foundation, 
Inc.
+   Copyright (C) 1988,89,90,91,92,93,94,96,97,98,99,2001,2003 Free Software 
Foundation, Inc.
    This file is part of the GNU C Library.  Its master source is NOT part of
    the C library, however.  The master source lives in /gd/gnu/lib.
 
@@ -119,12 +119,8 @@
 #endif
 
 #ifndef __INT_TO_PTR
-#if defined __STDC__ && __STDC__
-# define __INT_TO_PTR(P) ((void *) ((P) + (char *) 0))
-#else
 # define __INT_TO_PTR(P) ((P) + (char *) 0)
 #endif
-#endif
 
 /* We need the type of the resulting object.  If __PTRDIFF_TYPE__ is
    defined, as with GNU C, use that; that way we don't pollute the
@@ -582,7 +578,7 @@
     > (h)->chunk_limit - (char *) (h)->chunk)                          \
    ? ((h)->next_free = (h)->chunk_limit) : 0),                         \
   (h)->object_base = (h)->next_free,                                   \
-  __INT_TO_PTR ((h)->temp))
+  (void *) __INT_TO_PTR ((h)->temp))
 
 # if defined __STDC__ && __STDC__
 #  define obstack_free(h,obj)                                          \


-- 
Alexandre Duret-Lutz




reply via email to

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