Jim Meyering [Sat, 23 Jan 2010 10:52:44 +0000 (11:52 +0100)]
xstrtoll: new module
* modules/xstrtoll: New file.
* MODULES.html.sh (Numeric conversion functions): Add xstrtoll.
* lib/xstrtol.h [HAVE_LONG_LONG_INT]: Declare xstrtoll and xstrtoull.
* lib/xstrtoll.c, lib/xstrtoull.c: New files.
./configure fails if you use this module and lack "long long".
* modules/xstrtoll-tests: New module.
* tests/test-xstrtoll.c, tests/test-xstrtoull.c: New files.
* tests/test-xstrtoll.sh: Like test-xstrtol.c, but use the
new init.sh-based test framework.
#define STREQ(a, b) (strcmp ((a), (b)) == 0) is over-parenthesized,
since the only risk is that "a" or "b" contains an unparenthesized
comma, but if either did that, STREQ would have 3 or more arguments.
Hence, #define STREQ(a, b) (strcmp (a, b) == 0) is better.
* lib/fts.c (STREQ): Remove unnecessary parentheses.
* lib/hash-triple.c (STREQ): Likewise.
* tests/test-argv-iter.c (STREQ): Use a and b, not s1 and s2.
* lib/getugroups.c (STREQ): Likewise.
Eric Blake [Wed, 16 Dec 2009 23:20:28 +0000 (16:20 -0700)]
warn-on-use: use instead of link-warning
Each *.in.h file serves two purposes - provide enough self-contained
content to serve as a replacement for the system header regardless of
the user's compiler, and offer the developer the ability to detect any
gnulib modules that might have been inadvertantly excluded. The
former requires independence from config.h, and routes everything
through a Makefile.am snippet that uses @@ substitution specific to
the modules that were in use, with details learned at configure time.
The latter works by poisoning anything that gnulib did not replace,
but which the developer had natively available, explaining why their
tests passed during development. Poisoning relies on gcc features,
and requires manual triggering by adding -DGNULIB_POSIXCHECK to
CFLAGS; it assumes that <config.h> is properly included. In fact, we
do not want to use @@ substitution for HAVE_DECL_* during poisoning,
because the warning is only relevant for the gnulib modules which were
not included, and thus where the m4 macros to set proper @@ values
have not been run. Furthermore, we only need to poison interfaces
that already have a declaration; if something is not declared, then
the developer wouldn't have been able to link, so their code won't be
using the problematic interface in the first place.
Ralf Wildenhues [Sat, 16 Jan 2010 19:30:58 +0000 (20:30 +0100)]
Split large sed scripts, for HP-UX sed.
* modules/stdio: Split sed scripts around 50 sed commands,
to avoid HP-UX limit of 99 commands, in the near future.
* modules/string: Likewise.
* modules/unistd: Likewise.
Ralf Wildenhues [Sat, 16 Jan 2010 17:15:09 +0000 (18:15 +0100)]
gnulib-tool: avoid writing in the current directory.
* gnulib-tool (func_emit_lib_Makefile_am)
(func_emit_tests_Makefile_am): Put temporary files in $tmp,
not in the current directory, so concurrent gnulib-tool
instances do not interfere.
Eric Blake [Thu, 31 Dec 2009 20:48:15 +0000 (13:48 -0700)]
math: add portability warnings for classification macros
For interfaces which are defined to exist only as macros, implement
the proper magic needed to warn if the corresponding gnulib module was
not in use. This solution avoids promoting arguments unnecessarily,
to allow reuse in case gnulib ever implements fpclassify, since
fpclassify(1e-40f) is different than fpclassify(1e-40).
* modules/math (Depends-on): Add warn-on-use.
(Makefile.am): Provide new substitutions.
* m4/math_h.m4 (gl_MATH_H): Require inline.
* lib/math.in.h (_GL_WARN_REAL_FLOATING_DECL)
(_GL_WARN_REAL_FLOATING_IMPL): New helper macros.
(isfinite, isinf, isnan, signbit) [GNULIB_POSIXCHECK]: Use them to
implement warnings.
Eric Blake [Thu, 31 Dec 2009 20:28:59 +0000 (13:28 -0700)]
unistd: warn on use of environ without module
_GL_WARN_ON_USE only works for functions; so we wrap access to
environ through a function when CFLAGS has -DGNULIB_POSIXCHECK=1.
* modules/unistd (Depends-on): Add warn-on-use.
(Makefile.am): Provide new substitutions.
* m4/unistd_h.m4 (gl_UNISTD_H): Check for inline and environ.
* lib/unistd.in.h (environ): Wrap with a warning helper function.
Eric Blake [Thu, 31 Dec 2009 18:53:33 +0000 (11:53 -0700)]
stdio: warn on suspicious uses
Using gets is almost ALWAYS wrong (it is extremely rare that you have
full control over stdin). POSIX 2008 marked it as obsolete, even
though C89 requires it. Attach a warning to remind developers. Add
a comment to sprintf explaining why it does not get this treatment.
Improve the warnings for fseek/fseeko (and ftell/ftello), with
comments justifying our position.
Some of our unit tests never use large files, so rather than drag
in a dependency on fseeko, they should be the first compilation
units to use _GL_NO_LARGE_FILES.
* modules/stdio (Depends-on): Add warn-on-use.
(Makefile.am): Provide new substitutions.
* m4/stdio_h.m4 (gl_STDIO_H): Check for inline, ftello, and
fseeko.
* lib/stdio.in.h (gets): Always warn on use.
(fseek, ftell): Adjust when warnings are issued, and honor
_GL_NO_LARGE_FILES as a way to silence the warning.
* tests/test-fpurge.c [!GNULIB_FSEEK]: Use new means to squelch
any warning about large file offsets.
* tests/test-freadable.c [!GNULIB_FSEEK]: Likewise.
* tests/test-freading.c [!GNULIB_FSEEK]: Likewise.
* tests/test-fseeko.c [!GNULIB_FSEEK]: Likewise.
* tests/test-ftell.c [!GNULIB_FSEEK]: Likewise.
* tests/test-ftello.c [!GNULIB_FSEEK]: Likewise.
* tests/test-fwritable.c [!GNULIB_FSEEK]: Likewise.
* tests/test-fwriting.c [!GNULIB_FSEEK]: Likewise.
* tests/test-getopt.c [!GNULIB_FTELL]: Likewise.
Eric Blake [Wed, 16 Dec 2009 21:53:06 +0000 (14:53 -0700)]
warn-on-use: new module
The goal of GNULIB_POSIXCHECK is to allow a developer on a reasonably
portable system to detect instances where they may have succeeded
because their system is up-to-date, but where compilation would fail
or create a misbehaving application on some other system due to some
portability problem, all without requiring that the developer have
access to other machines. In other words, we want to poison all
interfaces that have a gnulib replacement if the corresponding gnulib
module is not in use. For macros, the solution is undefining the
macro; unfortunately this causes compilation error without many
details as to why, but it is better than nothing. For functions, the
solution is to cause a warning if the function is used.
Previously, the link-warning could poison functions, but only on glibc
systems and with gcc. This module introduces _GL_WARN_ON_USE as a way
of poisoning functions for a few more systems.
Using the gcc __warning__ attribute (added in 4.3.0, early 2008)
rather than using link-warning.h is favorable because:
1) Provides a warning immediately at compile-time. The user does not
have to wait until he links a program.
2) Less use of C macros. Less risk of collision.
3) It's available on more platforms. Depends only on GCC.
4) The formatting of the message is nicer.
There is a minor regression: the gcc attribute is currently not as
powerful as a link warning at detecting uses via function pointers:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42384
However, that style of coding is less frequent.
* modules/warn-on-use: New file.
* build-aux/warn-on-use.h: Likewise.
* m4/warn-on-use.m4: Likewise.
* MODULES.html.sh (Support for building): Mention it.