Skip to content

Commit

Permalink
[feat] mutex + fiber + thread + io
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-jpq committed Jul 8, 2022
1 parent cc852bf commit 2f35869
Show file tree
Hide file tree
Showing 9 changed files with 1,282 additions and 31 deletions.
6 changes: 1 addition & 5 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ impl TryConvert for Proc {
///
/// This effectivly makes the closure's lifetime managed by Ruby. It will be
/// dropped when the returned `Value` is garbage collected.
fn wrap_closure<F, R>(func: F) -> (*mut F, Value)
where
F: FnMut(&[Value], Option<Proc>) -> R,
R: BlockReturn,
{
pub(crate) fn wrap_closure<F>(func: F) -> (*mut F, Value) {
struct Closure();
impl DataTypeFunctions for Closure {}
let data_type = memoize!(DataType: {
Expand Down
27 changes: 7 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,12 +693,9 @@
// * `rb_fd_term`:
// * `rb_fd_zero`:
// * `rb_feature_provided`:
// * `rb_fiber_alive_p`:
// * `rb_fiber_current`:
// * `rb_fiber_new`:
// * `rb_fiber_raise`:
// * `rb_fiber_resume`:
// * `rb_fiber_resume_kw`:
// * `rb_fiber_transfer_kw`:
// * `rb_fiber_yield_kw`:
// * `rb_fiber_scheduler_address_resolve`:
// * `rb_fiber_scheduler_block`:
// * `rb_fiber_scheduler_close`:
Expand All @@ -723,10 +720,6 @@
// * `rb_fiber_scheduler_process_wait`:
// * `rb_fiber_scheduler_set`:
// * `rb_fiber_scheduler_unblock`:
// * `rb_fiber_transfer`:
// * `rb_fiber_transfer_kw`:
// * `rb_fiber_yield`:
// * `rb_fiber_yield_kw`:
//! * `rb_filesystem_encindex`: [`encoding::Index::filesystem`].
//! * `rb_filesystem_encoding`:
//! [`RbEncoding::filesystem`](encoding::RbEncoding::filesystem).
Expand Down Expand Up @@ -855,7 +848,6 @@
//! # `rb_h`
//!
// * `rb_Hash`:
// * `rb_hash`:
//! * `rb_hash_aref`: [`RHash::aref`].
//! * `rb_hash_aset`: [`RHash::aset`].
// * `rb_hash_bulk_insert`:
Expand Down Expand Up @@ -928,7 +920,6 @@
// * `rb_io_check_readable`:
// * `rb_io_check_writable`:
// * `rb_io_close`:
// * `rb_io_descriptor`:
// * `rb_io_eof`:
// * `rb_io_extract_encoding_option`:
// * `rb_io_extract_modeenc`:
Expand Down Expand Up @@ -1087,13 +1078,8 @@
// * `rb_mod_sys_fail`:
// * `rb_mod_sys_fail_str`:
// * `rb_must_asciicompat`:
// * `rb_mutex_lock`:
// * `rb_mutex_locked_p`:
// * `rb_mutex_new`:
// * `rb_mutex_sleep`:
// * `rb_mutex_synchronize`:
// * `rb_mutex_trylock`:
// * `rb_mutex_unlock`:
//!
//! ## `rb_n`
//!
Expand Down Expand Up @@ -1183,9 +1169,7 @@
// * `rb_obj_instance_eval`:
// * `rb_obj_instance_exec`:
// * `rb_obj_instance_variables`:
// * `rb_obj_is_fiber`:
// * `rb_obj_is_instance_of`:
//! * `rb_obj_is_kind_of`: [`Value::is_kind_of`].
// * `rb_obj_is_method`:
//! * `rb_obj_is_proc`: [`Proc::from_value`](block::Proc::from_value).
// * `rb_obj_method`:
Expand Down Expand Up @@ -1530,7 +1514,6 @@
// * `rb_thread_current`:
// * `rb_thread_fd_close`:
// * `rb_thread_fd_select`:
// * `rb_thread_fd_writable`:
// * `rb_thread_interrupted`:
// * `rb_thread_kill`:
// * `rb_thread_local_aref`:
Expand All @@ -1544,7 +1527,6 @@
// * `rb_thread_sleep_deadly`:
// * `rb_thread_sleep_forever`:
// * `rb_thread_stop`:
// * `rb_thread_wait_fd`:
// * `rb_thread_wait_for`:
// * `rb_thread_wakeup`:
// * `rb_thread_wakeup_alive`:
Expand Down Expand Up @@ -1821,15 +1803,20 @@ mod object;
mod r_array;
mod r_bignum;
mod r_complex;
#[cfg(ruby_gt_3_0)]
pub mod r_fiber;
mod r_file;
mod r_float;
pub mod r_hash;
pub mod r_io;
mod r_match;
pub mod r_mutex;
mod r_object;
mod r_rational;
mod r_regexp;
pub mod r_string;
pub mod r_struct;
pub mod r_thread;
pub mod r_typed_data;
mod range;
#[cfg(feature = "rb-sys-interop")]
Expand Down
10 changes: 9 additions & 1 deletion src/object.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{ffi::CString, mem::transmute, ops::Deref};

use crate::ruby_sys::{
rb_define_singleton_method, rb_extend_object, rb_ivar_get, rb_ivar_set, rb_singleton_class,
rb_define_singleton_method, rb_extend_object, rb_hash, rb_ivar_get, rb_ivar_set,
rb_singleton_class,
};

use crate::{
Expand All @@ -16,6 +17,13 @@ use crate::{

/// Functions available all non-immediate values.
pub trait Object: Deref<Target = Value> + Copy {
/// Call `obj.hash`
fn hash(self) -> Result<i64, Error> {
debug_assert_value!(self);
let hash = protect(|| Value::new(unsafe { rb_hash(self.as_rb_value()) }))?;
hash.try_convert()
}

/// Define a singleton method in `self`'s scope.
///
/// Singleton methods defined on a class are Ruby's method for implementing
Expand Down
Loading

0 comments on commit 2f35869

Please sign in to comment.