memory_buffer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75b33d40e4b3744c6f1744138bf6e3c5757c41c6
4
+ data.tar.gz: a5633fe700d91d528e915759c854177b5a67d51c
5
+ SHA512:
6
+ metadata.gz: 4154c5933dd643012743802782621578efae99fd8501e7b0e659d099b832620beb1cf129d1d6b92665fc01a0baf65c64b0eef216853b8ed2c0f21fdb42408e8d
7
+ data.tar.gz: 3b3304440f7968bd7dc21e8aa21339e6d68cb8037896268cc3f533ab399bf96ee812cea7e49ba5dfd5ad6f51e8af77edc7d8df2cc1e234664bcc8d9e6314c692
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.so
11
+ *.bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0"
4
+ - "2.1"
5
+ - "2.2"
6
+ - ruby-head
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: ruby-head
10
+ fast_finish: true
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in memory_buffer.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Red Hat, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # MemoryBuffer
2
+
3
+ Ruby module to create memory buffers on Linux platforms.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/memory_buffer.svg)](http://badge.fury.io/rb/memory_buffer)
6
+ [![Build Status](https://travis-ci.org/ManageIQ/memory_buffer.svg)](https://travis-ci.org/ManageIQ/memory_buffer)
7
+ [![Dependency Status](https://gemnasium.com/ManageIQ/memory_buffer.svg)](https://gemnasium.com/ManageIQ/memory_buffer)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'memory_buffer'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install memory_buffer
24
+
25
+ ## Usage
26
+
27
+ MemoryBuffer supports `.create_aligned_string` to create a Ruby string from a buffer obtained via [memalign](http://linux.die.net/man/3/memalign).
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ManageIQ/memory_buffer.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/extensiontask'
4
+ Rake::ExtensionTask.new do |ext|
5
+ ext.name = 'memory_buffer'
6
+ ext.ext_dir = 'ext/memory_buffer'
7
+ ext.lib_dir = 'lib/memory_buffer'
8
+ end
9
+
10
+ require "rspec/core/rake_task"
11
+ RSpec::Core::RakeTask.new(:spec => :compile)
12
+
13
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "memory_buffer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile("memory_buffer/memory_buffer");
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Ruby module to block device operations on Linux platforms.
3
+ */
4
+
5
+ #include <stdio.h>
6
+ #include <errno.h>
7
+ #include <string.h>
8
+ #include <stdlib.h>
9
+ #ifdef __linux__
10
+ #include <malloc.h>
11
+ #endif
12
+
13
+ #include "ruby.h"
14
+
15
+ static const char *module_name = "MemoryBuffer";
16
+
17
+ static VALUE
18
+ mb_create_aligned(VALUE self, VALUE ralign, VALUE rlen) {
19
+ size_t align = (size_t)NUM2INT(ralign);
20
+ size_t len = (size_t)NUM2INT(rlen);
21
+ char *abuf;
22
+ int rc;
23
+ VALUE asb;
24
+
25
+ #ifdef __linux__
26
+ abuf = memalign(align, len);
27
+ #elif __APPLE__
28
+ rc = posix_memalign((void **)&abuf, align, len);
29
+ if (0 != rc) {
30
+ abuf = NULL;
31
+ }
32
+ #endif
33
+
34
+ if (NULL == abuf) {
35
+ rb_raise(rb_eNoMemError, "Could not allocate %d bytes of aligned memory\n", (int)len);
36
+ }
37
+
38
+ asb = rb_str_new(NULL, 0);
39
+ RBASIC(asb)->flags |= RSTRING_NOEMBED;
40
+ RSTRING(asb)->as.heap.ptr = abuf;
41
+ RSTRING(asb)->as.heap.aux.capa = len;
42
+
43
+ return(asb);
44
+ }
45
+
46
+ VALUE mMemoryBuffer;
47
+
48
+ /*
49
+ * Initialize the class.
50
+ */
51
+ void Init_memory_buffer() {
52
+ /*
53
+ * Define the module.
54
+ */
55
+ mMemoryBuffer = rb_define_module(module_name);
56
+
57
+ rb_define_singleton_method(mMemoryBuffer, "create_aligned", mb_create_aligned, 2);
58
+ }
@@ -0,0 +1,25 @@
1
+ # encoding: US-ASCII
2
+
3
+ require "memory_buffer/memory_buffer"
4
+ require "memory_buffer/version"
5
+
6
+ module MemoryBuffer
7
+ PACK_MIN = 152 #size after which performance of pack is better than the * operator
8
+ PACK_MAX = 545259518 #size after which pack completely fails
9
+
10
+ def self.create(size)
11
+ return size >= PACK_MIN && size <= PACK_MAX ? [""].pack("a#{size}") : "\0" * size
12
+ end
13
+
14
+ def self.create_quad
15
+ "\000\000\000\000\000\000\000\000"
16
+ end
17
+
18
+ def self.create_long
19
+ "\000\000\000\000"
20
+ end
21
+
22
+ def self.create_short
23
+ "\000\000"
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module MemoryBuffer
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'memory_buffer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "memory_buffer"
8
+ spec.version = MemoryBuffer::VERSION
9
+ spec.authors = ["Rich Oliveri", "Oleg Barenboim", "Jason Frey"]
10
+ spec.email = ["roliveri@redhat.com", "chessbyte@gmail.com", "fryguy9@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby module to create memory buffers on Linux platforms.}
13
+ spec.description = %q{Ruby module to create memory buffers on Linux platforms.}
14
+ spec.homepage = "http://github.com/ManageIQ/memory_buffer"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.extensions = ["ext/memory_buffer/extconf.rb"]
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake-compiler"
34
+ spec.add_development_dependency "rspec"
35
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memory_buffer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rich Oliveri
8
+ - Oleg Barenboim
9
+ - Jason Frey
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2015-06-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rake-compiler
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rspec
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ description: Ruby module to create memory buffers on Linux platforms.
72
+ email:
73
+ - roliveri@redhat.com
74
+ - chessbyte@gmail.com
75
+ - fryguy9@gmail.com
76
+ executables: []
77
+ extensions:
78
+ - ext/memory_buffer/extconf.rb
79
+ extra_rdoc_files: []
80
+ files:
81
+ - .gitignore
82
+ - .rspec
83
+ - .travis.yml
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - ext/memory_buffer/extconf.rb
91
+ - ext/memory_buffer/memory_buffer.c
92
+ - lib/memory_buffer.rb
93
+ - lib/memory_buffer/version.rb
94
+ - memory_buffer.gemspec
95
+ homepage: http://github.com/ManageIQ/memory_buffer
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.0.14
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby module to create memory buffers on Linux platforms.
120
+ test_files: []