snow-data 1.3.0 → 1.4.0
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.
- checksums.yaml +5 -5
- data/README.md +12 -24
- data/ext/extconf.rb +1 -4
- data/ext/snow-data/snow-data.c +8 -2
- data/lib/snow-data/memory.rb +7 -1
- data/lib/snow-data/version.rb +1 -1
- metadata +21 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d9e719eecd9292aa7cdb5019c8c6756c4ac71cc7f1514f99f79d22427d01a8e
|
4
|
+
data.tar.gz: 86a0a3f25e1406c61e39036e8bd5d4aec8527fba6f2000cd6b9e943a113153e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 851f72c21008c1f6768fa25b10342faec9e87f524ccc3435447c95b4a1dfd02450722b90fc55169a26adb44005a40c4dfae948f776d958d5bbc1f299717e9ed4
|
7
|
+
data.tar.gz: 02d6a54f0b5e8c17756a4523877503e2e169eb681fcd97ad26a960fe3c0bc017d271048b89dbd317d5549050c1e4223c783f2bd23def4a6258865ca179605f93
|
data/README.md
CHANGED
@@ -8,30 +8,21 @@ Intro
|
|
8
8
|
-----
|
9
9
|
|
10
10
|
Snow-Data is a simple gem for dealing with memory and defining structs in a
|
11
|
-
C-like way.
|
12
|
-
by default. You'll thank me for this later, even if almost every operation does
|
13
|
-
bounds-checking where possible to ensure you're not being a horrible person.
|
11
|
+
C-like way. It's also hideously unsafe, so everything is tainted by default.
|
14
12
|
|
15
13
|
For more information on usage, see the rdoc documentation for Snow::Memory
|
16
|
-
and Snow::CStruct, as it
|
17
|
-
to talk to people. Ok, it can't help you with that.
|
18
|
-
|
19
|
-
_ALLONS-Y!_
|
20
|
-
|
14
|
+
and Snow::CStruct, as it should explain most of the important things.
|
21
15
|
|
22
16
|
Example
|
23
17
|
-------
|
24
18
|
|
25
|
-
For those wanting a quick-ish example of using snow-data,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Bear in mind that, down the road, it will also be possible to assign snow-math
|
30
|
-
types to these as well (provided they use the same underlying types), though I
|
31
|
-
wouldn't use this for defining data types for anything other than transit to
|
32
|
-
another API that expects its data in a format like this.
|
19
|
+
For those wanting a quick-ish example of using snow-data, the following example
|
20
|
+
shows how to define a few structs. These are a Vec3, Vec2, Color, and Vertex,
|
21
|
+
which may be common in game code.
|
33
22
|
|
34
|
-
|
23
|
+
In practice, this tends not to be highly useful except for interacting with
|
24
|
+
some APIs over FFI, such as OpenGL. That said, if it happens to be useful,
|
25
|
+
all the better.
|
35
26
|
|
36
27
|
#!/usr/bin/env ruby -w
|
37
28
|
|
@@ -42,11 +33,12 @@ How you use it, ultimately, is really up to you.
|
|
42
33
|
# it helps to illustrate that you can specify alignment).
|
43
34
|
Vec3 = Snow::CStruct[:Vec3, 'x: float :4; y: float :4; z: float :4']
|
44
35
|
Vec2 = Snow::CStruct[:Vec2, 'x: float :4; y: float :4']
|
36
|
+
|
45
37
|
# ui8 is shorthand for uint8_t -- you can write either, and the documentation
|
46
38
|
# for CStruct::new explains the short- and long-form names for each primitive
|
47
39
|
# type provided by Snow-Data. Further, CStructs defined with a name, as with
|
48
40
|
# Vec3, Vec2, and Color, have getters and setters defined in the Memory class
|
49
|
-
# and are usable as member types
|
41
|
+
# and are usable as member types (see below).
|
50
42
|
Color = Snow::CStruct[:Color, 'r: ui8; g: ui8; b: ui8; a: ui8']
|
51
43
|
|
52
44
|
# Define a vertex type whose members are all also 4-byte aligned. The vertex
|
@@ -69,7 +61,7 @@ How you use it, ultimately, is really up to you.
|
|
69
61
|
VERTEX_DESCRIPTION
|
70
62
|
end
|
71
63
|
|
72
|
-
#
|
64
|
+
# Now create a vertex:
|
73
65
|
a_vertex = Vertex.new { |v|
|
74
66
|
v.position = Vec3.new { |p| p.x = 1; p.y = 2; p.z = 3 }
|
75
67
|
v.normal = Vec3.new { |n| n.x = 0.707107; n.y = 0; n.z = 0.707107 }
|
@@ -83,7 +75,7 @@ How you use it, ultimately, is really up to you.
|
|
83
75
|
|
84
76
|
puts "Our vertex:\n#{stringify_vertex a_vertex}"
|
85
77
|
|
86
|
-
#
|
78
|
+
# Create an array of 64 vertices:
|
87
79
|
some_vertices = Vertex[64]
|
88
80
|
|
89
81
|
# And set all vertices to the above vertex.
|
@@ -119,7 +111,3 @@ Snow-Data is licensed under a simplified BSD license, like most of my gems.
|
|
119
111
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
120
112
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
121
113
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
122
|
-
|
123
|
-
The views and conclusions contained in the software and documentation are those
|
124
|
-
of the authors and should not be interpreted as representing official policies,
|
125
|
-
either expressed or implied, of the FreeBSD Project.
|
data/ext/extconf.rb
CHANGED
@@ -5,9 +5,6 @@
|
|
5
5
|
|
6
6
|
require 'mkmf'
|
7
7
|
|
8
|
-
# Compile as C99
|
9
|
-
$CFLAGS += " -std=c99 -Wall -pedantic"
|
10
|
-
|
11
8
|
OptKVPair = Struct.new(:key, :value)
|
12
9
|
|
13
10
|
option_mappings = {
|
@@ -53,7 +50,7 @@ else
|
|
53
50
|
end
|
54
51
|
|
55
52
|
$CFLAGS += ' -DSD_ALLOW_ALLOCA' if options[:allow_alloca]
|
56
|
-
$CFLAGS += ' -
|
53
|
+
$CFLAGS += ' -DSD_WARN_ON_IMPLICIT_COPY_SIZE' if options[:warn_implicit_size]
|
57
54
|
$CFLAGS += ' -DSD_WARN_ON_NO_BYTESIZE_METHOD' if options[:warn_no_bytesize]
|
58
55
|
$CFLAGS += ' -DSD_VERBOSE_COPY_LOG' if options[:debug_memory_copy]
|
59
56
|
$CFLAGS += ' -DSD_VERBOSE_MALLOC_LOG' if options[:debug_allocations]
|
data/ext/snow-data/snow-data.c
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
*/
|
6
6
|
|
7
7
|
#include "ruby.h"
|
8
|
+
#include <limits.h>
|
8
9
|
#include <stdint.h>
|
9
10
|
#include <stdio.h>
|
10
11
|
|
@@ -1668,7 +1669,9 @@ static VALUE sd_memory_copy(int argc, VALUE *argv, VALUE self)
|
|
1668
1669
|
size_t destination_offset;
|
1669
1670
|
size_t byte_size;
|
1670
1671
|
size_t self_byte_size;
|
1672
|
+
#if defined(SD_WARN_ON_NO_BYTESIZE_METHOD) || defined(SD_WARN_ON_IMPLICIT_COPY_SIZE)
|
1671
1673
|
int source_is_data = 0;
|
1674
|
+
#endif
|
1672
1675
|
|
1673
1676
|
sd_check_null_block(self);
|
1674
1677
|
rb_check_frozen(self);
|
@@ -1691,11 +1694,13 @@ static VALUE sd_memory_copy(int argc, VALUE *argv, VALUE self)
|
|
1691
1694
|
}
|
1692
1695
|
}
|
1693
1696
|
|
1694
|
-
if (RTEST(rb_obj_is_kind_of(sd_source,
|
1697
|
+
if (RTEST(rb_obj_is_kind_of(sd_source, rb_cObject))) {
|
1695
1698
|
/* Otherwise extract a pointer from the object if it's a Data object */
|
1696
1699
|
const struct RData *source_data = RDATA(sd_source);
|
1697
1700
|
source_pointer = ((const uint8_t *)source_data->data);
|
1701
|
+
#if defined(SD_WARN_ON_NO_BYTESIZE_METHOD) || defined(SD_WARN_ON_IMPLICIT_COPY_SIZE)
|
1698
1702
|
source_is_data = 1;
|
1703
|
+
#endif
|
1699
1704
|
} else if (RTEST(rb_obj_is_kind_of(sd_source, rb_cNumeric))) {
|
1700
1705
|
/* Otherwise, if it's a Numeric, try to convert what is assumed to be an
|
1701
1706
|
address to a pointer */
|
@@ -1890,7 +1895,8 @@ static VALUE sd_align_size(int argc, VALUE *argv, VALUE self)
|
|
1890
1895
|
void Init_snowdata_bindings(void)
|
1891
1896
|
{
|
1892
1897
|
VALUE sd_snow_module = rb_define_module("Snow");
|
1893
|
-
VALUE sd_memory_klass = rb_define_class_under(sd_snow_module, "Memory",
|
1898
|
+
VALUE sd_memory_klass = rb_define_class_under(sd_snow_module, "Memory", rb_cObject);
|
1899
|
+
rb_undef_alloc_func(sd_memory_klass);
|
1894
1900
|
|
1895
1901
|
kSD_IVAR_BYTESIZE = rb_intern("@__bytesize__");
|
1896
1902
|
kSD_IVAR_ALIGNMENT = rb_intern("@__alignment__");
|
data/lib/snow-data/memory.rb
CHANGED
@@ -77,7 +77,13 @@ class Snow::Memory
|
|
77
77
|
# overlap, refer to different chunks of memory, one might be null, etc.
|
78
78
|
#
|
79
79
|
def ==(other)
|
80
|
-
|
80
|
+
return false unless other
|
81
|
+
|
82
|
+
if other.kind_of?(Memory) || (other.respond_to?(:address) && other.respond_to?(:bytesize))
|
83
|
+
self.address == other.address && self.bytesize == other.bytesize
|
84
|
+
else
|
85
|
+
false
|
86
|
+
end
|
81
87
|
end
|
82
88
|
|
83
89
|
|
data/lib/snow-data/version.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snow-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noel Raymond Cower
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Snow-Data is a gem for allocating memory and working with existing blocks of
|
15
15
|
memory in a moderately safe but still technically really, really unsafe way. It
|
16
16
|
also provides functionality for defining C-struct classes, including those with
|
17
17
|
other structs as members.
|
18
|
-
email: ncower@
|
18
|
+
email: ncower@nil.dev
|
19
19
|
executables: []
|
20
20
|
extensions:
|
21
21
|
- ext/extconf.rb
|
@@ -24,46 +24,44 @@ extra_rdoc_files:
|
|
24
24
|
- README.md
|
25
25
|
- COPYING
|
26
26
|
files:
|
27
|
+
- COPYING
|
28
|
+
- README.md
|
29
|
+
- ext/extconf.rb
|
30
|
+
- ext/snow-data/snow-data.c
|
31
|
+
- lib/snow-data.rb
|
32
|
+
- lib/snow-data/c_struct.rb
|
27
33
|
- lib/snow-data/c_struct/array_base.rb
|
28
34
|
- lib/snow-data/c_struct/builder.rb
|
29
35
|
- lib/snow-data/c_struct/struct_base.rb
|
30
|
-
- lib/snow-data/c_struct.rb
|
31
36
|
- lib/snow-data/memory.rb
|
32
37
|
- lib/snow-data/version.rb
|
33
|
-
- lib/snow-data.rb
|
34
|
-
- ext/snow-data/snow-data.c
|
35
|
-
- ext/extconf.rb
|
36
|
-
- COPYING
|
37
|
-
- README.md
|
38
38
|
homepage: https://github.com/nilium/ruby-snowdata
|
39
39
|
licenses:
|
40
|
-
-
|
40
|
+
- BSD-2-Clause
|
41
41
|
metadata: {}
|
42
|
-
post_install_message:
|
42
|
+
post_install_message:
|
43
43
|
rdoc_options:
|
44
|
-
- --title
|
44
|
+
- "--title"
|
45
45
|
- snow-data -- C Data Types
|
46
|
-
- --main
|
46
|
+
- "--main"
|
47
47
|
- README.md
|
48
|
-
- --markup=markdown
|
49
|
-
- --line-numbers
|
48
|
+
- "--markup=markdown"
|
49
|
+
- "--line-numbers"
|
50
50
|
require_paths:
|
51
51
|
- lib
|
52
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 3.3.0
|
57
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
|
-
|
64
|
-
|
65
|
-
signing_key:
|
63
|
+
rubygems_version: 3.5.11
|
64
|
+
signing_key:
|
66
65
|
specification_version: 4
|
67
66
|
summary: 'Snow-Data: for working with memory like you''ve got nothing to lose.'
|
68
67
|
test_files: []
|
69
|
-
has_rdoc: true
|