Import new gnulib.

parent 93cd84df
2013-04-11 Vladimir Serbinenko <phcoder@gmail.com>
Import new gnulib.
2013-04-11 Vladimir Serbinenko <phcoder@gmail.com>
Use ACPI shutdown intests as traditional port was removed.
This diff is collapsed.
This diff is collapsed.
/* A C macro for emitting warnings if a function is used.
Copyright (C) 2010 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 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
Lesser 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/>. */
/* _GL_WARN_ON_USE (function, "literal string") issues a declaration
for FUNCTION which will then trigger a compiler warning containing
the text of "literal string" anywhere that function is called, if
supported by the compiler. If the compiler does not support this
feature, the macro expands to an unused extern declaration.
This macro is useful for marking a function as a potential
portability trap, with the intent that "literal string" include
instructions on the replacement function that should be used
instead. However, one of the reasons that a function is a
portability trap is if it has the wrong signature. Declaring
FUNCTION with a different signature in C is a compilation error, so
this macro must use the same type as any existing declaration so
that programs that avoid the problematic FUNCTION do not fail to
compile merely because they included a header that poisoned the
function. But this implies that _GL_WARN_ON_USE is only safe to
use if FUNCTION is known to already have a declaration. Use of
this macro implies that there must not be any other macro hiding
the declaration of FUNCTION; but undefining FUNCTION first is part
of the poisoning process anyway (although for symbols that are
provided only via a macro, the result is a compilation error rather
than a warning containing "literal string"). Also note that in
C++, it is only safe to use if FUNCTION has no overloads.
For an example, it is possible to poison 'getline' by:
- adding a call to gl_WARN_ON_USE_PREPARE([[#include <stdio.h>]],
[getline]) in configure.ac, which potentially defines
HAVE_RAW_DECL_GETLINE
- adding this code to a header that wraps the system <stdio.h>:
#undef getline
#if HAVE_RAW_DECL_GETLINE
_GL_WARN_ON_USE (getline, "getline is required by POSIX 2008, but"
"not universally present; use the gnulib module getline");
#endif
It is not possible to directly poison global variables. But it is
possible to write a wrapper accessor function, and poison that
(less common usage, like &environ, will cause a compilation error
rather than issue the nice warning, but the end result of informing
the developer about their portability problem is still achieved):
#if HAVE_RAW_DECL_ENVIRON
static inline char ***rpl_environ (void) { return &environ; }
_GL_WARN_ON_USE (rpl_environ, "environ is not always properly declared");
# undef environ
# define environ (*rpl_environ ())
#endif
*/
#ifndef _GL_WARN_ON_USE
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
/* A compiler attribute is available in gcc versions 4.3.0 and later. */
# define _GL_WARN_ON_USE(function, message) \
extern __typeof__ (function) function __attribute__ ((__warning__ (message)))
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
/* Verify the existence of the function. */
# define _GL_WARN_ON_USE(function, message) \
extern __typeof__ (function) function
# else /* Unsupported. */
# define _GL_WARN_ON_USE(function, message) \
_GL_WARN_EXTERN_C int _gl_warn_on_use
# endif
#endif
/* _GL_WARN_ON_USE_CXX (function, rettype, parameters_and_attributes, "string")
is like _GL_WARN_ON_USE (function, "string"), except that the function is
declared with the given prototype, consisting of return type, parameters,
and attributes.
This variant is useful for overloaded functions in C++. _GL_WARN_ON_USE does
not work in this case. */
#ifndef _GL_WARN_ON_USE_CXX
# if 4 < __GNUC__ || (__GNUC__ == 4 && 3 <= __GNUC_MINOR__)
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
extern rettype function parameters_and_attributes \
__attribute__ ((__warning__ (msg)))
# elif __GNUC__ >= 3 && GNULIB_STRICT_CHECKING
/* Verify the existence of the function. */
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
extern rettype function parameters_and_attributes
# else /* Unsupported. */
# define _GL_WARN_ON_USE_CXX(function,rettype,parameters_and_attributes,msg) \
_GL_WARN_EXTERN_C int _gl_warn_on_use
# endif
#endif
/* _GL_WARN_EXTERN_C declaration;
performs the declaration with C linkage. */
#ifndef _GL_WARN_EXTERN_C
# if defined __cplusplus
# define _GL_WARN_EXTERN_C extern "C"
# else
# define _GL_WARN_EXTERN_C extern
# endif
#endif
......@@ -49,4 +49,6 @@
#define RE_ENABLE_I18N 1
#define __USE_GNU 1
#endif
......@@ -194,7 +194,7 @@ kernel = {
emu = disk/host.c;
emu = gnulib/progname.c;
emu = gnulib/error.c;
emu = kern/emu/error.c;
emu = kern/emu/cache_s.S;
emu = kern/emu/hostdisk.c;
emu = kern/emu/hostfs.c;
......
=== modified file 'grub-core/gnulib/argp-parse.c'
--- grub-core/gnulib/argp-parse.c 2010-04-02 22:45:01 +0000
+++ grub-core/gnulib/argp-parse.c 2011-04-10 13:25:52 +0000
@@ -935,7 +935,7 @@
void *
__argp_input (const struct argp *argp, const struct argp_state *state)
{
- if (state)
+ if (state && state->pstate)
{
struct group *group;
struct parser *parser = state->pstate;
diff --git a/lib/argp-fmtstream.c b/lib/argp-fmtstream.c
index 7aa317c..02406ff 100644
--- a/lib/argp-fmtstream.c
+++ b/lib/argp-fmtstream.c
@@ -29,9 +29,11 @@
#include <errno.h>
#include <stdarg.h>
#include <ctype.h>
+#include <wchar.h>
#include "argp-fmtstream.h"
#include "argp-namefrob.h"
+#include "mbswidth.h"
#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
@@ -116,6 +118,51 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
#endif
#endif
+
+/* Return the pointer to the first character that doesn't fit in l columns. */
+static inline const ptrdiff_t
+add_width (const char *ptr, const char *end, size_t l)
+{
+ mbstate_t ps;
+ const char *ptr0 = ptr;
+
+ memset (&ps, 0, sizeof (ps));
+
+ while (ptr < end)
+ {
+ wchar_t wc;
+ size_t s, k;
+
+ s = mbrtowc (&wc, ptr, end - ptr, &ps);
+ if (s == (size_t) -1)
+ break;
+ if (s == (size_t) -2)
+ {
+ if (1 >= l)
+ break;
+ l--;
+ ptr++;
+ continue;
+ }
+
+ if (wc == '\e' && ptr + 3 < end
+ && ptr[1] == '[' && (ptr[2] == '0' || ptr[2] == '1')
+ && ptr[3] == 'm')
+ {
+ ptr += 4;
+ continue;
+ }
+
+ k = wcwidth (wc);
+
+ if (k >= l)
+ break;
+ l -= k;
+ ptr += s;
+ }
+ return ptr - ptr0;
+}
+
/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
end of its buffer. This code is mostly from glibc stdio/linewrap.c. */
void
@@ -168,14 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
if (!nl)
{
+ size_t display_width = mbsnwidth (buf, fs->p - buf, MBSW_STOP_AT_NUL);
/* The buffer ends in a partial line. */
- if (fs->point_col + len < fs->rmargin)
+ if (fs->point_col + display_width < fs->rmargin)
{
/* The remaining buffer text is a partial line and fits
within the maximum line width. Advance point for the
characters to be written and stop scanning. */
- fs->point_col += len;
+ fs->point_col += display_width;
break;
}
else
@@ -183,14 +231,18 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
the end of the buffer. */
nl = fs->p;
}
- else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
- {
- /* The buffer contains a full line that fits within the maximum
- line width. Reset point and scan the next line. */
- fs->point_col = 0;
- buf = nl + 1;
- continue;
- }
+ else
+ {
+ size_t display_width = mbsnwidth (buf, nl - buf, MBSW_STOP_AT_NUL);
+ if (display_width < (ssize_t) fs->rmargin)
+ {
+ /* The buffer contains a full line that fits within the maximum
+ line width. Reset point and scan the next line. */
+ fs->point_col = 0;
+ buf = nl + 1;
+ continue;
+ }
+ }
/* This line is too long. */
r = fs->rmargin - 1;
@@ -226,7 +278,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
char *p, *nextline;
int i;
- p = buf + (r + 1 - fs->point_col);
+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col));
while (p >= buf && !isblank ((unsigned char) *p))
--p;
nextline = p + 1; /* This will begin the next line. */
@@ -244,7 +296,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
{
/* A single word that is greater than the maximum line width.
Oh well. Put it on an overlong line by itself. */
- p = buf + (r + 1 - fs->point_col);
+ p = buf + add_width (buf, fs->p, (r + 1 - fs->point_col));
/* Find the end of the long word. */
if (p < nl)
do
@@ -278,7 +330,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
&& fs->p > nextline)
{
/* The margin needs more blanks than we removed. */
- if (fs->end - fs->p > fs->wmargin + 1)
+ if (mbsnwidth (fs->p, fs->end - fs->p, MBSW_STOP_AT_NUL)
+ > fs->wmargin + 1)
/* Make some space for them. */
{
size_t mv = fs->p - nextline;
diff --git a/lib/argp-help.c b/lib/argp-help.c
index 354f1e2..2914f47 100644
--- a/lib/argp-help.c
+++ b/lib/argp-help.c
@@ -50,6 +50,7 @@
#include "argp.h"
#include "argp-fmtstream.h"
#include "argp-namefrob.h"
+#include "mbswidth.h"
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
@@ -1452,7 +1453,7 @@ argp_args_usage (const struct argp *argp, const struct argp_state *state,
/* Manually do line wrapping so that it (probably) won't get wrapped at
any embedded spaces. */
- space (stream, 1 + nl - cp);
+ space (stream, 1 + mbsnwidth (cp, nl - cp, MBSW_STOP_AT_NUL));
__argp_fmtstream_write (stream, cp, nl - cp);
}
diff --git a/lib/mbswidth.c b/lib/mbswidth.c
index 7c2dfce..baa4f27 100644
--- a/lib/mbswidth.c
+++ b/lib/mbswidth.c
@@ -90,6 +90,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
p++;
width++;
break;
+ case '\0':
+ if (flags & MBSW_STOP_AT_NUL)
+ return width;
default:
/* If we have a multibyte sequence, scan it up to its end. */
{
@@ -168,6 +171,9 @@ mbsnwidth (const char *string, size_t nbytes, int flags)
{
unsigned char c = (unsigned char) *p++;
+ if (c == 0 && (flags & MBSW_STOP_AT_NUL))
+ return width;
+
if (isprint (c))
{
if (width == INT_MAX)
diff --git a/lib/mbswidth.h b/lib/mbswidth.h
index e9c0b03..d7207c5 100644
--- a/lib/mbswidth.h
+++ b/lib/mbswidth.h
@@ -45,6 +45,9 @@ extern "C" {
control characters and 1 otherwise. */
#define MBSW_REJECT_UNPRINTABLE 2
+/* If this bit is set \0 is treated as the end of string.
+ Otherwise it's treated as a normal one column width character. */
+#define MBSW_STOP_AT_NUL 4
/* Returns the number of screen columns needed for STRING. */
#define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */
diff --git a/modules/argp b/modules/argp
index 125046a..6f14d10 100644
--- a/modules/argp
+++ b/modules/argp
@@ -40,6 +40,7 @@ stdalign
strerror
memchr
memmove
+mbswidth
configure.ac:
gl_ARGP
diff --git a/modules/argp-tests b/modules/argp-tests
index 8f92a4d..0463927 100644
--- a/modules/argp-tests
+++ b/modules/argp-tests
@@ -1,11 +1,13 @@
Files:
tests/test-argp.c
tests/test-argp-2.sh
+tests/test-argp-2-utf.sh
Depends-on:
progname
Makefile.am:
TESTS += test-argp test-argp-2.sh
-check_PROGRAMS += test-argp
+TESTS += test-argp test-argp-2.sh test-argp-2-utf.sh
+check_PROGRAMS += test-argp test-argp-utf8
test_argp_LDADD = $(LDADD) @LIBINTL@
=== modified file 'grub-core/gnulib/regcomp.c'
--- grub-core/gnulib/regcomp.c 2010-09-20 10:35:33 +0000
+++ grub-core/gnulib/regcomp.c 2012-03-10 11:31:42 +0000
@@ -549,13 +549,9 @@ regerror (int errcode, const regex_t *_R
if (BE (errcode < 0
|| errcode >= (int) (sizeof (__re_error_msgid_idx)
/ sizeof (__re_error_msgid_idx[0])), 0))
- /* Only error codes returned by the rest of the code should be passed
- to this routine. If we are given anything else, or if other regex
- code generates an invalid error code, then the program has a bug.
- Dump core so we can fix it. */
- abort ();
-
- msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]);
+ msg = gettext ("unknown regexp error");
+ else
+ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]);
msg_size = strlen (msg) + 1; /* Includes the null. */
@@ -1119,7 +1119,7 @@
}
break;
default:
- abort ();
+ break;
}
if (mb_chars || has_period)
--- /tmp/x.diff 2013-04-11 16:51:42.777873536 +0200
+++ grub-core/gnulib/stdio.in.h 2013-04-11 16:51:49.917873298 +0200
@@ -700,7 +700,6 @@
removed it. */
#undef gets
#if HAVE_RAW_DECL_GETS
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
This diff is collapsed.
......@@ -93,26 +93,15 @@ long i00afunc ();
static int stack_dir; /* 1 or -1 once known. */
# define STACK_DIR stack_dir
static void
find_stack_direction (void)
static int
find_stack_direction (int *addr, int depth)
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
if (addr == NULL)
{ /* Initial entry. */
addr = ADDRESS_FUNCTION (dummy);
find_stack_direction (); /* Recurse once. */
}
else
{
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
int dir, dummy = 0;
if (! addr)
addr = &dummy;
*addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
dir = depth ? find_stack_direction (addr, depth - 1) : 0;
return dir + dummy;
}
# endif /* STACK_DIRECTION == 0 */
......@@ -155,7 +144,7 @@ alloca (size_t size)
# if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
STACK_DIR = find_stack_direction (NULL, (size & 1) + 20);
# endif
/* Reclaim garbage, defined as all alloca'd storage that
......@@ -486,4 +475,4 @@ i00afunc (long address)
# endif /* CRAY */
# endif /* no alloca */
#endif /* not GCC version 3 */
#endif /* not GCC 2 */
/* Memory allocation on the stack.
Copyright (C) 1995, 1999, 2001-2004, 2006-2010 Free Software Foundation,
Copyright (C) 1995, 1999, 2001-2004, 2006-2013 Free Software Foundation,
Inc.
This program is free software; you can redistribute it and/or modify it
......@@ -14,9 +14,9 @@
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA. */
License along with this program; if not, see
<http://www.gnu.org/licenses/>.
*/
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
means there is a real alloca function. */
......@@ -44,6 +44,13 @@
# define alloca _alloca
# elif defined __DECC && defined __VMS
# define alloca __ALLOCA
# elif defined __TANDEM && defined _TNS_E_TARGET
# ifdef __cplusplus
extern "C"
# endif
void *_alloca (unsigned short);
# pragma intrinsic (_alloca)
# define alloca _alloca
# else
# include <stddef.h>
# ifdef __cplusplus
......
/* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
Copyright (C) 1996, 1997, 1999, 2009, 2010 Free Software Foundation, Inc.
Copyright (C) 1996-1997, 1999, 2009-2013 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.
......@@ -19,11 +19,11 @@
/* If set by the user program, it should point to string that is the
bug-reporting address for the program. It will be printed by argp_help if
the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help
messages), embedded in a sentence that says something like `Report bugs to
ADDR.'. */
messages), embedded in a sentence that says something like "Report bugs to
ADDR." */
const char *argp_program_bug_address
/* This variable should be zero-initialized. On most systems, putting it into
BSS is sufficient. Not so on MacOS X 10.3 and 10.4, see
BSS is sufficient. Not so on Mac OS X 10.3 and 10.4, see
<http://lists.gnu.org/archive/html/bug-gnulib/2009-01/msg00329.html>
<http://lists.gnu.org/archive/html/bug-gnulib/2009-08/msg00096.html>. */
#if defined __ELF__
......
/* Default definition for ARGP_ERR_EXIT_STATUS
Copyright (C) 1997, 2009, 2010 Free Software Foundation, Inc.
Copyright (C) 1997, 2009-2013 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.
......
/* Word-wrapping and line-truncating streams
Copyright (C) 1997-1999, 2001-2003, 2005, 2009-2010 Free Software
Copyright (C) 1997-1999, 2001-2003, 2005, 2009-2013 Free Software
Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.
......@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This package emulates glibc `line_wrap_stream' semantics for systems that
/* This package emulates glibc 'line_wrap_stream' semantics for systems that
don't have that. */
#ifdef HAVE_CONFIG_H
......@@ -33,6 +33,7 @@
#include "argp-fmtstream.h"
#include "argp-namefrob.h"
#include "mbswidth.h"
#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
......@@ -118,51 +119,48 @@ weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
#endif
size_t
__argp_get_display_len (const char *beg, const char *end)
/* Return the pointer to the first character that doesn't fit in l columns. */
static inline const ptrdiff_t
add_width (const char *ptr, const char *end, size_t l)
{
const char *ptr;
size_t r = 0;
mbstate_t ps;
const char *ptr0 = ptr;
memset (&ps, 0, sizeof (ps));
for (ptr = beg; ptr < end && *ptr; )
while (ptr < end)
{
wchar_t wc;
size_t s;
size_t s, k;
s = mbrtowc (&wc, ptr, end - ptr, &ps);
if (s == (size_t) -1)
break;
r += wcwidth (wc);
ptr += s;
}
return r;
}
static inline char *
add_length (char *ptr, char *end, size_t l)
{
mbstate_t ps;
memset (&ps, 0, sizeof (ps));
if (s == (size_t) -2)
{
if (1 >= l)
break;
l--;
ptr++;
continue;
}
while (ptr < end && *ptr)
{
wchar_t wc;
size_t s, k;
if (wc == '\e' && ptr + 3 < end
&& ptr[1] == '[' && (ptr[2] == '0' || ptr[2] == '1')
&& ptr[3] == 'm')
{
ptr += 4;
continue;
}
s = mbrtowc (&wc, ptr, end - ptr, &ps);
if (s == (size_t) -1)
break;
k = wcwidth (wc);
if (k >= l)
break;
l -= k;
ptr += s;
}
return ptr;
return ptr - ptr0;
}
/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
......@@ -217,15 +215,15 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
if (!nl)
{
size_t display_len = __argp_get_display_len (buf, fs->p);
size_t display_width = mbsnwidth (buf, fs->p - buf, MBSW_STOP_AT_NUL);
/* The buffer ends in a partial line. */
if (fs->point_col + display_len < fs->rmargin)
if (fs->point_col + display_width < fs->rmargin)
{