Ruby: include/ruby/memory_view.h File Reference

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

Data Structures | Typedefs | Enumerations | Functions | Variables
memory_view.h File Reference

Memory View. More...

`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/stdbool.h"`
`#include "ruby/internal/value.h"`
`#include "ruby/intern.h"`

Go to the source code of this file.

## Data Structures
struct | rb_memory_view_item_component_t
struct | rb_memory_view_t
struct | rb_memory_view_entry_t

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

## Enumerations
enum | ruby_memory_view_flags { RUBY_MEMORY_VIEW_SIMPLE = 0 , RUBY_MEMORY_VIEW_WRITABLE = (1<<0) , RUBY_MEMORY_VIEW_FORMAT = (1<<1) , RUBY_MEMORY_VIEW_MULTI_DIMENSIONAL = (1<<2) , RUBY_MEMORY_VIEW_STRIDES = (1<<3) | RUBY_MEMORY_VIEW_MULTI_DIMENSIONAL , RUBY_MEMORY_VIEW_ROW_MAJOR = (1<<4) | RUBY_MEMORY_VIEW_STRIDES , RUBY_MEMORY_VIEW_COLUMN_MAJOR = (1<<5) | RUBY_MEMORY_VIEW_STRIDES , RUBY_MEMORY_VIEW_ANY_CONTIGUOUS = RUBY_MEMORY_VIEW_ROW_MAJOR | RUBY_MEMORY_VIEW_COLUMN_MAJOR , RUBY_MEMORY_VIEW_INDIRECT = (1<<6) | RUBY_MEMORY_VIEW_STRIDES }

## 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_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 *memory_view, int flags)
bool | rb_memory_view_release (rb_memory_view_t *memory_view)

## Variables
VALUE | rb_memory_view_exported_object_registry
const rb_data_type_t | rb_memory_view_exported_object_registry_data_type

## Detailed Description

Memory View.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Definition in file memory_view.h.

## Typedef Documentation

## ◆ rb_memory_view_available_p_func_t

typedef bool(* rb_memory_view_available_p_func_t) (VALUE obj)

Definition at line 110 of file memory_view.h.

## ◆ rb_memory_view_get_func_t

typedef bool(* rb_memory_view_get_func_t) (VALUE obj, rb_memory_view_t *view, int flags)

Definition at line 108 of file memory_view.h.

## ◆ rb_memory_view_release_func_t

typedef bool(* rb_memory_view_release_func_t) (VALUE obj, rb_memory_view_t *view)

Definition at line 109 of file memory_view.h.

## Enumeration Type Documentation

## ◆ ruby_memory_view_flags

enum ruby_memory_view_flags

Enumerator
RUBY_MEMORY_VIEW_SIMPLE |
RUBY_MEMORY_VIEW_WRITABLE |
RUBY_MEMORY_VIEW_FORMAT |
RUBY_MEMORY_VIEW_MULTI_DIMENSIONAL |
RUBY_MEMORY_VIEW_STRIDES |
RUBY_MEMORY_VIEW_ROW_MAJOR |
RUBY_MEMORY_VIEW_COLUMN_MAJOR |
RUBY_MEMORY_VIEW_ANY_CONTIGUOUS |
RUBY_MEMORY_VIEW_INDIRECT |

Definition at line 18 of file memory_view.h.

## Function Documentation

## ◆ 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_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 * | memory_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 * | memory_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
| extern

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

Definition at line 61 of file memory_view.c.

Referenced by Init_MemoryView().