crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Add support for IO::FileDescriptor staying open on finalize

Open refi64 opened this issue 2 years ago • 3 comments

refi64 avatar Aug 07 '22 19:08 refi64

Was there a discussion around this, or a reason to add it?

asterite avatar Aug 08 '22 10:08 asterite

Was there a discussion around this, or a reason to add it?

Welp the "throw out a PR right before night and leave the description blank" thing has come to bite me (again).

Essentially, when dealing with C APIs that return FDs that are owned by the callee, the only way to use IO::FileDescriptor's higher-level API functions with it is by dup-ing it. That's...an entirely workable solution, but can come with its own share of annoyances (dup-ing a pipe and then accidentally leaving one end open). Of course, not dup-ing the fd can lead to "oh the C API closed it but you didn't notice"...but stuff like that is inherent to using both C APIs and raw FDs anyway.

I could certainly add this in local projects, but monkeypatching the stdlib isn't my favorite thing :sweat_smile:

refi64 avatar Aug 09 '22 01:08 refi64

I see, that makes sense! I would then add all of that description to the documentation of this new property. Explaining a concrete example behind this property will help users know when to use it, and know that they probably shouldn't use it at all 😅

asterite avatar Aug 09 '22 13:08 asterite

Related: https://github.com/crystal-lang/crystal/pull/12457#issuecomment-1239903346

HertzDevil avatar Sep 09 '22 02:09 HertzDevil

@asterite more detailed docs added

refi64 avatar Sep 12 '22 01:09 refi64