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
@@ -178,22 +178,23 @@ ndt_type_seq_t *
178
178
  ndt_type_seq_new(ndt_t *elt, ndt_context_t *ctx)
179
179
  {
180
180
  ndt_type_seq_t *seq;
181
- ndt_t **ptr;
181
+ const ndt_t **ptr;
182
182
 
183
183
  seq = ndt_alloc_size(sizeof *seq);
184
184
  if (seq == NULL) {
185
- ndt_del(elt);
185
+ ndt_decref(elt);
186
186
  return ndt_memory_error(ctx);
187
187
  }
188
188
 
189
189
  ptr = ndt_alloc_size(2 * (sizeof *ptr));
190
190
  if (ptr == NULL) {
191
191
  ndt_free(seq);
192
- ndt_del(elt);
192
+ ndt_decref(elt);
193
193
  return ndt_memory_error(ctx);
194
194
  }
195
195
 
196
196
  ptr[0] = elt;
197
+
197
198
  seq->len = 1;
198
199
  seq->reserved = 2;
199
200
  seq->ptr = ptr;
@@ -213,9 +214,9 @@ ndt_type_seq_del(ndt_type_seq_t *seq)
213
214
  static int
214
215
  ndt_type_seq_grow(ndt_type_seq_t *seq, ndt_context_t *ctx)
215
216
  {
216
- ndt_t **ptr;
217
+ const ndt_t **ptr;
217
218
 
218
- ptr = ndt_realloc(seq->ptr, seq->reserved, 2 * (sizeof *ptr));
219
+ ptr = ndt_realloc((void *)seq->ptr, seq->reserved, 2 * (sizeof *ptr));
219
220
  if (ptr == NULL) {
220
221
  ndt_err_format(ctx, NDT_MemoryError, "out of memory");
221
222
  return -1;
@@ -235,7 +236,6 @@ ndt_type_seq_append(ndt_type_seq_t *seq, ndt_t *elt, ndt_context_t *ctx)
235
236
  if (seq->len == seq->reserved) {
236
237
  if (ndt_type_seq_grow(seq, ctx) < 0) {
237
238
  ndt_type_seq_del(seq);
238
- ndt_free(elt);
239
239
  return NULL;
240
240
  }
241
241
  }
@@ -249,7 +249,7 @@ ndt_type_seq_append(ndt_type_seq_t *seq, ndt_t *elt, ndt_context_t *ctx)
249
249
  ndt_type_seq_t *
250
250
  ndt_type_seq_finalize(ndt_type_seq_t *seq)
251
251
  {
252
- ndt_t **ptr;
252
+ const ndt_t **ptr;
253
253
 
254
254
  if (seq == NULL) {
255
255
  return NULL;
@@ -257,7 +257,7 @@ ndt_type_seq_finalize(ndt_type_seq_t *seq)
257
257
 
258
258
  assert(seq->len <= seq->reserved);
259
259
 
260
- ptr = ndt_realloc(seq->ptr, seq->len, sizeof *ptr);
260
+ ptr = ndt_realloc((void *)seq->ptr, seq->len, sizeof *ptr);
261
261
  if (ptr == NULL) {
262
262
  return seq; /* seq is still valid */
263
263
  }
@@ -168,7 +168,7 @@ typedef struct {
168
168
  typedef struct {
169
169
  int64_t len;
170
170
  int64_t reserved;
171
- ndt_t **ptr;
171
+ const ndt_t **ptr;
172
172
  } ndt_type_seq_t;
173
173
 
174
174
 
@@ -0,0 +1,48 @@
1
+
2
+ CC = gcc
3
+ LD = gcc
4
+
5
+ CONFIGURE_CFLAGS = -I.. -Wall -Wextra -std=c11 -pedantic -O2 -g
6
+ NDT_CFLAGS = $(strip $(CONFIGURE_CFLAGS) $(CFLAGS))
7
+ NDT_CFLAGS_SHARED = $(NDT_CFLAGS) -fPIC
8
+
9
+ CONFIGURE_COV_CFLAGS = -I.. -Wall -Wextra -std=c11 -pedantic -O0 -g -fno-inline -fprofile-arcs -ftest-coverage
10
+ ifeq ($(MAKECMDGOALS), coverage)
11
+ NDT_CFLAGS = $(strip $(CONFIGURE_COV_CFLAGS) $(CFLAGS))
12
+ endif
13
+
14
+
15
+ OBJS = serialize.o deserialize.o
16
+ SHARED_OBJS = .objs/serialize.o .objs/deserialize.o
17
+
18
+
19
+ default: $(OBJS) $(SHARED_OBJS)
20
+
21
+
22
+ serialize.o:\
23
+ Makefile serialize.c ../ndtypes.h
24
+ $(CC) $(NDT_CFLAGS) -c serialize.c
25
+
26
+ .objs/serialize.o:\
27
+ Makefile serialize.c ../ndtypes.h
28
+ $(CC) $(NDT_CFLAGS_SHARED) -c serialize.c -o .objs/serialize.o
29
+
30
+ deserialize.o:\
31
+ Makefile deserialize.c ../ndtypes.h
32
+ $(CC) $(NDT_CFLAGS) -c deserialize.c
33
+
34
+ .objs/deserialize.o:\
35
+ Makefile deserialize.c ../ndtypes.h
36
+ $(CC) $(NDT_CFLAGS_SHARED) -c deserialize.c -o .objs/deserialize.o
37
+
38
+
39
+ FORCE:
40
+
41
+ clean: FORCE
42
+ rm -f *.o *.so *.gch *.gcda *.gcno *.gcov *.dyn *.dpi *.lock
43
+ cd .objs && rm -f *.o *.so *.gch *.gcda *.gcno *.gcov *.dyn *.dpi *.lock
44
+
45
+ distclean: clean
46
+ rm -f Makefile
47
+
48
+
@@ -40,8 +40,8 @@
40
40
  #include "overflow.h"
41
41
 
42
42
 
43
- static ndt_t *read_type(ndt_meta_t *m, const char * const ptr, int64_t offset,
44
- const int64_t len, ndt_context_t *ctx);
43
+ static const ndt_t *read_type(const char * const ptr, int64_t offset,
44
+ const int64_t len, ndt_context_t *ctx);
45
45
 
46
46
 
47
47
 
@@ -247,7 +247,7 @@ copy_common(ndt_t *t, const common_t *f)
247
247
  static ndt_t *
248
248
  new_copy_common(const common_t *f, ndt_context_t *ctx)
249
249
  {
250
- ndt_t *t = ndt_new(f->tag, ctx);
250
+ ndt_t *t = ndt_new(f->tag, f->flags, ctx);
251
251
  if (t == NULL) {
252
252
  return NULL;
253
253
  }
@@ -350,12 +350,12 @@ read_common_fields(common_t *fields, const char * const ptr,
350
350
  return read_uint16(&fields->align, ptr, offset, len, ctx);
351
351
  }
352
352
 
353
- static ndt_t *
354
- read_module(ndt_meta_t *m, const common_t *fields, const char * const ptr,
355
- int64_t offset, const int64_t len, ndt_context_t *ctx)
353
+ static const ndt_t *
354
+ read_module(const common_t *fields, const char * const ptr, int64_t offset,
355
+ const int64_t len, ndt_context_t *ctx)
356
356
  {
357
357
  char *name;
358
- ndt_t *type;
358
+ const ndt_t *type;
359
359
  ndt_t *t;
360
360
 
361
361
  offset = read_string(&name, ptr, offset, len, ctx);
@@ -363,7 +363,7 @@ read_module(ndt_meta_t *m, const common_t *fields, const char * const ptr,
363
363
  return NULL;
364
364
  }
365
365
 
366
- type = read_type(m, ptr, offset, len, ctx);
366
+ type = read_type(ptr, offset, len, ctx);
367
367
  if (type == NULL) {
368
368
  ndt_free(name);
369
369
  return NULL;
@@ -371,7 +371,7 @@ read_module(ndt_meta_t *m, const common_t *fields, const char * const ptr,
371
371
 
372
372
  t = new_copy_common(fields, ctx);
373
373
  if (t == NULL) {
374
- ndt_del(type);
374
+ ndt_decref(type);
375
375
  ndt_free(name);
376
376
  return NULL;
377
377
  }
@@ -381,9 +381,9 @@ read_module(ndt_meta_t *m, const common_t *fields, const char * const ptr,
381
381
  return t;
382
382
  }
383
383
 
384
- static ndt_t *
385
- read_function(ndt_meta_t *m, common_t *fields, const char * const ptr,
386
- int64_t offset, const int64_t len, ndt_context_t *ctx)
384
+ static const ndt_t *
385
+ read_function(common_t *fields, const char * const ptr, int64_t offset,
386
+ const int64_t len, ndt_context_t *ctx)
387
387
  {
388
388
  int64_t metaoffset;
389
389
  int64_t nin;
@@ -412,9 +412,9 @@ read_function(ndt_meta_t *m, common_t *fields, const char * const ptr,
412
412
  metaoffset = next_metaoffset(&offset, ptr, metaoffset, len, ctx);
413
413
  if (metaoffset < 0) return NULL;
414
414
 
415
- t->Function.types[i] = read_type(m, ptr, offset, len, ctx);
415
+ t->Function.types[i] = read_type(ptr, offset, len, ctx);
416
416
  if (t->Function.types[i] == NULL) {
417
- ndt_del(t);
417
+ ndt_decref(t);
418
418
  return NULL;
419
419
  }
420
420
  }
@@ -425,15 +425,15 @@ read_function(ndt_meta_t *m, common_t *fields, const char * const ptr,
425
425
  return t;
426
426
  }
427
427
 
428
- static ndt_t *
429
- read_fixed_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
430
- int64_t offset, const int64_t len, ndt_context_t *ctx)
428
+ static const ndt_t *
429
+ read_fixed_dim(const common_t *fields, const char * const ptr, int64_t offset,
430
+ const int64_t len, ndt_context_t *ctx)
431
431
  {
432
432
  ndt_contig tag;
433
433
  int64_t shape;
434
434
  int64_t step;
435
435
  int64_t itemsize;
436
- ndt_t *type;
436
+ const ndt_t *type;
437
437
  ndt_t *t;
438
438
 
439
439
  offset = ndt_contig_from_uint8(&tag, ptr, offset, len, ctx);
@@ -448,14 +448,14 @@ read_fixed_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
448
448
  offset = read_pos_int64(&itemsize, ptr, offset, len, ctx);
449
449
  if (offset < 0) return NULL;
450
450
 
451
- type = read_type(m, ptr, offset, len, ctx);
451
+ type = read_type(ptr, offset, len, ctx);
452
452
  if (type == NULL) {
453
453
  return NULL;
454
454
  }
455
455
 
456
456
  t = new_copy_common(fields, ctx);
457
457
  if (t == NULL) {
458
- ndt_del(type);
458
+ ndt_decref(type);
459
459
  return NULL;
460
460
  }
461
461
  t->FixedDim.tag = tag;
@@ -467,13 +467,13 @@ read_fixed_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
467
467
  return t;
468
468
  }
469
469
 
470
- static ndt_t *
471
- read_symbolic_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
472
- int64_t offset, const int64_t len, ndt_context_t *ctx)
470
+ static const ndt_t *
471
+ read_symbolic_dim(const common_t *fields, const char * const ptr, int64_t offset,
472
+ const int64_t len, ndt_context_t *ctx)
473
473
  {
474
474
  ndt_contig tag;
475
475
  char *name;
476
- ndt_t *type;
476
+ const ndt_t *type;
477
477
  ndt_t *t;
478
478
 
479
479
  offset = ndt_contig_from_uint8(&tag, ptr, offset, len, ctx);
@@ -486,7 +486,7 @@ read_symbolic_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
486
486
  return NULL;
487
487
  }
488
488
 
489
- type = read_type(m, ptr, offset, len, ctx);
489
+ type = read_type(ptr, offset, len, ctx);
490
490
  if (type == NULL) {
491
491
  ndt_free(name);
492
492
  return NULL;
@@ -494,7 +494,7 @@ read_symbolic_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
494
494
 
495
495
  t = new_copy_common(fields, ctx);
496
496
  if (t == NULL) {
497
- ndt_del(type);
497
+ ndt_decref(type);
498
498
  ndt_free(name);
499
499
  return NULL;
500
500
  }
@@ -505,13 +505,13 @@ read_symbolic_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
505
505
  return t;
506
506
  }
507
507
 
508
- static ndt_t *
509
- read_ellipsis_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
510
- int64_t offset, const int64_t len, ndt_context_t *ctx)
508
+ static const ndt_t *
509
+ read_ellipsis_dim(const common_t *fields, const char * const ptr, int64_t offset,
510
+ const int64_t len, ndt_context_t *ctx)
511
511
  {
512
512
  ndt_contig tag;
513
513
  char *name;
514
- ndt_t *type;
514
+ const ndt_t *type;
515
515
  ndt_t *t;
516
516
 
517
517
  offset = ndt_contig_from_uint8(&tag, ptr, offset, len, ctx);
@@ -528,7 +528,7 @@ read_ellipsis_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
528
528
  name = NULL;
529
529
  }
530
530
 
531
- type = read_type(m, ptr, offset, len, ctx);
531
+ type = read_type(ptr, offset, len, ctx);
532
532
  if (type == NULL) {
533
533
  ndt_free(name);
534
534
  return NULL;
@@ -536,7 +536,7 @@ read_ellipsis_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
536
536
 
537
537
  t = new_copy_common(fields, ctx);
538
538
  if (t == NULL) {
539
- ndt_del(type);
539
+ ndt_decref(type);
540
540
  ndt_free(name);
541
541
  return NULL;
542
542
  }
@@ -547,16 +547,16 @@ read_ellipsis_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
547
547
  return t;
548
548
  }
549
549
 
550
- static ndt_t *
551
- read_var_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
552
- int64_t offset, const int64_t len, ndt_context_t *ctx)
550
+ static const ndt_t *
551
+ read_var_dim(const common_t *fields, const char * const ptr, int64_t offset,
552
+ const int64_t len, ndt_context_t *ctx)
553
553
  {
554
554
  int64_t itemsize;
555
555
  int32_t noffsets;
556
- int32_t *offsets;
556
+ ndt_offsets_t *offsets = NULL;
557
557
  int32_t nslices = 0;
558
558
  ndt_slice_t *slices = NULL;
559
- ndt_t *type;
559
+ const ndt_t *type;
560
560
  ndt_t *t;
561
561
 
562
562
  offset = read_pos_int64(&itemsize, ptr, offset, len, ctx);
@@ -568,26 +568,28 @@ read_var_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
568
568
  offset = read_pos_int32(&nslices, ptr, offset, len, ctx);
569
569
  if (offset < 0) return NULL;
570
570
 
571
- offsets = ndt_alloc(noffsets, sizeof *offsets);
572
- if (offsets == NULL) {
573
- return ndt_memory_error(ctx);
574
- }
571
+ if (noffsets > 0) {
572
+ offsets = ndt_offsets_new(noffsets, ctx);
573
+ if (offsets == NULL) {
574
+ return NULL;
575
+ }
575
576
 
576
- offset = read_int32_array(offsets, noffsets, ptr, offset, len, ctx);
577
- if (offset < 0) {
578
- ndt_free(offsets);
579
- return NULL;
577
+ offset = read_int32_array((int32_t *)offsets->v, noffsets, ptr, offset, len, ctx);
578
+ if (offset < 0) {
579
+ ndt_decref_offsets(offsets);
580
+ return NULL;
581
+ }
580
582
  }
581
583
 
582
584
  slices = ndt_alloc(nslices, sizeof *slices);
583
585
  if (slices == NULL) {
584
- ndt_free(offsets);
586
+ ndt_decref_offsets(offsets);
585
587
  return ndt_memory_error(ctx);
586
588
  }
587
589
 
588
590
  offset = read_ndt_slice_array(slices, nslices, ptr, offset, len, ctx);
589
591
  if (offset < 0) {
590
- ndt_free(offsets);
592
+ ndt_decref_offsets(offsets);
591
593
  ndt_free(slices);
592
594
  return NULL;
593
595
  }
@@ -597,38 +599,79 @@ read_var_dim(ndt_meta_t *m, const common_t *fields, const char * const ptr,
597
599
  slices = NULL;
598
600
  }
599
601
 
600
- type = read_type(m, ptr, offset, len, ctx);
602
+ type = read_type(ptr, offset, len, ctx);
601
603
  if (type == NULL) {
602
- ndt_free(offsets);
604
+ ndt_decref_offsets(offsets);
603
605
  ndt_free(slices);
604
606
  return NULL;
605
607
  }
606
608
 
607
609
  t = new_copy_common(fields, ctx);
608
610
  if (t == NULL) {
609
- ndt_free(offsets);
611
+ ndt_decref_offsets(offsets);
610
612
  ndt_free(slices);
611
- ndt_del(type);
613
+ ndt_decref(type);
612
614
  return NULL;
613
615
  }
614
616
  t->VarDim.type = type;
615
- t->Concrete.VarDim.flag = ExternalOffsets;
616
617
  t->Concrete.VarDim.itemsize = itemsize;
617
- t->Concrete.VarDim.noffsets = noffsets;
618
618
  t->Concrete.VarDim.offsets = offsets;
619
619
  t->Concrete.VarDim.nslices = nslices;
620
620
  t->Concrete.VarDim.slices = slices;
621
621
 
622
- m->noffsets[m->ndims] = noffsets;
623
- m->offsets[m->ndims] = offsets;
624
- m->ndims++;
622
+ return t;
623
+ }
624
+
625
+ static const ndt_t *
626
+ read_var_dim_elem(const common_t *fields, const char * const ptr, int64_t offset,
627
+ const int64_t len, ndt_context_t *ctx)
628
+ {
629
+ ndt_t *t;
630
+ int64_t index;
631
+
632
+ offset = read_pos_int64(&index, ptr, offset, len, ctx);
633
+ if (offset < 0) return NULL;
634
+
635
+ t = (ndt_t *)read_var_dim(fields, ptr, offset, len, ctx);
636
+ if (t == NULL) {
637
+ return NULL;
638
+ }
639
+ t->tag = VarDimElem;
640
+ t->VarDimElem.index = index;
641
+
642
+ return t;
643
+ }
644
+
645
+ static const ndt_t *
646
+ read_array(const common_t *fields, const char * const ptr, int64_t offset,
647
+ const int64_t len, ndt_context_t *ctx)
648
+ {
649
+ const ndt_t *type;
650
+ ndt_t *t;
651
+ int64_t itemsize;
652
+
653
+ offset = read_pos_int64(&itemsize, ptr, offset, len, ctx);
654
+ if (offset < 0) return NULL;
655
+
656
+ type = read_type(ptr, offset, len, ctx);
657
+ if (type == NULL) {
658
+ return NULL;
659
+ }
660
+
661
+ t = new_copy_common(fields, ctx);
662
+ if (t == NULL) {
663
+ ndt_decref(type);
664
+ return NULL;
665
+ }
666
+ t->Array.itemsize = itemsize;
667
+ t->Array.type = type;
625
668
 
626
669
  return t;
627
670
  }
628
671
 
629
672
  static ndt_t *
630
- read_tuple(ndt_meta_t *m, const common_t *fields, const char * const ptr,
631
- int64_t offset, const int64_t len, ndt_context_t *ctx)
673
+ read_tuple(const common_t *fields, const char * const ptr, int64_t offset,
674
+ const int64_t len, ndt_context_t *ctx)
632
675
  {
633
676
  int64_t metaoffset;
634
677
  enum ndt_variadic flag;
@@ -641,7 +684,7 @@ read_tuple(ndt_meta_t *m, const common_t *fields, const char * const ptr,
641
684
  offset = read_pos_int64(&shape, ptr, offset, len, ctx);
642
685
  if (offset < 0) return NULL;
643
686
 
644
- t = ndt_tuple_new(flag, shape, ctx);
687
+ t = ndt_tuple_new(flag, shape, 0, ctx);
645
688
  if (t == NULL) {
646
689
  return NULL;
647
690
  }
@@ -661,7 +704,7 @@ read_tuple(ndt_meta_t *m, const common_t *fields, const char * const ptr,
661
704
  metaoffset = next_metaoffset(&offset, ptr, metaoffset, len, ctx);
662
705
  if (metaoffset < 0) goto error;
663
706
 
664
- t->Tuple.types[i] = read_type(m, ptr, offset, len, ctx);
707
+ t->Tuple.types[i] = read_type(ptr, offset, len, ctx);
665
708
  if (t->Tuple.types[i] == NULL) {
666
709
  goto error;
667
710
  }
@@ -670,13 +713,13 @@ read_tuple(ndt_meta_t *m, const common_t *fields, const char * const ptr,
670
713
  return t;
671
714
 
672
715
  error:
673
- ndt_del(t);
716
+ ndt_decref(t);
674
717
  return NULL;
675
718
  }
676
719
 
677
- static ndt_t *
678
- read_record(ndt_meta_t *m, const common_t *fields, const char * const ptr,
679
- int64_t offset, const int64_t len, ndt_context_t *ctx)
720
+ static const ndt_t *
721
+ read_record(const common_t *fields, const char * const ptr, int64_t offset,
722
+ const int64_t len, ndt_context_t *ctx)
680
723
  {
681
724
  int64_t metaoffset;
682
725
  enum ndt_variadic flag;
@@ -689,7 +732,7 @@ read_record(ndt_meta_t *m, const common_t *fields, const char * const ptr,
689
732
  offset = read_pos_int64(&shape, ptr, offset, len, ctx);
690
733
  if (offset < 0) return NULL;
691
734
 
692
- t = ndt_record_new(flag, shape, ctx);
735
+ t = ndt_record_new(flag, shape, 0, ctx);
693
736
  if (t == NULL) {
694
737
  return NULL;
695
738
  }
@@ -712,7 +755,7 @@ read_record(ndt_meta_t *m, const common_t *fields, const char * const ptr,
712
755
  metaoffset = next_metaoffset(&offset, ptr, metaoffset, len, ctx);
713
756
  if (metaoffset < 0) goto error;
714
757
 
715
- t->Record.types[i] = read_type(m, ptr, offset, len, ctx);
758
+ t->Record.types[i] = read_type(ptr, offset, len, ctx);
716
759
  if (t->Record.types[i] == NULL) {
717
760
  goto error;
718
761
  }
@@ -721,25 +764,63 @@ read_record(ndt_meta_t *m, const common_t *fields, const char * const ptr,
721
764
  return t;
722
765
 
723
766
  error:
724
- ndt_del(t);
767
+ ndt_decref(t);
725
768
  return NULL;
726
769
  }
727
770
 
728
- static ndt_t *
729
- read_ref(ndt_meta_t *m, const common_t *fields, const char * const ptr,
730
- int64_t offset, const int64_t len, ndt_context_t *ctx)
771
+ static const ndt_t *
772
+ read_union(const common_t *fields, const char * const ptr, int64_t offset,
773
+ const int64_t len, ndt_context_t *ctx)
774
+ {
775
+ int64_t metaoffset;
776
+ int64_t ntags;
777
+ ndt_t *t;
778
+
779
+ offset = read_pos_int64(&ntags, ptr, offset, len, ctx);
780
+ if (offset < 0) return NULL;
781
+
782
+ t = ndt_union_new(ntags, 0, ctx);
783
+ if (t == NULL) {
784
+ return NULL;
785
+ }
786
+ copy_common(t, fields);
787
+
788
+ offset = read_string_array(t->Union.tags, ntags, ptr, offset, len, ctx);
789
+ if (offset < 0) goto error;
790
+
791
+ metaoffset = offset;
792
+ for (int64_t i = 0; i < ntags; i++) {
793
+ metaoffset = next_metaoffset(&offset, ptr, metaoffset, len, ctx);
794
+ if (metaoffset < 0) goto error;
795
+
796
+ t->Union.types[i] = read_type(ptr, offset, len, ctx);
797
+ if (t->Union.types[i] == NULL) {
798
+ goto error;
799
+ }
800
+ }
801
+
802
+ return t;
803
+
804
+ error:
805
+ ndt_decref(t);
806
+ return NULL;
807
+ }
808
+
809
+ static const ndt_t *
810
+ read_ref(const common_t *fields, const char * const ptr, int64_t offset,
811
+ const int64_t len, ndt_context_t *ctx)
731
812
  {
732
- ndt_t *type;
813
+ const ndt_t *type;
733
814
  ndt_t *t;
734
815
 
735
- type = read_type(m, ptr, offset, len, ctx);
816
+ type = read_type(ptr, offset, len, ctx);
736
817
  if (type == NULL) {
737
818
  return NULL;
738
819
  }
739
820
 
740
821
  t = new_copy_common(fields, ctx);
741
822
  if (t == NULL) {
742
- ndt_del(type);
823
+ ndt_decref(type);
743
824
  return NULL;
744
825
  }
745
826
  t->Ref.type = type;
@@ -747,18 +828,18 @@ read_ref(ndt_meta_t *m, const common_t *fields, const char * const ptr,
747
828
  return t;
748
829
  }
749
830
 
750
- static ndt_t *
751
- read_constr(ndt_meta_t *m, const common_t *fields, const char * const ptr,
752
- int64_t offset, const int64_t len, ndt_context_t *ctx)
831
+ static const ndt_t *
832
+ read_constr(const common_t *fields, const char * const ptr, int64_t offset,
833
+ const int64_t len, ndt_context_t *ctx)
753
834
  {
754
835
  char *name;
755
- ndt_t *type;
836
+ const ndt_t *type;
756
837
  ndt_t *t;
757
838
 
758
839
  offset = read_string(&name, ptr, offset, len, ctx);
759
840
  if (offset < 0) return NULL;
760
841
 
761
- type = read_type(m, ptr, offset, len, ctx);
842
+ type = read_type(ptr, offset, len, ctx);
762
843
  if (type == NULL) {
763
844
  ndt_free(name);
764
845
  return NULL;
@@ -766,7 +847,7 @@ read_constr(ndt_meta_t *m, const common_t *fields, const char * const ptr,
766
847
 
767
848
  t = new_copy_common(fields, ctx);
768
849
  if (t == NULL) {
769
- ndt_del(type);
850
+ ndt_decref(type);
770
851
  ndt_free(name);
771
852
  return NULL;
772
853
  }
@@ -776,19 +857,19 @@ read_constr(ndt_meta_t *m, const common_t *fields, const char * const ptr,
776
857
  return t;
777
858
  }
778
859
 
779
- static ndt_t *
780
- read_nominal(ndt_meta_t *m, const common_t *fields, const char * const ptr,
781
- int64_t offset, const int64_t len, ndt_context_t *ctx)
860
+ static const ndt_t *
861
+ read_nominal(const common_t *fields, const char * const ptr, int64_t offset,
862
+ const int64_t len, ndt_context_t *ctx)
782
863
  {
783
864
  char *name;
784
- ndt_t *type;
865
+ const ndt_t *type;
785
866
  const ndt_typedef_t *d;
786
867
  ndt_t *t;
787
868
 
788
869
  offset = read_string(&name, ptr, offset, len, ctx);
789
870
  if (offset < 0) return NULL;
790
871
 
791
- type = read_type(m, ptr, offset, len, ctx);
872
+ type = read_type(ptr, offset, len, ctx);
792
873
  if (type == NULL) {
793
874
  ndt_free(name);
794
875
  return NULL;
@@ -797,14 +878,14 @@ read_nominal(ndt_meta_t *m, const common_t *fields, const char * const ptr,
797
878
  d = ndt_typedef_find(name, ctx);
798
879
  if (d == NULL) {
799
880
  ndt_free(name);
800
- ndt_del(type);
881
+ ndt_decref(type);
801
882
  return NULL;
802
883
  }
803
884
 
804
885
  t = new_copy_common(fields, ctx);
805
886
  if (t == NULL) {
806
887
  ndt_free(name);
807
- ndt_del(type);
888
+ ndt_decref(type);
808
889
  return NULL;
809
890
  }
810
891
  t->Nominal.name = name;
@@ -814,7 +895,7 @@ read_nominal(ndt_meta_t *m, const common_t *fields, const char * const ptr,
814
895
  return t;
815
896
  }
816
897
 
817
- static ndt_t *
898
+ static const ndt_t *
818
899
  read_categorical(const common_t *fields, const char * const ptr, int64_t offset,
819
900
  const int64_t len, ndt_context_t *ctx)
820
901
  {
@@ -847,7 +928,7 @@ read_categorical(const common_t *fields, const char * const ptr, int64_t offset,
847
928
  return t;
848
929
  }
849
930
 
850
- static ndt_t *
931
+ static const ndt_t *
851
932
  read_fixed_string(const common_t *fields, const char * const ptr, int64_t offset,
852
933
  const int64_t len, ndt_context_t *ctx)
853
934
  {
@@ -871,7 +952,7 @@ read_fixed_string(const common_t *fields, const char * const ptr, int64_t offset
871
952
  return t;
872
953
  }
873
954
 
874
- static ndt_t *
955
+ static const ndt_t *
875
956
  read_fixed_bytes(const common_t *fields, const char * const ptr, int64_t offset,
876
957
  const int64_t len, ndt_context_t *ctx)
877
958
  {
@@ -895,7 +976,7 @@ read_fixed_bytes(const common_t *fields, const char * const ptr, int64_t offset,
895
976
  return t;
896
977
  }
897
978
 
898
- static ndt_t *
979
+ static const ndt_t *
899
980
  read_bytes(const common_t *fields, const char * const ptr, int64_t offset,
900
981
  const int64_t len, ndt_context_t *ctx)
901
982
  {
@@ -914,7 +995,7 @@ read_bytes(const common_t *fields, const char * const ptr, int64_t offset,
914
995
  return t;
915
996
  }
916
997
 
917
- static ndt_t *
998
+ static const ndt_t *
918
999
  read_char(const common_t *fields, const char * const ptr, int64_t offset,
919
1000
  const int64_t len, ndt_context_t *ctx)
920
1001
  {
@@ -933,7 +1014,7 @@ read_char(const common_t *fields, const char * const ptr, int64_t offset,
933
1014
  return t;
934
1015
  }
935
1016
 
936
- static ndt_t *
1017
+ static const ndt_t *
937
1018
  read_typevar(const common_t *fields, const char * const ptr, int64_t offset,
938
1019
  const int64_t len, ndt_context_t *ctx)
939
1020
  {
@@ -953,8 +1034,8 @@ read_typevar(const common_t *fields, const char * const ptr, int64_t offset,
953
1034
  return t;
954
1035
  }
955
1036
 
956
- static ndt_t *
957
- read_type(ndt_meta_t *m, const char * const ptr, int64_t offset, const int64_t len,
1037
+ static const ndt_t *
1038
+ read_type(const char * const ptr, int64_t offset, const int64_t len,
958
1039
  ndt_context_t *ctx)
959
1040
  {
960
1041
  common_t fields;
@@ -963,17 +1044,20 @@ read_type(ndt_meta_t *m, const char * const ptr, int64_t offset, const int64_t l
963
1044
  if (offset < 0) return NULL;
964
1045
 
965
1046
  switch (fields.tag) {
966
- case Module: return read_module(m, &fields, ptr, offset, len, ctx);
967
- case Function: return read_function(m, &fields, ptr, offset, len, ctx);
968
- case FixedDim: return read_fixed_dim(m, &fields, ptr, offset, len, ctx);
969
- case SymbolicDim: return read_symbolic_dim(m, &fields, ptr, offset, len, ctx);
970
- case EllipsisDim: return read_ellipsis_dim(m, &fields, ptr, offset, len, ctx);
971
- case VarDim: return read_var_dim(m, &fields, ptr, offset, len, ctx);
972
- case Tuple: return read_tuple(m, &fields, ptr, offset, len, ctx);
973
- case Record: return read_record(m, &fields, ptr, offset, len, ctx);
974
- case Ref: return read_ref(m, &fields, ptr, offset, len, ctx);
975
- case Constr: return read_constr(m, &fields, ptr, offset, len, ctx);
976
- case Nominal: return read_nominal(m, &fields, ptr, offset, len, ctx);
1047
+ case Module: return read_module(&fields, ptr, offset, len, ctx);
1048
+ case Function: return read_function(&fields, ptr, offset, len, ctx);
1049
+ case FixedDim: return read_fixed_dim(&fields, ptr, offset, len, ctx);
1050
+ case SymbolicDim: return read_symbolic_dim(&fields, ptr, offset, len, ctx);
1051
+ case EllipsisDim: return read_ellipsis_dim(&fields, ptr, offset, len, ctx);
1052
+ case VarDim: return read_var_dim(&fields, ptr, offset, len, ctx);
1053
+ case VarDimElem: return read_var_dim_elem(&fields, ptr, offset, len, ctx);
1054
+ case Array: return read_array(&fields, ptr, offset, len, ctx);
1055
+ case Tuple: return read_tuple(&fields, ptr, offset, len, ctx);
1056
+ case Record: return read_record(&fields, ptr, offset, len, ctx);
1057
+ case Union: return read_union(&fields, ptr, offset, len, ctx);
1058
+ case Ref: return read_ref(&fields, ptr, offset, len, ctx);
1059
+ case Constr: return read_constr(&fields, ptr, offset, len, ctx);
1060
+ case Nominal: return read_nominal(&fields, ptr, offset, len, ctx);
977
1061
  case Categorical: return read_categorical(&fields, ptr, offset, len, ctx);
978
1062
  case FixedString: return read_fixed_string(&fields, ptr, offset, len, ctx);
979
1063
  case FixedBytes: return read_fixed_bytes(&fields, ptr, offset, len, ctx);
@@ -981,16 +1065,17 @@ read_type(ndt_meta_t *m, const char * const ptr, int64_t offset, const int64_t l
981
1065
  case Char: return read_char(&fields, ptr, offset, len, ctx);
982
1066
  case Typevar: return read_typevar(&fields, ptr, offset, len, ctx);
983
1067
 
984
- case Bool:
985
- case Int8: case Int16: case Int32: case Int64:
986
- case Uint8: case Uint16: case Uint32: case Uint64:
987
- case Float16: case Float32: case Float64:
988
- case Complex32: case Complex64: case Complex128:
989
1068
  case String:
1069
+ case Bool:
1070
+ case SignedKind: case Int8: case Int16: case Int32: case Int64:
1071
+ case UnsignedKind: case Uint8: case Uint16: case Uint32: case Uint64:
1072
+ case FloatKind: case BFloat16: case Float16: case Float32: case Float64:
1073
+ case ComplexKind: case BComplex32: case Complex32: case Complex64: case Complex128:
1074
+ return ndt_primitive(fields.tag, fields.flags, ctx);
990
1075
 
991
1076
  case AnyKind:
992
- case ScalarKind: case SignedKind: case UnsignedKind: case FloatKind:
993
- case ComplexKind: case FixedStringKind: case FixedBytesKind:
1077
+ case ScalarKind:
1078
+ case FixedStringKind: case FixedBytesKind:
994
1079
  return new_copy_common(&fields, ctx);
995
1080
  }
996
1081
 
@@ -999,9 +1084,8 @@ read_type(ndt_meta_t *m, const char * const ptr, int64_t offset, const int64_t l
999
1084
  return NULL;
1000
1085
  }
1001
1086
 
1002
- ndt_t *
1003
- ndt_deserialize(ndt_meta_t *m, const char * const ptr, int64_t len,
1004
- ndt_context_t *ctx)
1087
+ const ndt_t *
1088
+ ndt_deserialize(const char * const ptr, int64_t len, ndt_context_t *ctx)
1005
1089
  {
1006
- return read_type(m, ptr, 0, len, ctx);
1090
+ return read_type(ptr, 0, len, ctx);
1007
1091
  }