mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
memory_view.c: Add _memory_view_entry member in rb_memory_view_t (#5088)
This commit is contained in:
parent
e0a5c3d2b7
commit
3501e0cbb5
Notes:
git
2021-11-08 12:52:35 +09:00
Merged-By: mrkn <mrkn@ruby-lang.org>
2 changed files with 12 additions and 7 deletions
|
@ -146,8 +146,11 @@ typedef struct {
|
|||
* Or, NULL when this memory view exposes a flat array. */
|
||||
const ssize_t *sub_offsets;
|
||||
|
||||
/** the private data for managing this exported memory */
|
||||
/** The private data for managing this exported memory */
|
||||
void *private_data;
|
||||
|
||||
/** DO NOT TOUCH THIS: The memory view entry for the internal use */
|
||||
const struct rb_memory_view_entry *_memory_view_entry;
|
||||
} rb_memory_view_t;
|
||||
|
||||
/** Type of function of ::rb_memory_view_entry_t::get_func. */
|
||||
|
@ -160,9 +163,10 @@ 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);
|
||||
|
||||
/** Operations applied to a specific kind of a memory view. */
|
||||
typedef struct {
|
||||
|
||||
/** Exports a memory view from a Ruby object. */
|
||||
typedef struct rb_memory_view_entry {
|
||||
/**
|
||||
* Exports a memory view from a Ruby object.
|
||||
*/
|
||||
rb_memory_view_get_func_t get_func;
|
||||
|
||||
/**
|
||||
|
|
|
@ -108,7 +108,8 @@ static void
|
|||
unregister_exported_object(VALUE obj)
|
||||
{
|
||||
RB_VM_LOCK_ENTER();
|
||||
st_update(exported_object_table, (st_data_t)obj, exported_object_dec_ref, 0);
|
||||
if (exported_object_table)
|
||||
st_update(exported_object_table, (st_data_t)obj, exported_object_dec_ref, 0);
|
||||
RB_VM_LOCK_LEAVE();
|
||||
}
|
||||
|
||||
|
@ -822,6 +823,7 @@ rb_memory_view_get(VALUE obj, rb_memory_view_t* view, int flags)
|
|||
|
||||
bool rv = (*entry->get_func)(obj, view, flags);
|
||||
if (rv) {
|
||||
view->_memory_view_entry = entry;
|
||||
register_exported_object(view->obj);
|
||||
}
|
||||
return rv;
|
||||
|
@ -834,8 +836,7 @@ rb_memory_view_get(VALUE obj, rb_memory_view_t* view, int flags)
|
|||
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);
|
||||
const rb_memory_view_entry_t *entry = view->_memory_view_entry;
|
||||
if (entry) {
|
||||
bool rv = true;
|
||||
if (entry->release_func) {
|
||||
|
|
Loading…
Reference in a new issue