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.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +7 -1940
  4. data/README.md +38 -32
  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 +6 -9
  11. data/ext/ca_bincmp_dispatch.h +16 -38
  12. data/ext/ca_binop_dispatch.c +27 -0
  13. data/ext/ca_binop_dispatch.h +22 -47
  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 -1506
  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 +90 -163
  28. data/ext/ca_obj_bincmp.c +47 -46
  29. data/ext/ca_obj_binop.c +38 -38
  30. data/ext/ca_obj_bitarray.c +5 -17
  31. data/ext/ca_obj_bitfield.c +15 -30
  32. data/ext/ca_obj_block.c +11 -12
  33. data/ext/ca_obj_byte_swap.c +32 -30
  34. data/ext/ca_obj_const_string.c +57 -62
  35. data/ext/ca_obj_face.c +99 -91
  36. data/ext/ca_obj_face.h +32 -170
  37. data/ext/ca_obj_fake.c +15 -21
  38. data/ext/ca_obj_farray.c +7 -9
  39. data/ext/ca_obj_field.c +17 -13
  40. data/ext/ca_obj_fixlen_string.c +8 -19
  41. data/ext/ca_obj_grid.c +137 -106
  42. data/ext/ca_obj_meld.c +23 -21
  43. data/ext/ca_obj_moncmp.c +10 -21
  44. data/ext/ca_obj_monop.c +24 -35
  45. data/ext/ca_obj_object.c +51 -37
  46. data/ext/ca_obj_record.c +74 -22
  47. data/ext/ca_obj_reduce.c +8 -10
  48. data/ext/ca_obj_refer.c +42 -29
  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 +18 -24
  52. data/ext/ca_obj_select.c +10 -22
  53. data/ext/ca_obj_select_axis.c +27 -36
  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 +28 -24
  57. data/ext/ca_obj_stride.c +53 -54
  58. data/ext/ca_obj_string.c +6 -18
  59. data/ext/ca_obj_tile.c +12 -12
  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 +35 -39
  64. data/ext/ca_obj_window.c +67 -86
  65. data/ext/ca_op_cmplx64.h +4 -0
  66. data/ext/ca_op_ipower.c +34 -12
  67. data/ext/ca_op_powi.h +4 -0
  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 +20 -26
  72. data/ext/ca_sweep_engine.c +2 -3
  73. data/ext/ca_sweep_engine.h +17 -9
  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 +11 -11
  77. data/ext/carray.h +300 -1011
  78. data/ext/carray_access.c +234 -180
  79. data/ext/carray_address_basis.c +33 -38
  80. data/ext/carray_attribute.c +81 -104
  81. data/ext/carray_bincount.c +12 -14
  82. data/ext/carray_broadcast.c +30 -26
  83. data/ext/carray_call_cfunc.c +169 -277
  84. data/ext/carray_call_cfunc.h +36 -28
  85. data/ext/carray_cast.c +912 -346
  86. data/ext/carray_cast_func.rb +31 -3
  87. data/ext/carray_class.c +6 -11
  88. data/ext/carray_conversion.c +43 -38
  89. data/ext/carray_copy.c +28 -26
  90. data/ext/carray_core.c +217 -126
  91. data/ext/carray_count.c +27 -15
  92. data/ext/carray_element.c +40 -25
  93. data/ext/carray_factorize.c +53 -52
  94. data/ext/carray_generate.c +26 -19
  95. data/ext/carray_histogram.c +8 -10
  96. data/ext/carray_hold.c +7 -9
  97. data/ext/carray_index_classifier.c +123 -228
  98. data/ext/carray_index_classifier.h +11 -10
  99. data/ext/carray_integer_total.c +523 -0
  100. data/ext/carray_internal.h +1274 -160
  101. data/ext/carray_key_windows.c +3 -3
  102. data/ext/carray_lazy.c +21 -36
  103. data/ext/carray_loop.c +19 -22
  104. data/ext/carray_mask.c +123 -145
  105. data/ext/carray_math_kernel.h +23 -47
  106. data/ext/carray_mathfunc.c +10 -3
  107. data/ext/carray_median_percentile.c +95 -94
  108. data/ext/carray_memory_view.c +42 -47
  109. data/ext/carray_operator.c +423 -122
  110. data/ext/carray_order.c +121 -85
  111. data/ext/carray_partition.c +13 -15
  112. data/ext/carray_random.c +47 -41
  113. data/ext/carray_round.c +9 -4
  114. data/ext/carray_scatter.c +54 -40
  115. data/ext/carray_segment.c +41 -45
  116. data/ext/carray_slab.c +64 -47
  117. data/ext/carray_slab.h +44 -33
  118. data/ext/carray_sort.c +32 -29
  119. data/ext/carray_sort_kernel.c +12 -10
  120. data/ext/carray_struct.c +38 -43
  121. data/ext/carray_test.c +47 -43
  122. data/ext/carray_time_text.c +24 -31
  123. data/ext/carray_undef.c +50 -7
  124. data/ext/carray_utils.c +258 -94
  125. data/ext/extconf.rb +24 -17
  126. data/ext/mk_call_cfunc.rb +19 -20
  127. data/ext/mk_pow5_table.rb +2 -1
  128. data/ext/mkkernel.rb +782 -461
  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 +264 -180
  135. data/lib/carray/basics.rb +272 -48
  136. data/lib/carray/bincount_nd.rb +33 -16
  137. data/lib/carray/block_iterator.rb +123 -102
  138. data/lib/carray/boolean_reduce.rb +7 -4
  139. data/lib/carray/categorical.rb +63 -51
  140. data/lib/carray/categorical_iterator.rb +89 -67
  141. data/lib/carray/complex.rb +61 -41
  142. data/lib/carray/conditional.rb +49 -22
  143. data/lib/carray/const_string.rb +54 -62
  144. data/lib/carray/core_extensions.rb +1 -1
  145. data/lib/carray/distance_limit.rb +7 -5
  146. data/lib/carray/factories.rb +269 -0
  147. data/lib/carray/fixlen_string.rb +25 -24
  148. data/lib/carray/frame/column_verbs.rb +20 -8
  149. data/lib/carray/frame/concat.rb +3 -3
  150. data/lib/carray/frame/convert.rb +2 -1
  151. data/lib/carray/frame/csv_parser.rb +7 -1
  152. data/lib/carray/frame/frame.rb +35 -25
  153. data/lib/carray/frame/group.rb +183 -150
  154. data/lib/carray/frame/io.rb +26 -7
  155. data/lib/carray/frame/join.rb +37 -12
  156. data/lib/carray/frame/records.rb +1 -1
  157. data/lib/carray/frame/reshape.rb +3 -3
  158. data/lib/carray/frame/sort.rb +10 -8
  159. data/lib/carray/frame/verbs.rb +148 -118
  160. data/lib/carray/frame/windows.rb +232 -21
  161. data/lib/carray/frame.rb +1 -2
  162. data/lib/carray/fuse_source.rb +24 -21
  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 +97 -24
  167. data/lib/carray/key_windows.rb +83 -57
  168. data/lib/carray/lazy.rb +196 -94
  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 +5 -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 +72 -71
  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/gather_nd.rb +106 -106
  183. data/lib/carray/methods/insert_block.rb +2 -2
  184. data/lib/carray/methods/is_between.rb +6 -4
  185. data/lib/carray/methods/is_in.rb +165 -145
  186. data/lib/carray/methods/join.rb +2 -1
  187. data/lib/carray/methods/lag.rb +6 -2
  188. data/lib/carray/methods/locate_addr.rb +150 -138
  189. data/lib/carray/methods/mask_duplicates.rb +1 -1
  190. data/lib/carray/methods/meshgrid.rb +28 -16
  191. data/lib/carray/methods/mode.rb +67 -67
  192. data/lib/carray/methods/nunique.rb +9 -7
  193. data/lib/carray/methods/repeat.rb +12 -12
  194. data/lib/carray/methods/resize.rb +1 -1
  195. data/lib/carray/methods/snap.rb +24 -20
  196. data/lib/carray/methods/string_format.rb +2 -2
  197. data/lib/carray/methods/unique.rb +4 -2
  198. data/lib/carray/methods/value_counts.rb +1 -1
  199. data/lib/carray/mkmf.rb +25 -28
  200. data/lib/carray/percentile_arguments.rb +82 -0
  201. data/lib/carray/record_order.rb +18 -17
  202. data/lib/carray/rng.rb +1 -0
  203. data/lib/carray/runtime.rb +190 -22
  204. data/lib/carray/segment_iterator.rb +251 -129
  205. data/lib/carray/serialize.rb +618 -571
  206. data/lib/carray/slab_iterator.rb +114 -114
  207. data/lib/carray/stack.rb +11 -12
  208. data/lib/carray/string.rb +16 -22
  209. data/lib/carray/string_operation_extension.rb +76 -52
  210. data/lib/carray/struct.rb +122 -164
  211. data/lib/carray/struct_builder.rb +243 -72
  212. data/lib/carray/time.rb +496 -342
  213. data/lib/carray/window_iterator.rb +191 -150
  214. data/lib/carray.rb +6 -11
  215. data/yard-stubs/ca_obj_array.rb +20 -135
  216. data/yard-stubs/ca_obj_bitarray.rb +1 -8
  217. data/yard-stubs/ca_obj_bitfield.rb +4 -3
  218. data/yard-stubs/ca_obj_byte_swap.rb +21 -7
  219. data/yard-stubs/ca_obj_fake.rb +3 -1
  220. data/yard-stubs/ca_obj_farray.rb +1 -1
  221. data/yard-stubs/ca_obj_field.rb +8 -6
  222. data/yard-stubs/ca_obj_refer.rb +7 -5
  223. data/yard-stubs/ca_obj_roll.rb +7 -6
  224. data/yard-stubs/ca_obj_shift.rb +2 -3
  225. data/yard-stubs/ca_obj_stride.rb +5 -7
  226. data/yard-stubs/ca_obj_tile.rb +1 -1
  227. data/yard-stubs/ca_obj_time.rb +43 -0
  228. data/yard-stubs/ca_obj_transpose.rb +1 -1
  229. data/yard-stubs/ca_obj_window.rb +26 -15
  230. data/yard-stubs/carray_access.rb +51 -4
  231. data/yard-stubs/carray_attribute.rb +26 -38
  232. data/yard-stubs/carray_cast.rb +118 -165
  233. data/yard-stubs/carray_class.rb +3 -4
  234. data/yard-stubs/carray_conversion.rb +6 -7
  235. data/yard-stubs/carray_copy.rb +2 -1
  236. data/yard-stubs/carray_count.rb +5 -3
  237. data/yard-stubs/carray_element.rb +4 -3
  238. data/yard-stubs/carray_limits.rb +100 -0
  239. data/yard-stubs/carray_loop.rb +0 -20
  240. data/yard-stubs/carray_mask.rb +59 -41
  241. data/yard-stubs/carray_math.rb +157 -100
  242. data/yard-stubs/carray_mathfunc.rb +415 -3
  243. data/yard-stubs/carray_median_percentile.rb +29 -11
  244. data/yard-stubs/carray_memory_view.rb +2 -2
  245. data/yard-stubs/carray_order.rb +67 -34
  246. data/yard-stubs/carray_random.rb +6 -6
  247. data/yard-stubs/carray_reduce.rb +353 -0
  248. data/yard-stubs/carray_rng.rb +92 -0
  249. data/yard-stubs/carray_scatter.rb +10 -2
  250. data/yard-stubs/carray_slab.rb +7 -4
  251. data/yard-stubs/carray_sort.rb +7 -6
  252. data/yard-stubs/carray_undef.rb +44 -5
  253. data/yard-stubs/ruby_carray.rb +75 -40
  254. metadata +62 -24
  255. data/CHANGELOG.v1.md +0 -126
  256. data/ext/carray_build_flags.h +0 -3
  257. data/ext/carray_config.h +0 -28
  258. data/ext/carray_data_type.c +0 -90
  259. data/ext/carray_kernels_bincmp.c +0 -6457
  260. data/ext/carray_kernels_binop.c +0 -31534
  261. data/ext/carray_kernels_init.c +0 -1734
  262. data/ext/carray_kernels_moncmp.c +0 -2104
  263. data/ext/carray_kernels_monop.c +0 -25337
  264. data/ext/carray_kernels_reduce_aggregate.c +0 -27545
  265. data/ext/carray_kernels_reduce_boolean.c +0 -1924
  266. data/ext/carray_kernels_reduce_cumulative.c +0 -11646
  267. data/ext/carray_kernels_reduce_extreme.c +0 -21631
  268. data/ext/carray_kernels_reduce_variance.c +0 -5981
  269. data/ext/carray_kernels_scan.c +0 -4302
  270. data/ext/carray_kernels_search.c +0 -37776
  271. data/ext/carray_kernels_sort.c +0 -10814
  272. data/ext/carray_kernels_triop.c +0 -1864
  273. data/lib/carray/construct.rb +0 -360
  274. data/lib/carray/data_type_extension.rb +0 -262
  275. data/lib/carray/data_type_limits.rb +0 -91
data/ext/ca_obj_face.c CHANGED
@@ -30,7 +30,6 @@
30
30
  #include "ruby.h"
31
31
  #include "carray.h"
32
32
  #include "ca_obj_face.h"
33
- #include "carray_internal.h"
34
33
 
35
34
  /* ---- shared op helpers (thin-forward) ---- */
36
35
 
@@ -39,7 +38,7 @@ ca_face_attach (void *ap)
39
38
  {
40
39
  CAView *cav = (CAView *) ap;
41
40
  CArray *ca = (CArray *) ap;
42
- ca_attach(cav->parent); /* window: a Face's attach slot; its detach slot releases */
41
+ ca_attach(cav->parent); /* attach: a Face's attach slot; its detach slot releases */
43
42
  /* alias parent->ptr (Face has identical data layout, so copy is unneeded) */
44
43
  ca->ptr = cav->parent->ptr;
45
44
  }
@@ -122,7 +121,7 @@ ca_face_xfer_all (void *ap, void *data, int dir)
122
121
  *
123
122
  * Called from ca_face_lift and from subclass lift / clone / dup paths. */
124
123
  VALUE
125
- rb_ca_face_template (VALUE original_face, CArray *new_parent,
124
+ rb_ca_face_template (volatile VALUE original_face, CArray *new_parent,
126
125
  ca_size_t *new_dim)
127
126
  {
128
127
  CArray *src;
@@ -131,7 +130,7 @@ rb_ca_face_template (VALUE original_face, CArray *new_parent,
131
130
  size_t size;
132
131
  const rb_data_type_t *tdata;
133
132
 
134
- TypedData_Get_Struct(original_face, CArray, &carray_data_type, src);
133
+ GetCArray(original_face, src);
135
134
  tdata = ca_typeddata[src->obj_type];
136
135
 
137
136
  /* The struct with its subclass tail. struct_size is the struct alone;
@@ -194,7 +193,7 @@ static void
194
193
  ca_face_fresh_entity_is_writable (volatile VALUE lifted, VALUE face)
195
194
  {
196
195
  CArray *lc;
197
- TypedData_Get_Struct(lifted, CArray, &carray_data_type, lc);
196
+ GetCArray(lifted, lc);
198
197
  if ( ca_test_flag(lc, CA_FLAG_READ_ONLY)
199
198
  && RTEST(rb_funcall(face, rb_intern("holds_new_values?"), 0)) ) {
200
199
  ca_unset_flag(lc, CA_FLAG_READ_ONLY);
@@ -206,18 +205,18 @@ ca_face_relift_entity (VALUE face, volatile VALUE result)
206
205
  {
207
206
  static ID id_copy_state = 0;
208
207
  CArray *rc, *lc;
209
- VALUE lifted;
208
+ volatile VALUE lifted;
210
209
  if ( id_copy_state == 0 ) id_copy_state = rb_intern("copy_state");
211
- TypedData_Get_Struct(result, CArray, &carray_data_type, rc);
210
+ GetCArray(result, rc);
212
211
  lifted = rb_ca_face_template(face, rc, rc->dim);
213
212
  rb_ca_set_parent(lifted, result);
214
213
  ca_face_fresh_entity_is_writable(lifted, face);
215
214
  if ( ca_has_mask(rc) ) {
216
215
  /* The template starts without a mask. */
217
- TypedData_Get_Struct(lifted, CArray, &carray_data_type, lc);
216
+ GetCArray(lifted, lc);
218
217
  ca_copy_mask(lc, rc);
219
218
  }
220
- if ( rb_respond_to(face, id_copy_state) ) {
219
+ if ( rb_obj_respond_to(face, id_copy_state, Qtrue) ) {
221
220
  rb_funcall(lifted, id_copy_state, 1, face);
222
221
  }
223
222
  return lifted;
@@ -248,14 +247,14 @@ ca_lift_move_mask_down (CArray *view_ca, CArray *wp)
248
247
  * Caller (rb_ca_aref / rb_ca_store) must have already checked that
249
248
  * face_parent carries the CA_FLAG_IS_FACE flag. */
250
249
  VALUE
251
- ca_face_lift (VALUE view, VALUE face_parent)
250
+ ca_face_lift (volatile VALUE view, volatile VALUE face_parent)
252
251
  {
253
252
  CArray *view_ca;
254
- VALUE lifted;
253
+ volatile VALUE lifted;
255
254
  static ID id_copy_state = 0;
256
255
  if ( id_copy_state == 0 ) id_copy_state = rb_intern("copy_state");
257
256
 
258
- TypedData_Get_Struct(view, CArray, &carray_data_type, view_ca);
257
+ GetCArray(view, view_ca);
259
258
 
260
259
  /* Idempotent lift: if the view is already a Face of the same class as
261
260
  face_parent, it has already been lifted — a builder that lifts internally
@@ -277,7 +276,7 @@ ca_face_lift (VALUE view, VALUE face_parent)
277
276
  presents the surface. */
278
277
  {
279
278
  CArray *fp, *p;
280
- TypedData_Get_Struct(face_parent, CArray, &carray_data_type, fp);
279
+ GetCArray(face_parent, fp);
281
280
  p = fp;
282
281
  while (p && ca_is_face(p)) {
283
282
  p = ((CAView *) p)->parent;
@@ -328,12 +327,12 @@ ca_face_lift (VALUE view, VALUE face_parent)
328
327
  etc.) auto-carry via the template memcpy; Faces holding state in
329
328
  Ruby ivars (Ruby-implemented CAObject-derived Faces etc.) should
330
329
  override copy_state to copy them. */
331
- if ( rb_respond_to(face_parent, id_copy_state) ) {
330
+ if ( rb_obj_respond_to(face_parent, id_copy_state, Qtrue) ) {
332
331
  rb_funcall(lifted, id_copy_state, 1, face_parent);
333
332
  }
334
333
 
335
334
  #ifdef CARRAY_DEV_BUILD
336
- /* Soundness tripwire (docs/internal/FaceLiftSoundness.md §0/§7): after a lift the view
335
+ /* Soundness check (docs/internal/FaceLiftSoundness.md §0/§7): after a lift the view
337
336
  node under the new Face must not point back at the Face we lifted from —
338
337
  the §8.3 one-level swap must have moved it exactly one level, so a
339
338
  redundant middle Face is structurally caught here, wherever it enters.
@@ -343,9 +342,9 @@ ca_face_lift (VALUE view, VALUE face_parent)
343
342
  ->parent (slot 0) is storage; this checks that slot. */
344
343
  {
345
344
  CArray *lifted_ca, *lp, *fps;
346
- TypedData_Get_Struct(lifted, CArray, &carray_data_type, lifted_ca);
345
+ GetCArray(lifted, lifted_ca);
347
346
  lp = CAVIEW(lifted_ca)->parent;
348
- TypedData_Get_Struct(face_parent, CArray, &carray_data_type, fps);
347
+ GetCArray(face_parent, fps);
349
348
  if ( lp && ca_is_view(lp) ) {
350
349
  if ( CAVIEW(lp)->parent == fps ) {
351
350
  rb_bug("ca_face_lift: §8.3 one-level swap did not fire — redundant "
@@ -376,12 +375,12 @@ ca_face_lift (VALUE view, VALUE face_parent)
376
375
  * builder handed us a view whose parent is the marker, and leaving it
377
376
  * there would stack a redundant marker in the middle. */
378
377
  static VALUE
379
- ca_lazy_marker_lift (VALUE view, volatile VALUE marker)
378
+ ca_lazy_marker_lift (volatile VALUE view, volatile VALUE marker)
380
379
  {
381
380
  CArray *view_ca, *mp;
382
381
  extern VALUE rb_ca_lazy_marker_new (VALUE cary);
383
382
 
384
- TypedData_Get_Struct(view, CArray, &carray_data_type, view_ca);
383
+ GetCArray(view, view_ca);
385
384
 
386
385
  /* Idempotent: a builder that wrapped internally already returned a
387
386
  marker (mirrors the same guard in ca_face_lift). */
@@ -389,7 +388,7 @@ ca_lazy_marker_lift (VALUE view, volatile VALUE marker)
389
388
  return view;
390
389
  }
391
390
 
392
- TypedData_Get_Struct(marker, CArray, &carray_data_type, mp);
391
+ GetCArray(marker, mp);
393
392
 
394
393
  /* One-level swap (CAFace.md section 8.3, same reasoning): move the view
395
394
  off the marker and onto what the marker wraps. Guarded on pointer
@@ -409,13 +408,13 @@ ca_lazy_marker_lift (VALUE view, volatile VALUE marker)
409
408
  * CA_WRAPPER_LIFT. The macro has already established that wrapper_ca
410
409
  * carries one of the two flags and that view is a CArray. */
411
410
  VALUE
412
- ca_wrapper_lift (VALUE view, VALUE wrapper, void *wrapper_ca)
411
+ ca_wrapper_lift (volatile VALUE view, VALUE wrapper, void *wrapper_ca)
413
412
  {
414
413
  CArray *ca = (CArray *) wrapper_ca;
415
414
 
416
415
  if ( ca_is_face(ca) ) {
417
416
  CArray *view_ca;
418
- TypedData_Get_Struct(view, CArray, &carray_data_type, view_ca);
417
+ GetCArray(view, view_ca);
419
418
  /* Some builders (select / repeat / ...) lift their own result; a
420
419
  second lift here would double-wrap. Mirrors the guard the `[]`
421
420
  call site used to carry inline. */
@@ -451,14 +450,14 @@ ca_strip_face (CArray *src)
451
450
  * result into a Face wrapper (index / addr / linear outputs are not
452
451
  * Face-semantic). Complements ca_strip_face on the C-struct axis. */
453
452
  VALUE
454
- rb_ca_strip_face_value (VALUE v)
453
+ rb_ca_strip_face_value (volatile VALUE v)
455
454
  {
456
455
  CArray *ca;
457
456
  if ( ! rb_obj_is_kind_of(v, rb_cCArray) ) return v;
458
- TypedData_Get_Struct(v, CArray, &carray_data_type, ca);
457
+ GetCArray(v, ca);
459
458
  while ( ca_is_face(ca) ) {
460
459
  v = rb_ca_parent(v);
461
- TypedData_Get_Struct(v, CArray, &carray_data_type, ca);
460
+ GetCArray(v, ca);
462
461
  }
463
462
  return v;
464
463
  }
@@ -498,7 +497,7 @@ rb_ca_face_s_allocate_forbidden (VALUE klass)
498
497
  }
499
498
 
500
499
  VALUE
501
- ca_face_storage_value (CArray *ca, VALUE raw)
500
+ ca_face_storage_value (CArray *ca, volatile VALUE raw)
502
501
  {
503
502
  CArray *storage;
504
503
  CArray as_storage;
@@ -528,7 +527,7 @@ ca_face_storage_value (CArray *ca, VALUE raw)
528
527
  ca_face_storage_to_element_fn ca_face_storage_to_element_table[CA_OBJ_TYPE_MAX];
529
528
 
530
529
  void
531
- ca_face_register_storage_to_element (int obj_type, ca_face_storage_to_element_fn fn)
530
+ ca_face_register_storage_to_element (int16_t obj_type, ca_face_storage_to_element_fn fn)
532
531
  {
533
532
  if ( obj_type < 0 || obj_type >= CA_OBJ_TYPE_MAX ) {
534
533
  rb_raise(rb_eArgError,
@@ -545,7 +544,7 @@ ca_face_register_storage_to_element (int obj_type, ca_face_storage_to_element_fn
545
544
  ca_face_element_to_storage_fn ca_face_element_to_storage_table[CA_OBJ_TYPE_MAX];
546
545
 
547
546
  void
548
- ca_face_register_element_to_storage (int obj_type, ca_face_element_to_storage_fn fn)
547
+ ca_face_register_element_to_storage (int16_t obj_type, ca_face_element_to_storage_fn fn)
549
548
  {
550
549
  if ( obj_type < 0 || obj_type >= CA_OBJ_TYPE_MAX ) {
551
550
  rb_raise(rb_eArgError,
@@ -560,7 +559,7 @@ ca_face_register_element_to_storage (int obj_type, ca_face_element_to_storage_fn
560
559
  ca_face_state_compatible_fn ca_face_state_compatible_table[CA_OBJ_TYPE_MAX];
561
560
 
562
561
  void
563
- ca_face_register_state_compatible (int obj_type, ca_face_state_compatible_fn fn)
562
+ ca_face_register_state_compatible (int16_t obj_type, ca_face_state_compatible_fn fn)
564
563
  {
565
564
  if ( obj_type < 0 || obj_type >= CA_OBJ_TYPE_MAX ) {
566
565
  rb_raise(rb_eArgError,
@@ -601,7 +600,7 @@ ca_face_state_compatible (VALUE va, CArray *a, VALUE vb, CArray *b)
601
600
 
602
601
  /* Ruby-side: CArray#face_state_compatible?(other) */
603
602
  static VALUE
604
- rb_ca_face_state_compatible_p (VALUE self, VALUE other)
603
+ rb_ca_face_state_compatible_p (volatile VALUE self, volatile VALUE other)
605
604
  {
606
605
  CArray *a, *b;
607
606
 
@@ -609,8 +608,8 @@ rb_ca_face_state_compatible_p (VALUE self, VALUE other)
609
608
  rb_raise(rb_eArgError,
610
609
  "face_state_compatible?: argument must be a CArray");
611
610
  }
612
- TypedData_Get_Struct(self, CArray, &carray_data_type, a);
613
- TypedData_Get_Struct(other, CArray, &carray_data_type, b);
611
+ GetCArray(self, a);
612
+ GetCArray(other, b);
614
613
  if ( ! ca_is_face(a) || ! ca_is_face(b) ) {
615
614
  rb_raise(rb_eArgError,
616
615
  "face_state_compatible?: both receiver and argument must be Face");
@@ -631,7 +630,7 @@ rb_ca_face_state_compatible_p (VALUE self, VALUE other)
631
630
  static int8_t ca_face_memory_view_table[CA_OBJ_TYPE_MAX];
632
631
 
633
632
  void
634
- ca_face_register_memory_view (int obj_type, int exportable)
633
+ ca_face_register_memory_view (int16_t obj_type, int exportable)
635
634
  {
636
635
  if ( obj_type < 0 || obj_type >= CA_OBJ_TYPE_MAX ) {
637
636
  rb_raise(rb_eArgError,
@@ -671,7 +670,7 @@ rb_ca_s_face_state_portable_false (VALUE klass)
671
670
  }
672
671
 
673
672
  void
674
- ca_face_register_state_portable (int obj_type, int portable)
673
+ ca_face_register_state_portable (int16_t obj_type, int portable)
675
674
  {
676
675
  if ( obj_type < 0 || obj_type >= CA_OBJ_TYPE_MAX ) {
677
676
  rb_raise(rb_eArgError,
@@ -685,7 +684,7 @@ ca_face_register_state_portable (int obj_type, int portable)
685
684
  ca_install_obj_type before this call — Faces register from
686
685
  within their Init_*, which runs after ca_install_obj_type. */
687
686
  if ( !NIL_P(ca_class[obj_type]) ) {
688
- rb_define_singleton_method(ca_class[obj_type], "face_state_portable?",
687
+ rb_define_private_method(rb_singleton_class(ca_class[obj_type]), "face_state_portable?",
689
688
  portable ? rb_ca_s_face_state_portable_true
690
689
  : rb_ca_s_face_state_portable_false,
691
690
  0);
@@ -704,7 +703,7 @@ ca_face_class_has_portable_method (VALUE klass)
704
703
  ID id_owner = rb_intern("owner");
705
704
  VALUE m, owner;
706
705
  if ( NIL_P(klass) ) return 0;
707
- if ( !rb_respond_to(klass, id_face_state_portable_p) ) return 0;
706
+ if ( !rb_obj_respond_to(klass, id_face_state_portable_p, Qtrue) ) return 0;
708
707
  m = rb_funcall(klass, id_method, 1, ID2SYM(id_face_state_portable_p));
709
708
  owner = rb_funcall(m, id_owner, 0);
710
709
  /* owner is a (singleton) class — if it isn't rb_singleton_class(rb_cCArray)
@@ -779,28 +778,29 @@ ca_face_refuse_order (const char *name, VALUE face, const char *verb)
779
778
  when the Face is ORDERABLE; refuses otherwise (ca_face_refuse_order). A
780
779
  family that can order by a key asks ca_face_orders_by_itself first. */
781
780
  void
782
- ca_face_require_orderable (VALUE face, const char *name, const char *verb)
781
+ ca_face_require_orderable (volatile VALUE face, const char *name, const char *verb)
783
782
  {
784
783
  CArray *ca;
785
- TypedData_Get_Struct(face, CArray, &carray_data_type, ca);
784
+ GetCArray(face, ca);
786
785
  if ( ! ca_test_flag(ca, CA_FLAG_FACE_ORDERABLE_STORAGE) ) {
787
786
  ca_face_refuse_order(name, face, verb);
788
787
  }
789
788
  }
790
789
 
791
- /* Whether a Face is ordered by its own #order rather than by its storage:
792
- it is not ORDERABLE and answers #order itself (CAConstString, CARecord),
793
- so a family that orders by a key can take that order. CArray#order is
794
- not one: it sorts the storage and comes back to the gate. */
790
+ /* Whether a Face is ordered by its own #rank_index rather than by its
791
+ storage: it is not ORDERABLE and answers #rank_index itself
792
+ (CAConstString, CARecord), so a family that orders by a key can take that
793
+ order. CArray#rank_index is not one: it sorts the storage and comes back
794
+ to the gate. */
795
795
  int
796
- ca_face_orders_by_itself (VALUE face)
796
+ ca_face_orders_by_itself (volatile VALUE face)
797
797
  {
798
- ID id_order = rb_intern("order");
798
+ ID id_order = rb_intern("rank_index");
799
799
  ID id_method = rb_intern("method");
800
800
  ID id_owner = rb_intern("owner");
801
801
  CArray *ca;
802
802
  VALUE m;
803
- TypedData_Get_Struct(face, CArray, &carray_data_type, ca);
803
+ GetCArray(face, ca);
804
804
  if ( ca_test_flag(ca, CA_FLAG_FACE_ORDERABLE_STORAGE) ) {
805
805
  return 0;
806
806
  }
@@ -812,7 +812,7 @@ ca_face_orders_by_itself (VALUE face)
812
812
  whose cells encode its values rather than being numbers, pointing at what
813
813
  gives numbers. Returns when `self` is not a Face. */
814
814
  void
815
- ca_face_refuse_numeric (VALUE self, const char *name, VALUE eclass)
815
+ ca_face_refuse_numeric (volatile VALUE self, const char *name, VALUE eclass)
816
816
  {
817
817
  CArray *ca;
818
818
  if ( ! rb_obj_is_carray(self) ) {
@@ -840,13 +840,13 @@ ca_face_refuse_numeric (VALUE self, const char *name, VALUE eclass)
840
840
  }
841
841
 
842
842
  VALUE
843
- ca_face_operand_descend (VALUE operand, const char *name)
843
+ ca_face_operand_descend (volatile VALUE operand, const char *name)
844
844
  {
845
845
  CArray *op;
846
846
  if ( ! RTEST(rb_obj_is_carray(operand)) ) {
847
847
  return operand;
848
848
  }
849
- TypedData_Get_Struct(operand, CArray, &carray_data_type, op);
849
+ GetCArray(operand, op);
850
850
  if ( ! ca_is_face(op) ) {
851
851
  return operand;
852
852
  }
@@ -887,12 +887,12 @@ ca_face_operand_descend (VALUE operand, const char *name)
887
887
  strings of different widths), and `eql?`, which has to agree with #hash,
888
888
  answers false. */
889
889
  int
890
- ca_face_equal (VALUE va, VALUE vb, int strict)
890
+ ca_face_equal (volatile VALUE va, volatile VALUE vb, int strict)
891
891
  {
892
892
  CArray *a, *b;
893
893
  int8_t i;
894
- TypedData_Get_Struct(va, CArray, &carray_data_type, a);
895
- TypedData_Get_Struct(vb, CArray, &carray_data_type, b);
894
+ GetCArray(va, a);
895
+ GetCArray(vb, b);
896
896
  if ( ! ca_is_face(a) || ! ca_is_face(b) ) {
897
897
  return 0;
898
898
  }
@@ -925,13 +925,13 @@ ca_face_equal (VALUE va, VALUE vb, int strict)
925
925
  (#to_string) or, for any other, its values (to_type(:object)). Any
926
926
  other operand is returned as it is. */
927
927
  static VALUE
928
- ca_face_operand_values (VALUE operand)
928
+ ca_face_operand_values (volatile VALUE operand)
929
929
  {
930
930
  CArray *op;
931
931
  if ( ! RTEST(rb_obj_is_carray(operand)) ) {
932
932
  return operand;
933
933
  }
934
- TypedData_Get_Struct(operand, CArray, &carray_data_type, op);
934
+ GetCArray(operand, op);
935
935
  if ( ! ca_is_face(op) || op->obj_type == CA_OBJ_RECORD
936
936
  || ca_test_flag(op, CA_FLAG_FACE_ORDERABLE_STORAGE) ) {
937
937
  return operand;
@@ -939,7 +939,8 @@ ca_face_operand_values (VALUE operand)
939
939
  if ( rb_respond_to(operand, rb_intern("to_string")) ) {
940
940
  return rb_funcall(operand, rb_intern("to_string"), 0);
941
941
  }
942
- return rb_funcall(operand, rb_intern("to_type"), 1, INT2NUM(CA_OBJECT));
942
+ /* coerce: a fixed type, the operand's values as objects */
943
+ return rb_ca_to_type(operand, ID2SYM(ca_data_type_sym[CA_OBJECT]), Qnil);
943
944
  }
944
945
 
945
946
  /* Bring `operand` into the storage space of `reference`, a Face, so the
@@ -965,17 +966,17 @@ ca_face_operand_values (VALUE operand)
965
966
  UNDEF is undefined in every space, so it passes as it is and the entry
966
967
  answers it as it does for a plain array. */
967
968
  VALUE
968
- ca_face_reconcile_operand (VALUE reference, VALUE operand, const char *name)
969
+ ca_face_reconcile_operand (volatile VALUE reference, volatile VALUE operand, const char *name)
969
970
  {
970
971
  CArray *ca;
971
972
  if ( operand == CA_UNDEF ) {
972
973
  return operand;
973
974
  }
974
- TypedData_Get_Struct(reference, CArray, &carray_data_type, ca);
975
+ GetCArray(reference, ca);
975
976
  if ( ca->obj_type == CA_OBJ_RECORD ) {
976
977
  if ( RTEST(rb_obj_is_carray(operand)) ) {
977
978
  CArray *op;
978
- TypedData_Get_Struct(operand, CArray, &carray_data_type, op);
979
+ GetCArray(operand, op);
979
980
  if ( ca_is_face(op) ) {
980
981
  if ( op->obj_type != CA_OBJ_RECORD ) {
981
982
  rb_raise(rb_eTypeError,
@@ -998,7 +999,7 @@ ca_face_reconcile_operand (VALUE reference, VALUE operand, const char *name)
998
999
  return ca_face_operand_descend(ca_face_operand_values(operand), name);
999
1000
  }
1000
1001
  ca_face_require_orderable(reference, name, "compare");
1001
- if ( rb_respond_to(reference, rb_intern("to_comparable")) ) {
1002
+ if ( rb_obj_respond_to(reference, rb_intern("to_comparable"), Qtrue) ) {
1002
1003
  return rb_ca_strip_face_value(rb_funcall(reference,
1003
1004
  rb_intern("to_comparable"),
1004
1005
  1, operand));
@@ -1033,17 +1034,18 @@ ca_face_reconcile_pair (volatile VALUE *pref, volatile VALUE *poperand,
1033
1034
  const char *name)
1034
1035
  {
1035
1036
  static ID id_comparable_pair = 0;
1036
- VALUE ref = *pref, operand = *poperand;
1037
+ volatile VALUE ref = *pref;
1038
+ VALUE operand = *poperand;
1037
1039
  CArray *ca;
1038
1040
  if ( id_comparable_pair == 0 ) {
1039
1041
  id_comparable_pair = rb_intern("comparable_pair");
1040
1042
  }
1041
- TypedData_Get_Struct(ref, CArray, &carray_data_type, ca);
1043
+ GetCArray(ref, ca);
1042
1044
  if ( operand != CA_UNDEF
1043
1045
  && ca->obj_type != CA_OBJ_RECORD
1044
1046
  && ! ca_test_flag(ca, CA_FLAG_FACE_COMPARABLE_STORAGE)
1045
1047
  && ca_test_flag(ca, CA_FLAG_FACE_ORDERABLE_STORAGE)
1046
- && rb_respond_to(ref, id_comparable_pair) ) {
1048
+ && rb_obj_respond_to(ref, id_comparable_pair, Qtrue) ) {
1047
1049
  VALUE pair = rb_funcall(ref, id_comparable_pair, 1, operand);
1048
1050
  *pref = rb_ary_entry(pair, 0);
1049
1051
  *poperand = rb_ca_strip_face_value(rb_ary_entry(pair, 1));
@@ -1053,7 +1055,7 @@ ca_face_reconcile_pair (volatile VALUE *pref, volatile VALUE *poperand,
1053
1055
  }
1054
1056
 
1055
1057
  int
1056
- ca_face_state_portable (int obj_type, VALUE klass)
1058
+ ca_face_state_portable (int16_t obj_type, VALUE klass)
1057
1059
  {
1058
1060
  int8_t entry;
1059
1061
  if ( obj_type < 0 || obj_type >= CA_OBJ_TYPE_MAX ) return 1;
@@ -1077,10 +1079,10 @@ ca_face_list_class (VALUE list, const char *who)
1077
1079
  CArray *ref = NULL;
1078
1080
 
1079
1081
  for ( i = 0; i < n; i++ ) {
1080
- VALUE p = rb_ary_entry(list, i);
1082
+ volatile VALUE p = rb_ary_entry(list, i);
1081
1083
  CArray *ca;
1082
1084
  rb_check_carray_object(p);
1083
- TypedData_Get_Struct(p, CArray, &carray_data_type, ca);
1085
+ GetCArray(p, ca);
1084
1086
  if ( ! ca_is_face(ca) ) { all_face = 0; continue; }
1085
1087
  any_face = 1;
1086
1088
  if ( NIL_P(face_class) ) {
@@ -1126,9 +1128,9 @@ ca_face_list_class (VALUE list, const char *who)
1126
1128
  ca_face_conversion_hint(face));
1127
1129
  }
1128
1130
  for ( i = 1; i < n; i++ ) {
1129
- VALUE p = rb_ary_entry(list, i);
1131
+ volatile VALUE p = rb_ary_entry(list, i);
1130
1132
  CArray *ca;
1131
- TypedData_Get_Struct(p, CArray, &carray_data_type, ca);
1133
+ GetCArray(p, ca);
1132
1134
  if ( ! ca_face_state_compatible(rb_ary_entry(list, 0), ref, p, ca) ) {
1133
1135
  rb_raise(rb_eArgError,
1134
1136
  "%s: Face state mismatch (the %"PRIsVALUE" at index %ld differs from "
@@ -1139,10 +1141,10 @@ ca_face_list_class (VALUE list, const char *who)
1139
1141
  }
1140
1142
 
1141
1143
  VALUE
1142
- ca_face_strip_one (VALUE v)
1144
+ ca_face_strip_one (volatile VALUE v)
1143
1145
  {
1144
1146
  CArray *c;
1145
- TypedData_Get_Struct(v, CArray, &carray_data_type, c);
1147
+ GetCArray(v, c);
1146
1148
  return ca_is_face(c) ? rb_ca_parent(v) : v;
1147
1149
  }
1148
1150
 
@@ -1162,7 +1164,7 @@ rb_ca_s_face_state_portable_p (VALUE klass)
1162
1164
  CA_FLAG_FACE_ORDERABLE_STORAGE, false for a Face whose cells encode the
1163
1165
  value (a const string's ranges, a categorical's codes). */
1164
1166
  static VALUE
1165
- rb_ca_orderable_storage_p (VALUE self)
1167
+ rb_ca_orderable_storage_p (volatile VALUE self)
1166
1168
  {
1167
1169
  CArray *ca;
1168
1170
  GetCArray(self, ca);
@@ -1175,7 +1177,7 @@ rb_ca_orderable_storage_p (VALUE self)
1175
1177
  for an array that is not a Face and for a Face that declares
1176
1178
  CA_FLAG_FACE_COMPARABLE_STORAGE. */
1177
1179
  static VALUE
1178
- rb_ca_comparable_storage_p (VALUE self)
1180
+ rb_ca_comparable_storage_p (volatile VALUE self)
1179
1181
  {
1180
1182
  CArray *ca;
1181
1183
  GetCArray(self, ca);
@@ -1196,7 +1198,7 @@ rb_ca_face_storage (VALUE self)
1196
1198
  (ca_face_reconcile_operand for a Face, ca_face_operand_descend for an
1197
1199
  array that is not one). For the families written in Ruby. */
1198
1200
  static VALUE
1199
- rb_ca_reconcile_operand (VALUE self, VALUE operand, VALUE rname)
1201
+ rb_ca_reconcile_operand (volatile VALUE self, VALUE operand, volatile VALUE rname)
1200
1202
  {
1201
1203
  CArray *ca;
1202
1204
  const char *name = StringValueCStr(rname);
@@ -1213,18 +1215,18 @@ rb_ca_reconcile_operand (VALUE self, VALUE operand, VALUE rname)
1213
1215
  promote_list pass). Delegates the data_type rewrite and optional
1214
1216
  copy_state callback to ca_face_lift. */
1215
1217
  static VALUE
1216
- rb_ca_face_lift_method (VALUE self, VALUE face_parent)
1218
+ rb_ca_face_lift_method (volatile VALUE self, volatile VALUE face_parent)
1217
1219
  {
1218
1220
  CArray *fp, *vc, *storage;
1219
1221
  if ( ! rb_obj_is_kind_of(face_parent, rb_cCArray) ) {
1220
1222
  rb_raise(rb_eArgError, "face_lift: face_parent must be a CArray");
1221
1223
  }
1222
- TypedData_Get_Struct(face_parent, CArray, &carray_data_type, fp);
1224
+ GetCArray(face_parent, fp);
1223
1225
  if ( ! ca_is_face(fp) ) {
1224
1226
  rb_raise(rb_eArgError, "face_lift: face_parent must be a Face instance");
1225
1227
  }
1226
1228
  rb_check_carray_object(self);
1227
- TypedData_Get_Struct(self, CArray, &carray_data_type, vc);
1229
+ GetCArray(self, vc);
1228
1230
  /* A Face of the same class is already lifted (see ca_face_lift). */
1229
1231
  if ( ca_is_face(vc) && rb_obj_class(self) == rb_obj_class(face_parent) ) {
1230
1232
  return self;
@@ -1263,13 +1265,13 @@ rb_ca_face_lift_method (VALUE self, VALUE face_parent)
1263
1265
  void
1264
1266
  ca_face_reconcile_comparison (volatile VALUE *pself, volatile VALUE *pother)
1265
1267
  {
1266
- VALUE self = *pself, other = *pother;
1268
+ volatile VALUE self = *pself, other = *pother;
1267
1269
  CArray *sc, *storage;
1268
1270
 
1269
1271
  if ( ! rb_obj_is_kind_of(self, rb_cCArray) ) {
1270
1272
  return;
1271
1273
  }
1272
- TypedData_Get_Struct(self, CArray, &carray_data_type, sc);
1274
+ GetCArray(self, sc);
1273
1275
  if ( ! ca_is_face(sc) ) {
1274
1276
  return;
1275
1277
  }
@@ -1282,7 +1284,7 @@ ca_face_reconcile_comparison (volatile VALUE *pself, volatile VALUE *pother)
1282
1284
  static ID id_to_string = 0;
1283
1285
  CArray *oc;
1284
1286
  if ( id_to_string == 0 ) id_to_string = rb_intern("to_string");
1285
- TypedData_Get_Struct(other, CArray, &carray_data_type, oc);
1287
+ GetCArray(other, oc);
1286
1288
  if ( ca_is_face(oc) && rb_respond_to(self, id_to_string)
1287
1289
  && rb_respond_to(other, id_to_string)
1288
1290
  && ( rb_obj_class(self) != rb_obj_class(other)
@@ -1322,22 +1324,29 @@ ca_face_reconcile_comparison (volatile VALUE *pself, volatile VALUE *pother)
1322
1324
  }
1323
1325
  }
1324
1326
 
1325
- /* A Face's parent, the array its values are stored in, is handed out as a
1326
- read-only view: a write through it would change the Face's values
1327
- without the Face's conversion (a tick count stored into a time, bytes
1328
- into a record). The storage is written through the Face's own named
1329
- methods (CATime#ticks), which take it with face_storage. */
1330
- static VALUE
1331
- rb_ca_face_parent (VALUE self)
1327
+ /* CArray#parent. A Face's parent, the array its values are stored in, is
1328
+ handed out as a read-only view: a write through it would change the
1329
+ Face's values without the Face's conversion (a tick count stored into a
1330
+ time, bytes into a record). The storage is written through the Face's
1331
+ own named methods (CATime#ticks), which take it with face_storage. A
1332
+ Face is told by its flag, so a Face written in Ruby (a CAObject with
1333
+ face: true) is handed the same view as a subclass of CAFace. Any other
1334
+ array gets its parent itself. */
1335
+ VALUE
1336
+ rb_ca_parent_method (volatile VALUE self)
1332
1337
  {
1333
1338
  volatile VALUE st = rb_ca_parent(self), view;
1334
- CArray *cs, *cv;
1339
+ CArray *ca, *cs, *cv;
1335
1340
  if ( NIL_P(st) ) {
1336
1341
  return st;
1337
1342
  }
1338
- TypedData_Get_Struct(st, CArray, &carray_data_type, cs);
1343
+ GetCArray(self, ca);
1344
+ if ( ! ca_is_face(ca) ) {
1345
+ return st;
1346
+ }
1347
+ GetCArray(st, cs);
1339
1348
  view = rb_ca_refer_new(st, cs->data_type, cs->ndim, cs->dim, cs->bytes, 0);
1340
- TypedData_Get_Struct(view, CArray, &carray_data_type, cv);
1349
+ GetCArray(view, cv);
1341
1350
  ca_set_flag(cv, CA_FLAG_READ_ONLY);
1342
1351
  return view;
1343
1352
  }
@@ -1351,7 +1360,6 @@ Init_ca_face (void)
1351
1360
  ahead of this Init) — CAFace inherits from it. */
1352
1361
  rb_cCAFace = rb_define_class("CAFace", rb_cCAView);
1353
1362
  rb_define_alloc_func(rb_cCAFace, rb_ca_face_s_allocate_forbidden);
1354
- rb_define_method(rb_cCAFace, "parent", rb_ca_face_parent, 0);
1355
1363
 
1356
1364
  /* Initialise the portable table to -1 for every slot so dispatch
1357
1365
  can distinguish "explicitly registered 0" (CAConstString) from
@@ -1360,11 +1368,11 @@ Init_ca_face (void)
1360
1368
  ca_face_state_portable_table[i] = -1;
1361
1369
  }
1362
1370
 
1363
- rb_define_method(rb_cCArray, "face_state_compatible?",
1371
+ rb_define_private_method(rb_cCArray, "face_state_compatible?",
1364
1372
  rb_ca_face_state_compatible_p, 1);
1365
- rb_define_singleton_method(rb_cCArray, "face_state_portable?",
1373
+ rb_define_private_method(rb_singleton_class(rb_cCArray), "face_state_portable?",
1366
1374
  rb_ca_s_face_state_portable_p, 0);
1367
- rb_define_method(rb_cCArray, "face_lift", rb_ca_face_lift_method, 1);
1375
+ rb_define_private_method(rb_cCArray, "face_lift", rb_ca_face_lift_method, 1);
1368
1376
  rb_define_private_method(rb_cCArray, "orderable_storage?",
1369
1377
  rb_ca_orderable_storage_p, 0);
1370
1378
  rb_define_private_method(rb_cCArray, "comparable_storage?",