Repository navigation
Conversation
bastibe
left a comment
There was a problem hiding this comment.
Thank you for your bug report. Were you actually using soundfile on a big endian system?
I don't think this is the right place to fix things, though. We should probably treat byte order like contiguous instead.
There was a problem hiding this comment.
here we convert data to contiguous, we could also convert the byte order.
There was a problem hiding this comment.
Moved native byte-order conversion to write(), alongside its contiguity conversion. Contiguous and strided inputs are covered; all sixteen write regressions pass on CPython and PyPy.
| @@ -1421,6 +1421,12 @@ def _array_io(self, action, array, frames): | |||
| raise ValueError("Data must be C-contiguous") | |||
There was a problem hiding this comment.
if out is not contiguous, we just error out. We should do the same with byte order.
There was a problem hiding this comment.
Non-native output arrays now raise ValueError before any samples are read. Tests verify the output bytes and file position stay unchanged, including fill settings.
|
The reproduction used non-native-endian NumPy arrays on little-endian Linux; no big-endian host was tested. Applied your suggested layout: |
NumPy arrays with a non-native byte order are passed to libsndfile as native samples, silently changing their values.
Convert write inputs to contiguous native storage in
write(). Reject non-nativeread(out=...)buffers in_array_io, alongside the existing contiguity validation, before altering the output or moving the file position. Document the output-buffer restriction.Before on a little-endian host:
[256, 1, -10250]. After:[1, 256, -2345].All 32 regressions fail on master and pass here: sixteen contiguous/strided non-native write cases and sixteen read-buffer rejection checks covering four sample dtypes, mono/stereo and fill settings. Recorded LJSpeech/AMI writes correct 123,616 sample values and match independent frame energies/spectra. All eight non-native output-buffer workflows reject before changing their buffers; all eight native controls remain byte-identical. Inputs remain unchanged.
Full native suite: 371 passed on CPython 3.12 and PyPy 3.10. Error lint and diff checks pass. Pyright retains the same two existing
dirname(_libname)findings as master. Tested on little-endian Linux; no big-endian host was tested.