Skip to content

Conversation

@mtrmac
Copy link
Contributor

@mtrmac mtrmac commented Nov 5, 2025

  • Don’t inspect errno in calls that don’t set it
  • On calls that do set errno, inspect it only when it is known to be valid
  • Correctly implement io.Writer.

Partially addresses #45 .

Copy link

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As reference for myself and others

https://pkg.go.dev/cmd/cgo

Note that the C errno value may be non-zero, and thus the err result may be non-nil, even if the function call is successful. Unlike normal Go conventions, you should first check whether the call succeeded before checking the error result. For example:

So this seems correct here overall.

Comment on lines +179 to +180
defer func() { d.err = nil }()
return total, d.err
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is just me and I know this is pre existing. But it is not obvious to me that this does work and return the error and at the same time set it to nil for *Data. I had to write a small test to confirm https://go.dev/play/p/9uC2vjLa_NU

Maybe it would be easier on reader to turn this into

err := d.err
d.err =nil
return total, err

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d slightly prefer the non-defer version as well, but I’ll let the package maintainer decide.

@mtrmac
Copy link
Contributor Author

mtrmac commented Nov 6, 2025

The macOS test failure will be fixed by #49 ; I didn’t investigate the PowerPC one that tends to fail from time to time, but #43 contains a commit that might be relevant.

The function is not documented to, and does not, set it.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
The function is not documented to, and does not, set it.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
... per the primary return value.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Short writes are a valid outcome of gpgme_data_write, but
invalid for io.Writer. Loop to conform to the interface.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@proglottis
Copy link
Owner

Thanks @mtrmac - I don't think changing the defer is enough to warrant another round. So I'll merge as-is.

@proglottis proglottis merged commit 9f162d3 into proglottis:master Nov 24, 2025
2 of 3 checks passed
@mtrmac mtrmac deleted the errno branch November 25, 2025 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants