Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc 1. refactoring new locale-db(RuneCT10) loading meth...
details: https://anonhg.NetBSD.org/src/rev/c28b0a726858
branches: trunk
changeset: 755764:c28b0a726858
user: tnozaki <tnozaki%NetBSD.org@localhost>
date: Sat Jun 19 13:26:51 2010 +0000
description:
1. refactoring new locale-db(RuneCT10) loading method with mmap(2).
2. remove unused field from _RuneLocale.
3. localeio(CITRUS=no) can read new locale-db(RuneCT10) now.
diffstat:
lib/libc/citrus/citrus_lc_ctype.c | 43 +-
lib/libc/locale/Makefile.inc | 5 +-
lib/libc/locale/bsdctype.c | 149 +++---
lib/libc/locale/bsdctype_local.h | 5 +-
lib/libc/locale/global_locale.c | 6 +-
lib/libc/locale/localeio.c | 53 ++-
lib/libc/locale/localeio.h | 5 +-
lib/libc/locale/localeio_lc_ctype.c | 15 +-
lib/libc/locale/rune.c | 723 ++++++++++++++---------------------
lib/libc/locale/runeglue.c | 148 -------
lib/libc/locale/runetable.c | 8 +-
lib/libc/locale/runetype_file.h | 89 ++++-
lib/libc/locale/runetype_local.h | 13 +-
13 files changed, 538 insertions(+), 724 deletions(-)
diffs (truncated from 1601 to 300 lines):
diff -r a2fc33eb3c00 -r c28b0a726858 lib/libc/citrus/citrus_lc_ctype.c
--- a/lib/libc/citrus/citrus_lc_ctype.c Sat Jun 19 11:16:31 2010 +0000
+++ b/lib/libc/citrus/citrus_lc_ctype.c Sat Jun 19 13:26:51 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: citrus_lc_ctype.c,v 1.8 2010/06/13 04:14:56 tnozaki Exp $ */
+/* $NetBSD: citrus_lc_ctype.c,v 1.9 2010/06/19 13:26:51 tnozaki Exp $ */
/*-
* Copyright (c)2008 Citrus Project,
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: citrus_lc_ctype.c,v 1.8 2010/06/13 04:14:56 tnozaki Exp $");
+__RCSID("$NetBSD: citrus_lc_ctype.c,v 1.9 2010/06/19 13:26:51 tnozaki Exp $");
#endif /* LIBC_SCCS and not lint */
#include "reentrant.h"
@@ -56,6 +56,7 @@
#include "citrus_aliasname_local.h"
#include "citrus_module.h"
#include "citrus_ctype.h"
+#include "citrus_mmap.h"
#include "runetype_local.h"
#include "multibyte.h"
@@ -77,9 +78,8 @@
const char * __restrict name, _RuneLocale ** __restrict pdata)
{
char path[PATH_MAX + 1];
- FILE *fp;
- _RuneLocale *data;
int ret;
+ struct _region r;
_DIAGASSERT(root != NULL);
_DIAGASSERT(name != NULL);
@@ -87,37 +87,12 @@
snprintf(path, sizeof(path),
"%s/%s/LC_CTYPE", root, name);
- fp = fopen(path, "r");
- if (fp == NULL)
- return ENOENT;
- data = _Read_RuneMagi(fp);
- if (data == NULL) {
- data = _Read_CTypeAsRune(fp);
- if (data == NULL) {
- fclose(fp);
- return EFTYPE;
- }
+ ret = _citrus_map_file(&r, path);
+ if (!ret) {
+ ret = _rune_load((const char *)r.r_head, r.r_size, pdata);
+ _citrus_unmap_file(&r);
}
- fclose(fp);
- ret = _citrus_ctype_open(&data->rl_citrus_ctype, data->rl_encoding,
- data->rl_variable, data->rl_variable_len, _PRIVSIZE);
- if (!ret)
- ret = __runetable_to_netbsd_ctype(data);
- if (ret || __mb_len_max_runtime <
- _citrus_ctype_get_mb_cur_max(data->rl_citrus_ctype)) {
- _NukeRune(data);
- return EINVAL;
- }
- data->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name = "tolower";
- data->rl_wctrans[_WCTRANS_INDEX_LOWER].te_cached = &data->rl_maplower[0];
- data->rl_wctrans[_WCTRANS_INDEX_LOWER].te_extmap = &data->rl_maplower_ext;
-
- data->rl_wctrans[_WCTRANS_INDEX_UPPER].te_name = "toupper";
- data->rl_wctrans[_WCTRANS_INDEX_UPPER].te_cached = &data->rl_mapupper[0];
- data->rl_wctrans[_WCTRANS_INDEX_UPPER].te_extmap = &data->rl_mapupper_ext;
-
- *pdata = data;
- return 0;
+ return ret;
}
static __inline void
diff -r a2fc33eb3c00 -r c28b0a726858 lib/libc/locale/Makefile.inc
--- a/lib/libc/locale/Makefile.inc Sat Jun 19 11:16:31 2010 +0000
+++ b/lib/libc/locale/Makefile.inc Sat Jun 19 13:26:51 2010 +0000
@@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 5.1 (Berkeley) 2/18/91
-# $NetBSD: Makefile.inc,v 1.57 2010/06/07 13:52:30 tnozaki Exp $
+# $NetBSD: Makefile.inc,v 1.58 2010/06/19 13:26:52 tnozaki Exp $
# locale sources
.PATH: ${ARCHDIR}/locale ${.CURDIR}/locale
@@ -16,10 +16,9 @@
# citrus multibyte locale support
# we have quirk for libc.a - see the last part of lib/libc/Makefile
CPPFLAGS+= -DWITH_RUNE -I${.CURDIR}
-SRCS+= _wctrans.c _wctype.c rune.c runeglue.c runetable.c \
+SRCS+= _wctrans.c _wctype.c rune.c runetable.c \
multibyte_c90.c multibyte_amd1.c iswctype_mb.c
CPPFLAGS.rune.c+= -I${LIBCDIR}/citrus
-CPPFLAGS.runeglue.c+= -I${LIBCDIR}/citrus
CPPFLAGS.runetable.c+= -I${LIBCDIR}/citrus
CPPFLAGS.multibyte_c90.c+= -I${LIBCDIR}/citrus
CPPFLAGS.multibyte_amd1.c+= -I${LIBCDIR}/citrus
diff -r a2fc33eb3c00 -r c28b0a726858 lib/libc/locale/bsdctype.c
--- a/lib/libc/locale/bsdctype.c Sat Jun 19 11:16:31 2010 +0000
+++ b/lib/libc/locale/bsdctype.c Sat Jun 19 13:26:51 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bsdctype.c,v 1.7 2010/06/13 04:14:57 tnozaki Exp $ */
+/* $NetBSD: bsdctype.c,v 1.8 2010/06/19 13:26:52 tnozaki Exp $ */
/*-
* Copyright (c)2008 Citrus Project,
@@ -28,11 +28,10 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: bsdctype.c,v 1.7 2010/06/13 04:14:57 tnozaki Exp $");
+__RCSID("$NetBSD: bsdctype.c,v 1.8 2010/06/19 13:26:52 tnozaki Exp $");
#endif /* LIBC_SCCS and not lint */
-#include <sys/stat.h>
-#include <sys/mman.h>
+#include <sys/endian.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
@@ -42,6 +41,7 @@
#include <unistd.h>
#include "bsdctype_local.h"
+#include "runetype_file.h"
const _BSDCTypeLocale _DefaultBSDCTypeLocale = {
_C_ctype_,
@@ -61,6 +61,15 @@
static __inline void
_bsdctype_init_priv(_BSDCTypeLocalePriv *blp)
{
+#if _CTYPE_CACHE_SIZE != _CTYPE_NUM_CHARS
+ int i;
+
+ for (i = _CTYPE_CACHE_SIZE; i < _CTYPE_NUM_CHARS; ++i) {
+ blp->blp_ctype_tab [i + 1] = 0;
+ blp->blp_tolower_tab[i + 1] = i;
+ blp->blp_toupper_tab[i + 1] = i;
+ }
+#endif
blp->blp_ctype_tab [0] = 0;
blp->blp_tolower_tab[0] = EOF;
blp->blp_toupper_tab[0] = EOF;
@@ -77,103 +86,93 @@
uint32_t value;
int i;
+ _DIAGASSERT(blp != NULL);
+
if (lenvar < sizeof(*fbl))
return EFTYPE;
fbl = (const _FileBSDCTypeLocale *)(const void *)var;
if (memcmp(&fbl->fbl_id[0], _CTYPE_ID, sizeof(fbl->fbl_id)))
return EFTYPE;
- value = ntohl(fbl->fbl_rev);
+ value = be32toh(fbl->fbl_rev);
if (value != _CTYPE_REV)
return EFTYPE;
- value = ntohl(fbl->fbl_num_chars);
+ value = be32toh(fbl->fbl_num_chars);
if (value != _CTYPE_CACHE_SIZE)
return EFTYPE;
for (i = 0; i < _CTYPE_CACHE_SIZE; ++i) {
blp->blp_ctype_tab [i + 1] = fbl->fbl_ctype_tab[i];
- blp->blp_tolower_tab[i + 1] = ntohs(fbl->fbl_tolower_tab[i]);
- blp->blp_toupper_tab[i + 1] = ntohs(fbl->fbl_toupper_tab[i]);
+ blp->blp_tolower_tab[i + 1] = be16toh(fbl->fbl_tolower_tab[i]);
+ blp->blp_toupper_tab[i + 1] = be16toh(fbl->fbl_toupper_tab[i]);
}
-#if _CTYPE_CACHE_SIZE != _CTYPE_NUM_CHARS
- for (i = _CTYPE_CACHE_SIZE; i < _CTYPE_NUM_CHARS; ++i) {
- blp->blp_ctype_tab [i + 1] = 0;
- blp->blp_tolower_tab[i + 1] = i;
- blp->blp_toupper_tab[i + 1] = i;
- }
-#endif
return 0;
}
static __inline int
-_bsdctype_load_priv(const char * __restrict path,
+_bsdctype_read_runetype(const char * __restrict var, size_t lenvar,
_BSDCTypeLocalePriv * __restrict blp)
{
- int fd, ret;
- struct stat st;
- size_t lenvar;
- char *var;
+ const _FileRuneLocale *frl;
+ int i;
+
+ _DIAGASSERT(blp != NULL);
- fd = open(path, O_RDONLY);
- if (fd == -1)
- goto err;
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
- goto err;
- if (fstat(fd, &st) == -1)
- goto err;
- if (!S_ISREG(st.st_mode)) {
- close(fd);
- return EBADF;
+ if (lenvar < sizeof(*frl))
+ return EFTYPE;
+ lenvar -= sizeof(*frl);
+ frl = (const _FileRuneLocale *)(const void *)var;
+ if (memcmp(_RUNECT10_MAGIC, &frl->frl_magic[0], sizeof(frl->frl_magic)))
+ return EFTYPE;
+ if (frl->frl_encoding[0] != 'N' || frl->frl_encoding[1] != 'O' ||
+ frl->frl_encoding[2] != 'N' || frl->frl_encoding[3] != 'E' ||
+ frl->frl_encoding[4] != '\0') /* XXX */
+ return EFTYPE;
+ if (be32toh(frl->frl_runetype_ext.frr_nranges) != 0 ||
+ be32toh(frl->frl_maplower_ext.frr_nranges) != 0 ||
+ be32toh(frl->frl_mapupper_ext.frr_nranges) != 0)
+ return EFTYPE;
+ if (lenvar < be32toh((uint32_t)frl->frl_variable_len))
+ return EFTYPE;
+ for (i = 0; i < _CTYPE_CACHE_SIZE; ++i) {
+ blp->blp_ctype_tab [i + 1] = (unsigned char)
+ _runetype_to_ctype((_RuneType)
+ be32toh(frl->frl_runetype[i]));
+ blp->blp_tolower_tab[i + 1] = (short)
+ be32toh((uint32_t)frl->frl_maplower[i]);
+ blp->blp_toupper_tab[i + 1] = (short)
+ be32toh((uint32_t)frl->frl_mapupper[i]);
}
- lenvar = (size_t)st.st_size;
- if (lenvar < 1) {
- close(fd);
+ return 0;
+}
+
+int
+_bsdctype_load(const char * __restrict var, size_t lenvar,
+ _BSDCTypeLocale ** __restrict pbl)
+{
+ int ret;
+ _BSDCTypeLocalePriv *blp;
+
+ _DIAGASSERT(var != NULL || lenvar < 1);
+ _DIAGASSERT(pbl != NULL);
+
+ if (lenvar < 1)
return EFTYPE;
- }
- var = mmap(NULL, lenvar, PROT_READ,
- MAP_FILE|MAP_PRIVATE, fd, (off_t)0);
- if (var == MAP_FAILED)
- goto err;
- if (close(fd) == -1) {
- ret = errno;
- munmap(var, lenvar);
- return ret;
- }
+ blp = malloc(sizeof(*blp));
+ if (blp == NULL)
+ return errno;
+ _bsdctype_init_priv(blp);
switch (*var) {
case 'B':
- ret = _bsdctype_read_file(var, lenvar, blp);
+ _bsdctype_read_file(var, lenvar, blp);
+ break;
+ case 'R':
+ _bsdctype_read_runetype(var, lenvar, blp);
break;
default:
ret = EFTYPE;
}
- munmap(var, lenvar);
- return ret;
-err:
- ret = errno;
- close(fd);
+ if (ret)
+ free(blp);
+ else
+ *pbl = &blp->bl;
return ret;
}
-
-int
-_bsdctype_load(const char * __restrict path,
- _BSDCTypeLocale ** __restrict pbl)
-{
- int sverr, ret;
- _BSDCTypeLocalePriv *blp;
-
- sverr = errno;
- errno = 0;
- blp = malloc(sizeof(*blp));
- if (blp == NULL) {
Home |
Main Index |
Thread Index |
Old Index