From 3fd17d375ab0f6586c0c80a15dc7ec0e9f925b07 Mon Sep 17 00:00:00 2001 From: Mat Sadler Date: Tue, 26 Dec 2023 20:56:19 +0000 Subject: [PATCH] use rb_io_descriptor for RFile::as_raw_fd on Ruby 3.3 --- src/r_file.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/r_file.rs b/src/r_file.rs index 95cfac15..7ce07857 100644 --- a/src/r_file.rs +++ b/src/r_file.rs @@ -1,5 +1,9 @@ -use std::{fmt, ptr::NonNull}; +use std::fmt; +#[cfg(ruby_lt_3_3)] +use std::ptr::NonNull; +#[cfg(ruby_gte_3_3)] +use rb_sys::rb_io_descriptor; use rb_sys::ruby_value_type; use crate::{ @@ -48,6 +52,7 @@ impl RFile { } } + #[cfg(ruby_lt_3_3)] fn as_internal(self) -> NonNull { // safe as inner value is NonZero unsafe { NonNull::new_unchecked(self.0.get().as_rb_value() as *mut _) } @@ -107,6 +112,11 @@ pub mod fd { pub use std::os::unix::io as fd; impl fd::AsRawFd for RFile { + #[cfg(ruby_gte_3_3)] + fn as_raw_fd(&self) -> fd::RawFd { + unsafe { rb_io_descriptor(self.as_rb_value()) } + } + #[cfg(ruby_lt_3_3)] fn as_raw_fd(&self) -> fd::RawFd { unsafe { (*self.as_internal().as_ref().fptr).fd } }