diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-09-05 09:47:04 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-09-05 09:47:04 +0000 |
commit | b39bc242141259d39f8fd57ba90d778f9c734fff (patch) | |
tree | 6b52c4a753e3901643cce5ce6e19cd54399aad92 /lib/libc/locale | |
parent | 8fb4b2b54d8a29c61c6df479a1351f098879bbc2 (diff) |
Delete some abstraction that we don't and won't need.
Declare functions rather than generating declarations with macros.
Just call functions rather than mainting function pointer tables.
Purge unused arguments. Simplify mbstate_t casting.
Garbage collect one empty and one unused function.
As a bonus, make mbsinit(3) work at all, it returned garbage
in the past due to a missing cast when passing mbstate_t.
Apart from that, no functional change.
No libc bump needed; only private functions are removed and
change prototype and only private structs change size.
OK stsp@ mpi@; deraadt@ likes the general direction.
Diffstat (limited to 'lib/libc/locale')
-rw-r--r-- | lib/libc/locale/multibyte.h | 50 | ||||
-rw-r--r-- | lib/libc/locale/multibyte_citrus.c | 44 | ||||
-rw-r--r-- | lib/libc/locale/rune.c | 15 | ||||
-rw-r--r-- | lib/libc/locale/rune_local.h | 3 | ||||
-rw-r--r-- | lib/libc/locale/runetable.c | 2 | ||||
-rw-r--r-- | lib/libc/locale/runetype.h | 3 | ||||
-rw-r--r-- | lib/libc/locale/setrunelocale.c | 25 |
7 files changed, 26 insertions, 116 deletions
diff --git a/lib/libc/locale/multibyte.h b/lib/libc/locale/multibyte.h deleted file mode 100644 index 9a69ada2751..00000000000 --- a/lib/libc/locale/multibyte.h +++ /dev/null @@ -1,50 +0,0 @@ -/* $OpenBSD: multibyte.h,v 1.1 2010/07/27 16:59:04 stsp Exp $ */ -/* $NetBSD: multibyte.h,v 1.5 2009/01/11 02:46:28 christos Exp $ */ - -/*- - * Copyright (c)2002 Citrus Project, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef _MULTIBYTE_H_ -#define _MULTIBYTE_H_ - -typedef struct _RuneStatePriv { - _RuneLocale *__runelocale; - char __private __attribute__((__aligned__)); -} _RuneStatePriv; - -typedef union _RuneState { - mbstate_t __pad; - struct _RuneStatePriv __priv; -#define rs_runelocale __priv.__runelocale -#define rs_private __priv.__private -} _RuneState; -#define _RUNE_STATE_PRIVSIZE (sizeof(mbstate_t)-offsetof(_RuneStatePriv, __private)) - -#define _ps_to_runestate(ps) ((_RuneState *)(void *)(ps)) -#define _ps_to_runelocale(ps) (_ps_to_runestate(ps)->rs_runelocale) -#define _ps_to_private(ps) ((void *)&_ps_to_runestate(ps)->rs_private) - -#endif /*_MULTIBYTE_H_*/ diff --git a/lib/libc/locale/multibyte_citrus.c b/lib/libc/locale/multibyte_citrus.c index 5e30f5bbee9..c4566579621 100644 --- a/lib/libc/locale/multibyte_citrus.c +++ b/lib/libc/locale/multibyte_citrus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: multibyte_citrus.c,v 1.6 2015/09/12 16:23:14 guenther Exp $ */ +/* $OpenBSD: multibyte_citrus.c,v 1.7 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: multibyte_amd1.c,v 1.7 2009/01/11 02:46:28 christos Exp $ */ /*- @@ -28,28 +28,18 @@ */ #include <sys/types.h> -#include <errno.h> #include <stdint.h> +#include <stdlib.h> #include <wchar.h> #include "citrus_ctype.h" -#include "rune.h" -#include "multibyte.h" int mbsinit(const mbstate_t *ps) { - struct _citrus_ctype_rec *cc; - _RuneLocale *rl; - - if (ps == NULL) + if (ps == NULL || __mb_cur_max == 1) return 1; - - rl = _ps_to_runelocale(ps); - if (rl == NULL) - rl = _CurrentRuneLocale; - cc = rl->rl_citrus_ctype; - return (*cc->cc_ops->co_mbsinit)(ps); + return _citrus_utf8_ctype_mbsinit(ps); } DEF_STRONG(mbsinit); @@ -57,12 +47,12 @@ size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_mbrtowc)(pwc, s, n, _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_mbrtowc(pwc, s, n); + return _citrus_utf8_ctype_mbrtowc(pwc, s, n, ps); } DEF_STRONG(mbrtowc); @@ -82,13 +72,12 @@ mbsnrtowcs(wchar_t *dst, const char **src, size_t nmc, size_t len, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_mbsnrtowcs)(dst, src, nmc, len, - _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_mbsnrtowcs(dst, src, nmc, len); + return _citrus_utf8_ctype_mbsnrtowcs(dst, src, nmc, len, ps); } DEF_WEAK(mbsnrtowcs); @@ -96,12 +85,12 @@ size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_wcrtomb)(s, wc, _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_wcrtomb(s, wc); + return _citrus_utf8_ctype_wcrtomb(s, wc, ps); } DEF_STRONG(wcrtomb); @@ -121,12 +110,11 @@ wcsnrtombs(char *dst, const wchar_t **src, size_t nwc, size_t len, mbstate_t *ps) { static mbstate_t mbs; - struct _citrus_ctype_rec *cc; if (ps == NULL) ps = &mbs; - cc = _CurrentRuneLocale->rl_citrus_ctype; - return (*cc->cc_ops->co_wcsnrtombs)(dst, src, nwc, len, - _ps_to_private(ps)); + if (__mb_cur_max == 1) + return _citrus_none_ctype_wcsnrtombs(dst, src, nwc, len); + return _citrus_utf8_ctype_wcsnrtombs(dst, src, nwc, len, ps); } DEF_WEAK(wcsnrtombs); diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index 7774859df86..d5c3e5c0681 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rune.c,v 1.6 2016/02/05 04:10:48 jsg Exp $ */ +/* $OpenBSD: rune.c,v 1.7 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: rune.c,v 1.26 2004/05/09 11:26:33 kleink Exp $ */ /*- @@ -319,16 +319,3 @@ err: free(hostdata); return NULL; } - -void -_NukeRune(_RuneLocale *rl) -{ - - if (rl != &_DefaultRuneLocale) { - _freeentry(&rl->rl_runetype_ext); - free(rl->rl_tabs); - free(rl->rl_codeset); - free(rl); - } -} - diff --git a/lib/libc/locale/rune_local.h b/lib/libc/locale/rune_local.h index 97491447955..7f2d5d90a5b 100644 --- a/lib/libc/locale/rune_local.h +++ b/lib/libc/locale/rune_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rune_local.h,v 1.4 2015/09/13 11:38:08 guenther Exp $ */ +/* $OpenBSD: rune_local.h,v 1.5 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: rune_local.h,v 1.7 2003/03/02 22:18:15 tshiozak Exp $ */ /*- @@ -34,7 +34,6 @@ __BEGIN_HIDDEN_DECLS /* rune.c */ extern _RuneLocale *_Read_RuneMagi(FILE *fp); -extern void _NukeRune(_RuneLocale *); /* setrunelocale.c */ extern int _xpg4_setrunelocale(const char *); diff --git a/lib/libc/locale/runetable.c b/lib/libc/locale/runetable.c index 9f0bd4afc0b..ad4e22c9631 100644 --- a/lib/libc/locale/runetable.c +++ b/lib/libc/locale/runetable.c @@ -42,7 +42,6 @@ #include "rune.h" #include "rune_local.h" #include "citrus_ctype.h" -#include "citrus_none.h" _RuneLocale _DefaultRuneLocale = { _RUNE_MAGIC_1, @@ -249,7 +248,6 @@ _RuneLocale _DefaultRuneLocale = { { 0, NULL }, NULL, 0, "US-ASCII", - &_citrus_ctype_none, { { NULL, NULL, NULL }, { NULL, NULL, NULL }, diff --git a/lib/libc/locale/runetype.h b/lib/libc/locale/runetype.h index c39ec6dce65..e12ed1f0818 100644 --- a/lib/libc/locale/runetype.h +++ b/lib/libc/locale/runetype.h @@ -1,7 +1,7 @@ #ifndef _NB_RUNETYPE_H_ #define _NB_RUNETYPE_H_ -/* $OpenBSD: runetype.h,v 1.7 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: runetype.h,v 1.8 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: runetype.h,v 1.18 2003/08/07 16:43:04 agc Exp $ */ /*- * Copyright (c) 1993 @@ -199,7 +199,6 @@ typedef struct { * the following portion is generated on the fly */ char *rl_codeset; - struct _citrus_ctype_rec *rl_citrus_ctype; _WCTransEntry rl_wctrans[_WCTRANS_NINDEXES]; _WCTypeEntry rl_wctype[_WCTYPE_NINDEXES]; diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c index 2ade6c4a84f..754a1b30dfe 100644 --- a/lib/libc/locale/setrunelocale.c +++ b/lib/libc/locale/setrunelocale.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setrunelocale.c,v 1.14 2016/09/02 15:00:14 schwarze Exp $ */ +/* $OpenBSD: setrunelocale.c,v 1.15 2016/09/05 09:47:03 schwarze Exp $ */ /* $NetBSD: setrunelocale.c,v 1.14 2003/08/07 16:43:07 agc Exp $ */ /*- @@ -107,7 +107,6 @@ int _newrunelocale(const char *path) { FILE *fp; - _RuneLocale *rl; if (_Utf8RuneLocale != NULL) return 0; @@ -115,20 +114,11 @@ _newrunelocale(const char *path) if ((fp = fopen(path, "re")) == NULL) return ENOENT; - if ((rl = _Read_RuneMagi(fp)) == NULL) { + if ((_Utf8RuneLocale = _Read_RuneMagi(fp)) == NULL) { fclose(fp); return EFTYPE; } fclose(fp); - - rl->rl_citrus_ctype = NULL; - - if (_citrus_ctype_open(&rl->rl_citrus_ctype, rl->rl_encoding)) { - _NukeRune(rl); - return EINVAL; - } - _Utf8RuneLocale = rl; - return 0; } @@ -141,7 +131,8 @@ _xpg4_setrunelocale(const char *locname) if (!strcmp(locname, "C") || !strcmp(locname, "POSIX")) { _CurrentRuneLocale = &_DefaultRuneLocale; - goto found; + __mb_cur_max = 1; + return 0; } /* Assumes "language[_territory][.codeset]" locale name. */ @@ -149,7 +140,8 @@ _xpg4_setrunelocale(const char *locname) if (dot == NULL) { /* No encoding specified. Fall back to ASCII. */ _CurrentRuneLocale = &_DefaultRuneLocale; - goto found; + __mb_cur_max = 1; + return 0; } encoding = dot + 1; @@ -167,9 +159,6 @@ _xpg4_setrunelocale(const char *locname) if (_Utf8RuneLocale == NULL) return ENOENT; _CurrentRuneLocale = _Utf8RuneLocale; - -found: - __mb_cur_max = _CurrentRuneLocale->rl_citrus_ctype->cc_mb_cur_max; - + __mb_cur_max = _CITRUS_UTF8_MB_CUR_MAX; return 0; } |