[RFA/RFC] libdecnumber/gstdint.h is back :-(

Joel Brobecker
2008-09-13T05:01:23Z

[-- Attachment #1: Type: text/plain, Size: 2685 bytes --]

Hello,

You might remember that we had some issues with libdecnumber/gstdint.h
when compiling dfp.c. This was because dfp.c includes headers from
libdecnumber which in turn includes gstdint.h. Unfortunately, GDB
also includes gnulib/stdint.h and the two header files are incompatible.
At the time, we thought we had fixed the problem by introducing
gdb/gstdint.h which only contained an include of <stdint.h>, thus
thinking that it would trick the libdecnumber header files into using
our stdint.h file while compiling GDB.

See: http://www.sourceware.org/ml/gdb-patches/2008-06/msg00513.html
and followup messages for more details.

Unfortunately, it doesn't seem to work after all. I am even wondering
whether it worked back then, but I don't want to spend the time to
do some archeology. The reason it doesn't work is because decContext.h
includes gstdint.h using double quotes:

#include "gstdint.h" /* C99 standard integers */

I looked at the C90 draft that I have, and it seems to be saying
that, whether you use angled brackets or double quotes in your include
syntax, the way the file is located is implementation defined.
So, no help there. This needs to be confirmed, but it looks like
GCC will try to find the include file starting from the same directory
as the file including it when double quotes are used. In other words,
when the following directive is used from ../libdecnumber/decContext.h

#include "gstdint.h"

GCC will first try ../libdecnumber/gstdint.h, not ./gstdint.h.
This defeats the purpose of the gstdint.h that we introduced in
the gdb subdirectory.

I experimented with using angled brackets to include gstdint.h,
just out of curiousity, and it does indeed fix the build failure.
However, I don't think that libdecnumber would agree to that
change.

What occured to me while thinking about all this is that the
root of the problem is that we have two incompatible files that
should be identical in practice. Since we are always building
libdecnumber, can we use libdecnumber's gstdint.h and ditch
gnulib's stdint.h?

Attached is a patch that implements that. It fixes the build problem
on Tru64, for instance.

2008-09-13 Joel Brobecker <brobecker@adacore.com>

* defs.h: Replace include of gnulib's stdint.h by libdecnumber's
gstdint.h.
* Makefile.in (GNULIB_H): Remove @GNULIB_STDINT_H@.
(HFILES_NO_SRCDIR): Remove gnulib/stdint.in.h.
* configure.ac: Remove computation and substitution of GNULIB_STDINT_H.
* configure: Regenerate.

Tested on x86-linux with a full rebuild. No regression.
Also fixes the build failure on Tru64.

Thoughts? OK to apply?

Thanks,
--
Joel

[-- Attachment #2: gstdint.diff --]
[-- Type: text/plain, Size: 3443 bytes --]

diff -r e03176e728c7 gdb/defs.h
--- a/gdb/defs.h Fri Sep 12 20:42:16 2008 -0700
+++ b/gdb/defs.h Fri Sep 12 21:24:21 2008 -0700
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <errno.h> /* System call error return status. */
#include <limits.h>
-#include <stdint.h>
+#include <gstdint.h>

#ifdef HAVE_STDDEF_H
#include <stddef.h>
diff -r e03176e728c7 gdb/gstdint.h
--- a/gdb/gstdint.h Fri Sep 12 20:42:16 2008 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/* Copyright (C) 2008 Free Software Foundation, Inc.
-
- This file is part of GDB.
-
- 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
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* The libdecnumber library, on which GDB depends, includes a header file
- called gstdint.h instead of relying directly on stdint.h. GDB, on the
- other hand, includes stdint.h directly, relying on the fact that gnulib
- generates a copy if the system doesn't provide one or if it is missing
- some features. Unfortunately, gstdint.h and stdint.h cannot be included
- at the same time, which may happen when we include a file from
- libdecnumber.
-
- The purpose of this file is to override the libdecnumber/gstdint.h file
- to use stdint.h instead. Thanks to the order of our include path,
- files from the GDB source tree have precedence over files from our
- dependencies. So the presence of this file will ensure that we
- consistently use the same stdint.h file when compiling GDB source
- files. */
-
-#include <stdint.h>
diff -r e03176e728c7 gdb/Makefile.in
--- a/gdb/Makefile.in Fri Sep 12 20:42:16 2008 -0700
+++ b/gdb/Makefile.in Fri Sep 12 21:24:21 2008 -0700
@@ -178,7 +178,7 @@

# Generated headers in the gnulib directory. These must be listed
# so that they are generated before other files are compiled.
-GNULIB_H = gnulib/string.h @GNULIB_STDINT_H@
+GNULIB_H = gnulib/string.h

#
# CLI sub directory definitons
@@ -682,7 +682,7 @@
cli/cli-decode.h cli/cli-cmds.h cli/cli-utils.h cli/cli-dump.h \
cli/cli-script.h macrotab.h symtab.h version.h gnulib/wchar.in.h \
gnulib/string.in.h gnulib/str-two-way.h gnulib/extra/link-warning.h \
-gnulib/stdint.in.h remote.h gdb.h sparc-nat.h gdbserver/win32-low.h \
+remote.h gdb.h sparc-nat.h gdbserver/win32-low.h \
gdbserver/i387-fp.h gdbserver/server.h gdbserver/terminal.h \
gdbserver/mem-break.h gdbserver/wincecompat.h gdbserver/target.h \
gdbserver/linux-low.h gdbserver/gdb_proc_service.h \
diff -r e03176e728c7 gdb/configure.ac
--- a/gdb/configure.ac Fri Sep 12 20:42:16 2008 -0700
+++ b/gdb/configure.ac Fri Sep 12 21:24:21 2008 -0700
@@ -76,13 +76,6 @@
fi

gl_INIT
-
-# For Makefile dependencies.
-GNULIB_STDINT_H=
-if test x"$STDINT_H" != x; then
- GNULIB_STDINT_H=gnulib/$STDINT_H
-fi
-AC_SUBST(GNULIB_STDINT_H)

PACKAGE=gdb
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of this package. ])