From owner-freebsd-arch@freebsd.org Thu Jul 11 17:34:07 2019 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 48A5015D9933 for ; Thu, 11 Jul 2019 17:34:07 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id CE46F896AE for ; Thu, 11 Jul 2019 17:34:06 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: by mailman.ysv.freebsd.org (Postfix) id 8ECBF15D9932; Thu, 11 Jul 2019 17:34:06 +0000 (UTC) Delivered-To: arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 696BE15D9931 for ; Thu, 11 Jul 2019 17:34:06 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 090DD896AD; Thu, 11 Jul 2019 17:34:06 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro-4.local (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 7D50B1891E; Thu, 11 Jul 2019 17:34:05 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Subject: Re: expand_number(3) To: Phil Shafer Cc: arch@FreeBSD.org References: From: John Baldwin Openpgp: preference=signencrypt Autocrypt: addr=jhb@FreeBSD.org; keydata= mQGiBETQ+XcRBADMFybiq69u+fJRy/0wzqTNS8jFfWaBTs5/OfcV7wWezVmf9sgwn8TW0Dk0 c9MBl0pz+H01dA2ZSGZ5fXlmFIsee1WEzqeJzpiwd/pejPgSzXB9ijbLHZ2/E0jhGBcVy5Yo /Tw5+U/+laeYKu2xb0XPvM0zMNls1ah5OnP9a6Ql6wCgupaoMySb7DXm2LHD1Z9jTsHcAQMD /1jzh2BoHriy/Q2s4KzzjVp/mQO5DSm2z14BvbQRcXU48oAosHA1u3Wrov6LfPY+0U1tG47X 1BGfnQH+rNAaH0livoSBQ0IPI/8WfIW7ub4qV6HYwWKVqkDkqwcpmGNDbz3gfaDht6nsie5Z pcuCcul4M9CW7Md6zzyvktjnbz61BADGDCopfZC4of0Z3Ka0u8Wik6UJOuqShBt1WcFS8ya1 oB4rc4tXfSHyMF63aPUBMxHR5DXeH+EO2edoSwViDMqWk1jTnYza51rbGY+pebLQOVOxAY7k do5Ordl3wklBPMVEPWoZ61SdbcjhHVwaC5zfiskcxj5wwXd2E9qYlBqRg7QeSm9obiBCYWxk d2luIDxqaGJARnJlZUJTRC5vcmc+iGAEExECACAFAkTQ+awCGwMGCwkIBwMCBBUCCAMEFgID AQIeAQIXgAAKCRBy3lIGd+N/BI6RAJ9S97fvbME+3hxzE3JUyUZ6vTewDACdE1stFuSfqMvM jomvZdYxIYyTUpC5Ag0ERND5ghAIAPwsO0B7BL+bz8sLlLoQktGxXwXQfS5cInvL17Dsgnr3 1AKa94j9EnXQyPEj7u0d+LmEe6CGEGDh1OcGFTMVrof2ZzkSy4+FkZwMKJpTiqeaShMh+Goj XlwIMDxyADYvBIg3eN5YdFKaPQpfgSqhT+7El7w+wSZZD8pPQuLAnie5iz9C8iKy4/cMSOrH YUK/tO+Nhw8Jjlw94Ik0T80iEhI2t+XBVjwdfjbq3HrJ0ehqdBwukyeJRYKmbn298KOFQVHO EVbHA4rF/37jzaMadK43FgJ0SAhPPF5l4l89z5oPu0b/+5e2inA3b8J3iGZxywjM+Csq1tqz hltEc7Q+E08AAwUIAL+15XH8bPbjNJdVyg2CMl10JNW2wWg2Q6qdljeaRqeR6zFus7EZTwtX sNzs5bP8y51PSUDJbeiy2RNCNKWFMndM22TZnk3GNG45nQd4OwYK0RZVrikalmJY5Q6m7Z16 4yrZgIXFdKj2t8F+x613/SJW1lIr9/bDp4U9tw0V1g3l2dFtD3p3ZrQ3hpoDtoK70ioIAjjH aIXIAcm3FGZFXy503DOA0KaTWwvOVdYCFLm3zWuSOmrX/GsEc7ovasOWwjPn878qVjbUKWwx Q4QkF4OhUV9zPtf9tDSAZ3x7QSwoKbCoRCZ/xbyTUPyQ1VvNy/mYrBcYlzHodsaqUDjHuW+I SQQYEQIACQUCRND5ggIbDAAKCRBy3lIGd+N/BCO8AJ9j1dWVQWxw/YdTbEyrRKOY8YZNwwCf afMAg8QvmOWnHx3wl8WslCaXaE8= Message-ID: <79c3ce4d-0f4b-37f3-9e66-58a71d67962c@FreeBSD.org> Date: Thu, 11 Jul 2019 10:34:01 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 090DD896AD X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.94 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.94)[-0.939,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[] X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jul 2019 17:34:07 -0000 On 7/10/19 2:29 PM, Phil Shafer wrote: > Would a reasonable goal be to make expand_number and humanize_number > (with HN_IEC_PREFIXES) should be as compatible as possible? In regards to IEC, I think mapping 'K' to 1000 by default would not be great, but we should support '2MiB' in addition to '2MB' probably. > The API doesn't allow many humanize-style features, but having the > number->string->number work would be ideal so support for > HN_DECIMAL-style input should be added, so "1.1K" does the right thing > (thought it rounds to 1126). Hmm, that seems harder to reason about, or maybe it requires parsing the original value as a float or double. I'm tempted to only support whole numbers to give more deterministic behavior such that if expand_number does support a value you will always get what you passed to humanize_number. > Lacking support for "suffix", trailing garbage should not be an error > (ala atoi), though I wish there was a parameter like strtol()'s endptr > to pass the next point to the character back in. If there was a suffix > parameter, the endptr would be skipped over it, if present. Yes, the API doesn't really make it easy to deal with trailing garbage as in some cases (e.g. bhyve's memory size) trailing garbage is an error and unless expand_number detects it I have no way of enforcing that. I don't really like atoi() for that reason even though it is convenient. I'm not sure of a good answer here. > The expand_number API uses uint64_t where humanize_number uses signed > int64_t so the answer for negative numbers is DOA. Except you can cast the result and it works (see the tests in the review). That said, I'm fine with that being the case, we should just pick one and document it as such. > Is it worth making a new expandize_number() function > (dehumanize_number?) that brings the API more into sync with > humanize_number? The main thing I wish was some way to reason about trailing garbage, but for now I'd just like to more clearly document how the API should work. > Thanks, > Phil > > > > On 10 Jul 2019, at 14:14, John Baldwin wrote: > >> While working on some bhyve changes I happened to look at the source >> to expand_number(3) and noticed what I think are several bugs. I >> wrote some tests to validate that these bugs are present, but in some >> cases I'm not sure what the correct / desired behavior is? I posted >> a review with the tests and questions about what some of the behavior >> should be with folks who have worked on expand_number(3) previously, >> but haven't gotten any feedback. The URL to the review is below if >> other folks would like to offer feedback on some of my open questions >> such as should we support negative numbers, hex and octal bases, >> trailing garbage, etc.? >> >> https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.freebsd.org_D20796&d=DwICAg&c=HAkYuh63rsuhr6Scbfh0UjBXeMK-ndb3voDTXcWzoCI&r=And7spKEXmRNIrq8pYCiSg&m=EHG6EmocNCDS6VoOZVxzZoCq-BqbJjBpsC9kXhGFTd0&s=bUQ8xvhg6vv95W5fHxswOrzDIeVxFsFJIa2582tjHgA&e= >> >> -- >> John Baldwin >> _______________________________________________ >> freebsd-arch@freebsd.org mailing list >> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freebsd.org_mailman_listinfo_freebsd-2Darch&d=DwICAg&c=HAkYuh63rsuhr6Scbfh0UjBXeMK-ndb3voDTXcWzoCI&r=And7spKEXmRNIrq8pYCiSg&m=EHG6EmocNCDS6VoOZVxzZoCq-BqbJjBpsC9kXhGFTd0&s=_ChOm4nn2d9pTlDuA6I2EdYXc73LOiS_N4c0k0DOWPo&e= >> To unsubscribe, send any mail to >> "freebsd-arch-unsubscribe@freebsd.org" -- John Baldwin