bitpack 0.1 → 0.2.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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a4225281a59edd833532a17d15221435c3a257a
4
+ data.tar.gz: d4eb429fd206d5ac5215d41d7939f33e9c70937e
5
+ SHA512:
6
+ metadata.gz: 44a8ee1fdd340d00b8749a63e30335da9f1a36a9f54f9b676cc5c467119b1478712e3ffc8e9ff7042726cf1fcf2041692a087d08904e9f19cc2722eb402323a0
7
+ data.tar.gz: 0ce6f765a75e38711589c03ce362e181b864a016d183a710606f623f652558096bfd3ca7d2e142dc3288c26887e25477aac93b0e1bb819bf538408eca024eb8a
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007 Corey Burrows
1
+ Copyright (c) 2017 Corey Burrows
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,39 +1,11 @@
1
-
2
1
  require 'rubygems'
3
- Gem::manage_gems
4
- require 'rake/gempackagetask'
5
2
  require 'rake/clean'
6
- require 'rake/rdoctask'
3
+ require 'rdoc/task'
7
4
 
8
- NAME = 'bitpack'
9
- VERS = '0.1'
10
- GEM_NAME = "#{NAME}-#{VERS}.gem"
5
+ require './lib/bitpack/version'
11
6
 
12
7
  RDOC_MAIN = "README"
13
8
 
14
- spec = Gem::Specification.new do |s|
15
- s.name = NAME
16
- s.version = VERS
17
- s.author = "Corey Burrows"
18
- s.email = "corey.burrows@gmail.com"
19
- s.platform = Gem::Platform::RUBY
20
- s.summary = "Library for packing and unpacking binary strings."
21
- s.files = %w{README CHANGELOG LICENSE Rakefile} +
22
- Dir.glob("ext/**/*.{h,c,rb}") +
23
- Dir.glob("lib/**/*.{rb}") +
24
- Dir.glob("test/**/*.rb")
25
- s.require_path = "."
26
- s.autorequire = "bitpack"
27
- s.extensions = ["ext/extconf.rb"]
28
- #s.test_file = ""
29
- s.has_rdoc = true
30
- s.extra_rdoc_files = [ RDOC_MAIN, "CHANGELOG", "LICENSE" ]
31
- end
32
-
33
- Rake::GemPackageTask.new(spec) do |pkg|
34
- pkg.need_tar = true
35
- end
36
-
37
9
  Rake::RDocTask.new do |rd|
38
10
  rd.main = RDOC_MAIN
39
11
  rd.rdoc_files.include(RDOC_MAIN, "CHANGELOG", "LICENSE", "ext/**/*.c", "lib/**/*.rb")
@@ -45,43 +17,31 @@ CLEAN.include FileList["ext/**/*.o",
45
17
  "ext/**/*.bundle",
46
18
  "ext/**/Makefile",
47
19
  "ext/**/mkmf.log",
48
- "pkg/*.gem",
20
+ "*.gem",
49
21
  "test/*.o",
50
22
  "test/test_driver",
51
23
  "html"
52
24
  ]
53
25
 
54
26
  task :build do
55
- Dir.chdir('ext')
56
- sh('ruby extconf.rb')
57
- sh('make')
58
- Dir.chdir('..')
59
- end
60
-
61
- task :c_test do
62
- Dir.chdir('test')
63
- sh('make')
64
- Dir.chdir('..')
65
- end
66
-
67
- task :ruby_test do
68
- Dir.chdir('test')
69
- sh('ruby bitpack_tests.rb')
70
- Dir.chdir('..')
27
+ Dir.chdir('ext/bitpack') do
28
+ sh('ruby extconf.rb && make')
29
+ end
71
30
  end
72
31
 
73
- task :test => [ :build, :c_test, :ruby_test ] do
32
+ task :test => [:build] do
33
+ sh('ruby test/bitpack_tests.rb')
74
34
  end
75
35
 
76
36
  task :gem do
77
- sh %{rake pkg/#{GEM_NAME}}
37
+ sh %{gem build bitpack.gemspec}
78
38
  end
79
39
 
80
40
  task :install => :gem do
81
- sh %{sudo gem install pkg/#{GEM_NAME}}
41
+ sh %{gem install ./bitpack-#{BitPack::VERSION}.gem}
82
42
  end
83
43
 
84
44
  task :uninstall do
85
- sh %{sudo gem uninstall #{NAME}}
45
+ sh %{gem uninstall bitpack}
86
46
  end
87
47
 
@@ -315,7 +315,7 @@ int bitpack_get_bits(bitpack_t bp, unsigned long num_bits, unsigned long index,
315
315
  bitpack_get(bp, index + i, &bit);
316
316
 
317
317
  if (bit == 1) {
318
- v |= bit << (num_bits - i - 1);
318
+ v |= (unsigned long)bit << (num_bits - i - 1);
319
319
  }
320
320
  }
321
321
 
File without changes
@@ -6,7 +6,7 @@
6
6
  static VALUE cBitPack;
7
7
 
8
8
  /* mapping of BitPack error codes to ruby exceptions */
9
- static VALUE bp_exceptions[6];
9
+ static VALUE bp_exceptions[7];
10
10
 
11
11
  /*
12
12
  * call-seq:
@@ -64,7 +64,7 @@ static VALUE bp_from_bytes(VALUE class, VALUE bytes_str)
64
64
 
65
65
  str = StringValue(bytes_str);
66
66
 
67
- bp = bitpack_init_from_bytes((unsigned char *)RSTRING(str)->ptr, RSTRING(str)->len);
67
+ bp = bitpack_init_from_bytes((unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));
68
68
 
69
69
  if (bp == NULL) {
70
70
  rb_raise(bp_exceptions[BITPACK_ERR_MALLOC_FAILED], "malloc() failed");
@@ -187,7 +187,7 @@ static VALUE bp_on(VALUE self, VALUE index)
187
187
  Data_Get_Struct(self, struct _bitpack_t, bp);
188
188
 
189
189
  if (!bitpack_on(bp, NUM2ULONG(index))) {
190
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
190
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
191
191
  bitpack_get_error_str(bp));
192
192
  }
193
193
 
@@ -209,7 +209,7 @@ static VALUE bp_off(VALUE self, VALUE index)
209
209
  Data_Get_Struct(self, struct _bitpack_t, bp);
210
210
 
211
211
  if (!bitpack_off(bp, NUM2ULONG(index))) {
212
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
212
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
213
213
  bitpack_get_error_str(bp));
214
214
  }
215
215
 
@@ -230,7 +230,7 @@ static VALUE bp_get(VALUE self, VALUE index)
230
230
  Data_Get_Struct(self, struct _bitpack_t, bp);
231
231
 
232
232
  if (!bitpack_get(bp, NUM2ULONG(index), &bit)) {
233
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
233
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
234
234
  bitpack_get_error_str(bp));
235
235
  }
236
236
 
@@ -265,7 +265,7 @@ static VALUE bp_set_bits(VALUE self, VALUE value, VALUE num_bits, VALUE index)
265
265
  Data_Get_Struct(self, struct _bitpack_t, bp);
266
266
 
267
267
  if (!bitpack_set_bits(bp, NUM2ULONG(value), NUM2ULONG(num_bits), NUM2ULONG(index))) {
268
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
268
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
269
269
  bitpack_get_error_str(bp));
270
270
  }
271
271
 
@@ -303,9 +303,9 @@ static VALUE bp_set_bytes(VALUE self, VALUE bytes, VALUE index)
303
303
 
304
304
  str = StringValue(bytes);
305
305
 
306
- if (!bitpack_set_bytes(bp, (unsigned char *)RSTRING(str)->ptr,
307
- RSTRING(str)->len, NUM2ULONG(index))) {
308
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
306
+ if (!bitpack_set_bytes(bp, (unsigned char *)RSTRING_PTR(str),
307
+ RSTRING_LEN(str), NUM2ULONG(index))) {
308
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
309
309
  bitpack_get_error_str(bp));
310
310
  }
311
311
 
@@ -350,7 +350,7 @@ static VALUE bp_get_bits(VALUE self, VALUE num_bits, VALUE index)
350
350
  Data_Get_Struct(self, struct _bitpack_t, bp);
351
351
 
352
352
  if (!bitpack_get_bits(bp, NUM2ULONG(num_bits), NUM2ULONG(index), &value)) {
353
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
353
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
354
354
  bitpack_get_error_str(bp));
355
355
  }
356
356
 
@@ -382,7 +382,7 @@ static VALUE bp_get_bytes(VALUE self, VALUE num_bytes, VALUE index)
382
382
  Data_Get_Struct(self, struct _bitpack_t, bp);
383
383
 
384
384
  if (!bitpack_get_bytes(bp, NUM2ULONG(num_bytes), NUM2ULONG(index), &bytes)) {
385
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
385
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
386
386
  bitpack_get_error_str(bp));
387
387
  }
388
388
 
@@ -420,7 +420,7 @@ static VALUE bp_append_bits(VALUE self, VALUE value, VALUE num_bits)
420
420
  Data_Get_Struct(self, struct _bitpack_t, bp);
421
421
 
422
422
  if (!bitpack_append_bits(bp, NUM2ULONG(value), NUM2ULONG(num_bits))) {
423
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
423
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
424
424
  bitpack_get_error_str(bp));
425
425
  }
426
426
 
@@ -463,9 +463,9 @@ static VALUE bp_append_bytes(VALUE self, VALUE value)
463
463
 
464
464
  str = StringValue(value);
465
465
 
466
- if (!bitpack_append_bytes(bp, (unsigned char *)RSTRING(str)->ptr,
467
- RSTRING(str)->len)) {
468
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
466
+ if (!bitpack_append_bytes(bp, (unsigned char *)RSTRING_PTR(str),
467
+ RSTRING_LEN(str))) {
468
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
469
469
  bitpack_get_error_str(bp));
470
470
  }
471
471
 
@@ -501,7 +501,7 @@ static VALUE bp_read_bits(VALUE self, VALUE num_bits)
501
501
  Data_Get_Struct(self, struct _bitpack_t, bp);
502
502
 
503
503
  if (!bitpack_read_bits(bp, NUM2ULONG(num_bits), &value)) {
504
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
504
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
505
505
  bitpack_get_error_str(bp));
506
506
  }
507
507
 
@@ -536,7 +536,7 @@ static VALUE bp_read_bytes(VALUE self, VALUE num_bytes)
536
536
  Data_Get_Struct(self, struct _bitpack_t, bp);
537
537
 
538
538
  if (!bitpack_read_bytes(bp, NUM2ULONG(num_bytes), &value)) {
539
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
539
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
540
540
  bitpack_get_error_str(bp));
541
541
  }
542
542
 
@@ -562,7 +562,7 @@ static VALUE bp_to_bin(VALUE self)
562
562
  Data_Get_Struct(self, struct _bitpack_t, bp);
563
563
 
564
564
  if (!bitpack_to_bin(bp, &s)) {
565
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
565
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
566
566
  bitpack_get_error_str(bp));
567
567
  }
568
568
 
@@ -607,7 +607,7 @@ static VALUE bp_to_bytes(VALUE self)
607
607
  Data_Get_Struct(self, struct _bitpack_t, bp);
608
608
 
609
609
  if (!bitpack_to_bytes(bp, &s, &num_bytes)) {
610
- rb_raise(bp_exceptions[bitpack_get_error(bp)],
610
+ rb_raise(bp_exceptions[bitpack_get_error(bp)], "%s",
611
611
  bitpack_get_error_str(bp));
612
612
  }
613
613
 
@@ -655,8 +655,5 @@ void Init_bitpack()
655
655
  bp_exceptions[BITPACK_ERR_RANGE_TOO_BIG] = rb_eRangeError;
656
656
  bp_exceptions[BITPACK_ERR_READ_PAST_END] = rb_eRangeError;
657
657
  bp_exceptions[BITPACK_ERR_EMPTY] = rb_eRangeError;
658
-
659
- /* require the pure ruby methods */
660
- rb_require("lib/bitpack.rb");
661
658
  }
662
659
 
@@ -4,5 +4,5 @@ require "mkmf"
4
4
 
5
5
  $CFLAGS << ' -W -Wall'
6
6
 
7
- create_makefile("bitpack")
7
+ create_makefile("bitpack/bitpack")
8
8
 
@@ -1,4 +1,3 @@
1
-
2
1
  class BitPack
3
2
  # Element Assignment. Sets the bit at +index+, or the range of bits indicated
4
3
  # by the Range object +range+, or the range specified by +index+ and +length+.
@@ -51,3 +50,4 @@ class BitPack
51
50
  end
52
51
  end
53
52
 
53
+ require "bitpack/bitpack"
@@ -0,0 +1,3 @@
1
+ class BitPack
2
+ VERSION = '0.2.0'
3
+ end
@@ -1,5 +1,6 @@
1
-
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
2
  $:.unshift File.join(File.dirname(__FILE__), '..', 'ext')
3
+
3
4
  require 'bitpack'
4
5
 
5
6
  require 'test/unit'
@@ -103,7 +104,7 @@ class TC_BitPack < Test::Unit::TestCase
103
104
  assert_equal("000000001011010111111111111111111111111111111111", bp.to_bin)
104
105
  assert_equal(0, bp.get_bits(8, 0))
105
106
 
106
- unsigned_long_size = [1].pack("L").size
107
+ unsigned_long_size = [1].pack("L_").size
107
108
 
108
109
  # error cases
109
110
  msg = sprintf("range size %d bits is too large (maximum size is %d bits)", unsigned_long_size * 8 + 1, unsigned_long_size * 8)
metadata CHANGED
@@ -1,57 +1,72 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
1
+ --- !ruby/object:Gem::Specification
4
2
  name: bitpack
5
- version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2007-11-14 00:00:00 -06:00
8
- summary: Library for packing and unpacking binary strings.
9
- require_paths:
10
- - .
11
- email: corey.burrows@gmail.com
12
- homepage:
13
- rubyforge_project:
14
- description:
15
- autorequire: bitpack
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
- authors:
6
+ authors:
30
7
  - Corey Burrows
31
- files:
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.0
27
+ description:
28
+ email: corey.burrows@gmail.com
29
+ executables: []
30
+ extensions:
31
+ - ext/bitpack/extconf.rb
32
+ extra_rdoc_files:
32
33
  - README
33
34
  - CHANGELOG
34
35
  - LICENSE
36
+ files:
37
+ - CHANGELOG
38
+ - LICENSE
39
+ - README
35
40
  - Rakefile
36
- - ext/bitpack.h
37
- - ext/bitpack.c
38
- - ext/bitpack_ext.c
39
- - ext/extconf.rb
41
+ - ext/bitpack/bitpack.c
42
+ - ext/bitpack/bitpack.h
43
+ - ext/bitpack/bitpack_ext.c
44
+ - ext/bitpack/extconf.rb
40
45
  - lib/bitpack.rb
46
+ - lib/bitpack/version.rb
41
47
  - test/bitpack_tests.rb
42
- test_files: []
43
-
48
+ homepage: https://github.com/burrows/bitpack
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
44
53
  rdoc_options: []
45
-
46
- extra_rdoc_files:
47
- - README
48
- - CHANGELOG
49
- - LICENSE
50
- executables: []
51
-
52
- extensions:
53
- - ext/extconf.rb
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
54
66
  requirements: []
55
-
56
- dependencies: []
57
-
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.5.1
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Library for packing and unpacking binary strings.
72
+ test_files: []