[memory_view] Make some rb_memroy_view_t members const

This commit is contained in:
Kenta Murata 2020-12-23 00:43:26 +09:00
Родитель db0385d657
Коммит 01ab29cc28
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CEFE8AFB6081B062
3 изменённых файлов: 10 добавлений и 8 удалений

Просмотреть файл

@ -314,8 +314,8 @@ mdview_get_memory_view(VALUE obj, rb_memory_view_t *view, int flags)
static bool
mdview_release_memory_view(VALUE obj, rb_memory_view_t *view)
{
if (view->shape) xfree(view->shape);
if (view->strides) xfree(view->strides);
if (view->shape) xfree((void *)view->shape);
if (view->strides) xfree((void *)view->strides);
return true;
}

Просмотреть файл

@ -80,7 +80,7 @@ typedef struct {
* item structure. rb_memory_view_prepare_item_desc and
* rb_memory_view_get_item allocate this memory if needed,
* and rb_memory_view_release frees it. */
rb_memory_view_item_component_t *components;
const rb_memory_view_item_component_t *components;
/* The number of components in an item. */
size_t length;
@ -91,15 +91,15 @@ typedef struct {
/* ndim size array indicating the number of elements in each dimension.
* This can be NULL when ndim == 1. */
ssize_t *shape;
const ssize_t *shape;
/* ndim size array indicating the number of bytes to skip to go to the
* next element in each dimension. */
ssize_t *strides;
const ssize_t *strides;
/* The offset in each dimension when this memory view exposes a nested array.
* Or, NULL when this memory view exposes a flat array. */
ssize_t *sub_offsets;
const ssize_t *sub_offsets;
/* the private data for managing this exported memory */
void *const private;

Просмотреть файл

@ -748,7 +748,9 @@ rb_memory_view_prepare_item_desc(rb_memory_view_t *view)
{
if (view->item_desc.components == NULL) {
const char *err;
ssize_t n = rb_memory_view_parse_item_format(view->format, &view->item_desc.components, &view->item_desc.length, &err);
rb_memory_view_item_component_t **p_components =
(rb_memory_view_item_component_t **)&view->item_desc.components;
ssize_t n = rb_memory_view_parse_item_format(view->format, p_components, &view->item_desc.length, &err);
if (n < 0) {
rb_raise(rb_eRuntimeError,
"Unable to parse item format at %"PRIdSIZE" in \"%s\"",
@ -841,7 +843,7 @@ rb_memory_view_release(rb_memory_view_t* view)
unregister_exported_object(view->obj);
view->obj = Qnil;
if (view->item_desc.components) {
xfree(view->item_desc.components);
xfree((void *)view->item_desc.components);
}
}
return rv;