snow-data 1.0.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.
@@ -0,0 +1,92 @@
1
+ # This file is part of ruby-snowdata.
2
+ # Copyright (c) 2013 Noel Raymond Cower. All rights reserved.
3
+ # See COPYING for license details.
4
+
5
+ require 'snow-data/snowdata_bindings'
6
+
7
+ module Snow ; end
8
+
9
+
10
+ #
11
+ # A class for representing blocks of memory. You can either allocate memory
12
+ # using ::malloc or wrap existing blocks of memory using ::new or ::wrap (or
13
+ # ::__wrap__ if a subclass has extended ::wrap and ::new).
14
+ #
15
+ # If wrapping an existing block of memory, note that the Memory object does not
16
+ # take ownership of the block. As such, freeing it is the responsibility of its
17
+ # allocator. Only a block allocated by ::malloc will be freed by a Memory
18
+ # object, either by calling #free! or when the GC collects the object.
19
+ #
20
+ # When subclassing Memory, which is fine to do, you'll likely want to override
21
+ # Memory::new and possibly Memory::wrap. It is also possible to override
22
+ # Memory::malloc, but it's recommended you never do this. If you do, keep in
23
+ # mind that __malloc__ exists as an alias of malloc and you must never try to
24
+ # override it, as this could result in very strange behavior. Similarly, new is
25
+ # aliased as both wrap and __wrap__, the latter of which you should must never
26
+ # override either. Again, it may result in undesirable behavior, crashes, and
27
+ # angry responses to any issues you create on GitHub as a result.
28
+ #
29
+ class Snow::Memory
30
+
31
+ class <<self
32
+ alias_method :wrap, :new
33
+ alias_method :__wrap__, :new
34
+ alias_method :[], :malloc
35
+ alias_method :__malloc__, :malloc
36
+ end
37
+
38
+
39
+ #
40
+ # The size in bytes of a memory block.
41
+ #
42
+ def bytesize
43
+ @__bytesize__
44
+ end
45
+
46
+
47
+ #
48
+ # The alignment in bytes of a memory block.
49
+ #
50
+ def alignment
51
+ @__alignment__
52
+ end
53
+
54
+
55
+ #
56
+ # Returns whether the memory block is pointing to a null address.
57
+ #
58
+ def null?
59
+ self.address == 0
60
+ end
61
+
62
+
63
+ #
64
+ # Returns whether this and another block are equal in terms of their
65
+ # properties -- that is, whether they have the address and bytesize. If true,
66
+ # the objects refer to teh same block of memory. If false, they might still
67
+ # overlap, refer to different chunks of memory, one might be null, etc.
68
+ #
69
+ def ==(other)
70
+ self.address == other.address && self.bytesize == other.bytesize
71
+ end
72
+
73
+
74
+ #
75
+ # Returns a string showing the memory block's classname, object ID, address,
76
+ # size, and alignment.
77
+ #
78
+ def inspect
79
+ "<#{self.class}:0x#{__id__.to_s(16).rjust(14, ?0)} *0x#{self.address.to_s(16).rjust(14, ?0)}:#{self.bytesize}:#{self.alignment}>"
80
+ end
81
+
82
+
83
+ #
84
+ # Creates a new block of memory with the same class, size, and alignment;
85
+ # copies the receiver's data to the new block; and returns the new block.
86
+ #
87
+ def dup
88
+ new_self = self.class.__malloc__(self.bytesize, self.alignment)
89
+ new_self.copy!(self, 0, 0, self.bytesize)
90
+ end
91
+
92
+ end
@@ -0,0 +1,12 @@
1
+ # This file is part of ruby-snowdata.
2
+ # Copyright (c) 2013 Noel Raymond Cower. All rights reserved.
3
+ # See COPYING for license details.
4
+
5
+ module Snow
6
+
7
+ #
8
+ # The snow-data version string.
9
+ #
10
+ SNOW_DATA_VERSION = '1.0.0'.freeze
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snow-data
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Noel Raymond Cower
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Snow-Data is a gem for allocating memory and working with existing blocks of
15
+ memory in a moderately safe but still technically really, really unsafe way. It
16
+ also provides functionality for defining C-struct classes, including those with
17
+ other structs as members.
18
+ email: ncower@gmail.com
19
+ executables: []
20
+ extensions:
21
+ - ext/extconf.rb
22
+ extra_rdoc_files:
23
+ - ext/snow-data/snow-data.c
24
+ - README.md
25
+ - COPYING
26
+ files:
27
+ - lib/snow-data/c_struct.rb
28
+ - lib/snow-data/memory.rb
29
+ - lib/snow-data/version.rb
30
+ - lib/snow-data.rb
31
+ - ext/snow-data/snow-data.c
32
+ - ext/extconf.rb
33
+ - COPYING
34
+ - README.md
35
+ homepage: https://github.com/nilium/ruby-snowdata
36
+ licenses:
37
+ - Simplified BSD
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --title
42
+ - snow-data -- C Data Types
43
+ - --main
44
+ - README.md
45
+ - --markup=markdown
46
+ - --line-numbers
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubyforge_project:
61
+ rubygems_version: 2.0.5
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: 'Snow-Data: for working with memory like you''ve got nothing to lose.'
65
+ test_files: []
66
+ has_rdoc: true