crystal
crystal copied to clipboard
Add support for IO::FileDescriptor staying open on finalize
Was there a discussion around this, or a reason to add it?
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:
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 😅
Related: https://github.com/crystal-lang/crystal/pull/12457#issuecomment-1239903346
@asterite more detailed docs added