ndtypes 0.2.0dev5 → 0.2.0dev6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +12 -0
  3. data/Rakefile +8 -0
  4. data/ext/ruby_ndtypes/GPATH +0 -0
  5. data/ext/ruby_ndtypes/GRTAGS +0 -0
  6. data/ext/ruby_ndtypes/GTAGS +0 -0
  7. data/ext/ruby_ndtypes/extconf.rb +1 -1
  8. data/ext/ruby_ndtypes/include/ndtypes.h +231 -122
  9. data/ext/ruby_ndtypes/include/ruby_ndtypes.h +1 -1
  10. data/ext/ruby_ndtypes/lib/libndtypes.a +0 -0
  11. data/ext/ruby_ndtypes/lib/libndtypes.so.0.2.0dev3 +0 -0
  12. data/ext/ruby_ndtypes/ndtypes/Makefile +87 -0
  13. data/ext/ruby_ndtypes/ndtypes/config.h +68 -0
  14. data/ext/ruby_ndtypes/ndtypes/config.log +477 -0
  15. data/ext/ruby_ndtypes/ndtypes/config.status +1027 -0
  16. data/ext/ruby_ndtypes/ndtypes/doc/_static/style.css +7 -0
  17. data/ext/ruby_ndtypes/ndtypes/doc/_templates/layout.html +2 -0
  18. data/ext/ruby_ndtypes/ndtypes/doc/conf.py +40 -4
  19. data/ext/ruby_ndtypes/ndtypes/doc/images/xndlogo.png +0 -0
  20. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +1 -1
  21. data/ext/ruby_ndtypes/ndtypes/doc/requirements.txt +2 -0
  22. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile +287 -0
  23. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +20 -4
  24. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +22 -3
  25. data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +1 -1
  26. data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.o +0 -0
  27. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.o +0 -0
  28. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile +73 -0
  29. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +246 -229
  30. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +15 -11
  31. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.o +0 -0
  32. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +38 -28
  33. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +91 -91
  34. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +1 -1
  35. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +4 -3
  36. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.o +0 -0
  37. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +8 -7
  38. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.o +0 -0
  39. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +2 -2
  40. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.o +0 -0
  41. data/ext/ruby_ndtypes/ndtypes/libndtypes/context.o +0 -0
  42. data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +263 -182
  43. data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.o +0 -0
  44. data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.o +0 -0
  45. data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +67 -7
  46. data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.o +0 -0
  47. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +1112 -1000
  48. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +69 -58
  49. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.o +0 -0
  50. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +150 -99
  51. data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +185 -15
  52. data/ext/ruby_ndtypes/ndtypes/libndtypes/io.o +0 -0
  53. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +301 -276
  54. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +1 -1
  55. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +9 -4
  56. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.o +0 -0
  57. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.a +0 -0
  58. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so +1 -0
  59. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so.0 +1 -0
  60. data/ext/ruby_ndtypes/ndtypes/libndtypes/libndtypes.so.0.2.0dev3 +0 -0
  61. data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +729 -228
  62. data/ext/ruby_ndtypes/ndtypes/libndtypes/match.o +0 -0
  63. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +768 -403
  64. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h +1002 -0
  65. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +231 -122
  66. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.o +0 -0
  67. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +176 -84
  68. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +26 -14
  69. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.o +0 -0
  70. data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +57 -35
  71. data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.o +0 -0
  72. data/ext/ruby_ndtypes/ndtypes/libndtypes/primitive.c +420 -0
  73. data/ext/ruby_ndtypes/ndtypes/libndtypes/primitive.o +0 -0
  74. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +8 -8
  75. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +1 -1
  76. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.o +0 -0
  77. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile +48 -0
  78. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +200 -116
  79. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.o +0 -0
  80. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +46 -4
  81. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.o +0 -0
  82. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +58 -27
  83. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +1 -1
  84. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.o +0 -0
  85. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +3 -5
  86. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +12 -4
  87. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.o +0 -0
  88. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile +55 -0
  89. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +8 -8
  90. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +5 -5
  91. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +274 -172
  92. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +24 -4
  93. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +2 -2
  94. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +14 -14
  95. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +32 -30
  96. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +37 -0
  97. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +36 -0
  98. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +16 -0
  99. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +5 -5
  100. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +706 -253
  101. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_unify.c +132 -0
  102. data/ext/ruby_ndtypes/ndtypes/libndtypes/unify.c +703 -0
  103. data/ext/ruby_ndtypes/ndtypes/libndtypes/unify.o +0 -0
  104. data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +335 -127
  105. data/ext/ruby_ndtypes/ndtypes/libndtypes/util.o +0 -0
  106. data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +2 -2
  107. data/ext/ruby_ndtypes/ndtypes/libndtypes/values.o +0 -0
  108. data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +88 -71
  109. data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +0 -1
  110. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +10 -13
  111. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +395 -314
  112. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.a +0 -0
  113. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so +1 -0
  114. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0 +1 -0
  115. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/libndtypes.so.0.2.0dev3 +0 -0
  116. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/ndtypes.h +1002 -0
  117. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +15 -33
  118. data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +340 -132
  119. data/ext/ruby_ndtypes/ndtypes/setup.py +11 -2
  120. data/ext/ruby_ndtypes/ruby_ndtypes.c +364 -241
  121. data/ext/ruby_ndtypes/ruby_ndtypes.h +1 -1
  122. data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +0 -1
  123. data/lib/ndtypes.rb +11 -0
  124. data/lib/ndtypes/version.rb +2 -2
  125. data/lib/ruby_ndtypes.so +0 -0
  126. data/ndtypes.gemspec +3 -0
  127. data/spec/ndtypes_spec.rb +6 -0
  128. metadata +98 -4
  129. data/ext/ruby_ndtypes/gc_guard.c +0 -36
  130. data/ext/ruby_ndtypes/gc_guard.h +0 -12
@@ -128,13 +128,27 @@ mk_attr_from_seq(char *name, ndt_string_seq_t *seq, ndt_context_t *ctx)
128
128
  /* Parser functions for creating types */
129
129
  /*****************************************************************************/
130
130
 
131
- ndt_t *
131
+ /*
132
+ * NOTE: These functions should be considered internal. Many of these
133
+ * deallocate "const ndt_t *type" for convenience in grammar.y.
134
+ */
135
+
136
+ const ndt_t *
137
+ mk_module(char *name, const ndt_t *type, ndt_context_t *ctx)
138
+ {
139
+ const ndt_t *t = ndt_module(name, type, ctx);
140
+ ndt_decref(type);
141
+ return t;
142
+ }
143
+
144
+ const ndt_t *
132
145
  mk_function(ndt_type_seq_t *in, ndt_type_seq_t *out, ndt_context_t *ctx)
133
146
  {
134
- ndt_t *types[NDT_MAX_ARGS];
147
+ const ndt_t *types[NDT_MAX_ARGS];
135
148
  int64_t nin = in->len;
136
149
  int64_t nout = out->len;
137
150
  int64_t nargs, i;
151
+ const ndt_t *t;
138
152
 
139
153
  nargs = nin + nout;
140
154
 
@@ -148,30 +162,72 @@ mk_function(ndt_type_seq_t *in, ndt_type_seq_t *out, ndt_context_t *ctx)
148
162
 
149
163
  for (i = 0; i < nin; i++) {
150
164
  types[i] = in->ptr[i];
165
+ ndt_incref(types[i]);
151
166
  }
152
167
 
153
168
  for (i = 0; i < nout; i++) {
154
169
  types[nin+i] = out->ptr[i];
170
+ ndt_incref(types[nin+i]);
155
171
  }
156
172
 
157
- ndt_free(in->ptr);
158
- ndt_free(in);
159
- ndt_free(out->ptr);
160
- ndt_free(out);
173
+ ndt_type_seq_del(in);
174
+ ndt_type_seq_del(out);
161
175
 
162
- return ndt_function(types, nargs, nin, nout, ctx);
176
+ t = ndt_function(types, nargs, nin, nout, ctx);
177
+
178
+ ndt_type_array_clear(types, nargs);
179
+ return t;
163
180
  }
164
181
 
165
- ndt_t *
166
- mk_fortran(ndt_t *type, ndt_context_t *ctx)
182
+ const ndt_t *
183
+ mk_ellipsis_dim(char *name, const ndt_t *type, ndt_context_t *ctx)
167
184
  {
168
- ndt_t *t = ndt_to_fortran(type, ctx);
185
+ const ndt_t *t = ndt_ellipsis_dim(name, type, ctx);
186
+ ndt_decref(type);
187
+ return t;
188
+ }
189
+
190
+ const ndt_t *
191
+ mk_symbolic_dim(char *name, const ndt_t *type, ndt_context_t *ctx)
192
+ {
193
+ const ndt_t *t = ndt_symbolic_dim(name, type, ctx);
194
+ ndt_decref(type);
195
+ return t;
196
+ }
197
+
198
+ const ndt_t *
199
+ mk_array(const ndt_t *type, bool opt, ndt_context_t *ctx)
200
+ {
201
+ const ndt_t *t = ndt_array(type, opt, ctx);
202
+ ndt_decref(type);
203
+ return t;
204
+ }
205
+
206
+ const ndt_t *
207
+ mk_constr(char *name, const ndt_t *type, bool opt, ndt_context_t *ctx)
208
+ {
209
+ const ndt_t *t = ndt_constr(name, type, opt, ctx);
210
+ ndt_decref(type);
211
+ return t;
212
+ }
213
+
214
+ const ndt_t *
215
+ mk_ref(const ndt_t *type, bool opt, ndt_context_t *ctx)
216
+ {
217
+ const ndt_t *t = ndt_ref(type, opt, ctx);
218
+ ndt_decref(type);
219
+ return t;
220
+ }
169
221
 
170
- ndt_del(type);
222
+ const ndt_t *
223
+ mk_fortran(const ndt_t *type, ndt_context_t *ctx)
224
+ {
225
+ const ndt_t *t = ndt_to_fortran(type, ctx);
226
+ ndt_decref(type);
171
227
  return t;
172
228
  }
173
229
 
174
- ndt_t *
230
+ const ndt_t *
175
231
  mk_contig(char *name, ndt_t *type, ndt_context_t *ctx)
176
232
  {
177
233
  enum ndt_contig tag = RequireNA;
@@ -187,7 +243,7 @@ mk_contig(char *name, ndt_t *type, ndt_context_t *ctx)
187
243
  if (tag == RequireNA) {
188
244
  ndt_err_format(ctx, NDT_ParseError,
189
245
  "valid contiguity modifiers are 'C' or 'F'");
190
- ndt_del(type);
246
+ ndt_decref(type);
191
247
  return NULL;
192
248
  }
193
249
 
@@ -199,13 +255,13 @@ mk_contig(char *name, ndt_t *type, ndt_context_t *ctx)
199
255
  if (!ndt_is_c_contiguous(type)) {
200
256
  ndt_err_format(ctx, NDT_ParseError,
201
257
  "valid contiguity modifiers are 'C' or 'F'");
202
- ndt_del(type);
258
+ ndt_decref(type);
203
259
  return NULL;
204
260
  }
205
261
 
206
262
  if (tag == RequireF) {
207
- t = ndt_to_fortran(type, ctx);
208
- ndt_del(type);
263
+ t = (ndt_t *)ndt_to_fortran(type, ctx);
264
+ ndt_decref(type);
209
265
  if (t == NULL) {
210
266
  return NULL;
211
267
  }
@@ -227,32 +283,36 @@ mk_contig(char *name, ndt_t *type, ndt_context_t *ctx)
227
283
  default: {
228
284
  ndt_err_format(ctx, NDT_ParseError,
229
285
  "'C' or 'F' can only be applied to fixed or symbolic dimensions");
230
- ndt_del(type);
286
+ ndt_decref(type);
231
287
  return NULL;
232
288
  }
233
289
  }
234
290
  }
235
291
 
236
- ndt_t *
237
- mk_fixed_dim_from_shape(char *v, ndt_t *type, ndt_context_t *ctx)
292
+ const ndt_t *
293
+ mk_fixed_dim_from_shape(char *v, const ndt_t *type, ndt_context_t *ctx)
238
294
  {
295
+ const ndt_t *t;
239
296
  int64_t shape;
240
297
 
241
298
  shape = ndt_strtoll(v, 0, INT64_MAX, ctx);
242
299
  ndt_free(v);
243
300
 
244
301
  if (ndt_err_occurred(ctx)) {
245
- ndt_del(type);
302
+ ndt_decref(type);
246
303
  return NULL;
247
304
  }
248
305
 
249
- return ndt_fixed_dim(type, shape, INT64_MAX, ctx);
306
+ t = ndt_fixed_dim(type, shape, INT64_MAX, ctx);
307
+ ndt_decref(type);
308
+ return t;
250
309
  }
251
310
 
252
- ndt_t *
253
- mk_fixed_dim_from_attrs(ndt_attr_seq_t *attrs, ndt_t *type, ndt_context_t *ctx)
311
+ const ndt_t *
312
+ mk_fixed_dim_from_attrs(ndt_attr_seq_t *attrs, const ndt_t *type, ndt_context_t *ctx)
254
313
  {
255
314
  static const attr_spec kwlist = {1, 2, {"shape", "step"}, {AttrInt64, AttrInt64}};
315
+ const ndt_t *t;
256
316
  int64_t shape;
257
317
  int64_t step = INT64_MAX;
258
318
  int ret;
@@ -260,81 +320,100 @@ mk_fixed_dim_from_attrs(ndt_attr_seq_t *attrs, ndt_t *type, ndt_context_t *ctx)
260
320
  ret = ndt_parse_attr(&kwlist, ctx, attrs, &shape, &step);
261
321
  ndt_attr_seq_del(attrs);
262
322
  if (ret < 0) {
263
- ndt_del(type);
323
+ ndt_decref(type);
264
324
  return NULL;
265
325
  }
266
326
 
267
- return ndt_fixed_dim(type, shape, step, ctx);
327
+ t = ndt_fixed_dim(type, shape, step, ctx);
328
+ ndt_decref(type);
329
+ return t;
268
330
  }
269
331
 
270
- ndt_t *
271
- mk_var_dim(ndt_meta_t *m, ndt_attr_seq_t *attrs, ndt_t *type, ndt_context_t *ctx)
332
+ const ndt_t *
333
+ mk_var_dim(ndt_attr_seq_t *attrs, const ndt_t *type, bool opt, ndt_context_t *ctx)
272
334
  {
273
335
  static const attr_spec kwlist = {1, 2, {"offsets", "_noffsets"}, {AttrInt32List, AttrInt64}};
336
+ const ndt_t *t;
274
337
 
275
338
  if (attrs) {
276
- int32_t *offsets = NULL;
277
- int64_t noffsets = 0;
278
- ndt_t *t;
339
+ ndt_offsets_t *offsets;
340
+ int32_t *ptr;
341
+ int64_t n;
279
342
  int ret;
280
343
 
281
- ret = ndt_parse_attr(&kwlist, ctx, attrs, &offsets, &noffsets);
344
+ ret = ndt_parse_attr(&kwlist, ctx, attrs, &ptr, &n);
282
345
  ndt_attr_seq_del(attrs);
283
346
  if (ret < 0) {
284
- ndt_del(type);
347
+ ndt_decref(type);
285
348
  return NULL;
286
349
  }
287
350
 
288
- if (noffsets > INT32_MAX) {
351
+ if (n > INT32_MAX) {
289
352
  ndt_err_format(ctx, NDT_ValueError, "too many offsets");
290
- ndt_del(type);
291
- ndt_free(offsets);
353
+ ndt_free(ptr);
354
+ ndt_decref(type);
292
355
  return NULL;
293
356
  }
294
357
 
295
- if (m == NULL) {
296
- t = ndt_var_dim(type, InternalOffsets, (int32_t)noffsets, offsets, 0, NULL, ctx);
297
- }
298
- else {
299
- if (m->ndims >= NDT_MAX_DIM) {
300
- ndt_err_format(ctx, NDT_RuntimeError, "too many dimensions");
301
- ndt_del(type);
302
- ndt_free(offsets);
303
- return NULL;
304
- }
305
- m->noffsets[m->ndims] = (int32_t)noffsets;
306
- m->offsets[m->ndims] = offsets;
307
- m->ndims++;
308
-
309
- t = ndt_var_dim(type, ExternalOffsets, (int32_t)noffsets, offsets, 0, NULL, ctx);
358
+ offsets = ndt_offsets_from_ptr(ptr, (int32_t)n, ctx);
359
+ if (offsets == NULL) {
360
+ ndt_decref(type);
361
+ return NULL;
310
362
  }
311
363
 
312
- return t;
364
+ t = ndt_var_dim(type, offsets, 0, NULL, opt, ctx);
365
+ ndt_decref_offsets(offsets);
313
366
  }
314
367
  else {
315
- return ndt_abstract_var_dim(type, ctx);
368
+ t = ndt_abstract_var_dim(type, opt, ctx);
316
369
  }
370
+
371
+ ndt_decref(type);
372
+ return t;
317
373
  }
318
374
 
319
- ndt_t *
320
- mk_var_ellipsis(ndt_t *type, ndt_context_t *ctx)
375
+ const ndt_t *
376
+ mk_var_ellipsis(const ndt_t *type, ndt_context_t *ctx)
321
377
  {
322
- char *s = ndt_strdup("var", ctx);
378
+ const ndt_t *t;
379
+ char *s;
323
380
 
381
+ s = ndt_strdup("var", ctx);
324
382
  if (s == NULL) {
383
+ ndt_decref(type);
325
384
  return NULL;
326
385
  }
327
386
 
328
- return ndt_ellipsis_dim(s, type, ctx);
387
+ t = ndt_ellipsis_dim(s, type, ctx);
388
+ ndt_decref(type);
389
+ return t;
390
+ }
391
+
392
+ const ndt_t *
393
+ mk_array_ellipsis(const ndt_t *type, ndt_context_t *ctx)
394
+ {
395
+ const ndt_t *t;
396
+ char *s;
397
+
398
+ s = ndt_strdup("array", ctx);
399
+ if (s == NULL) {
400
+ ndt_decref(type);
401
+ return NULL;
402
+ }
403
+
404
+ t = ndt_ellipsis_dim(s, type, ctx);
405
+ ndt_decref(type);
406
+ return t;
329
407
  }
330
408
 
331
409
  ndt_field_t *
332
- mk_field(char *name, ndt_t *type, ndt_attr_seq_t *attrs, ndt_context_t *ctx)
410
+ mk_field(char *name, const ndt_t *type, ndt_attr_seq_t *attrs, ndt_context_t *ctx)
333
411
  {
334
412
  static const attr_spec kwlist = {0, 2, {"align", "pack"}, {AttrUint16Opt, AttrUint16Opt}};
335
413
  uint16_opt_t align = {None, 0};
336
414
  uint16_opt_t pack = {None, 0};
337
415
  uint16_opt_t pad = {None, 0};
416
+ ndt_field_t *f;
338
417
 
339
418
  if (attrs) {
340
419
  int ret = ndt_parse_attr(&kwlist, ctx, attrs, &align, &pack);
@@ -342,22 +421,24 @@ mk_field(char *name, ndt_t *type, ndt_attr_seq_t *attrs, ndt_context_t *ctx)
342
421
 
343
422
  if (ret < 0) {
344
423
  ndt_free(name);
345
- ndt_del(type);
424
+ ndt_decref(type);
346
425
  return NULL;
347
426
  }
348
427
  }
349
428
 
350
- return ndt_field(name, type, align, pack, pad, ctx);
429
+ f = ndt_field(name, type, align, pack, pad, ctx);
430
+ ndt_decref(type);
431
+ return f;
351
432
  }
352
433
 
353
- ndt_t *
434
+ const ndt_t *
354
435
  mk_tuple(enum ndt_variadic flag, ndt_field_seq_t *fields,
355
- ndt_attr_seq_t *attrs, ndt_context_t *ctx)
436
+ ndt_attr_seq_t *attrs, bool opt, ndt_context_t *ctx)
356
437
  {
357
438
  static const attr_spec kwlist = {0, 2, {"align", "pack"}, {AttrUint16Opt, AttrUint16Opt}};
358
439
  uint16_opt_t align = {None, 0};
359
440
  uint16_opt_t pack = {None, 0};
360
- ndt_t *t;
441
+ const ndt_t *t;
361
442
 
362
443
  fields = ndt_field_seq_finalize(fields);
363
444
 
@@ -372,22 +453,22 @@ mk_tuple(enum ndt_variadic flag, ndt_field_seq_t *fields,
372
453
  }
373
454
 
374
455
  if (fields == NULL) {
375
- return ndt_tuple(flag, NULL, 0, align, pack, ctx);
456
+ return ndt_tuple(flag, NULL, 0, align, pack, opt, ctx);
376
457
  }
377
458
 
378
- t = ndt_tuple(flag, fields->ptr, fields->len, align, pack, ctx);
379
- ndt_free(fields);
459
+ t = ndt_tuple(flag, fields->ptr, fields->len, align, pack, opt, ctx);
460
+ ndt_field_seq_del(fields);
380
461
  return t;
381
462
  }
382
463
 
383
- ndt_t *
464
+ const ndt_t *
384
465
  mk_record(enum ndt_variadic flag, ndt_field_seq_t *fields,
385
- ndt_attr_seq_t *attrs, ndt_context_t *ctx)
466
+ ndt_attr_seq_t *attrs, bool opt, ndt_context_t *ctx)
386
467
  {
387
468
  static const attr_spec kwlist = {0, 2, {"align", "pack"}, {AttrUint16Opt, AttrUint16Opt}};
388
469
  uint16_opt_t align = {None, 0};
389
470
  uint16_opt_t pack = {None, 0};
390
- ndt_t *t;
471
+ const ndt_t *t;
391
472
 
392
473
  fields = ndt_field_seq_finalize(fields);
393
474
 
@@ -402,28 +483,39 @@ mk_record(enum ndt_variadic flag, ndt_field_seq_t *fields,
402
483
  }
403
484
 
404
485
  if (fields == NULL) {
405
- return ndt_record(flag, NULL, 0, align, pack, ctx);
486
+ return ndt_record(flag, NULL, 0, align, pack, opt, ctx);
406
487
  }
407
488
 
408
- t = ndt_record(flag, fields->ptr, fields->len, align, pack, ctx);
409
- ndt_free(fields);
489
+ t = ndt_record(flag, fields->ptr, fields->len, align, pack, opt, ctx);
490
+ ndt_field_seq_del(fields);
491
+ return t;
492
+ }
493
+
494
+ const ndt_t *
495
+ mk_union(ndt_field_seq_t *fields, bool opt, ndt_context_t *ctx)
496
+ {
497
+ const ndt_t *t;
498
+
499
+ fields = ndt_field_seq_finalize(fields);
500
+ t = ndt_union(fields->ptr, fields->len, opt, ctx);
501
+ ndt_field_seq_del(fields);
410
502
  return t;
411
503
  }
412
504
 
413
- ndt_t *
414
- mk_categorical(ndt_value_seq_t *seq, ndt_context_t *ctx)
505
+ const ndt_t *
506
+ mk_categorical(ndt_value_seq_t *seq, bool opt, ndt_context_t *ctx)
415
507
  {
416
- ndt_t *t;
508
+ const ndt_t *t;
417
509
 
418
510
  seq = ndt_value_seq_finalize(seq);
419
- t = ndt_categorical(seq->ptr, seq->len, ctx);
511
+ t = ndt_categorical(seq->ptr, seq->len, opt, ctx);
420
512
 
421
513
  ndt_free(seq);
422
514
  return t;
423
515
  }
424
516
 
425
- ndt_t *
426
- mk_fixed_string(char *v, enum ndt_encoding encoding, ndt_context_t *ctx)
517
+ const ndt_t *
518
+ mk_fixed_string(char *v, enum ndt_encoding encoding, bool opt, ndt_context_t *ctx)
427
519
  {
428
520
  int64_t size;
429
521
 
@@ -434,11 +526,11 @@ mk_fixed_string(char *v, enum ndt_encoding encoding, ndt_context_t *ctx)
434
526
  return NULL;
435
527
  }
436
528
 
437
- return ndt_fixed_string(size, encoding, ctx);
529
+ return ndt_fixed_string(size, encoding, opt, ctx);
438
530
  }
439
531
 
440
- ndt_t *
441
- mk_fixed_bytes(ndt_attr_seq_t *attrs, ndt_context_t *ctx)
532
+ const ndt_t *
533
+ mk_fixed_bytes(ndt_attr_seq_t *attrs, bool opt, ndt_context_t *ctx)
442
534
  {
443
535
  static const attr_spec kwlist = {1, 2, {"size", "align"}, {AttrInt64, AttrUint16Opt}};
444
536
  uint16_opt_t align = {None, 0};
@@ -452,11 +544,11 @@ mk_fixed_bytes(ndt_attr_seq_t *attrs, ndt_context_t *ctx)
452
544
  }
453
545
  }
454
546
 
455
- return ndt_fixed_bytes(datasize, align, ctx);
547
+ return ndt_fixed_bytes(datasize, align, opt, ctx);
456
548
  }
457
549
 
458
- ndt_t *
459
- mk_bytes(ndt_attr_seq_t *attrs, ndt_context_t *ctx)
550
+ const ndt_t *
551
+ mk_bytes(ndt_attr_seq_t *attrs, bool opt, ndt_context_t *ctx)
460
552
  {
461
553
  static const attr_spec kwlist = {0, 1, {"align"}, {AttrUint16Opt}};
462
554
  uint16_opt_t target_align = {None, 0};
@@ -469,5 +561,5 @@ mk_bytes(ndt_attr_seq_t *attrs, ndt_context_t *ctx)
469
561
  }
470
562
  }
471
563
 
472
- return ndt_bytes(target_align, ctx);
564
+ return ndt_bytes(target_align, opt, ctx);
473
565
  }