ndtypes 0.2.0dev4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +50 -0
  3. data/Gemfile +2 -0
  4. data/History.md +0 -0
  5. data/README.md +19 -0
  6. data/Rakefile +125 -0
  7. data/ext/ruby_ndtypes/extconf.rb +55 -0
  8. data/ext/ruby_ndtypes/gc_guard.c +36 -0
  9. data/ext/ruby_ndtypes/gc_guard.h +12 -0
  10. data/ext/ruby_ndtypes/ndtypes/AUTHORS.txt +5 -0
  11. data/ext/ruby_ndtypes/ndtypes/INSTALL.txt +101 -0
  12. data/ext/ruby_ndtypes/ndtypes/LICENSE.txt +29 -0
  13. data/ext/ruby_ndtypes/ndtypes/MANIFEST.in +3 -0
  14. data/ext/ruby_ndtypes/ndtypes/Makefile.in +87 -0
  15. data/ext/ruby_ndtypes/ndtypes/README.rst +47 -0
  16. data/ext/ruby_ndtypes/ndtypes/config.guess +1530 -0
  17. data/ext/ruby_ndtypes/ndtypes/config.h.in +67 -0
  18. data/ext/ruby_ndtypes/ndtypes/config.sub +1782 -0
  19. data/ext/ruby_ndtypes/ndtypes/configure +5260 -0
  20. data/ext/ruby_ndtypes/ndtypes/configure.ac +161 -0
  21. data/ext/ruby_ndtypes/ndtypes/doc/Makefile +14 -0
  22. data/ext/ruby_ndtypes/ndtypes/doc/_static/copybutton.js +66 -0
  23. data/ext/ruby_ndtypes/ndtypes/doc/conf.py +26 -0
  24. data/ext/ruby_ndtypes/ndtypes/doc/grammar/grammar.rst +27 -0
  25. data/ext/ruby_ndtypes/ndtypes/doc/index.rst +56 -0
  26. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/context.rst +131 -0
  27. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/encodings.rst +68 -0
  28. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/fields-values.rst +175 -0
  29. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/functions.rst +72 -0
  30. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/index.rst +43 -0
  31. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/init.rst +48 -0
  32. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/io.rst +100 -0
  33. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/memory.rst +124 -0
  34. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/predicates.rst +110 -0
  35. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/typedef.rst +31 -0
  36. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/types.rst +594 -0
  37. data/ext/ruby_ndtypes/ndtypes/doc/libndtypes/util.rst +166 -0
  38. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/buffer-protocol.rst +27 -0
  39. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/index.rst +21 -0
  40. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/pattern-matching.rst +330 -0
  41. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/quickstart.rst +144 -0
  42. data/ext/ruby_ndtypes/ndtypes/doc/ndtypes/types.rst +544 -0
  43. data/ext/ruby_ndtypes/ndtypes/doc/releases/index.rst +35 -0
  44. data/ext/ruby_ndtypes/ndtypes/install-sh +527 -0
  45. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.in +271 -0
  46. data/ext/ruby_ndtypes/ndtypes/libndtypes/Makefile.vc +269 -0
  47. data/ext/ruby_ndtypes/ndtypes/libndtypes/alloc.c +230 -0
  48. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.c +268 -0
  49. data/ext/ruby_ndtypes/ndtypes/libndtypes/attr.h +109 -0
  50. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.in +73 -0
  51. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/Makefile.vc +70 -0
  52. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/README.txt +16 -0
  53. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.c +2179 -0
  54. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.h +134 -0
  55. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bpgrammar.y +428 -0
  56. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.c +2543 -0
  57. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.h +735 -0
  58. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/bplexer.l +176 -0
  59. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/export.c +543 -0
  60. data/ext/ruby_ndtypes/ndtypes/libndtypes/compat/import.c +110 -0
  61. data/ext/ruby_ndtypes/ndtypes/libndtypes/context.c +228 -0
  62. data/ext/ruby_ndtypes/ndtypes/libndtypes/copy.c +634 -0
  63. data/ext/ruby_ndtypes/ndtypes/libndtypes/encodings.c +116 -0
  64. data/ext/ruby_ndtypes/ndtypes/libndtypes/equal.c +288 -0
  65. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.c +3067 -0
  66. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.h +180 -0
  67. data/ext/ruby_ndtypes/ndtypes/libndtypes/grammar.y +417 -0
  68. data/ext/ruby_ndtypes/ndtypes/libndtypes/io.c +1658 -0
  69. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.c +2773 -0
  70. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.h +734 -0
  71. data/ext/ruby_ndtypes/ndtypes/libndtypes/lexer.l +222 -0
  72. data/ext/ruby_ndtypes/ndtypes/libndtypes/match.c +1132 -0
  73. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.c +2323 -0
  74. data/ext/ruby_ndtypes/ndtypes/libndtypes/ndtypes.h.in +893 -0
  75. data/ext/ruby_ndtypes/ndtypes/libndtypes/overflow.h +161 -0
  76. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.c +473 -0
  77. data/ext/ruby_ndtypes/ndtypes/libndtypes/parsefuncs.h +92 -0
  78. data/ext/ruby_ndtypes/ndtypes/libndtypes/parser.c +246 -0
  79. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.c +269 -0
  80. data/ext/ruby_ndtypes/ndtypes/libndtypes/seq.h +197 -0
  81. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.in +48 -0
  82. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/Makefile.vc +46 -0
  83. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/deserialize.c +1007 -0
  84. data/ext/ruby_ndtypes/ndtypes/libndtypes/serialize/serialize.c +442 -0
  85. data/ext/ruby_ndtypes/ndtypes/libndtypes/slice.h +42 -0
  86. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.c +238 -0
  87. data/ext/ruby_ndtypes/ndtypes/libndtypes/substitute.h +50 -0
  88. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.c +371 -0
  89. data/ext/ruby_ndtypes/ndtypes/libndtypes/symtable.h +100 -0
  90. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.in +55 -0
  91. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/Makefile.vc +45 -0
  92. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.c +82 -0
  93. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/alloc_fail.h +49 -0
  94. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/runtest.c +1657 -0
  95. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test.h +85 -0
  96. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_array.c +115 -0
  97. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_buffer.c +137 -0
  98. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_indent.c +201 -0
  99. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_match.c +2397 -0
  100. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_numba.c +57 -0
  101. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse.c +349 -0
  102. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_error.c +27839 -0
  103. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_parse_roundtrip.c +350 -0
  104. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_record.c +231 -0
  105. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typecheck.c +375 -0
  106. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/test_typedef.c +65 -0
  107. data/ext/ruby_ndtypes/ndtypes/libndtypes/tests/valgrind.supp +30 -0
  108. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/bench.c +79 -0
  109. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/indent.c +94 -0
  110. data/ext/ruby_ndtypes/ndtypes/libndtypes/tools/print_ast.c +96 -0
  111. data/ext/ruby_ndtypes/ndtypes/libndtypes/util.c +474 -0
  112. data/ext/ruby_ndtypes/ndtypes/libndtypes/values.c +228 -0
  113. data/ext/ruby_ndtypes/ndtypes/python/bench.py +49 -0
  114. data/ext/ruby_ndtypes/ndtypes/python/ndt_randtype.py +409 -0
  115. data/ext/ruby_ndtypes/ndtypes/python/ndt_support.py +14 -0
  116. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/__init__.py +70 -0
  117. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/_ndtypes.c +1332 -0
  118. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/docstrings.h +319 -0
  119. data/ext/ruby_ndtypes/ndtypes/python/ndtypes/pyndtypes.h +154 -0
  120. data/ext/ruby_ndtypes/ndtypes/python/test_ndtypes.py +1977 -0
  121. data/ext/ruby_ndtypes/ndtypes/setup.py +288 -0
  122. data/ext/ruby_ndtypes/ndtypes/vcbuild/INSTALL.txt +41 -0
  123. data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest32.bat +15 -0
  124. data/ext/ruby_ndtypes/ndtypes/vcbuild/runtest64.bat +13 -0
  125. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild32.bat +38 -0
  126. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcbuild64.bat +38 -0
  127. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcclean.bat +13 -0
  128. data/ext/ruby_ndtypes/ndtypes/vcbuild/vcdistclean.bat +14 -0
  129. data/ext/ruby_ndtypes/ruby_ndtypes.c +1003 -0
  130. data/ext/ruby_ndtypes/ruby_ndtypes.h +37 -0
  131. data/ext/ruby_ndtypes/ruby_ndtypes_internal.h +28 -0
  132. data/lib/ndtypes.rb +45 -0
  133. data/lib/ndtypes/errors.rb +2 -0
  134. data/lib/ndtypes/version.rb +6 -0
  135. data/ndtypes.gemspec +47 -0
  136. data/spec/gc_table_spec.rb +10 -0
  137. data/spec/ndtypes_spec.rb +289 -0
  138. data/spec/spec_helper.rb +241 -0
  139. metadata +242 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e4f279735d63cdb4899d3df98a78dcde783ea64
4
+ data.tar.gz: 48e2f95ae6030f6c333ffbf88d8b253f6950830b
5
+ SHA512:
6
+ metadata.gz: 9f23ebcc82f55ddd54e2417a106e4ab0bf9804ee5c8e951e65f6366b4530bc60a6d0e1992ed5aad32d734ff709f62473e6ce6b9fe2a4ac8f4f8b6c7417fcf008
7
+ data.tar.gz: 5006d479c176243f23e9956a25890b0caf3df0b1cee7a1546fccc7f1e8b64dd6bfad3b8dddfa796146e9a296cbb32904fe850e84465a77ec9968bd748fec8402
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,50 @@
1
+ # Developer notes
2
+
3
+ ## Interfacing with Ruby's GC
4
+
5
+ ### Background
6
+
7
+ Ruby uses a mark-and-sweep GC that scans the entire Ruby interpreter stack for
8
+ objects that have gone out of scope and can be freed from memory. It does not
9
+ offer any of the reference counting mechanism that the Python GC offers.
10
+
11
+ While both approaches have their pros and cons, in the context of the ndtypes
12
+ wrapper, it becomes risky to have 'internal' Ruby objects that are only visible
13
+ to the C API and are shared between multiple user-facing Ruby objecs. If one of
14
+ the user-facing objects goes out of scope there is a possibilty that the GC will
15
+ clean up the internal object that is shared between multiple user-facing objects
16
+ (some of which might still be in use) and that will lead to segfaults.
17
+
18
+ To avoid such a situation, in ndtypes we use a 'global GC guard' (inspired by @mrkn's
19
+ [pycall.rb](https://github.com/mrkn/pycall.rb) gem) that stores the reference to the internal objects in a global Hash
20
+ so that they don't go out of scope. When a user-facing object needs to be freed, we remove
21
+ the reference to the user-facing object and its corresponding internal object from the
22
+ global Hash.
23
+
24
+ ### Details
25
+
26
+ More concretely, the `NdtObject` struct houses a `VALUE` object called `rbuf`. The struct
27
+ has the following definition:
28
+ ```
29
+ typedef struct {
30
+ VALUE rbuf; /* resource buffer */
31
+ ndt_t *ndt; /* type */
32
+ } NdtObject;
33
+ ```
34
+ In the above, the `rbuf` is a Ruby object that contains a struct of type `ResourceBufferObject`.
35
+ This is the internal object that need to be shared among multiple user-facing `NDTypes` objects.
36
+
37
+ The `gc_guard.c` file contains functions that help us interface with a global hash called
38
+ `__gc_guard_table` that is present under the `NDTypes::GCGuard` module as a instance variable
39
+ on the module object.
40
+
41
+ ### Impact on contributor
42
+
43
+ Whenever you allocate an `NDTypes` object you call the `gc_guard_register` function and pass
44
+ it the pointer of the `NdtObject` struct that you have allocated along with the `rbuf` object.
45
+
46
+ When an `NDTypes` objects needs to be freed (for example by the GC using the `NDTypes_dfree`
47
+ function), you must call the `gc_guard_unregister` function that will remove the reference
48
+ to the `rbuf` object from the global Hash.
49
+
50
+ Forgetting to call above procedures can lead to hard-to-trace GC errors.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/History.md ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # ndtypes
2
+
3
+ Ruby wrapper over the libndtypes library.
4
+
5
+ # Installation
6
+
7
+ Run `gem install ndtypes --pre` to install on your machine.
8
+
9
+ # Usage
10
+
11
+
12
+
13
+ # Tests
14
+
15
+ Run `rspec`.
16
+
17
+ # Contributing
18
+
19
+ Read the `CONTRIBUTING.md` file to know how to contribute to NDTypes.
data/Rakefile ADDED
@@ -0,0 +1,125 @@
1
+ require 'rake'
2
+ require 'rake/extensiontask'
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
5
+ require 'fileutils'
6
+ require "ndtypes/version.rb"
7
+
8
+ gemspec = eval(IO.read("ndtypes.gemspec"))
9
+
10
+ ext_name = "ruby_ndtypes"
11
+ Rake::ExtensionTask.new(ext_name, gemspec) do |ext|
12
+ ext.ext_dir = "ext/#{ext_name}"
13
+ ext.source_pattern = "**/*.{c, h}"
14
+ end
15
+
16
+ def run *cmd
17
+ sh(cmd.join(" "))
18
+ end
19
+
20
+ BASEDIR = Pathname( __FILE__ ).dirname.relative_path_from( Pathname.pwd )
21
+ SPECDIR = BASEDIR + 'spec'
22
+
23
+ VALGRIND_OPTIONS = [
24
+ "--tool=memcheck",
25
+ #"--leak-check=yes",
26
+ "--num-callers=15",
27
+ #"--error-limit=no",
28
+ "--partial-loads-ok=yes",
29
+ "--undef-value-errors=no" #,
30
+ #"--dsymutil=yes"
31
+ ]
32
+
33
+ CALLGRIND_OPTIONS = [
34
+ "--tool=callgrind",
35
+ "--dump-instr=yes",
36
+ "--simulate-cache=yes",
37
+ "--collect-jumps=yes"
38
+ ]
39
+
40
+ VALGRIND_MEMORYFILL_OPTIONS = [
41
+ "--freelist-vol=100000000",
42
+ "--malloc-fill=6D",
43
+ "--free-fill=66 ",
44
+ ]
45
+
46
+ GDB_OPTIONS = []
47
+
48
+ namespace :spec do
49
+ # partial-loads-ok and undef-value-errors necessary to ignore
50
+ # spurious (and eminently ignorable) warnings from the ruby
51
+ # interpreter
52
+
53
+ RSPEC_CMD = [ 'ruby', '-S', 'rspec', '-Ilib:ext', SPECDIR.to_s ]
54
+
55
+ desc "Run specs under GDB."
56
+ task :gdb => [ :compile ] do |task|
57
+ cmd = [ 'gdb' ] + GDB_OPTIONS
58
+ cmd += [ '--args' ]
59
+ cmd += RSPEC_CMD
60
+ run( *cmd )
61
+ end
62
+
63
+ desc "Run specs under cgdb."
64
+ task :cgdb => [ :compile ] do |task|
65
+ cmd = [ 'cgdb' ] + GDB_OPTIONS
66
+ cmd += [ '--args' ]
67
+ cmd += RSPEC_CMD
68
+ run( *cmd )
69
+ end
70
+
71
+ desc "Run specs under Valgrind."
72
+ task :valgrind => [ :compile ] do |task|
73
+ cmd = [ 'valgrind' ] + VALGRIND_OPTIONS
74
+ cmd += RSPEC_CMD
75
+ run( *cmd )
76
+ end
77
+
78
+ desc "Run specs under Callgrind."
79
+ task :callgrind => [ :compile ] do |task|
80
+ cmd = [ 'valgrind' ] + CALLGRIND_OPTIONS
81
+ cmd += RSPEC_CMD
82
+ run( *cmd )
83
+ end
84
+ end
85
+
86
+ LEAKCHECK_CMD = [ 'ruby', '-Ilib:ext', "#{SPECDIR}/leakcheck.rb" ]
87
+
88
+ desc "Run leakcheck script."
89
+ task :leakcheck => [ :compile ] do |task|
90
+ cmd = [ 'valgrind' ] + VALGRIND_OPTIONS
91
+ cmd += LEAKCHECK_CMD
92
+ run( *cmd )
93
+ end
94
+
95
+ task :clobber do |task|
96
+ [
97
+ "ext/#{ext_name}/include",
98
+ "ext/#{ext_name}/share",
99
+ "ext/#{ext_name}/lib",
100
+ ].each do |f|
101
+ puts "deleting folder #{f}..."
102
+ FileUtils.rm_rf(f)
103
+ end
104
+
105
+ Dir.chdir("ext/#{ext_name}/ndtypes/libndtypes/") do
106
+ system("make clean")
107
+ end
108
+ end
109
+
110
+ task :deploy do |task|
111
+ ext_ndtypes = "ext/ruby_ndtypes/ndtypes"
112
+ puts "deleting previously created #{ext_ndtypes} directory..."
113
+ FileUtils.rm_rf(ext_ndtypes)
114
+ Dir.mkdir(ext_ndtypes)
115
+
116
+ puts "cloning ndtypes repo into ext/ folder..."
117
+ system("git clone https://github.com/plures/ndtypes #{ext_ndtypes}")
118
+
119
+ Dir.chdir(ext_ndtypes) do
120
+ system("git checkout #{NDTypes::COMMIT}")
121
+ end
122
+
123
+ puts "building gem with rake build..."
124
+ system("rake build")
125
+ end
@@ -0,0 +1,55 @@
1
+ require 'mkmf'
2
+
3
+ def windows?
4
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
5
+ end
6
+
7
+ def mac?
8
+ (/darwin/ =~ RUBY_PLATFORM) != nil
9
+ end
10
+
11
+ def unix?
12
+ !windows?
13
+ end
14
+
15
+ puts "compiling libndtypes on your machine..."
16
+ Dir.chdir(File.join(File.dirname(__FILE__) + "/ndtypes")) do
17
+ if unix?
18
+ ["libndtypes", "libndtypes/compat", "libndtypes/serialize"].each do |f|
19
+ Dir.chdir(f) do
20
+ Dir.mkdir(".objs") unless Dir.exists? ".objs"
21
+ end
22
+ end
23
+
24
+ system("./configure --prefix=#{File.expand_path("../")} --with-docs=no")
25
+ system("make")
26
+ system("make install")
27
+ elsif windows?
28
+ raise NotImplementedError, "need to specify build instructions for windows."
29
+ end
30
+ end
31
+
32
+ $INSTALLFILES = [
33
+ ["ruby_ndtypes.h", "$(archdir)"]
34
+ ]
35
+ binaries = File.expand_path(File.join(File.dirname(__FILE__) + "/lib/"))
36
+ headers = File.expand_path(File.join(File.dirname(__FILE__) + "/include/"))
37
+ $LOAD_PATH << File.expand_path(binaries)
38
+
39
+ ["ndtypes"].each do |lib|
40
+ find_library(lib, nil, binaries)
41
+ end
42
+
43
+ ["ndtypes.h"].each do |header|
44
+ find_header(header, headers)
45
+ have_header(header)
46
+ end
47
+
48
+ dir_config("ndtypes", [headers], [binaries])
49
+
50
+ basenames = %w{gc_guard ruby_ndtypes}
51
+ $objs = basenames.map { |b| "#{b}.o" }
52
+ $srcs = basenames.map { |b| "#{b}.c" }
53
+
54
+ $CFLAGS += " -O0 -g "
55
+ create_makefile("ruby_ndtypes/ruby_ndtypes")
@@ -0,0 +1,36 @@
1
+ /* Functions useful for interfacing shared rbuf objects with the Ruby GC. */
2
+ /* Author: Sameer Deshmukh (@v0dro) */
3
+ #include "ruby_ndtypes_internal.h"
4
+
5
+ #define GC_GUARD_TABLE_NAME "@__gc_guard_table"
6
+
7
+ static ID id_gc_guard_table;
8
+
9
+ /* Unregister an NDT object-rbuf pair from the GC guard. */
10
+ void
11
+ rb_ndtypes_gc_guard_unregister(NdtObject *ndt)
12
+ {
13
+ VALUE table = rb_ivar_get(mNDTypes_GCGuard, id_gc_guard_table);
14
+ rb_hash_delete(table, PTR2NUM(ndt));
15
+ }
16
+
17
+ /* Register a NDT-rbuf pair in the GC guard. */
18
+ void
19
+ rb_ndtypes_gc_guard_register(NdtObject *ndt, VALUE rbuf)
20
+ {
21
+ VALUE table = rb_ivar_get(mNDTypes_GCGuard, id_gc_guard_table);
22
+ if (table == Qnil) {
23
+ rb_raise(rb_eLoadError, "GC guard not initialized.");
24
+ }
25
+
26
+ rb_hash_aset(table, PTR2NUM(ndt), rbuf);
27
+ }
28
+
29
+ /* Initialize the global GC guard table. klass is a VALUE reprensenting NDTypes class. */
30
+ void
31
+ rb_ndtypes_init_gc_guard(void)
32
+ {
33
+ id_gc_guard_table = rb_intern(GC_GUARD_TABLE_NAME);
34
+ rb_ivar_set(mNDTypes_GCGuard, id_gc_guard_table, rb_hash_new());
35
+ }
36
+
@@ -0,0 +1,12 @@
1
+ /* Header file containing various functions for GC guard table. */
2
+
3
+ #ifndef GC_GUARD_H
4
+ #define GC_GUARD_H
5
+
6
+ #include "ruby_ndtypes_internal.h"
7
+
8
+ void rb_ndtypes_gc_guard_unregister(NdtObject *ndt);
9
+ void rb_ndtypesgc_guard_register(NdtObject *ndt, VALUE rbuf);
10
+ void rb_ndtypes_init_gc_guard(VALUE cNDTypes);
11
+
12
+ #endif /* GC_GUARD_H */
@@ -0,0 +1,5 @@
1
+
2
+ Version 0.2.0
3
+ -------------
4
+
5
+ Stefan Krah <skrah@bytereef.org>, sponsored by Anaconda Inc. and Quansight LLC.
@@ -0,0 +1,101 @@
1
+
2
+
3
+ Unix: libndtypes build instructions
4
+ ===================================
5
+
6
+ # Build
7
+ ./configure
8
+ make
9
+
10
+ # Test
11
+ make check
12
+
13
+ # Install
14
+ make install
15
+
16
+ # Clean
17
+ make clean
18
+
19
+ # Distclean
20
+ make distclean
21
+
22
+
23
+ Windows: libndtypes build instructions
24
+ ======================================
25
+
26
+ See vcbuild/INSTALL.txt.
27
+
28
+
29
+
30
+ Unix/Windows: Python module build instructions
31
+ ==============================================
32
+
33
+ To avoid shared library mismatches, the Python module builds with an rpath
34
+ and ships the library inside the package.
35
+
36
+ Unless you are a distributor with tight control over the system library
37
+ versions, it is not recommended to install the library for the Python
38
+ module.
39
+
40
+
41
+ Build all
42
+ ---------
43
+
44
+ # Build libndtypes and the module (libndtypes is copied into the package)
45
+ python3 setup.py build
46
+
47
+ # Test
48
+ python3 setup.py test
49
+
50
+ # Doctest (optional, relies on Sphinx)
51
+ python3 setup.py doctest
52
+
53
+ # Install
54
+ python3 setup.py install
55
+
56
+ # Clean libndtypes and the module
57
+ python3 setup.py distclean
58
+
59
+
60
+ Build the module only (for developing)
61
+ --------------------------------------
62
+
63
+ First, build libndtypes as above. This also copies the shared library into
64
+ the package. Then, to avoid rebuilding the library repeatedly, use:
65
+
66
+ # Build the module
67
+ python3 setup.py module
68
+
69
+ # Clean the module
70
+ python3 setup.py clean
71
+
72
+
73
+ Alternative install (for developing)
74
+ ------------------------------------
75
+
76
+ # Install the package into a local directory. This is mainly useful for
77
+ # developing xnd or gufuncs:
78
+ python3 setup.py install --local="$PWD/../python"
79
+
80
+ # Windows:
81
+ python.exe setup.py install --local="%cd%\..\python"
82
+
83
+
84
+ Alternative install with conda (for developing)
85
+ -----------------------------------------------
86
+
87
+ # Install the ndtypes package into a local directory.
88
+
89
+ # Create and activate a new conda environment:
90
+ conda create --name xnd python=3.7
91
+ conda activate xnd
92
+
93
+ # Use conda to build libndtypes and ndtypes:
94
+ conda build .conda/libndtypes
95
+ conda build .conda/ndtypes
96
+
97
+ # Use conda to install the local version of the library and the
98
+ # Python module:
99
+ conda install --use-local ndtypes
100
+
101
+
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2017-2018, plures
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.