Ruby: memory_view.c File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Enumerations | Functions | Variables
memory_view.c File Reference
`#include "internal.h"`
`#include "internal/hash.h"`
`#include "internal/variable.h"`
`#include "internal/util.h"`
`#include "ruby/memory_view.h"`
`#include "vm_sync.h"`

Go to the source code of this file.

## Macros
#define | INTPTR2NUM LL2NUM
#define | UINTPTR2NUM ULL2NUM
#define | STRUCT_ALIGNOF(T, result)

## Enumerations
enum | endianness_t { ENDIANNESS_NATIVE , ENDIANNESS_LITTLE , ENDIANNESS_BIG }

## Functions
bool | rb_memory_view_register (VALUE klass, const rb_memory_view_entry_t *entry)
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)
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)
ssize_t | rb_memory_view_item_size_from_format (const char *format, const char **err)
void * | rb_memory_view_get_item_pointer (rb_memory_view_t *view, const ssize_t *indices)
VALUE | rb_memory_view_extract_item_member (const void *ptr, const rb_memory_view_item_component_t *member, const size_t i)
VALUE | rb_memory_view_extract_item_members (const void *ptr, const rb_memory_view_item_component_t *members, const size_t n_members)
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)
bool | rb_memory_view_available_p (VALUE obj)
bool | rb_memory_view_get (VALUE obj, rb_memory_view_t *view, int flags)
bool | rb_memory_view_release (rb_memory_view_t *view)
void | Init_MemoryView (void)

## Variables
VALUE | rb_memory_view_exported_object_registry = Qundef
const rb_data_type_t | rb_memory_view_exported_object_registry_data_type

## Macro Definition Documentation

## ◆ INTPTR2NUM

#define INTPTR2NUM LL2NUM

Definition at line 17 of file memory_view.c.

## ◆ STRUCT_ALIGNOF

#define STRUCT_ALIGNOF | ( |  | T,
|  |  | result
| ) |  |

Value:
do { \
(result) = RUBY_ALIGNOF(T); \
} while(0)
RUBY_ALIGNOF
#define RUBY_ALIGNOF
Definition: stdalign.h:28
T
unsigned char T
Definition: cls_uchar_va.c:10

Definition at line 28 of file memory_view.c.

## ◆ UINTPTR2NUM

#define UINTPTR2NUM ULL2NUM

Definition at line 18 of file memory_view.c.

## Enumeration Type Documentation

## ◆ endianness_t

enum endianness_t

Enumerator
ENDIANNESS_NATIVE |
ENDIANNESS_LITTLE |
ENDIANNESS_BIG |

Definition at line 224 of file memory_view.c.

## Function Documentation

## ◆ Init_MemoryView()

void Init_MemoryView | ( | void |  | ) |

Definition at line 856 of file memory_view.c.

References rb_gc_register_mark_object(), rb_init_identtable(), rb_memory_view_exported_object_registry, rb_memory_view_exported_object_registry_data_type, and TypedData_Wrap_Struct.

## ◆ rb_memory_view_available_p()

bool rb_memory_view_available_p | ( | VALUE | obj | ) |

Definition at line 800 of file memory_view.c.

References rb_memory_view_entry_t::available_p_func, and CLASS_OF.

## ◆ rb_memory_view_extract_item_member()

VALUE rb_memory_view_extract_item_member | ( | const void * | ptr,
|  | const rb_memory_view_item_component_t * | member,
|  | const size_t | i
| ) |  |

Definition at line 711 of file memory_view.c.

References NULL, ptr, Qnil, and rb_memory_view_item_component_t::repeat.

Referenced by rb_memory_view_extract_item_members().

## ◆ rb_memory_view_extract_item_members()

VALUE rb_memory_view_extract_item_members | ( | const void * | ptr,
|  | const rb_memory_view_item_component_t * | members,
|  | const size_t | n_members
| ) |  |

Definition at line 724 of file memory_view.c.

References NULL, ptr, Qnil, rb_ary_new(), rb_ary_push(), rb_memory_view_extract_item_member(), and rb_memory_view_item_component_t::repeat.

Referenced by rb_memory_view_get_item().

## ◆ rb_memory_view_fill_contiguous_strides()

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

Definition at line 179 of file memory_view.c.

## ◆ rb_memory_view_get()

bool rb_memory_view_get | ( | VALUE | obj,
|  | rb_memory_view_t * | view,
|  | int | flags
| ) |  |

Definition at line 812 of file memory_view.c.

References rb_memory_view_entry_t::available_p_func, CLASS_OF, rb_memory_view_entry_t::get_func, and rb_memory_view_t::obj.

## ◆ rb_memory_view_get_item()

VALUE rb_memory_view_get_item | ( | rb_memory_view_t * | view,
|  | const ssize_t * | indices
| ) |  |

Definition at line 764 of file memory_view.c.

References rb_memory_view_t::components, rb_memory_view_t::format, INT2FIX, rb_memory_view_t::item_desc, rb_memory_view_t::length, NULL, ptr, rb_memory_view_extract_item_members(), rb_memory_view_get_item_pointer(), and rb_memory_view_prepare_item_desc().

## ◆ rb_memory_view_get_item_pointer()

void * rb_memory_view_get_item_pointer | ( | rb_memory_view_t * | view,
|  | const ssize_t * | indices
| ) |  |

Definition at line 510 of file memory_view.c.

References assert, rb_memory_view_t::data, rb_memory_view_t::item_size, rb_memory_view_t::ndim, NULL, ptr, rb_memory_view_t::shape, rb_memory_view_t::strides, and rb_memory_view_t::sub_offsets.

Referenced by rb_memory_view_get_item().

## ◆ rb_memory_view_init_as_byte_array()

bool rb_memory_view_init_as_byte_array | ( | rb_memory_view_t * | view,
|  | VALUE | obj,
|  | void * | data,
|  | const ssize_t | len,
|  | const bool | readonly
| ) |  |

Definition at line 198 of file memory_view.c.

References rb_memory_view_t::byte_size, rb_memory_view_t::components, rb_memory_view_t::data, rb_memory_view_t::format, rb_memory_view_t::item_desc, rb_memory_view_t::item_size, len, rb_memory_view_t::length, rb_memory_view_t::ndim, NULL, rb_memory_view_t::obj, rb_memory_view_t::private, rb_memory_view_t::readonly, rb_memory_view_t::shape, rb_memory_view_t::strides, and rb_memory_view_t::sub_offsets.

## ◆ rb_memory_view_is_column_major_contiguous()

bool rb_memory_view_is_column_major_contiguous | ( | const rb_memory_view_t * | view | ) |

Definition at line 163 of file memory_view.c.

References rb_memory_view_t::item_size, rb_memory_view_t::ndim, rb_memory_view_t::shape, and rb_memory_view_t::strides.

## ◆ rb_memory_view_is_row_major_contiguous()

bool rb_memory_view_is_row_major_contiguous | ( | const rb_memory_view_t * | view | ) |

Definition at line 147 of file memory_view.c.

References rb_memory_view_t::item_size, rb_memory_view_t::ndim, rb_memory_view_t::shape, and rb_memory_view_t::strides.

## ◆ rb_memory_view_item_size_from_format()

ssize_t rb_memory_view_item_size_from_format | ( | const char * | format,
|  | const char ** | err
| ) |  |

Definition at line 503 of file memory_view.c.

References err, NULL, and rb_memory_view_parse_item_format().

## ◆ rb_memory_view_parse_item_format()

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

Definition at line 386 of file memory_view.c.

References ALLOC_N, count, ENDIANNESS_BIG, ENDIANNESS_LITTLE, ENDIANNESS_NATIVE, err, error(), ISSPACE, len, NULL, and Qnil.

Referenced by rb_memory_view_item_size_from_format(), and rb_memory_view_prepare_item_desc().

## ◆ rb_memory_view_prepare_item_desc()

void rb_memory_view_prepare_item_desc | ( | rb_memory_view_t * | view | ) |

Definition at line 747 of file memory_view.c.

References rb_memory_view_t::components, err, rb_memory_view_t::format, rb_memory_view_t::item_desc, rb_memory_view_t::length, NULL, PRIdSIZE, rb_eRuntimeError, rb_memory_view_parse_item_format(), and rb_raise().

Referenced by rb_memory_view_get_item().

## ◆ rb_memory_view_register()

bool rb_memory_view_register | ( | VALUE | klass,
|  | const rb_memory_view_entry_t * | entry
| ) |  |

Definition at line 131 of file memory_view.c.

References NIL_P, PRIsVALUE, Qnil, rb_ivar_lookup(), rb_ivar_set(), rb_warning(), T_CLASS, and TypedData_Wrap_Struct.

Referenced by Init_fiddle_pointer().

## ◆ rb_memory_view_release()

bool rb_memory_view_release | ( | rb_memory_view_t * | view | ) |

Definition at line 833 of file memory_view.c.

References CLASS_OF, rb_memory_view_t::components, rb_memory_view_t::item_desc, rb_memory_view_t::obj, Qnil, rb_memory_view_entry_t::release_func, and xfree.

## Variable Documentation

## ◆ rb_memory_view_exported_object_registry

VALUE rb_memory_view_exported_object_registry = Qundef

Definition at line 35 of file memory_view.c.

Referenced by Init_MemoryView().

## ◆ rb_memory_view_exported_object_registry_data_type

const rb_data_type_t rb_memory_view_exported_object_registry_data_type

Initial value:
= {
"memory_view/exported_object_registry",
{
exported_object_registry_mark,
exported_object_registry_free,
0,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
}
RUBY_TYPED_FREE_IMMEDIATELY
@ RUBY_TYPED_FREE_IMMEDIATELY
Definition: rtypeddata.h:62

Definition at line 61 of file memory_view.c.

Referenced by Init_MemoryView().