diff --git a/ext/-test-/memory_view/memory_view.c b/ext/-test-/memory_view/memory_view.c index c85ba6fbfa..00572b9109 100644 --- a/ext/-test-/memory_view/memory_view.c +++ b/ext/-test-/memory_view/memory_view.c @@ -24,15 +24,15 @@ static VALUE sym_endianness; static VALUE sym_little_endian; static VALUE sym_big_endian; -static int +static bool exportable_string_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags) { VALUE str = rb_ivar_get(obj, id_str); rb_memory_view_init_as_byte_array(view, obj, RSTRING_PTR(str), RSTRING_LEN(str), true); - return 1; + return true; } -static int +static bool exportable_string_memory_view_available_p(VALUE obj) { VALUE str = rb_ivar_get(obj, id_str); @@ -260,7 +260,7 @@ expstr_initialize(VALUE obj, VALUE s) return Qnil; } -static int +static bool mdview_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags) { VALUE buf_v = rb_ivar_get(obj, id_str); @@ -272,7 +272,7 @@ mdview_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags) const char *err; const ssize_t item_size = rb_memory_view_item_size_from_format(format, &err); if (item_size < 0) { - return 0; + return false; } ssize_t ndim = RARRAY_LEN(shape_v); @@ -308,10 +308,10 @@ mdview_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags) view->shape = shape; view->strides = strides; - return 1; + return true; } -static int +static bool mdview_memory_view_available_p(VALUE obj) { return true; diff --git a/ext/fiddle/pointer.c b/ext/fiddle/pointer.c index ca1d59ff5f..c5fb442aec 100644 --- a/ext/fiddle/pointer.c +++ b/ext/fiddle/pointer.c @@ -102,19 +102,19 @@ fiddle_ptr_check_memory_view(VALUE obj) return data; } -static int +static bool fiddle_ptr_memory_view_available_p(VALUE obj) { return fiddle_ptr_check_memory_view(obj) != NULL; } -static int +static bool fiddle_ptr_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags) { struct ptr_data *data = fiddle_ptr_check_memory_view(obj); rb_memory_view_init_as_byte_array(view, obj, data->ptr, data->size, true); - return 1; + return true; } static const rb_memory_view_entry_t fiddle_ptr_memory_view_entry = { diff --git a/include/ruby/memory_view.h b/include/ruby/memory_view.h index 29d8f7059d..b90a32d96e 100644 --- a/include/ruby/memory_view.h +++ b/include/ruby/memory_view.h @@ -48,7 +48,7 @@ typedef struct { /* The number of bytes in data. */ ssize_t len; - /* 1 for readonly memory, 0 for writable memory. */ + /* true for readonly memory, false for writable memory. */ bool readonly; /* A string to describe the format of an element, or NULL for unsigned byte. @@ -105,9 +105,9 @@ typedef struct { void *const private; } rb_memory_view_t; -typedef int (* rb_memory_view_get_func_t)(VALUE obj, rb_memory_view_t *view, int flags); -typedef int (* rb_memory_view_release_func_t)(VALUE obj, rb_memory_view_t *view); -typedef int (* rb_memory_view_available_p_func_t)(VALUE obj); +typedef bool (* rb_memory_view_get_func_t)(VALUE obj, rb_memory_view_t *view, int flags); +typedef bool (* rb_memory_view_release_func_t)(VALUE obj, rb_memory_view_t *view); +typedef bool (* rb_memory_view_available_p_func_t)(VALUE obj); typedef struct { rb_memory_view_get_func_t get_func; @@ -127,7 +127,7 @@ bool rb_memory_view_is_column_major_contiguous(const rb_memory_view_t *view); RBIMPL_ATTR_NOALIAS() void rb_memory_view_fill_contiguous_strides(const ssize_t ndim, const ssize_t item_size, const ssize_t *const shape, const bool row_major_p, ssize_t *const strides); RBIMPL_ATTR_NOALIAS() -int rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data, const ssize_t len, const bool readonly); +bool rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data, const ssize_t len, const bool readonly); ssize_t rb_memory_view_parse_item_format(const char *format, rb_memory_view_item_component_t **members, size_t *n_members, const char **err); @@ -137,9 +137,9 @@ VALUE rb_memory_view_extract_item_members(const void *ptr, const rb_memory_view_ void rb_memory_view_prepare_item_desc(rb_memory_view_t *view); VALUE rb_memory_view_get_item(rb_memory_view_t *view, const ssize_t *indices); -int rb_memory_view_available_p(VALUE obj); -int rb_memory_view_get(VALUE obj, rb_memory_view_t* memory_view, int flags); -int rb_memory_view_release(rb_memory_view_t* memory_view); +bool rb_memory_view_available_p(VALUE obj); +bool rb_memory_view_get(VALUE obj, rb_memory_view_t* memory_view, int flags); +bool rb_memory_view_release(rb_memory_view_t* memory_view); /* for testing */ RUBY_EXTERN VALUE rb_memory_view_exported_object_registry; diff --git a/memory_view.c b/memory_view.c index 7a2a518647..08ff967a1b 100644 --- a/memory_view.c +++ b/memory_view.c @@ -194,7 +194,7 @@ rb_memory_view_fill_contiguous_strides(const ssize_t ndim, const ssize_t item_si } /* Initialize view to expose a simple byte array */ -int +bool rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data, const ssize_t len, const bool readonly) { view->obj = obj; @@ -211,7 +211,7 @@ rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data, view->sub_offsets = NULL; *((void **)&view->private) = NULL; - return 1; + return true; } #ifdef HAVE_TRUE_LONG_LONG @@ -794,7 +794,7 @@ lookup_memory_view_entry(VALUE klass) } /* Examine whether the given object supports memory view. */ -int +bool rb_memory_view_available_p(VALUE obj) { VALUE klass = CLASS_OF(obj); @@ -802,38 +802,38 @@ rb_memory_view_available_p(VALUE obj) if (entry) return (* entry->available_p_func)(obj); else - return 0; + return false; } /* Obtain a memory view from obj, and substitute the information to view. */ -int +bool rb_memory_view_get(VALUE obj, rb_memory_view_t* view, int flags) { VALUE klass = CLASS_OF(obj); const rb_memory_view_entry_t *entry = lookup_memory_view_entry(klass); if (entry) { if (!(*entry->available_p_func)(obj)) { - return 0; + return false; } - int rv = (*entry->get_func)(obj, view, flags); + bool rv = (*entry->get_func)(obj, view, flags); if (rv) { register_exported_object(view->obj); } return rv; } else - return 0; + return false; } /* Release the memory view obtained from obj. */ -int +bool rb_memory_view_release(rb_memory_view_t* view) { VALUE klass = CLASS_OF(view->obj); const rb_memory_view_entry_t *entry = lookup_memory_view_entry(klass); if (entry) { - int rv = 1; + bool rv = true; if (entry->release_func) { rv = (*entry->release_func)(view->obj, view); } @@ -847,7 +847,7 @@ rb_memory_view_release(rb_memory_view_t* view) return rv; } else - return 0; + return false; } void