10
10
11
11
static ID id_buffer_protocol ;
12
12
13
- static const rb_data_type_t random_mt_type = {
13
+ static const rb_data_type_t buffer_protocol_type = {
14
14
"buffer_protocol" ,
15
15
{
16
16
0 ,
@@ -21,8 +21,8 @@ static const rb_data_type_t random_mt_type = {
21
21
};
22
22
23
23
/* Register buffer protocol functions for the given class */
24
- int
25
- rb_buffer_protocol_register_klass (VALUE klass , const rb_buffer_protocol_entry_t * entry ) {
24
+ bool
25
+ rb_buffer_protocol_register (VALUE klass , const rb_buffer_protocol_entry_t * entry ) {
26
26
VALUE entry_obj = rb_ivar_get (klass , id_buffer_protocol );
27
27
if (! NIL_P (entry_obj )) {
28
28
rb_warning ("Duplicated registration of buffer protocol to %" PRIsVALUE , klass );
40
40
rb_buffer_is_row_major_contiguous (const rb_buffer_t * view )
41
41
{
42
42
const ssize_t ndim = view -> ndim ;
43
- const ssize_t * shape = view -> shape ;
44
- const ssize_t * strides = view -> strides ;
43
+ const ssize_t * shape = view -> shape ;
44
+ const ssize_t * strides = view -> strides ;
45
45
ssize_t n = view -> item_size ;
46
46
ssize_t i ;
47
- for (i = view -> ndim - 1 ; i >= 0 ; -- i ) {
47
+ for (i = ndim - 1 ; i >= 0 ; -- i ) {
48
48
if (strides [i ] != n ) return 0 ;
49
49
n *= shape [i ];
50
50
}
56
56
rb_buffer_is_column_major_contiguous (const rb_buffer_t * view )
57
57
{
58
58
const ssize_t ndim = view -> ndim ;
59
- const ssize_t * shape = view -> shape ;
60
- const ssize_t * strides = view -> strides ;
59
+ const ssize_t * shape = view -> shape ;
60
+ const ssize_t * strides = view -> strides ;
61
61
ssize_t n = view -> item_size ;
62
62
ssize_t i ;
63
63
for (i = 0 ; i < ndim ; ++ i ) {
@@ -88,12 +88,11 @@ rb_buffer_fill_contiguous_strides(const int ndim, const int item_size, const ssi
88
88
89
89
/* Initialize view to expose a simple byte array */
90
90
int
91
- rb_buffer_init_as_byte_array (rb_buffer_t * view , VALUE obj , void * data , ssize_t len , int readonly , int flags )
91
+ rb_buffer_init_as_byte_array (rb_buffer_t * view , VALUE obj , void * data , ssize_t len , int read_only , int flags )
92
92
{
93
- view -> obj = obj ;
94
93
view -> data = data ;
95
94
view -> len = len ;
96
- view -> readonly = readonly ;
95
+ view -> read_only = read_only ;
97
96
view -> format = NULL ;
98
97
view -> item_size = 1 ;
99
98
view -> ndim = 1 ;
@@ -226,7 +225,7 @@ rb_buffer_get_item_pointer(rb_buffer_t *view, ssize_t *indices)
226
225
static rb_buffer_protocol_entry_t *
227
226
lookup_buffer_protocol_entry (VALUE klass ) {
228
227
VALUE entry_obj = rb_ivar_get (klass , id_buffer_protocol );
229
- while (entry_obj == Qnil ) {
228
+ while (NIL_P ( entry_obj ) ) {
230
229
klass = rb_class_get_superclass (klass );
231
230
232
231
if (klass == rb_cBasicObject || klass == rb_cObject )
@@ -238,20 +237,20 @@ lookup_buffer_protocol_entry(VALUE klass) {
238
237
if (! rb_typeddata_is_kind_of (entry_obj , & buffer_protocol_entry_data_type ))
239
238
return NULL ;
240
239
241
- return (rb_buffer_protocol_entry_t * )DATA_PTR (entry_obj );
240
+ return (rb_buffer_protocol_entry_t * )RTYPEDDATA_PTR (entry_obj );
242
241
}
243
242
244
243
/* Examine whether the given object supports buffer protocol. */
245
244
int
246
- rb_obj_has_buffer_protocol (VALUE obj )
245
+ rb_buffer_protocol_available_p (VALUE obj )
247
246
{
248
247
VALUE klass = CLASS_OF (obj );
249
248
return lookup_buffer_protocol_entry (klass ) != NULL ;
250
249
}
251
250
252
251
/* Obtain a buffer from obj, and substitute the information to view. */
253
252
int
254
- rb_obj_get_buffer (VALUE obj , rb_buffer_t * view , int flags ) {
253
+ rb_buffer_protocol_get_buffer (VALUE obj , rb_buffer_t * view , int flags ) {
255
254
VALUE klass = CLASS_OF (obj );
256
255
rb_buffer_protocol_entry_t * entry = lookup_buffer_protocol_entry (klass );
257
256
if (entry )
@@ -262,7 +261,7 @@ rb_obj_get_buffer(VALUE obj, rb_buffer_t* view, int flags) {
262
261
263
262
/* Release the buffer view obtained from obj. */
264
263
int
265
- rb_obj_release_buffer (VALUE obj , rb_buffer_t * view ) {
264
+ rb_buffer_protocol_release_buffer (VALUE obj , rb_buffer_t * view ) {
266
265
VALUE klass = CLASS_OF (obj );
267
266
rb_buffer_protocol_entry_t * entry = lookup_buffer_protocol_entry (klass );
268
267
if (entry )
0 commit comments