I'm not opposed to this. I don't think it's very important. For functions like these I don't think it's all that interesting to document precisely how they break. No working program is going to pass them invalid values.
Well NULL is (or could be) a valid value. I'm at the moment reviewing some improvements to some golang bindings for a C library. A particular C library function takes a numeric ID for an entity and returns a string (which the caller must free) if the ID is found, or NULL if it's not found. I'm trying to figure out if the following code is correct:
I probably should have been more explicit in my original report. The
reason I raised this (admittedly very minor, low priority) report was more
to determine what a "working program" could expect now /and in the future/
i.e. what the backward compatibility guarantee was. (Another reason was
that, as a relative neophyte, I found it tricky to quickly answer the
question for myself since there are a number of layers in the onion--but
that is entirely my own shortcoming :-)
As it stands, the only truly "future proof" approach is to always check
everywhere, which is rather tedious if it is actually unnecessary. Of
course, I don't seriously expect the contract to ever be changed but I
thought it might be worth bringing up. Apologies if I'm being needlessly
pedantic or wasting anyone's time.
On Fri, Jun 28, 2019 at 12:51 PM George Dunlap ***@***.***> wrote:
Same with C.free really -- in normal C, calling free on NULL is fine; I'd
assume it's the same in cgo, but it would be good for that to be documented
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
or mute the thread
@DryHumour No, getting things documented for backwards compatibility is always a good idea, rather than just relying on the implementation never to change. Things end up changing for all kinds of random reasons that people don't even notice. If there's documentation that GoString behaves in a certain way, then people will check to make sure that behavior is maintained; if not, they just might forget that's a possibility, and change the behavior without even realizing it.