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/carray_test.c CHANGED
@@ -10,7 +10,6 @@
10
10
  ---------------------------------------------------------------------------- */
11
11
 
12
12
  #include "carray.h"
13
- #include "carray_internal.h" /* ca_attach_window */
14
13
  #include "ca_obj_face.h" /* ca_face_equal */
15
14
 
16
15
  static ID id_equal;
@@ -24,7 +23,8 @@ ca_check_type (void *ap, int8_t data_type)
24
23
  {
25
24
  CArray *ca = (CArray *) ap;
26
25
  if ( ca->data_type != data_type ) {
27
- rb_raise(rb_eCADataTypeError, "data_type mismatch");
26
+ rb_raise(rb_eCADataTypeError, "%s: data_type mismatch",
27
+ ca_calling_method_name());
28
28
  }
29
29
  }
30
30
 
@@ -45,7 +45,8 @@ ca_check_uninitialized (void *ap)
45
45
  {
46
46
  CArray *ca = (CArray *) ap;
47
47
  if ( ca->dim != NULL ) {
48
- rb_raise(rb_eTypeError, "already initialized array");
48
+ rb_raise(rb_eTypeError, "%s: already initialized array",
49
+ ca_calling_method_name());
49
50
  }
50
51
  }
51
52
 
@@ -55,7 +56,7 @@ ca_check_ndim (void *ap, int ndim)
55
56
  CArray *ca = (CArray *) ap;
56
57
  if ( ! ca_is_scalar(ca) ) {
57
58
  if ( ca->ndim != ndim ) {
58
- rb_raise(rb_eArgError, "ndim mismatch");
59
+ rb_raise(rb_eArgError, "%s: ndim mismatch", ca_calling_method_name());
59
60
  }
60
61
  }
61
62
  }
@@ -67,11 +68,11 @@ ca_check_shape (void *ap, int ndim, ca_size_t *dim)
67
68
  int i;
68
69
  if ( ! ca_is_scalar(ca) ) {
69
70
  if ( ca->ndim != ndim ) {
70
- rb_raise(rb_eArgError, "shape mismatch");
71
+ rb_raise(rb_eArgError, "%s: shape mismatch", ca_calling_method_name());
71
72
  }
72
73
  for (i=0; i<ndim; i++) {
73
74
  if ( ca->dim[i] != dim[i] ) {
74
- rb_raise(rb_eArgError, "shape mismatch");
75
+ rb_raise(rb_eArgError, "%s: shape mismatch", ca_calling_method_name());
75
76
  }
76
77
  }
77
78
  }
@@ -84,7 +85,8 @@ ca_check_same_data_type (void *ap1, void *ap2)
84
85
  CArray *ca2 = (CArray *) ap2;
85
86
  if ( ca1->data_type != ca2->data_type ||
86
87
  ( ca1->data_type == CA_FIXLEN && ca1->bytes != ca2->bytes ) ) {
87
- rb_raise(rb_eCADataTypeError, "data_type mismatch");
88
+ rb_raise(rb_eCADataTypeError, "%s: data_type mismatch",
89
+ ca_calling_method_name());
88
90
  }
89
91
  }
90
92
 
@@ -94,7 +96,7 @@ ca_check_same_ndim (void *ap1, void *ap2)
94
96
  CArray *ca1 = (CArray *) ap1;
95
97
  CArray *ca2 = (CArray *) ap2;
96
98
  if ( ca1->ndim != ca2->ndim ) {
97
- rb_raise(rb_eArgError, "ndim mismatch");
99
+ rb_raise(rb_eArgError, "%s: ndim mismatch", ca_calling_method_name());
98
100
  }
99
101
  }
100
102
 
@@ -104,7 +106,7 @@ ca_check_same_elements (void *ap1, void *ap2)
104
106
  CArray *ca1 = (CArray *) ap1;
105
107
  CArray *ca2 = (CArray *) ap2;
106
108
  if ( ca1->elements != ca2->elements ) {
107
- rb_raise(rb_eArgError, "elements mismatch");
109
+ rb_raise(rb_eArgError, "%s: elements mismatch", ca_calling_method_name());
108
110
  }
109
111
  }
110
112
 
@@ -116,11 +118,11 @@ ca_check_same_shape (void *ap1, void *ap2)
116
118
  int i;
117
119
  if ( ( ! ca_is_scalar(ca1) ) && ( ! ca_is_scalar(ca2) ) ) {
118
120
  if ( ca1->ndim != ca2->ndim ) {
119
- rb_raise(rb_eArgError, "shape mismatch");
121
+ rb_raise(rb_eArgError, "%s: shape mismatch", ca_calling_method_name());
120
122
  }
121
123
  for (i=0; i<ca1->ndim; i++) {
122
124
  if ( ca1->dim[i] != ca2->dim[i] ) {
123
- rb_raise(rb_eArgError, "shape mismatch");
125
+ rb_raise(rb_eArgError, "%s: shape mismatch", ca_calling_method_name());
124
126
  }
125
127
  }
126
128
  }
@@ -133,7 +135,7 @@ ca_check_index (void *ap, ca_size_t *idx)
133
135
  int i;
134
136
  for (i=0; i<ca->ndim; i++) {
135
137
  if ( idx[i] < 0 || idx[i] >= ca->dim[i] ) {
136
- rb_raise(rb_eIndexError, "invalid index");
138
+ rb_raise(rb_eIndexError, "%s: invalid index", ca_calling_method_name());
137
139
  }
138
140
  }
139
141
  }
@@ -142,7 +144,7 @@ void
142
144
  rb_check_carray_object (VALUE arg)
143
145
  {
144
146
  if ( ! rb_obj_is_carray(arg) ) {
145
- rb_raise(rb_eTypeError, "CArray required");
147
+ rb_raise(rb_eTypeError, "%s: CArray required", ca_calling_method_name());
146
148
  }
147
149
  }
148
150
 
@@ -186,13 +188,13 @@ ca_is_valid_index (void *ap, ca_size_t *idx)
186
188
  /* rb_ca_is_type(arg, type) — returns 1 if arg is a CArray whose
187
189
  data_type equals `type`, else raises if not a CArray. */
188
190
  int
189
- rb_ca_is_type (VALUE arg, int type)
191
+ rb_ca_is_type (volatile VALUE arg, int type)
190
192
  {
191
193
  CArray *ca;
192
194
  if ( ! rb_obj_is_carray(arg) ) {
193
- rb_raise(rb_eTypeError, "CArray required");
195
+ rb_raise(rb_eTypeError, "%s: CArray required", ca_calling_method_name());
194
196
  }
195
- TypedData_Get_Struct(arg, CArray, &carray_data_type, ca);
197
+ GetCArray(arg, ca);
196
198
  return ca->data_type == type;
197
199
  }
198
200
 
@@ -201,28 +203,43 @@ rb_ca_is_type (VALUE arg, int type)
201
203
  live in ca_obj_record.c; signatures stay in carray.h for cross-file
202
204
  extern use. */
203
205
 
206
+ /* Whether v, an index along a length of n, names a position: a negative one
207
+ * counts from the end. An Integer too large for ca_size_t is out of any
208
+ * range; what is not an Integer is not an index. */
209
+ static int
210
+ ca_index_arg_in_range (VALUE v, ca_size_t n, const char *arg)
211
+ {
212
+ ca_size_t idx;
213
+ if ( RB_TYPE_P(v, T_BIGNUM) ) {
214
+ return 0;
215
+ }
216
+ idx = ca_integer_arg(v, arg, NULL);
217
+ if ( idx < 0 ) {
218
+ idx += n;
219
+ }
220
+ return idx >= 0 && idx < n;
221
+ }
222
+
204
223
  /* CArray#valid_index?(*idx) -- whether self[*idx] names a cell: a negative
205
224
  * index counts from the end of its axis, as it does at every door. The
206
225
  * number of indices must equal ndim (raises otherwise). */
207
226
  static VALUE
208
- rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
227
+ rb_ca_is_valid_index (int argc, VALUE *argv, volatile VALUE self)
209
228
  {
210
229
  CArray *ca;
211
- ca_size_t idx;
212
230
  int i;
213
231
 
214
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
232
+ rb_reject_options(rb_pop_options(&argc, &argv));
233
+
234
+ GetCArray(self, ca);
215
235
 
216
236
  if ( argc != ca->ndim ) {
217
237
  rb_raise(rb_eArgError,
218
- "invalid # of arguments (%i for %i)", argc, ca->ndim);
238
+ "%s: invalid # of arguments (%i for %i)",
239
+ ca_calling_method_name(), argc, ca->ndim);
219
240
  }
220
241
  for (i=0; i<ca->ndim; i++) {
221
- idx = NUM2SIZE(argv[i]);
222
- if ( idx < 0 ) {
223
- idx += ca->dim[i];
224
- }
225
- if ( idx < 0 || idx >= ca->dim[i] ) {
242
+ if ( ! ca_index_arg_in_range(argv[i], ca->dim[i], "an index") ) {
226
243
  return Qfalse;
227
244
  }
228
245
  }
@@ -233,33 +250,29 @@ rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
233
250
  /* CArray#valid_addr?(addr) -- whether addr names a cell: a negative address
234
251
  * counts from the end. */
235
252
  static VALUE
236
- rb_ca_is_valid_addr (VALUE self, VALUE raddr)
253
+ rb_ca_is_valid_addr (volatile VALUE self, VALUE raddr)
237
254
  {
238
255
  CArray *ca;
239
- ca_size_t addr;
240
256
 
241
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
242
- addr = NUM2SIZE(raddr);
243
- if ( addr < 0 ) {
244
- addr += ca->elements;
245
- }
246
- if ( addr < 0 || addr >= ca->elements ) {
247
- return Qfalse;
248
- }
249
- else {
250
- return Qtrue;
251
- }
257
+ GetCArray(self, ca);
258
+ return ca_index_arg_in_range(raddr, ca->elements, "an address") ? Qtrue : Qfalse;
252
259
  }
253
260
 
254
- /* CArray#same_shape?(other) — 1 if self and other share ndim and dim[].
255
- * Scalars compare true against any array (see ca_has_same_shape). */
261
+ /* CArray#same_shape?(other) — whether self and other share ndim and dim[].
262
+ * Scalars compare true against any array (see ca_has_same_shape). Only the
263
+ * shape is compared, so no value is converted: other that is not a CArray
264
+ * takes the shape it has as an object array. */
256
265
  static VALUE
257
- rb_ca_has_same_shape (VALUE self, VALUE other)
266
+ rb_ca_has_same_shape (volatile VALUE self, volatile VALUE other)
258
267
  {
259
268
  CArray *ca, *cb;
260
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
261
- /* coerce: only the shape is compared */
262
- cb = ca_wrap_readonly(other, ca->data_type);
269
+ GetCArray(self, ca);
270
+ if ( rb_obj_is_carray(other) ) {
271
+ GetCArray(other, cb);
272
+ }
273
+ else {
274
+ cb = ca_wrap_readonly(other, CA_OBJECT);
275
+ }
263
276
  return ca_has_same_shape(ca, cb) ? Qtrue : Qfalse;
264
277
  }
265
278
 
@@ -276,10 +289,22 @@ eql_## type (const char *a, const char *b, ca_size_t bytes) \
276
289
 
277
290
  /* == compares contents: a NaN equals a NaN (whatever its payload), as the
278
291
  same array read back or copied holds the same NaN; -0.0 equals 0.0 as
279
- values do. eql? stays bitwise. */
292
+ values do. eql? stays bitwise. An object cell equals itself first, as
293
+ in Array#== and Array#eql?, so a copy of an array holding any NaN object
294
+ equals it. A cell holding a CArray is asked all the same, so an array
295
+ that holds itself is refused as cyclic. */
296
+ static int
297
+ ca_object_cells_identical (VALUE x, VALUE y)
298
+ {
299
+ return x == y && ! rb_obj_is_carray(x);
300
+ }
301
+
280
302
  static int
281
303
  ca_object_cells_equal (VALUE x, VALUE y)
282
304
  {
305
+ if ( ca_object_cells_identical(x, y) ) {
306
+ return 1;
307
+ }
283
308
  if ( RB_FLOAT_TYPE_P(x) && RB_FLOAT_TYPE_P(y) &&
284
309
  isnan(RFLOAT_VALUE(x)) && isnan(RFLOAT_VALUE(y)) ) {
285
310
  return 1;
@@ -287,6 +312,13 @@ ca_object_cells_equal (VALUE x, VALUE y)
287
312
  return RTEST(rb_funcall(x, id_equal, 1, y)) ? 1 : 0;
288
313
  }
289
314
 
315
+ static int
316
+ ca_object_cells_eql (VALUE x, VALUE y)
317
+ {
318
+ return ca_object_cells_identical(x, y)
319
+ || RTEST(rb_funcall(x, id_eql, 1, y));
320
+ }
321
+
290
322
  static int
291
323
  eql_VALUE (const char *a, const char *b, ca_size_t bytes)
292
324
  {
@@ -416,8 +448,7 @@ ca_compare_body (VALUE arg)
416
448
  for (i=0; i<ca->elements; i++) {
417
449
  volatile VALUE x = va[i];
418
450
  volatile VALUE y = vb[i];
419
- int eq = strict ? RTEST(rb_funcall(x, id_eql, 1, y))
420
- : ca_object_cells_equal(x, y);
451
+ int eq = strict ? ca_object_cells_eql(x, y) : ca_object_cells_equal(x, y);
421
452
  if ( ! eq ) {
422
453
  flag = 0;
423
454
  break;
@@ -459,8 +490,7 @@ ca_compare_body (VALUE arg)
459
490
  if ( is_object ) {
460
491
  volatile VALUE x = *(VALUE *) pa;
461
492
  volatile VALUE y = *(VALUE *) pb;
462
- eq = strict ? RTEST(rb_funcall(x, id_eql, 1, y))
463
- : ca_object_cells_equal(x, y);
493
+ eq = strict ? ca_object_cells_eql(x, y) : ca_object_cells_equal(x, y);
464
494
  }
465
495
  else if ( strict
466
496
  || ca->data_type <= CA_UINT64
@@ -501,13 +531,13 @@ ca_compare_run (VALUE arg)
501
531
  * semantics, else 0.
502
532
  *
503
533
  * Common structure: metadata pre-check (scalar / data_type / bytes /
504
- * ndim / elements / dim), then ca_compare_body in a window over both
505
- * arrays (attaching an array attaches its mask), a unified loop over the
534
+ * ndim / elements / dim), then ca_compare_body with both arrays
535
+ * attached (attaching an array attaches its mask), a unified loop over the
506
536
  * four masked/unmasked combinations.
507
537
  *
508
538
  * The only difference is the per-element comparator:
509
539
  * == : ca_eql[data_type] (by value: NaN equals NaN, -0.0 equals 0.0)
510
- * eql?: memcmp for numeric, rb_funcall(:eql?) for CA_OBJECT
540
+ * eql?: memcmp for numeric, ca_object_cells_eql for CA_OBJECT
511
541
  *
512
542
  * The unmasked-unmasked branch takes a bulk memcmp or per-cell
513
543
  * shortcut to amortise per-element function pointer dispatch. */
@@ -578,7 +608,7 @@ ca_eql_storage (void *ap, void *bp)
578
608
  * equals 0.0; the IEEE comparison of each element is #eq. Non-CArray
579
609
  * other returns false. */
580
610
  static VALUE
581
- rb_ca_equal (VALUE self, VALUE other)
611
+ rb_ca_equal (volatile VALUE self, volatile VALUE other)
582
612
  {
583
613
  CArray *ca, *cb;
584
614
 
@@ -599,8 +629,8 @@ rb_ca_equal (VALUE self, VALUE other)
599
629
  }
600
630
  }
601
631
 
602
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
603
- TypedData_Get_Struct(other, CArray, &carray_data_type, cb);
632
+ GetCArray(self, ca);
633
+ GetCArray(other, cb);
604
634
 
605
635
  if ( ! rb_ca_has_data_class(self) && ( ca_is_face(ca) || ca_is_face(cb) ) ) {
606
636
  return ca_face_equal(self, other, 0) ? Qtrue : Qfalse;
@@ -614,7 +644,7 @@ rb_ca_equal (VALUE self, VALUE other)
614
644
  * comparison is bitwise (numeric) or Object#eql? (CA_OBJECT), so
615
645
  * NaN.eql?(NaN) holds. */
616
646
  static VALUE
617
- rb_ca_eql (VALUE self, VALUE other)
647
+ rb_ca_eql (volatile VALUE self, volatile VALUE other)
618
648
  {
619
649
  CArray *ca, *cb;
620
650
 
@@ -635,8 +665,8 @@ rb_ca_eql (VALUE self, VALUE other)
635
665
  }
636
666
  }
637
667
 
638
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
639
- TypedData_Get_Struct(other, CArray, &carray_data_type, cb);
668
+ GetCArray(self, ca);
669
+ GetCArray(other, cb);
640
670
 
641
671
  if ( ! rb_ca_has_data_class(self) && ( ca_is_face(ca) || ca_is_face(cb) ) ) {
642
672
  return ca_face_equal(self, other, 1) ? Qtrue : Qfalse;
@@ -659,6 +689,24 @@ rb_ca_eql (VALUE self, VALUE other)
659
689
 
660
690
  #define CA_HASH_SAMPLE_BYTES 64
661
691
 
692
+ typedef struct {
693
+ st_index_t h;
694
+ ca_size_t n;
695
+ const VALUE *cells;
696
+ } ca_hash_cells_t;
697
+
698
+ static VALUE
699
+ ca_hash_cells (VALUE arg)
700
+ {
701
+ ca_hash_cells_t *hc = (ca_hash_cells_t *) arg;
702
+ ca_size_t i;
703
+
704
+ for (i = 0; i < hc->n; i++) {
705
+ hc->h = rb_hash_uint(hc->h, (st_index_t) NUM2LONG(rb_hash(hc->cells[i])));
706
+ }
707
+ return Qnil;
708
+ }
709
+
662
710
  static st_index_t
663
711
  ca_hash (CArray *ca)
664
712
  {
@@ -668,19 +716,21 @@ ca_hash (CArray *ca)
668
716
  ca_size_t data_len = ca_length(ca);
669
717
  ca_size_t sample = (data_len < CA_HASH_SAMPLE_BYTES) ? data_len : CA_HASH_SAMPLE_BYTES;
670
718
 
671
- h = rb_memhash(&ca->data_type, sizeof(ca->data_type));
672
- h ^= rb_memhash(&ca->ndim, sizeof(ca->ndim));
673
- h ^= rb_memhash(&ca->bytes, sizeof(ca->bytes));
674
- h ^= rb_memhash(&ca->elements, sizeof(ca->elements));
675
- h ^= rb_memhash(&scalar_flag, sizeof(scalar_flag));
719
+ /* Mixed in order: XOR would cancel equal fields, as a 1-D array's dim
720
+ and elements are. */
721
+ h = rb_hash_start(ca->data_type);
722
+ h = rb_hash_uint(h, (st_index_t) ca->ndim);
723
+ h = rb_hash_uint(h, (st_index_t) ca->bytes);
724
+ h = rb_hash_uint(h, (st_index_t) ca->elements);
725
+ h = rb_hash_uint(h, (st_index_t) scalar_flag);
676
726
  if ( ca->ndim > 0 ) {
677
- h ^= rb_memhash(ca->dim, sizeof(ca_size_t) * ca->ndim);
727
+ h = rb_hash_uint(h, rb_memhash(ca->dim, sizeof(ca_size_t) * ca->ndim));
678
728
  }
679
729
 
680
730
  /* ca_is_any_masked() attaches/detaches the mask internally and returns
681
731
  only a boolean, so we never touch ca->mask->ptr here. */
682
732
  masked_flag = ca_is_any_masked(ca) ? 1 : 0;
683
- h ^= rb_memhash(&masked_flag, sizeof(masked_flag));
733
+ h = rb_hash_uint(h, (st_index_t) masked_flag);
684
734
 
685
735
  if ( ! masked_flag && sample > 0 ) {
686
736
  ca_size_t addrs[CA_HASH_SAMPLE_BYTES];
@@ -700,32 +750,32 @@ ca_hash (CArray *ca)
700
750
  #hash, not the VALUE bits. The cells sit on the stack, where the
701
751
  GC sees them while #hash runs. */
702
752
  VALUE cells[CA_HASH_SAMPLE_BYTES / sizeof(VALUE)];
753
+ ca_hash_cells_t hc;
703
754
  ca_xfer_addrs(ca, ncell, addrs, cells, CA_XFER_GET);
704
- for (i = 0; i < ncell; i++) {
705
- h = rb_hash_uint(h, (st_index_t) NUM2LONG(rb_hash(cells[i])));
706
- }
707
- RB_GC_GUARD(cells[0]);
755
+ hc.h = h; hc.n = ncell; hc.cells = cells;
756
+ ca_cell_walk_run(ca_hash_cells, (VALUE) &hc);
757
+ h = hc.h;
708
758
  }
709
759
  else {
710
760
  volatile VALUE holder;
711
761
  char *buf = ALLOCV_N(char, holder, ncell * ca->bytes);
712
762
  ca_xfer_addrs(ca, ncell, addrs, buf, CA_XFER_GET);
713
- h ^= rb_memhash(buf, ncell * ca->bytes);
763
+ h = rb_hash_uint(h, rb_memhash(buf, ncell * ca->bytes));
714
764
  ALLOCV_END(holder);
715
765
  }
716
766
  }
717
767
 
718
- return h;
768
+ return rb_hash_end(h);
719
769
  }
720
770
 
721
771
  /* CArray#hash — Hash key value; wraps ca_hash into a Ruby Integer. */
722
772
  VALUE
723
- rb_ca_hash (VALUE self)
773
+ rb_ca_hash (volatile VALUE self)
724
774
  {
725
775
  CArray *ca;
726
776
  st_index_t hash;
727
777
 
728
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
778
+ GetCArray(self, ca);
729
779
  hash = ca_hash(ca);
730
780
  return ST2FIX(hash);
731
781
  }
@@ -740,11 +790,11 @@ rb_ca_hash (VALUE self)
740
790
  * do not pass through xfer -- mutation entry points guard here so a
741
791
  * read-only-flag-only (non-frozen) array is fully protected. */
742
792
  void
743
- rb_ca_modify (VALUE self)
793
+ rb_ca_modify (volatile VALUE self)
744
794
  {
745
795
  CArray *ca;
746
796
  rb_check_frozen(self);
747
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
797
+ GetCArray(self, ca);
748
798
  if ( ca_is_readonly(ca) ) {
749
799
  ca_refuse_read_only();
750
800
  }
@@ -764,10 +814,10 @@ ca_refuse_read_only (void)
764
814
  /* CArray#freeze — freeze self and set CA_FLAG_READ_ONLY so subsequent
765
815
  * mutations raise FrozenError. */
766
816
  VALUE
767
- rb_ca_freeze (VALUE self)
817
+ rb_ca_freeze (volatile VALUE self)
768
818
  {
769
819
  CArray *ca;
770
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
820
+ GetCArray(self, ca);
771
821
  ca_set_flag(ca, CA_FLAG_READ_ONLY);
772
822
  return rb_obj_freeze(self);
773
823
  }
@@ -780,10 +830,10 @@ rb_ca_freeze (VALUE self)
780
830
  * memoise. A caller wanting a mutable array uses `.copy` (a copy does not
781
831
  * inherit the flag). */
782
832
  VALUE
783
- rb_ca_set_read_only_flag (VALUE self)
833
+ rb_ca_set_read_only_flag (volatile VALUE self)
784
834
  {
785
835
  CArray *ca;
786
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
836
+ GetCArray(self, ca);
787
837
  ca_set_flag(ca, CA_FLAG_READ_ONLY);
788
838
  return self;
789
839
  }
@@ -864,13 +914,13 @@ without_read_only_ensure (VALUE arg)
864
914
  * mutates the parent's mask allocation as a side effect, breaking the
865
915
  * view-inherits-readonly guarantee for sibling views of the same parent. */
866
916
  VALUE
867
- rb_ca_without_read_only_flag (VALUE self)
917
+ rb_ca_without_read_only_flag (volatile VALUE self)
868
918
  {
869
919
  CArray *ca;
870
920
  struct without_read_only_state s;
871
921
  rb_check_frozen(self);
872
922
  rb_need_block();
873
- TypedData_Get_Struct(self, CArray, &carray_data_type, ca);
923
+ GetCArray(self, ca);
874
924
  s.ca = ca;
875
925
  s.was_readonly = ca_test_flag(ca, CA_FLAG_READ_ONLY);
876
926
  if (s.was_readonly) {
@@ -1,5 +1,4 @@
1
1
  #include "carray.h"
2
- #include "carray_internal.h"
3
2
 
4
3
  /* ------------------------------------------------------------------------
5
4
  Reading year-first dates and times from text
@@ -103,7 +102,7 @@ ca_time_text_days_from_civil (int64_t y, int64_t m, int64_t d)
103
102
  }
104
103
 
105
104
  static int
106
- ca_time_text_read (VALUE str, ca_time_text_t *t, int wide)
105
+ ca_time_text_read (volatile VALUE str, ca_time_text_t *t, int wide)
107
106
  {
108
107
  const char *s = RSTRING_PTR(str);
109
108
  long n = RSTRING_LEN(str);
@@ -379,28 +378,28 @@ rb_ca_parse_time_text (int argc, VALUE *argv, VALUE self)
379
378
  }
380
379
  }
381
380
 
382
- TypedData_Get_Struct(src, CArray, &carray_data_type, ca);
381
+ GetCArray(src, ca);
383
382
  if ( ca->data_type != CA_OBJECT ) {
384
383
  rb_raise(rb_eArgError, "time text reading needs an object array");
385
384
  }
386
385
  if ( ! ca_is_entity(ca) || ! ca->ptr ) {
387
386
  src = rb_ca_copy(src);
388
- TypedData_Get_Struct(src, CArray, &carray_data_type, ca);
387
+ GetCArray(src, ca);
389
388
  }
390
389
 
391
390
  out = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
392
- TypedData_Get_Struct(out, CArray, &carray_data_type, co);
391
+ GetCArray(out, co);
393
392
  vmask = rb_carray_new(CA_BOOLEAN, ca->ndim, ca->dim, 0, NULL);
394
393
  vdays = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
395
- TypedData_Get_Struct(vdays, CArray, &carray_data_type, cdays);
394
+ GetCArray(vdays, cdays);
396
395
  vnsod = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
397
- TypedData_Get_Struct(vnsod, CArray, &carray_data_type, cnsod);
396
+ GetCArray(vnsod, cnsod);
398
397
  vmonths = rb_carray_new(CA_INT64, ca->ndim, ca->dim, 0, NULL);
399
- TypedData_Get_Struct(vmonths, CArray, &carray_data_type, cmonths);
398
+ GetCArray(vmonths, cmonths);
400
399
 
401
400
  cells = (VALUE *) ca->ptr;
402
401
  m_in = ca_has_mask(ca) ? (boolean8_t *) ca->mask->ptr : NULL;
403
- TypedData_Get_Struct(vmask, CArray, &carray_data_type, cmask);
402
+ GetCArray(vmask, cmask);
404
403
  m_out = (boolean8_t *) cmask->ptr;
405
404
  days = (int64_t *) cdays->ptr;
406
405
  nsod = (int64_t *) cnsod->ptr;
@@ -479,12 +478,7 @@ rb_ca_parse_time_text (int argc, VALUE *argv, VALUE self)
479
478
  }
480
479
 
481
480
  ca_mask_from_bytes(co, m_out);
482
- RB_GC_GUARD(src);
483
- RB_GC_GUARD(vdays);
484
- RB_GC_GUARD(vnsod);
485
- RB_GC_GUARD(vmonths);
486
- RB_GC_GUARD(vmask);
487
- return rb_assoc_new(out, ID2SYM(unit));
481
+ return rb_ary_new_from_args(2, out, ID2SYM(unit));
488
482
  }
489
483
 
490
484
  /* Floor division of an int128 by a positive int64. */
@@ -510,9 +504,10 @@ ca_time_floor_div (__int128 a, int64_t b)
510
504
  only. */
511
505
  static VALUE
512
506
  rb_ca_s_time_ticks_from_fields (VALUE klass,
513
- VALUE vyear, VALUE vmon, VALUE vday,
514
- VALUE vsod, VALUE vfrac, VALUE voff,
515
- VALUE vpresent, VALUE rkind, VALUE rper)
507
+ volatile VALUE vyear, volatile VALUE vmon,
508
+ volatile VALUE vday, volatile VALUE vsod,
509
+ volatile VALUE vfrac, volatile VALUE voff,
510
+ volatile VALUE vpresent, VALUE rkind, VALUE rper)
516
511
  {
517
512
  volatile VALUE out, vmask;
518
513
  CArray *cy, *cm, *cd, *cs, *cf, *co_, *cp, *co, *cmask;
@@ -526,8 +521,9 @@ rb_ca_s_time_ticks_from_fields (VALUE klass,
526
521
  if ( per <= 0 ) {
527
522
  rb_raise(rb_eArgError, "tick length must be positive");
528
523
  }
524
+ /* gc: v is one of the volatile parameters */
529
525
  #define CA_TIME_FIELD(v, c, field, T) \
530
- TypedData_Get_Struct(v, CArray, &carray_data_type, c); \
526
+ GetCArray(v, c); \
531
527
  if ( ! ca_is_entity(c) ) { \
532
528
  rb_raise(rb_eArgError, "time fields must be entities"); \
533
529
  } \
@@ -552,10 +548,10 @@ rb_ca_s_time_ticks_from_fields (VALUE klass,
552
548
  }
553
549
 
554
550
  out = rb_carray_new(CA_INT64, 1, &n, 0, NULL);
555
- TypedData_Get_Struct(out, CArray, &carray_data_type, co);
551
+ GetCArray(out, co);
556
552
  vmask = rb_carray_new(CA_BOOLEAN, 1, &n, 0, NULL);
557
553
  ticks = (int64_t *) co->ptr;
558
- TypedData_Get_Struct(vmask, CArray, &carray_data_type, cmask);
554
+ GetCArray(vmask, cmask);
559
555
  m_out = (boolean8_t *) cmask->ptr;
560
556
 
561
557
  for (i = 0; i < n; i++) {
@@ -585,7 +581,6 @@ rb_ca_s_time_ticks_from_fields (VALUE klass,
585
581
  }
586
582
  }
587
583
  ca_mask_from_bytes(co, m_out);
588
- RB_GC_GUARD(vmask);
589
584
  return out;
590
585
  }
591
586
 
@@ -602,6 +597,12 @@ rb_ca_s_time_ticks_from_fields (VALUE klass,
602
597
  other than Z, UTC and GMT, an offset written another way) is deferred to
603
598
  Date._strptime for that cell.
604
599
 
600
+ Three inputs read differently from Date._strptime. A format with both
601
+ a two-digit year and a four-digit year takes the four-digit year, where
602
+ Date._strptime adds the century to it. %Z ends at the zone's name, so
603
+ digits directly after it go to the next directive. A NUL in the text
604
+ is text, so it is left over.
605
+
605
606
  Strict reading, used to find the format a column is written in, holds
606
607
  the text to the shape of the format: %Y is four digits and %y two, %N
607
608
  one to nine digits, the other numbers one or two digits (two when a
@@ -1002,7 +1003,7 @@ ca_strp_supported (const char *f, long flen)
1002
1003
  /* One text in a format: CA_STRP_OK with the fields in *t, CA_STRP_FAIL,
1003
1004
  or CA_STRP_DEFER. */
1004
1005
  static int
1005
- ca_strp_text (VALUE str, const char *f, long flen, int strict, ca_strp_t *t)
1006
+ ca_strp_text (volatile VALUE str, const char *f, long flen, int strict, ca_strp_t *t)
1006
1007
  {
1007
1008
  const char *s = RSTRING_PTR(str);
1008
1009
  long n = RSTRING_LEN(str);
@@ -1053,7 +1054,7 @@ static VALUE
1053
1054
  rb_ca_strptime_fields (VALUE self, VALUE rformat, VALUE rstrict)
1054
1055
  {
1055
1056
  volatile VALUE src = self, rf = rformat;
1056
- VALUE fields[7];
1057
+ volatile VALUE fields[7];
1057
1058
  volatile VALUE unreadable, deferred;
1058
1059
  CArray *ca, *cf[7];
1059
1060
  int64_t *y, *mo, *d, *sod, *frac, *off;
@@ -1073,17 +1074,17 @@ rb_ca_strptime_fields (VALUE self, VALUE rformat, VALUE rstrict)
1073
1074
  if ( ! ca_strp_supported(f, flen) ) {
1074
1075
  return Qnil;
1075
1076
  }
1076
- TypedData_Get_Struct(src, CArray, &carray_data_type, ca);
1077
+ GetCArray(src, ca);
1077
1078
  if ( ca->data_type != CA_OBJECT ) {
1078
1079
  rb_raise(rb_eArgError, "strptime reading needs an object array");
1079
1080
  }
1080
1081
  if ( ! ca_is_entity(ca) || ! ca->ptr ) {
1081
1082
  src = rb_ca_copy(src);
1082
- TypedData_Get_Struct(src, CArray, &carray_data_type, ca);
1083
+ GetCArray(src, ca);
1083
1084
  }
1084
1085
  for (k = 0; k < 7; k++) {
1085
1086
  fields[k] = rb_carray_new(k == 6 ? CA_UINT8 : CA_INT64, 1, &ca->elements, 0, NULL);
1086
- TypedData_Get_Struct(fields[k], CArray, &carray_data_type, cf[k]);
1087
+ GetCArray(fields[k], cf[k]);
1087
1088
  }
1088
1089
  y = (int64_t *) cf[0]->ptr;
1089
1090
  mo = (int64_t *) cf[1]->ptr;
@@ -1098,7 +1099,7 @@ rb_ca_strptime_fields (VALUE self, VALUE rformat, VALUE rstrict)
1098
1099
  cells = (VALUE *) ca->ptr;
1099
1100
  m_in = ca_has_mask(ca) ? (boolean8_t *) ca->mask->ptr : NULL;
1100
1101
  for (i = 0; i < ca->elements; i++) {
1101
- VALUE v = cells[i];
1102
+ volatile VALUE v = cells[i];
1102
1103
  ca_strp_t t;
1103
1104
  int rc;
1104
1105
  y[i] = 1970; mo[i] = 1; d[i] = 1; sod[i] = 0; frac[i] = 0; off[i] = 0;
@@ -1140,8 +1141,6 @@ rb_ca_strptime_fields (VALUE self, VALUE rformat, VALUE rstrict)
1140
1141
  rb_ary_push(unreadable, SIZET2NUM(i));
1141
1142
  }
1142
1143
  }
1143
- RB_GC_GUARD(src);
1144
- RB_GC_GUARD(rf);
1145
1144
  return rb_ary_new_from_args(10, fields[0], fields[1], fields[2], fields[3],
1146
1145
  fields[4], fields[5], fields[6],
1147
1146
  unreadable, deferred, INT2NUM(fraction));
@@ -1158,7 +1157,7 @@ rb_ca_s_strptime_fits (VALUE klass, VALUE text, VALUE formats)
1158
1157
  StringValue(text);
1159
1158
  Check_Type(formats, T_ARRAY);
1160
1159
  for (i = 0; i < RARRAY_LEN(formats); i++) {
1161
- VALUE f = rb_ary_entry(formats, i);
1160
+ volatile VALUE f = rb_ary_entry(formats, i);
1162
1161
  ca_strp_t t;
1163
1162
  StringValue(f);
1164
1163
  if ( ca_strp_supported(RSTRING_PTR(f), RSTRING_LEN(f))