ruby-changes:64484
From: Kenta <ko1@a...>
Date: Wed, 23 Dec 2020 09:25:30 +0900 (JST)
Subject: [ruby-changes:64484] 05014dcb88 (master): [memory_view][fiddle] Use bool for boolean return value
https://git.ruby-lang.org/ruby.git/commit/?id=05014dcb88 From 05014dcb887681d986105653ab527da2c4ff7774 Mon Sep 17 00:00:00 2001 From: Kenta Murata <mrkn@m...> Date: Tue, 22 Dec 2020 17:33:14 +0900 Subject: [memory_view][fiddle] Use bool for boolean return value diff --git a/ext/-test-/memory_view/memory_view.c b/ext/-test-/memory_view/memory_view.c index c85ba6f..00572b9 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; https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L24 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) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L260 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) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L272 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) https://github.com/ruby/ruby/blob/trunk/ext/-test-/memory_view/memory_view.c#L308 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 ca1d59f..c5fb442 100644 --- a/ext/fiddle/pointer.c +++ b/ext/fiddle/pointer.c @@ -102,19 +102,19 @@ fiddle_ptr_check_memory_view(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/fiddle/pointer.c#L102 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 29d8f70..b90a32d 100644 --- a/include/ruby/memory_view.h +++ b/include/ruby/memory_view.h @@ -48,7 +48,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L48 /* 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 { https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L105 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); https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L127 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_ https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L137 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 7a2a518..08ff967 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 https://github.com/ruby/ruby/blob/trunk/memory_view.c#L194 } /* 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, https://github.com/ruby/ruby/blob/trunk/memory_view.c#L211 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) https://github.com/ruby/ruby/blob/trunk/memory_view.c#L794 } /* 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) https://github.com/ruby/ruby/blob/trunk/memory_view.c#L802 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) https://github.com/ruby/ruby/blob/trunk/memory_view.c#L847 return rv; } else - return 0; + return false; } void -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/