ndtypes 0.2.0dev4
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 +7 -0
- data/CONTRIBUTING.md +50 -0
- data/Gemfile +2 -0
- data/History.md +0 -0
- data/README.md +19 -0
- data/Rakefile +125 -0
- data/ext/ruby_ndtypes/extconf.rb +55 -0
- data/ext/ruby_ndtypes/gc_guard.c +36 -0
- data/ext/ruby_ndtypes/gc_guard.h +12 -0
- data/ext/ruby_ndtypes/ndtypes/AUTHORS.txt +5 -0
- data/ext/ruby_ndtypes/ndtypes/INSTALL.txt +101 -0
- data/ext/ruby_ndtypes/ndtypes/LICENSE.txt +29 -0
- data/ext/ruby_ndtypes/ndtypes/MANIFEST.in +3 -0
- data/ext/ruby_ndtypes/ndtypes/Makefile.in +87 -0
- data/ext/ruby_ndtypes/ndtypes/README.rst +47 -0
- data/ext/ruby_ndtypes/ndtypes/config.guess +1530 -0
- data/ext/ruby_ndtypes/ndtypes/config.h.in +67 -0
- data/ext/ruby_ndtypes/ndtypes/config.sub +1782 -0
- data/ext/ruby_ndtypes/ndtypes/configure +5260 -0
- data/ext/ruby_ndtypes/ndtypes/configure.ac +161 -0
- data/ext/ruby_ndtypes/ndtypes/doc/Makefile +14 -0
- data/ext/ruby_ndtypes/ndtypes/doc/_static/copybutton.js +66 -0
- data/ext/ruby_ndtypes/ndtypes/doc/conf.py +26 -0
- data/ext/ruby_ndtypes/ndtypes/doc/grammar/grammar.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/index.rst +56 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/context.rst +131 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/encodings.rst +68 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/fields-values.rst +175 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/functions.rst +72 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/index.rst +43 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/init.rst +48 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/io.rst +100 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/memory.rst +124 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/predicates.rst +110 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/typedef.rst +31 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/types.rst +594 -0
- data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/util.rst +166 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/buffer-protocol.rst +27 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/index.rst +21 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/pattern-matching.rst +330 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/quickstart.rst +144 -0
- data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +544 -0
- data/ext/ruby_ndtypes/ndtypes/doc/releases/index.rst +35 -0
- data/ext/ruby_ndtypes/ndtypes/install-sh +527 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +271 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +230 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.c +268 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.h +109 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.in +73 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.vc +70 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/README.txt +16 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +2179 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +134 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +428 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +2543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +735 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +176 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +543 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +110 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/context.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +634 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.c +116 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +288 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +3067 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +180 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +417 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +1658 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +2773 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +734 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +222 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +1132 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +2323 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +893 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/overflow.h +161 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +473 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +92 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +246 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +269 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +197 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.in +48 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.vc +46 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +1007 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +442 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/slice.h +42 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +238 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +50 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +371 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +100 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +55 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +45 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.c +82 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.h +49 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +1657 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +85 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +115 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +137 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_indent.c +201 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +2397 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_numba.c +57 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +349 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +27839 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +350 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +231 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +375 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typedef.c +65 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/valgrind.supp +30 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/bench.c +79 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/indent.c +94 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/print_ast.c +96 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +474 -0
- data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +228 -0
- data/ext/ruby_ndtypes/ndtypes/python/bench.py +49 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +409 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +14 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +70 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +1332 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/docstrings.h +319 -0
- data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +154 -0
- data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +1977 -0
- data/ext/ruby_ndtypes/ndtypes/setup.py +288 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/INSTALL.txt +41 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest32.bat +15 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest64.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild32.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild64.bat +38 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcclean.bat +13 -0
- data/ext/ruby_ndtypes/ndtypes/vcbuild/vcdistclean.bat +14 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.c +1003 -0
- data/ext/ruby_ndtypes/ruby_ndtypes.h +37 -0
- data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +28 -0
- data/lib/ndtypes.rb +45 -0
- data/lib/ndtypes/errors.rb +2 -0
- data/lib/ndtypes/version.rb +6 -0
- data/ndtypes.gemspec +47 -0
- data/spec/gc_table_spec.rb +10 -0
- data/spec/ndtypes_spec.rb +289 -0
- data/spec/spec_helper.rb +241 -0
- metadata +242 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* BSD 3-Clause License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017-2018, plures
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
|
9
|
+
*
|
|
10
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
* this list of conditions and the following disclaimer.
|
|
12
|
+
*
|
|
13
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
* and/or other materials provided with the distribution.
|
|
16
|
+
*
|
|
17
|
+
* 3. Neither the name of the copyright holder nor the names of its
|
|
18
|
+
* contributors may be used to endorse or promote products derived from
|
|
19
|
+
* this software without specific prior written permission.
|
|
20
|
+
*
|
|
21
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
#include "test.h"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/* Same as test_parse, but can only contain the canonical datashape forms. */
|
|
39
|
+
const char *parse_roundtrip_tests[] = {
|
|
40
|
+
"2395344366 * Any",
|
|
41
|
+
"10 * 2395344366 * Any",
|
|
42
|
+
"10 * 10 * 2395344366 * Any",
|
|
43
|
+
"L * Any",
|
|
44
|
+
"10 * L * Any",
|
|
45
|
+
"10 * 10 * L * Any",
|
|
46
|
+
"var * Any",
|
|
47
|
+
"... * Any",
|
|
48
|
+
"10 * Any",
|
|
49
|
+
"Any",
|
|
50
|
+
"10 * ScalarKind",
|
|
51
|
+
"ScalarKind",
|
|
52
|
+
"10 * bool",
|
|
53
|
+
"bool",
|
|
54
|
+
"10 * SignedKind",
|
|
55
|
+
"SignedKind",
|
|
56
|
+
"10 * int8",
|
|
57
|
+
"int8",
|
|
58
|
+
"10 * int16",
|
|
59
|
+
"int16",
|
|
60
|
+
"10 * int32",
|
|
61
|
+
"int32",
|
|
62
|
+
"10 * int64",
|
|
63
|
+
"int64",
|
|
64
|
+
"10 * UnsignedKind",
|
|
65
|
+
"UnsignedKind",
|
|
66
|
+
"10 * uint8",
|
|
67
|
+
"uint8",
|
|
68
|
+
"10 * uint16",
|
|
69
|
+
"uint16",
|
|
70
|
+
"10 * uint32",
|
|
71
|
+
"uint32",
|
|
72
|
+
"10 * uint64",
|
|
73
|
+
"uint64",
|
|
74
|
+
"10 * FloatKind",
|
|
75
|
+
"FloatKind",
|
|
76
|
+
"10 * float32",
|
|
77
|
+
"float32",
|
|
78
|
+
"10 * float64",
|
|
79
|
+
"float64",
|
|
80
|
+
"10 * ComplexKind",
|
|
81
|
+
"ComplexKind",
|
|
82
|
+
"10 * complex64",
|
|
83
|
+
"complex64",
|
|
84
|
+
"10 * complex128",
|
|
85
|
+
"complex128",
|
|
86
|
+
"10 * char('ascii')",
|
|
87
|
+
"char('ascii')",
|
|
88
|
+
"10 * char('utf8')",
|
|
89
|
+
"char('utf8')",
|
|
90
|
+
"10 * char('utf16')",
|
|
91
|
+
"char('utf16')",
|
|
92
|
+
"10 * char('utf32')",
|
|
93
|
+
"char('utf32')",
|
|
94
|
+
"10 * char('ucs2')",
|
|
95
|
+
"char('ucs2')",
|
|
96
|
+
"10 * string",
|
|
97
|
+
"string",
|
|
98
|
+
"10 * FixedStringKind",
|
|
99
|
+
"FixedStringKind",
|
|
100
|
+
"10 * fixed_string(729742655, 'ascii')",
|
|
101
|
+
"fixed_string(729742655, 'ascii')",
|
|
102
|
+
"10 * fixed_string(3952068488)",
|
|
103
|
+
"fixed_string(3952068488)",
|
|
104
|
+
"10 * fixed_string(2949183030, 'utf16')",
|
|
105
|
+
"fixed_string(2949183030, 'utf16')",
|
|
106
|
+
"10 * fixed_string(375133997, 'utf32')",
|
|
107
|
+
"fixed_string(375133997, 'utf32')",
|
|
108
|
+
"10 * fixed_string(969064578, 'ucs2')",
|
|
109
|
+
"fixed_string(969064578, 'ucs2')",
|
|
110
|
+
"10 * bytes(align=16)",
|
|
111
|
+
"bytes(align=16)",
|
|
112
|
+
"10 * FixedBytesKind",
|
|
113
|
+
"FixedBytesKind",
|
|
114
|
+
"10 * fixed_bytes(size=1904128700, align=4)",
|
|
115
|
+
"fixed_bytes(size=1904128700, align=4)",
|
|
116
|
+
"10 * categorical(63)",
|
|
117
|
+
"categorical(63)",
|
|
118
|
+
"10 * categorical(10, 63)",
|
|
119
|
+
"categorical(10, 63)",
|
|
120
|
+
"10 * categorical(8, 10)",
|
|
121
|
+
"categorical(8, 10)",
|
|
122
|
+
"10 * categorical(18514)",
|
|
123
|
+
"categorical(18514)",
|
|
124
|
+
"10 * categorical(10, 18514)",
|
|
125
|
+
"categorical(10, 18514)",
|
|
126
|
+
"10 * categorical(-176354404)",
|
|
127
|
+
"categorical(-176354404)",
|
|
128
|
+
"10 * categorical(-176354404, 10)",
|
|
129
|
+
"categorical(-176354404, 10)",
|
|
130
|
+
"10 * categorical(500601201)",
|
|
131
|
+
"categorical(500601201)",
|
|
132
|
+
"10 * categorical(10, 500601201)",
|
|
133
|
+
"categorical(10, 500601201)",
|
|
134
|
+
"10 * categorical(135)",
|
|
135
|
+
"categorical(135)",
|
|
136
|
+
"10 * categorical(10, 135)",
|
|
137
|
+
"categorical(10, 135)",
|
|
138
|
+
"10 * categorical(22234)",
|
|
139
|
+
"categorical(22234)",
|
|
140
|
+
"10 * categorical(10, 22234)",
|
|
141
|
+
"categorical(10, 22234)",
|
|
142
|
+
"10 * categorical(3761672407)",
|
|
143
|
+
"categorical(3761672407)",
|
|
144
|
+
"10 * categorical(10, 3761672407)",
|
|
145
|
+
"categorical(10, 3761672407)",
|
|
146
|
+
"10 * categorical(2339269771)",
|
|
147
|
+
"categorical(2339269771)",
|
|
148
|
+
"10 * categorical(10, 2339269771)",
|
|
149
|
+
"categorical(10, 2339269771)",
|
|
150
|
+
"10 * categorical(1.2)",
|
|
151
|
+
"categorical(-1.2e+33)",
|
|
152
|
+
"10 * categorical(10, 1.05e+10)",
|
|
153
|
+
"categorical(10, 1.05e+10)",
|
|
154
|
+
"10 * categorical(1.05e+300)",
|
|
155
|
+
"categorical(-1.05e+300)",
|
|
156
|
+
"10 * categorical(10, 1.05e+300)",
|
|
157
|
+
"categorical(10, 1.05e+300)",
|
|
158
|
+
"10 * categorical('jRAMoBPQ')",
|
|
159
|
+
"categorical('jRAMoBPQ')",
|
|
160
|
+
"10 * categorical(10, 'jRAMoBPQ')",
|
|
161
|
+
"categorical(10, 'jRAMoBPQ')",
|
|
162
|
+
"10 * categorical(127)",
|
|
163
|
+
"categorical(127)",
|
|
164
|
+
"10 * categorical(10, 127)",
|
|
165
|
+
"categorical(10, 127)",
|
|
166
|
+
"10 * categorical(-128)",
|
|
167
|
+
"categorical(-128)",
|
|
168
|
+
"10 * categorical(10, -128)",
|
|
169
|
+
"categorical(10, -128)",
|
|
170
|
+
"10 * categorical(32767)",
|
|
171
|
+
"categorical(32767)",
|
|
172
|
+
"10 * categorical(10, 32767)",
|
|
173
|
+
"categorical(10, 32767)",
|
|
174
|
+
"10 * categorical(-32768)",
|
|
175
|
+
"categorical(-32768)",
|
|
176
|
+
"10 * categorical(10, -32768)",
|
|
177
|
+
"categorical(10, -32768)",
|
|
178
|
+
"10 * categorical(2147483647)",
|
|
179
|
+
"categorical(2147483647)",
|
|
180
|
+
"10 * categorical(10, 2147483647)",
|
|
181
|
+
"categorical(10, 2147483647)",
|
|
182
|
+
"10 * categorical(-2147483648)",
|
|
183
|
+
"categorical(-2147483648)",
|
|
184
|
+
"10 * categorical(10, -2147483648)",
|
|
185
|
+
"categorical(10, -2147483648)",
|
|
186
|
+
"10 * categorical(9223372036854775807)",
|
|
187
|
+
"categorical(9223372036854775807)",
|
|
188
|
+
"10 * categorical(10, 9223372036854775807)",
|
|
189
|
+
"categorical(10, 9223372036854775807)",
|
|
190
|
+
"10 * categorical(-9223372036854775808)",
|
|
191
|
+
"categorical(-9223372036854775808)",
|
|
192
|
+
"10 * categorical(-9223372036854775808, 10)",
|
|
193
|
+
"categorical(-9223372036854775808, 10)",
|
|
194
|
+
"10 * categorical(255)",
|
|
195
|
+
"categorical(255)",
|
|
196
|
+
"10 * categorical(10, 255)",
|
|
197
|
+
"categorical(10, 255)",
|
|
198
|
+
"10 * categorical(65535)",
|
|
199
|
+
"categorical(65535)",
|
|
200
|
+
"10 * categorical(10, 65535)",
|
|
201
|
+
"categorical(10, 65535)",
|
|
202
|
+
"10 * categorical(4294967295)",
|
|
203
|
+
"categorical(4294967295)",
|
|
204
|
+
"10 * categorical(10, 4294967295)",
|
|
205
|
+
"categorical(10, 4294967295)",
|
|
206
|
+
"10 * categorical(1.1755e-38)",
|
|
207
|
+
"categorical(1.1755e-38)",
|
|
208
|
+
"10 * categorical(10, 1.1755e-38)",
|
|
209
|
+
"categorical(10, 1.1755e-38)",
|
|
210
|
+
"10 * categorical(2.22508e-308)",
|
|
211
|
+
"categorical(2.22508e-308)",
|
|
212
|
+
"10 * categorical(10, 2.22508e-308)",
|
|
213
|
+
"categorical(10, 2.22508e-308)",
|
|
214
|
+
"10 * categorical(3.40282e+38)",
|
|
215
|
+
"categorical(3.40282e+38)",
|
|
216
|
+
"10 * categorical(10, 3.40282e+38)",
|
|
217
|
+
"categorical(10, 3.40282e+38)",
|
|
218
|
+
"10 * categorical(1.79769e+308)",
|
|
219
|
+
"categorical(1.79769e+308)",
|
|
220
|
+
"10 * categorical(10, 1.79769e+308)",
|
|
221
|
+
"categorical(10, 1.79769e+308)",
|
|
222
|
+
"10 * categorical('')",
|
|
223
|
+
"categorical('')",
|
|
224
|
+
"10 * categorical(10, '')",
|
|
225
|
+
"categorical(10, '')",
|
|
226
|
+
"10 * categorical('xyz')",
|
|
227
|
+
"categorical('xyz')",
|
|
228
|
+
"10 * categorical(10, 'xyz')",
|
|
229
|
+
"categorical(10, 'xyz')",
|
|
230
|
+
"10 * ref(Any)",
|
|
231
|
+
"ref(Any)",
|
|
232
|
+
"10 * (...)",
|
|
233
|
+
"10 * (Any)",
|
|
234
|
+
"(Any)",
|
|
235
|
+
"10 * (int64, Any)",
|
|
236
|
+
"(int64, Any)",
|
|
237
|
+
"10 * (int64, int64, Any)",
|
|
238
|
+
"(int64, int64, Any)",
|
|
239
|
+
"(Any) -> complex64",
|
|
240
|
+
"Any -> complex64",
|
|
241
|
+
"10 * (Any, ...)",
|
|
242
|
+
"(Any, ...)",
|
|
243
|
+
"10 * {...}",
|
|
244
|
+
"{...}",
|
|
245
|
+
"10 * {a : Any}",
|
|
246
|
+
"{a : Any}",
|
|
247
|
+
"10 * {x : int64, a : Any}",
|
|
248
|
+
"{x : int64, a : Any}",
|
|
249
|
+
"10 * {x : int64, x : int64, a : Any}",
|
|
250
|
+
"{x : int64, x : int64, a : Any}",
|
|
251
|
+
"10 * {a : int64}",
|
|
252
|
+
"{a : int64}",
|
|
253
|
+
"10 * {a : int64, ...}",
|
|
254
|
+
"{a : int64, ...}",
|
|
255
|
+
"(...) -> Any",
|
|
256
|
+
"() -> (...)",
|
|
257
|
+
"void -> (int64)",
|
|
258
|
+
"void -> void",
|
|
259
|
+
"(Any) -> Any",
|
|
260
|
+
"Any -> Any",
|
|
261
|
+
"() -> (Any)",
|
|
262
|
+
"(int64, Any) -> Any",
|
|
263
|
+
"int64, Any -> Any",
|
|
264
|
+
"int64, Any -> float32, (complex128, string)",
|
|
265
|
+
"() -> (int64, Any)",
|
|
266
|
+
"(int64, int64, Any) -> Any",
|
|
267
|
+
"int64, int64, (bytes, ...) -> float32, float64",
|
|
268
|
+
"() -> (int64, int64, Any)",
|
|
269
|
+
"(Any, ...) -> Any",
|
|
270
|
+
"() -> (Any, ...)",
|
|
271
|
+
"10 * Up",
|
|
272
|
+
"Up",
|
|
273
|
+
"10 * X(Any)",
|
|
274
|
+
"X(Any)",
|
|
275
|
+
|
|
276
|
+
/* BEGIN RANDOM */
|
|
277
|
+
"fixed_bytes(size=1342281600, align=16)",
|
|
278
|
+
"var * var * var * (...)",
|
|
279
|
+
"categorical(-84, 18772, 49062, 1619552300, 'a', 'l')",
|
|
280
|
+
"categorical(24, 44038, 1763886348, 2840608325, 1.2e-32, 'jOt')",
|
|
281
|
+
"categorical(-2049848438, 94, 3577056037, 3599739756, 1.2e-32)",
|
|
282
|
+
"categorical(2753441703, 1.2e-32)",
|
|
283
|
+
"1286044356 * LbR6JPFI * 2096958782 * uint8",
|
|
284
|
+
"categorical(-25910, 4265882500, 1.2e-32, 'xM3Mys0XqH')",
|
|
285
|
+
"var * var * FixedBytesKind",
|
|
286
|
+
"var * var * var * fixed_bytes(size=2816010912, align=16)",
|
|
287
|
+
"36 * 16 * fixed_bytes(size=912328236, align=2)",
|
|
288
|
+
"var * var * var * ZcTmBXnKPi",
|
|
289
|
+
"categorical(946986991, 43, 'omhwkoWVWw')",
|
|
290
|
+
"var * float32",
|
|
291
|
+
"var * var * var * uint16",
|
|
292
|
+
"var * var * var * ScalarKind",
|
|
293
|
+
"fixed_bytes(size=280180300, align=2)",
|
|
294
|
+
"fixed_string(1901614748, 'utf32')",
|
|
295
|
+
"var * M7",
|
|
296
|
+
"var * bytes(align=2)",
|
|
297
|
+
"fixed_bytes(size=1882259712, align=16)",
|
|
298
|
+
"categorical(-83, -58, 1.2e-32)",
|
|
299
|
+
"3739637665 * 1476113530 * 1701021063 * IKd * 450514382 * WXn",
|
|
300
|
+
"ref(AilcKv4su1(FixedBytesKind))",
|
|
301
|
+
"var * QoFb",
|
|
302
|
+
"var * fixed_string(1233383142, 'utf32')",
|
|
303
|
+
"fixed_bytes(size=2882797900, align=2)",
|
|
304
|
+
"fixed_bytes(size=1233209904, align=8)",
|
|
305
|
+
"WhRsMHHXYp(categorical(145))",
|
|
306
|
+
"var * var * bytes(align=2)",
|
|
307
|
+
"categorical(-85, -49, -26791, 8094, 1780, 1.2e-32, 'pX')",
|
|
308
|
+
"D6nfBg_(categorical(16278, 26651, 147170982, 1.2e-32, 'ylR7'))",
|
|
309
|
+
"categorical(482331467, 3229733591, -1.2e-32, 1.2e-32)",
|
|
310
|
+
/* END RANDOM */
|
|
311
|
+
|
|
312
|
+
/* BEGIN MANUALLY GENERATED */
|
|
313
|
+
"()",
|
|
314
|
+
"{}",
|
|
315
|
+
"() -> ()",
|
|
316
|
+
"(...) -> ()",
|
|
317
|
+
"(...) -> (...)",
|
|
318
|
+
"(int64, ...) -> complex128",
|
|
319
|
+
"() -> int32",
|
|
320
|
+
"(int32) -> int32",
|
|
321
|
+
"(int32, float64) -> int32",
|
|
322
|
+
"(...) -> int32",
|
|
323
|
+
"(int32, ...) -> int32",
|
|
324
|
+
"(int32, float32, ...) -> int32",
|
|
325
|
+
|
|
326
|
+
"10 * defined_t",
|
|
327
|
+
"defined_t",
|
|
328
|
+
|
|
329
|
+
"10 * foo_t",
|
|
330
|
+
"foo_t",
|
|
331
|
+
|
|
332
|
+
"() -> void",
|
|
333
|
+
"(int32, ...) -> void",
|
|
334
|
+
|
|
335
|
+
"<int64",
|
|
336
|
+
">int64",
|
|
337
|
+
"2 * 10 * >float64",
|
|
338
|
+
|
|
339
|
+
/* Fortran */
|
|
340
|
+
"!2 * 3 * uint8",
|
|
341
|
+
"!2 * 3 * {a : !10 * 20 * int64, b : !10 * 2 * float64}",
|
|
342
|
+
|
|
343
|
+
/* Overflow */
|
|
344
|
+
"9223372036854775807 * uint8",
|
|
345
|
+
"1 * 1 * 9223372036854775807 * uint8",
|
|
346
|
+
|
|
347
|
+
/* END MANUALLY GENERATED */
|
|
348
|
+
|
|
349
|
+
NULL
|
|
350
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* BSD 3-Clause License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2017-2018, plures
|
|
5
|
+
* All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* Redistribution and use in source and binary forms, with or without
|
|
8
|
+
* modification, are permitted provided that the following conditions are met:
|
|
9
|
+
*
|
|
10
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
* this list of conditions and the following disclaimer.
|
|
12
|
+
*
|
|
13
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
* and/or other materials provided with the distribution.
|
|
16
|
+
*
|
|
17
|
+
* 3. Neither the name of the copyright holder nor the names of its
|
|
18
|
+
* contributors may be used to endorse or promote products derived from
|
|
19
|
+
* this software without specific prior written permission.
|
|
20
|
+
*
|
|
21
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
#include <stdlib.h>
|
|
36
|
+
#include <stdint.h>
|
|
37
|
+
#include <stdalign.h>
|
|
38
|
+
#include <stddef.h>
|
|
39
|
+
#include <string.h>
|
|
40
|
+
#include <assert.h>
|
|
41
|
+
#include "ndtypes.h"
|
|
42
|
+
#include "test.h"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
#ifdef __clang__
|
|
46
|
+
#pragma clang diagnostic ignored "-Wgnu-alignof-expression"
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/*********************************************************************/
|
|
51
|
+
/* struct packing and alignment */
|
|
52
|
+
/*********************************************************************/
|
|
53
|
+
|
|
54
|
+
#ifdef __GNUC__
|
|
55
|
+
typedef struct {
|
|
56
|
+
uint8_t u1;
|
|
57
|
+
int64_t i1 __attribute__((packed, aligned(1))); // align >= 1
|
|
58
|
+
uint8_t u2;
|
|
59
|
+
int64_t i2 __attribute__((packed, aligned(1))); // align >= 1
|
|
60
|
+
uint8_t u3;
|
|
61
|
+
} packed_no_trailing_padding_t;
|
|
62
|
+
|
|
63
|
+
typedef struct __attribute__((aligned(2))) {
|
|
64
|
+
char u1;
|
|
65
|
+
int64_t i1 __attribute__((packed, aligned(1))); // align >= 1
|
|
66
|
+
char u2;
|
|
67
|
+
int64_t i2 __attribute__((packed, aligned(1))); // align >= 1
|
|
68
|
+
char u3;
|
|
69
|
+
} packed_with_trailing_padding_t;
|
|
70
|
+
|
|
71
|
+
typedef struct {
|
|
72
|
+
char u1 __attribute__((aligned(16))); // align >= 16
|
|
73
|
+
int64_t i1 __attribute__((aligned(8))); // align >= max(1, alignof(int64_t))
|
|
74
|
+
char u2;
|
|
75
|
+
} aligned_t;
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
int
|
|
79
|
+
test_struct_align_pack(void)
|
|
80
|
+
{
|
|
81
|
+
static const char *s1 =
|
|
82
|
+
"{u1: uint8, i1: int64 |pack=1|, u2: uint8, i2: int64 |pack=1|, u3: uint8}";
|
|
83
|
+
static const char *s1_abbrev =
|
|
84
|
+
"{u1: uint8, i1: int64, u2: uint8, i2: int64, u3: uint8, pack=1}";
|
|
85
|
+
static const char *s2 =
|
|
86
|
+
"{u1: uint8, i1: int64 |pack=1|, u2: uint8, i2: int64 |pack=1|, u3: uint8, align=2}";
|
|
87
|
+
static const char *s3 =
|
|
88
|
+
"{u1: uint8 |align=16|, i1: int64 |align=8|, u2 : uint8}";
|
|
89
|
+
packed_no_trailing_padding_t packed_no_trail;
|
|
90
|
+
packed_with_trailing_padding_t packed_with_trail;
|
|
91
|
+
aligned_t aligned;
|
|
92
|
+
ndt_context_t *ctx;
|
|
93
|
+
ndt_t *t;
|
|
94
|
+
|
|
95
|
+
ctx = ndt_context_new();
|
|
96
|
+
if (ctx == NULL) {
|
|
97
|
+
fprintf(stderr, "error: out of memory");
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
t = ndt_from_string(s1, ctx);
|
|
102
|
+
if (t == NULL) {
|
|
103
|
+
fprintf(stderr, "test_struct_align_pack: parse: FAIL: %s\n",
|
|
104
|
+
ndt_context_msg(ctx));
|
|
105
|
+
ndt_context_del(ctx);
|
|
106
|
+
return -1;
|
|
107
|
+
}
|
|
108
|
+
if (ndt_is_abstract(t)) {
|
|
109
|
+
fprintf(stderr,
|
|
110
|
+
"test_struct_align_pack: parse: FAIL: unexpected abstract type\n");
|
|
111
|
+
ndt_context_del(ctx);
|
|
112
|
+
return -1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (t->datasize != sizeof(packed_no_trail) ||
|
|
116
|
+
t->align != alignof(packed_no_trail) ||
|
|
117
|
+
t->Concrete.Record.offset[0] != offsetof(packed_no_trailing_padding_t, u1) ||
|
|
118
|
+
t->Concrete.Record.align[0] != alignof(packed_no_trail.u1) ||
|
|
119
|
+
t->Concrete.Record.offset[1] != offsetof(packed_no_trailing_padding_t, i1) ||
|
|
120
|
+
t->Concrete.Record.align[1] != alignof(packed_no_trail.i1) ||
|
|
121
|
+
t->Concrete.Record.offset[2] != offsetof(packed_no_trailing_padding_t, u2) ||
|
|
122
|
+
t->Concrete.Record.align[2] != alignof(packed_no_trail.u2) ||
|
|
123
|
+
t->Concrete.Record.offset[3] != offsetof(packed_no_trailing_padding_t, i2) ||
|
|
124
|
+
t->Concrete.Record.align[3] != alignof(packed_no_trail.i2) ||
|
|
125
|
+
t->Concrete.Record.offset[4] != offsetof(packed_no_trailing_padding_t, u3) ||
|
|
126
|
+
t->Concrete.Record.align[4] != alignof(packed_no_trail.u3)) {
|
|
127
|
+
fprintf(stderr, "test_struct_align_pack: packed_no_trail: FAIL");
|
|
128
|
+
ndt_context_del(ctx);
|
|
129
|
+
}
|
|
130
|
+
ndt_del(t);
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
t = ndt_from_string(s1_abbrev, ctx);
|
|
134
|
+
if (t == NULL) {
|
|
135
|
+
fprintf(stderr, "test_struct_align_pack: parse: FAIL: %s\n",
|
|
136
|
+
ndt_context_msg(ctx));
|
|
137
|
+
ndt_context_del(ctx);
|
|
138
|
+
return -1;
|
|
139
|
+
}
|
|
140
|
+
if (ndt_is_abstract(t)) {
|
|
141
|
+
fprintf(stderr,
|
|
142
|
+
"test_struct_align_pack: parse: FAIL: unexpected abstract type\n");
|
|
143
|
+
ndt_context_del(ctx);
|
|
144
|
+
return -1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (t->datasize != sizeof(packed_no_trail) ||
|
|
148
|
+
t->align != alignof(packed_no_trail) ||
|
|
149
|
+
t->Concrete.Record.offset[0] != offsetof(packed_no_trailing_padding_t, u1) ||
|
|
150
|
+
t->Concrete.Record.align[0] != alignof(packed_no_trail.u1) ||
|
|
151
|
+
t->Concrete.Record.offset[1] != offsetof(packed_no_trailing_padding_t, i1) ||
|
|
152
|
+
t->Concrete.Record.align[1] != alignof(packed_no_trail.i1) ||
|
|
153
|
+
t->Concrete.Record.offset[2] != offsetof(packed_no_trailing_padding_t, u2) ||
|
|
154
|
+
t->Concrete.Record.align[2] != alignof(packed_no_trail.u2) ||
|
|
155
|
+
t->Concrete.Record.offset[3] != offsetof(packed_no_trailing_padding_t, i2) ||
|
|
156
|
+
t->Concrete.Record.align[3] != alignof(packed_no_trail.i2) ||
|
|
157
|
+
t->Concrete.Record.offset[4] != offsetof(packed_no_trailing_padding_t, u3) ||
|
|
158
|
+
t->Concrete.Record.align[4] != alignof(packed_no_trail.u3)) {
|
|
159
|
+
fprintf(stderr, "test_struct_align_pack: packed_no_trail_abbrev: FAIL\n");
|
|
160
|
+
ndt_context_del(ctx);
|
|
161
|
+
}
|
|
162
|
+
ndt_del(t);
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
t = ndt_from_string(s2, ctx);
|
|
166
|
+
if (t == NULL) {
|
|
167
|
+
fprintf(stderr, "test_struct_align_pack: parse: FAIL: %s\n",
|
|
168
|
+
ndt_context_msg(ctx));
|
|
169
|
+
ndt_context_del(ctx);
|
|
170
|
+
return -1;
|
|
171
|
+
}
|
|
172
|
+
if (ndt_is_abstract(t)) {
|
|
173
|
+
fprintf(stderr,
|
|
174
|
+
"test_struct_align_pack: parse: FAIL: unexpected abstract type\n");
|
|
175
|
+
ndt_context_del(ctx);
|
|
176
|
+
return -1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (t->datasize != sizeof(packed_with_trail) ||
|
|
180
|
+
t->align != alignof(packed_with_trail) ||
|
|
181
|
+
t->Concrete.Record.offset[0] != offsetof(packed_with_trailing_padding_t, u1) ||
|
|
182
|
+
t->Concrete.Record.align[0] != alignof(packed_with_trail.u1) ||
|
|
183
|
+
t->Concrete.Record.offset[1] != offsetof(packed_with_trailing_padding_t, i1) ||
|
|
184
|
+
t->Concrete.Record.align[1] != alignof(packed_with_trail.u1) ||
|
|
185
|
+
t->Concrete.Record.offset[2] != offsetof(packed_with_trailing_padding_t, u2) ||
|
|
186
|
+
t->Concrete.Record.align[2] != alignof(packed_with_trail.u2) ||
|
|
187
|
+
t->Concrete.Record.offset[3] != offsetof(packed_with_trailing_padding_t, i2) ||
|
|
188
|
+
t->Concrete.Record.align[3] != alignof(packed_with_trail.i2) ||
|
|
189
|
+
t->Concrete.Record.offset[4] != offsetof(packed_with_trailing_padding_t, u3) ||
|
|
190
|
+
t->Concrete.Record.align[4] != alignof(packed_with_trail.u3)) {
|
|
191
|
+
fprintf(stderr, "test_struct_align_pack: packed_with_trail: FAIL");
|
|
192
|
+
ndt_context_del(ctx);
|
|
193
|
+
}
|
|
194
|
+
ndt_del(t);
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
t = ndt_from_string(s3, ctx);
|
|
198
|
+
if (t == NULL) {
|
|
199
|
+
fprintf(stderr, "test_struct_align_pack: parse: FAIL: %s\n",
|
|
200
|
+
ndt_context_msg(ctx));
|
|
201
|
+
ndt_context_del(ctx);
|
|
202
|
+
return -1;
|
|
203
|
+
}
|
|
204
|
+
if (ndt_is_abstract(t)) {
|
|
205
|
+
fprintf(stderr,
|
|
206
|
+
"test_struct_align_pack: parse: FAIL: unexpected abstract type\n");
|
|
207
|
+
ndt_context_del(ctx);
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (t->datasize != sizeof(aligned) ||
|
|
212
|
+
t->align != alignof(aligned) ||
|
|
213
|
+
t->Concrete.Record.offset[0] != offsetof(aligned_t, u1) ||
|
|
214
|
+
t->Concrete.Record.align[0] != alignof(aligned.u1) ||
|
|
215
|
+
t->Concrete.Record.offset[1] != offsetof(aligned_t, i1) ||
|
|
216
|
+
t->Concrete.Record.align[1] != alignof(aligned.i1) ||
|
|
217
|
+
t->Concrete.Record.offset[2] != offsetof(aligned_t, u2) ||
|
|
218
|
+
t->Concrete.Record.align[2] != alignof(aligned.u2)) {
|
|
219
|
+
fprintf(stderr, "test_struct_align_pack: aligned: FAIL");
|
|
220
|
+
ndt_context_del(ctx);
|
|
221
|
+
}
|
|
222
|
+
ndt_del(t);
|
|
223
|
+
|
|
224
|
+
fprintf(stderr, "test_struct_align_pack (4 test cases)\n");
|
|
225
|
+
|
|
226
|
+
ndt_context_del(ctx);
|
|
227
|
+
return 0;
|
|
228
|
+
}
|
|
229
|
+
#endif
|
|
230
|
+
|
|
231
|
+
|