SwiftCommand icon indicating copy to clipboard operation
SwiftCommand copied to clipboard

swift6 warnings about passing raw mutable buffers?

Open heckj opened this issue 1 year ago • 2 comments

Hi josef,

I was digging into your package, kicked open the file in the latest beta Xcode and noticed (compiler warnings) that there were a couple of places where you're passing UnsafeMutableRawBufferPointer across an isolation boundary. It definitely seems like an unsafe practice, so I wanted to check to see if there was a better way to arrange what's happening here.

The relevant code is in FileHandle+Async.swift, around lines 197-208 in the main branch. Screenshot from my Xcode:

Screenshot 2024-12-02 at 4 19 05 PM

heckj avatar Dec 03 '24 00:12 heckj

It looks like the intent is likely to have the fileprivate actor hold all the relevant state and do the reading, and this is more of a complication in asserting that everything critical here (the filehandle and buffer being twiddled) is accessed only on that actor buffer.

Would you be open to a PR that changes the actor to a global actor, and annotates AsyncIterator with it, so that all the relevant pieces are "pinned" to executing within the isolation context of that actor? (I'm not sure how to wrangle things to do this without a global actor, but I suspect there is a path - I'm just not aware of the specifics on it)

heckj avatar Dec 03 '24 01:12 heckj

Thanks for making me aware of that issue. The code you are referring to was just copied from this PR, which remains open and unchanged to this day.

Unfortunately, I don't have the capacity to look into this right now. If you want to have a look at this, I would be more than happy to merge a PR that solves this (potential) problem. Otherwise, I will maybe come around to tackle this eventually.

Zollerboy1 avatar Dec 03 '24 13:12 Zollerboy1