Skip to content

Commit 0eebfc4

Browse files
committed
[feat] mutex + fiber + thread + io
1 parent cc852bf commit 0eebfc4

File tree

10 files changed

+1339
-29
lines changed

10 files changed

+1339
-29
lines changed

src/block.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,7 @@ impl TryConvert for Proc {
301301
///
302302
/// This effectivly makes the closure's lifetime managed by Ruby. It will be
303303
/// dropped when the returned `Value` is garbage collected.
304-
fn wrap_closure<F, R>(func: F) -> (*mut F, Value)
305-
where
306-
F: FnMut(&[Value], Option<Proc>) -> R,
307-
R: BlockReturn,
308-
{
304+
pub(crate) fn wrap_closure<F>(func: F) -> (*mut F, Value) {
309305
struct Closure();
310306
impl DataTypeFunctions for Closure {}
311307
let data_type = memoize!(DataType: {

src/lib.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,9 @@
693693
// * `rb_fd_term`:
694694
// * `rb_fd_zero`:
695695
// * `rb_feature_provided`:
696-
// * `rb_fiber_alive_p`:
697-
// * `rb_fiber_current`:
698-
// * `rb_fiber_new`:
699-
// * `rb_fiber_raise`:
700-
// * `rb_fiber_resume`:
701696
// * `rb_fiber_resume_kw`:
697+
// * `rb_fiber_transfer_kw`:
698+
// * `rb_fiber_yield_kw`:
702699
// * `rb_fiber_scheduler_address_resolve`:
703700
// * `rb_fiber_scheduler_block`:
704701
// * `rb_fiber_scheduler_close`:
@@ -723,10 +720,6 @@
723720
// * `rb_fiber_scheduler_process_wait`:
724721
// * `rb_fiber_scheduler_set`:
725722
// * `rb_fiber_scheduler_unblock`:
726-
// * `rb_fiber_transfer`:
727-
// * `rb_fiber_transfer_kw`:
728-
// * `rb_fiber_yield`:
729-
// * `rb_fiber_yield_kw`:
730723
//! * `rb_filesystem_encindex`: [`encoding::Index::filesystem`].
731724
//! * `rb_filesystem_encoding`:
732725
//! [`RbEncoding::filesystem`](encoding::RbEncoding::filesystem).
@@ -796,7 +789,6 @@
796789
// * `rb_funcall_passing_block`:
797790
// * `rb_funcall_passing_block_kw`:
798791
//! * `rb_funcall_with_block`: [`Value::funcall_with_block`].
799-
// * `rb_funcall_with_block_kw`:
800792
// * `rb_f_abort`:
801793
// * `rb_f_exec`:
802794
// * `rb_f_exit`:
@@ -855,7 +847,6 @@
855847
//! # `rb_h`
856848
//!
857849
// * `rb_Hash`:
858-
// * `rb_hash`:
859850
//! * `rb_hash_aref`: [`RHash::aref`].
860851
//! * `rb_hash_aset`: [`RHash::aset`].
861852
// * `rb_hash_bulk_insert`:
@@ -928,7 +919,6 @@
928919
// * `rb_io_check_readable`:
929920
// * `rb_io_check_writable`:
930921
// * `rb_io_close`:
931-
// * `rb_io_descriptor`:
932922
// * `rb_io_eof`:
933923
// * `rb_io_extract_encoding_option`:
934924
// * `rb_io_extract_modeenc`:
@@ -1087,13 +1077,8 @@
10871077
// * `rb_mod_sys_fail`:
10881078
// * `rb_mod_sys_fail_str`:
10891079
// * `rb_must_asciicompat`:
1090-
// * `rb_mutex_lock`:
1091-
// * `rb_mutex_locked_p`:
1092-
// * `rb_mutex_new`:
10931080
// * `rb_mutex_sleep`:
10941081
// * `rb_mutex_synchronize`:
1095-
// * `rb_mutex_trylock`:
1096-
// * `rb_mutex_unlock`:
10971082
//!
10981083
//! ## `rb_n`
10991084
//!
@@ -1183,9 +1168,7 @@
11831168
// * `rb_obj_instance_eval`:
11841169
// * `rb_obj_instance_exec`:
11851170
// * `rb_obj_instance_variables`:
1186-
// * `rb_obj_is_fiber`:
11871171
// * `rb_obj_is_instance_of`:
1188-
//! * `rb_obj_is_kind_of`: [`Value::is_kind_of`].
11891172
// * `rb_obj_is_method`:
11901173
//! * `rb_obj_is_proc`: [`Proc::from_value`](block::Proc::from_value).
11911174
// * `rb_obj_method`:
@@ -1530,7 +1513,6 @@
15301513
// * `rb_thread_current`:
15311514
// * `rb_thread_fd_close`:
15321515
// * `rb_thread_fd_select`:
1533-
// * `rb_thread_fd_writable`:
15341516
// * `rb_thread_interrupted`:
15351517
// * `rb_thread_kill`:
15361518
// * `rb_thread_local_aref`:
@@ -1544,7 +1526,6 @@
15441526
// * `rb_thread_sleep_deadly`:
15451527
// * `rb_thread_sleep_forever`:
15461528
// * `rb_thread_stop`:
1547-
// * `rb_thread_wait_fd`:
15481529
// * `rb_thread_wait_for`:
15491530
// * `rb_thread_wakeup`:
15501531
// * `rb_thread_wakeup_alive`:
@@ -1821,15 +1802,20 @@ mod object;
18211802
mod r_array;
18221803
mod r_bignum;
18231804
mod r_complex;
1805+
#[cfg(ruby_gt_3_0)]
1806+
pub mod r_fiber;
18241807
mod r_file;
18251808
mod r_float;
18261809
pub mod r_hash;
1810+
pub mod r_io;
18271811
mod r_match;
1812+
pub mod r_mutex;
18281813
mod r_object;
18291814
mod r_rational;
18301815
mod r_regexp;
18311816
pub mod r_string;
18321817
pub mod r_struct;
1818+
pub mod r_thread;
18331819
pub mod r_typed_data;
18341820
mod range;
18351821
#[cfg(feature = "rb-sys-interop")]

src/object.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::{ffi::CString, mem::transmute, ops::Deref};
22

33
use crate::ruby_sys::{
4-
rb_define_singleton_method, rb_extend_object, rb_ivar_get, rb_ivar_set, rb_singleton_class,
4+
rb_define_singleton_method, rb_extend_object, rb_hash, rb_ivar_get, rb_ivar_set,
5+
rb_singleton_class,
56
};
67

78
use crate::{
@@ -16,6 +17,13 @@ use crate::{
1617

1718
/// Functions available all non-immediate values.
1819
pub trait Object: Deref<Target = Value> + Copy {
20+
/// Call `obj.hash`
21+
fn hash(self) -> Result<i64, Error> {
22+
debug_assert_value!(self);
23+
let hash = protect(|| Value::new(unsafe { rb_hash(self.as_rb_value()) }))?;
24+
hash.try_convert()
25+
}
26+
1927
/// Define a singleton method in `self`'s scope.
2028
///
2129
/// Singleton methods defined on a class are Ruby's method for implementing

0 commit comments

Comments
 (0)