1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[memory_view][fiddle] Use bool for boolean return value

This commit is contained in:
Kenta Murata 2020-12-22 17:33:14 +09:00
parent 74a3569b59
commit 05014dcb88
No known key found for this signature in database
GPG key ID: CEFE8AFB6081B062
4 changed files with 29 additions and 29 deletions

View file

@ -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;

View file

@ -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 = {

View file

@ -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;

View file

@ -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