JuliaIO / TranscodingStreams.jl

Simple, consistent interfaces for any codec.
https://juliaio.github.io/TranscodingStreams.jl/
Other
86 stars 28 forks source link

Add a GC.@preserve when calling unsafe_transcode! #216

Closed mkitti closed 5 months ago

mkitti commented 5 months ago

Add GC.@preserve when calling unsafe_transcode! since buffer to memory conversions involve raw pointer conversions.

mkitti commented 5 months ago

From what I can tell there are a lot of missing GC.@preserve in unsafe_transcode!. Unless Julia automatically preserves all function inputs?

Currently, I think the GC.@preserve might be implicit becuase input and output are used latter in the function. Also the flow control with @goto may be difficult to optimize. However, a future optimization could do some kind of struct splitting, garbage collecting part of input or output in the future.

As far as I can tell, I think preserving the function input should be sufficient for the allocated memory to remain stable for the duration of the function call.