carray 3.0.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +7 -1830
- data/README.md +62 -35
- data/carray.gemspec +16 -4
- data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
- data/ext/ca_array_pool.c +4 -5
- data/ext/ca_axis_descriptor.h +45 -30
- data/ext/ca_axis_dispatch.c +7 -4
- data/ext/ca_axis_group.c +12 -15
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +35 -0
- data/ext/ca_binop_dispatch.h +22 -46
- data/ext/ca_categorical_iterator.c +36 -34
- data/ext/ca_compare.c +0 -1
- data/ext/ca_compare.h +8 -1
- data/ext/ca_composite_dispatch.h +6 -0
- data/ext/ca_for_buffer.h +6 -1
- data/ext/ca_group_iter.c +17 -18
- data/ext/ca_iter_state_fields.h +196 -0
- data/ext/ca_iter_substrate.h +84 -103
- data/ext/ca_kernel_iterator.c +125 -89
- data/ext/ca_kernel_iterator.h +229 -1504
- data/ext/ca_kernel_iterator_internal.h +1167 -0
- data/ext/ca_moncmp_dispatch.h +17 -24
- data/ext/ca_monop_dispatch.h +25 -74
- data/ext/ca_obj_array.c +92 -165
- data/ext/ca_obj_bincmp.c +65 -48
- data/ext/ca_obj_binop.c +74 -49
- data/ext/ca_obj_bitarray.c +7 -21
- data/ext/ca_obj_bitfield.c +93 -26
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +34 -34
- data/ext/ca_obj_const_string.c +464 -304
- data/ext/ca_obj_face.c +167 -121
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +127 -34
- data/ext/ca_obj_farray.c +13 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +57 -34
- data/ext/ca_obj_grid.c +149 -113
- data/ext/ca_obj_meld.c +28 -26
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +88 -73
- data/ext/ca_obj_object.c +60 -46
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +10 -14
- data/ext/ca_obj_refer.c +146 -39
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +20 -28
- data/ext/ca_obj_select.c +17 -27
- data/ext/ca_obj_select_axis.c +35 -42
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +33 -29
- data/ext/ca_obj_stride.c +99 -62
- data/ext/ca_obj_string.c +8 -20
- data/ext/ca_obj_tile.c +14 -16
- data/ext/ca_obj_time.c +12 -23
- data/ext/ca_obj_timedelta.c +12 -23
- data/ext/ca_obj_transpose.c +8 -10
- data/ext/ca_obj_triop.c +48 -49
- data/ext/ca_obj_window.c +87 -99
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +97 -27
- data/ext/ca_op_powi.h +9 -28
- data/ext/ca_pow5_table.h +2 -1
- data/ext/ca_rng_normal.h +4 -0
- data/ext/ca_rng_xoshiro256pp.h +3 -0
- data/ext/ca_sort_kernels.h +23 -26
- data/ext/ca_sweep_engine.c +92 -26
- data/ext/ca_sweep_engine.h +22 -15
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +12 -12
- data/ext/carray.h +300 -1009
- data/ext/carray_access.c +320 -207
- data/ext/carray_address_basis.c +128 -59
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +31 -27
- data/ext/carray_call_cfunc.c +174 -285
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +1191 -351
- data/ext/carray_cast_func.rb +68 -8
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +98 -39
- data/ext/carray_copy.c +52 -26
- data/ext/carray_core.c +286 -132
- data/ext/carray_count.c +53 -22
- data/ext/carray_element.c +49 -28
- data/ext/carray_factorize.c +64 -63
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +9 -11
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +127 -230
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1364 -156
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +37 -37
- data/ext/carray_loop.c +27 -23
- data/ext/carray_mask.c +235 -150
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +106 -100
- data/ext/carray_memory_view.c +83 -69
- data/ext/carray_operator.c +490 -128
- data/ext/carray_order.c +163 -84
- data/ext/carray_partition.c +14 -16
- data/ext/carray_random.c +48 -42
- data/ext/carray_round.c +33 -5
- data/ext/carray_scatter.c +57 -39
- data/ext/carray_segment.c +42 -46
- data/ext/carray_slab.c +77 -51
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +37 -31
- data/ext/carray_sort_kernel.c +36 -10
- data/ext/carray_struct.c +44 -34
- data/ext/carray_test.c +131 -81
- data/ext/carray_time_text.c +30 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +373 -139
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +25 -31
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +819 -488
- data/ext/ruby_carray.c +47 -42
- data/ext/version.h +7 -5
- data/lib/carray/attribute.rb +19 -18
- data/lib/carray/autoload_carray.rb +20 -15
- data/lib/carray/autoload_method_extension.rb +64 -57
- data/lib/carray/axis_group.rb +272 -185
- data/lib/carray/basics.rb +298 -56
- data/lib/carray/bincount_nd.rb +41 -18
- data/lib/carray/block_iterator.rb +167 -119
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +84 -59
- data/lib/carray/categorical_iterator.rb +90 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +98 -23
- data/lib/carray/const_string.rb +112 -46
- data/lib/carray/core_extensions.rb +20 -69
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +95 -12
- data/lib/carray/frame/column_verbs.rb +76 -9
- data/lib/carray/frame/concat.rb +51 -7
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +20 -5
- data/lib/carray/frame/frame.rb +73 -31
- data/lib/carray/frame/group.rb +247 -187
- data/lib/carray/frame/io.rb +36 -12
- data/lib/carray/frame/join.rb +56 -17
- data/lib/carray/frame/records.rb +7 -5
- data/lib/carray/frame/reshape.rb +27 -7
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +217 -134
- data/lib/carray/frame/windows.rb +254 -19
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +28 -23
- data/lib/carray/fusion.rb +30 -30
- data/lib/carray/histogram.rb +35 -16
- data/lib/carray/inspect.rb +7 -7
- data/lib/carray/iterator.rb +104 -23
- data/lib/carray/key_windows.rb +93 -61
- data/lib/carray/lazy.rb +208 -111
- data/lib/carray/limits.rb +80 -0
- data/lib/carray/mask_gap_fill.rb +21 -16
- data/lib/carray/math.rb +87 -50
- data/lib/carray/meld_reduce.rb +30 -8
- data/lib/carray/methods/align_addr.rb +29 -17
- data/lib/carray/methods/bin.rb +8 -1
- data/lib/carray/methods/bincount.rb +4 -2
- data/lib/carray/methods/bit_string.rb +19 -31
- data/lib/carray/methods/broadcast.rb +8 -3
- data/lib/carray/methods/choose.rb +5 -5
- data/lib/carray/methods/composition.rb +73 -72
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/factorize.rb +2 -0
- data/lib/carray/methods/gather_nd.rb +106 -103
- data/lib/carray/methods/insert_block.rb +2 -2
- data/lib/carray/methods/is_between.rb +6 -4
- data/lib/carray/methods/is_in.rb +183 -143
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +157 -94
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +28 -16
- data/lib/carray/methods/mode.rb +67 -67
- data/lib/carray/methods/nunique.rb +9 -7
- data/lib/carray/methods/repeat.rb +23 -13
- data/lib/carray/methods/resize.rb +1 -1
- data/lib/carray/methods/snap.rb +24 -20
- data/lib/carray/methods/string_format.rb +2 -2
- data/lib/carray/methods/unique.rb +4 -2
- data/lib/carray/methods/value_counts.rb +1 -1
- data/lib/carray/mkmf.rb +25 -28
- data/lib/carray/percentile_arguments.rb +82 -0
- data/lib/carray/record_order.rb +50 -20
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +195 -17
- data/lib/carray/segment_iterator.rb +262 -137
- data/lib/carray/serialize.rb +635 -566
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +14 -15
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +97 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +247 -73
- data/lib/carray/time.rb +663 -365
- data/lib/carray/window_iterator.rb +232 -155
- data/lib/carray.rb +6 -11
- data/yard-stubs/ca_obj_array.rb +20 -135
- data/yard-stubs/ca_obj_bitarray.rb +1 -8
- data/yard-stubs/ca_obj_bitfield.rb +6 -2
- data/yard-stubs/ca_obj_byte_swap.rb +21 -7
- data/yard-stubs/ca_obj_fake.rb +3 -1
- data/yard-stubs/ca_obj_farray.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +8 -6
- data/yard-stubs/ca_obj_refer.rb +10 -5
- data/yard-stubs/ca_obj_roll.rb +7 -6
- data/yard-stubs/ca_obj_shift.rb +2 -3
- data/yard-stubs/ca_obj_stride.rb +5 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_time.rb +43 -0
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +28 -16
- data/yard-stubs/carray_access.rb +55 -6
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +121 -162
- data/yard-stubs/carray_class.rb +3 -4
- data/yard-stubs/carray_conversion.rb +6 -7
- data/yard-stubs/carray_copy.rb +2 -1
- data/yard-stubs/carray_count.rb +10 -5
- data/yard-stubs/carray_element.rb +4 -3
- data/yard-stubs/carray_limits.rb +100 -0
- data/yard-stubs/carray_loop.rb +0 -20
- data/yard-stubs/carray_mask.rb +59 -41
- data/yard-stubs/carray_math.rb +162 -100
- data/yard-stubs/carray_mathfunc.rb +415 -3
- data/yard-stubs/carray_median_percentile.rb +29 -11
- data/yard-stubs/carray_memory_view.rb +2 -2
- data/yard-stubs/carray_order.rb +72 -33
- data/yard-stubs/carray_random.rb +6 -6
- data/yard-stubs/carray_reduce.rb +353 -0
- data/yard-stubs/carray_rng.rb +92 -0
- data/yard-stubs/carray_scatter.rb +12 -3
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_test.rb +18 -5
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +63 -25
- data/CHANGELOG.v1.md +0 -126
- data/ext/carray_build_flags.h +0 -3
- data/ext/carray_config.h +0 -28
- data/ext/carray_data_type.c +0 -90
- data/ext/carray_kernels_bincmp.c +0 -6457
- data/ext/carray_kernels_binop.c +0 -31534
- data/ext/carray_kernels_init.c +0 -1734
- data/ext/carray_kernels_moncmp.c +0 -2104
- data/ext/carray_kernels_monop.c +0 -25387
- data/ext/carray_kernels_reduce_aggregate.c +0 -27545
- data/ext/carray_kernels_reduce_boolean.c +0 -1924
- data/ext/carray_kernels_reduce_cumulative.c +0 -11646
- data/ext/carray_kernels_reduce_extreme.c +0 -21631
- data/ext/carray_kernels_reduce_variance.c +0 -5981
- data/ext/carray_kernels_scan.c +0 -4302
- data/ext/carray_kernels_search.c +0 -37776
- data/ext/carray_kernels_sort.c +0 -10814
- data/ext/carray_kernels_triop.c +0 -1864
- data/lib/carray/construct.rb +0 -360
- data/lib/carray/data_type_extension.rb +0 -261
- data/lib/carray/data_type_limits.rb +0 -91
data/ext/carray_core.c
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
---------------------------------------------------------------------------- */
|
|
9
9
|
|
|
10
10
|
#include "carray.h"
|
|
11
|
-
#include "
|
|
11
|
+
#include "ruby/version.h"
|
|
12
12
|
#include "ca_iter_substrate.h"
|
|
13
13
|
#include "ca_obj_face.h"
|
|
14
14
|
#include <stdarg.h>
|
|
@@ -320,7 +320,7 @@ ca_init_obj_type (void)
|
|
|
320
320
|
regsters a sub-class of CArray
|
|
321
321
|
*/
|
|
322
322
|
|
|
323
|
-
|
|
323
|
+
int16_t
|
|
324
324
|
ca_install_obj_type (VALUE klass,
|
|
325
325
|
const rb_data_type_t *typeddata,
|
|
326
326
|
VALUE mask_klass,
|
|
@@ -328,19 +328,18 @@ ca_install_obj_type (VALUE klass,
|
|
|
328
328
|
const ca_operation_function_t *func,
|
|
329
329
|
size_t func_size)
|
|
330
330
|
{
|
|
331
|
-
|
|
331
|
+
int16_t obj_type;
|
|
332
332
|
|
|
333
|
-
|
|
334
|
-
int8_t, so a number of 128 or above cannot be passed to them. */
|
|
335
|
-
if ( ca_obj_num > INT8_MAX || ca_obj_num + 1 >= CA_OBJ_TYPE_MAX ) {
|
|
333
|
+
if ( ca_obj_num >= CA_OBJ_TYPE_MAX ) {
|
|
336
334
|
rb_raise(rb_eRuntimeError,
|
|
337
|
-
"internal: too many CArray object types installed (an obj_type is numbered below
|
|
335
|
+
"internal: too many CArray object types installed (an obj_type is numbered below %d)",
|
|
336
|
+
CA_OBJ_TYPE_MAX);
|
|
338
337
|
}
|
|
339
338
|
|
|
340
339
|
if ( func_size > sizeof(ca_operation_function_t) ) {
|
|
341
340
|
rb_raise(rb_eRuntimeError,
|
|
342
|
-
"operation table is larger than this
|
|
343
|
-
"the caller was built against a newer carray",
|
|
341
|
+
"ca_install_obj_type: operation table is larger than this "
|
|
342
|
+
"carray's (%zu > %zu); the caller was built against a newer carray",
|
|
344
343
|
func_size, sizeof(ca_operation_function_t));
|
|
345
344
|
}
|
|
346
345
|
|
|
@@ -349,7 +348,8 @@ ca_install_obj_type (VALUE klass,
|
|
|
349
348
|
if ( func_size < offsetof(ca_operation_function_t, xfer_all) +
|
|
350
349
|
sizeof(((ca_operation_function_t *) 0)->xfer_all) ) {
|
|
351
350
|
rb_raise(rb_eRuntimeError,
|
|
352
|
-
"operation table is too small to dispatch
|
|
351
|
+
"ca_install_obj_type: operation table is too small to dispatch "
|
|
352
|
+
"(%zu < %zu)",
|
|
353
353
|
func_size,
|
|
354
354
|
(size_t) (offsetof(ca_operation_function_t, xfer_all) +
|
|
355
355
|
sizeof(((ca_operation_function_t *) 0)->xfer_all)));
|
|
@@ -364,7 +364,7 @@ ca_install_obj_type (VALUE klass,
|
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
/* A refused table takes no number. */
|
|
367
|
-
obj_type = ca_obj_num++;
|
|
367
|
+
obj_type = (int16_t) ca_obj_num++;
|
|
368
368
|
|
|
369
369
|
/* Copy by the caller's length and zero the rest: slots this build knows
|
|
370
370
|
about but the caller does not are NULL, which every dispatcher already
|
|
@@ -381,6 +381,23 @@ ca_install_obj_type (VALUE klass,
|
|
|
381
381
|
return obj_type;
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
+
void
|
|
385
|
+
ca_operation_table_copy (int16_t obj_type, ca_operation_function_t *dst,
|
|
386
|
+
size_t size)
|
|
387
|
+
{
|
|
388
|
+
if ( obj_type < 0 || obj_type >= ca_obj_num ) {
|
|
389
|
+
rb_raise(rb_eArgError,
|
|
390
|
+
"ca_operation_table_copy: obj_type %d is not installed",
|
|
391
|
+
obj_type);
|
|
392
|
+
}
|
|
393
|
+
if ( size > sizeof(ca_operation_function_t) ) {
|
|
394
|
+
memset((char *) dst + sizeof(ca_operation_function_t), 0,
|
|
395
|
+
size - sizeof(ca_operation_function_t));
|
|
396
|
+
size = sizeof(ca_operation_function_t);
|
|
397
|
+
}
|
|
398
|
+
memcpy(dst, &ca_func[obj_type], size);
|
|
399
|
+
}
|
|
400
|
+
|
|
384
401
|
/* ------------------------------------------------------------------- */
|
|
385
402
|
|
|
386
403
|
/* api: ca_mark
|
|
@@ -407,6 +424,7 @@ ca_mark (void *ap)
|
|
|
407
424
|
free function for the carray object needs free operation.
|
|
408
425
|
*/
|
|
409
426
|
|
|
427
|
+
/* recursion: frees this array only; a free never raises */
|
|
410
428
|
void
|
|
411
429
|
ca_free (void *ap)
|
|
412
430
|
{
|
|
@@ -445,6 +463,7 @@ ca_attach_is_alias (void *ap)
|
|
|
445
463
|
extern ca_operation_function_t ca_lazy_marker_func;
|
|
446
464
|
extern int ca_stride_attach_aliases_root (CAStride *ca);
|
|
447
465
|
|
|
466
|
+
ca_check_stack_room();
|
|
448
467
|
if ( ca == NULL ) return 0;
|
|
449
468
|
if ( ca_is_entity(ca) ) return 1;
|
|
450
469
|
|
|
@@ -495,13 +514,13 @@ ca_attach_is_alias (void *ap)
|
|
|
495
514
|
rather than at the slab walk). Mask is NULL on the output (=
|
|
496
515
|
reduction kernels populate it themselves if needed). */
|
|
497
516
|
VALUE
|
|
498
|
-
rb_ca_new_reduced_bytes (VALUE self, int8_t *slab_axes, int8_t naxes,
|
|
517
|
+
rb_ca_new_reduced_bytes (volatile VALUE self, int8_t *slab_axes, int8_t naxes,
|
|
499
518
|
int32_t data_type, ca_size_t bytes, int keep_axis)
|
|
500
519
|
{
|
|
501
520
|
CArray *ca;
|
|
502
521
|
int8_t k;
|
|
503
522
|
|
|
504
|
-
|
|
523
|
+
GetCArray(self, ca);
|
|
505
524
|
|
|
506
525
|
if ( naxes <= 0 || naxes > ca->ndim ) {
|
|
507
526
|
rb_raise(rb_eArgError,
|
|
@@ -561,7 +580,7 @@ rb_ca_new_reduced_bytes (VALUE self, int8_t *slab_axes, int8_t naxes,
|
|
|
561
580
|
}
|
|
562
581
|
|
|
563
582
|
/* Fixed-element-size wrapper: the byte width is looked up from ca_sizeof,
|
|
564
|
-
which rejects CA_FIXLEN
|
|
583
|
+
which rejects CA_FIXLEN (runtime-width cells). A
|
|
565
584
|
reduction whose output is a runtime-width data_type (fixlen min / max)
|
|
566
585
|
must call rb_ca_new_reduced_bytes with the source's own byte width. */
|
|
567
586
|
VALUE
|
|
@@ -625,7 +644,7 @@ parse_axes_items (const VALUE *items, int count, CArray *ca,
|
|
|
625
644
|
}
|
|
626
645
|
if ( count > CA_RANK_MAX ) { /* rank-check: a list of axes, no longer than the rank */
|
|
627
646
|
rb_raise(rb_eArgError,
|
|
628
|
-
"%s: too many axes (%d >
|
|
647
|
+
"%s: too many axes (%d > CArray::RANK_MAX=%d)",
|
|
629
648
|
CA_CTX_NAME(ctx), count, CA_RANK_MAX);
|
|
630
649
|
}
|
|
631
650
|
if ( count > ca->ndim ) {
|
|
@@ -636,7 +655,7 @@ parse_axes_items (const VALUE *items, int count, CArray *ca,
|
|
|
636
655
|
|
|
637
656
|
for ( i = 0; i < CA_RANK_MAX; i++ ) seen[i] = 0;
|
|
638
657
|
for ( i = 0; i < count; i++ ) {
|
|
639
|
-
ca_size_t a =
|
|
658
|
+
ca_size_t a = rb_ca_normalize_axis_arg(items[i], (int) ca->ndim, ctx);
|
|
640
659
|
if ( seen[a] ) {
|
|
641
660
|
rb_raise(rb_eArgError,
|
|
642
661
|
"%s: duplicate axis %ld", CA_CTX_NAME(ctx), (long) a);
|
|
@@ -667,7 +686,7 @@ rb_ca_parse_reduce_axes (int argc, VALUE *argv, CArray *ca, int8_t *out_axes)
|
|
|
667
686
|
const VALUE *items = (const VALUE *) argv;
|
|
668
687
|
int count = argc;
|
|
669
688
|
if ( argc == 1 && TYPE(argv[0]) == T_ARRAY ) {
|
|
670
|
-
VALUE arr = argv[0];
|
|
689
|
+
volatile VALUE arr = argv[0];
|
|
671
690
|
count = (int) RARRAY_LEN(arr);
|
|
672
691
|
items = (const VALUE *) RARRAY_CONST_PTR(arr);
|
|
673
692
|
}
|
|
@@ -688,7 +707,7 @@ rb_ca_parse_reduce_axes (int argc, VALUE *argv, CArray *ca, int8_t *out_axes)
|
|
|
688
707
|
variadic entry. out_axes[] receives axes in input order. Returns
|
|
689
708
|
the validated naxes. */
|
|
690
709
|
int8_t
|
|
691
|
-
rb_ca_parse_reduce_axes_kw_ctx (VALUE axis_val, CArray *ca, int8_t *out_axes,
|
|
710
|
+
rb_ca_parse_reduce_axes_kw_ctx (volatile VALUE axis_val, CArray *ca, int8_t *out_axes,
|
|
692
711
|
const char *ctx)
|
|
693
712
|
{
|
|
694
713
|
int i;
|
|
@@ -707,7 +726,8 @@ rb_ca_parse_reduce_axes_kw_ctx (VALUE axis_val, CArray *ca, int8_t *out_axes,
|
|
|
707
726
|
}
|
|
708
727
|
|
|
709
728
|
if ( rb_obj_is_kind_of(axis_val, rb_cInteger) ) {
|
|
710
|
-
|
|
729
|
+
VALUE item = axis_val;
|
|
730
|
+
return parse_axes_items(&item, 1, ca, out_axes, ctx);
|
|
711
731
|
}
|
|
712
732
|
|
|
713
733
|
rb_raise(rb_eTypeError,
|
|
@@ -909,6 +929,7 @@ static VALUE ca_recursion_probe (VALUE key, VALUE arg, int recursive);
|
|
|
909
929
|
would come back into that evaluation when it is computed. The walk is
|
|
910
930
|
bounded; past the bound the value is not refused here, and is caught when
|
|
911
931
|
it is evaluated, as a deeper expression is. */
|
|
932
|
+
/* recursion: stops when its budget runs out */
|
|
912
933
|
static int
|
|
913
934
|
ca_reaches_evaluating_walk (CArray *ca, int *budget)
|
|
914
935
|
{
|
|
@@ -946,7 +967,8 @@ ca_refuse_cells_reaching_evaluation (ca_size_t n, const VALUE *cells)
|
|
|
946
967
|
if ( rb_obj_is_carray(cells[i]) ) {
|
|
947
968
|
CArray *cv;
|
|
948
969
|
int budget = 1024;
|
|
949
|
-
|
|
970
|
+
/* gc: the caller holds the cells */
|
|
971
|
+
GetCArray(cells[i], cv);
|
|
950
972
|
if ( ! ca_is_entity(cv) && ca_reaches_evaluating_walk(cv, &budget) ) {
|
|
951
973
|
ca_refuse_cyclic(CA_RECURSION_COMPUTE);
|
|
952
974
|
}
|
|
@@ -954,15 +976,29 @@ ca_refuse_cells_reaching_evaluation (ca_size_t n, const VALUE *cells)
|
|
|
954
976
|
}
|
|
955
977
|
}
|
|
956
978
|
|
|
979
|
+
static VALUE
|
|
980
|
+
ca_computing_start (VALUE arg)
|
|
981
|
+
{
|
|
982
|
+
return ca_computing_next((ca_computing_t *) arg);
|
|
983
|
+
}
|
|
984
|
+
|
|
957
985
|
/* Runs body(arg), a computation over ops[0..n), with each object array
|
|
958
986
|
among them recorded as computed over. Raises when one of them is
|
|
959
987
|
already being computed over by the same method: a cell's value, or an
|
|
960
|
-
element's operation, led the computation back into it.
|
|
988
|
+
element's operation, led the computation back into it. A computation
|
|
989
|
+
over object cells calls methods of the cells, so it counts as a walk into
|
|
990
|
+
them (ca_cell_walk_run). */
|
|
961
991
|
VALUE
|
|
962
992
|
ca_computing_run (int n, CArray **ops, VALUE (*body)(VALUE), VALUE arg)
|
|
963
993
|
{
|
|
964
994
|
ca_computing_t c;
|
|
995
|
+
int k;
|
|
965
996
|
c.n = n; c.ops = ops; c.kind = CA_RECURSION_COMPUTE; c.k = 0; c.body = body; c.arg = arg;
|
|
997
|
+
for (k=0; k<n; k++) {
|
|
998
|
+
if ( ops[k] && ca_is_object_type(ops[k]) ) {
|
|
999
|
+
return ca_cell_walk_run(ca_computing_start, (VALUE) &c);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
966
1002
|
return ca_computing_next(&c);
|
|
967
1003
|
}
|
|
968
1004
|
|
|
@@ -985,6 +1021,55 @@ ca_recursion_probe (VALUE key, VALUE arg, int recursive)
|
|
|
985
1021
|
return recursive ? Qtrue : Qfalse;
|
|
986
1022
|
}
|
|
987
1023
|
|
|
1024
|
+
/* A walk into the cells of an object array (#hash, #==, a nested dump) goes
|
|
1025
|
+
on into any array it finds there. An array holding itself is found by
|
|
1026
|
+
the records above, but a cell can also give a new array each time it is
|
|
1027
|
+
opened (a lazy expression over an array that holds it), and then the walk
|
|
1028
|
+
never meets an array it has seen. So the depth of these walks is
|
|
1029
|
+
limited. It is counted for each fiber, not in the arrays. */
|
|
1030
|
+
|
|
1031
|
+
#define CA_CELL_NESTING_MAX 256
|
|
1032
|
+
|
|
1033
|
+
typedef struct {
|
|
1034
|
+
VALUE thread;
|
|
1035
|
+
VALUE before;
|
|
1036
|
+
} ca_cell_nesting_t;
|
|
1037
|
+
|
|
1038
|
+
static VALUE
|
|
1039
|
+
ca_cell_nesting_leave (VALUE varg)
|
|
1040
|
+
{
|
|
1041
|
+
ca_cell_nesting_t *t = (ca_cell_nesting_t *) varg;
|
|
1042
|
+
rb_thread_local_aset(t->thread, rb_intern("carray_cell_nesting"), t->before);
|
|
1043
|
+
return Qnil;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
VALUE
|
|
1047
|
+
ca_cell_walk_run (VALUE (*body)(VALUE), VALUE arg)
|
|
1048
|
+
{
|
|
1049
|
+
ca_cell_nesting_t t;
|
|
1050
|
+
long depth;
|
|
1051
|
+
|
|
1052
|
+
t.thread = rb_thread_current();
|
|
1053
|
+
if ( OBJ_FROZEN(t.thread) ) { /* it can not hold the count */
|
|
1054
|
+
return body(arg);
|
|
1055
|
+
}
|
|
1056
|
+
t.before = rb_thread_local_aref(t.thread, rb_intern("carray_cell_nesting"));
|
|
1057
|
+
depth = NIL_P(t.before) ? 0 : FIX2LONG(t.before);
|
|
1058
|
+
if ( depth >= CA_CELL_NESTING_MAX ) {
|
|
1059
|
+
rb_raise(rb_eArgError, "%s: object cells nested too deep: more than %d levels",
|
|
1060
|
+
ca_calling_method_name(), CA_CELL_NESTING_MAX);
|
|
1061
|
+
}
|
|
1062
|
+
rb_thread_local_aset(t.thread, rb_intern("carray_cell_nesting"), LONG2FIX(depth + 1));
|
|
1063
|
+
return rb_ensure(body, arg, ca_cell_nesting_leave, (VALUE) &t);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
static VALUE
|
|
1067
|
+
ca_yield_nil (VALUE arg)
|
|
1068
|
+
{
|
|
1069
|
+
(void) arg;
|
|
1070
|
+
return rb_yield(Qnil);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
988
1073
|
static VALUE
|
|
989
1074
|
ca_refuse_reentry_step (VALUE self, VALUE name, int recursive)
|
|
990
1075
|
{
|
|
@@ -993,14 +1078,14 @@ ca_refuse_reentry_step (VALUE self, VALUE name, int recursive)
|
|
|
993
1078
|
rb_raise(rb_eArgError, "%" PRIsVALUE ": cyclic reference is not allowed in CArray",
|
|
994
1079
|
name);
|
|
995
1080
|
}
|
|
996
|
-
return
|
|
1081
|
+
return ca_cell_walk_run(ca_yield_nil, Qnil);
|
|
997
1082
|
}
|
|
998
1083
|
|
|
999
1084
|
/* refuse_reentry(name) { ... } -- runs the block, refusing as cyclic a
|
|
1000
1085
|
second call for the same array from inside it (rb_exec_recursive, by
|
|
1001
|
-
the receiver)
|
|
1002
|
-
|
|
1003
|
-
view, goes through this. */
|
|
1086
|
+
the receiver), and counting it as a walk into cells. Ruby code that
|
|
1087
|
+
walks the cells of an object array and comes back to the array through a
|
|
1088
|
+
cell, such as the nested dump of a view, goes through this. */
|
|
1004
1089
|
static VALUE
|
|
1005
1090
|
rb_ca_refuse_reentry (VALUE self, VALUE name)
|
|
1006
1091
|
{
|
|
@@ -1015,10 +1100,10 @@ ca_test_cyclic_check (void *ap, void *ptr)
|
|
|
1015
1100
|
{
|
|
1016
1101
|
CArray *ca = (CArray *) ap;
|
|
1017
1102
|
if ( ca_is_object_type(ca) ) {
|
|
1018
|
-
VALUE rval = *(VALUE *) ptr;
|
|
1103
|
+
volatile VALUE rval = *(VALUE *) ptr;
|
|
1019
1104
|
if ( rb_obj_is_carray(rval) ) {
|
|
1020
1105
|
CArray *cv;
|
|
1021
|
-
|
|
1106
|
+
GetCArray(rval, cv);
|
|
1022
1107
|
if ( cv == ca ||
|
|
1023
1108
|
RTEST(rb_exec_recursive(ca_recursion_probe,
|
|
1024
1109
|
ca_recursion_key(cv, CA_RECURSION_READ),
|
|
@@ -1045,7 +1130,8 @@ ca_refuse_storing_self (CArray *ca, const void *data, ca_size_t n)
|
|
|
1045
1130
|
memcpy(&rval, d + i * sizeof(VALUE), sizeof(VALUE));
|
|
1046
1131
|
if ( rb_obj_is_carray(rval) ) {
|
|
1047
1132
|
CArray *cv;
|
|
1048
|
-
|
|
1133
|
+
/* gc: data, the caller's cells, holds it */
|
|
1134
|
+
GetCArray(rval, cv);
|
|
1049
1135
|
if ( ca_shares_root(ca, cv) ) {
|
|
1050
1136
|
rb_raise(rb_eArgError, "%s: can not store an object array into itself",
|
|
1051
1137
|
ca_calling_method_name());
|
|
@@ -1073,9 +1159,9 @@ ca_reading_step (VALUE key, VALUE varg, int recursive)
|
|
|
1073
1159
|
static char ca_obj_moves_cells[CA_OBJ_TYPE_MAX];
|
|
1074
1160
|
|
|
1075
1161
|
void
|
|
1076
|
-
ca_register_cell_moving_view (
|
|
1162
|
+
ca_register_cell_moving_view (int16_t obj_type)
|
|
1077
1163
|
{
|
|
1078
|
-
ca_obj_moves_cells[
|
|
1164
|
+
ca_obj_moves_cells[obj_type] = 1;
|
|
1079
1165
|
}
|
|
1080
1166
|
|
|
1081
1167
|
/* Whether the transfers of a Face are the forwarders of ca_obj_face.c, which
|
|
@@ -1095,6 +1181,7 @@ ca_face_forwards_transfers (CArray *ca)
|
|
|
1095
1181
|
/* Whether a transfer of ca reaches entities through cell-moving views only:
|
|
1096
1182
|
then it calls no Ruby on the way. An unknown view, one that computes its
|
|
1097
1183
|
cells (CAObject, a lazy expression) or converts them, answers no. */
|
|
1184
|
+
/* recursion: stops at a depth of 64 */
|
|
1098
1185
|
static int
|
|
1099
1186
|
ca_transfer_calls_no_ruby (CArray *ca, int depth)
|
|
1100
1187
|
{
|
|
@@ -1105,7 +1192,7 @@ ca_transfer_calls_no_ruby (CArray *ca, int depth)
|
|
|
1105
1192
|
if ( ca_test_flag(ca, CA_FLAG_MULTI_PARENTS) ) {
|
|
1106
1193
|
CAMultiParent *mp = (CAMultiParent *) ca;
|
|
1107
1194
|
int32_t k;
|
|
1108
|
-
if ( ! ca_obj_moves_cells[
|
|
1195
|
+
if ( ! ca_obj_moves_cells[ca->obj_type] ) {
|
|
1109
1196
|
return 0;
|
|
1110
1197
|
}
|
|
1111
1198
|
for ( k = 0; k < mp->n_parents; k++ ) {
|
|
@@ -1118,7 +1205,7 @@ ca_transfer_calls_no_ruby (CArray *ca, int depth)
|
|
|
1118
1205
|
}
|
|
1119
1206
|
if ( ca_is_face(ca) ? ! ca_face_forwards_transfers(ca)
|
|
1120
1207
|
: ! ( ca_is_stride_family(ca) ||
|
|
1121
|
-
ca_obj_moves_cells[
|
|
1208
|
+
ca_obj_moves_cells[ca->obj_type] ) ) {
|
|
1122
1209
|
return 0;
|
|
1123
1210
|
}
|
|
1124
1211
|
ca = ((CAView *) ca)->parent;
|
|
@@ -1200,6 +1287,7 @@ typedef struct {
|
|
|
1200
1287
|
enum { CA_TRIAL_ADDRS, CA_TRIAL_STRIDE, CA_TRIAL_ALL, CA_TRIAL_FILL,
|
|
1201
1288
|
CA_TRIAL_FILL_STRIDE, CA_TRIAL_FILL_ADDRS, CA_TRIAL_SYNC };
|
|
1202
1289
|
|
|
1290
|
+
/* recursion: reached only from the dispatchers, which check the stack */
|
|
1203
1291
|
static VALUE
|
|
1204
1292
|
ca_value_trial_put_body (VALUE arg)
|
|
1205
1293
|
{
|
|
@@ -1232,6 +1320,7 @@ ca_value_trial_put_body (VALUE arg)
|
|
|
1232
1320
|
} \
|
|
1233
1321
|
} while (0)
|
|
1234
1322
|
|
|
1323
|
+
/* recursion: reached only from ca_xfer_index, which checks the stack */
|
|
1235
1324
|
static inline void
|
|
1236
1325
|
ca_xfer_index_dispatch (CArray *ca, ca_size_t *idx, void *data, int dir)
|
|
1237
1326
|
{
|
|
@@ -1266,6 +1355,11 @@ ca_xfer_index (void *ap, ca_size_t *idx, void *data, int dir)
|
|
|
1266
1355
|
{
|
|
1267
1356
|
CArray *ca = (CArray *) ap;
|
|
1268
1357
|
|
|
1358
|
+
/* An entity has no parent to recurse into; this runs once per cell. */
|
|
1359
|
+
if ( ! ca_is_entity(ca) ) {
|
|
1360
|
+
ca_check_stack_room();
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1269
1363
|
if ( dir == CA_XFER_PUT && ca_is_readonly(ca) ) {
|
|
1270
1364
|
ca_refuse_read_only();
|
|
1271
1365
|
}
|
|
@@ -1334,6 +1428,7 @@ ca_xfer_addrs_is_sequential_run (ca_size_t n, ca_size_t *addrs,
|
|
|
1334
1428
|
return 1;
|
|
1335
1429
|
}
|
|
1336
1430
|
|
|
1431
|
+
/* recursion: reached only from ca_xfer_addrs, which checks the stack */
|
|
1337
1432
|
static void
|
|
1338
1433
|
ca_xfer_addrs_dispatch (CArray *ca, ca_size_t n, ca_size_t *addrs,
|
|
1339
1434
|
void *data, int dir)
|
|
@@ -1418,6 +1513,11 @@ ca_xfer_addrs (void *ap, ca_size_t n, ca_size_t *addrs, void *data, int dir)
|
|
|
1418
1513
|
{
|
|
1419
1514
|
CArray *ca = (CArray *) ap;
|
|
1420
1515
|
|
|
1516
|
+
/* An entity has no parent to recurse into; this runs once per cell. */
|
|
1517
|
+
if ( ! ca_is_entity(ca) ) {
|
|
1518
|
+
ca_check_stack_room();
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1421
1521
|
if ( dir == CA_XFER_PUT && ca_is_readonly(ca) ) {
|
|
1422
1522
|
ca_refuse_read_only();
|
|
1423
1523
|
}
|
|
@@ -1784,6 +1884,7 @@ ca_xfer_stride_request_is_axis_box (void *ap, ca_size_t *starts,
|
|
|
1784
1884
|
return 1;
|
|
1785
1885
|
}
|
|
1786
1886
|
|
|
1887
|
+
/* recursion: reached only from ca_xfer_stride, which checks the stack */
|
|
1787
1888
|
static void
|
|
1788
1889
|
ca_xfer_stride_dispatch (CArray *ca, ca_size_t *starts, ca_size_t *counts,
|
|
1789
1890
|
ca_size_t *strides, void *data, int dir)
|
|
@@ -1877,6 +1978,8 @@ ca_xfer_stride (void *ap, ca_size_t *starts, ca_size_t *counts,
|
|
|
1877
1978
|
{
|
|
1878
1979
|
CArray *ca = (CArray *) ap;
|
|
1879
1980
|
|
|
1981
|
+
ca_check_stack_room();
|
|
1982
|
+
|
|
1880
1983
|
if ( dir == CA_XFER_PUT && ca_is_readonly(ca) ) {
|
|
1881
1984
|
ca_refuse_read_only();
|
|
1882
1985
|
}
|
|
@@ -1926,6 +2029,7 @@ typedef struct {
|
|
|
1926
2029
|
int dir;
|
|
1927
2030
|
} ca_xfer_all_args_t;
|
|
1928
2031
|
|
|
2032
|
+
/* recursion: reached only from ca_xfer_all, which checks the stack */
|
|
1929
2033
|
static VALUE
|
|
1930
2034
|
ca_xfer_all_body (VALUE arg)
|
|
1931
2035
|
{
|
|
@@ -1950,6 +2054,8 @@ ca_xfer_all (void *ap, void *data, int dir)
|
|
|
1950
2054
|
CArray *ca = (CArray *) ap;
|
|
1951
2055
|
ca_xfer_all_args_t args;
|
|
1952
2056
|
int guard = -1;
|
|
2057
|
+
|
|
2058
|
+
ca_check_stack_room();
|
|
1953
2059
|
if ( ! ca_func[ca->obj_type].xfer_all ) {
|
|
1954
2060
|
rb_raise(rb_eRuntimeError,
|
|
1955
2061
|
"[BUG] xfer_all not defined for object type <%i>",
|
|
@@ -2018,6 +2124,7 @@ ca_allocate_rest (CArray *ca, CArray *mask0)
|
|
|
2018
2124
|
|
|
2019
2125
|
/* The view half of ca_allocate, after the attach level is taken. Run
|
|
2020
2126
|
under rb_protect by ca_allocate. */
|
|
2127
|
+
/* recursion: reached only from ca_allocate, which checks the stack */
|
|
2021
2128
|
static VALUE
|
|
2022
2129
|
ca_allocate_view (VALUE arg)
|
|
2023
2130
|
{
|
|
@@ -2034,7 +2141,7 @@ ca_allocate_view (VALUE arg)
|
|
|
2034
2141
|
|
|
2035
2142
|
/* Steps a view's attach level by d. A development build also counts the
|
|
2036
2143
|
views whose level is above zero, and the spec compares that count
|
|
2037
|
-
before and after every test: a
|
|
2144
|
+
before and after every test: a view left attached shows as a view that
|
|
2038
2145
|
stays counted. */
|
|
2039
2146
|
#ifdef CARRAY_DEV_BUILD
|
|
2040
2147
|
static long ca_attached_views = 0;
|
|
@@ -2141,10 +2248,12 @@ ca_shortcuts_off_from_env (void)
|
|
|
2141
2248
|
static VALUE
|
|
2142
2249
|
rb_ca_s_fast_paths_enabled (int argc, VALUE *argv, VALUE klass)
|
|
2143
2250
|
{
|
|
2144
|
-
VALUE
|
|
2251
|
+
VALUE rname_arg;
|
|
2252
|
+
volatile VALUE rname;
|
|
2145
2253
|
int id;
|
|
2146
2254
|
|
|
2147
|
-
rb_scan_args(argc, argv, "01", &
|
|
2255
|
+
rb_scan_args(argc, argv, "01", &rname_arg);
|
|
2256
|
+
rname = rname_arg;
|
|
2148
2257
|
if ( NIL_P(rname) ) {
|
|
2149
2258
|
return ca_fast_paths_on ? Qtrue : Qfalse;
|
|
2150
2259
|
}
|
|
@@ -2178,6 +2287,8 @@ ca_allocate (void *ap)
|
|
|
2178
2287
|
return;
|
|
2179
2288
|
}
|
|
2180
2289
|
|
|
2290
|
+
ca_check_stack_room();
|
|
2291
|
+
|
|
2181
2292
|
if ( ca_is_view(ca) ) { /* view array */
|
|
2182
2293
|
|
|
2183
2294
|
if ( CAVIEW(ca)->attach >= CA_ATTACH_MAX ) {
|
|
@@ -2214,6 +2325,7 @@ ca_allocate (void *ap)
|
|
|
2214
2325
|
|
|
2215
2326
|
/* The first attach of a view: materialise through the type's slot, then
|
|
2216
2327
|
its mask. Run under rb_protect by ca_attach. */
|
|
2328
|
+
/* recursion: reached only from ca_attach, which checks the stack */
|
|
2217
2329
|
static VALUE
|
|
2218
2330
|
ca_attach_view_first (VALUE arg)
|
|
2219
2331
|
{
|
|
@@ -2258,6 +2370,8 @@ ca_attach (void *ap)
|
|
|
2258
2370
|
return;
|
|
2259
2371
|
}
|
|
2260
2372
|
|
|
2373
|
+
ca_check_stack_room();
|
|
2374
|
+
|
|
2261
2375
|
if ( ca_is_view(ca) ) { /* view array */
|
|
2262
2376
|
|
|
2263
2377
|
if ( CAVIEW(ca)->attach >= CA_ATTACH_MAX ) {
|
|
@@ -2388,21 +2502,21 @@ ca_sync_all (CArray **list, int32_t n)
|
|
|
2388
2502
|
}
|
|
2389
2503
|
}
|
|
2390
2504
|
|
|
2391
|
-
/*
|
|
2505
|
+
/* Attaches list[0..n-1], runs body, and detaches them however body leaves.
|
|
2392
2506
|
|
|
2393
2507
|
modes holds one letter per array:
|
|
2394
|
-
'r' attach; detach
|
|
2395
|
-
'w' attach; sync, then detach
|
|
2396
|
-
'a' allocate (write only); sync, then detach
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
even when body raised or broke out -- the cells body wrote
|
|
2400
|
-
parent, as they would for an entity, which has no separate
|
|
2401
|
-
'a' array is not synced after a raise: allocate did not
|
|
2402
|
-
cells body never wrote hold nothing faithful to push
|
|
2403
|
-
clears the mask
|
|
2404
|
-
has no separate mask to fall back on, so the mask of an 'a' array
|
|
2405
|
-
copied before
|
|
2508
|
+
'r' attach; detach at the end
|
|
2509
|
+
'w' attach; sync, then detach at the end
|
|
2510
|
+
'a' allocate (write only); sync, then detach at the end
|
|
2511
|
+
|
|
2512
|
+
Attaching takes all of the arrays or none. At the end the 'w' arrays
|
|
2513
|
+
are synced even when body raised or broke out -- the cells body wrote
|
|
2514
|
+
reach the parent, as they would for an entity, which has no separate
|
|
2515
|
+
buffer. An 'a' array is not synced after a raise: allocate did not
|
|
2516
|
+
gather, so its cells body never wrote hold nothing faithful to push
|
|
2517
|
+
back. Allocate clears the mask, and an entity (or the parent under a
|
|
2518
|
+
view) has no separate mask to fall back on, so the mask of an 'a' array
|
|
2519
|
+
is copied before the allocate and written back when body raises.
|
|
2406
2520
|
|
|
2407
2521
|
Every array is detached, in reverse order, whatever happens. body's
|
|
2408
2522
|
own exception wins over one raised by a sync; when body returned and a
|
|
@@ -2437,7 +2551,7 @@ ca_attach_window_save_masks (ca_window_ctx_t *w)
|
|
|
2437
2551
|
}
|
|
2438
2552
|
ca_update_mask(ca);
|
|
2439
2553
|
{
|
|
2440
|
-
VALUE buf = rb_str_new(NULL, (long) ca->elements);
|
|
2554
|
+
volatile VALUE buf = rb_str_new(NULL, (long) ca->elements);
|
|
2441
2555
|
ca_copy_data(ca->mask, RSTRING_PTR(buf));
|
|
2442
2556
|
rb_ary_store(w->masks, k, buf);
|
|
2443
2557
|
}
|
|
@@ -2453,7 +2567,10 @@ ca_attach_window_restore_masks (ca_window_ctx_t *w)
|
|
|
2453
2567
|
return;
|
|
2454
2568
|
}
|
|
2455
2569
|
for ( k = 0; k < w->n; k++ ) {
|
|
2456
|
-
|
|
2570
|
+
/* held otherwise only by w->masks, where compaction can move it, and
|
|
2571
|
+
the write may call into Ruby (a CAObject's mask hooks): held on the
|
|
2572
|
+
stack here, which also pins it */
|
|
2573
|
+
volatile VALUE buf = rb_ary_entry(w->masks, k);
|
|
2457
2574
|
CArray *ca = w->list[k];
|
|
2458
2575
|
if ( NIL_P(buf) ) {
|
|
2459
2576
|
continue;
|
|
@@ -2463,9 +2580,6 @@ ca_attach_window_restore_masks (ca_window_ctx_t *w)
|
|
|
2463
2580
|
ca_create_mask(ca);
|
|
2464
2581
|
}
|
|
2465
2582
|
ca_xfer_all(ca->mask, RSTRING_PTR(buf), CA_XFER_PUT);
|
|
2466
|
-
/* held only by w->masks, where compaction can move it; the write may
|
|
2467
|
-
call into Ruby (a CAObject's mask hooks) */
|
|
2468
|
-
RB_GC_GUARD(buf);
|
|
2469
2583
|
}
|
|
2470
2584
|
}
|
|
2471
2585
|
|
|
@@ -2573,21 +2687,21 @@ ca_attach_window (int32_t n, CArray **list, const char *modes,
|
|
|
2573
2687
|
return result;
|
|
2574
2688
|
}
|
|
2575
2689
|
|
|
2576
|
-
/* ----
|
|
2690
|
+
/* ---- Arrays attached in a Fiber that is abandoned -------------------------
|
|
2577
2691
|
|
|
2578
|
-
|
|
2692
|
+
Arrays attached for a block are detached by rb_ensure. Ruby does not
|
|
2579
2693
|
run the ensure of a Fiber that is suspended and then collected -- an
|
|
2580
|
-
Enumerator stopped with #next and dropped is one -- so such
|
|
2581
|
-
would stay
|
|
2694
|
+
Enumerator stopped with #next and dropped is one -- so such arrays
|
|
2695
|
+
would stay attached for good: a view keeps its attach, and a source that
|
|
2582
2696
|
publishes its ptr only while held (a CASource) keeps it published and
|
|
2583
2697
|
stops checking its backend.
|
|
2584
2698
|
|
|
2585
|
-
The guard
|
|
2586
|
-
on the heap, owned by the guard; a sentinel object that
|
|
2587
|
-
|
|
2588
|
-
the Fiber is collected the sentinel goes with it, and the
|
|
2589
|
-
which runs outside GC, where Ruby may be called -- runs
|
|
2590
|
-
|
|
2699
|
+
The guard detaches them from a finalizer instead. The state of the
|
|
2700
|
+
attach lives on the heap, owned by the guard; a sentinel object that
|
|
2701
|
+
only the attaching frame refers to carries a finalizer that holds the
|
|
2702
|
+
guard. When the Fiber is collected the sentinel goes with it, and the
|
|
2703
|
+
finalizer -- which runs outside GC, where Ruby may be called -- runs
|
|
2704
|
+
`cleanup`. Code that detaches normally disarms the guard first.
|
|
2591
2705
|
|
|
2592
2706
|
`mark` marks the VALUEs `arg` holds, which nothing else does once the
|
|
2593
2707
|
frame that referred to them is gone. The guard frees `arg` with xfree. */
|
|
@@ -2617,7 +2731,7 @@ ca_window_guard_free (void *p)
|
|
|
2617
2731
|
}
|
|
2618
2732
|
|
|
2619
2733
|
static const rb_data_type_t ca_window_guard_data_type = {
|
|
2620
|
-
.wrap_struct_name = "
|
|
2734
|
+
.wrap_struct_name = "CArray::WindowGuard",
|
|
2621
2735
|
.function = {
|
|
2622
2736
|
.dmark = ca_window_guard_mark,
|
|
2623
2737
|
.dfree = ca_window_guard_free,
|
|
@@ -2627,7 +2741,7 @@ static const rb_data_type_t ca_window_guard_data_type = {
|
|
|
2627
2741
|
};
|
|
2628
2742
|
|
|
2629
2743
|
static VALUE
|
|
2630
|
-
ca_window_guard_cleanup_step (VALUE gv)
|
|
2744
|
+
ca_window_guard_cleanup_step (volatile VALUE gv)
|
|
2631
2745
|
{
|
|
2632
2746
|
ca_window_guard_t *g;
|
|
2633
2747
|
TypedData_Get_Struct(gv, ca_window_guard_t, &ca_window_guard_data_type, g);
|
|
@@ -2641,7 +2755,7 @@ ca_window_guard_cleanup_step (VALUE gv)
|
|
|
2641
2755
|
static VALUE rb_cCAWindowGuard;
|
|
2642
2756
|
|
|
2643
2757
|
static VALUE
|
|
2644
|
-
ca_window_guard_call (VALUE gv, VALUE object_id)
|
|
2758
|
+
ca_window_guard_call (volatile VALUE gv, VALUE object_id)
|
|
2645
2759
|
{
|
|
2646
2760
|
ca_window_guard_t *g;
|
|
2647
2761
|
int tag = 0;
|
|
@@ -2657,42 +2771,65 @@ ca_window_guard_call (VALUE gv, VALUE object_id)
|
|
|
2657
2771
|
return Qnil;
|
|
2658
2772
|
}
|
|
2659
2773
|
|
|
2774
|
+
/* Ruby 3.4 corrupts its finalizer table when Ractors define and undefine
|
|
2775
|
+
finalizers at the same time (a Ruby loop of define_finalizer and
|
|
2776
|
+
undefine_finalizer in eight Ractors crashes it), so there only the main
|
|
2777
|
+
Ractor sets the finalizer. Arrays attached in another Ractor whose
|
|
2778
|
+
Fiber is abandoned stay attached there. */
|
|
2779
|
+
static int
|
|
2780
|
+
ca_window_guard_finalizes (void)
|
|
2781
|
+
{
|
|
2782
|
+
#if RUBY_API_VERSION_MAJOR < 4
|
|
2783
|
+
return ca_in_main_ractor();
|
|
2784
|
+
#else
|
|
2785
|
+
return 1;
|
|
2786
|
+
#endif
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2660
2789
|
/* Takes ownership of arg (allocated with xmalloc). Returns the guard and
|
|
2661
|
-
stores the sentinel
|
|
2662
|
-
|
|
2790
|
+
stores the sentinel (nil when no finalizer is set); the caller keeps
|
|
2791
|
+
both on its frame, in volatile variables or in a struct there, for as
|
|
2792
|
+
long as the arrays may be attached. */
|
|
2663
2793
|
VALUE
|
|
2664
2794
|
ca_window_guard_arm (void (*cleanup)(void *), void (*mark)(void *), void *arg,
|
|
2665
|
-
VALUE *sentinel)
|
|
2795
|
+
volatile VALUE *sentinel)
|
|
2666
2796
|
{
|
|
2667
2797
|
ca_window_guard_t *g;
|
|
2668
2798
|
volatile VALUE gv, sv;
|
|
2799
|
+
|
|
2669
2800
|
gv = TypedData_Make_Struct(rb_cCAWindowGuard, ca_window_guard_t,
|
|
2670
2801
|
&ca_window_guard_data_type, g);
|
|
2671
2802
|
g->cleanup = cleanup;
|
|
2672
2803
|
g->mark = mark;
|
|
2673
2804
|
g->arg = arg;
|
|
2674
2805
|
g->armed = 1;
|
|
2675
|
-
sv =
|
|
2676
|
-
|
|
2806
|
+
sv = Qnil;
|
|
2807
|
+
if ( ca_window_guard_finalizes() ) {
|
|
2808
|
+
sv = rb_class_new_instance(0, NULL, rb_cObject);
|
|
2809
|
+
rb_define_finalizer(sv, gv);
|
|
2810
|
+
}
|
|
2677
2811
|
*sentinel = sv;
|
|
2678
2812
|
return gv;
|
|
2679
2813
|
}
|
|
2680
2814
|
|
|
2681
|
-
/* Called first thing when the
|
|
2682
|
-
cannot also run from the finalizer. */
|
|
2815
|
+
/* Called first thing when the arrays are detached normally, so that
|
|
2816
|
+
cleanup cannot also run from the finalizer. */
|
|
2683
2817
|
void
|
|
2684
|
-
ca_window_guard_disarm (VALUE gv, VALUE sentinel)
|
|
2818
|
+
ca_window_guard_disarm (volatile VALUE gv, VALUE sentinel)
|
|
2685
2819
|
{
|
|
2686
2820
|
ca_window_guard_t *g;
|
|
2687
2821
|
TypedData_Get_Struct(gv, ca_window_guard_t, &ca_window_guard_data_type, g);
|
|
2688
2822
|
g->armed = 0;
|
|
2823
|
+
if ( NIL_P(sentinel) ) {
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2689
2826
|
/* rb_undefine_finalizer is declared in the headers but not exported by
|
|
2690
2827
|
every libruby (3.4.1 lacks it), so go through ObjectSpace. */
|
|
2691
2828
|
rb_funcall(rb_const_get(rb_cObject, rb_intern("ObjectSpace")),
|
|
2692
2829
|
rb_intern("undefine_finalizer"), 1, sentinel);
|
|
2693
2830
|
}
|
|
2694
2831
|
|
|
2695
|
-
/* ca_attach_window for a
|
|
2832
|
+
/* ca_attach_window for a body that yields to a block, detached by the
|
|
2696
2833
|
guard above if its Fiber is abandoned. The context, the list and the
|
|
2697
2834
|
modes are copied to the heap, since the caller's frame goes with the
|
|
2698
2835
|
Fiber; `owners` keeps the arrays in list alive until then. */
|
|
@@ -2761,7 +2898,7 @@ ca_attach_window_yielding (VALUE owners, int32_t n, CArray **list,
|
|
|
2761
2898
|
gw->w.body = body;
|
|
2762
2899
|
gw->w.arg = arg;
|
|
2763
2900
|
gw->w.masks = Qnil;
|
|
2764
|
-
guard = ca_window_guard_arm(NULL, ca_guarded_window_mark, gw,
|
|
2901
|
+
guard = ca_window_guard_arm(NULL, ca_guarded_window_mark, gw, &sentinel);
|
|
2765
2902
|
ca_attach_window_save_masks(&gw->w);
|
|
2766
2903
|
|
|
2767
2904
|
rb_protect(ca_attach_window_open, (VALUE) &gw->w, &tag);
|
|
@@ -2792,17 +2929,14 @@ ca_attach_window_yielding (VALUE owners, int32_t n, CArray **list,
|
|
|
2792
2929
|
if ( gw->w.sync_tag && RB_TYPE_P(gw->w.sync_err, T_OBJECT) &&
|
|
2793
2930
|
RTEST(rb_obj_is_kind_of(gw->w.sync_err, rb_eException)) ) {
|
|
2794
2931
|
VALUE err = gw->w.sync_err;
|
|
2795
|
-
RB_GC_GUARD(guard);
|
|
2796
|
-
RB_GC_GUARD(sentinel);
|
|
2797
2932
|
rb_exc_raise(err);
|
|
2798
2933
|
}
|
|
2799
|
-
RB_GC_GUARD(guard);
|
|
2800
|
-
RB_GC_GUARD(sentinel);
|
|
2801
2934
|
return result;
|
|
2802
2935
|
}
|
|
2803
2936
|
|
|
2804
2937
|
/* re-gather an attached view's buffer from its parent */
|
|
2805
2938
|
|
|
2939
|
+
/* recursion: re-enters once, for the mask */
|
|
2806
2940
|
void
|
|
2807
2941
|
ca_update (void *ap)
|
|
2808
2942
|
{
|
|
@@ -2839,6 +2973,8 @@ ca_sync (void *ap)
|
|
|
2839
2973
|
return;
|
|
2840
2974
|
}
|
|
2841
2975
|
|
|
2976
|
+
ca_check_stack_room();
|
|
2977
|
+
|
|
2842
2978
|
if ( ! ca->ptr ) {
|
|
2843
2979
|
rb_raise(rb_eRuntimeError,
|
|
2844
2980
|
"[BUG] tried to sync data to detached array");
|
|
@@ -2854,10 +2990,10 @@ ca_sync (void *ap)
|
|
|
2854
2990
|
}
|
|
2855
2991
|
|
|
2856
2992
|
|
|
2857
|
-
/* Only a mask that exists can hold writes: one made
|
|
2858
|
-
is attached with the view (ca_create_mask). Making one here
|
|
2859
|
-
read the parent's mask
|
|
2860
|
-
cannot answer would leave the
|
|
2993
|
+
/* Only a mask that exists can hold writes: one made while the view is
|
|
2994
|
+
attached is attached with the view (ca_create_mask). Making one here
|
|
2995
|
+
would read the parent's mask during the detach, and a parent that
|
|
2996
|
+
cannot answer would leave the view attached. */
|
|
2861
2997
|
if ( ca->mask ) {
|
|
2862
2998
|
ca_sync(ca->mask);
|
|
2863
2999
|
}
|
|
@@ -2873,11 +3009,11 @@ ca_sync (void *ap)
|
|
|
2873
3009
|
|
|
2874
3010
|
}
|
|
2875
3011
|
|
|
2876
|
-
/* Sync ap and detach it -- the
|
|
3012
|
+
/* Sync ap and detach it -- the end of an attach a frame began with
|
|
2877
3013
|
ca_attach or ca_allocate. The detach happens even when the sync raises
|
|
2878
3014
|
(a read-only array, a backing whose write fails); the sync's exception
|
|
2879
3015
|
then propagates. Written as two calls, a raising sync skips the detach
|
|
2880
|
-
and the
|
|
3016
|
+
and the array stays attached.
|
|
2881
3017
|
|
|
2882
3018
|
Not a replacement for every ca_sync: a view's sync slot syncs its parent
|
|
2883
3019
|
without detaching it, because that attach belongs to the view and its
|
|
@@ -2911,6 +3047,7 @@ ca_sync_detach (void *ap)
|
|
|
2911
3047
|
|
|
2912
3048
|
/* make ca->ptr to be detached */
|
|
2913
3049
|
|
|
3050
|
+
/* recursion: closes what ca_attach opened along the same chain, which checked the stack; it must not raise */
|
|
2914
3051
|
void
|
|
2915
3052
|
ca_detach (void *ap)
|
|
2916
3053
|
{
|
|
@@ -3080,6 +3217,7 @@ ca_fill_data (void *ap, void *aptr)
|
|
|
3080
3217
|
{
|
|
3081
3218
|
CArray *ca = (CArray *) ap;
|
|
3082
3219
|
char *ptr = (char *) aptr;
|
|
3220
|
+
ca_check_stack_room();
|
|
3083
3221
|
|
|
3084
3222
|
if ( ca_is_readonly(ca) ) {
|
|
3085
3223
|
ca_refuse_read_only();
|
|
@@ -3139,6 +3277,7 @@ ca_fill_stride (void *ap, ca_size_t base, int8_t ndim,
|
|
|
3139
3277
|
ca_size_t *counts, ca_size_t *steps, void *ptr)
|
|
3140
3278
|
{
|
|
3141
3279
|
CArray *ca = (CArray *) ap;
|
|
3280
|
+
ca_check_stack_room();
|
|
3142
3281
|
|
|
3143
3282
|
if ( ca_is_readonly(ca) ) {
|
|
3144
3283
|
ca_refuse_read_only();
|
|
@@ -3265,6 +3404,7 @@ void
|
|
|
3265
3404
|
ca_fill_addrs (void *ap, ca_size_t n, ca_size_t *addrs, void *ptr)
|
|
3266
3405
|
{
|
|
3267
3406
|
CArray *ca = (CArray *) ap;
|
|
3407
|
+
ca_check_stack_room();
|
|
3268
3408
|
|
|
3269
3409
|
if ( ca_is_readonly(ca) ) {
|
|
3270
3410
|
ca_refuse_read_only();
|
|
@@ -3291,6 +3431,7 @@ void *
|
|
|
3291
3431
|
ca_clone (void *ap)
|
|
3292
3432
|
{
|
|
3293
3433
|
CArray *ca = (CArray *) ap;
|
|
3434
|
+
ca_check_stack_room();
|
|
3294
3435
|
return ca_func[ca->obj_type].clone(ap);
|
|
3295
3436
|
}
|
|
3296
3437
|
|
|
@@ -3314,23 +3455,24 @@ ca_fill (void *ap, void *aptr)
|
|
|
3314
3455
|
#ifdef CARRAY_DEV_BUILD
|
|
3315
3456
|
|
|
3316
3457
|
/* The Ruby attach surface is built into development builds only. Ruby has no
|
|
3317
|
-
raw pointer, so the only thing a block can do
|
|
3318
|
-
back into the array API
|
|
3319
|
-
|
|
3320
|
-
to the root (R5,
|
|
3321
|
-
whole-array writes reach the buffer and survive the sync; a
|
|
3322
|
-
derived view is discarded. The in-tree tests drive the
|
|
3323
|
-
the surface stays reachable here and out of
|
|
3458
|
+
raw pointer, so the only thing a block can do while an array is attached
|
|
3459
|
+
is call back into the array API, and the syntax does not show which
|
|
3460
|
+
of the two a call takes: v[0] reads the attached buffer while v[] and v[0..1]
|
|
3461
|
+
compose past it to the root (R5, guides/devel/04_attach_lifecycle.md).
|
|
3462
|
+
Per-cell and whole-array writes reach the buffer and survive the sync; a
|
|
3463
|
+
write through a derived view is discarded. The in-tree tests drive the
|
|
3464
|
+
healthy spellings, so the surface stays reachable here and out of
|
|
3465
|
+
released builds. */
|
|
3324
3466
|
|
|
3325
3467
|
/* subroutines for CArray.attach, CArray.attach!
|
|
3326
3468
|
CArray#attach, CArray#attach! */
|
|
3327
3469
|
|
|
3328
3470
|
static void
|
|
3329
|
-
rb_ca_attach_i (VALUE self)
|
|
3471
|
+
rb_ca_attach_i (volatile VALUE self)
|
|
3330
3472
|
{
|
|
3331
3473
|
CArray *ca;
|
|
3332
3474
|
if ( rb_obj_is_carray(self) ) {
|
|
3333
|
-
|
|
3475
|
+
GetCArray(self, ca);
|
|
3334
3476
|
ca_attach(ca);
|
|
3335
3477
|
if ( ca_is_view(ca) ) {
|
|
3336
3478
|
CAVIEW(ca)->nosync += 1;
|
|
@@ -3342,11 +3484,11 @@ rb_ca_attach_i (VALUE self)
|
|
|
3342
3484
|
}
|
|
3343
3485
|
|
|
3344
3486
|
static void
|
|
3345
|
-
rb_ca_sync_i (VALUE self)
|
|
3487
|
+
rb_ca_sync_i (volatile VALUE self)
|
|
3346
3488
|
{
|
|
3347
3489
|
CArray *ca;
|
|
3348
3490
|
if ( rb_obj_is_carray(self) ) {
|
|
3349
|
-
|
|
3491
|
+
GetCArray(self, ca);
|
|
3350
3492
|
if ( ca_is_view(ca) ) {
|
|
3351
3493
|
CAVIEW(ca)->nosync -= 1;
|
|
3352
3494
|
ca_sync(ca);
|
|
@@ -3359,11 +3501,11 @@ rb_ca_sync_i (VALUE self)
|
|
|
3359
3501
|
}
|
|
3360
3502
|
|
|
3361
3503
|
static void
|
|
3362
|
-
rb_ca_detach_i (VALUE self)
|
|
3504
|
+
rb_ca_detach_i (volatile VALUE self)
|
|
3363
3505
|
{
|
|
3364
3506
|
CArray *ca;
|
|
3365
3507
|
if ( rb_obj_is_carray(self) ) {
|
|
3366
|
-
|
|
3508
|
+
GetCArray(self, ca);
|
|
3367
3509
|
if ( ca_is_view(ca) ) { /* view array */
|
|
3368
3510
|
CAVIEW(ca)->nosync -= 1;
|
|
3369
3511
|
ca_detach(ca);
|
|
@@ -3405,7 +3547,7 @@ rb_ca_s_attach (int argc, VALUE *argv, VALUE self)
|
|
|
3405
3547
|
volatile VALUE list, obj;
|
|
3406
3548
|
int i;
|
|
3407
3549
|
|
|
3408
|
-
list =
|
|
3550
|
+
list = rb_ary_new_from_values(argc, argv);
|
|
3409
3551
|
|
|
3410
3552
|
for (i=0; i<RARRAY_LEN(list); i++) {
|
|
3411
3553
|
obj = rb_ary_entry(list, i);
|
|
@@ -3445,7 +3587,7 @@ rb_ca_s_attach_bang (int argc, VALUE *argv, VALUE self)
|
|
|
3445
3587
|
volatile VALUE list, obj;
|
|
3446
3588
|
int i;
|
|
3447
3589
|
|
|
3448
|
-
list =
|
|
3590
|
+
list = rb_ary_new_from_values(argc, argv);
|
|
3449
3591
|
|
|
3450
3592
|
for (i=0; i<RARRAY_LEN(list); i++) {
|
|
3451
3593
|
obj = rb_ary_entry(list, i);
|
|
@@ -3584,7 +3726,8 @@ rb_ca_members (VALUE self)
|
|
|
3584
3726
|
{
|
|
3585
3727
|
volatile VALUE data_class = rb_ca_data_class(self);
|
|
3586
3728
|
if ( NIL_P(data_class) ) {
|
|
3587
|
-
rb_raise(rb_eTypeError, "carray doesn't have data class"
|
|
3729
|
+
rb_raise(rb_eTypeError, "%s: carray doesn't have data class",
|
|
3730
|
+
ca_calling_method_name());
|
|
3588
3731
|
}
|
|
3589
3732
|
else {
|
|
3590
3733
|
return rb_obj_clone(rb_const_get(data_class, rb_intern("MEMBERS")));
|
|
@@ -3598,7 +3741,7 @@ rb_ca_members (VALUE self)
|
|
|
3598
3741
|
actual field view is the CAField on the parent. A plain FIXLEN entity
|
|
3599
3742
|
keeps self == receiver. */
|
|
3600
3743
|
static VALUE
|
|
3601
|
-
ca_face_field_lookup (VALUE self, VALUE sym)
|
|
3744
|
+
ca_face_field_lookup (volatile VALUE self, volatile VALUE sym)
|
|
3602
3745
|
{
|
|
3603
3746
|
volatile VALUE data_class = rb_ca_data_class(self);
|
|
3604
3747
|
volatile VALUE member;
|
|
@@ -3607,10 +3750,11 @@ ca_face_field_lookup (VALUE self, VALUE sym)
|
|
|
3607
3750
|
CArray *ca;
|
|
3608
3751
|
|
|
3609
3752
|
if ( NIL_P(data_class) ) {
|
|
3610
|
-
rb_raise(rb_eTypeError, "carray doesn't have data class"
|
|
3753
|
+
rb_raise(rb_eTypeError, "%s: carray doesn't have data class",
|
|
3754
|
+
ca_calling_method_name());
|
|
3611
3755
|
}
|
|
3612
3756
|
|
|
3613
|
-
|
|
3757
|
+
GetCArray(self, ca);
|
|
3614
3758
|
receiver = ca_is_face(ca) ? rb_ca_parent(self) : self;
|
|
3615
3759
|
|
|
3616
3760
|
member = rb_ivar_get(self, rb_intern("member"));
|
|
@@ -3636,7 +3780,7 @@ ca_face_field_lookup (VALUE self, VALUE sym)
|
|
|
3636
3780
|
else {
|
|
3637
3781
|
obj = rb_hash_aref(member, sym);
|
|
3638
3782
|
if ( NIL_P(obj) ) {
|
|
3639
|
-
sym =
|
|
3783
|
+
sym = rb_obj_as_string(sym);
|
|
3640
3784
|
obj = rb_hash_aref(member, sym);
|
|
3641
3785
|
}
|
|
3642
3786
|
}
|
|
@@ -3649,10 +3793,11 @@ ca_face_field_lookup (VALUE self, VALUE sym)
|
|
|
3649
3793
|
volatile VALUE info = rb_hash_aref(MEMBER_TABLE, sym);
|
|
3650
3794
|
if ( NIL_P(info) ) {
|
|
3651
3795
|
if ( TYPE(sym) != T_STRING ) {
|
|
3652
|
-
sym =
|
|
3796
|
+
sym = rb_obj_as_string(sym);
|
|
3653
3797
|
}
|
|
3654
3798
|
rb_raise(rb_eArgError,
|
|
3655
|
-
"can't find data_member named <%s>",
|
|
3799
|
+
"%s: can't find data_member named <%s>",
|
|
3800
|
+
ca_calling_method_name(), StringValuePtr(sym));
|
|
3656
3801
|
}
|
|
3657
3802
|
Check_Type(info, T_ARRAY);
|
|
3658
3803
|
/* Bit-typed members route through a CAField power-of-2 byte
|
|
@@ -3684,14 +3829,21 @@ ca_face_field_lookup (VALUE self, VALUE sym)
|
|
|
3684
3829
|
else { view_bytes = 8; vtype_name = "uint64"; }
|
|
3685
3830
|
(void) view_bytes;
|
|
3686
3831
|
vtype_sym = ID2SYM(rb_intern(vtype_name));
|
|
3687
|
-
|
|
3688
|
-
|
|
3832
|
+
{
|
|
3833
|
+
VALUE args[2];
|
|
3834
|
+
args[0] = SIZE2NUM(start_byte);
|
|
3835
|
+
args[1] = vtype_sym;
|
|
3836
|
+
word_view = rb_ca_field(2, args, receiver);
|
|
3837
|
+
}
|
|
3689
3838
|
/* little-endian on every host, as the layout numbers the bits */
|
|
3690
|
-
word_view =
|
|
3691
|
-
ID2SYM(rb_intern("little")));
|
|
3839
|
+
word_view = rb_ca_endian(word_view, ID2SYM(rb_intern("little")));
|
|
3692
3840
|
range = rb_range_new(LONG2NUM(bit_in_word),
|
|
3693
3841
|
SIZE2NUM(bit_in_word + bits - 1), 0);
|
|
3694
|
-
|
|
3842
|
+
{
|
|
3843
|
+
VALUE args[1];
|
|
3844
|
+
args[0] = range;
|
|
3845
|
+
obj = rb_ca_bitfield(1, args, word_view);
|
|
3846
|
+
}
|
|
3695
3847
|
rb_hash_aset(member, sym, obj);
|
|
3696
3848
|
return obj;
|
|
3697
3849
|
}
|
|
@@ -3706,22 +3858,19 @@ ca_face_field_lookup (VALUE self, VALUE sym)
|
|
|
3706
3858
|
}
|
|
3707
3859
|
if ( ! NIL_P(endian) ) {
|
|
3708
3860
|
volatile VALUE field_opts = rb_hash_dup(opts);
|
|
3861
|
+
VALUE args[3];
|
|
3709
3862
|
rb_hash_delete(field_opts, ID2SYM(rb_intern("endian")));
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
else {
|
|
3716
|
-
obj = rb_funcall(receiver, rb_intern("field"), 2,
|
|
3717
|
-
rb_ary_entry(info, 0), rb_ary_entry(info, 1));
|
|
3718
|
-
}
|
|
3719
|
-
obj = rb_funcall(obj, rb_intern("endian"), 1, endian);
|
|
3863
|
+
args[0] = rb_ary_entry(info, 0);
|
|
3864
|
+
args[1] = rb_ary_entry(info, 1);
|
|
3865
|
+
args[2] = field_opts;
|
|
3866
|
+
obj = rb_ca_field(RHASH_SIZE(field_opts) > 0 ? 3 : 2, args, receiver);
|
|
3867
|
+
obj = rb_ca_endian(obj, endian);
|
|
3720
3868
|
rb_hash_aset(member, sym, obj);
|
|
3721
3869
|
return obj;
|
|
3722
3870
|
}
|
|
3723
3871
|
}
|
|
3724
|
-
obj =
|
|
3872
|
+
obj = rb_ca_field(RARRAY_LENINT(info), (VALUE *) RARRAY_CONST_PTR(info),
|
|
3873
|
+
receiver);
|
|
3725
3874
|
rb_hash_aset(member, sym, obj);
|
|
3726
3875
|
return obj;
|
|
3727
3876
|
}
|
|
@@ -3731,13 +3880,13 @@ ca_face_field_lookup (VALUE self, VALUE sym)
|
|
|
3731
3880
|
read-only state of the record array (frozen, or a read-only view) is not
|
|
3732
3881
|
on its parent chain; the field carries it itself. */
|
|
3733
3882
|
VALUE
|
|
3734
|
-
rb_ca_face_field (VALUE self, VALUE sym)
|
|
3883
|
+
rb_ca_face_field (volatile VALUE self, VALUE sym)
|
|
3735
3884
|
{
|
|
3736
3885
|
volatile VALUE obj = ca_face_field_lookup(self, sym);
|
|
3737
3886
|
CArray *ca, *co;
|
|
3738
|
-
|
|
3887
|
+
GetCArray(self, ca);
|
|
3739
3888
|
if ( ca_is_readonly(ca) && rb_obj_is_carray(obj) ) {
|
|
3740
|
-
|
|
3889
|
+
GetCArray(obj, co);
|
|
3741
3890
|
ca_set_flag(co, CA_FLAG_READ_ONLY);
|
|
3742
3891
|
}
|
|
3743
3892
|
return obj;
|
|
@@ -3755,10 +3904,11 @@ rb_ca_fields (VALUE self)
|
|
|
3755
3904
|
volatile VALUE member_names, list;
|
|
3756
3905
|
int i;
|
|
3757
3906
|
if ( NIL_P(data_class) ) {
|
|
3758
|
-
rb_raise(rb_eTypeError, "carray doesn't have data class"
|
|
3907
|
+
rb_raise(rb_eTypeError, "%s: carray doesn't have data class",
|
|
3908
|
+
ca_calling_method_name());
|
|
3759
3909
|
}
|
|
3760
3910
|
member_names = rb_const_get(data_class, rb_intern("MEMBERS"));
|
|
3761
|
-
list =
|
|
3911
|
+
list = rb_ary_new_capa(RARRAY_LEN(member_names));
|
|
3762
3912
|
for (i=0; i<RARRAY_LEN(member_names); i++) {
|
|
3763
3913
|
VALUE name = rb_ary_entry(member_names, i);
|
|
3764
3914
|
rb_ary_store(list, i, rb_ca_face_field(self, name));
|
|
@@ -3777,11 +3927,13 @@ rb_ca_fields_at (int argc, VALUE *argv, VALUE self)
|
|
|
3777
3927
|
volatile VALUE data_class = rb_ca_data_class(self);
|
|
3778
3928
|
volatile VALUE member_names, list;
|
|
3779
3929
|
int i;
|
|
3930
|
+
rb_reject_options(rb_pop_options(&argc, &argv));
|
|
3780
3931
|
if ( NIL_P(data_class) ) {
|
|
3781
|
-
rb_raise(rb_eTypeError, "carray doesn't have data class"
|
|
3932
|
+
rb_raise(rb_eTypeError, "%s: carray doesn't have data class",
|
|
3933
|
+
ca_calling_method_name());
|
|
3782
3934
|
}
|
|
3783
|
-
member_names =
|
|
3784
|
-
list =
|
|
3935
|
+
member_names = rb_ary_new_from_values(argc, argv);
|
|
3936
|
+
list = rb_ary_new_capa(RARRAY_LEN(member_names));
|
|
3785
3937
|
for (i=0; i<RARRAY_LEN(member_names); i++) {
|
|
3786
3938
|
VALUE name = rb_ary_entry(member_names, i);
|
|
3787
3939
|
rb_ary_store(list, i, rb_ca_face_field(self, name));
|
|
@@ -3804,6 +3956,8 @@ Init_carray_core (void)
|
|
|
3804
3956
|
rb_undef_alloc_func(rb_cCAWindowGuard);
|
|
3805
3957
|
rb_undef_method(CLASS_OF(rb_cCAWindowGuard), "new");
|
|
3806
3958
|
rb_define_method(rb_cCAWindowGuard, "call", ca_window_guard_call, 1);
|
|
3959
|
+
rb_funcall(rb_cCArray, rb_intern("private_constant"), 1,
|
|
3960
|
+
ID2SYM(rb_intern("WindowGuard")));
|
|
3807
3961
|
|
|
3808
3962
|
#ifdef CARRAY_DEV_BUILD
|
|
3809
3963
|
rb_define_singleton_method(rb_cCArray, "attach", rb_ca_s_attach, -1);
|