Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add strtof_l, strtod_l and strtold_l.
details: https://anonhg.NetBSD.org/src/rev/fd2689ca6aa1
branches: trunk
changeset: 786180:fd2689ca6aa1
user: joerg <joerg%NetBSD.org@localhost>
date: Thu Apr 18 21:54:10 2013 +0000
description:
Add strtof_l, strtod_l and strtold_l.
diffstat:
include/stdlib.h | 6 ++++-
lib/libc/gdtoa/_strtof.c | 13 ++++++++-
lib/libc/gdtoa/gdtoa.h | 18 +++++++++----
lib/libc/gdtoa/strtod.c | 53 +++++++++++++++++++++---------------------
lib/libc/gdtoa/strtodg.c | 30 +++---------------------
lib/libc/gdtoa/strtof.c | 30 +++++++++++++++++------
lib/libc/gdtoa/strtof_vaxf.c | 29 +++++++++++++++++------
lib/libc/gdtoa/strtold_subr.c | 28 ++++++++++++++++++----
lib/libc/gdtoa/strtopQ.c | 10 ++-----
lib/libc/gdtoa/strtopx.c | 10 ++-----
lib/libc/gdtoa/strtopxL.c | 10 ++-----
lib/libc/gdtoa/strtord.c | 10 ++-----
lib/libc/include/namespace.h | 5 +++-
13 files changed, 140 insertions(+), 112 deletions(-)
diffs (truncated from 589 to 300 lines):
diff -r 792badd52480 -r fd2689ca6aa1 include/stdlib.h
--- a/include/stdlib.h Thu Apr 18 21:53:55 2013 +0000
+++ b/include/stdlib.h Thu Apr 18 21:54:10 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: stdlib.h,v 1.101 2013/04/16 21:44:06 joerg Exp $ */
+/* $NetBSD: stdlib.h,v 1.102 2013/04/18 21:54:10 joerg Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -334,6 +334,10 @@
typedef struct _locale *locale_t;
# define __LOCALE_T_DECLARED
# endif
+double strtod_l(const char * __restrict, char ** __restrict, locale_t);
+float strtof_l(const char * __restrict, char ** __restrict, locale_t);
+long double strtold_l(const char * __restrict, char ** __restrict,
+ locale_t);
long strtol_l(const char * __restrict, char ** __restrict, int, locale_t);
unsigned long
strtoul_l(const char * __restrict, char ** __restrict, int, locale_t);
diff -r 792badd52480 -r fd2689ca6aa1 lib/libc/gdtoa/_strtof.c
--- a/lib/libc/gdtoa/_strtof.c Thu Apr 18 21:53:55 2013 +0000
+++ b/lib/libc/gdtoa/_strtof.c Thu Apr 18 21:54:10 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: _strtof.c,v 1.2 2009/10/21 01:07:45 snj Exp $ */
+/* $NetBSD: _strtof.c,v 1.3 2013/04/18 21:54:10 joerg Exp $ */
/*
* Copyright (c) 1996 Christos Zoulas. All rights reserved.
@@ -26,15 +26,17 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: _strtof.c,v 1.2 2009/10/21 01:07:45 snj Exp $");
+__RCSID("$NetBSD: _strtof.c,v 1.3 2013/04/18 21:54:10 joerg Exp $");
#endif /* LIBC_SCCS and not lint */
#if defined(__indr_reference)
__indr_reference(_strtof, strtof)
+__indr_reference(_strtof_l, strtof_l)
#else
#include <stdlib.h>
float _strtof(const char * __restrict, char ** __restrict);
+float _strtof_l(const char * __restrict, char ** __restrict, locale_t);
float
strtof(const char *nptr, char **endptr)
@@ -42,4 +44,11 @@
return _strtof(nptr, endptr);
}
+
+float
+strtof_l(const char *nptr, char **endptr, locale_t loc)
+{
+
+ return _strtof_l(nptr, endptr, loc);
+}
#endif
diff -r 792badd52480 -r fd2689ca6aa1 lib/libc/gdtoa/gdtoa.h
--- a/lib/libc/gdtoa/gdtoa.h Thu Apr 18 21:53:55 2013 +0000
+++ b/lib/libc/gdtoa/gdtoa.h Thu Apr 18 21:54:10 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gdtoa.h,v 1.9 2011/03/20 23:15:35 christos Exp $ */
+/* $NetBSD: gdtoa.h,v 1.10 2013/04/18 21:54:10 joerg Exp $ */
/****************************************************************
@@ -38,6 +38,11 @@
#include <stddef.h> /* for size_t */
#include <stdint.h>
+#ifndef __LOCALE_T_DECLARED
+typedef struct _locale *locale_t;
+#define __LOCALE_T_DECLARED
+#endif
+
#ifndef Long
#define Long int32_t
#endif
@@ -133,7 +138,8 @@
extern void freedtoa ANSI((char*));
extern float strtof ANSI((CONST char *, char **));
extern double strtod ANSI((CONST char *, char **));
-extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*));
+extern int strtodg ANSI((CONST char*, char**, CONST FPI*, Long*, ULong*,
+ locale_t));
extern char* g_ddfmt ANSI((char*, double*, int, size_t));
extern char* g_dfmt ANSI((char*, double*, int, size_t));
@@ -148,7 +154,7 @@
extern int strtoIQ ANSI((CONST char*, char**, void*, void*));
extern int strtoIx ANSI((CONST char*, char**, void*, void*));
extern int strtoIxL ANSI((CONST char*, char**, void*, void*));
-extern int strtord ANSI((CONST char*, char**, int, double*));
+extern int strtord ANSI((CONST char*, char**, int, double*, locale_t));
extern int strtordd ANSI((CONST char*, char**, int, double*));
extern int strtorf ANSI((CONST char*, char**, int, float*));
extern int strtorQ ANSI((CONST char*, char**, int, void*));
@@ -159,9 +165,9 @@
extern int strtopd ANSI((CONST char*, char**, double*));
extern int strtopdd ANSI((CONST char*, char**, double*));
extern int strtopf ANSI((CONST char*, char**, float*));
-extern int strtopQ ANSI((CONST char*, char**, void*));
-extern int strtopx ANSI((CONST char*, char**, void*));
-extern int strtopxL ANSI((CONST char*, char**, void*));
+extern int strtopQ ANSI((CONST char*, char**, void*, locale_t));
+extern int strtopx ANSI((CONST char*, char**, void*, locale_t));
+extern int strtopxL ANSI((CONST char*, char**, void*, locale_t));
#else
#define strtopd(s,se,x) strtord(s,se,1,x)
#define strtopdd(s,se,x) strtordd(s,se,1,x)
diff -r 792badd52480 -r fd2689ca6aa1 lib/libc/gdtoa/strtod.c
--- a/lib/libc/gdtoa/strtod.c Thu Apr 18 21:53:55 2013 +0000
+++ b/lib/libc/gdtoa/strtod.c Thu Apr 18 21:54:10 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strtod.c,v 1.11 2012/03/22 15:34:14 christos Exp $ */
+/* $NetBSD: strtod.c,v 1.12 2013/04/18 21:54:10 joerg Exp $ */
/****************************************************************
@@ -31,13 +31,15 @@
/* Please send bug reports to David M. Gay (dmg at acm dot org,
* with " at " changed at "@" and " dot " changed to "."). */
+#include "namespace.h"
#include "gdtoaimp.h"
#ifndef NO_FENV_H
#include <fenv.h>
#endif
#ifdef USE_LOCALE
-#include "locale.h"
+#include <locale.h>
+#include "setlocale_local.h"
#endif
#ifdef IEEE_Arith
@@ -62,6 +64,8 @@
#ifndef __HAVE_LONG_DOUBLE
__strong_alias(_strtold, strtod)
__weak_alias(strtold, _strtold)
+__strong_alias(_strtold_l, strtod_l)
+__weak_alias(strtold_l, _strtold_l)
#endif
#ifdef Avoid_Underflow /*{*/
@@ -86,13 +90,8 @@
}
#endif /*}*/
- double
-strtod
-#ifdef KR_headers
- (s00, se) CONST char *s00; char **se;
-#else
- (CONST char *s00, char **se)
-#endif
+static double
+_int_strtod_l(CONST char *s00, char **se, locale_t loc)
{
#ifdef Avoid_Underflow
int scale;
@@ -116,25 +115,8 @@
int inexact, oldinexact;
#endif
#ifdef USE_LOCALE /*{{*/
-#ifdef NO_LOCALE_CACHE
- char *decimalpoint = localeconv()->decimal_point;
+ char *decimalpoint = localeconv_l(loc)->decimal_point;
size_t dplen = strlen(decimalpoint);
-#else
- char *decimalpoint;
- static char *decimalpoint_cache;
- static size_t dplen;
- if (!(s0 = decimalpoint_cache)) {
- s0 = localeconv()->decimal_point;
- if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) {
- strcpy(decimalpoint_cache, s0);
- s0 = decimalpoint_cache;
- }
- dplen = strlen(s0);
- }
- decimalpoint = __UNCONST(s0);
-#endif /*NO_LOCALE_CACHE*/
-#else /*USE_LOCALE}{*/
-#define dplen 1
#endif /*USE_LOCALE}}*/
#ifdef Honor_FLT_ROUNDS /*{*/
@@ -1118,3 +1100,20 @@
return sign ? -dval(&rv) : dval(&rv);
}
+double
+strtod(CONST char *s, char **sp)
+{
+ return _int_strtod_l(s, sp, *_current_locale());
+}
+
+#ifdef __weak_alias
+__weak_alias(strtod_l, _strtod_l)
+#endif
+
+double
+strtod_l(CONST char *s, char **sp, locale_t loc)
+{
+ if (loc == NULL)
+ loc = _C_locale;
+ return _int_strtod_l(s, sp, loc);
+}
diff -r 792badd52480 -r fd2689ca6aa1 lib/libc/gdtoa/strtodg.c
--- a/lib/libc/gdtoa/strtodg.c Thu Apr 18 21:53:55 2013 +0000
+++ b/lib/libc/gdtoa/strtodg.c Thu Apr 18 21:54:10 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strtodg.c,v 1.10 2012/03/22 13:09:12 he Exp $ */
+/* $NetBSD: strtodg.c,v 1.11 2013/04/18 21:54:10 joerg Exp $ */
/****************************************************************
@@ -319,13 +319,8 @@
#endif /* !VAX */
int
-strtodg
-#ifdef KR_headers
- (s00, se, fpi, expt, bits)
- CONST char *s00; char **se; CONST FPI *fpi; Long *expt; ULong *bits;
-#else
- (CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits)
-#endif
+strtodg(CONST char *s00, char **se, CONST FPI *fpi, Long *expt, ULong *bits,
+ locale_t loc)
{
int abe, abits, asub;
#ifdef INFNAN_CHECK
@@ -342,25 +337,8 @@
ULong *b, *be, y, z;
Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;
#ifdef USE_LOCALE /*{{*/
-#ifdef NO_LOCALE_CACHE
- char *decimalpoint = localeconv()->decimal_point;
+ char *decimalpoint = localeconv_l(loc)->decimal_point;
size_t dplen = strlen(decimalpoint);
-#else
- char *decimalpoint;
- static char *decimalpoint_cache;
- static size_t dplen;
- if (!(s0 = decimalpoint_cache)) {
- s0 = localeconv()->decimal_point;
- if ((decimalpoint_cache = MALLOC(strlen(s0) + 1)) != NULL) {
- strcpy(decimalpoint_cache, s0);
- s0 = decimalpoint_cache;
- }
- dplen = strlen(s0);
- }
- decimalpoint = __UNCONST(s0);
-#endif /*NO_LOCALE_CACHE*/
-#else /*USE_LOCALE}{*/
-#define dplen 1
#endif /*USE_LOCALE}}*/
e2 = 0; /* XXX gcc */
diff -r 792badd52480 -r fd2689ca6aa1 lib/libc/gdtoa/strtof.c
--- a/lib/libc/gdtoa/strtof.c Thu Apr 18 21:53:55 2013 +0000
+++ b/lib/libc/gdtoa/strtof.c Thu Apr 18 21:54:10 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: strtof.c,v 1.5 2011/06/20 09:11:17 mrg Exp $ */
+/* $NetBSD: strtof.c,v 1.6 2013/04/18 21:54:11 joerg Exp $ */
/****************************************************************
@@ -34,16 +34,16 @@
#include "namespace.h"
#include "gdtoaimp.h"
+#include <locale.h>
+#include "setlocale_local.h"
+
#ifdef __weak_alias
__weak_alias(strtof, _strtof)
+__weak_alias(strtof_l, _strtof_l)
#endif
- float
-#ifdef KR_headers
-strtof(s, sp) CONST char *s; char **sp;
-#else
-strtof(CONST char *s, char **sp)
-#endif
+static float
+_int_strtof_l(CONST char *s, char **sp, locale_t loc)
{
static CONST FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
ULong bits[1];
@@ -56,7 +56,7 @@
#define fpi &fpi0
#endif
Home |
Main Index |
Thread Index |
Old Index