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.
Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1830
  4. data/README.md +62 -35
  5. data/carray.gemspec +16 -4
  6. data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
  7. data/ext/ca_array_pool.c +4 -5
  8. data/ext/ca_axis_descriptor.h +45 -30
  9. data/ext/ca_axis_dispatch.c +7 -4
  10. data/ext/ca_axis_group.c +12 -15
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +35 -0
  13. data/ext/ca_binop_dispatch.h +22 -46
  14. data/ext/ca_categorical_iterator.c +36 -34
  15. data/ext/ca_compare.c +0 -1
  16. data/ext/ca_compare.h +8 -1
  17. data/ext/ca_composite_dispatch.h +6 -0
  18. data/ext/ca_for_buffer.h +6 -1
  19. data/ext/ca_group_iter.c +17 -18
  20. data/ext/ca_iter_state_fields.h +196 -0
  21. data/ext/ca_iter_substrate.h +84 -103
  22. data/ext/ca_kernel_iterator.c +125 -89
  23. data/ext/ca_kernel_iterator.h +229 -1504
  24. data/ext/ca_kernel_iterator_internal.h +1167 -0
  25. data/ext/ca_moncmp_dispatch.h +17 -24
  26. data/ext/ca_monop_dispatch.h +25 -74
  27. data/ext/ca_obj_array.c +92 -165
  28. data/ext/ca_obj_bincmp.c +65 -48
  29. data/ext/ca_obj_binop.c +74 -49
  30. data/ext/ca_obj_bitarray.c +7 -21
  31. data/ext/ca_obj_bitfield.c +93 -26
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +34 -34
  34. data/ext/ca_obj_const_string.c +464 -304
  35. data/ext/ca_obj_face.c +167 -121
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +127 -34
  38. data/ext/ca_obj_farray.c +13 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +57 -34
  41. data/ext/ca_obj_grid.c +149 -113
  42. data/ext/ca_obj_meld.c +28 -26
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +88 -73
  45. data/ext/ca_obj_object.c +60 -46
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +10 -14
  48. data/ext/ca_obj_refer.c +146 -39
  49. data/ext/ca_obj_remap.c +11 -29
  50. data/ext/ca_obj_repeat.c +41 -23
  51. data/ext/ca_obj_roll.c +20 -28
  52. data/ext/ca_obj_select.c +17 -27
  53. data/ext/ca_obj_select_axis.c +35 -42
  54. data/ext/ca_obj_shift.c +22 -42
  55. data/ext/ca_obj_source.c +1 -5
  56. data/ext/ca_obj_stack.c +33 -29
  57. data/ext/ca_obj_stride.c +99 -62
  58. data/ext/ca_obj_string.c +8 -20
  59. data/ext/ca_obj_tile.c +14 -16
  60. data/ext/ca_obj_time.c +12 -23
  61. data/ext/ca_obj_timedelta.c +12 -23
  62. data/ext/ca_obj_transpose.c +8 -10
  63. data/ext/ca_obj_triop.c +48 -49
  64. data/ext/ca_obj_window.c +87 -99
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +97 -27
  67. data/ext/ca_op_powi.h +9 -28
  68. data/ext/ca_pow5_table.h +2 -1
  69. data/ext/ca_rng_normal.h +4 -0
  70. data/ext/ca_rng_xoshiro256pp.h +3 -0
  71. data/ext/ca_sort_kernels.h +23 -26
  72. data/ext/ca_sweep_engine.c +92 -26
  73. data/ext/ca_sweep_engine.h +22 -15
  74. data/ext/ca_transform_common.c +3 -8
  75. data/ext/ca_triop_dispatch.h +20 -32
  76. data/ext/caframe_csv_reader.c +12 -12
  77. data/ext/carray.h +300 -1009
  78. data/ext/carray_access.c +320 -207
  79. data/ext/carray_address_basis.c +128 -59
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +31 -27
  83. data/ext/carray_call_cfunc.c +174 -285
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +1191 -351
  86. data/ext/carray_cast_func.rb +68 -8
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +98 -39
  89. data/ext/carray_copy.c +52 -26
  90. data/ext/carray_core.c +286 -132
  91. data/ext/carray_count.c +53 -22
  92. data/ext/carray_element.c +49 -28
  93. data/ext/carray_factorize.c +64 -63
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +9 -11
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +127 -230
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1364 -156
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +37 -37
  103. data/ext/carray_loop.c +27 -23
  104. data/ext/carray_mask.c +235 -150
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +106 -100
  108. data/ext/carray_memory_view.c +83 -69
  109. data/ext/carray_operator.c +490 -128
  110. data/ext/carray_order.c +163 -84
  111. data/ext/carray_partition.c +14 -16
  112. data/ext/carray_random.c +48 -42
  113. data/ext/carray_round.c +33 -5
  114. data/ext/carray_scatter.c +57 -39
  115. data/ext/carray_segment.c +42 -46
  116. data/ext/carray_slab.c +77 -51
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +37 -31
  119. data/ext/carray_sort_kernel.c +36 -10
  120. data/ext/carray_struct.c +44 -34
  121. data/ext/carray_test.c +131 -81
  122. data/ext/carray_time_text.c +30 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +373 -139
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +25 -31
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +819 -488
  129. data/ext/ruby_carray.c +47 -42
  130. data/ext/version.h +7 -5
  131. data/lib/carray/attribute.rb +19 -18
  132. data/lib/carray/autoload_carray.rb +20 -15
  133. data/lib/carray/autoload_method_extension.rb +64 -57
  134. data/lib/carray/axis_group.rb +272 -185
  135. data/lib/carray/basics.rb +298 -56
  136. data/lib/carray/bincount_nd.rb +41 -18
  137. data/lib/carray/block_iterator.rb +167 -119
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +84 -59
  140. data/lib/carray/categorical_iterator.rb +90 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +98 -23
  143. data/lib/carray/const_string.rb +112 -46
  144. data/lib/carray/core_extensions.rb +20 -69
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +95 -12
  148. data/lib/carray/frame/column_verbs.rb +76 -9
  149. data/lib/carray/frame/concat.rb +51 -7
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +20 -5
  152. data/lib/carray/frame/frame.rb +73 -31
  153. data/lib/carray/frame/group.rb +247 -187
  154. data/lib/carray/frame/io.rb +36 -12
  155. data/lib/carray/frame/join.rb +56 -17
  156. data/lib/carray/frame/records.rb +7 -5
  157. data/lib/carray/frame/reshape.rb +27 -7
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +217 -134
  160. data/lib/carray/frame/windows.rb +254 -19
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +28 -23
  163. data/lib/carray/fusion.rb +30 -30
  164. data/lib/carray/histogram.rb +35 -16
  165. data/lib/carray/inspect.rb +7 -7
  166. data/lib/carray/iterator.rb +104 -23
  167. data/lib/carray/key_windows.rb +93 -61
  168. data/lib/carray/lazy.rb +208 -111
  169. data/lib/carray/limits.rb +80 -0
  170. data/lib/carray/mask_gap_fill.rb +21 -16
  171. data/lib/carray/math.rb +87 -50
  172. data/lib/carray/meld_reduce.rb +30 -8
  173. data/lib/carray/methods/align_addr.rb +29 -17
  174. data/lib/carray/methods/bin.rb +8 -1
  175. data/lib/carray/methods/bincount.rb +4 -2
  176. data/lib/carray/methods/bit_string.rb +19 -31
  177. data/lib/carray/methods/broadcast.rb +8 -3
  178. data/lib/carray/methods/choose.rb +5 -5
  179. data/lib/carray/methods/composition.rb +73 -72
  180. data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
  181. data/lib/carray/methods/discovery_along.rb +3 -3
  182. data/lib/carray/methods/factorize.rb +2 -0
  183. data/lib/carray/methods/gather_nd.rb +106 -103
  184. data/lib/carray/methods/insert_block.rb +2 -2
  185. data/lib/carray/methods/is_between.rb +6 -4
  186. data/lib/carray/methods/is_in.rb +183 -143
  187. data/lib/carray/methods/join.rb +2 -1
  188. data/lib/carray/methods/lag.rb +6 -2
  189. data/lib/carray/methods/locate_addr.rb +157 -94
  190. data/lib/carray/methods/mask_duplicates.rb +1 -1
  191. data/lib/carray/methods/meshgrid.rb +28 -16
  192. data/lib/carray/methods/mode.rb +67 -67
  193. data/lib/carray/methods/nunique.rb +9 -7
  194. data/lib/carray/methods/repeat.rb +23 -13
  195. data/lib/carray/methods/resize.rb +1 -1
  196. data/lib/carray/methods/snap.rb +24 -20
  197. data/lib/carray/methods/string_format.rb +2 -2
  198. data/lib/carray/methods/unique.rb +4 -2
  199. data/lib/carray/methods/value_counts.rb +1 -1
  200. data/lib/carray/mkmf.rb +25 -28
  201. data/lib/carray/percentile_arguments.rb +82 -0
  202. data/lib/carray/record_order.rb +50 -20
  203. data/lib/carray/rng.rb +1 -0
  204. data/lib/carray/runtime.rb +195 -17
  205. data/lib/carray/segment_iterator.rb +262 -137
  206. data/lib/carray/serialize.rb +635 -566
  207. data/lib/carray/slab_iterator.rb +114 -114
  208. data/lib/carray/stack.rb +14 -15
  209. data/lib/carray/string.rb +16 -22
  210. data/lib/carray/string_operation_extension.rb +97 -52
  211. data/lib/carray/struct.rb +122 -164
  212. data/lib/carray/struct_builder.rb +247 -73
  213. data/lib/carray/time.rb +663 -365
  214. data/lib/carray/window_iterator.rb +232 -155
  215. data/lib/carray.rb +6 -11
  216. data/yard-stubs/ca_obj_array.rb +20 -135
  217. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  218. data/yard-stubs/ca_obj_bitfield.rb +6 -2
  219. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  220. data/yard-stubs/ca_obj_fake.rb +3 -1
  221. data/yard-stubs/ca_obj_farray.rb +1 -1
  222. data/yard-stubs/ca_obj_field.rb +8 -6
  223. data/yard-stubs/ca_obj_refer.rb +10 -5
  224. data/yard-stubs/ca_obj_roll.rb +7 -6
  225. data/yard-stubs/ca_obj_shift.rb +2 -3
  226. data/yard-stubs/ca_obj_stride.rb +5 -7
  227. data/yard-stubs/ca_obj_tile.rb +1 -1
  228. data/yard-stubs/ca_obj_time.rb +43 -0
  229. data/yard-stubs/ca_obj_transpose.rb +1 -1
  230. data/yard-stubs/ca_obj_window.rb +28 -16
  231. data/yard-stubs/carray_access.rb +55 -6
  232. data/yard-stubs/carray_attribute.rb +26 -38
  233. data/yard-stubs/carray_cast.rb +121 -162
  234. data/yard-stubs/carray_class.rb +3 -4
  235. data/yard-stubs/carray_conversion.rb +6 -7
  236. data/yard-stubs/carray_copy.rb +2 -1
  237. data/yard-stubs/carray_count.rb +10 -5
  238. data/yard-stubs/carray_element.rb +4 -3
  239. data/yard-stubs/carray_limits.rb +100 -0
  240. data/yard-stubs/carray_loop.rb +0 -20
  241. data/yard-stubs/carray_mask.rb +59 -41
  242. data/yard-stubs/carray_math.rb +162 -100
  243. data/yard-stubs/carray_mathfunc.rb +415 -3
  244. data/yard-stubs/carray_median_percentile.rb +29 -11
  245. data/yard-stubs/carray_memory_view.rb +2 -2
  246. data/yard-stubs/carray_order.rb +72 -33
  247. data/yard-stubs/carray_random.rb +6 -6
  248. data/yard-stubs/carray_reduce.rb +353 -0
  249. data/yard-stubs/carray_rng.rb +92 -0
  250. data/yard-stubs/carray_scatter.rb +12 -3
  251. data/yard-stubs/carray_slab.rb +7 -4
  252. data/yard-stubs/carray_sort.rb +7 -6
  253. data/yard-stubs/carray_test.rb +18 -5
  254. data/yard-stubs/carray_undef.rb +44 -5
  255. data/yard-stubs/ruby_carray.rb +75 -40
  256. metadata +63 -25
  257. data/CHANGELOG.v1.md +0 -126
  258. data/ext/carray_build_flags.h +0 -3
  259. data/ext/carray_config.h +0 -28
  260. data/ext/carray_data_type.c +0 -90
  261. data/ext/carray_kernels_bincmp.c +0 -6457
  262. data/ext/carray_kernels_binop.c +0 -31534
  263. data/ext/carray_kernels_init.c +0 -1734
  264. data/ext/carray_kernels_moncmp.c +0 -2104
  265. data/ext/carray_kernels_monop.c +0 -25387
  266. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  267. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  268. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  269. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  270. data/ext/carray_kernels_reduce_variance.c +0 -5981
  271. data/ext/carray_kernels_scan.c +0 -4302
  272. data/ext/carray_kernels_search.c +0 -37776
  273. data/ext/carray_kernels_sort.c +0 -10814
  274. data/ext/carray_kernels_triop.c +0 -1864
  275. data/lib/carray/construct.rb +0 -360
  276. data/lib/carray/data_type_extension.rb +0 -261
  277. data/lib/carray/data_type_limits.rb +0 -91
data/ext/ca_obj_face.h CHANGED
@@ -1,19 +1,26 @@
1
1
  /* ---------------------------------------------------------------------------
2
2
 
3
- ca_obj_face.h
4
-
5
- Face mechanism — shared op helper signatures + lift/strip entry points.
6
-
7
- This header provides signatures for (1) shared op helpers (= thin-forward
8
- for storage ops, alias-based since Face is data-layout identical to
9
- parent), (2) `rb_ca_face_template` (struct duplicate + parent swap),
10
- (3) `ca_face_lift` (= wrap hook at the tail of user-facing access
11
- methods), (4) `ca_strip_face` (= Face-stripping helper for code that
12
- must see the storage).
13
-
14
- A Face is a "mask of a semantic type" (= identity layered on a storage
15
- type such as int64, with no value conversion), sibling to CAFake which
16
- was a "mask of data_type conversion".
3
+ ca_obj_face.h -- the Face authoring surface
4
+
5
+ A Face is a "mask of a semantic type": an identity layered on a storage
6
+ type such as int64, with no value conversion. An extension that defines
7
+ its own Face includes this header itself, after carray.h; carray.h does
8
+ not include it.
9
+
10
+ For extensions, and fixed for the rest of 3.x:
11
+ - the operation-table slots ca_face_attach / sync / detach / fill_* /
12
+ xfer_*, which forward to the parent
13
+ - the lift and strip parts: CA_FACE_LIFT_IF_FACE, ca_face_lift,
14
+ ca_strip_face, rb_ca_strip_face_value
15
+ - the hooks a Face registers (ca_face_register_storage_to_element /
16
+ _element_to_storage / _state_compatible / _state_portable, with their
17
+ *_fn types), and CA_FACE_STORAGE_TO_ELEMENT_IF_FACE with what it
18
+ expands to
19
+ - the ordering and search gate parts ca_face_require_orderable,
20
+ ca_face_orders_by_itself, ca_face_refuse_order and
21
+ ca_face_reconcile_operand
22
+ The Face parts that are carray's own are declared in carray_internal.h,
23
+ which is not installed.
17
24
 
18
25
  --------------------------------------------------------------------------- */
19
26
 
@@ -53,23 +60,11 @@ void ca_face_xfer_all (void *ap, void *data, int dir);
53
60
 
54
61
  /* -- lift / strip helpers -- */
55
62
 
56
- /* Struct duplicate + parent + shape swap. The primitive under
57
- ca_face_lift; also called directly where a result is re-wrapped under
58
- a Face without going through a view (partition, generated reduce). */
59
- VALUE rb_ca_face_template (VALUE original_face, CArray *new_parent,
60
- ca_size_t *new_dim);
61
-
62
63
  /* At the tail of view-creating methods, `if the receiver is a Face, wrap
63
64
  the result as a Face`. Reached through CA_FACE_LIFT_IF_FACE, which
64
65
  each view-creating method deploys at its return path. */
65
66
  VALUE ca_face_lift (VALUE view, VALUE face_parent);
66
67
 
67
- /* Lift a fresh array `result` (one a reduction, a scan or a partition built
68
- from the Face's storage) into the Face `face`: the same Face class over
69
- `result`, carrying the subclass tail, `result`'s mask and the state
70
- copy_state carries. `result` stays reachable through the new Face. */
71
- VALUE ca_face_relift_entity (VALUE face, VALUE result);
72
-
73
68
  /* Follow the Face flag down to the first non-Face parent, for code that
74
69
  must talk to the storage (store, mask, MemoryView export). The kernel
75
70
  iterator strips Faces at entry with its own loop, which also strips
@@ -82,32 +77,6 @@ CArray *ca_strip_face (CArray *src);
82
77
  root storage, not the Face surface. */
83
78
  VALUE rb_ca_strip_face_value (VALUE v);
84
79
 
85
- /* Face gate for the element-wise comparison operators (< <= > >=, eq, ne).
86
- When self is a Face over numeric storage, descends both operands to
87
- storage (ORDERABLE required) and reconciles a Face RHS via to_comparable;
88
- a fixlen-storage Face or a non-Face self is left untouched. Called from
89
- rb_ca_call_bincmp. See ca_obj_face.c for the full contract. */
90
- void ca_face_reconcile_comparison (volatile VALUE *pself,
91
- volatile VALUE *pother);
92
-
93
- /* CAFace abstract base class init (rev11 2026-06-10).
94
- Called from ruby_carray.c's Init after rb_cCAView is defined, before
95
- CATime / CATimedelta Init. */
96
- void Init_ca_face (void);
97
-
98
- /* -- R.5: composite Face data_class universal dispatch --
99
- Extern for direct C access from `rb_ca_data_class` (carray_attribute.c)
100
- into the CARecord tail. CA_OBJ_RECORD identifies the obj_type (assigned
101
- at runtime by ca_install_obj_type). To add a future composite Face,
102
- follow the same pattern: add an extern here and one line of case in the
103
- switch in carray_attribute.c. */
104
- extern int8_t CA_OBJ_RECORD;
105
- VALUE rb_ca_record_get_data_class (CArray *ca);
106
-
107
- /* CA_OBJ_STRING identifies CAString, read by the store path
108
- (carray_access.c) to send an array source through the write hook. */
109
- extern int8_t CA_OBJ_STRING;
110
-
111
80
  /* -- Convenience macro for view-creating method deployment --
112
81
  Insert at the tail of each view-creating Ruby method (= rb_ca_transpose
113
82
  / rb_ca_reshape / etc.) just before return. `ca` is self's CArray *,
@@ -119,39 +88,12 @@ extern int8_t CA_OBJ_STRING;
119
88
  } \
120
89
  } while (0)
121
90
 
122
- /* -- wrapper lift (Face or CALazyMarker) --
123
-
124
- A Face and a CALazyMarker are both storage-identical wrappers: they add
125
- an interpretation over their parent's bytes without changing them. Both
126
- want the same invariant at a view-creating method -- the wrapper stays on
127
- top, and the view is built against what the wrapper wraps. For a Face
128
- that keeps `dt.shift(1)` a CATime; for a marker it keeps a fuse block's
129
- expression lazy instead of dropping out of the chain.
130
-
131
- The flag test comes first and covers both bits in one mask, so an
132
- ordinary array leaves through a single AND. That matters: `[]` is the
133
- hottest method this is deployed on.
134
-
135
- NOT interchangeable with CA_FACE_LIFT_IF_FACE. Face is lifted at ~24
136
- sites, including ones a marker must not follow it through -- `copy` owns
137
- its data, `sort` reorders values, `value` and `strip_mask` change what
138
- the mask means. Deploy this only where the result is a view whose shape
139
- was fixed at construction and which only moves positions. */
140
- #define CA_WRAPPER_LIFT(obj, self, ca) do { \
141
- if ( ca_test_flag((ca), CA_FLAG_IS_FACE | CA_FLAG_IS_LAZY_MARKER) \
142
- && rb_obj_is_kind_of((obj), rb_cCArray) ) { \
143
- (obj) = ca_wrapper_lift((obj), (self), (ca)); \
144
- } \
145
- } while (0)
146
-
147
- VALUE ca_wrapper_lift (VALUE view, VALUE wrapper, void *wrapper_ca);
148
-
149
91
  /* -- Scalar fetch decode hook (storage -> surface) --
150
92
  On the scalar-return path (= tail of rb_ca_fetch_index /
151
93
  rb_ca_fetch_addr), if a Face-derived subclass defines a
152
94
  `storage_to_element(raw_value)` Ruby callback, invoke it. This is a
153
95
  decode (copy the storage value out and construct a new value object),
154
- not a wrap (a zero-copy lens over live memory). Its write-direction
96
+ not a wrap (a zero-copy view of live memory). Its write-direction
155
97
  counterpart is `element_to_storage` (below).
156
98
 
157
99
  Use cases:
@@ -180,7 +122,7 @@ typedef VALUE (*ca_face_storage_to_element_fn)(VALUE self, VALUE raw);
180
122
 
181
123
  extern ca_face_storage_to_element_fn ca_face_storage_to_element_table[];
182
124
 
183
- void ca_face_register_storage_to_element (int obj_type,
125
+ void ca_face_register_storage_to_element (int16_t obj_type,
184
126
  ca_face_storage_to_element_fn fn);
185
127
 
186
128
  /* -- Scalar store encode hook (surface -> storage), mirror of the decode --
@@ -194,44 +136,20 @@ void ca_face_register_storage_to_element (int obj_type,
194
136
  first, then the Ruby fallback. */
195
137
  typedef VALUE (*ca_face_element_to_storage_fn)(VALUE self, VALUE surface);
196
138
 
197
- extern ca_face_element_to_storage_fn ca_face_element_to_storage_table[];
198
-
199
- void ca_face_register_element_to_storage (int obj_type,
139
+ void ca_face_register_element_to_storage (int16_t obj_type,
200
140
  ca_face_element_to_storage_fn fn);
201
141
 
202
- /* Single source of truth for the surface -> storage-domain conversion.
203
- Returns `obj` unchanged when `ca` is not a Face or when no hook is
204
- registered / defined (so a bare Integer / String passes through to the
205
- existing storage cast). Otherwise returns the storage-domain value the
206
- Face produced. Called from rb_ca_obj2ptr (single-cell / fill / masked /
207
- range stores) and from the Array-of-scalars bulk store branch. */
208
- VALUE ca_face_element_to_storage (VALUE self, CArray *ca, VALUE obj);
209
-
210
- /* -- F.S0: Face state homogeneity check (= prerequisite for multi-Face APIs
211
- such as CAStack lift) --
142
+ /* -- Face state homogeneity check (what multi-Face operations such as
143
+ CAStack lift ask) --
212
144
  Per-obj_type C hook returning 1 if `a` and `b` (= both Face instances of
213
145
  the same obj_type) have compatible state (= same struct tail fields).
214
- Caller of `ca_face_state_compatible` guarantees both args are Face and
215
- have identical obj_type. */
146
+ carray calls it only with two Faces of the same obj_type. */
216
147
  typedef int (*ca_face_state_compatible_fn)(CArray *a, CArray *b);
217
148
 
218
- extern ca_face_state_compatible_fn ca_face_state_compatible_table[];
219
-
220
- void ca_face_register_state_compatible (int obj_type,
149
+ void ca_face_register_state_compatible (int16_t obj_type,
221
150
  ca_face_state_compatible_fn fn);
222
151
 
223
- /* Dispatch order:
224
- 1. C hook registered for a->obj_type → call hook, return its result
225
- 2. Else if the Ruby class of `va` defines `face_state_compatible?`
226
- on a Face subclass (= overrides CArray's default) → invoke with
227
- `vb`, return RTEST of result
228
- 3. Else → 1 (= default compatible, class identity only)
229
- Caller must pre-check a->obj_type == b->obj_type. `va` / `vb` are
230
- the Ruby VALUEs of the same instances (used only for the Ruby fallback
231
- path). */
232
- int ca_face_state_compatible (VALUE va, CArray *a, VALUE vb, CArray *b);
233
-
234
- /* -- F.S1: Face state portability (= class-level predicate) --
152
+ /* -- Face state portability (= class-level predicate) --
235
153
  Whether a Face class's state can be "moved" from one parent to
236
154
  another -- i.e., whether list[0]'s state can stand in for the result
237
155
  when a multi-parent operation (CAStack lift, compose family Face
@@ -247,46 +165,8 @@ int ca_face_state_compatible (VALUE va, CArray *a, VALUE vb, CArray *b);
247
165
  metadata-only Faces, including Ruby-implemented Faces that don't reach
248
166
  a C Init). Faces whose state holds per-parent storage MUST explicitly
249
167
  register 0 (= CAConstString). */
250
- extern int8_t ca_face_state_portable_table[];
251
-
252
- void ca_face_register_state_portable (int obj_type, int portable);
253
-
254
- /* Dispatch:
255
- 1. C table entry registered for obj_type → return that value
256
- 2. Else if the Ruby class `klass` defines a singleton method
257
- `face_state_portable?` (= subclass owns it) → invoke and RTEST
258
- 3. Else → 1 (= default portable)
259
- `klass` is the Ruby class of the Face instance (used for the Ruby
260
- fallback path). Pass Qnil when the class is unknown / unavailable
261
- (= falls through to default). */
262
- int ca_face_state_portable (int obj_type, VALUE klass);
263
-
264
- /* Check a list of arrays about to be combined into one (CAStack, CAMeld,
265
- promote_list). Returns the Face class every element shares, or Qnil
266
- when none of them is a Face; the combined array is then lifted into
267
- that class. Raises ArgumentError for a mix of Face and non-Face arrays
268
- or of two Face classes, for two or more of a Face whose state is not
269
- portable, and for elements whose state differs from the first one's.
270
- `who` names the caller at the head of the message. */
271
- VALUE ca_face_list_class (VALUE list, const char *who);
272
-
273
- /* A Face array's storage-side parent, one level down; any other array
274
- as it is. */
275
- VALUE ca_face_strip_one (VALUE v);
276
-
277
- /* Bring a Face *operand* into the reference's storage space, or refuse.
278
-
279
- The gate asks `fz_face_descend`'s question -- "is your storage your
280
- surface?" -- of the receiver, and for a long time asked nothing at all of
281
- the operand: a COMPARABLE receiver stripped any Face handed to it, and got
282
- back that Face's encoding rather than its values. Where the two encodings
283
- happened to be the same width the comparison then answered, wrongly and
284
- silently. Call this instead of stripping an operand by hand.
285
-
286
- A Face passes only if it declares COMPARABLE_STORAGE, i.e. its storage
287
- cells *are* the values it shows. Anything else -- a byte range, a code, a
288
- tick -- is refused rather than compared as bytes. Non-Face operands are
289
- returned untouched. `name` opens the message. */
168
+ void ca_face_register_state_portable (int16_t obj_type, int portable);
169
+
290
170
  /* Refuse to order (verb "order") or count by value (verb "count") a Face
291
171
  whose storage does not hold its values in order, naming the conversion. */
292
172
  NORETURN(void ca_face_refuse_order (const char *name, VALUE face,
@@ -303,20 +183,6 @@ void ca_face_require_orderable (VALUE face, const char *name,
303
183
  the storage. */
304
184
  int ca_face_orders_by_itself (VALUE face);
305
185
 
306
- /* The conversion a refusal of a Face whose cells encode its values points
307
- at (#to_string for a string Face, to_type(:object) for any other). */
308
- const char *ca_face_conversion_hint (VALUE face);
309
-
310
- /* The method that gives the storage under a Face (#ticks, #codes), or NULL
311
- when the Face has none of those. */
312
- const char *ca_face_storage_method (VALUE face);
313
-
314
- /* Raise eclass naming a Face that does not define the numeric operation
315
- `name`; returns when self is not a Face. See ca_obj_face.c. */
316
- void ca_face_refuse_numeric (VALUE self, const char *name, VALUE eclass);
317
-
318
- VALUE ca_face_operand_descend (VALUE operand, const char *name);
319
-
320
186
  /* Bring an operand into the storage space of a Face reference (a record's
321
187
  own data_class, a COMPARABLE Face's plain values, or the reference's
322
188
  to_comparable), refusing what the reference cannot read. See
@@ -324,10 +190,6 @@ VALUE ca_face_operand_descend (VALUE operand, const char *name);
324
190
  VALUE ca_face_reconcile_operand (VALUE reference, VALUE operand,
325
191
  const char *name);
326
192
 
327
- /* `==` (strict = 0) / `eql?` (strict = 1) when an operand is a Face other
328
- than a record array. See ca_obj_face.c. */
329
- int ca_face_equal (VALUE va, VALUE vb, int strict);
330
-
331
193
  /* The storage value of a cell read through a Face. A gated (CA_FIXLEN)
332
194
  surface over a numeric storage delivers the cell as its bytes; they are
333
195
  read back as the storage data_type (a boolean as true / false). A
@@ -348,7 +210,7 @@ VALUE ca_face_storage_value (CArray *ca, VALUE raw);
348
210
  static ID _id_storage_to_element = 0; \
349
211
  (obj) = ca_face_storage_value((ca), (obj)); \
350
212
  if ( _id_storage_to_element == 0 ) _id_storage_to_element = rb_intern("storage_to_element"); \
351
- if ( rb_respond_to((self), _id_storage_to_element) ) { \
213
+ if ( rb_obj_respond_to((self), _id_storage_to_element, Qtrue) ) { \
352
214
  (obj) = rb_funcall((self), _id_storage_to_element, 1, (obj)); \
353
215
  } \
354
216
  } \
data/ext/ca_obj_fake.c CHANGED
@@ -8,22 +8,12 @@
8
8
  ---------------------------------------------------------------------------- */
9
9
 
10
10
  #include "carray.h"
11
- #include "carray_internal.h" /* per-obj_type view constructors */
12
11
  #include "ca_iter_substrate.h" /* ca_xfer_stride_transform_fused */
13
12
 
14
13
  extern ca_operation_function_t ca_stride_func;
15
14
 
16
15
  typedef struct {
17
- int16_t obj_type;
18
- int8_t data_type;
19
- int8_t ndim;
20
- int32_t flags;
21
- ca_size_t bytes;
22
- ca_size_t elements;
23
- ca_size_t *dim;
24
- char *ptr;
25
- CArray *mask;
26
- char *_pool; /* framework-managed pool buffer (NULL = legacy ALLOC_N path). */
16
+ CA_ARRAY_HEADER
27
17
  CArray *parent;
28
18
  uint32_t attach;
29
19
  uint8_t nosync;
@@ -64,7 +54,7 @@ const rb_data_type_t cafake_data_type = {
64
54
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
65
55
  };
66
56
 
67
- static int8_t CA_OBJ_FAKE;
57
+ static int16_t CA_OBJ_FAKE;
68
58
 
69
59
  static VALUE rb_cCAFake;
70
60
 
@@ -78,8 +68,8 @@ ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, ca_size_t bytes)
78
68
 
79
69
  /* check arguments */
80
70
 
81
- CA_CHECK_DATA_TYPE_GIVEN(data_type);
82
- CA_CHECK_BYTES_GIVEN(data_type, bytes);
71
+ CA_CHECK_DATA_TYPE(data_type);
72
+ CA_CHECK_BYTES(data_type, bytes);
83
73
 
84
74
  /* ca == NULL asks for the checks above only, so that a constructor can
85
75
  run them before it allocates. */
@@ -154,6 +144,71 @@ ca_fake_func_clone (void *ap)
154
144
  return ca_fake_new(ca->parent, ca->data_type, ca->bytes);
155
145
  }
156
146
 
147
+ /* A read does not raise for a masked cell (ca_fake_cast_get), as attach
148
+ does not: the value under a mask is not defined, and converting it can
149
+ raise (NaN to an integer type). The view's cells are its parent's at the same
150
+ addresses, so the parent's mask is read for the same cells. The view's
151
+ own mask is not made here: once it exists, sync leaves masked cells
152
+ alone, and a read must not change what a later write does. */
153
+ static CArray *
154
+ ca_fake_read_mask (CAFake *ca)
155
+ {
156
+ if ( ca->mask ) {
157
+ return ca->mask;
158
+ }
159
+ if ( ca_has_mask(ca->parent) ) {
160
+ return ca->parent->mask;
161
+ }
162
+ return NULL;
163
+ }
164
+
165
+ /* Convert n cells read from the parent. A masked cell is converted as
166
+ well, so that the cell holds what the parent holds (a walk that sends
167
+ back only the cells a kernel changed compares against it), but a value
168
+ that cannot be converted (NaN to an integer) leaves zero bytes instead
169
+ of raising: the value under a mask is not defined. */
170
+ typedef struct {
171
+ CArray *src_ca, *dst_ca;
172
+ char *src, *dst;
173
+ } ca_fake_cell_ctx_t;
174
+
175
+ static VALUE
176
+ ca_fake_cast_cell (VALUE arg)
177
+ {
178
+ ca_fake_cell_ctx_t *c = (ca_fake_cell_ctx_t *) arg;
179
+ ca_ptr2ptr(c->src_ca, c->src, c->dst_ca, c->dst);
180
+ return Qnil;
181
+ }
182
+
183
+ static void
184
+ ca_fake_cast_get (CAFake *ca, ca_size_t n, char *src, char *dst, boolean8_t *m)
185
+ {
186
+ CArray *parent = ca->parent;
187
+ ca_size_t i;
188
+ if ( ! m ) {
189
+ ca_cast_block(n, parent, src, (CArray *) ca, dst);
190
+ return;
191
+ }
192
+ ca_cast_block_skip_masked(n, parent, src, (CArray *) ca, dst, m);
193
+ for ( i = 0; i < n; i++ ) {
194
+ if ( m[i] ) {
195
+ ca_fake_cell_ctx_t c;
196
+ int state = 0;
197
+ c.src_ca = parent;
198
+ c.dst_ca = (CArray *) ca;
199
+ c.src = src + i * parent->bytes;
200
+ c.dst = dst + i * ca->bytes;
201
+ /* A masked cell that cannot be converted reads as zero bytes. */
202
+ /* protect: converts a masked cell; nothing is held */
203
+ rb_protect(ca_fake_cast_cell, (VALUE) &c, &state);
204
+ if ( state ) {
205
+ rb_set_errinfo(Qnil);
206
+ memset(c.dst, 0, ca->bytes);
207
+ }
208
+ }
209
+ }
210
+ }
211
+
157
212
  /* Per-cell GET/PUT via a parent-sized scratch cell — same code services
158
213
  both directions, casting through the parent data_type. */
159
214
  static void
@@ -161,10 +216,16 @@ ca_fake_func_xfer_index (void *ap, ca_size_t *idx, void *data, int dir)
161
216
  {
162
217
  CAFake *ca = (CAFake *) ap;
163
218
  volatile VALUE holder;
164
- char *v = ALLOCV_N(char, holder, ca->parent->bytes);
219
+ char *v;
220
+ v = ALLOCV_N(char, holder, ca->parent->bytes);
165
221
  if ( dir == CA_XFER_GET ) {
222
+ CArray *mask = ca_fake_read_mask(ca);
223
+ boolean8_t masked = 0;
224
+ if ( mask ) {
225
+ ca_fetch_index(mask, idx, &masked);
226
+ }
166
227
  ca_fetch_index(ca->parent, idx, v);
167
- ca_ptr2ptr(ca->parent, v, ca, data);
228
+ ca_fake_cast_get(ca, 1, v, (char *) data, mask ? &masked : NULL);
168
229
  }
169
230
  else {
170
231
  ca_ptr2ptr(ca, data, ca->parent, v);
@@ -184,10 +245,22 @@ ca_fake_func_xfer_addrs (void *ap, ca_size_t n, ca_size_t *addrs,
184
245
  CAFake *ca = (CAFake *) ap;
185
246
  CArray *parent = ca->parent;
186
247
  CArray *eff;
248
+ CArray *mask = ( dir == CA_XFER_GET ) ? ca_fake_read_mask(ca) : NULL;
187
249
  ca_size_t base;
188
250
  char *v;
189
251
  volatile VALUE holder;
190
252
 
253
+ if ( mask ) {
254
+ volatile VALUE mholder;
255
+ boolean8_t *m = ALLOCV_N(boolean8_t, mholder, n + n * parent->bytes);
256
+ v = (char *) (m + n);
257
+ ca_xfer_addrs(mask, n, addrs, m, CA_XFER_GET);
258
+ ca_xfer_addrs(parent, n, addrs, v, CA_XFER_GET);
259
+ ca_fake_cast_get(ca, n, v, (char *) data, m);
260
+ ALLOCV_END(mholder);
261
+ return;
262
+ }
263
+
191
264
  /* Sequential-run + live-ptr fast path: cast directly from
192
265
  parent->ptr + base*pbytes to data, no intermediate scratch. */
193
266
  eff = ca_resolve_attached_root_via_identity(parent);
@@ -251,6 +324,24 @@ ca_fake_func_xfer_stride (void *ap, ca_size_t *starts, ca_size_t *counts,
251
324
  int8_t k;
252
325
  char *v;
253
326
  volatile VALUE holder;
327
+ CArray *mask = ( dir == CA_XFER_GET ) ? ca_fake_read_mask(ca) : NULL;
328
+
329
+ if ( mask ) {
330
+ ca_size_t mstrides[CA_RANK_MAX];
331
+ boolean8_t *m;
332
+ for ( k = 0; k < ndim; k++ ) {
333
+ n *= counts[k];
334
+ pstrides[k] = strides[k] / ca->bytes * ca->parent->bytes;
335
+ mstrides[k] = strides[k] / ca->bytes;
336
+ }
337
+ m = ALLOCV_N(boolean8_t, holder, n + n * ca->parent->bytes);
338
+ v = (char *) (m + n);
339
+ ca_xfer_stride(mask, starts, counts, mstrides, m, CA_XFER_GET);
340
+ ca_xfer_stride(ca->parent, starts, counts, pstrides, v, CA_XFER_GET);
341
+ ca_fake_cast_get(ca, n, v, (char *) data, m);
342
+ ALLOCV_END(holder);
343
+ return;
344
+ }
254
345
 
255
346
  /* Fast path: fused walk + cast for GET/PUT */
256
347
  if ( ca_xfer_stride_transform_fused((CArray *)ca, ca->parent,
@@ -282,21 +373,19 @@ static void
282
373
  ca_fake_func_allocate (void *ap)
283
374
  {
284
375
  CAFake *ca = (CAFake *) ap;
285
- ca_attach(ca->parent);
286
- ca->ptr = ca_alloc_cells((CArray *) ca);
376
+ ca->ptr = ca_alloc_cells_then_attach((CArray *) ca, 1, &ca->parent);
287
377
  }
288
378
 
289
379
  static void
290
380
  ca_fake_func_attach (void *ap)
291
381
  {
292
382
  CAFake *ca = (CAFake *) ap;
293
- ca_attach(ca->parent);
294
- ca->ptr = ca_alloc_cells((CArray *) ca);
383
+ ca->ptr = ca_alloc_cells_then_attach((CArray *) ca, 1, &ca->parent);
295
384
 
296
385
  if ( ca->parent->mask ) {
297
- ca_cast_block_with_mask(ca->elements, ca->parent, ca->parent->ptr,
298
- ca, ca->ptr,
299
- (boolean8_t*)ca->parent->mask->ptr);
386
+ ca_cast_block_skip_masked(ca->elements, ca->parent, ca->parent->ptr,
387
+ ca, ca->ptr,
388
+ (boolean8_t*)ca->parent->mask->ptr);
300
389
  }
301
390
  else {
302
391
  ca_cast_block(ca->elements, ca->parent, ca->parent->ptr, ca, ca->ptr);
@@ -309,8 +398,8 @@ ca_fake_func_sync (void *ap)
309
398
  CAFake *ca = (CAFake *) ap;
310
399
  ca_update_mask(ca);
311
400
  if ( ca->mask ) {
312
- ca_cast_block_with_mask(ca->elements, ca, ca->ptr, ca->parent, ca->parent->ptr,
313
- (boolean8_t *)ca->mask->ptr);
401
+ ca_cast_block_skip_masked(ca->elements, ca, ca->ptr, ca->parent, ca->parent->ptr,
402
+ (boolean8_t *)ca->mask->ptr);
314
403
  }
315
404
  else {
316
405
  ca_cast_block(ca->elements, ca, ca->ptr, ca->parent, ca->parent->ptr);
@@ -330,7 +419,7 @@ ca_fake_func_detach (void *ap)
330
419
  }
331
420
 
332
421
  /* Thin wrapper around xfer_stride that walks native row-major
333
- strides. xfer_stride itself picks the right rung via
422
+ strides. xfer_stride itself picks the right fast path via
334
423
  ca_xfer_stride_transform_fused:
335
424
  CAStride family parent fused walk + cast in one pass
336
425
  Non-CAStride parent with live ptr fused via linear stride math
@@ -412,13 +501,13 @@ ca_operation_function_t ca_fake_func = {
412
501
  /* ------------------------------------------------------------------- */
413
502
 
414
503
  VALUE
415
- rb_ca_fake_new (VALUE cary, int8_t data_type, ca_size_t bytes)
504
+ rb_ca_fake_new (volatile VALUE cary, int8_t data_type, ca_size_t bytes)
416
505
  {
417
506
  volatile VALUE obj;
418
507
  CArray *parent;
419
508
  CAFake *ca;
420
509
  rb_check_carray_object(cary);
421
- TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
510
+ GetCArray(cary, parent);
422
511
  if ( ca_is_face(parent) && ( data_type == CA_OBJECT
423
512
  || parent->data_type == CA_FIXLEN ) ) {
424
513
  /* A Face's cells do not mean their storage bytes, so reading them
@@ -426,9 +515,9 @@ rb_ca_fake_new (VALUE cary, int8_t data_type, ca_size_t bytes)
426
515
  Both ways down stay open and say which one they are. A Numeric Face
427
516
  is not one of these: its surface is its storage. */
428
517
  rb_raise(rb_eTypeError,
429
- "%s has no view of its values in another data_type: "
518
+ "%"PRIsVALUE" has no view of its values in another data_type: "
430
519
  "#to_type gives the values, #parent.fake the raw storage",
431
- rb_obj_classname(cary));
520
+ rb_obj_class(cary));
432
521
  }
433
522
  ca = ca_fake_new(parent, data_type, bytes);
434
523
  obj = ca_wrap_struct(ca);
@@ -442,12 +531,17 @@ rb_ca_fake_new (VALUE cary, int8_t data_type, ca_size_t bytes)
442
531
  VALUE
443
532
  rb_ca_fake (int argc, VALUE *argv, VALUE self)
444
533
  {
445
- volatile VALUE obj, rtype, ropt, rbytes = Qnil;
534
+ volatile VALUE obj;
535
+ VALUE rtype, ropt, rbytes = Qnil;
446
536
  int8_t data_type;
447
537
  ca_size_t bytes;
448
538
 
449
- rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
539
+ rb_scan_args(argc, argv, "11", &rtype, &ropt);
450
540
  rb_scan_options(ropt, "bytes", &rbytes);
541
+ ca_refuse_type_number(rtype);
542
+ if ( RTEST(rb_obj_is_data_class(rtype)) ) {
543
+ return ca_record_view_of(self, rtype, "fake");
544
+ }
451
545
 
452
546
  rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
453
547
  obj = rb_ca_fake_new(self, data_type, bytes);
@@ -474,7 +568,7 @@ rb_ca_fake_s_allocate (VALUE klass)
474
568
  }
475
569
 
476
570
  static VALUE
477
- rb_ca_fake_initialize_copy (VALUE self, VALUE other)
571
+ rb_ca_fake_initialize_copy (volatile VALUE self, volatile VALUE other)
478
572
  {
479
573
  CAFake *ca, *cs;
480
574
 
@@ -504,7 +598,6 @@ Init_ca_obj_fake (void)
504
598
  &cafake_data_type,
505
599
  rb_cCArrayMask,
506
600
  &carray_mask_data_type, &ca_fake_func, sizeof(ca_fake_func));
507
- rb_define_const(rb_cObject, "CA_OBJ_FAKE", INT2NUM(CA_OBJ_FAKE));
508
601
 
509
602
  rb_define_method(rb_cCArray, "fake", rb_ca_fake, -1);
510
603
 
data/ext/ca_obj_farray.c CHANGED
@@ -7,11 +7,11 @@
7
7
  ---------------------------------------------------------------------------- */
8
8
 
9
9
  #include "carray.h"
10
- #include "carray_internal.h" /* ca_view_inherit_mask */
10
+ #include "ca_obj_face.h" /* CA_WRAPPER_LIFT */
11
11
 
12
12
  extern ca_operation_function_t ca_stride_func;
13
13
 
14
- static int8_t CA_OBJ_FARRAY;
14
+ static int16_t CA_OBJ_FARRAY;
15
15
 
16
16
  VALUE rb_cCAFarray;
17
17
  VALUE rb_cCAFarrayMask;
@@ -70,13 +70,13 @@ ca_farray_new (CArray *parent)
70
70
  /* ------------------------------------------------------------------- */
71
71
 
72
72
  VALUE
73
- rb_ca_farray_new (VALUE cary)
73
+ rb_ca_farray_new (volatile VALUE cary)
74
74
  {
75
75
  volatile VALUE obj;
76
76
  CArray *parent;
77
77
  CAStride *ca;
78
78
  rb_check_carray_object(cary);
79
- TypedData_Get_Struct(cary, CArray, &carray_data_type, parent);
79
+ GetCArray(cary, parent);
80
80
  ca = ca_farray_new(parent);
81
81
  obj = ca_wrap_struct(ca);
82
82
  rb_ca_set_parent(obj, cary);
@@ -85,13 +85,18 @@ rb_ca_farray_new (VALUE cary)
85
85
 
86
86
  /* CArray#farray -- column-major view (dimension order reversed). */
87
87
  VALUE
88
- rb_ca_farray (VALUE self)
88
+ rb_ca_farray (volatile VALUE self)
89
89
  {
90
- return rb_ca_farray_new(self);
90
+ volatile VALUE obj = rb_ca_farray_new(self);
91
+ CArray *ca;
92
+
93
+ GetCArray(self, ca);
94
+ CA_WRAPPER_LIFT(obj, self, ca);
95
+ return obj;
91
96
  }
92
97
 
93
98
  static VALUE
94
- rb_ca_farray_initialize_copy (VALUE self, VALUE other)
99
+ rb_ca_farray_initialize_copy (volatile VALUE self, volatile VALUE other)
95
100
  {
96
101
  CAStride *ca, *cs;
97
102
  TypedData_Get_Struct(self, CAStride, &castride_data_type, ca);
@@ -110,14 +115,13 @@ void
110
115
  Init_ca_obj_farray (void)
111
116
  {
112
117
  rb_cCAFarray = rb_define_class("CAFarray", rb_cCAStride);
113
- rb_cCAFarrayMask = rb_define_class("CAFarrayMask", rb_cCAFarray);
118
+ rb_cCAFarrayMask = rb_define_class_under(rb_cCAFarray, "Mask", rb_cCAFarray);
114
119
 
115
120
  CA_OBJ_FARRAY = ca_install_obj_type(rb_cCAFarray,
116
121
  &castride_data_type,
117
122
  rb_cCAFarrayMask,
118
123
  &castride_mask_data_type,
119
124
  &ca_stride_func, sizeof(ca_stride_func));
120
- rb_define_const(rb_cObject, "CA_OBJ_FARRAY", INT2NUM(CA_OBJ_FARRAY));
121
125
 
122
126
  rb_define_method(rb_cCArray, "farray", rb_ca_farray, 0);
123
127