[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Alan Hourihane: [bug #24687] implicit usage of mbsinit & mbrtowc
From: |
Bruno Haible |
Subject: |
Re: Alan Hourihane: [bug #24687] implicit usage of mbsinit & mbrtowc |
Date: |
Thu, 30 Oct 2008 12:42:48 +0100 |
User-agent: |
KMail/1.5.4 |
Hello Sergey,
> > This renders compilation of 4.13 inoperable on these systems, and you get
> > the
> > build errors below....
> >
> > display.o:display.o:(.text+0x786): undefined reference to `mbrtowc'
> > display.o:display.o:(.text+0x78c): undefined reference to `mbsinit'
The problem is that texinfo's info.h includes mbiter.h unconditionally,
whereas the module description in gnulib specifies this:
Include:
#if HAVE_MBRTOWC
#include "mbiter.h"
#endif
Now I see that you have 9 functions in
texinfo/info/{display.c,session.c,window.c}
which use the mbiter facility unconditionally, and you probably have no
interest in adding fallback code for older systems for each of these functions.
I'll therefore extend the modules in a way that they work also on older
systems without HAVE_MBRTOWC.
Something like this. Probably also adding replacements for btowc and mbrtowc.
Bruno
--- modules/mbfile.orig 2008-10-30 12:42:19.000000000 +0100
+++ modules/mbfile 2008-10-30 11:22:00.000000000 +0100
@@ -18,9 +18,7 @@
lib_SOURCES += mbfile.h
Include:
-#if HAVE_MBRTOWC
#include "mbfile.h"
-#endif
License:
LGPL
--- modules/mbiter.orig 2008-10-30 12:42:19.000000000 +0100
+++ modules/mbiter 2008-10-30 11:21:50.000000000 +0100
@@ -18,9 +18,7 @@
lib_SOURCES += mbiter.h
Include:
-#if HAVE_MBRTOWC
#include "mbiter.h"
-#endif
License:
LGPL
--- modules/mbuiter.orig 2008-10-30 12:42:19.000000000 +0100
+++ modules/mbuiter 2008-10-30 11:21:40.000000000 +0100
@@ -19,9 +19,7 @@
lib_SOURCES += mbuiter.h
Include:
-#if HAVE_MBRTOWC
#include "mbuiter.h"
-#endif
License:
LGPL
--- lib/mbfile.h.orig 2008-10-30 12:41:22.000000000 +0100
+++ lib/mbfile.h 2008-10-30 12:27:45.000000000 +0100
@@ -1,5 +1,5 @@
/* Multibyte character I/O: macros for multi-byte encodings.
- Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2005, 2008 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
@@ -62,6 +62,42 @@
#include "mbchar.h"
+/* ------------------ Implementation for unibyte locales ------------------ */
+
+typedef FILE * mbfile_unibyte;
+
+static inline void
+mbfile_unibyte_getc (struct mbchar *mbc, mbfile_unibyte mbf)
+{
+ int c = getc (mbf);
+ if (c != EOF)
+ {
+ mbc->buf[0] = (unsigned char) c;
+ mbc->ptr = &mbc->buf[0];
+ mbc->bytes = 1;
+ mbc->wc = btowc (c);
+ mbc->wc_valid = true;
+ }
+ else
+ {
+ /* An mbchar_t with bytes == 0 is used to indicate EOF. */
+ mbc->ptr = NULL;
+ mbc->bytes = 0;
+ mbc->wc_valid = false;
+ }
+}
+
+static inline void
+mbfile_unibyte_ungetc (const struct mbchar *mbc, mbfile_unibyte mbf)
+{
+ if (mbc->bytes > 0)
+ ungetc ((unsigned char) mbc->ptr[0]);
+}
+
+/* ----------------- Implementation for multibyte locales ----------------- */
+
+#if HAVE_MBRTOWC
+
struct mbfile_multi {
FILE *fp;
bool eof_seen;
@@ -222,6 +258,12 @@
mbf->have_pushback = true;
}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+#if HAVE_MBRTOWC /* systems with multibyte locales */
+
typedef struct mbfile_multi mb_file_t;
typedef mbchar_t mbf_char_t;
@@ -237,6 +279,20 @@
#define mbf_ungetc(mbc, mbf) mbfile_multi_ungetc (&(mbc), &(mbf))
+#else /* systems without multibyte locales */
+
+typedef mbfile_unibyte mb_file_t;
+
+typedef mbchar_t mbf_char_t;
+
+#define mbf_init(mbf, stream) ((mbf) = (stream))
+
+#define mbf_getc(mbc, mbf) mbfile_unibyte_getc (&(mbc), (mbf))
+
+#define mbf_ungetc(mbc, mbf) mbfile_unibyte_ungetc (&(mbc), (mbf))
+
+#endif
+
#define mb_iseof(mbc) ((mbc).bytes == 0)
#endif /* _MBFILE_H */
--- lib/mbiter.h.orig 2008-10-30 12:41:22.000000000 +0100
+++ lib/mbiter.h 2008-10-30 12:27:51.000000000 +0100
@@ -1,5 +1,5 @@
/* Iterating through multibyte strings: macros for multi-byte encodings.
- Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2005, 2007-2008 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
@@ -97,6 +97,31 @@
#include "mbchar.h"
+/* ------------------ Implementation for unibyte locales ------------------ */
+
+struct mbiter_unibyte
+{
+ const char *limit; /* pointer to end of string */
+ struct mbchar cur; /* the current character:
+ const char *cur.ptr pointer to current character
+ The following are only valid after mbi_avail.
+ size_t cur.bytes number of bytes of current character
+ bool cur.wc_valid true if wc is a valid wide character
+ wchar_t cur.wc if wc_valid: the current character
+ */
+};
+
+static inline void
+mbiter_unibyte_copy (struct mbiter_unibyte *new_iter, const struct
mbiter_unibyte *old_iter)
+{
+ new_iter->limit = old_iter->limit;
+ mb_copy (&new_iter->cur, &old_iter->cur);
+}
+
+/* ----------------- Implementation for multibyte locales ----------------- */
+
+#if HAVE_MBRTOWC
+
struct mbiter_multi
{
const char *limit; /* pointer to end of string */
@@ -191,6 +216,12 @@
mb_copy (&new_iter->cur, &old_iter->cur);
}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+#if HAVE_MBRTOWC /* systems with multibyte locales */
+
/* Iteration macros. */
typedef struct mbiter_multi mbi_iterator_t;
#define mbi_init(iter, startptr, length) \
@@ -212,4 +243,29 @@
/* Copying an iterator. */
#define mbi_copy mbiter_multi_copy
+#else /* systems without multibyte locales */
+
+/* Iteration macros. */
+typedef struct mbiter_unibyte mbi_iterator_t;
+#define mbi_init(iter, startptr, length) \
+ ((iter).cur.ptr = (startptr), (iter).limit = (iter).cur.ptr + (length), \
+ (iter).cur.bytes = 1, (iter).cur.wc_valid = true)
+#define mbi_avail(iter) \
+ ((iter).cur.ptr < (iter).limit \
+ && (((iter).cur.wc = btowc (*(iter).cur.ptr)), true))
+#define mbi_advance(iter) \
+ ((iter).cur.ptr++)
+
+/* Access to the current character. */
+#define mbi_cur(iter) (iter).cur
+#define mbi_cur_ptr(iter) (iter).cur.ptr
+
+/* Relocation. */
+#define mbi_reloc(iter, ptrdiff) (void) ((iter).cur.ptr += (ptrdiff))
+
+/* Copying an iterator. */
+#define mbi_copy mbiter_unibyte_copy
+
+#endif
+
#endif /* _MBITER_H */
--- lib/mbuiter.h.orig 2008-10-30 12:41:23.000000000 +0100
+++ lib/mbuiter.h 2008-10-30 12:27:57.000000000 +0100
@@ -1,5 +1,5 @@
/* Iterating through multibyte strings: macros for multi-byte encodings.
- Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2005, 2007-2008 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
@@ -106,6 +106,29 @@
#include "mbchar.h"
#include "strnlen1.h"
+/* ------------------ Implementation for unibyte locales ------------------ */
+
+struct mbuiter_unibyte
+{
+ struct mbchar cur; /* the current character:
+ const char *cur.ptr pointer to current character
+ The following are only valid after mbui_avail.
+ size_t cur.bytes number of bytes of current character
+ bool cur.wc_valid true if wc is a valid wide character
+ wchar_t cur.wc if wc_valid: the current character
+ */
+};
+
+static inline void
+mbuiter_unibyte_copy (struct mbuiter_unibyte *new_iter, const struct
mbuiter_unibyte *old_iter)
+{
+ mb_copy (&new_iter->cur, &old_iter->cur);
+}
+
+/* ----------------- Implementation for multibyte locales ----------------- */
+
+#if HAVE_MBRTOWC
+
struct mbuiter_multi
{
bool in_shift; /* true if next byte may not be interpreted as ASCII */
@@ -198,6 +221,12 @@
mb_copy (&new_iter->cur, &old_iter->cur);
}
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+#if HAVE_MBRTOWC /* systems with multibyte locales */
+
/* Iteration macros. */
typedef struct mbuiter_multi mbui_iterator_t;
#define mbui_init(iter, startptr) \
@@ -219,4 +248,29 @@
/* Copying an iterator. */
#define mbui_copy mbuiter_multi_copy
+#else /* systems without multibyte locales */
+
+/* Iteration macros. */
+typedef struct mbuiter_unibyte mbui_iterator_t;
+#define mbui_init(iter, startptr) \
+ ((iter).cur.ptr = (startptr), \
+ (iter).cur.bytes = 1, (iter).cur.wc_valid = true)
+#define mbui_avail(iter) \
+ (*(iter).cur.ptr != '\0' \
+ && (((iter).cur.wc = btowc (*(iter).cur.ptr)), true))
+#define mbui_advance(iter) \
+ ((iter).cur.ptr++)
+
+/* Access to the current character. */
+#define mbui_cur(iter) (iter).cur
+#define mbui_cur_ptr(iter) (iter).cur.ptr
+
+/* Relocation. */
+#define mbui_reloc(iter, ptrdiff) (void) ((iter).cur.ptr += (ptrdiff))
+
+/* Copying an iterator. */
+#define mbui_copy mbuiter_unibyte_copy
+
+#endif
+
#endif /* _MBUITER_H */