8000 plugins/thumbnails: fix FFI with GIO on s390x by Hyask · Pull Request #5708 · beetbox/beets · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

plugins/thumbnails: fix FFI with GIO on s390x #5708

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

Merged
merged 2 commits into from
Apr 14, 2025

Conversation

Hyask
Copy link
Contributor
@Hyask Hyask commented Apr 4, 2025

Description

Using the correct function signature for g_file_new_for_path fixes the tests on s390x.
I do not have the full story on why this failed consistently only on s390x, but I guess the big endian might have something to play with this.

Here is how the tests were failing:

169s ___________________________ ThumbnailsTest.test_uri ____________________________
169s
169s self = <test.plugins.test_thumbnails.ThumbnailsTest testMethod=test_uri>
169s
169s     def test_uri(self):
169s         gio = GioURI()
169s         if not gio.available:
169s             self.skipTest("GIO library not found")
169s
169s >       assert gio.uri("/foo") == "file:///"  # silent fail
169s E       AssertionError: assert '' == 'file:///'
169s E
169s E         - file:///
169s
169s test/plugins/test_thumbnails.py:268: AssertionError

You can see a full log here 1 and a history of consistent failure here 2. Both links are bound to expire at some point, sorry future archeologist 🤷.

To Do

  • Discuss the behavior in case a string is passed. I've currently updated the test to reflect the exception being raised, but I did not do a thorough check of the code to know if that exception would need to be caught elsewhere in the code, or if that API might be used externally.

Copy link
github-actions bot commented Apr 4, 2025

Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry.

@Hyask Hyask force-pushed the skia/fix_s390x_ffi branch from 2c6c932 to 7f1eb66 Compare April 4, 2025 15:27
Copy link
Member
@wisp3rwind wisp3rwind left a comment

Choose a reason for hiding this comment

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

Wow, that copy-and-paste error (I presume) seems to have been around forever (10 years, to be precise: 530b421); thanks for the fix 🎉

Given https://docs.gtk.org/gio/type_func.File.new_for_path.html, this appears to be correct.

Discuss the behavior in case a string is passed. I've currently updated the test to reflect the exception being raised, but I did not do a thorough check of the code to know if that exception would need to be caught elsewhere in the code, or if that API might be used externally.

While undocumented, unchecked and untyped (and I'm unfamiliar with this part of the code), I'm fairly confident that this is only expected to take bytestrings. That's (historically) the internal representation of paths that beets chooses (with the caveat that I'm quite sure that was never 100% correctly implemented). Additionally, with the previous code, ctypes would pass the argument as wchar_t *, which presumably ended up being interpreted as b"\\\0" on little-endian systems (and the empty string on big-endian systems, which might explain the test failures). In any case, the result would definitely be broken thumbnails (or rather failure to even write them).

So, the only sense in which this could regress seems to be by different failures modes, in particular during import: Logging a warning/silent failure due to the broken code (before) and a crash with ArgumentError (after).

Given that the thumbnail plugin seems to be essentially unmaintained (the only contributions since its inception seem to be small bug fixes by drive-by contributors, and repo-wide refactorings), I'd argue to just merge this and deal with potential fall-out later. @snejus @JOJ0 any objections?

Eventually, it would be nice if the thumbnails plugin would also be subject to typing (slowly, beets is getting type annotations throughout its codebase) to highlight incorrect usage of these functions.

I'm also wondering whether gio is even required here these days: From a quick glance at the PR which added it, there used to be some discrepancy between Python and glib, but that's really a long time ago. Maybe, the much simpler pathlib implementation is sufficient nowadays?

@wisp3rwind
Copy link
Member

Would you mind adding a quick changelog entry?

@Hyask Hyask force-pushed the skia/fix_s390x_ffi branch from 7f1eb66 to db671b6 Compare April 8, 2025 13:49
@Hyask
Copy link
Contributor Author
Hyask commented Apr 8, 2025

Thanks for the review, and the hindsight on that little-endian/big-endian thing. That was more or less my conclusion too, but I really don't know enough about these things to be confident in a clear explanation.

I've added an entry to the changelog, hope it's good enough :-)

Hyask and others added 2 commits April 14, 2025 02:19
Using the correct function signature for g_file_new_for_path fixes the
tests on s390x.
I do not have the full story on why this failed consistently only on
s390x, but I guess the big endian might have something to play with
this.

Here is how the tests were failing:
```
169s ___________________________ ThumbnailsTest.test_uri ____________________________
169s
169s self = <test.plugins.test_thumbnails.ThumbnailsTest testMethod=test_uri>
169s
169s     def test_uri(self):
169s         gio = GioURI()
169s         if not gio.available:
169s             self.skipTest("GIO library not found")
169s
169s >       assert gio.uri("/foo") == "file:///"  # silent fail
169s E       AssertionError: assert '' == 'file:///'
169s E
169s E         - file:///
169s
169s test/plugins/test_thumbnails.py:268: AssertionError
```
You can see a full log here [1] and a history of consistent failure
here [2]. Both links are bound to expire at some point, sorry future
archeologist 🤷.

[1]: https://autopkgtest.ubuntu.com/results/autopkgtest-plucky/plucky/s390x/b/beets/20250403_162414_5d1da@/log.gz#S5
[2]: https://autopkgtest.ubuntu.com/packages/beets/plucky/s390x
@snejus snejus force-pushed the skia/fix_s390x_ffi branch from 060137a to f4de44f Compare April 14, 2025 01:19
@snejus snejus enabled auto-merge April 14, 2025 01:20
@snejus snejus merged commit 69b12a3 into beetbox:master Apr 14, 2025
13 checks passed
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
0