ruby-changes:63283
From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Tue, 6 Oct 2020 14:20:27 +0900 (JST)
Subject: [ruby-changes:63283] 7d594399f6 (master): memory_view.h: use bool
https://git.ruby-lang.org/ruby.git/commit/?id=7d594399f6 From 7d594399f666f35eff1c7be4ec944605dc9aa49c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= <shyouhei@r...> Date: Tue, 6 Oct 2020 12:00:16 +0900 Subject: memory_view.h: use bool Because `bool` is already used in the header there is no reason to hesitate. diff --git a/include/ruby/memory_view.h b/include/ruby/memory_view.h index f9348f5..58db2a9 100644 --- a/include/ruby/memory_view.h +++ b/include/ruby/memory_view.h @@ -49,7 +49,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L49 ssize_t len; /* 1 for readonly memory, 0 for writable memory. */ - int readonly; + bool readonly; /* A string to describe the format of an element, or NULL for unsigned byte. * The format string is a sequence the following pack-template specifiers: @@ -122,10 +122,10 @@ bool rb_memory_view_register(VALUE klass, const rb_memory_view_entry_t *entry); https://github.com/ruby/ruby/blob/trunk/include/ruby/memory_view.h#L122 rb_memory_view_is_row_major_contiguous(view) \ || rb_memory_view_is_column_major_contiguous(view)) -int rb_memory_view_is_row_major_contiguous(const rb_memory_view_t *view); -int rb_memory_view_is_column_major_contiguous(const rb_memory_view_t *view); -void rb_memory_view_fill_contiguous_strides(const ssize_t ndim, const ssize_t item_size, const ssize_t *const shape, const int row_major_p, ssize_t *const strides); -int rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data, const ssize_t len, const int readonly); +bool rb_memory_view_is_row_major_contiguous(const rb_memory_view_t *view); +bool rb_memory_view_is_column_major_contiguous(const rb_memory_view_t *view); +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); +int 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, ssize_t *n_members, const char **err); diff --git a/memory_view.c b/memory_view.c index ea503c3..0b3565c 100644 --- a/memory_view.c +++ b/memory_view.c @@ -35,17 +35,17 @@ rb_memory_view_register(VALUE klass, const rb_memory_view_entry_t *entry) { https://github.com/ruby/ruby/blob/trunk/memory_view.c#L35 VALUE entry_obj = rb_ivar_lookup(klass, id_memory_view, Qnil); if (! NIL_P(entry_obj)) { rb_warning("Duplicated registration of memory view to %"PRIsVALUE, klass); - return 0; + return false; } else { entry_obj = TypedData_Wrap_Struct(0, &memory_view_entry_data_type, (void *)entry); rb_ivar_set(klass, id_memory_view, entry_obj); - return 1; + return true; } } /* Examine whether the given memory view has row-major order strides. */ -int +bool rb_memory_view_is_row_major_contiguous(const rb_memory_view_t *view) { const ssize_t ndim = view->ndim; @@ -54,14 +54,14 @@ rb_memory_view_is_row_major_contiguous(const rb_memory_view_t *view) https://github.com/ruby/ruby/blob/trunk/memory_view.c#L54 ssize_t n = view->item_size; ssize_t i; for (i = ndim - 1; i >= 0; --i) { - if (strides[i] != n) return 0; + if (strides[i] != n) return false; n *= shape[i]; } - return 1; + return true; } /* Examine whether the given memory view has column-major order strides. */ -int +bool rb_memory_view_is_column_major_contiguous(const rb_memory_view_t *view) { const ssize_t ndim = view->ndim; @@ -70,15 +70,15 @@ rb_memory_view_is_column_major_contiguous(const rb_memory_view_t *view) https://github.com/ruby/ruby/blob/trunk/memory_view.c#L70 ssize_t n = view->item_size; ssize_t i; for (i = 0; i < ndim; ++i) { - if (strides[i] != n) return 0; + if (strides[i] != n) return false; n *= shape[i]; } - return 1; + return true; } /* Initialize strides array to represent the specified contiguous array. */ void -rb_memory_view_fill_contiguous_strides(const ssize_t ndim, const ssize_t item_size, const ssize_t *const shape, const int row_major_p, ssize_t *const strides) +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) { ssize_t i, n = item_size; if (row_major_p) { @@ -97,7 +97,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#L97 /* Initialize view to expose a simple byte array */ int -rb_memory_view_init_as_byte_array(rb_memory_view_t *view, VALUE obj, void *data, const ssize_t len, const int readonly) +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; view->data = data; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/