xnd 0.2.0dev3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +42 -0
  3. data/Gemfile +3 -0
  4. data/History.md +0 -0
  5. data/README.md +7 -0
  6. data/Rakefile +135 -0
  7. data/ext/ruby_xnd/extconf.rb +70 -0
  8. data/ext/ruby_xnd/float_pack_unpack.c +277 -0
  9. data/ext/ruby_xnd/float_pack_unpack.h +39 -0
  10. data/ext/ruby_xnd/gc_guard.c +36 -0
  11. data/ext/ruby_xnd/gc_guard.h +12 -0
  12. data/ext/ruby_xnd/include/xnd.h +449 -0
  13. data/ext/ruby_xnd/lib/libxnd.a +0 -0
  14. data/ext/ruby_xnd/lib/libxnd.so +1 -0
  15. data/ext/ruby_xnd/lib/libxnd.so.0 +1 -0
  16. data/ext/ruby_xnd/lib/libxnd.so.0.2.0dev3 +0 -0
  17. data/ext/ruby_xnd/memory_block_object.c +32 -0
  18. data/ext/ruby_xnd/memory_block_object.h +33 -0
  19. data/ext/ruby_xnd/ruby_xnd.c +1953 -0
  20. data/ext/ruby_xnd/ruby_xnd.h +61 -0
  21. data/ext/ruby_xnd/ruby_xnd_internal.h +85 -0
  22. data/ext/ruby_xnd/util.h +170 -0
  23. data/ext/ruby_xnd/xnd/AUTHORS.txt +5 -0
  24. data/ext/ruby_xnd/xnd/INSTALL.txt +134 -0
  25. data/ext/ruby_xnd/xnd/LICENSE.txt +29 -0
  26. data/ext/ruby_xnd/xnd/MANIFEST.in +3 -0
  27. data/ext/ruby_xnd/xnd/Makefile.in +80 -0
  28. data/ext/ruby_xnd/xnd/README.rst +44 -0
  29. data/ext/ruby_xnd/xnd/config.guess +1530 -0
  30. data/ext/ruby_xnd/xnd/config.h.in +22 -0
  31. data/ext/ruby_xnd/xnd/config.sub +1782 -0
  32. data/ext/ruby_xnd/xnd/configure +4867 -0
  33. data/ext/ruby_xnd/xnd/configure.ac +164 -0
  34. data/ext/ruby_xnd/xnd/doc/Makefile +14 -0
  35. data/ext/ruby_xnd/xnd/doc/_static/copybutton.js +66 -0
  36. data/ext/ruby_xnd/xnd/doc/conf.py +26 -0
  37. data/ext/ruby_xnd/xnd/doc/index.rst +44 -0
  38. data/ext/ruby_xnd/xnd/doc/libxnd/data-structures.rst +186 -0
  39. data/ext/ruby_xnd/xnd/doc/libxnd/functions.rst +148 -0
  40. data/ext/ruby_xnd/xnd/doc/libxnd/index.rst +25 -0
  41. data/ext/ruby_xnd/xnd/doc/releases/index.rst +34 -0
  42. data/ext/ruby_xnd/xnd/doc/xnd/align-pack.rst +96 -0
  43. data/ext/ruby_xnd/xnd/doc/xnd/buffer-protocol.rst +42 -0
  44. data/ext/ruby_xnd/xnd/doc/xnd/index.rst +30 -0
  45. data/ext/ruby_xnd/xnd/doc/xnd/quickstart.rst +62 -0
  46. data/ext/ruby_xnd/xnd/doc/xnd/types.rst +674 -0
  47. data/ext/ruby_xnd/xnd/install-sh +527 -0
  48. data/ext/ruby_xnd/xnd/libxnd/Makefile.in +102 -0
  49. data/ext/ruby_xnd/xnd/libxnd/Makefile.vc +112 -0
  50. data/ext/ruby_xnd/xnd/libxnd/bitmaps.c +345 -0
  51. data/ext/ruby_xnd/xnd/libxnd/contrib.h +313 -0
  52. data/ext/ruby_xnd/xnd/libxnd/copy.c +944 -0
  53. data/ext/ruby_xnd/xnd/libxnd/equal.c +1216 -0
  54. data/ext/ruby_xnd/xnd/libxnd/inline.h +154 -0
  55. data/ext/ruby_xnd/xnd/libxnd/overflow.h +147 -0
  56. data/ext/ruby_xnd/xnd/libxnd/split.c +286 -0
  57. data/ext/ruby_xnd/xnd/libxnd/tests/Makefile.in +39 -0
  58. data/ext/ruby_xnd/xnd/libxnd/tests/Makefile.vc +44 -0
  59. data/ext/ruby_xnd/xnd/libxnd/tests/README.txt +2 -0
  60. data/ext/ruby_xnd/xnd/libxnd/tests/runtest.c +101 -0
  61. data/ext/ruby_xnd/xnd/libxnd/tests/test.h +48 -0
  62. data/ext/ruby_xnd/xnd/libxnd/tests/test_fixed.c +108 -0
  63. data/ext/ruby_xnd/xnd/libxnd/xnd.c +1304 -0
  64. data/ext/ruby_xnd/xnd/libxnd/xnd.h +449 -0
  65. data/ext/ruby_xnd/xnd/python/test_xnd.py +3144 -0
  66. data/ext/ruby_xnd/xnd/python/xnd/__init__.py +290 -0
  67. data/ext/ruby_xnd/xnd/python/xnd/_xnd.c +2822 -0
  68. data/ext/ruby_xnd/xnd/python/xnd/contrib/pretty.py +850 -0
  69. data/ext/ruby_xnd/xnd/python/xnd/docstrings.h +129 -0
  70. data/ext/ruby_xnd/xnd/python/xnd/pyxnd.h +200 -0
  71. data/ext/ruby_xnd/xnd/python/xnd/util.h +182 -0
  72. data/ext/ruby_xnd/xnd/python/xnd_randvalue.py +1121 -0
  73. data/ext/ruby_xnd/xnd/python/xnd_support.py +106 -0
  74. data/ext/ruby_xnd/xnd/setup.py +303 -0
  75. data/ext/ruby_xnd/xnd/vcbuild/INSTALL.txt +42 -0
  76. data/ext/ruby_xnd/xnd/vcbuild/runtest32.bat +16 -0
  77. data/ext/ruby_xnd/xnd/vcbuild/runtest64.bat +14 -0
  78. data/ext/ruby_xnd/xnd/vcbuild/vcbuild32.bat +29 -0
  79. data/ext/ruby_xnd/xnd/vcbuild/vcbuild64.bat +29 -0
  80. data/ext/ruby_xnd/xnd/vcbuild/vcclean.bat +13 -0
  81. data/ext/ruby_xnd/xnd/vcbuild/vcdistclean.bat +14 -0
  82. data/lib/ruby_xnd.so +0 -0
  83. data/lib/xnd.rb +306 -0
  84. data/lib/xnd/monkeys.rb +29 -0
  85. data/lib/xnd/version.rb +6 -0
  86. data/spec/debug_spec.rb +9 -0
  87. data/spec/gc_guard_spec.rb +10 -0
  88. data/spec/leakcheck.rb +9 -0
  89. data/spec/spec_helper.rb +877 -0
  90. data/spec/type_inference_spec.rb +81 -0
  91. data/spec/xnd_spec.rb +2921 -0
  92. data/xnd.gemspec +47 -0
  93. metadata +215 -0
@@ -0,0 +1,164 @@
1
+
2
+ AC_PREREQ([2.67])
3
+ AC_INIT(xnd, 0.2.0dev3, skrah@bytereef.org, xnd, https://github.com/plures/)
4
+ AC_CONFIG_HEADER(config.h)
5
+ AC_CONFIG_FILES([Makefile libxnd/Makefile libxnd/tests/Makefile])
6
+
7
+ # System and machine type (only used for Darwin):
8
+ AC_MSG_CHECKING(system as reported by uname -s)
9
+ ac_sys_system=`uname -s`
10
+ AC_MSG_RESULT($ac_sys_system)
11
+
12
+ LIBSTATIC=libxnd.a
13
+ case $ac_sys_system in
14
+ darwin*|Darwin*)
15
+ LIBRARY_PATH="DYLD_LIBRARY_PATH"
16
+ LIBNAME="libxnd.dylib"
17
+ LIBSONAME="libxnd.0.dylib"
18
+ LIBSHARED="libxnd.0.2.0dev3.dylib"
19
+ CONFIGURE_LDFLAGS="-dynamiclib -install_name @rpath/$LIBSONAME -undefined dynamic_lookup -compatibility_version 0.2 -current_version 0.2.0"
20
+ ;;
21
+ *)
22
+ LIBRARY_PATH="LD_LIBRARY_PATH"
23
+ LIBNAME="libxnd.so"
24
+ LIBSONAME="libxnd.so.0"
25
+ LIBSHARED="libxnd.so.0.2.0dev3"
26
+ CONFIGURE_LDFLAGS="-shared -Wl,-soname,$LIBSONAME"
27
+ ;;
28
+ esac
29
+
30
+ AC_SUBST(LIBSTATIC)
31
+ AC_SUBST(LIBRARY_PATH)
32
+ AC_SUBST(LIBNAME)
33
+ AC_SUBST(LIBSONAME)
34
+ AC_SUBST(LIBSHARED)
35
+
36
+
37
+ # Apparently purely informational for this particular build:
38
+ AC_CANONICAL_HOST
39
+ AC_SUBST(build)
40
+ AC_SUBST(host)
41
+
42
+ # Language and compiler:
43
+ AC_LANG_C
44
+ saved_cflags=$CFLAGS
45
+ AC_PROG_CC
46
+ CFLAGS=$saved_cflags
47
+
48
+ # ar and ranlib:
49
+ AC_CHECK_TOOL(AR, ar, ar)
50
+ AC_PROG_RANLIB
51
+ AC_SUBST(RANLIB)
52
+
53
+
54
+ # Checks for header files:
55
+ AC_HEADER_STDC
56
+
57
+ # Install program:
58
+ AC_PROG_INSTALL
59
+ AC_SUBST(INSTALL)
60
+
61
+ # Add an explicit include directory.
62
+ AC_MSG_CHECKING(for --with-includes)
63
+ AC_ARG_WITH(includes,
64
+ AS_HELP_STRING([--with-includes="/usr/local/include"],
65
+ [absolute path to an include directory]),
66
+ [],
67
+ [with_includes="none"])
68
+
69
+ AC_MSG_RESULT($with_includes)
70
+
71
+ if test "$with_includes" = "none"; then
72
+ CONFIGURE_INCLUDES=../ndtypes/libndtypes
73
+ CONFIGURE_INCLUDES_TEST=../../ndtypes/libndtypes
74
+ else
75
+ CONFIGURE_INCLUDES=$with_includes
76
+ CONFIGURE_INCLUDES_TEST=$with_includes
77
+ fi
78
+
79
+ AC_SUBST(CONFIGURE_INCLUDES)
80
+ AC_SUBST(CONFIGURE_INCLUDES_TEST)
81
+
82
+ # Add an explicit library path.
83
+ AC_MSG_CHECKING(for --with-libs)
84
+ AC_ARG_WITH(libs,
85
+ AS_HELP_STRING([--with-libs="/usr/local/lib"],
86
+ [absolute path to a library directory]),
87
+ [],
88
+ [with_libs="none"])
89
+
90
+ AC_MSG_RESULT($with_libs)
91
+
92
+ if test "$with_libs" = "none"; then
93
+ CONFIGURE_LIBS=../ndtypes/libndtypes
94
+ CONFIGURE_LIBS_TEST=../../ndtypes/libndtypes
95
+ else
96
+ CONFIGURE_LIBS=$with_libs
97
+ CONFIGURE_LIBS_TEST=$with_libs
98
+ fi
99
+
100
+ AC_SUBST(CONFIGURE_LIBS)
101
+ AC_SUBST(CONFIGURE_LIBS_TEST)
102
+
103
+ # Without documentation:
104
+ AC_MSG_CHECKING([for --with-docs])
105
+ AC_ARG_WITH([docs],
106
+ AS_HELP_STRING([--with-docs], [install documentation - enabled by default]),,
107
+ with_docs=yes)
108
+ AC_MSG_RESULT([$with_docs])
109
+ if test "$with_docs" = yes; then
110
+ NDT_INSTALL_DOCS="install_docs"
111
+ else
112
+ NDT_INSTALL_DOCS=""
113
+ fi
114
+
115
+ AC_SUBST(NDT_INSTALL_DOCS)
116
+
117
+ # Compiler dependent settings:
118
+ XND_WARN=
119
+ XND_OPT="-O2"
120
+ case $CC in
121
+ *gcc*)
122
+ XND_WARN="-Wall -Wextra -std=c11 -pedantic"
123
+ XND_OPT="-O2"
124
+ ;;
125
+ *icc*)
126
+ AR=xiar
127
+ XND_WARN="-Wall"
128
+ XND_OPT="-O2"
129
+ ;;
130
+ *clang*)
131
+ XND_WARN="-Wall -Wextra -std=c11 -pedantic"
132
+ XND_OPT="-O2"
133
+ ;;
134
+ esac
135
+
136
+
137
+
138
+ # Substitute variables and generate output:
139
+ if test -z "$LD"; then
140
+ LD="$CC"
141
+ fi
142
+ AC_SUBST(LD)
143
+ AC_SUBST(AR)
144
+ AC_SUBST(XND_WARN)
145
+ AC_SUBST(XND_OPT)
146
+
147
+
148
+ if test -z "$CFLAGS"; then
149
+ CONFIGURE_CFLAGS="$XND_INCLUDE $XND_WARN $XND_CONFIG $XND_OPT"
150
+ else
151
+ CONFIGURE_CFLAGS="$XND_INCLUDE $XND_WARN $XND_CONFIG $XND_OPT $CFLAGS"
152
+ fi
153
+
154
+ if test -z "$LDFLAGS"; then
155
+ CONFIGURE_LDFLAGS="$XND_LINK $CONFIGURE_LDFLAGS"
156
+ else
157
+ CONFIGURE_LDFLAGS="$XND_LINK $CONFIGURE_LDFLAGS $LDFLAGS"
158
+ fi
159
+
160
+ AC_SUBST(CONFIGURE_CFLAGS)
161
+ AC_SUBST(CONFIGURE_LDFLAGS)
162
+
163
+ AC_OUTPUT
164
+
@@ -0,0 +1,14 @@
1
+ # Makefile for Sphinx documentation.
2
+ SPHINXBUILD = sphinx-build
3
+ BUILDDIR = build
4
+
5
+ default: html
6
+
7
+ html:
8
+ sphinx-build -b html -d build/doctrees . build/html
9
+
10
+ doctest:
11
+ sphinx-build -b doctest -d build/doctrees . build/html
12
+
13
+ clean:
14
+ rm -rf $(BUILDDIR)/*
@@ -0,0 +1,66 @@
1
+ // Copyright 2014 PSF. Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
2
+ // File originates from the cpython source found in Doc/tools/sphinxext/static/copybutton.js
3
+
4
+ $(document).ready(function() {
5
+ /* Add a [>>>] button on the top-right corner of code samples to hide
6
+ * the >>> and ... prompts and the output and thus make the code
7
+ * copyable. */
8
+ var div = $('.highlight-py .highlight,' +
9
+ '.highlight-default .highlight,' +
10
+ '.highlight-py3 .highlight')
11
+ var pre = div.find('pre');
12
+
13
+ // get the styles from the current theme
14
+ pre.parent().parent().css('position', 'relative');
15
+ var hide_text = 'Hide the prompts and output';
16
+ var show_text = 'Show the prompts and output';
17
+ var border_width = pre.css('border-top-width');
18
+ var border_style = pre.css('border-top-style');
19
+ var border_color = pre.css('border-top-color');
20
+ var button_styles = {
21
+ 'cursor':'pointer', 'position': 'absolute', 'top': '0', 'right': '0',
22
+ 'border-color': border_color, 'border-style': border_style,
23
+ 'border-width': border_width, 'color': border_color, 'text-size': '75%',
24
+ 'font-family': 'monospace', 'padding-left': '0.2em', 'padding-right': '0.2em',
25
+ 'border-radius': '0 3px 0 0'
26
+ }
27
+
28
+ // create and add the button to all the code blocks that contain >>>
29
+ div.each(function(index) {
30
+ var jthis = $(this);
31
+ if (jthis.find('.gp').length > 0) {
32
+ var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
33
+ button.css(button_styles)
34
+ button.attr('title', hide_text);
35
+ button.data('hidden', 'false');
36
+ jthis.prepend(button);
37
+ }
38
+ // tracebacks (.gt) contain bare text elements that need to be
39
+ // wrapped in a span to work with .nextUntil() (see later)
40
+ jthis.find('pre:has(.gt)').contents().filter(function() {
41
+ return ((this.nodeType == 3) && (this.data.trim().length > 0));
42
+ }).wrap('<span>');
43
+ });
44
+
45
+ // define the behavior of the button when it's clicked
46
+ $('.copybutton').click(function(e){
47
+ e.preventDefault();
48
+ var button = $(this);
49
+ if (button.data('hidden') === 'false') {
50
+ // hide the code output
51
+ button.parent().find('.go, .gp, .gt').hide();
52
+ button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
53
+ button.css('text-decoration', 'line-through');
54
+ button.attr('title', show_text);
55
+ button.data('hidden', 'true');
56
+ } else {
57
+ // show the code output
58
+ button.parent().find('.go, .gp, .gt').show();
59
+ button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
60
+ button.css('text-decoration', 'none');
61
+ button.attr('title', hide_text);
62
+ button.data('hidden', 'false');
63
+ }
64
+ });
65
+ });
66
+
@@ -0,0 +1,26 @@
1
+ import sys, os, docutils
2
+
3
+
4
+ extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.doctest']
5
+
6
+ source_suffix = '.rst'
7
+ master_doc = 'index'
8
+ project = 'xnd'
9
+ copyright = '2017-2018, Plures Project'
10
+ version = 'v0.2.0dev3'
11
+ release = 'v0.2.0dev3'
12
+ exclude_patterns = ['doc', 'build']
13
+ pygments_style = 'sphinx'
14
+ html_static_path = ['_static']
15
+
16
+ primary_domain = 'py'
17
+ add_function_parentheses = False
18
+
19
+
20
+ def setup(app):
21
+ app.add_crossref_type('topic', 'topic', 'single: %s',
22
+ docutils.nodes.strong)
23
+ app.add_javascript("copybutton.js")
24
+
25
+
26
+
@@ -0,0 +1,44 @@
1
+ .. meta::
2
+ :robots: index, follow
3
+ :description: xnd documentation
4
+ :keywords: libxnd, xnd, C, Python, array computing
5
+
6
+ .. sectionauthor:: Stefan Krah <skrah at bytereef.org>
7
+
8
+
9
+ xnd
10
+ ===
11
+
12
+ xnd is a package for typed memory blocks.
13
+
14
+
15
+ Libxnd
16
+ ------
17
+
18
+ C library.
19
+
20
+ .. toctree::
21
+ :maxdepth: 1
22
+
23
+ libxnd/index.rst
24
+
25
+
26
+ Xnd
27
+ ---
28
+
29
+ Python module.
30
+
31
+
32
+ .. toctree::
33
+ :maxdepth: 1
34
+
35
+ xnd/index.rst
36
+
37
+
38
+ Releases
39
+ --------
40
+
41
+ .. toctree::
42
+ :maxdepth: 1
43
+
44
+ releases/index.rst
@@ -0,0 +1,186 @@
1
+ .. meta::
2
+ :robots: index,follow
3
+ :description: libxnd documentation
4
+
5
+ .. sectionauthor:: Stefan Krah <skrah at bytereef.org>
6
+
7
+
8
+ Data structures
9
+ ===============
10
+
11
+ libxnd is a lightweight container library that leaves most of the work to
12
+ libndtypes. The underlying idea is to have a small struct that contains
13
+ bitmaps, a linear index, a type and a data pointer.
14
+
15
+ The type contains all low level access information.
16
+
17
+ Since the struct is small, it can easily be passed around by value when
18
+ it serves as a view on the data.
19
+
20
+ The owner of the data is a master buffer with some additional bookkeeping
21
+ fields.
22
+
23
+
24
+ Bitmaps
25
+ -------
26
+
27
+ .. topic:: bitmaps
28
+
29
+ .. code-block:: c
30
+
31
+ typedef struct xnd_bitmap xnd_bitmap_t;
32
+
33
+ struct xnd_bitmap {
34
+ uint8_t *data; /* bitmap */
35
+ int64_t size; /* number of subtree bitmaps in the "next" array */
36
+ xnd_bitmap_t *next; /* array of bitmaps for subtrees */
37
+ };
38
+
39
+ libxnd supports data with optional values. Any type can have a bitmap for its
40
+ data. Bitmaps are addressed using the linear index in the :c:macro:`xnd_t`
41
+ struct.
42
+
43
+ For a scalar, the bitmap contains just one addressable bit.
44
+
45
+ For fixed and variable arrays, the bitmap contains one bit for each item.
46
+
47
+ Container types like tuples and records have new bitmaps for each of their
48
+ fields if any of the field subtrees contains optional data.
49
+
50
+ These field bitmaps are in the *next* array.
51
+
52
+
53
+ View
54
+ ----
55
+
56
+ .. topic:: xnd_view
57
+
58
+ .. code-block:: c
59
+
60
+
61
+ /* Typed memory block, usually a view. */
62
+ typedef struct xnd {
63
+ xnd_bitmap_t bitmap; /* bitmap tree */
64
+ int64_t index; /* linear index for var dims */
65
+ const ndt_t *type; /* type of the data */
66
+ char *ptr; /* data */
67
+ } xnd_t;
68
+
69
+ This is the xnd view, with a typed data pointer, the current linear index
70
+ and a bitmap.
71
+
72
+ When passing the view around, the linear index needs to be maintained because
73
+ it is required to determine if a value is missing (NA).
74
+
75
+ The convention is to apply the linear index (adjust the *ptr* and set it
76
+ to *0*) only when a non-optional element at *ndim == 0* is actually
77
+ accessed.
78
+
79
+ This happens for example when getting the value of an element or when
80
+ descending into a record.
81
+
82
+
83
+ Flags
84
+ -----
85
+
86
+ .. topic:: flags
87
+
88
+ .. code-block:: c
89
+
90
+ #define XND_OWN_TYPE 0x00000001U /* type pointer */
91
+ #define XND_OWN_DATA 0x00000002U /* data pointer */
92
+ #define XND_OWN_STRINGS 0x00000004U /* embedded string pointers */
93
+ #define XND_OWN_BYTES 0x00000008U /* embedded bytes pointers */
94
+ #define XND_OWN_POINTERS 0x00000010U /* embedded pointers */
95
+
96
+ #define XND_OWN_ALL (XND_OWN_TYPE | \
97
+ XND_OWN_DATA | \
98
+ XND_OWN_STRINGS | \
99
+ XND_OWN_BYTES | \
100
+ XND_OWN_POINTERS)
101
+
102
+ #define XND_OWN_EMBEDDED (XND_OWN_DATA | \
103
+ XND_OWN_STRINGS | \
104
+ XND_OWN_BYTES | \
105
+ XND_OWN_POINTERS)
106
+
107
+
108
+ The ownership flags for the xnd master buffer (see below). Like libndtypes,
109
+ libxnd itself has no notion of how many exported views a master buffer has.
110
+
111
+ This is deliberately done in order to prevent two different memory management
112
+ schemes from getting in each other's way.
113
+
114
+ However, for deallocating a master buffer the flags must be set correctly.
115
+
116
+ :c:macro:`XND_OWN_TYPE` is set if the master buffer owns the :c:macro:`ndt_t`.
117
+
118
+ :c:macro:`XND_OWN_DATA` is set if the master buffer owns the data pointer.
119
+
120
+
121
+ The *string*, *bytes* and *ref* types have pointers that are embedded in the
122
+ data. Usually, these are owned and deallocated by libxnd.
123
+
124
+ For strings, the Python bindings use the convention that :c:macro:`NULL` strings
125
+ are interpreted as the empty string. Once a string pointer is initialized it
126
+ belongs to the master buffer.
127
+
128
+
129
+ Macros
130
+ ------
131
+
132
+ .. topic:: macros
133
+
134
+ .. code-block:: c
135
+
136
+ /* Convenience macros to extract embedded values. */
137
+ #define XND_POINTER_DATA(ptr) (*((char **)ptr))
138
+ #define XND_BYTES_SIZE(ptr) (((ndt_bytes_t *)ptr)->size)
139
+ #define XND_BYTES_DATA(ptr) (((ndt_bytes_t *)ptr)->data)
140
+
141
+ These macros should be used to extract embedded *ref*, *string* and *bytes*
142
+ data.
143
+
144
+
145
+
146
+ Master buffer
147
+ -------------
148
+
149
+ .. topic:: xnd_master
150
+
151
+ .. code-block:: c
152
+
153
+ /* Master memory block. */
154
+ typedef struct xnd_master {
155
+ uint32_t flags; /* ownership flags */
156
+ xnd_t master; /* typed memory */
157
+ } xnd_master_t;
158
+
159
+ This is the master buffer. *flags* are explained above, the *master* buffer
160
+ should be considered constant.
161
+
162
+ For traversing memory, copy a new view buffer by value.
163
+
164
+
165
+ Slice and index keys
166
+ --------------------
167
+
168
+ .. topic:: xnd_key
169
+
170
+ .. code-block:: c
171
+
172
+ enum xnd_key { Index, FieldName, Slice };
173
+ typedef struct {
174
+ enum xnd_key tag;
175
+ union {
176
+ int64_t Index;
177
+ const char *FieldName;
178
+ ndt_slice_t Slice;
179
+ };
180
+ } xnd_index_t;
181
+
182
+ Slicing and indexing uses the same model as Python. Indices are usually
183
+ integers, but record fields may also be indexed with field names.
184
+
185
+ *ndt_slice_t* has *start*, *stop*, *step* fields that must be filled in with
186
+ normalized values following the same protocol as :c:func:`PySlice_Unpack`.