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
@@ -14,23 +14,23 @@ default: runtest runtest_shared
14
14
 
15
15
  runtest:\
16
16
  Makefile runtest.c alloc_fail.c test_parse.c test_parse_error.c test_parse_roundtrip.c \
17
- test_indent.c test_typecheck.c test_numba.c test_typedef.c test_match.c test_buffer.c \
18
- test.h alloc_fail.h \
17
+ test_indent.c test_typecheck.c test_numba.c test_typedef.c test_match.c test_unify.c \
18
+ test_buffer.c test.h alloc_fail.h \
19
19
  $(SRCDIR)\ndtypes.h $(SRCDIR)\$(LIBSTATIC)
20
20
  $(CC) -I$(SRCDIR) $(CFLAGS) -DTEST_ALLOC /Feruntest runtest.c \
21
21
  alloc_fail.c test_parse.c test_parse_error.c test_parse_roundtrip.c \
22
22
  test_indent.c test_typecheck.c test_numba.c test_typedef.c test_match.c \
23
- test_buffer.c \
23
+ test_unify.c test_buffer.c \
24
24
  $(SRCDIR)\$(LIBSTATIC)
25
25
 
26
26
  runtest_shared:\
27
27
  Makefile runtest.c alloc_fail.c test_parse.c test_parse_error.c test_parse_roundtrip.c \
28
- test_indent.c test_typedef.c test_match.c test.h alloc_fail.h \
28
+ test_indent.c test_typedef.c test_match.c test_unify.c test.h alloc_fail.h \
29
29
  $(SRCDIR)\ndtypes.h $(SRCDIR)\$(LIBSHARED)
30
30
  $(CC) -I$(SRCDIR) $(CFLAGS_SHARED) -DTEST_ALLOC /Feruntest_shared runtest.c \
31
31
  alloc_fail.c test_parse.c test_parse_error.c test_parse_roundtrip.c \
32
32
  test_indent.c test_typecheck.c test_numba.c test_typedef.c test_match.c \
33
- test_buffer.c \
33
+ test_unify.c test_buffer.c \
34
34
  $(SRCDIR)\$(LIBSHARED)
35
35
 
36
36
 
@@ -53,7 +53,8 @@ static int
53
53
  init_tests(void)
54
54
  {
55
55
  ndt_context_t *ctx;
56
- ndt_t *t = NULL;
56
+ const ndt_t *t = NULL;
57
+ int ret;
57
58
 
58
59
  ctx = ndt_context_new();
59
60
  if (ctx == NULL) {
@@ -73,7 +74,10 @@ init_tests(void)
73
74
  ndt_context_del(ctx);
74
75
  return -1;
75
76
  }
76
- if (ndt_typedef("defined_t", t, NULL, ctx) < 0) {
77
+
78
+ ret = ndt_typedef("defined_t", t, NULL, ctx);
79
+ ndt_decref(t);
80
+ if (ret < 0) {
77
81
  ndt_err_fprint(stderr, ctx);
78
82
  ndt_context_del(ctx);
79
83
  return -1;
@@ -85,7 +89,10 @@ init_tests(void)
85
89
  ndt_context_del(ctx);
86
90
  return -1;
87
91
  }
88
- if (ndt_typedef("foo_t", t, NULL, ctx) < 0) {
92
+
93
+ ret = ndt_typedef("foo_t", t, NULL, ctx);
94
+ ndt_decref(t);
95
+ if (ret < 0) {
89
96
  ndt_err_fprint(stderr, ctx);
90
97
  ndt_context_del(ctx);
91
98
  return -1;
@@ -100,7 +107,7 @@ test_parse(void)
100
107
  {
101
108
  const char **c;
102
109
  ndt_context_t *ctx;
103
- ndt_t *t;
110
+ const ndt_t *t;
104
111
  char *s;
105
112
  int count = 0;
106
113
 
@@ -123,7 +130,7 @@ test_parse(void)
123
130
  }
124
131
 
125
132
  if (t != NULL) {
126
- ndt_del(t);
133
+ ndt_decref(t);
127
134
  ndt_context_del(ctx);
128
135
  fprintf(stderr, "test_parse: parse: FAIL: t != NULL after MemoryError\n");
129
136
  fprintf(stderr, "test_parse: parse: FAIL: %s\n", *c);
@@ -152,7 +159,7 @@ test_parse(void)
152
159
 
153
160
  if (s != NULL) {
154
161
  ndt_free(s);
155
- ndt_del(t);
162
+ ndt_decref(t);
156
163
  ndt_context_del(ctx);
157
164
  fprintf(stderr, "test_parse: convert: FAIL: s != NULL after MemoryError\n");
158
165
  fprintf(stderr, "test_parse: parse: FAIL: %s\n", *c);
@@ -164,13 +171,13 @@ test_parse(void)
164
171
  fprintf(stderr, "test_parse: convert: FAIL: got: %s: %s\n\n",
165
172
  ndt_err_as_string(ctx->err),
166
173
  ndt_context_msg(ctx));
167
- ndt_del(t);
174
+ ndt_decref(t);
168
175
  ndt_context_del(ctx);
169
176
  return -1;
170
177
  }
171
178
 
172
179
  ndt_free(s);
173
- ndt_del(t);
180
+ ndt_decref(t);
174
181
  count++;
175
182
  }
176
183
  fprintf(stderr, "test_parse (%d test cases)\n", count);
@@ -184,7 +191,7 @@ test_parse_roundtrip(void)
184
191
  {
185
192
  const char **c;
186
193
  ndt_context_t *ctx;
187
- ndt_t *t;
194
+ const ndt_t *t;
188
195
  char *s;
189
196
  int count = 0;
190
197
 
@@ -211,7 +218,7 @@ test_parse_roundtrip(void)
211
218
  fprintf(stderr, "test_parse_roundtrip: convert: FAIL: got: %s: %s\n\n",
212
219
  ndt_err_as_string(ctx->err),
213
220
  ndt_context_msg(ctx));
214
- ndt_del(t);
221
+ ndt_decref(t);
215
222
  ndt_context_del(ctx);
216
223
  return -1;
217
224
  }
@@ -220,13 +227,13 @@ test_parse_roundtrip(void)
220
227
  fprintf(stderr, "test_parse_roundtrip: convert: FAIL: input: \"%s\"\n", *c);
221
228
  fprintf(stderr, "test_parse_roundtrip: convert: FAIL: roundtrip: \"%s\"\n", s);
222
229
  ndt_free(s);
223
- ndt_del(t);
230
+ ndt_decref(t);
224
231
  ndt_context_del(ctx);
225
232
  return -1;
226
233
  }
227
234
 
228
235
  ndt_free(s);
229
- ndt_del(t);
236
+ ndt_decref(t);
230
237
  count++;
231
238
  }
232
239
  fprintf(stderr, "test_parse_roundtrip (%d test cases)\n", count);
@@ -240,7 +247,7 @@ test_parse_error(void)
240
247
  {
241
248
  const char **c;
242
249
  ndt_context_t *ctx;
243
- ndt_t *t;
250
+ const ndt_t *t;
244
251
  int count = 0;
245
252
 
246
253
  ctx = ndt_context_new();
@@ -262,7 +269,7 @@ test_parse_error(void)
262
269
  }
263
270
 
264
271
  if (t != NULL) {
265
- ndt_del(t);
272
+ ndt_decref(t);
266
273
  ndt_context_del(ctx);
267
274
  fprintf(stderr, "test_parse_error: FAIL: t != NULL after MemoryError\n");
268
275
  fprintf(stderr, "test_parse_error: FAIL: input: %s\n", *c);
@@ -274,7 +281,7 @@ test_parse_error(void)
274
281
  fprintf(stderr, "test_parse_error: FAIL: t != NULL after %s: %s\n",
275
282
  ndt_err_as_string(ctx->err),
276
283
  ndt_context_msg(ctx));
277
- ndt_del(t);
284
+ ndt_decref(t);
278
285
  ndt_context_del(ctx);
279
286
  return -1;
280
287
  }
@@ -292,7 +299,7 @@ test_indent(void)
292
299
  const indent_testcase_t *tc;
293
300
  const char **c;
294
301
  ndt_context_t *ctx;
295
- ndt_t *t;
302
+ const ndt_t *t;
296
303
  char *s;
297
304
  int count = 0;
298
305
 
@@ -326,7 +333,7 @@ test_indent(void)
326
333
 
327
334
  if (s != NULL) {
328
335
  ndt_free(s);
329
- ndt_del(t);
336
+ ndt_decref(t);
330
337
  ndt_context_del(ctx);
331
338
  fprintf(stderr, "test_indent: convert: FAIL: s != NULL after MemoryError\n");
332
339
  fprintf(stderr, "test_indent: convert: FAIL: %s\n", *c);
@@ -338,13 +345,13 @@ test_indent(void)
338
345
  fprintf(stderr, "test_indent: convert: FAIL: got: %s: %s\n\n",
339
346
  ndt_err_as_string(ctx->err),
340
347
  ndt_context_msg(ctx));
341
- ndt_del(t);
348
+ ndt_decref(t);
342
349
  ndt_context_del(ctx);
343
350
  return -1;
344
351
  }
345
352
 
346
353
  ndt_free(s);
347
- ndt_del(t);
354
+ ndt_decref(t);
348
355
  count++;
349
356
  }
350
357
 
@@ -372,7 +379,7 @@ test_indent(void)
372
379
 
373
380
  if (s != NULL) {
374
381
  ndt_free(s);
375
- ndt_del(t);
382
+ ndt_decref(t);
376
383
  ndt_context_del(ctx);
377
384
  fprintf(stderr, "test_indent: convert: FAIL: s != NULL after MemoryError\n");
378
385
  fprintf(stderr, "test_indent: convert: FAIL: %s\n", tc->input);
@@ -384,7 +391,7 @@ test_indent(void)
384
391
  fprintf(stderr, "test_indent: convert: FAIL: got: %s: %s\n\n",
385
392
  ndt_err_as_string(ctx->err),
386
393
  ndt_context_msg(ctx));
387
- ndt_del(t);
394
+ ndt_decref(t);
388
395
  ndt_context_del(ctx);
389
396
  return -1;
390
397
  }
@@ -394,13 +401,13 @@ test_indent(void)
394
401
  fprintf(stderr, "test_indent: convert: FAIL: got: %s: %s\n\n",
395
402
  ndt_err_as_string(ctx->err),
396
403
  ndt_context_msg(ctx));
397
- ndt_del(t);
404
+ ndt_decref(t);
398
405
  ndt_context_del(ctx);
399
406
  return -1;
400
407
  }
401
408
 
402
409
  ndt_free(s);
403
- ndt_del(t);
410
+ ndt_decref(t);
404
411
  count++;
405
412
  }
406
413
 
@@ -415,7 +422,7 @@ test_typedef(void)
415
422
  {
416
423
  const char **c;
417
424
  ndt_context_t *ctx;
418
- ndt_t *t;
425
+ const ndt_t *t;
419
426
  int count = 0;
420
427
 
421
428
  ctx = ndt_context_new();
@@ -433,6 +440,7 @@ test_typedef(void)
433
440
  ndt_set_alloc_fail();
434
441
  (void)ndt_typedef(*c, t, NULL, ctx);
435
442
  ndt_set_alloc();
443
+ ndt_decref(t);
436
444
 
437
445
  if (ctx->err != NDT_MemoryError) {
438
446
  break;
@@ -469,7 +477,7 @@ test_typedef_duplicates(void)
469
477
  {
470
478
  const char **c;
471
479
  ndt_context_t *ctx;
472
- ndt_t *t;
480
+ const ndt_t *t;
473
481
  int count = 0;
474
482
 
475
483
  ctx = ndt_context_new();
@@ -487,19 +495,23 @@ test_typedef_duplicates(void)
487
495
  ndt_set_alloc_fail();
488
496
  (void)ndt_typedef(*c, t, NULL, ctx);
489
497
  ndt_set_alloc();
498
+ ndt_decref(t);
490
499
 
491
500
  if (ctx->err != NDT_MemoryError) {
501
+ if (ndt_typedef_find(*c, ctx) == NULL) {
502
+ fprintf(stderr, "test_typedef: FAIL: key should be in map\n");
503
+ fprintf(stderr, "test_typedef: FAIL: input: %s\n", *c);
504
+ ndt_context_del(ctx);
505
+ return -1;
506
+ }
492
507
  break;
493
508
  }
494
-
495
- if (ndt_typedef_find(*c, ctx) == NULL) {
496
- fprintf(stderr, "test_typedef: FAIL: key should be in map\n");
497
- fprintf(stderr, "test_typedef: FAIL: input: %s\n", *c);
498
- ndt_context_del(ctx);
499
- return -1;
500
- }
501
509
  }
502
510
 
511
+ t = ndt_from_string("10 * 20 * {a : int64, b : ref(float64)}", ctx);
512
+ (void)ndt_typedef(*c, t, NULL, ctx);
513
+ ndt_decref(t);
514
+
503
515
  if (ctx->err != NDT_ValueError) {
504
516
  fprintf(stderr, "test_typedef: FAIL: no value error after duplicate key\n");
505
517
  fprintf(stderr, "test_typedef: FAIL: input: %s\n", *c);
@@ -521,7 +533,7 @@ test_typedef_error(void)
521
533
  {
522
534
  const char **c;
523
535
  ndt_context_t *ctx;
524
- ndt_t *t;
536
+ const ndt_t *t;
525
537
  int count = 0;
526
538
 
527
539
  ctx = ndt_context_new();
@@ -539,6 +551,7 @@ test_typedef_error(void)
539
551
  ndt_set_alloc_fail();
540
552
  (void)ndt_typedef(*c, t, NULL, ctx);
541
553
  ndt_set_alloc();
554
+ ndt_decref(t);
542
555
 
543
556
  if (ctx->err != NDT_MemoryError) {
544
557
  break;
@@ -575,7 +588,7 @@ test_equal(void)
575
588
  {
576
589
  const char **c;
577
590
  ndt_context_t *ctx;
578
- ndt_t *t, *u;
591
+ const ndt_t *t, *u;
579
592
  int count = 0;
580
593
 
581
594
  ctx = ndt_context_new();
@@ -596,29 +609,29 @@ test_equal(void)
596
609
 
597
610
  u = ndt_from_string(*(c+1), ctx);
598
611
  if (u == NULL) {
599
- ndt_del(t);
612
+ ndt_decref(t);
600
613
  ndt_context_del(ctx);
601
614
  fprintf(stderr, "test_equal: FAIL: could not parse \"%s\"\n", *(c+1));
602
615
  return -1;
603
616
  }
604
617
 
605
618
  if (!ndt_equal(t, t)) {
606
- ndt_del(t);
607
- ndt_del(u);
619
+ ndt_decref(t);
620
+ ndt_decref(u);
608
621
  ndt_context_del(ctx);
609
622
  fprintf(stderr, "test_equal: FAIL: \"%s\" != \"%s\"\n", *c, *c);
610
623
  return -1;
611
624
  }
612
625
 
613
626
  if (ndt_equal(t, u)) {
614
- ndt_del(t);
615
- ndt_del(u);
627
+ ndt_decref(t);
628
+ ndt_decref(u);
616
629
  fprintf(stderr, "test_equal: FAIL: \"%s\" == \"%s\"\n", *c, *(c+1));
617
630
  return -1;
618
631
  }
619
632
 
620
- ndt_del(t);
621
- ndt_del(u);
633
+ ndt_decref(t);
634
+ ndt_decref(u);
622
635
  count++;
623
636
  }
624
637
 
@@ -633,8 +646,8 @@ test_match(void)
633
646
  {
634
647
  const match_testcase_t *t;
635
648
  ndt_context_t *ctx;
636
- ndt_t *p;
637
- ndt_t *c;
649
+ const ndt_t *p;
650
+ const ndt_t *c;
638
651
  int ret, count = 0;
639
652
 
640
653
  ctx = ndt_context_new();
@@ -653,7 +666,7 @@ test_match(void)
653
666
 
654
667
  c = ndt_from_string(t->candidate, ctx);
655
668
  if (c == NULL) {
656
- ndt_del(p);
669
+ ndt_decref(p);
657
670
  ndt_context_del(ctx);
658
671
  fprintf(stderr, "test_match: FAIL: could not parse \"%s\"\n", t->candidate);
659
672
  return -1;
@@ -671,8 +684,8 @@ test_match(void)
671
684
  }
672
685
 
673
686
  if (ret != -1) {
674
- ndt_del(p);
675
- ndt_del(c);
687
+ ndt_decref(p);
688
+ ndt_decref(c);
676
689
  ndt_context_del(ctx);
677
690
  fprintf(stderr, "test_match: FAIL: expect ret == -1 after MemoryError\n");
678
691
  fprintf(stderr, "test_match: FAIL: \"%s\"\n", t->pattern);
@@ -681,8 +694,8 @@ test_match(void)
681
694
  }
682
695
 
683
696
  if (ret != t->expected) {
684
- ndt_del(p);
685
- ndt_del(c);
697
+ ndt_decref(p);
698
+ ndt_decref(c);
686
699
  ndt_context_del(ctx);
687
700
  fprintf(stderr, "test_match: FAIL: expected %s\n", t->expected ? "true" : "false");
688
701
  fprintf(stderr, "test_match: FAIL: pattern: \"%s\"\n", t->pattern);
@@ -690,8 +703,8 @@ test_match(void)
690
703
  return -1;
691
704
  }
692
705
 
693
- ndt_del(p);
694
- ndt_del(c);
706
+ ndt_decref(p);
707
+ ndt_decref(c);
695
708
  count++;
696
709
  }
697
710
  fprintf(stderr, "test_match (%d test cases)\n", count);
@@ -700,9 +713,104 @@ test_match(void)
700
713
  return 0;
701
714
  }
702
715
 
716
+ static int
717
+ test_unify(void)
718
+ {
719
+ const unify_testcase_t *t;
720
+ ndt_context_t *ctx;
721
+ const ndt_t *t1;
722
+ const ndt_t *t2;
723
+ const ndt_t *expected;
724
+ const ndt_t *ret;
725
+ int count = 0;
726
+
727
+ ctx = ndt_context_new();
728
+ if (ctx == NULL) {
729
+ fprintf(stderr, "error: out of memory");
730
+ return -1;
731
+ }
732
+
733
+ for (t = unify_tests; t->t1 != NULL; t++) {
734
+ t1 = ndt_from_string(t->t1, ctx);
735
+ if (t1 == NULL) {
736
+ fprintf(stderr, "test_unify: FAIL: could not parse t1 \"%s\"\n", t->t1);
737
+ ndt_context_del(ctx);
738
+ return -1;
739
+ }
740
+
741
+ t2 = ndt_from_string(t->t2, ctx);
742
+ if (t2 == NULL) {
743
+ ndt_decref(t1);
744
+ ndt_context_del(ctx);
745
+ fprintf(stderr, "test_unify: FAIL: could not parse t2 \"%s\"\n", t->t2);
746
+ return -1;
747
+ }
748
+
749
+ expected = NULL;
750
+ if (t->expected) {
751
+ expected = ndt_from_string(t->expected, ctx);
752
+ if (expected == NULL) {
753
+ ndt_decref(t1);
754
+ ndt_decref(t2);
755
+ ndt_context_del(ctx);
756
+ fprintf(stderr, "test_unify: FAIL: could not parse expected \"%s\"\n", t->expected);
757
+ return -1;
758
+ }
759
+ }
760
+
761
+ for (alloc_fail = 1; alloc_fail < INT_MAX; alloc_fail++) {
762
+ ndt_err_clear(ctx);
763
+
764
+ ndt_set_alloc_fail();
765
+ ret = ndt_unify(t1, t2, ctx);
766
+ ndt_set_alloc();
767
+
768
+ if (ctx->err != NDT_MemoryError) {
769
+ break;
770
+ }
771
+
772
+ if (ret != NULL) {
773
+ ndt_decref(t1);
774
+ ndt_decref(t2);
775
+ ndt_decref(expected);
776
+ ndt_context_del(ctx);
777
+ fprintf(stderr, "test_unify: FAIL: expect ret == NULL after MemoryError\n");
778
+ fprintf(stderr, "test_unify: FAIL: \"%s\"\n", t->t1);
779
+ return -1;
780
+ }
781
+ }
782
+
783
+ ndt_decref(t1);
784
+ ndt_decref(t2);
785
+
786
+ if (ret == NULL && expected == NULL) {
787
+ ndt_err_clear(ctx);
788
+ continue;
789
+ }
790
+
791
+ if ((ret != NULL && expected != NULL) && ndt_equal(ret, expected)) {
792
+ ndt_decref(ret);
793
+ ndt_decref(expected);
794
+ count++;
795
+ continue;
796
+ }
797
+
798
+ ndt_decref(expected);
799
+ ndt_decref(ret);
800
+ fprintf(stderr, "test_unify: FAIL: expected \"%s\"\n", t->expected);
801
+ fprintf(stderr, "test_unify: FAIL: t1: \"%s\"\n", t->t1);
802
+ fprintf(stderr, "test_unify: FAIL: t2: \"%s\"\n", t->t2);
803
+ return -1;
804
+ }
805
+ fprintf(stderr, "test_unify (%d test cases)\n", count);
806
+
807
+ ndt_context_del(ctx);
808
+ return 0;
809
+ }
810
+
703
811
  typedef struct {
704
812
  int64_t size;
705
- ndt_t *types[NDT_MAX_ARGS];
813
+ const ndt_t *types[NDT_MAX_ARGS];
706
814
  } type_array_t;
707
815
 
708
816
  static type_array_t
@@ -726,14 +834,13 @@ types_from_string(const char * const *s, ndt_context_t *ctx)
726
834
  }
727
835
 
728
836
  static int
729
- validate_typecheck_test(const typecheck_testcase_t *test,
837
+ validate_typecheck_test(ndt_apply_spec_t *spec,
730
838
  const ndt_t *sig,
731
- ndt_apply_spec_t *spec,
839
+ const typecheck_testcase_t *test,
732
840
  int ret,
733
841
  ndt_context_t *ctx)
734
842
  {
735
- type_array_t out;
736
- type_array_t broadcast;
843
+ type_array_t expected;
737
844
  int64_t i;
738
845
 
739
846
  if (!test->success) {
@@ -741,68 +848,62 @@ validate_typecheck_test(const typecheck_testcase_t *test,
741
848
  return 0;
742
849
  }
743
850
  ndt_err_format(ctx, NDT_RuntimeError,
744
- "test_typecheck: unexpected success: %s %s %s",
745
- test->signature, test->in[0], test->in[1]);
851
+ "test_typecheck: %s: expected success=false, got success=true",
852
+ test->loc);
746
853
  return -1;
747
854
  }
748
855
 
749
- out = types_from_string(test->out, ctx);
750
- if (out.size < 0) {
856
+ expected = types_from_string(test->types, ctx);
857
+ if (expected.size < 0) {
751
858
  return -1;
752
859
  }
753
860
 
754
- broadcast = types_from_string(test->broadcast, ctx);
755
- if (broadcast.size < 0) {
756
- ndt_type_array_clear(broadcast.types, broadcast.size);
861
+ if (spec->outer_dims != test->outer_dims) {
862
+ ndt_err_format(ctx, NDT_RuntimeError,
863
+ "test_typecheck: %s: expected outer_dims=%d, got outer_dims=%d",
864
+ test->loc, test->outer_dims, spec->outer_dims);
865
+ ndt_type_array_clear(expected.types, expected.size);
757
866
  return -1;
758
867
  }
759
868
 
760
- if (spec->nout != sig->Function.nout ||
761
- spec->nout != out.size) {
869
+ if (spec->nin != sig->Function.nin || spec->nin != test->nin) {
762
870
  ndt_err_format(ctx, NDT_RuntimeError,
763
- "test_typecheck: expected nout==test->nout==%d, got nout==%d and "
764
- "test->nout==%d\n", sig->Function.nout, spec->nout, out.size);
871
+ "test_typecheck: %s: expected nin=%d, got nin=%d",
872
+ test->loc, test->nin, spec->nin);
873
+ ndt_type_array_clear(expected.types, expected.size);
765
874
  return -1;
766
875
  }
767
876
 
768
- if (spec->nbroadcast != broadcast.size) {
877
+ if (spec->nout != sig->Function.nout || spec->nout != test->nout) {
769
878
  ndt_err_format(ctx, NDT_RuntimeError,
770
- "test_typecheck: expected nbroadcast==%d, got %d\n",
771
- broadcast.size, spec->nbroadcast);
879
+ "test_typecheck: %s: expected nout=%d, got nout=%d",
880
+ test->loc, test->nout, spec->nout);
881
+ ndt_type_array_clear(expected.types, expected.size);
772
882
  return -1;
773
883
  }
774
884
 
775
- if (spec->outer_dims != test->outer_dims) {
885
+ if (spec->nargs != sig->Function.nargs || spec->nargs != test->nargs ||
886
+ spec->nargs != expected.size) {
776
887
  ndt_err_format(ctx, NDT_RuntimeError,
777
- "test_typecheck: expected outer_dims==%d, got %d\n",
778
- test->outer_dims, spec->outer_dims);
888
+ "test_typecheck: %s: expected nargs=%d, got nargs=%d",
889
+ test->loc, test->nargs, spec->nargs);
890
+ ndt_type_array_clear(expected.types, expected.size);
779
891
  return -1;
780
892
  }
781
893
 
782
- for (i = 0; i < spec->nout; i++) {
783
- if (!ndt_equal(spec->out[i], out.types[i])) {
894
+ for (i = 0; i < spec->nargs; i++) {
895
+ if (!ndt_equal(spec->types[i], expected.types[i])) {
784
896
  ndt_err_format(ctx, NDT_RuntimeError,
785
- "test_typecheck: out value %d: expected %s, got %s",
786
- i, test->out[i], ndt_ast_repr(spec->out[i], ctx));
787
- ndt_type_array_clear(out.types, out.size);
788
- ndt_type_array_clear(broadcast.types, broadcast.size);
897
+ "test_typecheck: %s: expected %s, got %s",
898
+ test->loc,
899
+ ndt_ast_repr(expected.types[i], ctx),
900
+ ndt_ast_repr(spec->types[i], ctx));
901
+ ndt_type_array_clear(expected.types, expected.size);
789
902
  return -1;
790
903
  }
791
904
  }
792
905
 
793
- for (i = 0; i < spec->nbroadcast; i++) {
794
- if (!ndt_equal(spec->broadcast[i], broadcast.types[i])) {
795
- ndt_err_format(ctx, NDT_RuntimeError,
796
- "test_typecheck: broadcast value %d: expected %s, got %s",
797
- i, test->broadcast[i], ndt_ast_repr(spec->broadcast[i], ctx));
798
- ndt_type_array_clear(out.types, out.size);
799
- ndt_type_array_clear(broadcast.types, broadcast.size);
800
- return -1;
801
- }
802
- }
803
-
804
- ndt_type_array_clear(out.types, out.size);
805
- ndt_type_array_clear(broadcast.types, broadcast.size);
906
+ ndt_type_array_clear(expected.types, expected.size);
806
907
 
807
908
  return 0;
808
909
  }
@@ -813,8 +914,11 @@ test_typecheck(void)
813
914
  NDT_STATIC_CONTEXT(ctx);
814
915
  ndt_apply_spec_t spec = ndt_apply_spec_empty;
815
916
  const typecheck_testcase_t *test;
917
+ const ndt_t *types[NDT_MAX_DIM] = {NULL};
918
+ const int64_t li[NDT_MAX_DIM] = {0};
919
+ type_array_t args;
920
+ type_array_t kwargs;
816
921
  const ndt_t *sig = NULL;
817
- type_array_t in;
818
922
  int count = 0;
819
923
  int ret = -1;
820
924
 
@@ -826,36 +930,60 @@ test_typecheck(void)
826
930
  goto error;
827
931
  }
828
932
 
829
- in = types_from_string(test->in, &ctx);
830
- if (in.size < 0) {
933
+ args = types_from_string(test->args, &ctx);
934
+ if (args.size < 0) {
935
+ goto error;
936
+ }
937
+ const int nin = args.size;
938
+
939
+ kwargs = types_from_string(test->kwargs, &ctx);
940
+ if (kwargs.size < 0) {
831
941
  goto error;
832
942
  }
943
+ const int nout = kwargs.size;
944
+
945
+ for (int i = 0; i < nin; i++) {
946
+ types[i] = args.types[i];
947
+ }
948
+
949
+ for (int i = 0; i < nout; i++) {
950
+ types[nin+i] = kwargs.types[i];
951
+ }
833
952
 
834
953
  for (alloc_fail = 1; alloc_fail < INT_MAX; alloc_fail++) {
835
954
  ndt_err_clear(&ctx);
836
955
 
837
956
  ndt_set_alloc_fail();
838
- ret = ndt_typecheck(&spec, sig, (const ndt_t **)in.types, in.size, NULL, NULL, &ctx);
957
+ ret = ndt_typecheck(&spec, sig, types, li, nin, nout, false, NULL,
958
+ NULL, &ctx);
839
959
  ndt_set_alloc();
840
960
 
841
961
  if (ctx.err != NDT_MemoryError) {
842
962
  break;
843
963
  }
844
964
 
845
- ndt_apply_spec_clear(&spec);
965
+ assert(spec.flags == 0);
966
+ assert(spec.outer_dims == 0);
967
+ assert(spec.nin == 0);
968
+ assert(spec.nout == 0);
969
+ assert(spec.nargs == 0);
970
+
846
971
  if (ret != -1) {
847
972
  ndt_err_format(&ctx, NDT_RuntimeError,
848
- "test_typecheck: expect nout == -1 after MemoryError\n"
849
- "test_typecheck: \"%s\"\n", test->signature);
973
+ "test_typecheck: %s: nout != -1 after MemoryError\n",
974
+ test->loc);
850
975
  goto error;
851
976
  }
852
977
  }
853
978
 
979
+ ndt_type_array_clear(args.types, args.size);
980
+ ndt_type_array_clear(kwargs.types, kwargs.size);
854
981
  ndt_err_clear(&ctx);
855
- ret = validate_typecheck_test(test, sig, &spec, ret, &ctx);
856
- ndt_type_array_clear(in.types, in.size);
982
+
983
+ ret = validate_typecheck_test(&spec, sig, test, ret, &ctx);
984
+
857
985
  ndt_apply_spec_clear(&spec);
858
- ndt_del((ndt_t *)sig);
986
+ ndt_decref(sig);
859
987
 
860
988
  if (ret < 0) {
861
989
  goto error;
@@ -883,7 +1011,7 @@ test_numba(void)
883
1011
  {
884
1012
  NDT_STATIC_CONTEXT(ctx);
885
1013
  const numba_testcase_t *test;
886
- ndt_t *t;
1014
+ const ndt_t *t;
887
1015
  char *sig = NULL;
888
1016
  char *core = NULL;
889
1017
  int count = 0;
@@ -909,7 +1037,7 @@ test_numba(void)
909
1037
  }
910
1038
 
911
1039
  if (ret != -1) {
912
- ndt_del(t);
1040
+ ndt_decref(t);
913
1041
  ndt_err_format(&ctx, NDT_RuntimeError,
914
1042
  "test_numba: expect ret == -1 after MemoryError\n"
915
1043
  "test_numba: \"%s\"\n", test->signature);
@@ -918,7 +1046,7 @@ test_numba(void)
918
1046
  }
919
1047
 
920
1048
  ndt_err_clear(&ctx);
921
- ndt_del(t);
1049
+ ndt_decref(t);
922
1050
 
923
1051
  if (sig == NULL || strcmp(sig, test->sig) != 0) {
924
1052
  ndt_err_format(&ctx, NDT_RuntimeError,
@@ -958,7 +1086,7 @@ test_static_context(void)
958
1086
  {
959
1087
  const char **c;
960
1088
  NDT_STATIC_CONTEXT(ctx);
961
- ndt_t *t;
1089
+ const ndt_t *t;
962
1090
  char *s;
963
1091
  int count = 0;
964
1092
 
@@ -975,7 +1103,7 @@ test_static_context(void)
975
1103
  }
976
1104
 
977
1105
  if (t != NULL) {
978
- ndt_del(t);
1106
+ ndt_decref(t);
979
1107
  fprintf(stderr, "test_static_context: FAIL: t != NULL after MemoryError\n");
980
1108
  fprintf(stderr, "test_static_context: FAIL: %s\n", *c);
981
1109
  return -1;
@@ -1003,7 +1131,7 @@ test_static_context(void)
1003
1131
 
1004
1132
  if (s != NULL) {
1005
1133
  ndt_free(s);
1006
- ndt_del(t);
1134
+ ndt_decref(t);
1007
1135
  fprintf(stderr, "test_static_context: FAIL: s != NULL after MemoryError\n");
1008
1136
  fprintf(stderr, "test_static_context: FAIL: %s\n", *c);
1009
1137
  ndt_context_del(&ctx);
@@ -1015,13 +1143,13 @@ test_static_context(void)
1015
1143
  fprintf(stderr, "test_static_context: FAIL: got: %s: %s\n\n",
1016
1144
  ndt_err_as_string(ctx.err),
1017
1145
  ndt_context_msg(&ctx));
1018
- ndt_del(t);
1146
+ ndt_decref(t);
1019
1147
  ndt_context_del(&ctx);
1020
1148
  return -1;
1021
1149
  }
1022
1150
 
1023
1151
  ndt_free(s);
1024
- ndt_del(t);
1152
+ ndt_decref(t);
1025
1153
  count++;
1026
1154
  }
1027
1155
 
@@ -1029,7 +1157,7 @@ test_static_context(void)
1029
1157
  t = ndt_from_string(s, &ctx);
1030
1158
  if (s == NULL) {
1031
1159
  fprintf(stderr, "test_static_context: FAIL: expected failure: \"%s\"\n", s);
1032
- ndt_del(t);
1160
+ ndt_decref(t);
1033
1161
  ndt_context_del(&ctx);
1034
1162
  return -1;
1035
1163
  }
@@ -1069,7 +1197,7 @@ test_hash(void)
1069
1197
  hash_testcase_t buf[1000];
1070
1198
  ptrdiff_t n = 1;
1071
1199
  const char **c;
1072
- ndt_t *t;
1200
+ const ndt_t *t;
1073
1201
  hash_testcase_t x;
1074
1202
  int i;
1075
1203
 
@@ -1093,7 +1221,7 @@ test_hash(void)
1093
1221
 
1094
1222
  x.hash = ndt_hash(t, &ctx);
1095
1223
  x.str = *c;
1096
- ndt_del(t);
1224
+ ndt_decref(t);
1097
1225
 
1098
1226
  if (x.hash == -1) {
1099
1227
  fprintf(stderr, "test_hash: FAIL: hash==-1\n\n");
@@ -1125,7 +1253,7 @@ test_hash(void)
1125
1253
  x.hash = ndt_hash(t, &ctx);
1126
1254
  ndt_set_alloc();
1127
1255
 
1128
- ndt_del(t);
1256
+ ndt_decref(t);
1129
1257
 
1130
1258
  if (x.hash != -1 || ctx.err != NDT_MemoryError) {
1131
1259
  fprintf(stderr, "test_hash: FAIL: expected failure, got %" PRI_ndt_ssize "\n\n", x.hash);
@@ -1144,7 +1272,7 @@ test_copy(void)
1144
1272
  {
1145
1273
  NDT_STATIC_CONTEXT(ctx);
1146
1274
  const char **c;
1147
- ndt_t *t, *u;
1275
+ const ndt_t *t, *u;
1148
1276
  int count = 0;
1149
1277
 
1150
1278
  for (c = parse_tests; *c != NULL; c++) {
@@ -1171,8 +1299,8 @@ test_copy(void)
1171
1299
 
1172
1300
  if (u != NULL) {
1173
1301
  fprintf(stderr, "test_copy: FAIL: unexpected success: \"%s\"\n", *c);
1174
- ndt_del(u);
1175
- ndt_del(t);
1302
+ ndt_decref(u);
1303
+ ndt_decref(t);
1176
1304
  ndt_context_del(&ctx);
1177
1305
  return -1;
1178
1306
  }
@@ -1182,21 +1310,21 @@ test_copy(void)
1182
1310
  fprintf(stderr, "test_copy: FAIL: got: %s: %s\n\n",
1183
1311
  ndt_err_as_string(ctx.err),
1184
1312
  ndt_context_msg(&ctx));
1185
- ndt_del(t);
1313
+ ndt_decref(t);
1186
1314
  ndt_context_del(&ctx);
1187
1315
  return -1;
1188
1316
  }
1189
1317
 
1190
1318
  if (!ndt_equal(t, u)) {
1191
1319
  fprintf(stderr, "test_copy: FAIL: copy: not equal\n\n");
1192
- ndt_del(t);
1193
- ndt_del(u);
1320
+ ndt_decref(t);
1321
+ ndt_decref(u);
1194
1322
  ndt_context_del(&ctx);
1195
1323
  return -1;
1196
1324
  }
1197
1325
 
1198
- ndt_del(u);
1199
- ndt_del(t);
1326
+ ndt_decref(u);
1327
+ ndt_decref(t);
1200
1328
  count++;
1201
1329
  }
1202
1330
 
@@ -1211,7 +1339,7 @@ test_buffer(void)
1211
1339
  {
1212
1340
  const char **c;
1213
1341
  ndt_context_t *ctx;
1214
- ndt_t *t;
1342
+ const ndt_t *t;
1215
1343
  int count = 0;
1216
1344
 
1217
1345
  ctx = ndt_context_new();
@@ -1233,7 +1361,7 @@ test_buffer(void)
1233
1361
  }
1234
1362
 
1235
1363
  if (t != NULL) {
1236
- ndt_del(t);
1364
+ ndt_decref(t);
1237
1365
  ndt_context_del(ctx);
1238
1366
  fprintf(stderr, "test_buffer: convert: FAIL: t != NULL after MemoryError\n");
1239
1367
  fprintf(stderr, "test_buffer: convert: FAIL: %s\n", *c);
@@ -1249,7 +1377,7 @@ test_buffer(void)
1249
1377
  return -1;
1250
1378
  }
1251
1379
 
1252
- ndt_del(t);
1380
+ ndt_decref(t);
1253
1381
  count++;
1254
1382
  }
1255
1383
  fprintf(stderr, "test_buffer (%d test cases)\n", count);
@@ -1263,7 +1391,7 @@ test_buffer_roundtrip(void)
1263
1391
  {
1264
1392
  const char **c;
1265
1393
  ndt_context_t *ctx;
1266
- ndt_t *t;
1394
+ const ndt_t *t;
1267
1395
  char *s;
1268
1396
  int count = 0;
1269
1397
  int ret;
@@ -1287,7 +1415,7 @@ test_buffer_roundtrip(void)
1287
1415
  }
1288
1416
 
1289
1417
  if (t != NULL) {
1290
- ndt_del(t);
1418
+ ndt_decref(t);
1291
1419
  ndt_context_del(ctx);
1292
1420
  fprintf(stderr, "test_buffer: convert: FAIL: t != NULL after MemoryError\n");
1293
1421
  fprintf(stderr, "test_buffer: convert: FAIL: %s\n", *c);
@@ -1316,7 +1444,7 @@ test_buffer_roundtrip(void)
1316
1444
 
1317
1445
  if (s != NULL) {
1318
1446
  ndt_free(s);
1319
- ndt_del(t);
1447
+ ndt_decref(t);
1320
1448
  ndt_context_del(ctx);
1321
1449
  fprintf(stderr, "test_buffer_roundtrip: convert: FAIL: s != NULL after MemoryError\n");
1322
1450
  fprintf(stderr, "test_buffer_roundtrip: convert: FAIL: %s\n", *c);
@@ -1328,13 +1456,13 @@ test_buffer_roundtrip(void)
1328
1456
  fprintf(stderr, "test_buffer_roundtrip: convert: FAIL: got: %s: %s\n\n",
1329
1457
  ndt_err_as_string(ctx->err),
1330
1458
  ndt_context_msg(ctx));
1331
- ndt_del(t);
1459
+ ndt_decref(t);
1332
1460
  ndt_context_del(ctx);
1333
1461
  return -1;
1334
1462
  }
1335
1463
 
1336
1464
  ret = strcmp(s, *c);
1337
- ndt_del(t);
1465
+ ndt_decref(t);
1338
1466
 
1339
1467
  if (ret != 0) {
1340
1468
  fprintf(stderr, "test_buffer_roundtrip: convert: FAIL: input: \"%s\" output: \"%s\"\n", *c, s);
@@ -1357,7 +1485,7 @@ test_buffer_error(void)
1357
1485
  {
1358
1486
  const char **c;
1359
1487
  ndt_context_t *ctx;
1360
- ndt_t *t;
1488
+ const ndt_t *t;
1361
1489
  int count = 0;
1362
1490
 
1363
1491
  ctx = ndt_context_new();
@@ -1379,7 +1507,7 @@ test_buffer_error(void)
1379
1507
  }
1380
1508
 
1381
1509
  if (t != NULL) {
1382
- ndt_del(t);
1510
+ ndt_decref(t);
1383
1511
  ndt_context_del(ctx);
1384
1512
  fprintf(stderr, "test_buffer_error: FAIL: t != NULL after MemoryError\n");
1385
1513
  fprintf(stderr, "test_buffer_error: FAIL: input: %s\n", *c);
@@ -1391,7 +1519,7 @@ test_buffer_error(void)
1391
1519
  fprintf(stderr, "test_buffer_error: FAIL: t != NULL after %s: %s\n",
1392
1520
  ndt_err_as_string(ctx->err),
1393
1521
  ndt_context_msg(ctx));
1394
- ndt_del(t);
1522
+ ndt_decref(t);
1395
1523
  ndt_context_del(ctx);
1396
1524
  return -1;
1397
1525
  }
@@ -1407,9 +1535,8 @@ static int
1407
1535
  test_serialize(void)
1408
1536
  {
1409
1537
  const char **c;
1410
- ndt_meta_t *m;
1411
1538
  ndt_context_t *ctx;
1412
- ndt_t *t, *u;
1539
+ const ndt_t *t, *u;
1413
1540
  int count = 0;
1414
1541
  char *bytes;
1415
1542
  int64_t len;
@@ -1421,17 +1548,8 @@ test_serialize(void)
1421
1548
  }
1422
1549
 
1423
1550
  for (c = parse_tests; *c != NULL; c++) {
1424
- m = ndt_meta_new(ctx);
1425
- if (m == NULL) {
1426
- ndt_context_del(ctx);
1427
- fprintf(stderr,
1428
- "test_serialize: FAIL: unexpected failure in meta_new");
1429
- return -1;
1430
- }
1431
-
1432
1551
  t = ndt_from_string(*c, ctx);
1433
1552
  if (t == NULL) {
1434
- ndt_meta_del(m);
1435
1553
  ndt_context_del(ctx);
1436
1554
  fprintf(stderr,
1437
1555
  "test_serialize: FAIL: unexpected failure in from_string");
@@ -1451,9 +1569,8 @@ test_serialize(void)
1451
1569
  }
1452
1570
 
1453
1571
  if (len >= 0 || bytes != NULL) {
1454
- ndt_del(t);
1572
+ ndt_decref(t);
1455
1573
  ndt_free(bytes);
1456
- ndt_meta_del(m);
1457
1574
  ndt_context_del(ctx);
1458
1575
  fprintf(stderr, "test_serialize: FAIL: invalid len or bytes after MemoryError\n");
1459
1576
  fprintf(stderr, "test_serialize: FAIL: %s\n", *c);
@@ -1462,9 +1579,8 @@ test_serialize(void)
1462
1579
  }
1463
1580
 
1464
1581
  if (len < 0 || bytes == NULL) {
1465
- ndt_del(t);
1582
+ ndt_decref(t);
1466
1583
  ndt_free(bytes);
1467
- ndt_meta_del(m);
1468
1584
  ndt_context_del(ctx);
1469
1585
  fprintf(stderr, "test_serialize: FAIL: invalid len or bytes (expected success)\n");
1470
1586
  fprintf(stderr, "test_serialize: FAIL: %s\n", *c);
@@ -1475,7 +1591,7 @@ test_serialize(void)
1475
1591
  ndt_err_clear(ctx);
1476
1592
 
1477
1593
  ndt_set_alloc_fail();
1478
- u = ndt_deserialize(m, bytes, len, ctx);
1594
+ u = ndt_deserialize(bytes, len, ctx);
1479
1595
  ndt_set_alloc();
1480
1596
 
1481
1597
  if (ctx->err != NDT_MemoryError) {
@@ -1483,10 +1599,9 @@ test_serialize(void)
1483
1599
  }
1484
1600
 
1485
1601
  if (u != NULL) {
1486
- ndt_del(t);
1487
- ndt_del(u);
1602
+ ndt_decref(t);
1603
+ ndt_decref(u);
1488
1604
  ndt_free(bytes);
1489
- ndt_meta_del(m);
1490
1605
  ndt_context_del(ctx);
1491
1606
  fprintf(stderr, "test_serialize: FAIL: u != NULL after MemoryError\n");
1492
1607
  fprintf(stderr, "test_serialize: FAIL: %s\n", *c);
@@ -1499,9 +1614,8 @@ test_serialize(void)
1499
1614
  fprintf(stderr, "test_serialize: FAIL: got: %s: %s\n\n",
1500
1615
  ndt_err_as_string(ctx->err),
1501
1616
  ndt_context_msg(ctx));
1502
- ndt_del(t);
1617
+ ndt_decref(t);
1503
1618
  ndt_free(bytes);
1504
- ndt_meta_del(m);
1505
1619
  ndt_context_del(ctx);
1506
1620
  return -1;
1507
1621
  }
@@ -1510,17 +1624,15 @@ test_serialize(void)
1510
1624
 
1511
1625
  if (!ndt_equal(u, t)) {
1512
1626
  fprintf(stderr, "test_serialize: FAIL: u != v in %s\n", *c);
1513
- ndt_del(t);
1514
- ndt_del(u);
1515
- ndt_meta_del(m);
1627
+ ndt_decref(t);
1628
+ ndt_decref(u);
1516
1629
  ndt_context_del(ctx);
1517
1630
  return -1;
1518
1631
  }
1519
1632
 
1520
- ndt_del(t);
1521
- ndt_del(u);
1633
+ ndt_decref(t);
1634
+ ndt_decref(u);
1522
1635
 
1523
- ndt_meta_del(m);
1524
1636
  count++;
1525
1637
  }
1526
1638
  fprintf(stderr, "test_serialize (%d test cases)\n", count);
@@ -1534,7 +1646,6 @@ static int
1534
1646
  test_serialize_fuzz(void)
1535
1647
  {
1536
1648
  ndt_context_t *ctx;
1537
- ndt_meta_t *m;
1538
1649
  char *buf;
1539
1650
  ssize_t ret, n;
1540
1651
  int src;
@@ -1572,23 +1683,13 @@ test_serialize_fuzz(void)
1572
1683
  return -1;
1573
1684
  }
1574
1685
 
1575
- m = ndt_meta_new(ctx);
1576
- if (m == NULL) {
1577
- ndt_free(buf);
1578
- close(src);
1579
- ndt_context_del(ctx);
1580
- fprintf(stderr, "\nmalloc error in fuzz tests\n");
1581
- return -1;
1582
- }
1583
-
1584
1686
  ndt_err_clear(ctx);
1585
- ndt_t *t = ndt_deserialize(m, buf, n, ctx);
1687
+ const ndt_t *t = ndt_deserialize(buf, n, ctx);
1586
1688
  if (t != NULL) {
1587
- ndt_del(t);
1689
+ ndt_decref(t);
1588
1690
  }
1589
1691
 
1590
1692
  ndt_free(buf);
1591
- ndt_meta_del(m);
1592
1693
  }
1593
1694
  fprintf(stderr, "test_serialize_fuzz (%" PRIi64 " test cases)\n", i);
1594
1695
 
@@ -1608,6 +1709,7 @@ static int (*tests[])(void) = {
1608
1709
  test_typedef_error,
1609
1710
  test_equal,
1610
1711
  test_match,
1712
+ test_unify,
1611
1713
  test_typecheck,
1612
1714
  test_numba,
1613
1715
  test_static_context,