Skip to content

Commit ca4732b

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

File tree

10 files changed

+1302
-31
lines changed

10 files changed

+1302
-31
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 & 20 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).
@@ -855,7 +848,6 @@
855848
//! # `rb_h`
856849
//!
857850
// * `rb_Hash`:
858-
// * `rb_hash`:
859851
//! * `rb_hash_aref`: [`RHash::aref`].
860852
//! * `rb_hash_aset`: [`RHash::aset`].
861853
// * `rb_hash_bulk_insert`:
@@ -928,7 +920,6 @@
928920
// * `rb_io_check_readable`:
929921
// * `rb_io_check_writable`:
930922
// * `rb_io_close`:
931-
// * `rb_io_descriptor`:
932923
// * `rb_io_eof`:
933924
// * `rb_io_extract_encoding_option`:
934925
// * `rb_io_extract_modeenc`:
@@ -1087,13 +1078,8 @@
10871078
// * `rb_mod_sys_fail`:
10881079
// * `rb_mod_sys_fail_str`:
10891080
// * `rb_must_asciicompat`:
1090-
// * `rb_mutex_lock`:
1091-
// * `rb_mutex_locked_p`:
1092-
// * `rb_mutex_new`:
10931081
// * `rb_mutex_sleep`:
10941082
// * `rb_mutex_synchronize`:
1095-
// * `rb_mutex_trylock`:
1096-
// * `rb_mutex_unlock`:
10971083
//!
10981084
//! ## `rb_n`
10991085
//!
@@ -1183,9 +1169,7 @@
11831169
// * `rb_obj_instance_eval`:
11841170
// * `rb_obj_instance_exec`:
11851171
// * `rb_obj_instance_variables`:
1186-
// * `rb_obj_is_fiber`:
11871172
// * `rb_obj_is_instance_of`:
1188-
//! * `rb_obj_is_kind_of`: [`Value::is_kind_of`].
11891173
// * `rb_obj_is_method`:
11901174
//! * `rb_obj_is_proc`: [`Proc::from_value`](block::Proc::from_value).
11911175
// * `rb_obj_method`:
@@ -1530,7 +1514,6 @@
15301514
// * `rb_thread_current`:
15311515
// * `rb_thread_fd_close`:
15321516
// * `rb_thread_fd_select`:
1533-
// * `rb_thread_fd_writable`:
15341517
// * `rb_thread_interrupted`:
15351518
// * `rb_thread_kill`:
15361519
// * `rb_thread_local_aref`:
@@ -1544,7 +1527,6 @@
15441527
// * `rb_thread_sleep_deadly`:
15451528
// * `rb_thread_sleep_forever`:
15461529
// * `rb_thread_stop`:
1547-
// * `rb_thread_wait_fd`:
15481530
// * `rb_thread_wait_for`:
15491531
// * `rb_thread_wakeup`:
15501532
// * `rb_thread_wakeup_alive`:
@@ -1821,15 +1803,20 @@ mod object;
18211803
mod r_array;
18221804
mod r_bignum;
18231805
mod r_complex;
1806+
#[cfg(ruby_gt_3_0)]
1807+
pub mod r_fiber;
18241808
mod r_file;
18251809
mod r_float;
18261810
pub mod r_hash;
1811+
pub mod r_io;
18271812
mod r_match;
1813+
pub mod r_mutex;
18281814
mod r_object;
18291815
mod r_rational;
18301816
mod r_regexp;
18311817
pub mod r_string;
18321818
pub mod r_struct;
1819+
pub mod r_thread;
18331820
pub mod r_typed_data;
18341821
mod range;
18351822
#[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)