carray 3.0.7 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +7 -1940
- data/README.md +38 -32
- data/carray.gemspec +16 -4
- data/docs/changelogs/CHANGELOG-3.0.md +2464 -0
- data/ext/ca_array_pool.c +4 -5
- data/ext/ca_axis_descriptor.h +45 -30
- data/ext/ca_axis_dispatch.c +7 -4
- data/ext/ca_axis_group.c +6 -9
- data/ext/ca_bincmp_dispatch.h +16 -38
- data/ext/ca_binop_dispatch.c +27 -0
- data/ext/ca_binop_dispatch.h +22 -47
- data/ext/ca_categorical_iterator.c +36 -34
- data/ext/ca_compare.c +0 -1
- data/ext/ca_compare.h +8 -1
- data/ext/ca_composite_dispatch.h +6 -0
- data/ext/ca_for_buffer.h +6 -1
- data/ext/ca_group_iter.c +17 -18
- data/ext/ca_iter_state_fields.h +196 -0
- data/ext/ca_iter_substrate.h +84 -103
- data/ext/ca_kernel_iterator.c +125 -89
- data/ext/ca_kernel_iterator.h +229 -1506
- data/ext/ca_kernel_iterator_internal.h +1167 -0
- data/ext/ca_moncmp_dispatch.h +17 -24
- data/ext/ca_monop_dispatch.h +25 -74
- data/ext/ca_obj_array.c +90 -163
- data/ext/ca_obj_bincmp.c +47 -46
- data/ext/ca_obj_binop.c +38 -38
- data/ext/ca_obj_bitarray.c +5 -17
- data/ext/ca_obj_bitfield.c +15 -30
- data/ext/ca_obj_block.c +11 -12
- data/ext/ca_obj_byte_swap.c +32 -30
- data/ext/ca_obj_const_string.c +57 -62
- data/ext/ca_obj_face.c +99 -91
- data/ext/ca_obj_face.h +32 -170
- data/ext/ca_obj_fake.c +15 -21
- data/ext/ca_obj_farray.c +7 -9
- data/ext/ca_obj_field.c +17 -13
- data/ext/ca_obj_fixlen_string.c +8 -19
- data/ext/ca_obj_grid.c +137 -106
- data/ext/ca_obj_meld.c +23 -21
- data/ext/ca_obj_moncmp.c +10 -21
- data/ext/ca_obj_monop.c +24 -35
- data/ext/ca_obj_object.c +51 -37
- data/ext/ca_obj_record.c +74 -22
- data/ext/ca_obj_reduce.c +8 -10
- data/ext/ca_obj_refer.c +42 -29
- data/ext/ca_obj_remap.c +11 -29
- data/ext/ca_obj_repeat.c +41 -23
- data/ext/ca_obj_roll.c +18 -24
- data/ext/ca_obj_select.c +10 -22
- data/ext/ca_obj_select_axis.c +27 -36
- data/ext/ca_obj_shift.c +22 -42
- data/ext/ca_obj_source.c +1 -5
- data/ext/ca_obj_stack.c +28 -24
- data/ext/ca_obj_stride.c +53 -54
- data/ext/ca_obj_string.c +6 -18
- data/ext/ca_obj_tile.c +12 -12
- data/ext/ca_obj_time.c +12 -23
- data/ext/ca_obj_timedelta.c +12 -23
- data/ext/ca_obj_transpose.c +8 -10
- data/ext/ca_obj_triop.c +35 -39
- data/ext/ca_obj_window.c +67 -86
- data/ext/ca_op_cmplx64.h +4 -0
- data/ext/ca_op_ipower.c +34 -12
- data/ext/ca_op_powi.h +4 -0
- data/ext/ca_pow5_table.h +2 -1
- data/ext/ca_rng_normal.h +4 -0
- data/ext/ca_rng_xoshiro256pp.h +3 -0
- data/ext/ca_sort_kernels.h +20 -26
- data/ext/ca_sweep_engine.c +2 -3
- data/ext/ca_sweep_engine.h +17 -9
- data/ext/ca_transform_common.c +3 -8
- data/ext/ca_triop_dispatch.h +20 -32
- data/ext/caframe_csv_reader.c +11 -11
- data/ext/carray.h +300 -1011
- data/ext/carray_access.c +234 -180
- data/ext/carray_address_basis.c +33 -38
- data/ext/carray_attribute.c +81 -104
- data/ext/carray_bincount.c +12 -14
- data/ext/carray_broadcast.c +30 -26
- data/ext/carray_call_cfunc.c +169 -277
- data/ext/carray_call_cfunc.h +36 -28
- data/ext/carray_cast.c +912 -346
- data/ext/carray_cast_func.rb +31 -3
- data/ext/carray_class.c +6 -11
- data/ext/carray_conversion.c +43 -38
- data/ext/carray_copy.c +28 -26
- data/ext/carray_core.c +217 -126
- data/ext/carray_count.c +27 -15
- data/ext/carray_element.c +40 -25
- data/ext/carray_factorize.c +53 -52
- data/ext/carray_generate.c +26 -19
- data/ext/carray_histogram.c +8 -10
- data/ext/carray_hold.c +7 -9
- data/ext/carray_index_classifier.c +123 -228
- data/ext/carray_index_classifier.h +11 -10
- data/ext/carray_integer_total.c +523 -0
- data/ext/carray_internal.h +1274 -160
- data/ext/carray_key_windows.c +3 -3
- data/ext/carray_lazy.c +21 -36
- data/ext/carray_loop.c +19 -22
- data/ext/carray_mask.c +123 -145
- data/ext/carray_math_kernel.h +23 -47
- data/ext/carray_mathfunc.c +10 -3
- data/ext/carray_median_percentile.c +95 -94
- data/ext/carray_memory_view.c +42 -47
- data/ext/carray_operator.c +423 -122
- data/ext/carray_order.c +121 -85
- data/ext/carray_partition.c +13 -15
- data/ext/carray_random.c +47 -41
- data/ext/carray_round.c +9 -4
- data/ext/carray_scatter.c +54 -40
- data/ext/carray_segment.c +41 -45
- data/ext/carray_slab.c +64 -47
- data/ext/carray_slab.h +44 -33
- data/ext/carray_sort.c +32 -29
- data/ext/carray_sort_kernel.c +12 -10
- data/ext/carray_struct.c +38 -43
- data/ext/carray_test.c +47 -43
- data/ext/carray_time_text.c +24 -31
- data/ext/carray_undef.c +50 -7
- data/ext/carray_utils.c +258 -94
- data/ext/extconf.rb +24 -17
- data/ext/mk_call_cfunc.rb +19 -20
- data/ext/mk_pow5_table.rb +2 -1
- data/ext/mkkernel.rb +782 -461
- data/ext/ruby_carray.c +47 -42
- data/ext/version.h +7 -5
- data/lib/carray/attribute.rb +19 -18
- data/lib/carray/autoload_carray.rb +20 -15
- data/lib/carray/autoload_method_extension.rb +64 -57
- data/lib/carray/axis_group.rb +264 -180
- data/lib/carray/basics.rb +272 -48
- data/lib/carray/bincount_nd.rb +33 -16
- data/lib/carray/block_iterator.rb +123 -102
- data/lib/carray/boolean_reduce.rb +7 -4
- data/lib/carray/categorical.rb +63 -51
- data/lib/carray/categorical_iterator.rb +89 -67
- data/lib/carray/complex.rb +61 -41
- data/lib/carray/conditional.rb +49 -22
- data/lib/carray/const_string.rb +54 -62
- data/lib/carray/core_extensions.rb +1 -1
- data/lib/carray/distance_limit.rb +7 -5
- data/lib/carray/factories.rb +269 -0
- data/lib/carray/fixlen_string.rb +25 -24
- data/lib/carray/frame/column_verbs.rb +20 -8
- data/lib/carray/frame/concat.rb +3 -3
- data/lib/carray/frame/convert.rb +2 -1
- data/lib/carray/frame/csv_parser.rb +7 -1
- data/lib/carray/frame/frame.rb +35 -25
- data/lib/carray/frame/group.rb +183 -150
- data/lib/carray/frame/io.rb +26 -7
- data/lib/carray/frame/join.rb +37 -12
- data/lib/carray/frame/records.rb +1 -1
- data/lib/carray/frame/reshape.rb +3 -3
- data/lib/carray/frame/sort.rb +10 -8
- data/lib/carray/frame/verbs.rb +148 -118
- data/lib/carray/frame/windows.rb +232 -21
- data/lib/carray/frame.rb +1 -2
- data/lib/carray/fuse_source.rb +24 -21
- data/lib/carray/fusion.rb +30 -30
- data/lib/carray/histogram.rb +35 -16
- data/lib/carray/inspect.rb +7 -7
- data/lib/carray/iterator.rb +97 -24
- data/lib/carray/key_windows.rb +83 -57
- data/lib/carray/lazy.rb +196 -94
- data/lib/carray/limits.rb +80 -0
- data/lib/carray/mask_gap_fill.rb +21 -16
- data/lib/carray/math.rb +87 -50
- data/lib/carray/meld_reduce.rb +30 -8
- data/lib/carray/methods/align_addr.rb +29 -17
- data/lib/carray/methods/bin.rb +5 -1
- data/lib/carray/methods/bincount.rb +4 -2
- data/lib/carray/methods/bit_string.rb +19 -31
- data/lib/carray/methods/broadcast.rb +8 -3
- data/lib/carray/methods/choose.rb +5 -5
- data/lib/carray/methods/composition.rb +72 -71
- data/lib/carray/methods/{index.rb → coordinate.rb} +13 -13
- data/lib/carray/methods/discovery_along.rb +3 -3
- data/lib/carray/methods/gather_nd.rb +106 -106
- data/lib/carray/methods/insert_block.rb +2 -2
- data/lib/carray/methods/is_between.rb +6 -4
- data/lib/carray/methods/is_in.rb +165 -145
- data/lib/carray/methods/join.rb +2 -1
- data/lib/carray/methods/lag.rb +6 -2
- data/lib/carray/methods/locate_addr.rb +150 -138
- data/lib/carray/methods/mask_duplicates.rb +1 -1
- data/lib/carray/methods/meshgrid.rb +28 -16
- data/lib/carray/methods/mode.rb +67 -67
- data/lib/carray/methods/nunique.rb +9 -7
- data/lib/carray/methods/repeat.rb +12 -12
- data/lib/carray/methods/resize.rb +1 -1
- data/lib/carray/methods/snap.rb +24 -20
- data/lib/carray/methods/string_format.rb +2 -2
- data/lib/carray/methods/unique.rb +4 -2
- data/lib/carray/methods/value_counts.rb +1 -1
- data/lib/carray/mkmf.rb +25 -28
- data/lib/carray/percentile_arguments.rb +82 -0
- data/lib/carray/record_order.rb +18 -17
- data/lib/carray/rng.rb +1 -0
- data/lib/carray/runtime.rb +190 -22
- data/lib/carray/segment_iterator.rb +251 -129
- data/lib/carray/serialize.rb +618 -571
- data/lib/carray/slab_iterator.rb +114 -114
- data/lib/carray/stack.rb +11 -12
- data/lib/carray/string.rb +16 -22
- data/lib/carray/string_operation_extension.rb +76 -52
- data/lib/carray/struct.rb +122 -164
- data/lib/carray/struct_builder.rb +243 -72
- data/lib/carray/time.rb +496 -342
- data/lib/carray/window_iterator.rb +191 -150
- data/lib/carray.rb +6 -11
- data/yard-stubs/ca_obj_array.rb +20 -135
- data/yard-stubs/ca_obj_bitarray.rb +1 -8
- data/yard-stubs/ca_obj_bitfield.rb +4 -3
- data/yard-stubs/ca_obj_byte_swap.rb +21 -7
- data/yard-stubs/ca_obj_fake.rb +3 -1
- data/yard-stubs/ca_obj_farray.rb +1 -1
- data/yard-stubs/ca_obj_field.rb +8 -6
- data/yard-stubs/ca_obj_refer.rb +7 -5
- data/yard-stubs/ca_obj_roll.rb +7 -6
- data/yard-stubs/ca_obj_shift.rb +2 -3
- data/yard-stubs/ca_obj_stride.rb +5 -7
- data/yard-stubs/ca_obj_tile.rb +1 -1
- data/yard-stubs/ca_obj_time.rb +43 -0
- data/yard-stubs/ca_obj_transpose.rb +1 -1
- data/yard-stubs/ca_obj_window.rb +26 -15
- data/yard-stubs/carray_access.rb +51 -4
- data/yard-stubs/carray_attribute.rb +26 -38
- data/yard-stubs/carray_cast.rb +118 -165
- data/yard-stubs/carray_class.rb +3 -4
- data/yard-stubs/carray_conversion.rb +6 -7
- data/yard-stubs/carray_copy.rb +2 -1
- data/yard-stubs/carray_count.rb +5 -3
- data/yard-stubs/carray_element.rb +4 -3
- data/yard-stubs/carray_limits.rb +100 -0
- data/yard-stubs/carray_loop.rb +0 -20
- data/yard-stubs/carray_mask.rb +59 -41
- data/yard-stubs/carray_math.rb +157 -100
- data/yard-stubs/carray_mathfunc.rb +415 -3
- data/yard-stubs/carray_median_percentile.rb +29 -11
- data/yard-stubs/carray_memory_view.rb +2 -2
- data/yard-stubs/carray_order.rb +67 -34
- data/yard-stubs/carray_random.rb +6 -6
- data/yard-stubs/carray_reduce.rb +353 -0
- data/yard-stubs/carray_rng.rb +92 -0
- data/yard-stubs/carray_scatter.rb +10 -2
- data/yard-stubs/carray_slab.rb +7 -4
- data/yard-stubs/carray_sort.rb +7 -6
- data/yard-stubs/carray_undef.rb +44 -5
- data/yard-stubs/ruby_carray.rb +75 -40
- metadata +62 -24
- data/CHANGELOG.v1.md +0 -126
- data/ext/carray_build_flags.h +0 -3
- data/ext/carray_config.h +0 -28
- data/ext/carray_data_type.c +0 -90
- data/ext/carray_kernels_bincmp.c +0 -6457
- data/ext/carray_kernels_binop.c +0 -31534
- data/ext/carray_kernels_init.c +0 -1734
- data/ext/carray_kernels_moncmp.c +0 -2104
- data/ext/carray_kernels_monop.c +0 -25337
- data/ext/carray_kernels_reduce_aggregate.c +0 -27545
- data/ext/carray_kernels_reduce_boolean.c +0 -1924
- data/ext/carray_kernels_reduce_cumulative.c +0 -11646
- data/ext/carray_kernels_reduce_extreme.c +0 -21631
- data/ext/carray_kernels_reduce_variance.c +0 -5981
- data/ext/carray_kernels_scan.c +0 -4302
- data/ext/carray_kernels_search.c +0 -37776
- data/ext/carray_kernels_sort.c +0 -10814
- data/ext/carray_kernels_triop.c +0 -1864
- data/lib/carray/construct.rb +0 -360
- data/lib/carray/data_type_extension.rb +0 -262
- data/lib/carray/data_type_limits.rb +0 -91
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# CAStruct::Builder -- the DSL backend behind CArray.struct { ... } and
|
|
2
2
|
# CArray.union { ... }. Autoloaded from lib/carray/struct.rb on first
|
|
3
3
|
# reference to CAStruct::Builder, so applications that only consume
|
|
4
|
-
# pre-defined struct classes never
|
|
4
|
+
# pre-defined struct classes never load the Builder.
|
|
5
5
|
|
|
6
6
|
# ---------------------------------------------------------------------
|
|
7
7
|
#
|
|
@@ -13,7 +13,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
13
13
|
|
|
14
14
|
class Member # :nodoc:
|
|
15
15
|
|
|
16
|
-
def initialize
|
|
16
|
+
def initialize(name, type, opt={})
|
|
17
17
|
@name, @type, @opt = name, type, opt
|
|
18
18
|
if @type == :bitfield
|
|
19
19
|
# Bit members carry their own offset/length math via the
|
|
@@ -49,7 +49,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
49
49
|
# `data_size` is the struct's DATA_SIZE; needed up front so we can
|
|
50
50
|
# bounds-check bit-field projections at definition time rather than
|
|
51
51
|
# at first access.
|
|
52
|
-
def self.build_dispatch_table
|
|
52
|
+
def self.build_dispatch_table(member_table, data_size)
|
|
53
53
|
dispatch = {}
|
|
54
54
|
member_table.each do |name, entry|
|
|
55
55
|
offset, type, opts = *entry
|
|
@@ -104,7 +104,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
104
104
|
FAST_KIND_ENDIAN = 2
|
|
105
105
|
|
|
106
106
|
# @!visibility private
|
|
107
|
-
def self.build_fast_primitives
|
|
107
|
+
private_class_method def self.build_fast_primitives(member_table, data_size = nil)
|
|
108
108
|
fast = {}
|
|
109
109
|
host_endian = CArray.endian
|
|
110
110
|
member_table.each do |name, entry|
|
|
@@ -139,7 +139,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
139
139
|
# word reaches past DATA_SIZE -- the existing build_bitfield_dispatcher
|
|
140
140
|
# raises in that case at definition time; here we just bow out and
|
|
141
141
|
# let DISPATCH_TABLE raise).
|
|
142
|
-
def self.build_fast_bitfield_entry
|
|
142
|
+
private_class_method def self.build_fast_bitfield_entry(opts, data_size)
|
|
143
143
|
bits = opts[:bits]
|
|
144
144
|
bit_offset = opts[:bit_offset]
|
|
145
145
|
start_byte = bit_offset / 8
|
|
@@ -159,11 +159,10 @@ class CAStruct::Builder # :nodoc:
|
|
|
159
159
|
# an actual byte swap on the current host. Matches CArray#endian's
|
|
160
160
|
# short-circuit logic: :preserve and :native are always identity;
|
|
161
161
|
# :big / :little are identity when the host already matches.
|
|
162
|
-
def self.endian_needs_swap?
|
|
162
|
+
private_class_method def self.endian_needs_swap?(endian_sym, host_endian)
|
|
163
163
|
case endian_sym
|
|
164
164
|
when :preserve, :native then false
|
|
165
|
-
when :big
|
|
166
|
-
when :little then host_endian != CA_LITTLE_ENDIAN
|
|
165
|
+
when :big, :little then host_endian != endian_sym
|
|
167
166
|
else false # unknown sym — be conservative, defer to DISPATCH_TABLE
|
|
168
167
|
end
|
|
169
168
|
end
|
|
@@ -202,7 +201,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
202
201
|
|
|
203
202
|
# -- per-kind dispatcher builders -------------------------------------
|
|
204
203
|
|
|
205
|
-
def self.build_bitfield_dispatcher
|
|
204
|
+
private_class_method def self.build_bitfield_dispatcher(name, opts, data_size)
|
|
206
205
|
bits = opts[:bits]
|
|
207
206
|
bit_offset = opts[:bit_offset]
|
|
208
207
|
start_byte = bit_offset / 8
|
|
@@ -240,7 +239,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
240
239
|
# parent's own bytes (a field view), so writing to it writes to the
|
|
241
240
|
# parent, as writing to an array member does. A frozen parent gives a
|
|
242
241
|
# frozen nested element.
|
|
243
|
-
def self.build_nested_struct_dispatcher
|
|
242
|
+
private_class_method def self.build_nested_struct_dispatcher(offset, nested_class)
|
|
244
243
|
reader = ->(data) {
|
|
245
244
|
element = nested_class.allocate
|
|
246
245
|
element.instance_variable_set(:@data, data.field(offset, nested_class).send(:face_storage))
|
|
@@ -252,14 +251,14 @@ class CAStruct::Builder # :nodoc:
|
|
|
252
251
|
end
|
|
253
252
|
|
|
254
253
|
# @!visibility private
|
|
255
|
-
def self.build_carray_template_dispatcher
|
|
254
|
+
private_class_method def self.build_carray_template_dispatcher(offset, template)
|
|
256
255
|
reader = ->(data) { data.field(offset, template)[0, false] }
|
|
257
256
|
writer = ->(data, val) { data.field(offset, template)[0, false] = val }
|
|
258
257
|
[reader, writer].freeze
|
|
259
258
|
end
|
|
260
259
|
|
|
261
260
|
# @!visibility private
|
|
262
|
-
def self.build_primitive_dispatcher
|
|
261
|
+
private_class_method def self.build_primitive_dispatcher(offset, type, opts)
|
|
263
262
|
# Specialise the reader/writer to the smallest amount of work
|
|
264
263
|
# this particular member needs: no opts → 2-arg field; opts with
|
|
265
264
|
# only :bytes → 3-arg field; opts with :endian → 3-arg field +
|
|
@@ -293,34 +292,23 @@ class CAStruct::Builder # :nodoc:
|
|
|
293
292
|
# Shared with every Ractor when it can be. A member whose type is an
|
|
294
293
|
# array template holds a CArray, which cannot be shared, and its struct
|
|
295
294
|
# is then used in the main Ractor only.
|
|
296
|
-
def self.shareable
|
|
295
|
+
private_class_method def self.shareable(object)
|
|
297
296
|
Ractor.make_shareable(object)
|
|
298
297
|
rescue Ractor::Error
|
|
299
298
|
object.freeze
|
|
300
299
|
end
|
|
301
300
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
CA_UINT16 => CA_ALIGN_INT16,
|
|
309
|
-
CA_INT32 => CA_ALIGN_INT32,
|
|
310
|
-
CA_UINT32 => CA_ALIGN_INT32,
|
|
311
|
-
CA_INT64 => CA_ALIGN_INT64,
|
|
312
|
-
CA_UINT64 => CA_ALIGN_INT64,
|
|
313
|
-
CA_FLOAT32 => CA_ALIGN_FLOAT32,
|
|
314
|
-
CA_FLOAT64 => CA_ALIGN_FLOAT64,
|
|
315
|
-
CA_CMPLX64 => CA_ALIGN_FLOAT32,
|
|
316
|
-
CA_CMPLX128 => CA_ALIGN_FLOAT64,
|
|
317
|
-
}
|
|
318
|
-
Ractor.make_shareable(ALIGN_TABLE)
|
|
301
|
+
# The alignment of each member type, as the C compiler lays it out
|
|
302
|
+
# (data type Symbol => bytes), and of a pointer.
|
|
303
|
+
ALIGN_TABLE = Ractor.make_shareable(
|
|
304
|
+
CArray.const_get(:STRUCT_ALIGNMENT).reject { |type, _| type == :voidp })
|
|
305
|
+
ALIGN_VOIDP = CArray.const_get(:STRUCT_ALIGNMENT)[:voidp]
|
|
306
|
+
private_constant :ALIGN_TABLE, :ALIGN_VOIDP
|
|
319
307
|
|
|
320
308
|
# Raises ArgumentError when `opt` names a key outside `allowed`. The
|
|
321
309
|
# options are read one key at a time, so a misspelt key would otherwise
|
|
322
310
|
# be ignored and the layout would change without a word.
|
|
323
|
-
def self.check_keys!
|
|
311
|
+
private_class_method def self.check_keys!(opt, allowed, where)
|
|
324
312
|
unknown = opt.keys - allowed
|
|
325
313
|
return if unknown.empty?
|
|
326
314
|
raise ArgumentError, "#{where}: unknown keyword#{unknown.size > 1 ? "s" : ""}: " +
|
|
@@ -331,14 +319,17 @@ class CAStruct::Builder # :nodoc:
|
|
|
331
319
|
MEMBER_KEYS = [:offset, :bytes, :endian].freeze
|
|
332
320
|
NESTED_KEYS = (BUILDER_KEYS + [:type, :offset]).freeze
|
|
333
321
|
|
|
334
|
-
def initialize
|
|
335
|
-
CAStruct::Builder.check_keys
|
|
336
|
-
|
|
322
|
+
def initialize(type, opt = {})
|
|
323
|
+
CAStruct::Builder.send(:check_keys!, opt, BUILDER_KEYS, type.to_s)
|
|
324
|
+
# pack: 1 places each member right after the previous one; nil aligns
|
|
325
|
+
# each member to its type. A packing bound other than 1 is not
|
|
326
|
+
# implemented, so it is refused rather than read as 1.
|
|
327
|
+
unless opt[:pack].nil? or opt[:pack].equal?(1)
|
|
337
328
|
raise CAStruct::DefinitionError,
|
|
338
|
-
"invalid :pack value #{opt[:pack].inspect} (expected nil or
|
|
329
|
+
"invalid :pack value #{opt[:pack].inspect} (expected nil or 1)"
|
|
339
330
|
end
|
|
340
331
|
@type = type ### :struct or :union
|
|
341
|
-
@align = opt[:pack] ### nil
|
|
332
|
+
@align = opt[:pack] ### nil aligns each member, 1 packs them
|
|
342
333
|
@members = [] ### array of CArray::Struct::Builder::Member
|
|
343
334
|
@offset = 0 ### offset of each member and size of struct
|
|
344
335
|
@extent = 0 ### furthest byte any member reaches
|
|
@@ -351,7 +342,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
351
342
|
# The `order_by:` members, as member names. Each has to be a member of
|
|
352
343
|
# this struct that holds one ordered value: not a nested record, an array
|
|
353
344
|
# member or a complex number.
|
|
354
|
-
def order_keys
|
|
345
|
+
def order_keys(table)
|
|
355
346
|
keys = Array(@order_by).map(&:to_s)
|
|
356
347
|
if keys.empty?
|
|
357
348
|
raise CAStruct::DefinitionError, "order_by: names no member"
|
|
@@ -388,9 +379,10 @@ class CAStruct::Builder # :nodoc:
|
|
|
388
379
|
@bit_offset = 0
|
|
389
380
|
end
|
|
390
381
|
end
|
|
382
|
+
private :flush_bit_offset
|
|
391
383
|
|
|
392
|
-
#
|
|
393
|
-
def define
|
|
384
|
+
# Runs the definition block and returns the struct class it describes.
|
|
385
|
+
private def define(&block)
|
|
394
386
|
# ---
|
|
395
387
|
case block.arity
|
|
396
388
|
when 1
|
|
@@ -475,9 +467,9 @@ class CAStruct::Builder # :nodoc:
|
|
|
475
467
|
end
|
|
476
468
|
table.freeze
|
|
477
469
|
names.freeze
|
|
478
|
-
klass.const_set(:MEMBER_TABLE, self.class.shareable
|
|
479
|
-
klass.const_set(:MEMBERS, self.class.shareable
|
|
480
|
-
klass.const_set(:ORDER_BY, self.class.shareable
|
|
470
|
+
klass.const_set(:MEMBER_TABLE, self.class.send(:shareable, table)) ### required element as data class
|
|
471
|
+
klass.const_set(:MEMBERS, self.class.send(:shareable, names))
|
|
472
|
+
klass.const_set(:ORDER_BY, self.class.send(:shareable, order_keys(table))) if @order_by
|
|
481
473
|
# ---
|
|
482
474
|
# Step 3 dispatch table: precompute a per-member [reader, writer]
|
|
483
475
|
# Proc pair so `record[name]` is one Hash lookup + one Proc call,
|
|
@@ -485,7 +477,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
485
477
|
# checks and view-shape decisions happen here, once, at class
|
|
486
478
|
# definition time.
|
|
487
479
|
klass.const_set(:DISPATCH_TABLE,
|
|
488
|
-
self.class.shareable
|
|
480
|
+
self.class.send(:shareable, self.class.build_dispatch_table(table, @offset)))
|
|
489
481
|
# Also precompute FAST_PRIMITIVES, the subset of members that the
|
|
490
482
|
# C-side `[]` / `[]=` can handle without
|
|
491
483
|
# allocating a CAField view. Entries are `[offset, type_code]`;
|
|
@@ -494,7 +486,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
494
486
|
# members are absent here -- they stay on the DISPATCH_TABLE Proc
|
|
495
487
|
# path.
|
|
496
488
|
klass.const_set(:FAST_PRIMITIVES,
|
|
497
|
-
self.class.build_fast_primitives
|
|
489
|
+
self.class.send(:build_fast_primitives, table, @offset).freeze)
|
|
498
490
|
# ---
|
|
499
491
|
# An accessor for each member, unless the name is already a method of
|
|
500
492
|
# the element (hash, size, class, initialize, ...): the accessor would
|
|
@@ -522,8 +514,8 @@ class CAStruct::Builder # :nodoc:
|
|
|
522
514
|
|
|
523
515
|
private
|
|
524
516
|
|
|
525
|
-
def alignment
|
|
526
|
-
# ALIGN_TABLE keys are
|
|
517
|
+
def alignment(addr, data_type, opt={})
|
|
518
|
+
# ALIGN_TABLE keys are data type Symbols. Dispatch on
|
|
527
519
|
# Symbol directly; the Integer path (= raw data_type code) maps via the
|
|
528
520
|
# canonical Symbol name.
|
|
529
521
|
case data_type
|
|
@@ -538,7 +530,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
538
530
|
when Integer
|
|
539
531
|
align = ALIGN_TABLE[CArray.data_type_name(data_type).to_sym]
|
|
540
532
|
when CArray, Class
|
|
541
|
-
align =
|
|
533
|
+
align = ALIGN_VOIDP
|
|
542
534
|
else
|
|
543
535
|
data_type, bytes = CArray.guess_type_and_bytes(data_type, opt[:bytes])
|
|
544
536
|
return alignment(addr, data_type, :bytes=>bytes)
|
|
@@ -552,7 +544,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
552
544
|
return addr
|
|
553
545
|
end
|
|
554
546
|
|
|
555
|
-
def pack
|
|
547
|
+
def pack(addr, align, opt={})
|
|
556
548
|
if addr < 0
|
|
557
549
|
raise CAStruct::DefinitionError, format("negative member offset: %d", addr)
|
|
558
550
|
end
|
|
@@ -575,8 +567,8 @@ class CAStruct::Builder # :nodoc:
|
|
|
575
567
|
# when `nil`.
|
|
576
568
|
# @param opt [Hash] member options (`:offset`, `:bytes`, `:endian`, ...).
|
|
577
569
|
# @return [Member]
|
|
578
|
-
def member
|
|
579
|
-
CAStruct::Builder.check_keys
|
|
570
|
+
def member(data_type, id = nil, opt = {})
|
|
571
|
+
CAStruct::Builder.send(:check_keys!, opt, MEMBER_KEYS, "member")
|
|
580
572
|
opt = opt.clone
|
|
581
573
|
# If a bit member sequence was in flight, round up to a clean byte
|
|
582
574
|
# boundary before placing this byte-typed member.
|
|
@@ -630,12 +622,12 @@ class CAStruct::Builder # :nodoc:
|
|
|
630
622
|
# @return [Class] the nested struct class.
|
|
631
623
|
# @raise [CAStruct::DefinitionError] when neither a block nor
|
|
632
624
|
# `type:` is provided.
|
|
633
|
-
def struct
|
|
625
|
+
def struct(*args, &block)
|
|
634
626
|
opt = args.last.is_a?(Hash) ? args.pop : {}
|
|
635
|
-
CAStruct::Builder.check_keys
|
|
627
|
+
CAStruct::Builder.send(:check_keys!, opt, NESTED_KEYS, "struct")
|
|
636
628
|
if block
|
|
637
629
|
inner = {:pack => @align}.update(opt.slice(*BUILDER_KEYS))
|
|
638
|
-
st = self.class.new(:struct, inner).define
|
|
630
|
+
st = self.class.new(:struct, inner).send(:define, &block)
|
|
639
631
|
elsif opt[:type] and opt[:type] <= CAStruct
|
|
640
632
|
st = opt[:type]
|
|
641
633
|
else
|
|
@@ -657,12 +649,12 @@ class CAStruct::Builder # :nodoc:
|
|
|
657
649
|
# @return [Class] the nested union class.
|
|
658
650
|
# @raise [CAStruct::DefinitionError] when neither a block nor
|
|
659
651
|
# `type:` is provided.
|
|
660
|
-
def union
|
|
652
|
+
def union(*args, &block)
|
|
661
653
|
opt = args.last.is_a?(Hash) ? args.pop : {}
|
|
662
|
-
CAStruct::Builder.check_keys
|
|
654
|
+
CAStruct::Builder.send(:check_keys!, opt, NESTED_KEYS, "union")
|
|
663
655
|
if block
|
|
664
656
|
inner = {:pack => @align}.update(opt.slice(*BUILDER_KEYS))
|
|
665
|
-
st = self.class.new(:union, inner).define
|
|
657
|
+
st = self.class.new(:union, inner).send(:define, &block)
|
|
666
658
|
elsif opt[:type] and opt[:type] <= CAStruct
|
|
667
659
|
st = opt[:type]
|
|
668
660
|
else
|
|
@@ -682,9 +674,9 @@ class CAStruct::Builder # :nodoc:
|
|
|
682
674
|
# @return [void]
|
|
683
675
|
# @raise [CAStruct::DefinitionError] when `type:` is not a
|
|
684
676
|
# CArray template.
|
|
685
|
-
def array
|
|
677
|
+
def array(*args)
|
|
686
678
|
opt = args.last.is_a?(Hash) ? args.pop : {}
|
|
687
|
-
CAStruct::Builder.check_keys
|
|
679
|
+
CAStruct::Builder.send(:check_keys!, opt, [:type, :offset], "array")
|
|
688
680
|
if not opt[:type] or not opt[:type].kind_of?(CArray)
|
|
689
681
|
raise CAStruct::DefinitionError,
|
|
690
682
|
"no :type given for array member (expected a CArray template)"
|
|
@@ -708,7 +700,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
708
700
|
# @return [void]
|
|
709
701
|
# @raise [CAStruct::DefinitionError] on `:union` context, a
|
|
710
702
|
# missing name, or an invalid `bits` value.
|
|
711
|
-
def bit
|
|
703
|
+
def bit(name, bits:)
|
|
712
704
|
if @type == :union
|
|
713
705
|
raise CAStruct::DefinitionError,
|
|
714
706
|
"bit members in :union are not supported"
|
|
@@ -750,7 +742,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
750
742
|
# Validate the `endian:` option on a typed-member declaration.
|
|
751
743
|
# `allow` is false for non-numeric types (e.g. fixlen) where a
|
|
752
744
|
# byte-swap view would mangle the value.
|
|
753
|
-
def self.validate_endian!
|
|
745
|
+
private_class_method def self.validate_endian!(opt, typename, allow)
|
|
754
746
|
return unless opt.key?(:endian)
|
|
755
747
|
unless allow
|
|
756
748
|
raise CAStruct::DefinitionError,
|
|
@@ -763,6 +755,192 @@ class CAStruct::Builder # :nodoc:
|
|
|
763
755
|
end
|
|
764
756
|
end
|
|
765
757
|
|
|
758
|
+
# @!group Members by type
|
|
759
|
+
|
|
760
|
+
# @!method boolean(*names, offset: nil, endian: nil)
|
|
761
|
+
# Declares one `:boolean` member for each name, in order.
|
|
762
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
763
|
+
# declares an unnamed member, which serves as padding.
|
|
764
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
765
|
+
# struct (`pack:`), in place of the next position.
|
|
766
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
767
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
768
|
+
# @return [void]
|
|
769
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
770
|
+
# `offset:` is given in a struct that is not packed.
|
|
771
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
772
|
+
|
|
773
|
+
# @!method int8(*names, offset: nil, endian: nil)
|
|
774
|
+
# Declares one `:int8` member for each name, in order.
|
|
775
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
776
|
+
# declares an unnamed member, which serves as padding.
|
|
777
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
778
|
+
# struct (`pack:`), in place of the next position.
|
|
779
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
780
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
781
|
+
# @return [void]
|
|
782
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
783
|
+
# `offset:` is given in a struct that is not packed.
|
|
784
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
785
|
+
|
|
786
|
+
# @!method uint8(*names, offset: nil, endian: nil)
|
|
787
|
+
# Declares one `:uint8` member for each name, in order.
|
|
788
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
789
|
+
# declares an unnamed member, which serves as padding.
|
|
790
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
791
|
+
# struct (`pack:`), in place of the next position.
|
|
792
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
793
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
794
|
+
# @return [void]
|
|
795
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
796
|
+
# `offset:` is given in a struct that is not packed.
|
|
797
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
798
|
+
|
|
799
|
+
# @!method int16(*names, offset: nil, endian: nil)
|
|
800
|
+
# Declares one `:int16` member for each name, in order.
|
|
801
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
802
|
+
# declares an unnamed member, which serves as padding.
|
|
803
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
804
|
+
# struct (`pack:`), in place of the next position.
|
|
805
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
806
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
807
|
+
# @return [void]
|
|
808
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
809
|
+
# `offset:` is given in a struct that is not packed.
|
|
810
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
811
|
+
|
|
812
|
+
# @!method uint16(*names, offset: nil, endian: nil)
|
|
813
|
+
# Declares one `:uint16` member for each name, in order.
|
|
814
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
815
|
+
# declares an unnamed member, which serves as padding.
|
|
816
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
817
|
+
# struct (`pack:`), in place of the next position.
|
|
818
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
819
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
820
|
+
# @return [void]
|
|
821
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
822
|
+
# `offset:` is given in a struct that is not packed.
|
|
823
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
824
|
+
|
|
825
|
+
# @!method int32(*names, offset: nil, endian: nil)
|
|
826
|
+
# Declares one `:int32` member for each name, in order.
|
|
827
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
828
|
+
# declares an unnamed member, which serves as padding.
|
|
829
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
830
|
+
# struct (`pack:`), in place of the next position.
|
|
831
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
832
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
833
|
+
# @return [void]
|
|
834
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
835
|
+
# `offset:` is given in a struct that is not packed.
|
|
836
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
837
|
+
|
|
838
|
+
# @!method uint32(*names, offset: nil, endian: nil)
|
|
839
|
+
# Declares one `:uint32` member for each name, in order.
|
|
840
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
841
|
+
# declares an unnamed member, which serves as padding.
|
|
842
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
843
|
+
# struct (`pack:`), in place of the next position.
|
|
844
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
845
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
846
|
+
# @return [void]
|
|
847
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
848
|
+
# `offset:` is given in a struct that is not packed.
|
|
849
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
850
|
+
|
|
851
|
+
# @!method int64(*names, offset: nil, endian: nil)
|
|
852
|
+
# Declares one `:int64` member for each name, in order.
|
|
853
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
854
|
+
# declares an unnamed member, which serves as padding.
|
|
855
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
856
|
+
# struct (`pack:`), in place of the next position.
|
|
857
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
858
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
859
|
+
# @return [void]
|
|
860
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
861
|
+
# `offset:` is given in a struct that is not packed.
|
|
862
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
863
|
+
|
|
864
|
+
# @!method uint64(*names, offset: nil, endian: nil)
|
|
865
|
+
# Declares one `:uint64` member for each name, in order.
|
|
866
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
867
|
+
# declares an unnamed member, which serves as padding.
|
|
868
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
869
|
+
# struct (`pack:`), in place of the next position.
|
|
870
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
871
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
872
|
+
# @return [void]
|
|
873
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
874
|
+
# `offset:` is given in a struct that is not packed.
|
|
875
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
876
|
+
|
|
877
|
+
# @!method float32(*names, offset: nil, endian: nil)
|
|
878
|
+
# Declares one `:float32` member for each name, in order.
|
|
879
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
880
|
+
# declares an unnamed member, which serves as padding.
|
|
881
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
882
|
+
# struct (`pack:`), in place of the next position.
|
|
883
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
884
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
885
|
+
# @return [void]
|
|
886
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
887
|
+
# `offset:` is given in a struct that is not packed.
|
|
888
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
889
|
+
|
|
890
|
+
# @!method float64(*names, offset: nil, endian: nil)
|
|
891
|
+
# Declares one `:float64` member for each name, in order.
|
|
892
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
893
|
+
# declares an unnamed member, which serves as padding.
|
|
894
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
895
|
+
# struct (`pack:`), in place of the next position.
|
|
896
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
897
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
898
|
+
# @return [void]
|
|
899
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
900
|
+
# `offset:` is given in a struct that is not packed.
|
|
901
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
902
|
+
|
|
903
|
+
# @!method cmplx64(*names, offset: nil, endian: nil)
|
|
904
|
+
# Declares one `:cmplx64` member for each name, in order.
|
|
905
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
906
|
+
# declares an unnamed member, which serves as padding.
|
|
907
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
908
|
+
# struct (`pack:`), in place of the next position.
|
|
909
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
910
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
911
|
+
# @return [void]
|
|
912
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
913
|
+
# `offset:` is given in a struct that is not packed.
|
|
914
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
915
|
+
|
|
916
|
+
# @!method cmplx128(*names, offset: nil, endian: nil)
|
|
917
|
+
# Declares one `:cmplx128` member for each name, in order.
|
|
918
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
919
|
+
# declares an unnamed member, which serves as padding.
|
|
920
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
921
|
+
# struct (`pack:`), in place of the next position.
|
|
922
|
+
# @param endian [Symbol, nil] byte order of the stored value:
|
|
923
|
+
# `:preserve`, `:native`, `:big` or `:little`.
|
|
924
|
+
# @return [void]
|
|
925
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
926
|
+
# `offset:` is given in a struct that is not packed.
|
|
927
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
928
|
+
|
|
929
|
+
# @!method fixlen(*names, bytes:, offset: nil)
|
|
930
|
+
# Declares one fixed-length byte-string member of `bytes` bytes for
|
|
931
|
+
# each name, in order.
|
|
932
|
+
# @param names [Array<Symbol, String, nil>] member names; `nil`
|
|
933
|
+
# declares an unnamed member, which serves as padding.
|
|
934
|
+
# @param bytes [Integer] length of the member in bytes.
|
|
935
|
+
# @param offset [Integer, nil] byte offset of the member in a packed
|
|
936
|
+
# struct (`pack:`), in place of the next position.
|
|
937
|
+
# @return [void]
|
|
938
|
+
# @raise [CAStruct::DefinitionError] when no name is given, or when
|
|
939
|
+
# `offset:` is given in a struct that is not packed.
|
|
940
|
+
# @raise [ArgumentError] on an unknown keyword.
|
|
941
|
+
|
|
942
|
+
# @!endgroup
|
|
943
|
+
|
|
766
944
|
[
|
|
767
945
|
["fixlen", false],
|
|
768
946
|
["boolean", true],
|
|
@@ -780,15 +958,15 @@ class CAStruct::Builder # :nodoc:
|
|
|
780
958
|
["cmplx128", true],
|
|
781
959
|
].each do |typename, allow_endian|
|
|
782
960
|
class_eval %{
|
|
783
|
-
def #{typename}
|
|
961
|
+
def #{typename}(*args)
|
|
784
962
|
opt = args.last.is_a?(Hash) ? args.pop : {}
|
|
785
963
|
if args.empty?
|
|
786
964
|
raise CAStruct::DefinitionError,
|
|
787
965
|
"#{typename} requires at least one member name " \
|
|
788
966
|
"(use nil for anonymous padding)"
|
|
789
967
|
end
|
|
790
|
-
CAStruct::Builder.check_keys
|
|
791
|
-
CAStruct::Builder.validate_endian
|
|
968
|
+
CAStruct::Builder.send(:check_keys!, opt, MEMBER_KEYS, "#{typename}")
|
|
969
|
+
CAStruct::Builder.send(:validate_endian!, opt, "#{typename}", #{allow_endian})
|
|
792
970
|
args.each do |arg|
|
|
793
971
|
member(:#{typename}, arg, opt)
|
|
794
972
|
end
|
|
@@ -796,14 +974,7 @@ class CAStruct::Builder # :nodoc:
|
|
|
796
974
|
}
|
|
797
975
|
end
|
|
798
976
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
alias short int16
|
|
802
|
-
alias int int32
|
|
803
|
-
alias float float32
|
|
804
|
-
alias double float64
|
|
805
|
-
alias complex cmplx64
|
|
806
|
-
alias dcomplex cmplx128
|
|
977
|
+
private_constant :FAST_KIND_PRIMITIVE, :FAST_KIND_BITFIELD, :FAST_KIND_ENDIAN,
|
|
978
|
+
:BUILDER_KEYS, :MEMBER_KEYS, :NESTED_KEYS, :VALID_ENDIAN
|
|
807
979
|
|
|
808
980
|
end
|
|
809
|
-
|