carray 3.0.7 → 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 -1940
- data/README.md +38 -32
- 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 +6 -9
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +27 -0
- data/ext/ca_binop_dispatch.h +22 -47
- 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 -1506
- 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 +90 -163
- data/ext/ca_obj_bincmp.c +47 -46
- data/ext/ca_obj_binop.c +38 -38
- data/ext/ca_obj_bitarray.c +5 -17
- data/ext/ca_obj_bitfield.c +15 -30
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +32 -30
- data/ext/ca_obj_const_string.c +57 -62
- data/ext/ca_obj_face.c +99 -91
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +15 -21
- data/ext/ca_obj_farray.c +7 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +8 -19
- data/ext/ca_obj_grid.c +137 -106
- data/ext/ca_obj_meld.c +23 -21
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +24 -35
- data/ext/ca_obj_object.c +51 -37
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +8 -10
- data/ext/ca_obj_refer.c +42 -29
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +18 -24
- data/ext/ca_obj_select.c +10 -22
- data/ext/ca_obj_select_axis.c +27 -36
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +28 -24
- data/ext/ca_obj_stride.c +53 -54
- data/ext/ca_obj_string.c +6 -18
- data/ext/ca_obj_tile.c +12 -12
- 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 +35 -39
- data/ext/ca_obj_window.c +67 -86
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +34 -12
- data/ext/ca_op_powi.h +4 -0
- 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 +20 -26
- data/ext/ca_sweep_engine.c +2 -3
- data/ext/ca_sweep_engine.h +17 -9
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +11 -11
- data/ext/carray.h +300 -1011
- data/ext/carray_access.c +234 -180
- data/ext/carray_address_basis.c +33 -38
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +30 -26
- data/ext/carray_call_cfunc.c +169 -277
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +912 -346
- data/ext/carray_cast_func.rb +31 -3
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +43 -38
- data/ext/carray_copy.c +28 -26
- data/ext/carray_core.c +217 -126
- data/ext/carray_count.c +27 -15
- data/ext/carray_element.c +40 -25
- data/ext/carray_factorize.c +53 -52
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +8 -10
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +123 -228
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1274 -160
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +21 -36
- data/ext/carray_loop.c +19 -22
- data/ext/carray_mask.c +123 -145
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +95 -94
- data/ext/carray_memory_view.c +42 -47
- data/ext/carray_operator.c +423 -122
- data/ext/carray_order.c +121 -85
- data/ext/carray_partition.c +13 -15
- data/ext/carray_random.c +47 -41
- data/ext/carray_round.c +9 -4
- data/ext/carray_scatter.c +54 -40
- data/ext/carray_segment.c +41 -45
- data/ext/carray_slab.c +64 -47
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +32 -29
- data/ext/carray_sort_kernel.c +12 -10
- data/ext/carray_struct.c +38 -43
- data/ext/carray_test.c +47 -43
- data/ext/carray_time_text.c +24 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +258 -94
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +19 -20
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +782 -461
- 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 +264 -180
- data/lib/carray/basics.rb +272 -48
- data/lib/carray/bincount_nd.rb +33 -16
- data/lib/carray/block_iterator.rb +123 -102
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +63 -51
- data/lib/carray/categorical_iterator.rb +89 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +49 -22
- data/lib/carray/const_string.rb +54 -62
- data/lib/carray/core_extensions.rb +1 -1
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +25 -24
- data/lib/carray/frame/column_verbs.rb +20 -8
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +7 -1
- data/lib/carray/frame/frame.rb +35 -25
- data/lib/carray/frame/group.rb +183 -150
- data/lib/carray/frame/io.rb +26 -7
- data/lib/carray/frame/join.rb +37 -12
- data/lib/carray/frame/records.rb +1 -1
- data/lib/carray/frame/reshape.rb +3 -3
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +148 -118
- data/lib/carray/frame/windows.rb +232 -21
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +24 -21
- 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 +97 -24
- data/lib/carray/key_windows.rb +83 -57
- data/lib/carray/lazy.rb +196 -94
- 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 +5 -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 +72 -71
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/gather_nd.rb +106 -106
- 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 +165 -145
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +150 -138
- 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 +12 -12
- 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 +18 -17
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +190 -22
- data/lib/carray/segment_iterator.rb +251 -129
- data/lib/carray/serialize.rb +618 -571
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +11 -12
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +76 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +243 -72
- data/lib/carray/time.rb +496 -342
- data/lib/carray/window_iterator.rb +191 -150
- 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 +4 -3
- 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 +7 -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 +26 -15
- data/yard-stubs/carray_access.rb +51 -4
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +118 -165
- 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 +5 -3
- 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 +157 -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 +67 -34
- 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 +10 -2
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +62 -24
- 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 -25337
- 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 -262
- data/lib/carray/data_type_limits.rb +0 -91
data/ext/carray_slab.h
CHANGED
|
@@ -2,22 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
carray_slab.h
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This header is internal to carray and carries no contract. It is not
|
|
6
|
+
installed; it ships in the gem's ext/ directory only because carray is
|
|
7
|
+
built from it there.
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`slab_state_run_body`
|
|
12
|
-
|
|
9
|
+
The state of one call of the slab iterator. Each `CArray#map_slab` /
|
|
10
|
+
`#reduce_slab` / `#each_slab` entry heap-allocates a zeroed
|
|
11
|
+
`ca_slab_iter_state_t` under a guard from `ca_window_guard_arm`
|
|
12
|
+
(slab_state_new), fills it with `slab_state_init`, which acquires
|
|
13
|
+
nothing, and runs `slab_state_run_body` and `slab_state_finish` under
|
|
14
|
+
`rb_ensure`, so the kernel iterator states and the scratch buffers are
|
|
15
|
+
released on both normal and exceptional exit. If the block's Fiber is
|
|
16
|
+
abandoned mid-walk, the guard's finalizer runs `slab_state_finish`.
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
The walk goes through the kernel iterator (ext/ca_kernel_iterator.h).
|
|
19
|
+
|
|
20
|
+
`ca_detach(slab_view)` is never called in finish: the slab buffer
|
|
21
|
+
belongs to the kernel iterator state or to this state, and a detach
|
|
22
|
+
would free it as if slab_view owned it. Finish drops the slab_view
|
|
23
|
+
VALUE handle instead, and GC reclaims the CAStride wrapper without
|
|
24
|
+
freeing the borrowed ptr.
|
|
21
25
|
|
|
22
26
|
--------------------------------------------------------------------------- */
|
|
23
27
|
|
|
@@ -27,10 +31,11 @@
|
|
|
27
31
|
#include "carray.h"
|
|
28
32
|
#include "ca_kernel_iterator.h"
|
|
29
33
|
|
|
30
|
-
/*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
/* Which method the call serves. reduce_slab has two forms: with `init:`
|
|
35
|
+
the block is yielded per element of a fiber (REDUCE_FIBER), without it
|
|
36
|
+
the block receives the whole slab (REDUCE_SLAB). The form is fixed by
|
|
37
|
+
the entry point before slab_state_init, and slab_state_run_body
|
|
38
|
+
switches on it once per call. */
|
|
34
39
|
typedef enum {
|
|
35
40
|
CA_SLAB_FORM_MAP = 0,
|
|
36
41
|
CA_SLAB_FORM_REDUCE_FIBER = 1, /* `init:` given, per-element yield */
|
|
@@ -38,29 +43,34 @@ typedef enum {
|
|
|
38
43
|
CA_SLAB_FORM_EACH = 3
|
|
39
44
|
} ca_slab_form_t;
|
|
40
45
|
|
|
41
|
-
/*
|
|
46
|
+
/* How the slab view reaches the cells: aliasing the source, or through a
|
|
47
|
+
scratch buffer. carray_slab.c does not set the `mode` field of the
|
|
48
|
+
state; a slab view read through a scratch buffer has a non-nil
|
|
49
|
+
`carrier`. */
|
|
42
50
|
typedef enum {
|
|
43
51
|
CA_SLAB_MODE_ALIAS = 0,
|
|
44
52
|
CA_SLAB_MODE_SCRATCH_CONTIG = 1,
|
|
45
53
|
CA_SLAB_MODE_SCRATCH_STRIDED = 2
|
|
46
54
|
} ca_slab_mode_t;
|
|
47
55
|
|
|
48
|
-
/*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
/* The state of one call. The guard from ca_window_guard_arm marks the
|
|
57
|
+
VALUE fields. The kernel iterator states (`t1`, `t1_out`) and the
|
|
58
|
+
own_*_scratch buffers are heap-allocated and freed by slab_state_finish.
|
|
59
|
+
The other resources (carrier / output / *_slab_view) are CArray VALUEs
|
|
60
|
+
that GC reclaims; finish sets the slab view and carrier handles to
|
|
61
|
+
Qnil. */
|
|
52
62
|
typedef struct ca_slab_iter_state {
|
|
53
63
|
VALUE self; /* source CArray (= @reference compatible) */
|
|
54
64
|
VALUE slab_view; /* CAStride view, per-iter ptr mutate target */
|
|
55
65
|
VALUE carrier; /* SCRATCH mode owning CArray, Qnil in ALIAS */
|
|
56
|
-
VALUE mask_carrier; /*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
VALUE mask_carrier; /* unused (always Qnil): the mask sibling
|
|
67
|
+
is owned by `carrier` through its C-level
|
|
68
|
+
mask field and needs no Ruby pin of its
|
|
69
|
+
own */
|
|
60
70
|
VALUE output; /* map_slab output / reduce_slab accumulator */
|
|
61
71
|
VALUE output_slab_view; /* write-side CAStride, Qnil unless MAP */
|
|
62
|
-
ca_iter_state *t1; /*
|
|
63
|
-
ca_iter_state *t1_out; /*
|
|
72
|
+
ca_iter_state *t1; /* kernel iterator state (READ side), heap, freed in finish */
|
|
73
|
+
ca_iter_state *t1_out; /* kernel iterator state (WRITE side, MAP only), heap */
|
|
64
74
|
uint8_t t1_started; /* 1 once t1 init_l2 returned OK (= finish gate) */
|
|
65
75
|
uint8_t t1_out_started; /* 1 once t1_out init_l2 returned OK */
|
|
66
76
|
int8_t form; /* ca_slab_form_t */
|
|
@@ -71,10 +81,11 @@ typedef struct ca_slab_iter_state {
|
|
|
71
81
|
ca_size_t out_bytes; /* output element size in bytes */
|
|
72
82
|
VALUE init_val; /* REDUCE_FIBER initial accumulator, Qnil if N/A */
|
|
73
83
|
|
|
74
|
-
/*
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
/* Own gather/scatter scratch for a slab of more than one axis that
|
|
85
|
+
cannot be lent in place: allocated when slab_ndim > 1 and the walk
|
|
86
|
+
does not read the source in place with row-major contiguous slab
|
|
87
|
+
strides; freed in finish. Independent of the kernel iterator's own
|
|
88
|
+
scratch. */
|
|
78
89
|
char *own_data_scratch; /* per-iter K-D gather (input side) */
|
|
79
90
|
boolean8_t *own_mask_scratch; /* per-iter K-D gather (input mask) */
|
|
80
91
|
char *own_out_scratch; /* per-iter K-D scatter (map output) */
|
data/ext/carray_sort.c
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
#include "ca_obj_face.h" /* CA_FACE_LIFT_IF_FACE */
|
|
14
14
|
#include "ca_sort_kernels.h" /* ca_sort_quick_* / ca_sort_merge_* / ca_partition_nan_* */
|
|
15
15
|
#include "ca_compare.h" /* ca_elem_cmp[] -- shared element comparators */
|
|
16
|
-
#include "carray_internal.h" /* ca_attach_window */
|
|
17
16
|
#include <math.h>
|
|
18
17
|
#include <float.h>
|
|
19
18
|
|
|
@@ -364,14 +363,16 @@ rb_ca_s_sort_addr_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
364
363
|
if ( elements != NUM2SIZE(rb_ca_elements(argv[j])) ) {
|
|
365
364
|
rb_raise(rb_eArgError, "elements mismatch");
|
|
366
365
|
}
|
|
367
|
-
|
|
366
|
+
/* gc: argv holds it for the call */
|
|
367
|
+
GetCArray(argv[j], ca_j);
|
|
368
368
|
if ( ca_is_face(ca_j) ) {
|
|
369
369
|
argv[j] = ca_order_key(argv[j], "sort_addr");
|
|
370
370
|
continue;
|
|
371
371
|
}
|
|
372
372
|
{
|
|
373
373
|
CArray *k;
|
|
374
|
-
|
|
374
|
+
/* gc: argv holds it for the call */
|
|
375
|
+
GetCArray(argv[j], k);
|
|
375
376
|
if ( ca_is_complex_type(k) ) {
|
|
376
377
|
rb_raise(rb_eCADataTypeError,
|
|
377
378
|
"sort_addr: a %s key has no order (complex numbers are not "
|
|
@@ -381,22 +382,25 @@ rb_ca_s_sort_addr_kw (int argc, VALUE *argv, VALUE ropt, VALUE self)
|
|
|
381
382
|
}
|
|
382
383
|
}
|
|
383
384
|
|
|
384
|
-
/* Scratch the unwind collects: the keys are read
|
|
385
|
-
|
|
385
|
+
/* Scratch the unwind collects: the keys are read while they are
|
|
386
|
+
attached, and a comparison of object keys can raise. */
|
|
386
387
|
base->n = argc;
|
|
387
388
|
base->masked_last = masked_last;
|
|
388
389
|
base->ca = ALLOCV_N(CArray *, hlist, base->n);
|
|
389
390
|
modes = ALLOCV_N(char, hmodes, argc + 1);
|
|
390
391
|
|
|
391
392
|
for (j=0; j<argc; j++) {
|
|
392
|
-
|
|
393
|
+
/* gc: argv holds it for the call */
|
|
394
|
+
GetCArray(argv[j], base->ca[j]);
|
|
393
395
|
has_object |= ( base->ca[j]->data_type == CA_OBJECT );
|
|
394
396
|
modes[j] = 'r';
|
|
395
397
|
}
|
|
396
398
|
modes[argc] = '\0';
|
|
397
399
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
+
/* Flat, as sort_index answers: the addresses of the whole array in sorted
|
|
401
|
+
order have no row or column to sit in. */
|
|
402
|
+
out = rb_carray_new(CA_SIZE, 1, &elements, 0, NULL);
|
|
403
|
+
GetCArray(out, co);
|
|
400
404
|
q = (ca_size_t *) co->ptr;
|
|
401
405
|
|
|
402
406
|
run.data = NULL;
|
|
@@ -621,16 +625,16 @@ axis2addr_body (void *user_data, void *ptr, ca_size_t n)
|
|
|
621
625
|
* by rb_ca_take_along_axis_c / rb_ca_put_along_axis in
|
|
622
626
|
* carray_order.c. */
|
|
623
627
|
VALUE
|
|
624
|
-
rb_ca_axis2addr_c (VALUE self, volatile VALUE vindices, VALUE vaxis)
|
|
628
|
+
rb_ca_axis2addr_c (volatile VALUE self, volatile VALUE vindices, VALUE vaxis)
|
|
625
629
|
{
|
|
626
630
|
rb_check_carray_object(vindices);
|
|
627
631
|
|
|
628
632
|
CArray *ca, *idx_ca, *out_ca;
|
|
629
|
-
|
|
630
|
-
|
|
633
|
+
GetCArray(self, ca);
|
|
634
|
+
GetCArray(vindices, idx_ca);
|
|
631
635
|
|
|
632
|
-
long axis_l =
|
|
633
|
-
|
|
636
|
+
long axis_l = rb_ca_normalize_axis_arg(NIL_P(vaxis) ? INT2FIX(0) : vaxis,
|
|
637
|
+
(int) ca->ndim, NULL);
|
|
634
638
|
int axis = (int) axis_l;
|
|
635
639
|
|
|
636
640
|
/* Shape rule: indices.ndim == self.ndim, dims match except at axis. */
|
|
@@ -661,9 +665,9 @@ rb_ca_axis2addr_c (VALUE self, volatile VALUE vindices, VALUE vaxis)
|
|
|
661
665
|
volatile VALUE vidx_cast = vindices;
|
|
662
666
|
CArray *idx_cast = idx_ca;
|
|
663
667
|
if ( idx_ca->data_type != CA_SIZE ) {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
668
|
+
/* coerce: a fixed type, indices are CA_SIZE */
|
|
669
|
+
vidx_cast = rb_ca_to_type(vindices, ID2SYM(ca_data_type_sym[CA_SIZE]), Qnil);
|
|
670
|
+
GetCArray(vidx_cast, idx_cast);
|
|
667
671
|
}
|
|
668
672
|
|
|
669
673
|
/* Row-major view-flat strides for self (in cells). */
|
|
@@ -678,7 +682,7 @@ rb_ca_axis2addr_c (VALUE self, volatile VALUE vindices, VALUE vaxis)
|
|
|
678
682
|
/* Allocate output: same shape as indices, data_type CA_SIZE. */
|
|
679
683
|
volatile VALUE vout =
|
|
680
684
|
rb_ca_template_with_type(vidx_cast, INT2NUM(CA_SIZE), INT2NUM(0));
|
|
681
|
-
|
|
685
|
+
GetCArray(vout, out_ca);
|
|
682
686
|
|
|
683
687
|
/* out_ca is a freshly allocated entity of the indices' shape and cell
|
|
684
688
|
width, so the indices are copied into it (a view is gathered without
|
|
@@ -722,22 +726,22 @@ rb_ca_axis2addr (int argc, VALUE *argv, VALUE self)
|
|
|
722
726
|
cells (a sort, a selection, a ranking, an extremum by key). A plain
|
|
723
727
|
array is its own key. An ORDERABLE Face orders by its storage, so the
|
|
724
728
|
key is the storage. A Face that is not ORDERABLE but defines its own
|
|
725
|
-
#
|
|
729
|
+
#rank_index (CAConstString, whose cells are offsets; CARecord, whose bytes
|
|
726
730
|
are no order) is keyed by that order, as a dense rank, so ties stay ties
|
|
727
731
|
and a masked cell stays masked. A Face that has no order (a CARecord
|
|
728
732
|
without order_by:) raises in that order; any other Face raises here. */
|
|
729
733
|
VALUE
|
|
730
|
-
ca_order_key (VALUE v, const char *name)
|
|
734
|
+
ca_order_key (volatile VALUE v, const char *name)
|
|
731
735
|
{
|
|
732
736
|
CArray *ca;
|
|
733
|
-
|
|
737
|
+
GetCArray(v, ca);
|
|
734
738
|
if ( ! ca_is_face(ca) ) {
|
|
735
739
|
return v;
|
|
736
740
|
}
|
|
737
741
|
if ( ca_face_orders_by_itself(v) ) {
|
|
738
742
|
VALUE opts = rb_hash_new();
|
|
739
743
|
rb_hash_aset(opts, ID2SYM(rb_intern("method")), ID2SYM(rb_intern("dense")));
|
|
740
|
-
return rb_funcallv_kw(v, rb_intern("
|
|
744
|
+
return rb_funcallv_kw(v, rb_intern("rank_index"), 1, &opts, RB_PASS_KEYWORDS);
|
|
741
745
|
}
|
|
742
746
|
ca_face_require_orderable(v, name, "order");
|
|
743
747
|
return rb_ca_strip_face_value(v);
|
|
@@ -781,7 +785,7 @@ ca_order_key (VALUE v, const char *name)
|
|
|
781
785
|
* numeric, both no-axis and axis: forms.
|
|
782
786
|
*/
|
|
783
787
|
static VALUE
|
|
784
|
-
rb_ca_sorted_view_kw (VALUE rkw, VALUE self)
|
|
788
|
+
rb_ca_sorted_view_kw (VALUE rkw, volatile VALUE self)
|
|
785
789
|
{
|
|
786
790
|
VALUE vaxis = Qnil;
|
|
787
791
|
VALUE vkind = Qnil;
|
|
@@ -801,7 +805,7 @@ rb_ca_sorted_view_kw (VALUE rkw, VALUE self)
|
|
|
801
805
|
: ca_symbol_choice(vmasked_position, "masked_position", "first", "last", NULL);
|
|
802
806
|
|
|
803
807
|
CArray *ca;
|
|
804
|
-
|
|
808
|
+
GetCArray(self, ca);
|
|
805
809
|
|
|
806
810
|
/* Build target view (flatten for no-arg, identity for axis: kwarg)
|
|
807
811
|
before mask handling: rb_ca_flatten re-propagates the mask field
|
|
@@ -870,7 +874,7 @@ rb_ca_sorted_view (int argc, VALUE *argv, VALUE self)
|
|
|
870
874
|
* different ways depending on which of the pair was asked.
|
|
871
875
|
*/
|
|
872
876
|
static VALUE
|
|
873
|
-
rb_ca_sort_copy (int argc, VALUE *argv, VALUE self)
|
|
877
|
+
rb_ca_sort_copy (int argc, VALUE *argv, volatile VALUE self)
|
|
874
878
|
{
|
|
875
879
|
VALUE rkw = Qnil;
|
|
876
880
|
VALUE vaxis = Qnil;
|
|
@@ -891,7 +895,7 @@ rb_ca_sort_copy (int argc, VALUE *argv, VALUE self)
|
|
|
891
895
|
}
|
|
892
896
|
|
|
893
897
|
CArray *ca;
|
|
894
|
-
|
|
898
|
+
GetCArray(self, ca);
|
|
895
899
|
|
|
896
900
|
/* The per-fiber path below covers unmasked CA_INT8..CA_FLOAT64 only.
|
|
897
901
|
Everything else goes to {sort} (which handles the fixlen dialect,
|
|
@@ -922,10 +926,10 @@ rb_ca_sort_copy (int argc, VALUE *argv, VALUE self)
|
|
|
922
926
|
}
|
|
923
927
|
|
|
924
928
|
CArray *cat;
|
|
925
|
-
|
|
929
|
+
GetCArray(target, cat);
|
|
926
930
|
|
|
927
931
|
/* Normalize axis (negative -> +ndim, range check). */
|
|
928
|
-
int axis =
|
|
932
|
+
int axis = rb_ca_normalize_axis_arg(vaxis_use, cat->ndim, NULL);
|
|
929
933
|
|
|
930
934
|
/* Allocate output: same shape and data_type as target
|
|
931
935
|
(bytes=0 = preserve native bytes). */
|
|
@@ -933,7 +937,7 @@ rb_ca_sort_copy (int argc, VALUE *argv, VALUE self)
|
|
|
933
937
|
INT2NUM(cat->data_type),
|
|
934
938
|
INT2NUM(0));
|
|
935
939
|
CArray *cao;
|
|
936
|
-
|
|
940
|
+
GetCArray(vout, cao);
|
|
937
941
|
|
|
938
942
|
/* Per-fiber sort via the CA_FOR_EACH_FIBER_INOUT catalog macro.
|
|
939
943
|
The kernel_iterator engine guarantees pi/po contig delivery
|
|
@@ -1014,7 +1018,6 @@ rb_ca_sort_copy (int argc, VALUE *argv, VALUE self)
|
|
|
1014
1018
|
}
|
|
1015
1019
|
ALLOCV_END(aux_holder);
|
|
1016
1020
|
|
|
1017
|
-
RB_GC_GUARD(target);
|
|
1018
1021
|
rb_ca_inherit_attr(vout, self);
|
|
1019
1022
|
return vout;
|
|
1020
1023
|
}
|
data/ext/carray_sort_kernel.c
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
#define DEFINE_SORT_MERGE(TYPE, SUFFIX) \
|
|
64
64
|
\
|
|
65
65
|
/* insertion-sort pre-pass on a[lo..hi-1] (half-open). R-wide blocks. \
|
|
66
|
-
Writes only into `a` (no
|
|
66
|
+
Writes only into `a` (no extra buffers). Body is intentionally \
|
|
67
67
|
identical to the quicksort insertion base. */ \
|
|
68
68
|
static void \
|
|
69
69
|
ca_sort_merge_##SUFFIX##_inspass (TYPE *a, ca_size_t n) \
|
|
@@ -170,11 +170,12 @@ ca_sort_quick_##SUFFIX##_range (TYPE *a, ca_size_t lo, ca_size_t hi, \
|
|
|
170
170
|
/* Depth-limit escape: mergesort the remaining subrange. \
|
|
171
171
|
The surrounding quicksort loop has already partitioned the \
|
|
172
172
|
higher subranges, so only this [lo, hi] window needs the aux \
|
|
173
|
-
buffer
|
|
173
|
+
buffer. */ \
|
|
174
174
|
ca_size_t n_remain = hi - lo + 1; \
|
|
175
|
-
|
|
175
|
+
volatile VALUE haux = 0; \
|
|
176
|
+
TYPE *aux = ALLOCV_N(TYPE, haux, n_remain); \
|
|
176
177
|
ca_sort_merge_##SUFFIX(a + lo, aux, n_remain); \
|
|
177
|
-
|
|
178
|
+
ALLOCV_END(haux); \
|
|
178
179
|
return; \
|
|
179
180
|
} \
|
|
180
181
|
depth_limit--; \
|
|
@@ -339,10 +340,10 @@ ca_sort_quick_pair_##SUFFIX##_range (ca_pair_##SUFFIX *a, \
|
|
|
339
340
|
while ( hi - lo > CA_SORT_INSERTION_THRESHOLD ) { \
|
|
340
341
|
if ( depth_limit <= 0 ) { \
|
|
341
342
|
ca_size_t n_remain = hi - lo + 1; \
|
|
342
|
-
|
|
343
|
-
|
|
343
|
+
volatile VALUE haux = 0; \
|
|
344
|
+
ca_pair_##SUFFIX *aux = ALLOCV_N(ca_pair_##SUFFIX, haux, n_remain); \
|
|
344
345
|
ca_sort_merge_pair_##SUFFIX(a + lo, aux, n_remain); \
|
|
345
|
-
|
|
346
|
+
ALLOCV_END(haux); \
|
|
346
347
|
return; \
|
|
347
348
|
} \
|
|
348
349
|
depth_limit--; \
|
|
@@ -537,9 +538,10 @@ ca_partition_quick_##SUFFIX##_range (TYPE *a, ca_size_t lo, ca_size_t hi, \
|
|
|
537
538
|
ends up correct as a side-effect. Cheaper than continuing to \
|
|
538
539
|
degrade on adversarial input. */ \
|
|
539
540
|
ca_size_t n_remain = hi - lo + 1; \
|
|
540
|
-
|
|
541
|
+
volatile VALUE haux = 0; \
|
|
542
|
+
TYPE *aux = ALLOCV_N(TYPE, haux, n_remain); \
|
|
541
543
|
ca_sort_merge_##SUFFIX(a + lo, aux, n_remain); \
|
|
542
|
-
|
|
544
|
+
ALLOCV_END(haux); \
|
|
543
545
|
return; \
|
|
544
546
|
} \
|
|
545
547
|
depth_limit--; \
|
|
@@ -576,7 +578,7 @@ ca_partition_quick_##SUFFIX##_range (TYPE *a, ca_size_t lo, ca_size_t hi, \
|
|
|
576
578
|
} \
|
|
577
579
|
/* insertion-sort the residual base window so a[kth] is exact within \
|
|
578
580
|
[lo, hi]. Cheaper than another quickselect step and gives the \
|
|
579
|
-
partition contract
|
|
581
|
+
partition contract across the small window. */ \
|
|
580
582
|
for ( ca_size_t k = lo + 1; k <= hi; k++ ) { \
|
|
581
583
|
TYPE v = a[k]; \
|
|
582
584
|
ca_size_t m = k; \
|
data/ext/carray_struct.c
CHANGED
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
---------------------------------------------------------------------------- */
|
|
23
23
|
|
|
24
24
|
#include "carray.h"
|
|
25
|
-
#include "carray_internal.h" /* ca_obj2integer_fitting */
|
|
26
25
|
#include <string.h>
|
|
27
26
|
|
|
28
27
|
/* ---------------------------------------------------------------------
|
|
@@ -113,15 +112,12 @@ ca_struct_read_primitive_fast (const char *p, int type_code)
|
|
|
113
112
|
}
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
/* A
|
|
117
|
-
|
|
115
|
+
/* A number member takes a Numeric, as a store into the member's field
|
|
116
|
+
view does (ca_refuse_non_number_value). */
|
|
118
117
|
static void
|
|
119
118
|
ca_struct_write_primitive_fast (char *p, int type_code, VALUE val)
|
|
120
119
|
{
|
|
121
|
-
|
|
122
|
-
ca_decimal_string_store(val, (int8_t) type_code, p);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
120
|
+
ca_refuse_non_number_value((int8_t) type_code, val);
|
|
125
121
|
switch (type_code) {
|
|
126
122
|
case CA_BOOLEAN: {
|
|
127
123
|
/* The values a boolean array takes: true / false / 1 / 0. */
|
|
@@ -137,42 +133,42 @@ ca_struct_write_primitive_fast (char *p, int type_code, VALUE val)
|
|
|
137
133
|
return;
|
|
138
134
|
}
|
|
139
135
|
case CA_INT8: {
|
|
140
|
-
int8_t v = (int8_t) NUM2LL(
|
|
136
|
+
int8_t v = (int8_t) NUM2LL(rb_ca_obj2integer_fitting(val, CA_INT8));
|
|
141
137
|
memcpy(p, &v, 1);
|
|
142
138
|
return;
|
|
143
139
|
}
|
|
144
140
|
case CA_UINT8: {
|
|
145
|
-
uint8_t v = (uint8_t) rb_num2ull(
|
|
141
|
+
uint8_t v = (uint8_t) rb_num2ull(rb_ca_obj2integer_fitting(val, CA_UINT8));
|
|
146
142
|
memcpy(p, &v, 1);
|
|
147
143
|
return;
|
|
148
144
|
}
|
|
149
145
|
case CA_INT16: {
|
|
150
|
-
int16_t v = (int16_t) NUM2LL(
|
|
146
|
+
int16_t v = (int16_t) NUM2LL(rb_ca_obj2integer_fitting(val, CA_INT16));
|
|
151
147
|
memcpy(p, &v, 2);
|
|
152
148
|
return;
|
|
153
149
|
}
|
|
154
150
|
case CA_UINT16: {
|
|
155
|
-
uint16_t v = (uint16_t) rb_num2ull(
|
|
151
|
+
uint16_t v = (uint16_t) rb_num2ull(rb_ca_obj2integer_fitting(val, CA_UINT16));
|
|
156
152
|
memcpy(p, &v, 2);
|
|
157
153
|
return;
|
|
158
154
|
}
|
|
159
155
|
case CA_INT32: {
|
|
160
|
-
int32_t v = (int32_t) NUM2LL(
|
|
156
|
+
int32_t v = (int32_t) NUM2LL(rb_ca_obj2integer_fitting(val, CA_INT32));
|
|
161
157
|
memcpy(p, &v, 4);
|
|
162
158
|
return;
|
|
163
159
|
}
|
|
164
160
|
case CA_UINT32: {
|
|
165
|
-
uint32_t v = (uint32_t) rb_num2ull(
|
|
161
|
+
uint32_t v = (uint32_t) rb_num2ull(rb_ca_obj2integer_fitting(val, CA_UINT32));
|
|
166
162
|
memcpy(p, &v, 4);
|
|
167
163
|
return;
|
|
168
164
|
}
|
|
169
165
|
case CA_INT64: {
|
|
170
|
-
int64_t v = (int64_t) NUM2LL(
|
|
166
|
+
int64_t v = (int64_t) NUM2LL(rb_ca_obj2integer_fitting(val, CA_INT64));
|
|
171
167
|
memcpy(p, &v, 8);
|
|
172
168
|
return;
|
|
173
169
|
}
|
|
174
170
|
case CA_UINT64: {
|
|
175
|
-
uint64_t v = (uint64_t) rb_num2ull(
|
|
171
|
+
uint64_t v = (uint64_t) rb_num2ull(rb_ca_obj2integer_fitting(val, CA_UINT64));
|
|
176
172
|
memcpy(p, &v, 8);
|
|
177
173
|
return;
|
|
178
174
|
}
|
|
@@ -330,43 +326,35 @@ ca_struct_read_endian_swapped_fast (const char *p, int type_code)
|
|
|
330
326
|
static void
|
|
331
327
|
ca_struct_write_endian_swapped_fast (char *p, int type_code, VALUE val)
|
|
332
328
|
{
|
|
333
|
-
|
|
334
|
-
char host[8];
|
|
335
|
-
ca_decimal_string_store(val, (int8_t) type_code, host);
|
|
336
|
-
switch ( ca_sizeof[type_code] ) {
|
|
337
|
-
case 2: { uint16_t v; memcpy(&v, host, 2); v = CA_BSWAP16(v); memcpy(p, &v, 2); return; }
|
|
338
|
-
case 4: { uint32_t v; memcpy(&v, host, 4); v = CA_BSWAP32(v); memcpy(p, &v, 4); return; }
|
|
339
|
-
case 8: { uint64_t v; memcpy(&v, host, 8); v = CA_BSWAP64(v); memcpy(p, &v, 8); return; }
|
|
340
|
-
}
|
|
341
|
-
}
|
|
329
|
+
ca_refuse_non_number_value((int8_t) type_code, val);
|
|
342
330
|
switch (type_code) {
|
|
343
331
|
case CA_INT16: {
|
|
344
|
-
uint16_t v = (uint16_t) NUM2LL(
|
|
332
|
+
uint16_t v = (uint16_t) NUM2LL(rb_ca_obj2integer_fitting(val, CA_INT16));
|
|
345
333
|
v = CA_BSWAP16(v); memcpy(p, &v, 2);
|
|
346
334
|
return;
|
|
347
335
|
}
|
|
348
336
|
case CA_UINT16: {
|
|
349
|
-
uint16_t v = (uint16_t) rb_num2ull(
|
|
337
|
+
uint16_t v = (uint16_t) rb_num2ull(rb_ca_obj2integer_fitting(val, CA_UINT16));
|
|
350
338
|
v = CA_BSWAP16(v); memcpy(p, &v, 2);
|
|
351
339
|
return;
|
|
352
340
|
}
|
|
353
341
|
case CA_INT32: {
|
|
354
|
-
uint32_t v = (uint32_t) NUM2LL(
|
|
342
|
+
uint32_t v = (uint32_t) NUM2LL(rb_ca_obj2integer_fitting(val, CA_INT32));
|
|
355
343
|
v = CA_BSWAP32(v); memcpy(p, &v, 4);
|
|
356
344
|
return;
|
|
357
345
|
}
|
|
358
346
|
case CA_UINT32: {
|
|
359
|
-
uint32_t v = (uint32_t) rb_num2ull(
|
|
347
|
+
uint32_t v = (uint32_t) rb_num2ull(rb_ca_obj2integer_fitting(val, CA_UINT32));
|
|
360
348
|
v = CA_BSWAP32(v); memcpy(p, &v, 4);
|
|
361
349
|
return;
|
|
362
350
|
}
|
|
363
351
|
case CA_INT64: {
|
|
364
|
-
uint64_t v = (uint64_t) NUM2LL(
|
|
352
|
+
uint64_t v = (uint64_t) NUM2LL(rb_ca_obj2integer_fitting(val, CA_INT64));
|
|
365
353
|
v = CA_BSWAP64(v); memcpy(p, &v, 8);
|
|
366
354
|
return;
|
|
367
355
|
}
|
|
368
356
|
case CA_UINT64: {
|
|
369
|
-
uint64_t v = (uint64_t) rb_num2ull(
|
|
357
|
+
uint64_t v = (uint64_t) rb_num2ull(rb_ca_obj2integer_fitting(val, CA_UINT64));
|
|
370
358
|
v = CA_BSWAP64(v); memcpy(p, &v, 8);
|
|
371
359
|
return;
|
|
372
360
|
}
|
|
@@ -427,10 +415,16 @@ ca_struct_member_name (VALUE klass, VALUE name)
|
|
|
427
415
|
VALUE str = rb_sym2str(name);
|
|
428
416
|
if ( ! NIL_P(rb_hash_aref(rb_const_get(klass, rb_intern("MEMBER_TABLE")),
|
|
429
417
|
str)) ) {
|
|
418
|
+
/* The accessors are the only public methods the struct class defines
|
|
419
|
+
itself; a member named like an existing method has none. */
|
|
420
|
+
VALUE hint = RTEST(rb_funcall(klass, rb_intern("public_method_defined?"),
|
|
421
|
+
2, name, Qfalse))
|
|
422
|
+
? rb_sprintf(" or read by its accessor (s.%"PRIsVALUE")", str)
|
|
423
|
+
: rb_str_new_cstr("");
|
|
430
424
|
rb_raise(rb_eTypeError,
|
|
431
|
-
"a struct member is named by a String (s[\"%"PRIsVALUE"\"])
|
|
432
|
-
"
|
|
433
|
-
str,
|
|
425
|
+
"a struct member is named by a String (s[\"%"PRIsVALUE"\"])"
|
|
426
|
+
"%"PRIsVALUE", not by a Symbol",
|
|
427
|
+
str, hint);
|
|
434
428
|
}
|
|
435
429
|
rb_raise(rb_eTypeError,
|
|
436
430
|
"a struct member is named by a String, not by a Symbol "
|
|
@@ -461,7 +455,7 @@ ca_struct_member_name (VALUE klass, VALUE name)
|
|
|
461
455
|
--------------------------------------------------------------------- */
|
|
462
456
|
|
|
463
457
|
static int
|
|
464
|
-
ca_struct_dispatch_write (VALUE klass, VALUE name_s, VALUE val, VALUE data_val)
|
|
458
|
+
ca_struct_dispatch_write (VALUE klass, VALUE name_s, VALUE val, volatile VALUE data_val)
|
|
465
459
|
{
|
|
466
460
|
if (rb_const_defined(klass, rb_intern("FAST_PRIMITIVES"))) {
|
|
467
461
|
VALUE fast_table = rb_const_get(klass, rb_intern("FAST_PRIMITIVES"));
|
|
@@ -469,7 +463,7 @@ ca_struct_dispatch_write (VALUE klass, VALUE name_s, VALUE val, VALUE data_val)
|
|
|
469
463
|
if (!NIL_P(entry)) {
|
|
470
464
|
int kind = NUM2INT(rb_ary_entry(entry, 0));
|
|
471
465
|
CArray *ca;
|
|
472
|
-
|
|
466
|
+
GetCArray(data_val, ca);
|
|
473
467
|
switch (kind) {
|
|
474
468
|
case FAST_KIND_PRIMITIVE: {
|
|
475
469
|
ca_size_t offset = NUM2SIZE(rb_ary_entry(entry, 1));
|
|
@@ -524,9 +518,9 @@ rb_ca_struct_aref (VALUE self, VALUE name)
|
|
|
524
518
|
if (rb_const_defined(klass, rb_intern("FAST_PRIMITIVES"))) {
|
|
525
519
|
VALUE fast_table = rb_const_get(klass, rb_intern("FAST_PRIMITIVES"));
|
|
526
520
|
VALUE entry = rb_hash_aref(fast_table, name_s);
|
|
527
|
-
VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
521
|
+
volatile VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
528
522
|
CArray *ca;
|
|
529
|
-
|
|
523
|
+
GetCArray(data_val, ca);
|
|
530
524
|
/* The fast path reads ca->ptr, which only an entity holds. A nested
|
|
531
525
|
element's @data is a view on its parent's bytes and goes through the
|
|
532
526
|
dispatch procs below, which reach them through field views. */
|
|
@@ -570,7 +564,7 @@ rb_ca_struct_aref (VALUE self, VALUE name)
|
|
|
570
564
|
VALUE pair = rb_hash_aref(dispatch_table, name_s);
|
|
571
565
|
if (!NIL_P(pair)) {
|
|
572
566
|
VALUE reader = rb_ary_entry(pair, 0);
|
|
573
|
-
VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
567
|
+
volatile VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
574
568
|
return rb_funcall(reader, rb_intern("call"), 1, data_val);
|
|
575
569
|
}
|
|
576
570
|
|
|
@@ -606,9 +600,9 @@ rb_ca_struct_aset (VALUE self, VALUE name, VALUE val)
|
|
|
606
600
|
if (rb_const_defined(klass, rb_intern("FAST_PRIMITIVES"))) {
|
|
607
601
|
VALUE fast_table = rb_const_get(klass, rb_intern("FAST_PRIMITIVES"));
|
|
608
602
|
VALUE entry = rb_hash_aref(fast_table, name_s);
|
|
609
|
-
VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
603
|
+
volatile VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
610
604
|
CArray *ca;
|
|
611
|
-
|
|
605
|
+
GetCArray(data_val, ca);
|
|
612
606
|
/* Only an entity @data is written through ca->ptr (see the reader). */
|
|
613
607
|
if (!NIL_P(entry) && ca_is_entity(ca)) {
|
|
614
608
|
int kind = NUM2INT(rb_ary_entry(entry, 0));
|
|
@@ -646,7 +640,7 @@ rb_ca_struct_aset (VALUE self, VALUE name, VALUE val)
|
|
|
646
640
|
VALUE pair = rb_hash_aref(dispatch_table, name_s);
|
|
647
641
|
if (!NIL_P(pair)) {
|
|
648
642
|
VALUE writer = rb_ary_entry(pair, 1);
|
|
649
|
-
VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
643
|
+
volatile VALUE data_val = rb_ivar_get(self, rb_intern("@data"));
|
|
650
644
|
rb_funcall(writer, rb_intern("call"), 2, data_val, val);
|
|
651
645
|
return val;
|
|
652
646
|
}
|
|
@@ -691,6 +685,7 @@ ca_struct_hash_init_iter (VALUE key, VALUE val, VALUE state_va)
|
|
|
691
685
|
static VALUE
|
|
692
686
|
rb_ca_struct_initialize (int argc, VALUE *argv, VALUE self)
|
|
693
687
|
{
|
|
688
|
+
/* args: the values of the members, in order or as keywords by name */
|
|
694
689
|
VALUE klass = rb_obj_class(self);
|
|
695
690
|
|
|
696
691
|
/* @data is a CScalar entity sized to klass::DATA_SIZE. The
|
|
@@ -720,8 +715,8 @@ rb_ca_struct_initialize (int argc, VALUE *argv, VALUE self)
|
|
|
720
715
|
(VALUE) &state);
|
|
721
716
|
if (!NIL_P(state.unknown_keys)) {
|
|
722
717
|
VALUE members = rb_const_get(klass, rb_intern("MEMBERS"));
|
|
723
|
-
VALUE unknown_inspect = rb_inspect(state.unknown_keys);
|
|
724
|
-
VALUE known_inspect = rb_inspect(members);
|
|
718
|
+
volatile VALUE unknown_inspect = rb_inspect(state.unknown_keys);
|
|
719
|
+
volatile VALUE known_inspect = rb_inspect(members);
|
|
725
720
|
rb_raise(rb_eArgError,
|
|
726
721
|
"unknown member(s) for %"PRIsVALUE": %s (known: %s)",
|
|
727
722
|
klass,
|