CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Sun Aug 18 18:47:20 UTC 2024 Modified Files: src/lib/libc/stdlib: aligned_alloc.c Log Message: aligned_alloc(3): Nix trailing whitespace. Add RCS id. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/aligned_alloc.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/aligned_alloc.c diff -u src/lib/libc/stdlib/aligned_alloc.c:1.2 src/lib/libc/stdlib/aligned_alloc.c:1.3 --- src/lib/libc/stdlib/aligned_alloc.c:1.2 Fri Jul 27 13:08:47 2018 +++ src/lib/libc/stdlib/aligned_alloc.c Sun Aug 18 18:47:20 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: aligned_alloc.c,v 1.2 2018/07/27 13:08:47 maya Exp $ */ +/* $NetBSD: aligned_alloc.c,v 1.3 2024/08/18 18:47:20 riastradh Exp $ */ /*- * Copyright (C) 2015 The NetBSD Foundation, Inc. @@ -32,6 +32,9 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +__RCSID("$NetBSD: aligned_alloc.c,v 1.3 2024/08/18 18:47:20 riastradh Exp $"); + #include #include @@ -40,7 +43,7 @@ aligned_alloc(size_t alignment, size_t s { void *memptr; int err; - + /* * Check that alignment is a power of 2. */ @@ -48,7 +51,7 @@ aligned_alloc(size_t alignment, size_t s errno = EINVAL; return NULL; } - + /* * Adjust alignment to satisfy posix_memalign, * larger alignments satisfy smaller alignments. @@ -56,13 +59,12 @@ aligned_alloc(size_t alignment, size_t s while (alignment < sizeof(void *)) { alignment <<= 1; } - + err = posix_memalign(, alignment, size); - if (err) { errno = err; return NULL; } - + return memptr; }
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Sun Aug 18 18:47:20 UTC 2024 Modified Files: src/lib/libc/stdlib: aligned_alloc.c Log Message: aligned_alloc(3): Nix trailing whitespace. Add RCS id. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/aligned_alloc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Sat Jan 27 17:58:36 UTC 2024 Modified Files: src/lib/libc/stdlib: Makefile.inc Log Message: fix i386 lint To generate a diff of this commit: cvs rdiff -u -r1.97 -r1.98 src/lib/libc/stdlib/Makefile.inc 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/Makefile.inc diff -u src/lib/libc/stdlib/Makefile.inc:1.97 src/lib/libc/stdlib/Makefile.inc:1.98 --- src/lib/libc/stdlib/Makefile.inc:1.97 Sat Jan 20 11:45:07 2024 +++ src/lib/libc/stdlib/Makefile.inc Sat Jan 27 12:58:36 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.97 2024/01/20 16:45:07 christos Exp $ +# $NetBSD: Makefile.inc,v 1.98 2024/01/27 17:58:36 christos Exp $ # from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # stdlib sources @@ -120,10 +120,12 @@ LINTFLAGS.extent.c += -X 86,161,117,191, LINTFLAGS.extent_dss.c += -X 86,117,161,191,193,207,217,226 LINTFLAGS.extent_mmap.c += -X 86,117,161,191,193,207,217,226 LINTFLAGS.jemalloc.c += -X 86,117,161,191,193,207,217,226,236,307 +LINTFLAGS.jemalloc.c += -X 141 # i386 LINTFLAGS.hooks.c += -X 226 LINTFLAGS.large.c += -X 86,161,117,191,193,207,217,226 LINTFLAGS.log.c += -X 86,117,161,191,193,207,217,226 LINTFLAGS.malloc_io.c += -X 86,117,161,191,193,207,217,226,284 +LINTFLAGS.malloc_io.c += -X 132 # i386 LINTFLAGS.mutex.c += -X 86,117,161,191,193,207,217,226 LINTFLAGS.mutex_pool.c += -X 86,117,161,191,193,207,217,226 LINTFLAGS.nstime.c += -X 86,117,161,191,193,207,217,226
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Sat Jan 27 17:58:36 UTC 2024 Modified Files: src/lib/libc/stdlib: Makefile.inc Log Message: fix i386 lint To generate a diff of this commit: cvs rdiff -u -r1.97 -r1.98 src/lib/libc/stdlib/Makefile.inc Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Sat Jan 20 16:45:07 UTC 2024 Modified Files: src/lib/libc/stdlib: Makefile.inc strtoi.3 Removed Files: src/lib/libc/stdlib: strtou.3 Log Message: generate strtou.3 from strtoi.3, grammar police To generate a diff of this commit: cvs rdiff -u -r1.96 -r1.97 src/lib/libc/stdlib/Makefile.inc cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdlib/strtoi.3 cvs rdiff -u -r1.8 -r0 src/lib/libc/stdlib/strtou.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Sat Jan 20 16:45:07 UTC 2024 Modified Files: src/lib/libc/stdlib: Makefile.inc strtoi.3 Removed Files: src/lib/libc/stdlib: strtou.3 Log Message: generate strtou.3 from strtoi.3, grammar police To generate a diff of this commit: cvs rdiff -u -r1.96 -r1.97 src/lib/libc/stdlib/Makefile.inc cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdlib/strtoi.3 cvs rdiff -u -r1.8 -r0 src/lib/libc/stdlib/strtou.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/Makefile.inc diff -u src/lib/libc/stdlib/Makefile.inc:1.96 src/lib/libc/stdlib/Makefile.inc:1.97 --- src/lib/libc/stdlib/Makefile.inc:1.96 Fri Jan 19 13:41:30 2024 +++ src/lib/libc/stdlib/Makefile.inc Sat Jan 20 11:45:07 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.96 2024/01/19 18:41:30 christos Exp $ +# $NetBSD: Makefile.inc,v 1.97 2024/01/20 16:45:07 christos Exp $ # from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # stdlib sources @@ -62,6 +62,12 @@ MAN+= a64l.3 abort.3 abs.3 alloca.3 atex tsearch.3 \ unlockpt.3 +strtou.3: strtoi.3 + ${_MKTARGET_CREATE} + ${TOOL_SED} -e s/strtoi/strtou/g -e s/STRTOI/STRTOU/g \ + -e s/intmax_t/uintmax_t/g -e s/%jd/%ju/g ${.ALLSRC} > ${.TARGET} +CLEANFILES += strtou.3 + MLINKS+=a64l.3 l64a.3 MLINKS+=a64l.3 l64a_r.3 MLINKS+=abs.3 labs.3 \ Index: src/lib/libc/stdlib/strtoi.3 diff -u src/lib/libc/stdlib/strtoi.3:1.8 src/lib/libc/stdlib/strtoi.3:1.9 --- src/lib/libc/stdlib/strtoi.3:1.8 Sat Jan 20 11:13:39 2024 +++ src/lib/libc/stdlib/strtoi.3 Sat Jan 20 11:45:07 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: strtoi.3,v 1.8 2024/01/20 16:13:39 christos Exp $ +.\" $NetBSD: strtoi.3,v 1.9 2024/01/20 16:45:07 christos Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -202,7 +202,7 @@ or the range given was invalid, i.e. .Fa hi . .El .Pp -The range check is important than the unconverted characters check, +The range check is more important than the unconverted characters check, and it is performed first. If a program needs to know if there were unconverted characters when an out of range number has been provided, it needs to supply and test
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Fri Jan 19 18:41:38 UTC 2024 Modified Files: src/lib/libc/stdlib: getopt.c getopt_long.c Log Message: add some const To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/lib/libc/stdlib/getopt.c cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdlib/getopt_long.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/getopt.c diff -u src/lib/libc/stdlib/getopt.c:1.29 src/lib/libc/stdlib/getopt.c:1.30 --- src/lib/libc/stdlib/getopt.c:1.29 Thu Jun 5 18:00:22 2014 +++ src/lib/libc/stdlib/getopt.c Fri Jan 19 13:41:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ +/* $NetBSD: getopt.c,v 1.30 2024/01/19 18:41:38 christos Exp $ */ /* * Copyright (c) 1987, 1993, 1994 @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $"); +__RCSID("$NetBSD: getopt.c,v 1.30 2024/01/19 18:41:38 christos Exp $"); #include "namespace.h" @@ -63,7 +63,7 @@ int getopt(int nargc, char * const nargv[], const char *ostr) { static const char *place = EMSG; /* option letter processing */ - char *oli;/* option letter list index */ + const char *oli; /* option letter list index */ _DIAGASSERT(nargv != NULL); _DIAGASSERT(ostr != NULL); Index: src/lib/libc/stdlib/getopt_long.c diff -u src/lib/libc/stdlib/getopt_long.c:1.27 src/lib/libc/stdlib/getopt_long.c:1.28 --- src/lib/libc/stdlib/getopt_long.c:1.27 Tue Sep 1 15:39:57 2015 +++ src/lib/libc/stdlib/getopt_long.c Fri Jan 19 13:41:38 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: getopt_long.c,v 1.27 2015/09/01 19:39:57 kamil Exp $ */ +/* $NetBSD: getopt_long.c,v 1.28 2024/01/19 18:41:38 christos Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: getopt_long.c,v 1.27 2015/09/01 19:39:57 kamil Exp $"); +__RCSID("$NetBSD: getopt_long.c,v 1.28 2024/01/19 18:41:38 christos Exp $"); #include "namespace.h" @@ -167,7 +167,7 @@ permute_args(int panonopt_start, int pan static int getopt_internal(int nargc, char **nargv, const char *options) { - char *oli;/* option letter list index */ + const char *oli; /* option letter list index */ int optchar; _DIAGASSERT(nargv != NULL);
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Fri Jan 19 18:41:30 UTC 2024 Modified Files: src/lib/libc/stdlib: Makefile.inc Log Message: Add lint flags for jemalloc To generate a diff of this commit: cvs rdiff -u -r1.95 -r1.96 src/lib/libc/stdlib/Makefile.inc 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/Makefile.inc diff -u src/lib/libc/stdlib/Makefile.inc:1.95 src/lib/libc/stdlib/Makefile.inc:1.96 --- src/lib/libc/stdlib/Makefile.inc:1.95 Mon Mar 4 12:30:33 2019 +++ src/lib/libc/stdlib/Makefile.inc Fri Jan 19 13:41:30 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.95 2019/03/04 17:30:33 christos Exp $ +# $NetBSD: Makefile.inc,v 1.96 2024/01/19 18:41:30 christos Exp $ # from: @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # stdlib sources @@ -99,3 +99,35 @@ MLINKS+=strtoul.3 strtoull.3 MLINKS+=strtoul.3 strtoumax.3 MLINKS+=strtoul.3 strtouq.3 MLINKS+=tsearch.3 tfind.3 tsearch.3 twalk.3 tsearch.3 tdelete.3 + +# jemalloc +LINTFLAGS.arena.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.background_thread.c += -X 86,117,132,161,191,193,207,217,226 +LINTFLAGS.base.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.bin.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.bitmap.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.chk.c += -X 191,193,217,226,239 +LINTFLAGS.ckh.c += -X 86,117,161,191,193,207,217,226,239,284 +LINTFLAGS.ctl.c += -X 86,117,135,161,193,191,207,217,226 +LINTFLAGS.divide.c += -X 226 +LINTFLAGS.extent.c += -X 86,161,117,191,193,207,217,226 +LINTFLAGS.extent_dss.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.extent_mmap.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.jemalloc.c += -X 86,117,161,191,193,207,217,226,236,307 +LINTFLAGS.hooks.c += -X 226 +LINTFLAGS.large.c += -X 86,161,117,191,193,207,217,226 +LINTFLAGS.log.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.malloc_io.c += -X 86,117,161,191,193,207,217,226,284 +LINTFLAGS.mutex.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.mutex_pool.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.nstime.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.pages.c += -X 86,117,161,191,193,207,217,226,298 +LINTFLAGS.prng.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.prof.c += -X 86,117,161,181,191,193,207,217,226,236 +LINTFLAGS.rtree.c += -X 86,117,161,191,193,207,217,226,239 +LINTFLAGS.sz.c += -X 86,226 +LINTFLAGS.stats.c += -X 42,86,117,135,161,191,193,207,217,226,247,351 +LINTFLAGS.tcache.c += -X 86,117,161,191,193,207,217,226,239,309 +LINTFLAGS.ticker.c += -X 86,117,161,191,193,207,217,226 +LINTFLAGS.tsd.c += -X 86,117,161,191,193,207,217,226,346,351 +LINTFLAGS.witness.c += -X 86,117,161,191,193,207,217,226
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Fri Jan 19 18:41:38 UTC 2024 Modified Files: src/lib/libc/stdlib: getopt.c getopt_long.c Log Message: add some const To generate a diff of this commit: cvs rdiff -u -r1.29 -r1.30 src/lib/libc/stdlib/getopt.c cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdlib/getopt_long.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Fri Jan 19 18:41:30 UTC 2024 Modified Files: src/lib/libc/stdlib: Makefile.inc Log Message: Add lint flags for jemalloc To generate a diff of this commit: cvs rdiff -u -r1.95 -r1.96 src/lib/libc/stdlib/Makefile.inc Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: mrg Date: Wed Dec 13 23:53:50 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: make malloc_usable_size() visible with old jemalloc. it's in and applications like firefox expect it. XXX: pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 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.63 src/lib/libc/stdlib/jemalloc.c:1.64 --- src/lib/libc/stdlib/jemalloc.c:1.63 Sat Oct 14 19:39:33 2023 +++ src/lib/libc/stdlib/jemalloc.c Wed Dec 13 23:53:50 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.63 2023/10/14 19:39:33 ad Exp $ */ +/* $NetBSD: jemalloc.c,v 1.64 2023/12/13 23:53:50 mrg Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -111,7 +111,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.63 2023/10/14 19:39:33 ad Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.64 2023/12/13 23:53:50 mrg Exp $"); #include "namespace.h" #include @@ -135,6 +135,7 @@ __RCSID("$NetBSD: jemalloc.c,v 1.63 2023 #include #include #include +#include #include #include "extern.h" @@ -3784,7 +3785,6 @@ free(void *ptr) /* * Begin non-standard functions. */ -#ifndef __NetBSD__ size_t malloc_usable_size(const void *ptr) { @@ -3793,7 +3793,6 @@ malloc_usable_size(const void *ptr) return (isalloc(ptr)); } -#endif /* * End non-standard functions.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: mrg Date: Wed Dec 13 23:53:50 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: make malloc_usable_size() visible with old jemalloc. it's in and applications like firefox expect it. XXX: pullup-10 To generate a diff of this commit: cvs rdiff -u -r1.63 -r1.64 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Mon Nov 27 19:46:14 UTC 2023 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: Restore original code now that the broken test has been fixed. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdlib/strfmon.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/strfmon.c diff -u src/lib/libc/stdlib/strfmon.c:1.20 src/lib/libc/stdlib/strfmon.c:1.21 --- src/lib/libc/stdlib/strfmon.c:1.20 Sun Nov 19 13:57:11 2023 +++ src/lib/libc/stdlib/strfmon.c Mon Nov 27 14:46:14 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: strfmon.c,v 1.20 2023/11/19 18:57:11 christos Exp $ */ +/* $NetBSD: strfmon.c,v 1.21 2023/11/27 19:46:14 christos Exp $ */ /*- * Copyright (c) 2001 Alexey Zelkin @@ -32,7 +32,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); #else -__RCSID("$NetBSD: strfmon.c,v 1.20 2023/11/19 18:57:11 christos Exp $"); +__RCSID("$NetBSD: strfmon.c,v 1.21 2023/11/27 19:46:14 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -387,10 +387,8 @@ vstrfmon_l(char * __restrict s, size_t m if (sign_posn == 0) { if (flags & IS_NEGATIVE) PRINT(')'); -#if 0 else if (left_prec >= 0) PRINT(' '); -#endif } if (dst - tmpptr < width) {
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Mon Nov 27 19:46:14 UTC 2023 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: Restore original code now that the broken test has been fixed. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdlib/strfmon.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Sun Nov 19 18:57:11 UTC 2023 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: minimize diffs with FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdlib/strfmon.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/strfmon.c diff -u src/lib/libc/stdlib/strfmon.c:1.19 src/lib/libc/stdlib/strfmon.c:1.20 --- src/lib/libc/stdlib/strfmon.c:1.19 Thu Sep 28 06:03:41 2023 +++ src/lib/libc/stdlib/strfmon.c Sun Nov 19 13:57:11 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: strfmon.c,v 1.19 2023/09/28 10:03:41 martin Exp $ */ +/* $NetBSD: strfmon.c,v 1.20 2023/11/19 18:57:11 christos Exp $ */ /*- * Copyright (c) 2001 Alexey Zelkin @@ -32,7 +32,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); #else -__RCSID("$NetBSD: strfmon.c,v 1.19 2023/09/28 10:03:41 martin Exp $"); +__RCSID("$NetBSD: strfmon.c,v 1.20 2023/11/19 18:57:11 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -61,53 +61,53 @@ __RCSID("$NetBSD: strfmon.c,v 1.19 2023/ #define SUPPRESS_CURR_SYMBOL 0x10 /* suppress the currency from output */ #define LEFT_JUSTIFY 0x20 /* left justify */ #define USE_INTL_CURRENCY 0x40 /* use international currency symbol */ -#define IS_NEGATIVE 0x80 /* is argument value negative ? */ - -#ifndef NBCHAR_MAX -#define NBCHAR_MAX ((unsigned char)CHAR_MAX) -#endif +#define IS_NEGATIVE 0x80 /* is argument value negative ? */ /* internal macros */ -#define PRINT(CH) do { \ +#define PRINT(CH) do { \ if (dst >= s + maxsize) \ goto e2big_error;\ *dst++ = CH; \ } while (0) -#define PRINTS(STR) do { \ +#define PRINTS(STR) do { \ const char *tmps = STR; \ while (*tmps != '\0') \ PRINT(*tmps++); \ } while (0) -#define GET_NUMBER(VAR) do { \ +#define GET_NUMBER(VAR, LOC) do {\ VAR = 0; \ - while (isdigit((unsigned char)*fmt)) { \ + while (isdigit_l((unsigned char)*fmt, LOC)) { \ + if (VAR > INT_MAX / 10)\ + goto e2big_error; \ VAR *= 10; \ VAR += *fmt - '0';\ - if (VAR > 0x00ff)\ + if (VAR < 0) \ goto e2big_error; \ fmt++; \ } \ } while (0) -#define GRPCPY(howmany) do { \ +#define GRPCPY(howmany) do { \ int i = howmany; \ while (i-- > 0) { \ avalue_size--; \ - *--bufend = *(avalue+avalue_size+padded); \ + *--bufend = *(avalue + avalue_size + padded); \ } \ } while (0) -#define GRPSEP do { \ +#define GRPSEP do { \ bufend -= thousands_sep_size;\ memcpy(bufend, thousands_sep, thousands_sep_size); \ groups++; \ } while (0) -static void __setup_vars(struct lconv *, int, char *, char *, char *, const char **); -static int __calc_left_pad(struct lconv *, int, char *); -static char *__format_grouped_double(struct lconv *, double, int *, int, int, int); +static void __setup_vars(int, char *, char *, char *, const char **, +struct lconv *); +static int __calc_left_pad(int, char *, struct lconv *); +static char *__format_grouped_double(double, int *, int, int, int, +struct lconv *, locale_t loc); static ssize_t vstrfmon_l(char * __restrict s, size_t maxsize, locale_t loc, @@ -150,7 +150,7 @@ vstrfmon_l(char * __restrict s, size_t m /* '%' found ! */ /* "%%" mean just '%' */ - if (*(fmt+1) == '%') { + if (*(fmt + 1) == '%') { fmt++; literal: PRINT(*fmt++); @@ -200,9 +200,9 @@ vstrfmon_l(char * __restrict s, size_t m } /* field Width */ - if (isdigit((unsigned char)*fmt)) { + if (isdigit_l((unsigned char)*fmt, loc)) { ptrdiff_t d = dst - s; - GET_NUMBER(width); + GET_NUMBER(width, loc); /* Do we have enough space to put number with * required width ? */ @@ -213,18 +213,18 @@ vstrfmon_l(char * __restrict s, size_t m /* Left precision */ if (*fmt == '#') { - if (!isdigit((unsigned char)*++fmt)) + if (!isdigit_l((unsigned char)*++fmt, loc)) goto format_error; - GET_NUMBER(left_prec); + GET_NUMBER(left_prec, loc); if ((unsigned int)left_prec >= maxsize - (dst - s)) goto e2big_error; } /* Right precision */ if (*fmt == '.') { - if (!isdigit((unsigned char)*++fmt)) + if (!isdigit_l((unsigned char)*++fmt, loc)) goto format_error; - GET_NUMBER(right_prec); + GET_NUMBER(right_prec, loc); if ((unsigned int)right_prec >= maxsize - (dst - s) - left_prec) goto e2big_error; @@ -243,7 +243,7 @@ vstrfmon_l(char * __restrict s, size_t m goto format_error; } - if (currency_symbol) + if (currency_symbol != NULL) free(currency_symbol); if (flags & USE_INTL_CURRENCY) { currency_symbol = strdup(lc->int_curr_symbol); @@ -252,7 +252,6 @@ vstrfmon_l(char * __restrict s, size_t m space_char = currency_symbol[3];
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Sun Nov 19 18:57:11 UTC 2023 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: minimize diffs with FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdlib/strfmon.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:39:34 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: A few more branch hints. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 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.62 src/lib/libc/stdlib/jemalloc.c:1.63 --- src/lib/libc/stdlib/jemalloc.c:1.62 Sat Oct 14 19:38:51 2023 +++ src/lib/libc/stdlib/jemalloc.c Sat Oct 14 19:39:33 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $ */ +/* $NetBSD: jemalloc.c,v 1.63 2023/10/14 19:39:33 ad Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -111,7 +111,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.62 2023/10/14 19:38:51 ad Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.63 2023/10/14 19:39:33 ad Exp $"); #include "namespace.h" #include @@ -3699,7 +3699,7 @@ calloc(size_t num, size_t size) ret = icalloc(num_size); RETURN: - if (ret == NULL) { + if (__predict_false(ret == NULL)) { if (OPT(xmalloc)) { _malloc_message(getprogname(), ": (malloc) Error in calloc(): out of memory\n", "", @@ -3734,7 +3734,7 @@ realloc(void *ptr, size_t size) ret = iralloc(ptr, size); - if (ret == NULL) { + if (__predict_false(ret == NULL)) { if (OPT(xmalloc)) { _malloc_message(getprogname(), ": (malloc) Error in realloc(): out of " @@ -3749,7 +3749,7 @@ realloc(void *ptr, size_t size) else ret = imalloc(size); - if (ret == NULL) { + if (__predict_false(ret == NULL)) { if (OPT(xmalloc)) { _malloc_message(getprogname(), ": (malloc) Error in realloc(): out of " @@ -3770,7 +3770,7 @@ free(void *ptr) { UTRACE(ptr, 0, 0); - if (ptr != NULL) { + if (__predict_true(ptr != NULL)) { assert(malloc_initialized); idalloc(ptr);
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:39:34 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: A few more branch hints. To generate a diff of this commit: cvs rdiff -u -r1.62 -r1.63 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:38:51 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Cherry pick a fix from FreeBSD: commit 80bc871bdd4a8254ce19a65a54c8c918dd3ddd11 Author: Konstantin Belousov Date: Sat Sep 12 18:16:46 2009 + MFC r196861: Handle zero size for posix_memalign. Return NULL or unique address according to the 'V' option. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 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.61 src/lib/libc/stdlib/jemalloc.c:1.62 --- src/lib/libc/stdlib/jemalloc.c:1.61 Sat Oct 14 19:37:24 2023 +++ src/lib/libc/stdlib/jemalloc.c Sat Oct 14 19:38:51 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $ */ +/* $NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -111,7 +111,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.61 2023/10/14 19:37:24 ad Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.62 2023/10/14 19:38:51 ad Exp $"); #include "namespace.h" #include @@ -3632,6 +3632,15 @@ posix_memalign(void **memptr, size_t ali goto RETURN; } + if (size == 0) { + if (NOT_OPT(sysv)) +size = 1; + else { +result = NULL; +ret = 0; +goto RETURN; + } + } result = ipalloc(alignment, size); }
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:38:51 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Cherry pick a fix from FreeBSD: commit 80bc871bdd4a8254ce19a65a54c8c918dd3ddd11 Author: Konstantin Belousov Date: Sat Sep 12 18:16:46 2009 + MFC r196861: Handle zero size for posix_memalign. Return NULL or unique address according to the 'V' option. To generate a diff of this commit: cvs rdiff -u -r1.61 -r1.62 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:37:24 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Cherry pick a fix from FreeBSD: commit 52d7a117c0fe8bd0226d964f4272131700035f12 Author: Jason Evans Date: Thu Aug 14 17:03:29 2008 + Re-order the terms of an expression in arena_run_reg_dalloc() to correctly detect whether the integer division table is large enough to handle the divisor. Before this change, the last two table elements were never used, thus causing the slow path to be used for those divisors. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 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.60 src/lib/libc/stdlib/jemalloc.c:1.61 --- src/lib/libc/stdlib/jemalloc.c:1.60 Sat Oct 14 19:36:17 2023 +++ src/lib/libc/stdlib/jemalloc.c Sat Oct 14 19:37:24 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.60 2023/10/14 19:36:17 ad Exp $ */ +/* $NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -111,7 +111,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.60 2023/10/14 19:36:17 ad Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.61 2023/10/14 19:37:24 ad Exp $"); #include "namespace.h" #include @@ -1685,8 +1685,8 @@ arena_run_reg_dalloc(arena_run_t *run, a */ regind = (unsigned)(diff / size); } - } else if (size <= ((sizeof(size_invs) / sizeof(unsigned)) - << QUANTUM_2POW_MIN) + 2) { + } else if (size <= (((sizeof(size_invs) / sizeof(unsigned)) + 2) + << QUANTUM_2POW_MIN)) { regind = size_invs[(size >> QUANTUM_2POW_MIN) - 3] * diff; regind >>= SIZE_INV_SHIFT; } else {
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:37:24 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Cherry pick a fix from FreeBSD: commit 52d7a117c0fe8bd0226d964f4272131700035f12 Author: Jason Evans Date: Thu Aug 14 17:03:29 2008 + Re-order the terms of an expression in arena_run_reg_dalloc() to correctly detect whether the integer division table is large enough to handle the divisor. Before this change, the last two table elements were never used, thus causing the slow path to be used for those divisors. To generate a diff of this commit: cvs rdiff -u -r1.60 -r1.61 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:36:17 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Fix a bug in the rbtree conversion. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 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.59 src/lib/libc/stdlib/jemalloc.c:1.60 --- src/lib/libc/stdlib/jemalloc.c:1.59 Sat Oct 14 06:29:10 2023 +++ src/lib/libc/stdlib/jemalloc.c Sat Oct 14 19:36:17 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.59 2023/10/14 06:29:10 mrg Exp $ */ +/* $NetBSD: jemalloc.c,v 1.60 2023/10/14 19:36:17 ad Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -111,7 +111,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.59 2023/10/14 06:29:10 mrg Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.60 2023/10/14 19:36:17 ad Exp $"); #include "namespace.h" #include @@ -174,10 +174,10 @@ static inline int ptrcmp(const void *pa, const void *pb) { #ifdef _LP64 - const intptr_t a = (intptr_t)pa, b = (intptr_t)pb; - const intptr_t diff = a - b; + const uintptr_t a = (uintptr_t)pa, b = (uintptr_t)pb; + const uintptr_t diff = a - b; assert(((a | b) & 1) == 0); - return (int)(diff >> 32) | ((int)diff >> 1); + return (int)(diff >> 32) | ((unsigned)diff >> 1); #else return (intptr_t)pa - (intptr_t)pb; #endif
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Sat Oct 14 19:36:17 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Fix a bug in the rbtree conversion. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: mrg Date: Sat Oct 14 06:29:10 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: fix compile error on 32-bit platforms. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: mrg Date: Sat Oct 14 06:29:10 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: fix compile error on 32-bit platforms. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 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.58 src/lib/libc/stdlib/jemalloc.c:1.59 --- src/lib/libc/stdlib/jemalloc.c:1.58 Fri Oct 13 20:57:30 2023 +++ src/lib/libc/stdlib/jemalloc.c Sat Oct 14 06:29:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.58 2023/10/13 20:57:30 ad Exp $ */ +/* $NetBSD: jemalloc.c,v 1.59 2023/10/14 06:29:10 mrg Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -111,7 +111,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.58 2023/10/13 20:57:30 ad Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.59 2023/10/14 06:29:10 mrg Exp $"); #include "namespace.h" #include @@ -179,7 +179,7 @@ ptrcmp(const void *pa, const void *pb) assert(((a | b) & 1) == 0); return (int)(diff >> 32) | ((int)diff >> 1); #else - return (intptr_t)a - (intptr_t)b; + return (intptr_t)pa - (intptr_t)pb; #endif }
re: CVS commit: src/lib/libc/stdlib
> Minor changes to jemalloc100 (the old one that only vax etc currently uses). thanks. i'm still using this version on a bunch of modern machines. new jemalloc was problematic for a few things for me a number of years ago and i keep meaning to test again, but for now i'm still mostly using this version everwhere. FYI. .mrg.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Fri Oct 13 20:57:30 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Convert to use Matt Thomas's rbtree, which the env code probably already pulls into libc. amd64 object size before and after: textdata bss dec hex filename 21001 88 365 2145453ce jemalloc.po 14991 184 429 156043cf4 jemalloc.po libmicro on AMD Athlon Silver 3050e comparing this and the revision before previous (i.e. the old code, versus arena changes + rbtree changes): exit_10_nolibc 135.168300 128.07790[ +5.5%] fork_100180.539040 149.63721[ +20.7%] fork_1000 200.421650 167.09660[ +19.9%] mallocT2_10 0.1329200.13317[ -0.2%] mallocT2_1000.1363500.13635[ +0.0%] mallocT2_100k 0.2586900.26641[ -3.0%] mallocT2_10k0.2233400.22733[ -1.8%] mallocT2_1k 0.1371700.14254[ -3.9%] malloc_10 0.1005400.10849[ -7.9%] malloc_100 0.1072900.10753[ -0.2%] malloc_100k 0.1935600.19355[ +0.0%] malloc_10k 0.1732500.17454[ -0.7%] malloc_1k 0.1134900.11335[ +0.1%] To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 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.57 src/lib/libc/stdlib/jemalloc.c:1.58 --- src/lib/libc/stdlib/jemalloc.c:1.57 Fri Oct 13 19:30:28 2023 +++ src/lib/libc/stdlib/jemalloc.c Fri Oct 13 20:57:30 2023 @@ -1,7 +1,8 @@ -/* $NetBSD: jemalloc.c,v 1.57 2023/10/13 19:30:28 ad Exp $ */ +/* $NetBSD: jemalloc.c,v 1.58 2023/10/13 20:57:30 ad Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . + * Copyright (C) 2023 Andrew Doran . * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -110,7 +111,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.57 2023/10/13 19:30:28 ad Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.58 2023/10/13 20:57:30 ad Exp $"); #include "namespace.h" #include @@ -118,7 +119,7 @@ __RCSID("$NetBSD: jemalloc.c,v 1.57 2023 #include #include #include -#include +#include #include #include /* Must come after several other sys/ includes. */ @@ -161,6 +162,27 @@ __RCSID("$NetBSD: jemalloc.c,v 1.57 2023 # define inline #endif +/* + * Compare two pointers of 64/32 bit width and produce a ternary 32-bit + * indicator without using conditionals that maintains the expected + * ordering: [negative, equal, positive]. + * + * XXX it depends on twos complement arithemetic. + * XXX maybe should be a built-in for rbtree? + */ +static inline int +ptrcmp(const void *pa, const void *pb) +{ +#ifdef _LP64 + const intptr_t a = (intptr_t)pa, b = (intptr_t)pb; + const intptr_t diff = a - b; + assert(((a | b) & 1) == 0); + return (int)(diff >> 32) | ((int)diff >> 1); +#else + return (intptr_t)a - (intptr_t)b; +#endif +} + /* Size of stack-allocated buffer passed to strerror_r(). */ #define STRERROR_BUF 64 @@ -412,7 +434,7 @@ struct chunk_stats_s { typedef struct chunk_node_s chunk_node_t; struct chunk_node_s { /* Linkage for the chunk tree. */ - RB_ENTRY(chunk_node_s) link; + rb_node_t link; /* * Pointer to the chunk that this tree node is responsible for. In some @@ -426,7 +448,14 @@ struct chunk_node_s { size_t size; }; typedef struct chunk_tree_s chunk_tree_t; -RB_HEAD(chunk_tree_s, chunk_node_s); + +static int chunk_comp(void *, const void *, const void *); + +static const rb_tree_ops_t chunk_tree_ops = { + .rbto_compare_nodes = chunk_comp, + .rbto_compare_key = chunk_comp, + .rbto_node_offset = offsetof(struct chunk_node_s, link), +}; /**/ /* @@ -455,12 +484,12 @@ struct arena_chunk_map_s { /* Arena chunk header. */ typedef struct arena_chunk_s arena_chunk_t; struct arena_chunk_s { + /* Linkage for the arena's chunk tree. */ + rb_node_t link; + /* Arena that owns the chunk. */ arena_t *arena; - /* Linkage for the arena's chunk tree. */ - RB_ENTRY(arena_chunk_s) link; - /* * Number of pages in use. This is maintained in order to make * detection of empty chunks fast. @@ -490,12 +519,19 @@ struct arena_chunk_s { arena_chunk_map_t map[1]; /* Dynamically sized. */ }; typedef struct arena_chunk_tree_s arena_chunk_tree_t; -RB_HEAD(arena_chunk_tree_s, arena_chunk_s); + +static int arena_chunk_comp(void *, const void *, const void *); + +static const rb_tree_ops_t arena_chunk_tree_ops = { + .rbto_compare_nodes = arena_chunk_comp,
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Fri Oct 13 20:57:30 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Convert to use Matt Thomas's rbtree, which the env code probably already pulls into libc. amd64 object size before and after: textdata bss dec hex filename 21001 88 365 2145453ce jemalloc.po 14991 184 429 156043cf4 jemalloc.po libmicro on AMD Athlon Silver 3050e comparing this and the revision before previous (i.e. the old code, versus arena changes + rbtree changes): exit_10_nolibc 135.168300 128.07790[ +5.5%] fork_100180.539040 149.63721[ +20.7%] fork_1000 200.421650 167.09660[ +19.9%] mallocT2_10 0.1329200.13317[ -0.2%] mallocT2_1000.1363500.13635[ +0.0%] mallocT2_100k 0.2586900.26641[ -3.0%] mallocT2_10k0.2233400.22733[ -1.8%] mallocT2_1k 0.1371700.14254[ -3.9%] malloc_10 0.1005400.10849[ -7.9%] malloc_100 0.1072900.10753[ -0.2%] malloc_100k 0.1935600.19355[ +0.0%] malloc_10k 0.1732500.17454[ -0.7%] malloc_1k 0.1134900.11335[ +0.1%] To generate a diff of this commit: cvs rdiff -u -r1.57 -r1.58 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Fri Oct 13 19:30:28 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Minor changes to jemalloc100 (the old one that only vax etc currently uses). - Don't use TLS nor pretend to hash out arenas to reduce lock contention, because NetBSD uses thr_curcpu() to choose arena (i.e. per-CPU arenas). - In a single threaded process, don't prepare "ncpus" worth of arenas, allocate only one. - Use getpagesize() since it caches the return. - Sprinkle branch hints. - Make MALLOC_TRACE and MALLOC_DEBUG work again. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 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.56 src/lib/libc/stdlib/jemalloc.c:1.57 --- src/lib/libc/stdlib/jemalloc.c:1.56 Sun May 7 12:41:47 2023 +++ src/lib/libc/stdlib/jemalloc.c Fri Oct 13 19:30:28 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.56 2023/05/07 12:41:47 skrll Exp $ */ +/* $NetBSD: jemalloc.c,v 1.57 2023/10/13 19:30:28 ad Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -97,13 +97,6 @@ /* LINTLIBRARY */ -#ifdef __NetBSD__ -# define xutrace(a, b) utrace("malloc", (a), (b)) -# define __DECONST(x, y) ((x)__UNCONST(y)) -#else -# define xutrace(a, b) utrace((a), (b)) -#endif /* __NetBSD__ */ - /* * MALLOC_PRODUCTION disables assertions and statistics gathering. It also * defaults the A and J runtime options to off. These settings are appropriate @@ -117,21 +110,11 @@ #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.56 2023/05/07 12:41:47 skrll Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.57 2023/10/13 19:30:28 ad Exp $"); -#ifdef __FreeBSD__ -#include "libc_private.h" -#ifdef MALLOC_DEBUG -# define _LOCK_DEBUG -#endif -#include "spinlock.h" -#endif #include "namespace.h" #include #include -#ifdef __FreeBSD__ -#include -#endif #include #include #include @@ -139,12 +122,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023 #include #include /* Must come after several other sys/ includes. */ -#ifdef __FreeBSD__ -#include -#include -#include -#endif - #include #include #include @@ -158,17 +135,10 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023 #include #include -#ifdef __NetBSD__ -# include -# include "extern.h" +#include +#include "extern.h" #define STRERROR_R(a, b, c) strerror_r_ss(a, b, c); -#endif - -#ifdef __FreeBSD__ -#define STRERROR_R(a, b, c) strerror_r(a, b, c); -#include "un-namespace.h" -#endif /* MALLOC_STATS enables statistics calculation. */ #ifndef MALLOC_PRODUCTION @@ -260,7 +230,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023 # define QUANTUM_2POW_MIN 4 # define SIZEOF_PTR_2POW 2 # define USE_BRK -# define NO_TLS #endif #ifdef __sh__ # define QUANTUM_2POW_MIN 4 @@ -271,9 +240,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023 # define QUANTUM_2POW_MIN 4 # define SIZEOF_PTR_2POW 2 # define USE_BRK -# ifdef __mc68010__ -#define NO_TLS -# endif #endif #if defined(__mips__) # ifdef _LP64 @@ -284,9 +250,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023 # endif # define QUANTUM_2POW_MIN 4 # define USE_BRK -# if defined(__mips__) -#define NO_TLS -# endif #endif #if defined(__riscv__) # ifdef _LP64 @@ -297,7 +260,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023 # endif # define QUANTUM_2POW_MIN 4 # define USE_BRK -# define NO_TLS #endif #ifdef __hppa__ # define QUANTUM_2POW_MIN 4 @@ -367,21 +329,6 @@ __RCSID("$NetBSD: jemalloc.c,v 1.56 2023 /**/ -#ifdef __FreeBSD__ -/* - * Mutexes based on spinlocks. We can't use normal pthread mutexes, because - * they require malloc()ed memory. - */ -typedef struct { - spinlock_t lock; -} malloc_mutex_t; - -/* Set to true once the allocator has been initialized. */ -static bool malloc_initialized = false; - -/* Used to avoid initialization races. */ -static malloc_mutex_t init_lock = {_SPINLOCK_INITIALIZER}; -#else #define malloc_mutex_t mutex_t /* Set to true once the allocator has been initialized. */ @@ -391,7 +338,6 @@ static bool malloc_initialized = false; /* Used to avoid initialization races. */ static mutex_t init_lock = MUTEX_INITIALIZER; #endif -#endif /**/ /* @@ -774,71 +720,10 @@ static size_t base_mapped; * arenas array are necessarily used; arenas are created lazily as needed. */ static arena_t **arenas; -static unsigned narenas; -static unsigned next_arena; #ifdef _REENTRANT static malloc_mutex_t arenas_mtx; /* Protects arenas initialization. */ #endif -/* - * Map of pthread_self() --> arenas[???], used for
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: ad Date: Fri Oct 13 19:30:28 UTC 2023 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Minor changes to jemalloc100 (the old one that only vax etc currently uses). - Don't use TLS nor pretend to hash out arenas to reduce lock contention, because NetBSD uses thr_curcpu() to choose arena (i.e. per-CPU arenas). - In a single threaded process, don't prepare "ncpus" worth of arenas, allocate only one. - Use getpagesize() since it caches the return. - Sprinkle branch hints. - Make MALLOC_TRACE and MALLOC_DEBUG work again. To generate a diff of this commit: cvs rdiff -u -r1.56 -r1.57 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: martin Date: Thu Sep 28 10:03:41 UTC 2023 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: Fix padding for formats with mutliple padded values. PR lib/57633, fix from FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdlib/strfmon.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: martin Date: Thu Sep 28 10:03:41 UTC 2023 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: Fix padding for formats with mutliple padded values. PR lib/57633, fix from FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/lib/libc/stdlib/strfmon.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/strfmon.c diff -u src/lib/libc/stdlib/strfmon.c:1.18 src/lib/libc/stdlib/strfmon.c:1.19 --- src/lib/libc/stdlib/strfmon.c:1.18 Thu Aug 18 11:05:02 2022 +++ src/lib/libc/stdlib/strfmon.c Thu Sep 28 10:03:41 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: strfmon.c,v 1.18 2022/08/18 11:05:02 christos Exp $ */ +/* $NetBSD: strfmon.c,v 1.19 2023/09/28 10:03:41 martin Exp $ */ /*- * Copyright (c) 2001 Alexey Zelkin @@ -32,7 +32,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); #else -__RCSID("$NetBSD: strfmon.c,v 1.18 2022/08/18 11:05:02 christos Exp $"); +__RCSID("$NetBSD: strfmon.c,v 1.19 2023/09/28 10:03:41 martin Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -141,7 +141,6 @@ vstrfmon_l(char * __restrict s, size_t m fmt = format; asciivalue = NULL; currency_symbol = NULL; - pad_size = 0; while (*fmt) { /* pass nonformating characters AS IS */ @@ -161,6 +160,7 @@ vstrfmon_l(char * __restrict s, size_t m /* set up initial values */ flags = (NEED_GROUPING|LOCALE_POSN); pad_char = ' '; /* padding character is "space" */ + pad_size = 0; /* no padding initially */ left_prec = -1; /* no left precision specified */ right_prec = -1; /* no right precision specified */ width = -1; /* no width specified */
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: rillig Date: Tue Feb 21 19:27:14 UTC 2023 Modified Files: src/lib/libc/stdlib: hcreate.3 Log Message: hcreate.3: fix typo To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdlib/hcreate.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/hcreate.3 diff -u src/lib/libc/stdlib/hcreate.3:1.14 src/lib/libc/stdlib/hcreate.3:1.15 --- src/lib/libc/stdlib/hcreate.3:1.14 Tue Feb 7 22:25:25 2017 +++ src/lib/libc/stdlib/hcreate.3 Tue Feb 21 19:27:14 2023 @@ -1,4 +1,4 @@ -.\" $NetBSD: hcreate.3,v 1.14 2017/02/07 22:25:25 christos Exp $ +.\" $NetBSD: hcreate.3,v 1.15 2023/02/21 19:27:14 rillig Exp $ .\" .\" Copyright (c) 1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -99,7 +99,7 @@ the data can no longer be accessed. .Pp The .Fn hsearch -function is used to search to the hash table. +function is used to search the hash table. It returns a pointer into the hash table indicating the address of an item. The
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: rillig Date: Tue Feb 21 19:27:14 UTC 2023 Modified Files: src/lib/libc/stdlib: hcreate.3 Log Message: hcreate.3: fix typo To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/lib/libc/stdlib/hcreate.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: skrll Date: Wed Nov 30 04:35:53 UTC 2022 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 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.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: skrll Date: Wed Nov 30 04:35:53 UTC 2022 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.54 -r1.55 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.54 src/lib/libc/stdlib/jemalloc.c:1.55 --- src/lib/libc/stdlib/jemalloc.c:1.54 Mon Aug 30 13:12:16 2021 +++ src/lib/libc/stdlib/jemalloc.c Wed Nov 30 04:35:53 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.54 2021/08/30 13:12:16 christos Exp $ */ +/* $NetBSD: jemalloc.c,v 1.55 2022/11/30 04:35:53 skrll Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -116,8 +116,8 @@ #endif #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.54 2021/08/30 13:12:16 christos Exp $"); +/* __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.55 2022/11/30 04:35:53 skrll Exp $"); #ifdef __FreeBSD__ #include "libc_private.h" @@ -288,12 +288,12 @@ __RCSID("$NetBSD: jemalloc.c,v 1.54 2021 #define NO_TLS # endif #endif -#ifdef __hppa__ -# define QUANTUM_2POW_MIN 4 +#ifdef __hppa__ +# define QUANTUM_2POW_MIN 4 # define TINY_MIN_2POW 4 -# define SIZEOF_PTR_2POW 2 -# define USE_BRK -#endif +# define SIZEOF_PTR_2POW 2 +# define USE_BRK +#endif #define SIZEOF_PTR (1 << SIZEOF_PTR_2POW) @@ -3572,7 +3572,7 @@ malloc_init_hard(void) break; default: { char cbuf[2]; - + cbuf[0] = opts[j]; cbuf[1] = '\0'; _malloc_message(getprogname(),
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Sun Nov 27 20:17:20 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarray.3 Log Message: reallocarray.3: minor grammar and style tweaks To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/reallocarray.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/reallocarray.3 diff -u src/lib/libc/stdlib/reallocarray.3:1.5 src/lib/libc/stdlib/reallocarray.3:1.6 --- src/lib/libc/stdlib/reallocarray.3:1.5 Fri Oct 28 09:43:59 2022 +++ src/lib/libc/stdlib/reallocarray.3 Sun Nov 27 20:17:20 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: reallocarray.3,v 1.5 2022/10/28 09:43:59 wiz Exp $ +.\" $NetBSD: reallocarray.3,v 1.6 2022/11/27 20:17:20 gutteridge Exp $ .\" .\" Copyright (c) 2015 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -104,19 +104,19 @@ functions by centralizing the overflow c and .Fa size . .Pp -There are still portability issues (it does not solve -the +There are still portability issues. +(It does not solve the .Dv 0 sized allocation return ambiguity in the C standard: does .Fn reallocarray return .Dv NULL -or a unique pointer to memory that cannot be accessed? Does a +or a unique pointer to memory that cannot be accessed? +Does a .Dv NULL mean that an error occurred, and can someone check .Dv errno -in that case to find out what happened?). -.Pp +in that case to find out what happened?) For this reason .Nx decided to go with an alternative implementation, and created
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Sun Nov 27 20:17:20 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarray.3 Log Message: reallocarray.3: minor grammar and style tweaks To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/reallocarray.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Tue Nov 15 22:17:53 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: add a history section To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/posix_openpt.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/posix_openpt.3 diff -u src/lib/libc/stdlib/posix_openpt.3:1.9 src/lib/libc/stdlib/posix_openpt.3:1.10 --- src/lib/libc/stdlib/posix_openpt.3:1.9 Tue Oct 4 01:46:18 2022 +++ src/lib/libc/stdlib/posix_openpt.3 Tue Nov 15 22:17:53 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: posix_openpt.3,v 1.9 2022/10/04 01:46:18 gutteridge Exp $ +.\" $NetBSD: posix_openpt.3,v 1.10 2022/11/15 22:17:53 gutteridge Exp $ .\" .\" Copyright (c) 2004 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 4, 2022 +.Dd November 15, 2022 .Dt POSIX_OPENPT 3 .Os .Sh NAME @@ -98,3 +98,8 @@ The .Fn posix_openpt function conforms to .St -p1003.1-2001 . +.Sh HISTORY +This function first appeared in +.Nx 3 . +Support for non-standard flags appeared in +.Nx 10 .
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Tue Nov 15 22:17:53 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: add a history section To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/posix_openpt.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Tue Oct 4 01:46:18 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: reflect changes from r. 1.45 of tty_ptm.c To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdlib/posix_openpt.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/posix_openpt.3 diff -u src/lib/libc/stdlib/posix_openpt.3:1.8 src/lib/libc/stdlib/posix_openpt.3:1.9 --- src/lib/libc/stdlib/posix_openpt.3:1.8 Wed Sep 28 00:35:47 2022 +++ src/lib/libc/stdlib/posix_openpt.3 Tue Oct 4 01:46:18 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: posix_openpt.3,v 1.8 2022/09/28 00:35:47 gutteridge Exp $ +.\" $NetBSD: posix_openpt.3,v 1.9 2022/10/04 01:46:18 gutteridge Exp $ .\" .\" Copyright (c) 2004 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 28, 2022 +.Dd October 4, 2022 .Dt POSIX_OPENPT 3 .Os .Sh NAME @@ -51,9 +51,6 @@ The argument has the same meaning as in the .Xr open 2 call. -However, flags supplied in -.Fa oflag -may be ignored if they are unsupported. .Sh RETURN VALUES If successful, .Fn posix_openpt @@ -75,6 +72,11 @@ This means it is not possible to dynamic flags are possible to set, and apply a fallback if .Er EINVAL is received. +However, this is unlikely to be a concern in practice, as flags such as +.Dv O_NONBLOCK +and +.Dv O_CLOEXEC +are supported. .Sh SEE ALSO .Xr ioctl 2 , .Xr open 2 ,
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Tue Oct 4 01:46:18 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: reflect changes from r. 1.45 of tty_ptm.c To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/lib/libc/stdlib/posix_openpt.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/lib/libc/stdlib
Date:Thu, 29 Sep 2022 08:18:49 -0400 From:Christos Zoulas Message-ID: | Yes, I had forgotten about the need to do this explicitly... | > On Sep 28, 2022, at 10:23 PM, Robert Elz wrote: | > | > Apologies, I did not read the code closely enough, there must be a bug | > in the way the clone file descriptor is created. I think I know the cause now, and it isn't anything specific to /dev/ptmx it would affect all cloning devices. In kern/vfs_syscalls.c do_open() we see the following: if (vp == NULL) { fd_abort(p, fp, indx); error = fd_dupopen(dupfd, dupfd_move, flags, ); if (error) return error; *fd = indx; } else { error = open_setfp(l, fp, vp, indx, flags); if (error) return error; VOP_UNLOCK(vp); *fd = indx; fd_affix(p, fp, indx); } The vp==NULL case is where cloning devices are handled. fd_dupopen() arranges top make the duplicate happen. It attempts to handle O_CLOEXEC thus: error = fd_dup(fp, 0, newp, ff->ff_exclose); where ff_exclose is the close_on_exec bit for the old file descriptor (the one being duplicated) which is just fine for other calls of fd_dupopen(). The vp!=NULL case above is for "normal" opens, and open_setfp() is what handles O_CLOEXEC - that's what (eventually) makes ff_exclose be true (it also handles O_EXLOCK and O_SHLOCK. None of that is being done in the cloning device open case, so those 3 flags simply cannot work, as the code is written currently, for these devices. I'm not about to go playing in this very fiddly piece of code, but I'm kind of hoping that dholland@ might know the right magic sequence to make this issue go away. It probably means a call to open_setfp() with some parameters or other, somewhere in the vp==NULL side of that if statement, though, just what I have not attempted to work out. kre
Re: CVS commit: src/lib/libc/stdlib
Yes, I had forgotten about the need to do this explicitly... christos > On Sep 28, 2022, at 10:23 PM, Robert Elz wrote: > > Apologies, I did not read the code closely enough, there must be a bug > in the way the clone file descriptor is created. > > kre signature.asc Description: Message signed with OpenPGP
Re: CVS commit: src/lib/libc/stdlib
Apologies, I did not read the code closely enough, there must be a bug in the way the clone file descriptor is created. kre
Re: CVS commit: src/lib/libc/stdlib
Date:Wed, 28 Sep 2022 20:48:53 -0400 From:"David H. Gutteridge" Message-ID: <9c9c8e9d9384338320b47dabfdc94...@gutteridge.ca> | (O_CLOEXEC, on the other hand, is ignored, at the moment.) No it isn't, your test is faulty, O_CLOEXEC is a different kind of flag, applies at a different level, and is fetched a different way. That's what dholland@ tried to tell you a few days ago. kre | | $ cat open_test.c | #include | #include | #include | | int main(int argc, char* argv[]) | { | int fd, flags; | | printf("Regular file (read-only) with O_NONBLOCK | O_CLOEXEC.\n"); | if ((fd = open("/etc/release", O_RDONLY | O_NONBLOCK | O_CLOEXEC)) < 0) | printf("Failed to get file handle.\n"); | else { | printf("Descriptor flags: %d\n", flags = fcntl(fd, F_GETFD)); | printf("Status flags: %d\n", flags = fcntl(fd, F_GETFL, 0)); | close(fd); | } | | printf("POSIX pt cloning device with O_NONBLOCK | O_CLOEXEC.\n"); | if ((fd = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_NONBLOCK | | O_CLOEXEC)) < 0) | printf("Failed to open /dev/ptmx.\n"); | else { | printf("Descriptor flags: %d\n", flags = fcntl(fd, F_GETFD)); | printf("Status flags: %d\n", flags = fcntl(fd, F_GETFL, 0)); | close(fd); | } | | return 0; | } | | $ ./open_test | Regular file (read-only) with O_NONBLOCK | O_CLOEXEC. | Descriptor flags: 1 | Status flags: 4 | POSIX pt cloning device with O_NONBLOCK | O_CLOEXEC. | Descriptor flags: 0 | Status flags: 6 | | Regards, | | Dave |
Re: CVS commit: src/lib/libc/stdlib
On Wed, 28 Sep 2022, at 15:07:41 - (UTC), Christos Zoulas wrote: In article <20220928003547.D2375FA92%cvs.NetBSD.org@localhost>, David H. Gutteridge wrote: -=-=-=-=-=- Module Name:src Committed By: gutteridge Date: Wed Sep 28 00:35:47 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: reflect flag changes from r. 1.44 of tty_ptm.c Some flags are now accepted, others are still ignored. (E.g., other BSDs would return EINVAL if O_RDWR wasn't passed, and we now accept O_NONBLOCK but not O_CLOEXEC.) How so? #define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FDSYNC|FRSYNC|FALTIO|\ ^ FDIRECT|FNOSIGPIPE) /* bits to save after open(2) */ #define FMASK (FREAD|FWRITE|FCNTLFLAGS|FEXEC) ^^ Best, christos Hi Christos, I'm sorry, I don't follow your question? I wrote "we now accept O_NONBLOCK...", which is what I'm reading you're saying too? (O_CLOEXEC, on the other hand, is ignored, at the moment.) $ cat open_test.c #include #include #include int main(int argc, char* argv[]) { int fd, flags; printf("Regular file (read-only) with O_NONBLOCK | O_CLOEXEC.\n"); if ((fd = open("/etc/release", O_RDONLY | O_NONBLOCK | O_CLOEXEC)) < 0) printf("Failed to get file handle.\n"); else { printf("Descriptor flags: %d\n", flags = fcntl(fd, F_GETFD)); printf("Status flags: %d\n", flags = fcntl(fd, F_GETFL, 0)); close(fd); } printf("POSIX pt cloning device with O_NONBLOCK | O_CLOEXEC.\n"); if ((fd = open("/dev/ptmx", O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC)) < 0) printf("Failed to open /dev/ptmx.\n"); else { printf("Descriptor flags: %d\n", flags = fcntl(fd, F_GETFD)); printf("Status flags: %d\n", flags = fcntl(fd, F_GETFL, 0)); close(fd); } return 0; } $ ./open_test Regular file (read-only) with O_NONBLOCK | O_CLOEXEC. Descriptor flags: 1 Status flags: 4 POSIX pt cloning device with O_NONBLOCK | O_CLOEXEC. Descriptor flags: 0 Status flags: 6 Regards, Dave
Re: CVS commit: src/lib/libc/stdlib
In article <20220928003547.d2375f...@cvs.netbsd.org>, David H. Gutteridge wrote: >-=-=-=-=-=- > >Module Name: src >Committed By: gutteridge >Date: Wed Sep 28 00:35:47 UTC 2022 > >Modified Files: > src/lib/libc/stdlib: posix_openpt.3 > >Log Message: >posix_openpt.3: reflect flag changes from r. 1.44 of tty_ptm.c > >Some flags are now accepted, others are still ignored. (E.g., other >BSDs would return EINVAL if O_RDWR wasn't passed, and we now accept >O_NONBLOCK but not O_CLOEXEC.) How so? #define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FDSYNC|FRSYNC|FALTIO|\ ^ FDIRECT|FNOSIGPIPE) /* bits to save after open(2) */ #define FMASK (FREAD|FWRITE|FCNTLFLAGS|FEXEC) ^^ Best, christos
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Wed Sep 28 00:35:47 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: reflect flag changes from r. 1.44 of tty_ptm.c Some flags are now accepted, others are still ignored. (E.g., other BSDs would return EINVAL if O_RDWR wasn't passed, and we now accept O_NONBLOCK but not O_CLOEXEC.) To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/posix_openpt.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/posix_openpt.3 diff -u src/lib/libc/stdlib/posix_openpt.3:1.7 src/lib/libc/stdlib/posix_openpt.3:1.8 --- src/lib/libc/stdlib/posix_openpt.3:1.7 Tue Sep 6 22:54:41 2022 +++ src/lib/libc/stdlib/posix_openpt.3 Wed Sep 28 00:35:47 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: posix_openpt.3,v 1.7 2022/09/06 22:54:41 gutteridge Exp $ +.\" $NetBSD: posix_openpt.3,v 1.8 2022/09/28 00:35:47 gutteridge Exp $ .\" .\" Copyright (c) 2004 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 6, 2022 +.Dd September 28, 2022 .Dt POSIX_OPENPT 3 .Os .Sh NAME @@ -51,9 +51,9 @@ The argument has the same meaning as in the .Xr open 2 call. -However, the value of +However, flags supplied in .Fa oflag -is ignored; it exists for compatibility reasons only. +may be ignored if they are unsupported. .Sh RETURN VALUES If successful, .Fn posix_openpt @@ -67,7 +67,7 @@ Note that unlike implementations on some .Fn posix_openpt does not return .Er EINVAL -if the value of +if a flag supplied in .Fa oflag would be deemed invalid, instead it is simply ignored. This means it is not possible to dynamically test which
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Wed Sep 28 00:35:47 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: reflect flag changes from r. 1.44 of tty_ptm.c Some flags are now accepted, others are still ignored. (E.g., other BSDs would return EINVAL if O_RDWR wasn't passed, and we now accept O_NONBLOCK but not O_CLOEXEC.) To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/lib/libc/stdlib/posix_openpt.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Tue Sep 6 22:54:41 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: add caveats about oflags The NetBSD implementation differs from other BSDs in that it does not return EINVAL if invalid oflags are submitted, since it completely ignores them. This is surprising to upstream projects that may expect otherwise. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/posix_openpt.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/posix_openpt.3 diff -u src/lib/libc/stdlib/posix_openpt.3:1.6 src/lib/libc/stdlib/posix_openpt.3:1.7 --- src/lib/libc/stdlib/posix_openpt.3:1.6 Thu May 5 07:36:44 2011 +++ src/lib/libc/stdlib/posix_openpt.3 Tue Sep 6 22:54:41 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: posix_openpt.3,v 1.6 2011/05/05 07:36:44 wiz Exp $ +.\" $NetBSD: posix_openpt.3,v 1.7 2022/09/06 22:54:41 gutteridge Exp $ .\" .\" Copyright (c) 2004 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 25, 2004 +.Dd September 6, 2022 .Dt POSIX_OPENPT 3 .Os .Sh NAME @@ -51,6 +51,9 @@ The argument has the same meaning as in the .Xr open 2 call. +However, the value of +.Fa oflag +is ignored; it exists for compatibility reasons only. .Sh RETURN VALUES If successful, .Fn posix_openpt @@ -59,6 +62,19 @@ pointing to the master pseudo-terminal d Otherwise, a value of \-1 is returned and .Va errno is set to indicate the error. +.Pp +Note that unlike implementations on some other operating systems, +.Fn posix_openpt +does not return +.Er EINVAL +if the value of +.Fa oflag +would be deemed invalid, instead it is simply ignored. +This means it is not possible to dynamically test which +.Xr open 2 +flags are possible to set, and apply a fallback if +.Er EINVAL +is received. .Sh SEE ALSO .Xr ioctl 2 , .Xr open 2 ,
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: gutteridge Date: Tue Sep 6 22:54:41 UTC 2022 Modified Files: src/lib/libc/stdlib: posix_openpt.3 Log Message: posix_openpt.3: add caveats about oflags The NetBSD implementation differs from other BSDs in that it does not return EINVAL if invalid oflags are submitted, since it completely ignores them. This is surprising to upstream projects that may expect otherwise. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/posix_openpt.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Wed Aug 31 12:18:41 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarr.3 Log Message: reallocarr(3): Touch up xrefs. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/reallocarr.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/reallocarr.3 diff -u src/lib/libc/stdlib/reallocarr.3:1.6 src/lib/libc/stdlib/reallocarr.3:1.7 --- src/lib/libc/stdlib/reallocarr.3:1.6 Wed Aug 31 12:17:14 2022 +++ src/lib/libc/stdlib/reallocarr.3 Wed Aug 31 12:18:41 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: reallocarr.3,v 1.6 2022/08/31 12:17:14 riastradh Exp $ +.\" $NetBSD: reallocarr.3,v 1.7 2022/08/31 12:18:41 riastradh Exp $ .\" .\" Copyright (c) 2015 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -123,7 +123,7 @@ as a side effect. Note that the argument .Fa ptrp is a pointer to a pointer to allocated memory, unlike -.Xr realloc +.Xr realloc 3 which takes a pointer to allocated memory. .Sh RETURN VALUES On successful completion, @@ -163,7 +163,9 @@ if (error) assert(data == NULL); .Ed .Sh SEE ALSO -.Xr calloc 3 +.Xr calloc 3 , +.Xr realloc 3 , +.Xr reallocarray 3 .Sh HISTORY .Nm first appeared in
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Wed Aug 31 12:18:41 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarr.3 Log Message: reallocarr(3): Touch up xrefs. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/libc/stdlib/reallocarr.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Wed Aug 31 12:17:14 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarr.3 Log Message: reallocarr(3): Bump date. Note overflow is handled internally. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/reallocarr.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/reallocarr.3 diff -u src/lib/libc/stdlib/reallocarr.3:1.5 src/lib/libc/stdlib/reallocarr.3:1.6 --- src/lib/libc/stdlib/reallocarr.3:1.5 Wed Aug 31 12:10:05 2022 +++ src/lib/libc/stdlib/reallocarr.3 Wed Aug 31 12:17:14 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: reallocarr.3,v 1.5 2022/08/31 12:10:05 riastradh Exp $ +.\" $NetBSD: reallocarr.3,v 1.6 2022/08/31 12:17:14 riastradh Exp $ .\" .\" Copyright (c) 2015 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -26,7 +26,7 @@ .\" 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. -.Dd February 19, 2015 +.Dd August 31, 2022 .Dt REALLOCARR 3 .Os .Sh NAME @@ -100,6 +100,20 @@ which will always succeed and unconditio .Fa ptr to null. .Pp +Like +.Xr calloc 3 , +.Nm +fails gracefully if the product of +.Fa number +and +.Fa size +would overflow the representable size of memory. +Unlike +.Xr calloc 3 , +new memory allocated by +.Nm +is not zero-initialized. +.Pp The .Nm function may alter
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Wed Aug 31 12:17:14 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarr.3 Log Message: reallocarr(3): Bump date. Note overflow is handled internally. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/lib/libc/stdlib/reallocarr.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Wed Aug 31 12:10:05 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarr.3 Log Message: reallocarr(3): Clarify semantics. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdlib/reallocarr.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/reallocarr.3 diff -u src/lib/libc/stdlib/reallocarr.3:1.4 src/lib/libc/stdlib/reallocarr.3:1.5 --- src/lib/libc/stdlib/reallocarr.3:1.4 Tue Jul 28 17:13:34 2015 +++ src/lib/libc/stdlib/reallocarr.3 Wed Aug 31 12:10:05 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: reallocarr.3,v 1.4 2015/07/28 17:13:34 kamil Exp $ +.\" $NetBSD: reallocarr.3,v 1.5 2022/08/31 12:10:05 riastradh Exp $ .\" .\" Copyright (c) 2015 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -36,41 +36,117 @@ .In stdlib.h .Ft int .Fo reallocarr -.Fa "void *ptr" +.Fa "void *ptrp" .Fa "size_t number" .Fa "size_t size" .Fc .Sh DESCRIPTION The .Nm -function reallocates the memory in -.Fa *ptr . +function safely allocates, resizes, or frees arrays in memory. +.Pp +If +.Fa ptr +is a null pointer, or a pointer to memory previously allocated with +.Nm , +then +.Fo reallocarr +.Li & Ns Fa ptr , +.Fa number , +.Fa size +.Fc +allocates or reallocates the memory that +.Fa ptr +points to, possibly moving it to a different location in memory, so +that it has space for an array of +.Fa number +elements of +.Fa size +bytes apiece. +.Nm +updates +.Fa ptr +in case it was moved on success, and leaves it unchanged on failure. +.Pp +If +.Fa ptr +was previously allocated, the objects stored at +.Fa ptr Ns Li "[0]" , +.Fa ptr Ns Li "[1]" , +\&..., +up to the shorter of its old +.Fa number +and its new +.Fa number , +are copied into the new memory, like +.Xr realloc 3 . +.Pp +.Fa ptr +may be null and +.Fa number +may be zero. +.Fa size +must be nonzero. +.Pp +The memory allocated by +.Nm +may be freed with +.Fo reallocarr +.Li & Ns Fa ptr , +.Li 0 , +.Fa size +.Fc , +which will always succeed and unconditionally set +.Fa ptr +to null. +.Pp +The +.Nm +function may alter +.Va errno +as a side effect. +.Pp +Note that the argument +.Fa ptrp +is a pointer to a pointer to allocated memory, unlike +.Xr realloc +which takes a pointer to allocated memory. .Sh RETURN VALUES On successful completion, -.Fn +.Nm returns 0 and updates -.Fa *ptr . -Otherwise, an error code (see -.Xr errno 2 ) -is returned and -.Fa *ptr -and the referenced memory is unmodified. +.Fa ptr . +Otherwise, an +.Xr errno 2 +is returned, and +.Fa ptr +and the memory it points to are unmodified. .Sh EXAMPLES The following uses .Fn reallocarr -to initialize an array of INITSIZE integers, then -resizes it to NEWSIZE elements: +to initialize an array of +.Dv INITSIZE +integers, then +resizes it to +.Dv NEWSIZE +elements, and finally frees it: .Bd -literal -offset indent int *data = NULL; -int ret = 0; - -ret = reallocarr(, INITSIZE, sizeof(*data)); -if (ret) -errc(1, ret, "reallocarr failed"); +int error = 0; -ret = reallocarr(, NEWSIZE, sizeof(*data)); -if (ret) -errc(1, ret, "reallocarr failed on resize"); +/* allocate */ +error = reallocarr(, INITSIZE, sizeof(*data)); +if (error) + errc(1, error, "reallocarr failed"); +\&... +/* resize */ +error = reallocarr(, NEWSIZE, sizeof(*data)); +if (error) + errc(1, error, "reallocarr failed on resize"); +\&... +/* free */ +(void)reallocarr(, 0, sizeof(*data)); +assert(data == NULL); .Ed .Sh SEE ALSO .Xr calloc 3
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Wed Aug 31 12:10:05 UTC 2022 Modified Files: src/lib/libc/stdlib: reallocarr.3 Log Message: reallocarr(3): Clarify semantics. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdlib/reallocarr.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Thu Aug 18 11:05:02 UTC 2022 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: fix whitespace prefix behavior To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdlib/strfmon.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/strfmon.c diff -u src/lib/libc/stdlib/strfmon.c:1.17 src/lib/libc/stdlib/strfmon.c:1.18 --- src/lib/libc/stdlib/strfmon.c:1.17 Wed Aug 17 05:32:56 2022 +++ src/lib/libc/stdlib/strfmon.c Thu Aug 18 07:05:02 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: strfmon.c,v 1.17 2022/08/17 09:32:56 christos Exp $ */ +/* $NetBSD: strfmon.c,v 1.18 2022/08/18 11:05:02 christos Exp $ */ /*- * Copyright (c) 2001 Alexey Zelkin @@ -32,7 +32,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); #else -__RCSID("$NetBSD: strfmon.c,v 1.17 2022/08/17 09:32:56 christos Exp $"); +__RCSID("$NetBSD: strfmon.c,v 1.18 2022/08/18 11:05:02 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -454,7 +454,7 @@ __setup_vars(struct lconv *lc, int flags if (*cs_precedes != 0) *cs_precedes = 1; if ((unsigned char)*sep_by_space == NBCHAR_MAX) - *sep_by_space = 0; + *sep_by_space = 1; if ((unsigned char)*sign_posn == NBCHAR_MAX) *sign_posn = 0; }
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Thu Aug 18 11:05:02 UTC 2022 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: fix whitespace prefix behavior To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/lib/libc/stdlib/strfmon.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Wed Aug 17 09:32:56 UTC 2022 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: PR/56967: John Zaitseff: Reduce diff with FreeBSD, fixes various bugs. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdlib/strfmon.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/strfmon.c diff -u src/lib/libc/stdlib/strfmon.c:1.16 src/lib/libc/stdlib/strfmon.c:1.17 --- src/lib/libc/stdlib/strfmon.c:1.16 Mon May 23 15:21:30 2022 +++ src/lib/libc/stdlib/strfmon.c Wed Aug 17 05:32:56 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: strfmon.c,v 1.16 2022/05/23 19:21:30 andvar Exp $ */ +/* $NetBSD: strfmon.c,v 1.17 2022/08/17 09:32:56 christos Exp $ */ /*- * Copyright (c) 2001 Alexey Zelkin @@ -32,7 +32,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.14 2003/03/20 08:18:55 ache Exp $"); #else -__RCSID("$NetBSD: strfmon.c,v 1.16 2022/05/23 19:21:30 andvar Exp $"); +__RCSID("$NetBSD: strfmon.c,v 1.17 2022/08/17 09:32:56 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -100,7 +100,8 @@ __RCSID("$NetBSD: strfmon.c,v 1.16 2022/ } while (0) #define GRPSEP do { \ - *--bufend = thousands_sep;\ + bufend -= thousands_sep_size;\ + memcpy(bufend, thousands_sep, thousands_sep_size); \ groups++; \ } while (0) @@ -215,6 +216,8 @@ vstrfmon_l(char * __restrict s, size_t m if (!isdigit((unsigned char)*++fmt)) goto format_error; GET_NUMBER(left_prec); + if ((unsigned int)left_prec >= maxsize - (dst - s)) +goto e2big_error; } /* Right precision */ @@ -222,6 +225,9 @@ vstrfmon_l(char * __restrict s, size_t m if (!isdigit((unsigned char)*++fmt)) goto format_error; GET_NUMBER(right_prec); + if ((unsigned int)right_prec >= maxsize - (dst - s) - + left_prec) +goto e2big_error; } /* Conversion Characters */ @@ -271,6 +277,8 @@ vstrfmon_l(char * __restrict s, size_t m pad_size = 0; } + if (asciivalue != NULL) + free(asciivalue); asciivalue = __format_grouped_double(lc, value, , left_prec, right_prec, pad_char); if (asciivalue == NULL) @@ -422,7 +430,7 @@ __setup_vars(struct lconv *lc, int flags *cs_precedes = lc->int_n_cs_precedes; *sep_by_space = lc->int_n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->int_n_sign_posn; - *signstr = (*lc->negative_sign == '\0') ? "-" + *signstr = (lc->negative_sign[0] == '\0') ? "-" : lc->negative_sign; } else if (flags & USE_INTL_CURRENCY) { *cs_precedes = lc->int_p_cs_precedes; @@ -433,7 +441,7 @@ __setup_vars(struct lconv *lc, int flags *cs_precedes = lc->n_cs_precedes; *sep_by_space = lc->n_sep_by_space; *sign_posn = (flags & PARENTH_POSN) ? 0 : lc->n_sign_posn; - *signstr = (*lc->negative_sign == '\0') ? "-" + *signstr = (lc->negative_sign[0] == '\0') ? "-" : lc->negative_sign; } else { *cs_precedes = lc->p_cs_precedes; @@ -446,7 +454,7 @@ __setup_vars(struct lconv *lc, int flags if (*cs_precedes != 0) *cs_precedes = 1; if ((unsigned char)*sep_by_space == NBCHAR_MAX) - *sep_by_space = 1; + *sep_by_space = 0; if ((unsigned char)*sign_posn == NBCHAR_MAX) *sign_posn = 0; } @@ -502,7 +510,7 @@ get_groups(int size, char *grouping) { return (chars); } -/* convert double to ASCII */ +/* convert double to locale-encoded string */ static char * __format_grouped_double(struct lconv *lc, double value, int *flags, int left_prec, int right_prec, int pad_char) { @@ -517,18 +525,23 @@ __format_grouped_double(struct lconv *lc int padded; char *grouping; - char decimal_point; - char thousands_sep; + const char *decimal_point; + const char *thousands_sep; + size_t decimal_point_size; + size_t thousands_sep_size; int groups = 0; grouping = lc->mon_grouping; - decimal_point = *lc->mon_decimal_point; - if (decimal_point == '\0') - decimal_point = *lc->decimal_point; - thousands_sep = *lc->mon_thousands_sep; - if (thousands_sep == '\0') - thousands_sep = *lc->thousands_sep; + decimal_point = lc->mon_decimal_point; + if (*decimal_point == '\0') + decimal_point = lc->decimal_point; + thousands_sep = lc->mon_thousands_sep; + if (*thousands_sep == '\0') + thousands_sep = lc->thousands_sep; + + decimal_point_size = strlen(decimal_point); + thousands_sep_size = strlen(thousands_sep); /* fill left_prec with default value */ if (left_prec == -1) @@ -555,7 +568,8 @@ __format_grouped_double(struct lconv *lc return (NULL); /* make sure that we've enough space for result string */ - bufsize = avalue_size * 2 + 1; + bufsize = avalue_size * (1 + thousands_sep_size) + decimal_point_size + + 1; rslt = calloc(1, bufsize); if (rslt == NULL) { free(avalue); @@ -574,13 +588,13 @@ __format_grouped_double(struct lconv *lc bufend -= right_prec; memcpy(bufend, avalue +
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Wed Aug 17 09:32:56 UTC 2022 Modified Files: src/lib/libc/stdlib: strfmon.c Log Message: PR/56967: John Zaitseff: Reduce diff with FreeBSD, fixes various bugs. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/lib/libc/stdlib/strfmon.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Mon Mar 14 22:14:19 UTC 2022 Modified Files: src/lib/libc/stdlib: system.c Log Message: system(3): Simplify initialization of argp. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdlib/system.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/system.c diff -u src/lib/libc/stdlib/system.c:1.27 src/lib/libc/stdlib/system.c:1.28 --- src/lib/libc/stdlib/system.c:1.27 Mon Mar 14 22:06:28 2022 +++ src/lib/libc/stdlib/system.c Mon Mar 14 22:14:19 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: system.c,v 1.27 2022/03/14 22:06:28 riastradh Exp $ */ +/* $NetBSD: system.c,v 1.28 2022/03/14 22:14:19 riastradh Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: system.c,v 1.27 2022/03/14 22:06:28 riastradh Exp $"); +__RCSID("$NetBSD: system.c,v 1.28 2022/03/14 22:14:19 riastradh Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -57,12 +57,10 @@ system(const char *command) struct sigaction intsa, quitsa, sa; sigset_t nmask, omask, sigdefault; int pstat; - const char *argp[] = {"sh", "-c", "--", NULL, NULL}; + const char *argp[] = {"sh", "-c", "--", command, NULL}; posix_spawnattr_t attr; int error; - argp[3] = command; - /* * ISO/IEC 9899:1999 in 7.20.4.6 describes this special case. * We need to check availability of a command interpreter.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Mon Mar 14 22:14:19 UTC 2022 Modified Files: src/lib/libc/stdlib: system.c Log Message: system(3): Simplify initialization of argp. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/lib/libc/stdlib/system.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Mon Mar 14 22:06:28 UTC 2022 Modified Files: src/lib/libc/stdlib: system.c Log Message: system(3): Switch from vfork/execve to posix_spawn. Changes by me: - Minor style nits. - Set errno on posix_spawn failure. - Handle edge cases of SIGINT/SIGQUIT set to SIG_IGN by caller. Author: Nikita Ronja Gillmann Committer: Taylor R Campbell To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdlib/system.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: riastradh Date: Mon Mar 14 22:06:28 UTC 2022 Modified Files: src/lib/libc/stdlib: system.c Log Message: system(3): Switch from vfork/execve to posix_spawn. Changes by me: - Minor style nits. - Set errno on posix_spawn failure. - Handle edge cases of SIGINT/SIGQUIT set to SIG_IGN by caller. Author: Nikita Ronja Gillmann Committer: Taylor R Campbell To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/lib/libc/stdlib/system.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/system.c diff -u src/lib/libc/stdlib/system.c:1.26 src/lib/libc/stdlib/system.c:1.27 --- src/lib/libc/stdlib/system.c:1.26 Fri Oct 29 19:27:06 2021 +++ src/lib/libc/stdlib/system.c Mon Mar 14 22:06:28 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: system.c,v 1.26 2021/10/29 19:27:06 kre Exp $ */ +/* $NetBSD: system.c,v 1.27 2022/03/14 22:06:28 riastradh Exp $ */ /* * Copyright (c) 1988, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: system.c,v 1.26 2021/10/29 19:27:06 kre Exp $"); +__RCSID("$NetBSD: system.c,v 1.27 2022/03/14 22:06:28 riastradh Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -46,6 +46,7 @@ __RCSID("$NetBSD: system.c,v 1.26 2021/1 #include #include #include +#include #include "env.h" @@ -54,9 +55,12 @@ system(const char *command) { pid_t pid; struct sigaction intsa, quitsa, sa; - sigset_t nmask, omask; + sigset_t nmask, omask, sigdefault; int pstat; const char *argp[] = {"sh", "-c", "--", NULL, NULL}; + posix_spawnattr_t attr; + int error; + argp[3] = command; /* @@ -88,22 +92,41 @@ system(const char *command) return -1; } + /* + * We arrange to inherit all signal handlers from the caller by + * default, except possibly SIGINT and SIGQUIT. These we have + * overridden internally for system(3) to be SIG_IGN. + * + * - If the caller had SIGINT or SIGQUIT at SIG_IGN, then we + * inherit them as is -- caller had SIG_IGN, child will too. + * + * - Otherwise, they are SIG_DFL or a signal handler, and we + * must reset them to SIG_DFL in the child, rather than + * SIG_IGN in system(3) in the parent, by including them in + * the sigdefault set. + */ + sigemptyset(); + if (intsa.sa_handler != SIG_IGN) + sigaddset(, SIGINT); + if (quitsa.sa_handler != SIG_IGN) + sigaddset(, SIGQUIT); + + posix_spawnattr_init(); + posix_spawnattr_setsigdefault(, ); + posix_spawnattr_setsigmask(, ); + posix_spawnattr_setflags(, + POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK); (void)__readlockenv(); - switch(pid = vfork()) { - case -1: /* error */ - (void)__unlockenv(); - sigaction(SIGINT, , NULL); - sigaction(SIGQUIT, , NULL); - (void)sigprocmask(SIG_SETMASK, , NULL); - return -1; - case 0:/* child */ - sigaction(SIGINT, , NULL); - sigaction(SIGQUIT, , NULL); - (void)sigprocmask(SIG_SETMASK, , NULL); - execve(_PATH_BSHELL, __UNCONST(argp), environ); - _exit(127); - } + error = posix_spawn(, _PATH_BSHELL, NULL, , __UNCONST(argp), + environ); (void)__unlockenv(); + posix_spawnattr_destroy(); + + if (error) { + errno = error; + pstat = -1; + goto out; + } while (waitpid(pid, , 0) == -1) { if (errno != EINTR) { @@ -112,7 +135,7 @@ system(const char *command) } } - sigaction(SIGINT, , NULL); +out: sigaction(SIGINT, , NULL); sigaction(SIGQUIT, , NULL); (void)sigprocmask(SIG_SETMASK, , NULL);
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: kre Date: Sun Mar 13 01:44:37 UTC 2022 Modified Files: src/lib/libc/stdlib: hcreate.c Log Message: Avoid referencing uninit'd memory. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdlib/hcreate.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/hcreate.c diff -u src/lib/libc/stdlib/hcreate.c:1.12 src/lib/libc/stdlib/hcreate.c:1.13 --- src/lib/libc/stdlib/hcreate.c:1.12 Sat Mar 12 17:31:39 2022 +++ src/lib/libc/stdlib/hcreate.c Sun Mar 13 01:44:37 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: hcreate.c,v 1.12 2022/03/12 17:31:39 christos Exp $ */ +/* $NetBSD: hcreate.c,v 1.13 2022/03/13 01:44:37 kre Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou @@ -43,7 +43,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: hcreate.c,v 1.12 2022/03/12 17:31:39 christos Exp $"); +__RCSID("$NetBSD: hcreate.c,v 1.13 2022/03/13 01:44:37 kre Exp $"); #endif /* LIBC_SCCS and not lint */ #if !defined(lint) @@ -124,6 +124,7 @@ hcreate_r(size_t nel, struct hsearch_dat /* Allocate the table. */ head->size = nel; head->filled = 0; + table = NULL; errno = reallocarr(, nel, sizeof(*table)); if (errno) return 0;
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: kre Date: Sun Mar 13 01:44:37 UTC 2022 Modified Files: src/lib/libc/stdlib: hcreate.c Log Message: Avoid referencing uninit'd memory. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdlib/hcreate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/lib/libc/stdlib
On Sat, 12 Mar 2022 08:26:01 + Nia Alarie wrote: > Module Name: src > Committed By: nia > Date: Sat Mar 12 08:26:01 UTC 2022 > > Modified Files: > src/lib/libc/stdlib: hcreate.c > > Log Message: > hcreate(3): use reallocarr instead of malloc(x * y) Caution: malloc(0) and reallocarr(, 0, s) have different semantics for the returned pointer value.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: nia Date: Sat Mar 12 08:44:39 UTC 2022 Modified Files: src/lib/libc/stdlib: _env.c Log Message: _env: use reallocarr To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdlib/_env.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/_env.c diff -u src/lib/libc/stdlib/_env.c:1.11 src/lib/libc/stdlib/_env.c:1.12 --- src/lib/libc/stdlib/_env.c:1.11 Tue Apr 20 21:42:32 2021 +++ src/lib/libc/stdlib/_env.c Sat Mar 12 08:44:38 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: _env.c,v 1.11 2021/04/20 21:42:32 christos Exp $ */ +/* $NetBSD: _env.c,v 1.12 2022/03/12 08:44:38 nia Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _env.c,v 1.11 2021/04/20 21:42:32 christos Exp $"); +__RCSID("$NetBSD: _env.c,v 1.12 2022/03/12 08:44:38 nia Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -296,18 +296,23 @@ __getenvslot(const char *name, size_t l_ /* Allocate a new environment array. */ if (environ == allocated_environ) { - new_environ = realloc(environ, - new_size * sizeof(*new_environ)); - if (new_environ == NULL) + new_environ = environ; + if (reallocarr(_environ, + new_size, sizeof(*new_environ)) != 0) { + errno = ENOMEM; return -1; + } } else { free(allocated_environ); allocated_environ = NULL; allocated_environ_size = 0; - new_environ = malloc(new_size * sizeof(*new_environ)); - if (new_environ == NULL) + new_environ = NULL; + if (reallocarr(_environ, + new_size, sizeof(*new_environ)) != 0) { + errno = ENOMEM; return -1; + } (void)memcpy(new_environ, environ, num_entries * sizeof(*new_environ)); }
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: nia Date: Sat Mar 12 08:44:39 UTC 2022 Modified Files: src/lib/libc/stdlib: _env.c Log Message: _env: use reallocarr To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/lib/libc/stdlib/_env.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: nia Date: Sat Mar 12 08:26:01 UTC 2022 Modified Files: src/lib/libc/stdlib: hcreate.c Log Message: hcreate(3): use reallocarr instead of malloc(x * y) To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/hcreate.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/hcreate.c diff -u src/lib/libc/stdlib/hcreate.c:1.10 src/lib/libc/stdlib/hcreate.c:1.11 --- src/lib/libc/stdlib/hcreate.c:1.10 Sun Jul 20 20:17:21 2014 +++ src/lib/libc/stdlib/hcreate.c Sat Mar 12 08:26:01 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: hcreate.c,v 1.10 2014/07/20 20:17:21 christos Exp $ */ +/* $NetBSD: hcreate.c,v 1.11 2022/03/12 08:26:01 nia Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou @@ -43,7 +43,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: hcreate.c,v 1.10 2014/07/20 20:17:21 christos Exp $"); +__RCSID("$NetBSD: hcreate.c,v 1.11 2022/03/12 08:26:01 nia Exp $"); #endif /* LIBC_SCCS and not lint */ #if !defined(lint) @@ -125,8 +125,8 @@ hcreate_r(size_t nel, struct hsearch_dat /* Allocate the table. */ head->size = nel; head->filled = 0; - p = malloc(nel * sizeof table[0]); - if (p == NULL) { + p = NULL; + if (reallocarr(, nel, sizeof(table[0])) != 0) { errno = ENOMEM; return 0; }
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: nia Date: Sat Mar 12 08:26:01 UTC 2022 Modified Files: src/lib/libc/stdlib: hcreate.c Log Message: hcreate(3): use reallocarr instead of malloc(x * y) To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/hcreate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Re: CVS commit: src/lib/libc/stdlib
On Sat, Feb 12, 2022, 11:52 AM Taylor R Campbell < campbell+netbsd-source-change...@mumble.net> wrote: > > Date: Sun, 13 Feb 2022 05:44:38 +1100 > > from: matthew green > > > > "Roland Illig" writes: > > > Module Name:src > > > Committed By: rillig > > > Date: Fri Feb 11 21:36:46 UTC 2022 > > > > > > Modified Files: > > > src/lib/libc/stdlib: getenv.c > > > > > > Log Message: > > > libc/getenv: remove trailing whitespace > > > > > > No binary change. > > > > please avoid purely whitespace changes unless you're > > also going to be modifying the code itself. > > > > (don't back out now.) > > I thought we were supposed to _avoid_ mixing whitespace changes and > functional changes? > > (Obviously the solution is to just only ever commit code with perfect > style to begin with so this is never an issue! Speaking of which, > (setq show-trailing-whitespace t) is helpful to avoid this kind of > mistake up front. git diff or git add -p will also flag this kind of > mistake, if you're working in git. /usr/share/misc/NetBSD.el is also > helpful for other KNF style.) > I thought the rule was don't make purely whitespace changes UNLESS you plan on making other changes to (or are fixing an oops you just made). If that's the case, separate the two commits. Warner >
Re: CVS commit: src/lib/libc/stdlib
Am 12.02.2022 um 20:10 schrieb Warner Losh: I thought the rule was don't make purely whitespace changes UNLESS you plan on making other changes to (or are fixing an oops you just made). If that's the case, separate the two commits. That sounds like a useful rule, I'll stick to it. Roland
Re: CVS commit: src/lib/libc/stdlib
> Date: Sun, 13 Feb 2022 05:44:38 +1100 > from: matthew green > > "Roland Illig" writes: > > Module Name:src > > Committed By: rillig > > Date: Fri Feb 11 21:36:46 UTC 2022 > > > > Modified Files: > > src/lib/libc/stdlib: getenv.c > > > > Log Message: > > libc/getenv: remove trailing whitespace > > > > No binary change. > > please avoid purely whitespace changes unless you're > also going to be modifying the code itself. > > (don't back out now.) I thought we were supposed to _avoid_ mixing whitespace changes and functional changes? (Obviously the solution is to just only ever commit code with perfect style to begin with so this is never an issue! Speaking of which, (setq show-trailing-whitespace t) is helpful to avoid this kind of mistake up front. git diff or git add -p will also flag this kind of mistake, if you're working in git. /usr/share/misc/NetBSD.el is also helpful for other KNF style.)
re: CVS commit: src/lib/libc/stdlib
"Roland Illig" writes: > Module Name: src > Committed By: rillig > Date: Fri Feb 11 21:36:46 UTC 2022 > > Modified Files: > src/lib/libc/stdlib: getenv.c > > Log Message: > libc/getenv: remove trailing whitespace > > No binary change. please avoid purely whitespace changes unless you're also going to be modifying the code itself. (don't back out now.) thanks. .mrg.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: rillig Date: Fri Feb 11 21:36:46 UTC 2022 Modified Files: src/lib/libc/stdlib: getenv.c Log Message: libc/getenv: remove trailing whitespace No binary change. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/lib/libc/stdlib/getenv.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: rillig Date: Fri Feb 11 21:36:46 UTC 2022 Modified Files: src/lib/libc/stdlib: getenv.c Log Message: libc/getenv: remove trailing whitespace No binary change. To generate a diff of this commit: cvs rdiff -u -r1.36 -r1.37 src/lib/libc/stdlib/getenv.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/getenv.c diff -u src/lib/libc/stdlib/getenv.c:1.36 src/lib/libc/stdlib/getenv.c:1.37 --- src/lib/libc/stdlib/getenv.c:1.36 Tue Jan 20 18:31:25 2015 +++ src/lib/libc/stdlib/getenv.c Fri Feb 11 21:36:46 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: getenv.c,v 1.36 2015/01/20 18:31:25 christos Exp $ */ +/* $NetBSD: getenv.c,v 1.37 2022/02/11 21:36:46 rillig Exp $ */ /* * Copyright (c) 1987, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)getenv.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: getenv.c,v 1.36 2015/01/20 18:31:25 christos Exp $"); +__RCSID("$NetBSD: getenv.c,v 1.37 2022/02/11 21:36:46 rillig Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -73,7 +73,7 @@ getenv(const char *name) result = __findenvvar(name, l_name); (void)__unlockenv(); } - + return result; } @@ -107,6 +107,6 @@ getenv_r(const char *name, char *buf, si } (void)__unlockenv(); } - + return rv; }
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: uwe Date: Tue Jan 4 19:36:16 UTC 2022 Modified Files: src/lib/libc/stdlib: getopt_long.3 Log Message: getopt_long(3): "index" is an argument, not a field. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/lib/libc/stdlib/getopt_long.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: uwe Date: Tue Jan 4 19:36:16 UTC 2022 Modified Files: src/lib/libc/stdlib: getopt_long.3 Log Message: getopt_long(3): "index" is an argument, not a field. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/lib/libc/stdlib/getopt_long.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/getopt_long.3 diff -u src/lib/libc/stdlib/getopt_long.3:1.21 src/lib/libc/stdlib/getopt_long.3:1.22 --- src/lib/libc/stdlib/getopt_long.3:1.21 Tue Jan 4 19:32:16 2022 +++ src/lib/libc/stdlib/getopt_long.3 Tue Jan 4 19:36:16 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: getopt_long.3,v 1.21 2022/01/04 19:32:16 uwe Exp $ +.\" $NetBSD: getopt_long.3,v 1.22 2022/01/04 19:36:16 uwe Exp $ .\" .\" Copyright (c) 1988, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -146,7 +146,7 @@ like .Pp If the .Fa index -field is not +argument is not .Dv NULL , the integer it points to will be set to the index of the long option in the
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: uwe Date: Tue Jan 4 19:32:16 UTC 2022 Modified Files: src/lib/libc/stdlib: getopt_long.3 Log Message: getopt_long(3): use NULL, not 0, for flag in the example. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdlib/getopt_long.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: uwe Date: Tue Jan 4 19:32:16 UTC 2022 Modified Files: src/lib/libc/stdlib: getopt_long.3 Log Message: getopt_long(3): use NULL, not 0, for flag in the example. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/lib/libc/stdlib/getopt_long.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/getopt_long.3 diff -u src/lib/libc/stdlib/getopt_long.3:1.20 src/lib/libc/stdlib/getopt_long.3:1.21 --- src/lib/libc/stdlib/getopt_long.3:1.20 Sun Dec 9 20:29:53 2018 +++ src/lib/libc/stdlib/getopt_long.3 Tue Jan 4 19:32:16 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: getopt_long.3,v 1.20 2018/12/09 20:29:53 christos Exp $ +.\" $NetBSD: getopt_long.3,v 1.21 2022/01/04 19:32:16 uwe Exp $ .\" .\" Copyright (c) 1988, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -167,8 +167,8 @@ int daggerset; /* options descriptor */ static struct option longopts[] = { - { "buffy", no_argument, 0, 'b' }, - { "fluoride", required_argument, 0, 'f' }, + { "buffy", no_argument, NULL, 'b' }, + { "fluoride", required_argument, NULL, 'f' }, { "daggerset", no_argument, , 1 }, { NULL, 0, NULL, 0 } };
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: uwe Date: Sun Jan 2 03:46:40 UTC 2022 Modified Files: src/lib/libc/stdlib: ptsname.3 Log Message: ptsname(3): fix equivalence example The buffer is static, don't make it appear that we are returning a pointer to a local variable. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdlib/ptsname.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/ptsname.3 diff -u src/lib/libc/stdlib/ptsname.3:1.12 src/lib/libc/stdlib/ptsname.3:1.13 --- src/lib/libc/stdlib/ptsname.3:1.12 Wed Feb 7 11:16:05 2018 +++ src/lib/libc/stdlib/ptsname.3 Sun Jan 2 03:46:40 2022 @@ -1,4 +1,4 @@ -.\" $NetBSD: ptsname.3,v 1.12 2018/02/07 11:16:05 pgoyette Exp $ +.\" $NetBSD: ptsname.3,v 1.13 2022/01/02 03:46:40 uwe Exp $ .\" .\" Copyright (c) 2004 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd February 7, 2018 +.Dd January 2, 2022 .Dt PTSNAME 3 .Os .Sh NAME @@ -136,7 +136,7 @@ The .Fn ptsname function is equivalent to: .Bd -literal - struct ptmget pm; + static struct ptmget pm; return ioctl(masterfd, TIOCPTSNAME, ) == -1 ? NULL : pm.sn; .Ed .Pp
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: uwe Date: Sun Jan 2 03:46:40 UTC 2022 Modified Files: src/lib/libc/stdlib: ptsname.3 Log Message: ptsname(3): fix equivalence example The buffer is static, don't make it appear that we are returning a pointer to a local variable. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/lib/libc/stdlib/ptsname.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: rillig Date: Sun Dec 5 14:25:04 UTC 2021 Modified Files: src/lib/libc/stdlib: jemalloc.3 Log Message: jemalloc.3: fix malformed CVS Id To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/jemalloc.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: rillig Date: Sun Dec 5 14:25:04 UTC 2021 Modified Files: src/lib/libc/stdlib: jemalloc.3 Log Message: jemalloc.3: fix malformed CVS Id To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/jemalloc.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/jemalloc.3 diff -u src/lib/libc/stdlib/jemalloc.3:1.10 src/lib/libc/stdlib/jemalloc.3:1.11 --- src/lib/libc/stdlib/jemalloc.3:1.10 Wed Oct 25 17:09:47 2017 +++ src/lib/libc/stdlib/jemalloc.3 Sun Dec 5 14:25:04 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD $ +.\" $NetBSD: jemalloc.3,v 1.11 2021/12/05 14:25:04 rillig Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: nia Date: Fri Oct 29 10:29:51 UTC 2021 Modified Files: src/lib/libc/stdlib: radixsort.c Log Message: radixsort(3): use reallocarr instead of malloc(x * y) To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdlib/radixsort.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/radixsort.c diff -u src/lib/libc/stdlib/radixsort.c:1.19 src/lib/libc/stdlib/radixsort.c:1.20 --- src/lib/libc/stdlib/radixsort.c:1.19 Sat Sep 5 08:53:06 2009 +++ src/lib/libc/stdlib/radixsort.c Fri Oct 29 10:29:51 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: radixsort.c,v 1.19 2009/09/05 08:53:06 dsl Exp $ */ +/* $NetBSD: radixsort.c,v 1.20 2021/10/29 10:29:51 nia Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)radixsort.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: radixsort.c,v 1.19 2009/09/05 08:53:06 dsl Exp $"); +__RCSID("$NetBSD: radixsort.c,v 1.20 2021/10/29 10:29:51 nia Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -129,7 +129,8 @@ sradixsort(const u_char **a, int n, cons if (n < THRESHOLD) simplesort(a, n, 0, tr, endch); else { - if ((ta = malloc(n * sizeof(a))) == NULL) + ta = NULL; + if (reallocarr(, n, sizeof(a)) != 0) return (-1); r_sort_b(a, ta, n, 0, tr, endch); free(ta);
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: nia Date: Fri Oct 29 10:29:51 UTC 2021 Modified Files: src/lib/libc/stdlib: radixsort.c Log Message: radixsort(3): use reallocarr instead of malloc(x * y) To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/lib/libc/stdlib/radixsort.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Mon Aug 30 13:12:16 UTC 2021 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Remove lint workarounds To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 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.53 src/lib/libc/stdlib/jemalloc.c:1.54 --- src/lib/libc/stdlib/jemalloc.c:1.53 Fri May 15 10:37:21 2020 +++ src/lib/libc/stdlib/jemalloc.c Mon Aug 30 09:12:16 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: jemalloc.c,v 1.53 2020/05/15 14:37:21 joerg Exp $ */ +/* $NetBSD: jemalloc.c,v 1.54 2021/08/30 13:12:16 christos Exp $ */ /*- * Copyright (C) 2006,2007 Jason Evans . @@ -117,7 +117,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.53 2020/05/15 14:37:21 joerg Exp $"); +__RCSID("$NetBSD: jemalloc.c,v 1.54 2021/08/30 13:12:16 christos Exp $"); #ifdef __FreeBSD__ #include "libc_private.h" @@ -1276,7 +1276,6 @@ stats_print(arena_t *arena) * Begin chunk management functions. */ -#ifndef lint static inline int chunk_comp(chunk_node_t *a, chunk_node_t *b) { @@ -1293,8 +1292,7 @@ chunk_comp(chunk_node_t *a, chunk_node_t } /* Generate red-black tree code for chunks. */ -RB_GENERATE_STATIC(chunk_tree_s, chunk_node_s, link, chunk_comp); -#endif +RB_GENERATE_STATIC(chunk_tree_s, chunk_node_s, link, chunk_comp) static void * pages_map_align(void *addr, size_t size, int align) @@ -1371,18 +1369,15 @@ chunk_alloc(size_t size) * to use them. */ - /* LINTED */ tchunk = RB_MIN(chunk_tree_s, _chunks); while (tchunk != NULL) { /* Found an address range. Try to recycle it. */ chunk = tchunk->chunk; delchunk = tchunk; - /* LINTED */ tchunk = RB_NEXT(chunk_tree_s, _chunks, delchunk); /* Remove delchunk from the tree. */ - /* LINTED */ RB_REMOVE(chunk_tree_s, _chunks, delchunk); base_chunk_node_dealloc(delchunk); @@ -1465,15 +1460,12 @@ RETURN: * memory we just allocated. */ key.chunk = ret; - /* LINTED */ tchunk = RB_NFIND(chunk_tree_s, _chunks, ); while (tchunk != NULL && (uintptr_t)tchunk->chunk >= (uintptr_t)ret && (uintptr_t)tchunk->chunk < (uintptr_t)ret + size) { delchunk = tchunk; - /* LINTED */ tchunk = RB_NEXT(chunk_tree_s, _chunks, delchunk); - /* LINTED */ RB_REMOVE(chunk_tree_s, _chunks, delchunk); base_chunk_node_dealloc(delchunk); } @@ -1551,7 +1543,6 @@ chunk_dealloc(void *chunk, size_t size) node->chunk = (void *)((uintptr_t)chunk + (uintptr_t)offset); node->size = chunksize; -/* LINTED */ RB_INSERT(chunk_tree_s, _chunks, node); } } @@ -1571,7 +1562,6 @@ chunk_dealloc(void *chunk, size_t size) if (node != NULL) { node->chunk = (void *)(uintptr_t)chunk; node->size = chunksize; -/* LINTED */ RB_INSERT(chunk_tree_s, _chunks, node); } } @@ -1644,7 +1634,6 @@ choose_arena(void) return choose_arena_hard(); } -#ifndef lint static inline int arena_chunk_comp(arena_chunk_t *a, arena_chunk_t *b) { @@ -1666,10 +1655,8 @@ arena_chunk_comp(arena_chunk_t *a, arena } /* Generate red-black tree code for arena chunks. */ -RB_GENERATE_STATIC(arena_chunk_tree_s, arena_chunk_s, link, arena_chunk_comp); -#endif +RB_GENERATE_STATIC(arena_chunk_tree_s, arena_chunk_s, link, arena_chunk_comp) -#ifndef lint static inline int arena_run_comp(arena_run_t *a, arena_run_t *b) { @@ -1686,8 +1673,7 @@ arena_run_comp(arena_run_t *a, arena_run } /* Generate red-black tree code for arena runs. */ -RB_GENERATE_STATIC(arena_run_tree_s, arena_run_s, link, arena_run_comp); -#endif +RB_GENERATE_STATIC(arena_run_tree_s, arena_run_s, link, arena_run_comp) static inline void * arena_run_reg_alloc(arena_run_t *run, arena_bin_t *bin) @@ -1896,7 +1882,6 @@ arena_chunk_alloc(arena_t *arena) chunk = arena->spare; arena->spare = NULL; - /* LINTED */ RB_INSERT(arena_chunk_tree_s, >chunks, chunk); } else { chunk = (arena_chunk_t *)chunk_alloc(chunksize); @@ -1942,7 +1927,6 @@ arena_chunk_dealloc(arena_t *arena, aren * Remove chunk from the chunk tree, regardless of whether this chunk * will be cached, so that the arena does not use it. */ - /* LINTED */ RB_REMOVE(arena_chunk_tree_s, >arena->chunks, chunk); if (opt_hint == false) { @@ -2145,10 +2129,8 @@ arena_bin_nonfull_run_get(arena_t *arena unsigned i, remainder; /* Look for a usable run. */ - /* LINTED */ if ((run = RB_MIN(arena_run_tree_s, >runs)) != NULL) { /* run is guaranteed to have available space. */ - /* LINTED */ RB_REMOVE(arena_run_tree_s, >runs, run); #ifdef MALLOC_STATS bin->stats.reruns++; @@ -2621,7 +2603,6 @@ arena_dalloc(arena_t *arena,
CVS commit: src/lib/libc/stdlib
Module Name:src Committed By: christos Date: Mon Aug 30 13:12:16 UTC 2021 Modified Files: src/lib/libc/stdlib: jemalloc.c Log Message: Remove lint workarounds To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 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.
Re: CVS commit: src/lib/libc/stdlib
On Sun, Feb 23, 2020 at 10:57:28 +0100, Kamil Rytarowski wrote: > On 23.02.2020 08:46, Martin Husemann wrote: > > > Source code consistency is a very important stylistic plus, every break of > > that should be accompanied by a comment. > > Done. Thank you. -uwe
Re: CVS commit: src/lib/libc/stdlib
On 23.02.2020 08:46, Martin Husemann wrote: > On Sun, Feb 23, 2020 at 03:35:19AM +0100, Kamil Rytarowski wrote: >> Algorithm would be changed from calculating on 32bit numbers with signed >> integer overflows to an algorithm calculating on 64bit numbers. The >> __dorand48() function truncates the result to least significant 16bits >> only so it does not matter. I retained operations on 32bits avoiding >> changes of types for stylistic reasons. > > I am with uwe here - either it would not make any difference at all (on > 32bit architectures) or it would end up with the same results and would > make no performance difference (on 64 bit architectures), so going with > the consistent (unsigned long) would have been fine. > > Even better would be a cleanup to make it (uint32_t) everwhere, but of > course only after carefull examination. > > Source code consistency is a very important stylistic plus, every break of > that should be accompanied by a comment. > > Martin > Done. signature.asc Description: OpenPGP digital signature
Re: CVS commit: src/lib/libc/stdlib
On Sun, Feb 23, 2020 at 03:35:19AM +0100, Kamil Rytarowski wrote: > Algorithm would be changed from calculating on 32bit numbers with signed > integer overflows to an algorithm calculating on 64bit numbers. The > __dorand48() function truncates the result to least significant 16bits > only so it does not matter. I retained operations on 32bits avoiding > changes of types for stylistic reasons. I am with uwe here - either it would not make any difference at all (on 32bit architectures) or it would end up with the same results and would make no performance difference (on 64 bit architectures), so going with the consistent (unsigned long) would have been fine. Even better would be a cleanup to make it (uint32_t) everwhere, but of course only after carefull examination. Source code consistency is a very important stylistic plus, every break of that should be accompanied by a comment. Martin
Re: CVS commit: src/lib/libc/stdlib
On Sun, Feb 23, 2020 at 03:35:19 +0100, Kamil Rytarowski wrote: > On 23.02.2020 03:20, Valery Ushakov wrote: > > On Sun, Feb 23, 2020 at 02:51:49 +0100, Kamil Rytarowski wrote: > > > >> On 23.02.2020 02:29, Valery Ushakov wrote: > >>> On Sat, Feb 22, 2020 at 14:07:57 +, Kamil Rytarowski wrote: > >>> > Module Name: src > Committed By:kamil > Date:Sat Feb 22 14:07:57 UTC 2020 > > Modified Files: > src/lib/libc/stdlib: _rand48.c > > Log Message: > Avoid undefined behavior in the rand48(3) implementation > > Instead of implicid promotion to signed int, > explicitly cast the arguments to unsigned int. > >>> > >>> Please, please, please, pay at least some attention to what is going > >>> on around the code you are changing. > >>> > >>> If there's already code in this function that does: > >>> > >>>accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0]; > >>> > >>> then keep it consistent and don't do casts to a different type > >>> > >>>accu += (unsigned int) __rand48_mult[0] * (unsigned int) xseed[2]; > >> > >> cast to unsigned long still works, but changes algorithm. My change was > >> performed deliberately. On the other hand and according to local tests > >> the end-result for unsigned long produces the same reults as cast to > >> unsigned int and unsigned char so it does not matter. > > > > I cannot make sense of your answer. Does the cast to unsigned long > > there change the algorithm or does it produce the same result? If it > > produces the same result, then it should be used to be consistent with > > the rest of the code (or the rest of the code changed to use unsigned > > int). If it does change the result, there should be a comment > > explaining it. > > Algorithm would be changed from calculating on 32bit numbers with signed > integer overflows to an algorithm calculating on 64bit numbers. The > __dorand48() function truncates the result to least significant 16bits > only so it does not matter. I retained operations on 32bits avoiding > changes of types for stylistic reasons. That still doesn't make sense to me. You took your time to figure out whats going on in this bit of code. Then you make a change that looks extremely unobvious b/c it is inconsistent with the rest of the code, and you say you did this for stylistic reasons. The next person looking at that code (in $bignum years) will have to waste their time puzzling out the reason. Why not use the knowledge you've gained of this code for good and change the code properly? The 90s unsigned long was probably meant to be 32-bit anyway (cf. X11 mess up with using long for 32 bit quantities in the protocol and then running into issues when 64-bit happened). So if doing things in 32-bit here is the right and intended thing to do, then change that unsigned long to uint32_t. If you don't want to dive that deep (which is entirely understandable), then, exactly for stylistic reasons, cast to unsigned long to be consistent with the old code - as you already established that it didn't change the result. -uwe
Re: CVS commit: src/lib/libc/stdlib
On 23.02.2020 03:20, Valery Ushakov wrote: > On Sun, Feb 23, 2020 at 02:51:49 +0100, Kamil Rytarowski wrote: > >> On 23.02.2020 02:29, Valery Ushakov wrote: >>> On Sat, Feb 22, 2020 at 14:07:57 +, Kamil Rytarowski wrote: >>> Module Name: src Committed By: kamil Date: Sat Feb 22 14:07:57 UTC 2020 Modified Files: src/lib/libc/stdlib: _rand48.c Log Message: Avoid undefined behavior in the rand48(3) implementation Instead of implicid promotion to signed int, explicitly cast the arguments to unsigned int. >>> >>> Please, please, please, pay at least some attention to what is going >>> on around the code you are changing. >>> >>> If there's already code in this function that does: >>> >>>accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0]; >>> >>> then keep it consistent and don't do casts to a different type >>> >>>accu += (unsigned int) __rand48_mult[0] * (unsigned int) xseed[2]; >> >> cast to unsigned long still works, but changes algorithm. My change was >> performed deliberately. On the other hand and according to local tests >> the end-result for unsigned long produces the same reults as cast to >> unsigned int and unsigned char so it does not matter. > > I cannot make sense of your answer. Does the cast to unsigned long > there change the algorithm or does it produce the same result? If it > produces the same result, then it should be used to be consistent with > the rest of the code (or the rest of the code changed to use unsigned > int). If it does change the result, there should be a comment > explaining it. > > -uwe > Algorithm would be changed from calculating on 32bit numbers with signed integer overflows to an algorithm calculating on 64bit numbers. The __dorand48() function truncates the result to least significant 16bits only so it does not matter. I retained operations on 32bits avoiding changes of types for stylistic reasons. signature.asc Description: OpenPGP digital signature
Re: CVS commit: src/lib/libc/stdlib
On Sun, Feb 23, 2020 at 02:51:49 +0100, Kamil Rytarowski wrote: > On 23.02.2020 02:29, Valery Ushakov wrote: > > On Sat, Feb 22, 2020 at 14:07:57 +, Kamil Rytarowski wrote: > > > >> Module Name: src > >> Committed By: kamil > >> Date: Sat Feb 22 14:07:57 UTC 2020 > >> > >> Modified Files: > >>src/lib/libc/stdlib: _rand48.c > >> > >> Log Message: > >> Avoid undefined behavior in the rand48(3) implementation > >> > >> Instead of implicid promotion to signed int, > >> explicitly cast the arguments to unsigned int. > > > > Please, please, please, pay at least some attention to what is going > > on around the code you are changing. > > > > If there's already code in this function that does: > > > >accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0]; > > > > then keep it consistent and don't do casts to a different type > > > >accu += (unsigned int) __rand48_mult[0] * (unsigned int) xseed[2]; > > cast to unsigned long still works, but changes algorithm. My change was > performed deliberately. On the other hand and according to local tests > the end-result for unsigned long produces the same reults as cast to > unsigned int and unsigned char so it does not matter. I cannot make sense of your answer. Does the cast to unsigned long there change the algorithm or does it produce the same result? If it produces the same result, then it should be used to be consistent with the rest of the code (or the rest of the code changed to use unsigned int). If it does change the result, there should be a comment explaining it. -uwe
Re: CVS commit: src/lib/libc/stdlib
On 23.02.2020 02:29, Valery Ushakov wrote: > On Sat, Feb 22, 2020 at 14:07:57 +, Kamil Rytarowski wrote: > >> Module Name: src >> Committed By:kamil >> Date:Sat Feb 22 14:07:57 UTC 2020 >> >> Modified Files: >> src/lib/libc/stdlib: _rand48.c >> >> Log Message: >> Avoid undefined behavior in the rand48(3) implementation >> >> Instead of implicid promotion to signed int, >> explicitly cast the arguments to unsigned int. > > Please, please, please, pay at least some attention to what is going > on around the code you are changing. > > If there's already code in this function that does: > >accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0]; > > then keep it consistent and don't do casts to a different type > >accu += (unsigned int) __rand48_mult[0] * (unsigned int) xseed[2]; > > > -uwe > cast to unsigned long still works, but changes algorithm. My change was performed deliberately. On the other hand and according to local tests the end-result for unsigned long produces the same reults as cast to unsigned int and unsigned char so it does not matter. signature.asc Description: OpenPGP digital signature
Re: CVS commit: src/lib/libc/stdlib
On Sat, Feb 22, 2020 at 14:07:57 +, Kamil Rytarowski wrote: > Module Name: src > Committed By: kamil > Date: Sat Feb 22 14:07:57 UTC 2020 > > Modified Files: > src/lib/libc/stdlib: _rand48.c > > Log Message: > Avoid undefined behavior in the rand48(3) implementation > > Instead of implicid promotion to signed int, > explicitly cast the arguments to unsigned int. Please, please, please, pay at least some attention to what is going on around the code you are changing. If there's already code in this function that does: accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0]; then keep it consistent and don't do casts to a different type accu += (unsigned int) __rand48_mult[0] * (unsigned int) xseed[2]; -uwe