CVS commit: [netbsd-7] src/lib/libc/stdlib

2017-09-04 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Mon Sep  4 06:21:45 UTC 2017

Modified Files:
src/lib/libc/stdlib [netbsd-7]: merge.c

Log Message:
Pull up following revision(s) (requested by ginsbach in ticket #1495):
lib/libc/stdlib/merge.c: revision 1.15
PR lib/50316: Gracefully handle a zero number of members argument.
Taken from FreeBSD (which fixed this same issue long ago).


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.14.10.1 src/lib/libc/stdlib/merge.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/merge.c
diff -u src/lib/libc/stdlib/merge.c:1.14 src/lib/libc/stdlib/merge.c:1.14.10.1
--- src/lib/libc/stdlib/merge.c:1.14	Tue Mar 13 21:13:48 2012
+++ src/lib/libc/stdlib/merge.c	Mon Sep  4 06:21:45 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $	*/
+/*	$NetBSD: merge.c,v 1.14.10.1 2017/09/04 06:21:45 snj Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "from: @(#)merge.c	8.2 (Berkeley) 2/14/94";
 #else
-__RCSID("$NetBSD: merge.c,v 1.14 2012/03/13 21:13:48 christos Exp $");
+__RCSID("$NetBSD: merge.c,v 1.14.10.1 2017/09/04 06:21:45 snj Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -125,6 +125,9 @@ mergesort(void *base, size_t nmemb, size
 		return (-1);
 	}
 
+	if (nmemb == 0)
+		return (0);
+
 	/*
 	 * XXX
 	 * Stupid subtraction for the Cray.



CVS commit: [netbsd-7] src/lib/libc/stdlib

2016-12-17 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sun Dec 18 06:31:01 UTC 2016

Modified Files:
src/lib/libc/stdlib [netbsd-7]: strtod.3 strtol.3 strtoul.3

Log Message:
Pull up following revision(s) (requested by riastradh in ticket #1311):
lib/libc/stdlib/strtod.3: revisions 1.21-1.29
lib/libc/stdlib/strtol.3: revision 1.36-1.38
lib/libc/stdlib/strtoul.3: revision 1.36
strtod yields ERANGE for below-subnormal magnitudes, not underflow.
For a floating-point computation, in the language of IEEE 754,
`underflow' means the output was rounded and is too small to be
represented *normally*.
There are many nonzero floating-point numbers to which the exact
output may have been rounded -- namely subnormals.  The condition
under which strtod returns ERANGE for small magnitudes is when the
magnitude of the exact result is so small it is rounded to zero, not
even to a subnormal.
While here, use parallel language about large magnitudes instead of
the (albeit correct) word `overflow', to avoid temptation to treat
`underflow' as the opposite notion with zero instead of infinity.
--
Bump date for previous.
--
Fix description of ERANGE cases again.
Do use the technical terms `overflow' and `underflow', because strtod
sets ERANGE precisely to indicate either of these two conditions, and
they are the right keywords that one might be looking for.
Note that strtod may set ERANGE even if it returns noninfinity and
nonzero -- specifically, if the result is subnormal.  This part was
wrong before I `fixed' it and remained wrong after I `fixed' it
earlier this year.
--
Add example for strtod.
This illustrates all the cases you might be interested in and asserts
theorems in those cases.
--
Fix infinity detection with isinf(d), not d == HUGE_VAL.
Negative infinity counts as overflow too.
Simplify.
--
EXIT_FAILURE police
--
Distinguish altogether invalid syntax from trailing garbage.
--
Distinguish invalid syntax from trailing garbage cases.  Clarify.
--
Simplify error condition case.
Add assertions to reflect its implications.
--
Tidy up the second example too.
--
Update strtoul(3) example to reflect clarifications in strtol(3).
--
Fix phrasing about `out-of-band' and `sentinel value'.
Either an out-of-band channel, or an in-band sentinel value, could
indicate an error, but an out-of-band sentinel value is a silly
proposition.
Noted by uwe@.
--
Use the keywords `underflow' and `overflow' in ERANGE summary.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.20.50.1 src/lib/libc/stdlib/strtod.3
cvs rdiff -u -r1.26.24.2 -r1.26.24.3 src/lib/libc/stdlib/strtol.3
cvs rdiff -u -r1.25.24.2 -r1.25.24.3 src/lib/libc/stdlib/strtoul.3

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/strtod.3
diff -u src/lib/libc/stdlib/strtod.3:1.20 src/lib/libc/stdlib/strtod.3:1.20.50.1
--- src/lib/libc/stdlib/strtod.3:1.20	Wed Oct 24 13:42:10 2007
+++ src/lib/libc/stdlib/strtod.3	Sun Dec 18 06:31:01 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: strtod.3,v 1.20 2007/10/24 13:42:10 reed Exp $
+.\"	$NetBSD: strtod.3,v 1.20.50.1 2016/12/18 06:31:01 snj Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -33,7 +33,7 @@
 .\"
 .\" from: @(#)strtod.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd March 12, 2006
+.Dd November 4, 2016
 .Dt STRTOD 3
 .Os
 .Sh NAME
@@ -151,7 +151,9 @@ If no conversion is performed, zero is r
 is stored in the location referenced by
 .Fa endptr .
 .Pp
-If the correct value would cause overflow, plus or minus
+If the correct value is too large in magnitude to be represented
+.Pq Sq overflow ,
+plus or minus
 .Dv HUGE_VAL ,
 .Dv HUGE_VALF ,
 or
@@ -160,15 +162,58 @@ is returned (according to the return typ
 .Dv ERANGE
 is stored in
 .Va errno .
-If the correct value would cause underflow, zero is
-returned and
+.Pp
+If the correct value is too small in magnitude to be represented
+normally with full precision
+.Pq Sq underflow ,
+the closest subnormal value, or zero, is returned, and
 .Dv ERANGE
 is stored in
 .Va errno .
+.Sh EXAMPLES
+Since there is no out-of-band channel or sentinel value to indicate an
+error, callers who wish to know whether there was overflow or underflow
+must set
+.Va errno
+to zero before calling
+.Fn strtod ,
+.Fn strtof ,
+or
+.Fn strtold ;
+in the case of no underflow or overflow, these functions preserve
+.Va errno .
+.Pp
+To check for syntax errors, callers must
+.Em also
+check whether
+.Fa endptr
+was updated to reflect the true end of the string in order to determine
+whether the full string was consumed or whether there were additional
+erroneous characters in it.
+.Bd -literal -offset abcd
+char *end;
+double d;
+
+\&...
+
+errno = 0;
+d = strtod(s, );
+if (end == s)
+	errx(EXIT_FAILURE, "invalid syntax");
+if (end[0] != '\e0')
+	errx(EXIT_FAILURE, "trailing garbage");
+if (errno) {
+	assert(errno == 

CVS commit: [netbsd-7] src/lib/libc/stdlib

2016-05-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 10 09:10:11 UTC 2016

Modified Files:
src/lib/libc/stdlib [netbsd-7]: jemalloc.c

Log Message:
Fix merge botch for #1161


To generate a diff of this commit:
cvs rdiff -u -r1.34.2.2 -r1.34.2.3 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.34.2.2 src/lib/libc/stdlib/jemalloc.c:1.34.2.3
--- src/lib/libc/stdlib/jemalloc.c:1.34.2.2	Mon May  9 19:34:50 2016
+++ src/lib/libc/stdlib/jemalloc.c	Tue May 10 09:10:11 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.34.2.2 2016/05/09 19:34:50 snj Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.34.2.3 2016/05/10 09:10:11 martin Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.34.2.2 2016/05/09 19:34:50 snj Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.34.2.3 2016/05/10 09:10:11 martin Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -1651,6 +1651,11 @@ arena_chunk_comp(arena_chunk_t *a, arena
 	assert(a != NULL);
 	assert(b != NULL);
 
+	if (a->max_frun_npages < b->max_frun_npages)
+		return -1;
+	if (a->max_frun_npages > b->max_frun_npages)
+		return 1;
+
 	if ((uintptr_t)a < (uintptr_t)b)
 		return (-1);
 	else if (a == b)
@@ -1671,11 +1676,6 @@ arena_run_comp(arena_run_t *a, arena_run
 	assert(a != NULL);
 	assert(b != NULL);
 
-	if (a->max_frun_npages < b->max_frun_npages)
-		return -1;
-	if (a->max_frun_npages > b->max_frun_npages)
-		return 1;
-
 	if ((uintptr_t)a < (uintptr_t)b)
 		return (-1);
 	else if (a == b)



CVS commit: [netbsd-7] src/lib/libc/stdlib

2016-05-09 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Mon May  9 19:34:50 UTC 2016

Modified Files:
src/lib/libc/stdlib [netbsd-7]: jemalloc.c

Log Message:
Pull up following revision(s) (requested by joerg in ticket #1161):
lib/libc/stdlib/jemalloc.c: revision 1.40
lib/50791: Instead of using sorting the arena chunks by address only,
sort by size of the longest run and address as tie break. Avoids long
linear searches for code heavy on medium sized allocations.


To generate a diff of this commit:
cvs rdiff -u -r1.34.2.1 -r1.34.2.2 src/lib/libc/stdlib/jemalloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/jemalloc.c
diff -u src/lib/libc/stdlib/jemalloc.c:1.34.2.1 src/lib/libc/stdlib/jemalloc.c:1.34.2.2
--- src/lib/libc/stdlib/jemalloc.c:1.34.2.1	Tue Nov 24 17:37:16 2015
+++ src/lib/libc/stdlib/jemalloc.c	Mon May  9 19:34:50 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: jemalloc.c,v 1.34.2.1 2015/11/24 17:37:16 martin Exp $	*/
+/*	$NetBSD: jemalloc.c,v 1.34.2.2 2016/05/09 19:34:50 snj Exp $	*/
 
 /*-
  * Copyright (C) 2006,2007 Jason Evans .
@@ -118,7 +118,7 @@
 
 #include 
 /* __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.147 2007/06/15 22:00:16 jasone Exp $"); */ 
-__RCSID("$NetBSD: jemalloc.c,v 1.34.2.1 2015/11/24 17:37:16 martin Exp $");
+__RCSID("$NetBSD: jemalloc.c,v 1.34.2.2 2016/05/09 19:34:50 snj Exp $");
 
 #ifdef __FreeBSD__
 #include "libc_private.h"
@@ -1671,6 +1671,11 @@ arena_run_comp(arena_run_t *a, arena_run
 	assert(a != NULL);
 	assert(b != NULL);
 
+	if (a->max_frun_npages < b->max_frun_npages)
+		return -1;
+	if (a->max_frun_npages > b->max_frun_npages)
+		return 1;
+
 	if ((uintptr_t)a < (uintptr_t)b)
 		return (-1);
 	else if (a == b)
@@ -1902,9 +1907,6 @@ arena_chunk_alloc(arena_t *arena)
 
 		chunk->arena = arena;
 
-		/* LINTED */
-		RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
-
 		/*
 		 * Claim that no pages are in use, since the header is merely
 		 * overhead.
@@ -1924,6 +1926,8 @@ arena_chunk_alloc(arena_t *arena)
 		chunk->map[chunk_npages - 1].npages = chunk_npages -
 		arena_chunk_header_npages;
 		chunk->map[chunk_npages - 1].pos = POS_FREE;
+
+		RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
 	}
 
 	return (chunk);
@@ -1960,30 +1964,44 @@ arena_chunk_dealloc(arena_t *arena, aren
 static arena_run_t *
 arena_run_alloc(arena_t *arena, size_t size)
 {
-	arena_chunk_t *chunk;
+	arena_chunk_t *chunk, *chunk_tmp;
 	arena_run_t *run;
-	unsigned need_npages, limit_pages, compl_need_npages;
+	unsigned need_npages;
 
 	assert(size <= (chunksize - (arena_chunk_header_npages <<
 	pagesize_2pow)));
 	assert((size & pagesize_mask) == 0);
 
 	/*
-	 * Search through arena's chunks in address order for a free run that is
-	 * large enough.  Look for the first fit.
+	 * Search through the arena chunk tree for a large enough free run.
+	 * Tree order ensures that any exact fit is picked immediately or
+	 * otherwise the lowest address of the next size.
 	 */
 	need_npages = (unsigned)(size >> pagesize_2pow);
-	limit_pages = chunk_npages - arena_chunk_header_npages;
-	compl_need_npages = limit_pages - need_npages;
 	/* LINTED */
-	RB_FOREACH(chunk, arena_chunk_tree_s, >chunks) {
+	for (;;) {
+		chunk_tmp = RB_ROOT(>chunks);
+		chunk = NULL;
+		while (chunk_tmp) {
+			if (chunk_tmp->max_frun_npages == need_npages) {
+chunk = chunk_tmp;
+break;
+			}
+			if (chunk_tmp->max_frun_npages < need_npages) {
+chunk_tmp = RB_RIGHT(chunk_tmp, link);
+continue;
+			}
+			chunk = chunk_tmp;
+			chunk_tmp = RB_LEFT(chunk, link);
+		}
+		if (chunk == NULL)
+			break;
 		/*
-		 * Avoid searching this chunk if there are not enough
-		 * contiguous free pages for there to possibly be a large
-		 * enough free run.
+		 * At this point, the chunk must have a cached run size large
+		 * enough to fit the allocation.
 		 */
-		if (chunk->pages_used <= compl_need_npages &&
-		need_npages <= chunk->max_frun_npages) {
+		assert(need_npages <= chunk->max_frun_npages);
+		{
 			arena_chunk_map_t *mapelm;
 			unsigned i;
 			unsigned max_frun_npages = 0;
@@ -2021,7 +2039,9 @@ arena_run_alloc(arena_t *arena, size_t s
 			 * chunk->min_frun_ind was already reset above (if
 			 * necessary).
 			 */
+			RB_REMOVE(arena_chunk_tree_s, >chunks, chunk);
 			chunk->max_frun_npages = max_frun_npages;
+			RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
 		}
 	}
 
@@ -2104,8 +2124,11 @@ arena_run_dalloc(arena_t *arena, arena_r
 		assert(chunk->map[run_ind + run_pages - 1].pos == POS_FREE);
 	}
 
-	if (chunk->map[run_ind].npages > chunk->max_frun_npages)
+	if (chunk->map[run_ind].npages > chunk->max_frun_npages) {
+		RB_REMOVE(arena_chunk_tree_s, >chunks, chunk);
 		chunk->max_frun_npages = chunk->map[run_ind].npages;
+		RB_INSERT(arena_chunk_tree_s, >chunks, chunk);
+	}
 	if (run_ind < chunk->min_frun_ind)
 		chunk->min_frun_ind = run_ind;
 



CVS commit: [netbsd-7] src/lib/libc/stdlib

2015-04-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Apr 19 05:03:02 UTC 2015

Modified Files:
src/lib/libc/stdlib [netbsd-7]: atexit.c

Log Message:
Pull up following revision(s) (requested by joerg in ticket #708):
lib/libc/stdlib/atexit.c: revision 1.28
Add __aeabi_atexit alias for another case of NIH on ARM.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.26.4.1 src/lib/libc/stdlib/atexit.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/atexit.c
diff -u src/lib/libc/stdlib/atexit.c:1.26 src/lib/libc/stdlib/atexit.c:1.26.4.1
--- src/lib/libc/stdlib/atexit.c:1.26	Mon Aug 19 22:14:37 2013
+++ src/lib/libc/stdlib/atexit.c	Sun Apr 19 05:03:02 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: atexit.c,v 1.26 2013/08/19 22:14:37 matt Exp $	*/
+/*	$NetBSD: atexit.c,v 1.26.4.1 2015/04/19 05:03:02 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if defined(LIBC_SCCS)  !defined(lint)
-__RCSID($NetBSD: atexit.c,v 1.26 2013/08/19 22:14:37 matt Exp $);
+__RCSID($NetBSD: atexit.c,v 1.26.4.1 2015/04/19 05:03:02 msaitoh Exp $);
 #endif /* LIBC_SCCS and not lint */
 
 #include reentrant.h
@@ -133,6 +133,10 @@ __libc_atexit_init(void)
  *
  *	http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor
  */
+#if defined(__ARM_EABI__)  !defined(lint)
+__strong_alias(__aeabi_atexit,__cxa_atexit);
+#endif
+
 int
 __cxa_atexit(void (*func)(void *), void *arg, void *dso)
 {