From nobody Sat Aug 1 03:35:28 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hBpVS6cncz6mlHT for ; Sat, 01 Aug 2026 03:35:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hBpVS5Zylz3F1M for ; Sat, 01 Aug 2026 03:35:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785555328; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=X9chtMoviiTSOaOSU9yCTmf+vozwwd95eWLkB/2zOlo=; b=BEBSEG8DWNhE1vdc81Xk+aY64loOoNhguxHks0j4hVl2cwUglGTg5TYB4sbLy6PyI2P0zQ qdCf5YG+8RUqRHXEuBx2t5QfOQjTSfixqaUYgyRQg4jOzuIPHqlBNhK4GQzJi8H8Ik3XmI 1HKguL8/SNQDgRePTq6wmyLTC/ipoDERhUXAo+cTvWifMx4mwmb15QMH/TQaeJzUbxotIU 3+jXLJbI0XDGWwZgKU9mmE/E6eSpkOnVtIqiG9EHW7fIw0wLRO4d6PSsyKqjt+gD1HRowO cXrfg9xDSmAlEAQUhBAlnvB1IuJZ+kCTIcr0P3anvPyhuNV8rURcNV30cyXjgA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1785555328; a=rsa-sha256; cv=none; b=ym+JZdjmEYyS4gWdt7oAVQCsQlxOqQWzR1qvAEGcMUG0Hr+7p11pE1EsCCbvlDyp/9+2wz ZnwaYc20CTHr8cJhtM/KJGQzvZpGmPpa2tO2VbUb0jwK1tzBd0jYnKOo6wBWckkntGuOTH 0iR2YGObVULMEggUSr1TWSaVMM5d+/zISgKcIC3eb+uVLQufAmSiXz0aHFI6KouNJ+Lr/I /wD9rBZKbG86Z4M9Sl/FVzL0Ra0LHrb5kJwb+gea2pT7GdsBzhiwc7butxjK+RiBYoK2Zp eYQZz9YZtmpvOd6QdMd4un5+oMAHtXXnYYhLh5I3W81i8MlxbGWocgZSA1GxwQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1785555328; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=X9chtMoviiTSOaOSU9yCTmf+vozwwd95eWLkB/2zOlo=; b=P+utmAao6BzjknVT1m/aky2xbiIAAfBX7oC8B3mgZP7IRzgX3aD+zEvwumfaAyxhvZEzby P3N3XK60fVMlX4AE3O0V3cfW4qPXk/fmw9GVlbxH6FHp8MjsU4CL6qhvYzZKuM87j1y638 rRXUP/MEb2YjZeSQUNjm/+8A1hQe/92zQxIvGAAW/jprMeHoj+ARc00geSaluegbVH/nEe 5V3v8QZJ5konW3OvhTB8nF/c3V8B3Fbiv/9gzutUkU0ms77YQtQtOH8r5qqe3Ikto4+Pyj HooBgHlVUyeUGtE8vm1OPBJSLazeFD88Qs4hPK7Rlim0GoKx+Oe/89WWUden5g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hBpVS3qpFzCV8 for ; Sat, 01 Aug 2026 03:35:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 32e43 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 01 Aug 2026 03:35:28 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 781defc7eb06 - main - stdio: *memstream: decouple the buffer size from the stream length List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 781defc7eb061a82b1e3e8dbc6b34993f23e79a6 Auto-Submitted: auto-generated Date: Sat, 01 Aug 2026 03:35:28 +0000 Message-Id: <6a6d6980.32e43.6cc900c9@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=781defc7eb061a82b1e3e8dbc6b34993f23e79a6 commit 781defc7eb061a82b1e3e8dbc6b34993f23e79a6 Author: Kyle Evans AuthorDate: 2026-08-01 03:34:37 +0000 Commit: Kyle Evans CommitDate: 2026-08-01 03:34:37 +0000 stdio: *memstream: decouple the buffer size from the stream length It's useful to be able to track both facts with a single variable, but it also makes it more difficult to change how the buffer size scales. As an example, Apple's implementation seems to scale the buffer size by 1.5x on growth, presumably in an attempt to reduce trips into realloc(). This might be questionable in the face of stdio buffering, but avoiding serious churn in the line- or un-buffered case is a net positive if doing so isn't incredibly invasive. Reviewed by: des, jhb, obiwac Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D57354 --- lib/libc/stdio/open_memstream.c | 13 +++++++++---- lib/libc/stdio/open_wmemstream.c | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c index 29de688376bf..d0a22bcfe59f 100644 --- a/lib/libc/stdio/open_memstream.c +++ b/lib/libc/stdio/open_memstream.c @@ -46,6 +46,7 @@ struct memstream { char **bufp; size_t *sizep; + size_t size; ssize_t len; fpos_t offset; }; @@ -60,19 +61,22 @@ memstream_grow(struct memstream *ms, fpos_t newoff) newsize = SSIZE_MAX - 1; else newsize = newoff; - if (newsize > ms->len) { + if (newsize > ms->size) { buf = realloc(*ms->bufp, newsize + 1); if (buf == NULL) return (0); #ifdef DEBUG fprintf(stderr, "MS: %p growing from %zd to %zd\n", - ms, ms->len, newsize); + ms, ms->size, newsize); #endif - memset(buf + ms->len + 1, 0, newsize - ms->len); + memset(buf + ms->size + 1, 0, newsize - ms->size); *ms->bufp = buf; - ms->len = newsize; + ms->size = newsize; } + + if (newsize > ms->len) + ms->len = newsize; return (1); } @@ -192,6 +196,7 @@ open_memstream(char **bufp, size_t *sizep) } ms->bufp = bufp; ms->sizep = sizep; + ms->size = 0; ms->len = 0; ms->offset = 0; memstream_update(ms); diff --git a/lib/libc/stdio/open_wmemstream.c b/lib/libc/stdio/open_wmemstream.c index 0bed4cff5d11..d1844e573b1b 100644 --- a/lib/libc/stdio/open_wmemstream.c +++ b/lib/libc/stdio/open_wmemstream.c @@ -46,6 +46,7 @@ struct wmemstream { wchar_t **bufp; size_t *sizep; + size_t size; ssize_t len; fpos_t offset; mbstate_t mbstate; @@ -61,18 +62,20 @@ wmemstream_grow(struct wmemstream *ms, fpos_t newoff) newsize = SSIZE_MAX / sizeof(wchar_t) - 1; else newsize = newoff; - if (newsize > ms->len) { + if (newsize > ms->size) { buf = reallocarray(*ms->bufp, newsize + 1, sizeof(wchar_t)); if (buf == NULL) return (0); #ifdef DEBUG fprintf(stderr, "WMS: %p growing from %zd to %zd\n", - ms, ms->len, newsize); + ms, ms->size, newsize); #endif - wmemset(buf + ms->len + 1, 0, newsize - ms->len); + wmemset(buf + ms->size + 1, 0, newsize - ms->size); *ms->bufp = buf; - ms->len = newsize; + ms->size = newsize; } + if (newsize > ms->len) + ms->len = newsize; return (1); } @@ -252,6 +255,7 @@ open_wmemstream(wchar_t **bufp, size_t *sizep) } ms->bufp = bufp; ms->sizep = sizep; + ms->size = 0; ms->len = 0; ms->offset = 0; memset(&ms->mbstate, 0, sizeof(mbstate_t));