|
From: | Paul Eggert |
Subject: | Re: JSON/YAML/TOML/etc. parsing performance |
Date: | Wed, 4 Oct 2017 14:24:59 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 |
On 10/04/2017 12:38 PM, Eli Zaretskii wrote:
Sure, but we would also have worse problems, as size_t is inherently more error-prone. ptrdiff_t overflows are reliably diagnosed when Emacs is compiled with suitable GCC compiler options. size_t overflows cannot be diagnosed, are all too common, and can cause serious trouble.if we did use size_t for the arguments which can clearly only be non-negative, the problems which we are discussing would not have happened
The Emacs internals occasionally use size_t because underlying primitives like 'malloc' do, so we do make some exceptions. Perhaps there should be an exception here, for convenience with the JSON library. The code snippets I've seen so far in this thread are not enough context to judge whether an exception would be helpful in this case. Generally speaking, though, unsigned types should be avoided because they are more error-prone. This has long been the style in Emacs internals, and it's served us well.
(Ironically, just last week I was telling beginning students to beware unsigned types, with (0u < -1) as an example....)
[Prev in Thread] | Current Thread | [Next in Thread] |