Skip to content
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

ChannelStatistics breaks the cgo #301

Closed
freakmaxi opened this issue Jan 7, 2024 · 4 comments
Closed

ChannelStatistics breaks the cgo #301

freakmaxi opened this issue Jan 7, 2024 · 4 comments
Assignees

Comments

@freakmaxi
Copy link

Hello,

When I use imagemagick 7.1.1-24 or higher. I'm getting this compile error

cgo: ../../../../../../../../imagick/imagick/channel_statistics.go:16:6: unexpected: 16-byte float type - long double

Because of this commit in imagemagick

ImageMagick/ImageMagick@1f241fd

that contains long double variable additions in ChannelStatistics (long double - that is not precisely defined in golang).

Do you have any idea to get over it? It is a long time problem for me when I use golang with C integration and I couldn't find any solution to fix the long double variable usage.

I'm able to compile the golang application if I convert long double variables to double in statistics.h file in imagemagick header file and it will be mapped to float64 in golang. I couldn't have done any deep test if it is working but I believe, it will not break something. However, it is not a proper solution and I'm looking for a solution out of the box.

Thanks.

@freakmaxi freakmaxi changed the title ChannelStatistics break the cgo usage ChannelStatistics breaks the cgo usage Jan 7, 2024
@freakmaxi freakmaxi changed the title ChannelStatistics breaks the cgo usage ChannelStatistics breaks the cgo Jan 7, 2024
@justinfx
Copy link
Member

justinfx commented Jan 7, 2024

The only useful information I could find on long double handling in cgo is here: https://groups.google.com/g/golang-nuts/c/JnuXVK2lv_s?pli=1

If it's a struct field, there isn't really any best practice. Avoid
referring to the struct from Go, I guess.

It doesn't seem that any of the Imagick binding code is actually using ChannelStatistics as a input or output parameter. So that implies that it is just an unused binding right now and we could change it to fix compilation. The *C.ChannelStatistics is an unexported field as well, so we can do whatever we want to the Go ChannelStatistics struct.
The easiest fix would be to just remove the cs *C.ChannelStatistics field on the Go side for now until there are bindings added that actually make use of it. Otherwise, we could add a C shim to that file after the include that redefines the struct with a double.

@freakmaxi
Copy link
Author

Yes, I've also reached to that google group post while I'm looking for a solution and also this (https://tip.golang.org/src/cmd/cgo/internal/testerrors/testdata/issue28069.go) which is related to the issue in golang side.

If there is no usage for that, I'll remove it and may be you can also put _ (underscore) to the file to omit from the compilation and create a new release so I can continue to use your repo other than my fork to have the future updates in your releases...

thank you for your quick response.

@justinfx
Copy link
Member

justinfx commented Jan 8, 2024

I've tagged this fix as v3.5.1

@justinfx justinfx closed this as completed Jan 8, 2024
@fghj1
Copy link

fghj1 commented Jan 9, 2024

Ah ... I changed my program for three days. For three days I could die.
Oh My GOD!
Thank you!!!
I lived!!

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

No branches or pull requests

3 participants