New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: documentation for C.GoString could be more complete #32734
Comments
@ianlancetaylor in case he has opinions |
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
If Defining what will happen if |
Same with |
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.
Regards,
Neil
…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
somewhere.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#32734?email_source=notifications&email_token=AHDQVW2Y5WUUHEZAG3EVWKDP4Y6STA5CNFSM4H2VACMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY2TCAY#issuecomment-506802435>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHDQVWZDLN4WQKUBCSHAMZDP4Y6STANCNFSM4H2VACMA>
.
|
At present if you call
|
Awesome, thanks. |
@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. |
Documentation for
C.GoString()
,C.GoStringN()
, andC.GoBytes()
should probably explicitly document behaviour for "special" values (e.g.NULL
pointer, negative integers).https://golang.org/cmd/cgo/#hdr-Go_references_to_C
System details
The text was updated successfully, but these errors were encountered: