Permalink
Browse files

Use Zlib.crc32 instead of native extension. Prepare for 1.5.0.5 release.

  • Loading branch information...
1 parent 9c291ad commit 9f81841bbb4fc6a3dfe5525a285a045d3da1a589 @mperham mperham committed Nov 25, 2008
Showing with 9 additions and 90 deletions.
  1. +5 −0 History.txt
  2. +0 −38 ext/crc32/crc32.c
  3. +0 −5 ext/crc32/extconf.rb
  4. +2 −33 lib/memcache.rb
  5. +2 −3 memcache-client.gemspec
  6. +0 −11 test/test_mem_cache.rb
View
5 History.txt
@@ -1,3 +1,8 @@
+= 1.5.0.5
+
+* Remove native C CRC32_ITU_T extension in favor of Zlib's crc32 method.
+ memcache-client is now pure Ruby again and will work with JRuby and Rubinius.
+
= 1.5.0.4
* Get test suite working again (packagethief)
View
38 ext/crc32/crc32.c
@@ -1,38 +0,0 @@
-#include "ruby.h"
-#include "stdio.h"
-
-static VALUE t_itu_t(VALUE self, VALUE string) {
- VALUE str = StringValue(string);
-#ifdef RSTRING_LEN
- int n = RSTRING_LEN(str);
-#else
- int n = RSTRING(str)->len;
-#endif
-
-#ifdef RSTRING_PTR
- char* p = RSTRING_PTR(str);
-#else
- char* p = RSTRING(str)->ptr;
-#endif
-
- unsigned long r = 0xFFFFFFFF;
- int i, j;
-
- for (i = 0; i < n; i++) {
- r = r ^ p[i];
- for (j = 0; j < 8; j++) {
- if ( (r & 1) != 0 ) {
- r = (r >> 1) ^ 0xEDB88320;
- } else {
- r = r >> 1;
- }
- }
- }
- return INT2FIX(r ^ 0xFFFFFFFF);
-}
-
-VALUE cCRC32;
-void Init_crc32() {
- cCRC32 = rb_define_module("CRC32");
- rb_define_module_function(cCRC32, "itu_t", t_itu_t, 1);
-}
View
5 ext/crc32/extconf.rb
@@ -1,5 +0,0 @@
-require 'mkmf'
-
-dir_config("crc32")
-
-create_makefile("crc32")
View
35 lib/memcache.rb
@@ -4,38 +4,7 @@
require 'thread'
require 'timeout'
require 'rubygems'
-
-class String
-
- ##
- # Uses the ITU-T polynomial in the CRC32 algorithm.
- begin
- require 'crc32'
- def crc32_ITU_T
- CRC32.itu_t(self)
- end
- rescue LoadError => e
- puts "Loading with slow CRC32 ITU-T implementation: #{e.message}"
-
- def crc32_ITU_T
- r = 0xFFFFFFFF
-
- each_byte do |i|
- r ^= i
- 8.times do
- if (r & 1) != 0 then
- r = (r>>1) ^ 0xEDB88320
- else
- r >>= 1
- end
- end
- end
-
- r ^ 0xFFFFFFFF
- end
- end
-
-end
+require 'zlib'
##
# A Ruby client library for memcached.
@@ -500,7 +469,7 @@ def get_server_for_key(key)
# sketchy for down servers).
def hash_for(key)
- (key.crc32_ITU_T >> 16) & 0x7fff
+ (Zlib.crc32(key) >> 16) & 0x7fff
end
##
View
5 memcache-client.gemspec
@@ -1,15 +1,14 @@
Gem::Specification.new do |s|
s.name = 'memcache-client'
- s.version = '1.5.0.4'
+ s.version = '1.5.0.5'
s.authors = ['Eric Hodel', 'Robert Cottrell', 'Mike Perham']
s.email = 'mperham@gmail.com'
s.homepage = 'http://github.com/fiveruns/memcache-client'
s.summary = 'A Ruby-based memcached client library'
s.description = s.summary
- s.extensions << 'ext/crc32/extconf.rb'
s.require_path = 'lib'
- s.files = ["README.txt", "License.txt", "History.txt", "Rakefile", "lib/memcache.rb", "lib/memcache_util.rb", "ext/crc32/crc32.c"]
+ s.files = ["README.txt", "License.txt", "History.txt", "Rakefile", "lib/memcache.rb", "lib/memcache_util.rb"]
s.test_files = ["test/test_mem_cache.rb"]
end
View
11 test/test_mem_cache.rb
@@ -164,17 +164,6 @@ def test_cache_get_multi_bad_state
assert_match /get my_namespace:key\r\n/, server.socket.written.string
end
- def test_crc32_ITU_T
- assert_equal 0, ''.crc32_ITU_T
- # First value is the fast C version, last value is the pure Ruby version
- assert_in [-886631737, 1260851911], 'my_namespace:key'.crc32_ITU_T
- assert_in [-224284233, 870540390], 'my_name√space:key'.crc32_ITU_T
- end
-
- def assert_in(possible_values, value)
- assert possible_values.include?(value), "#{possible_values.inspect} should contain #{value}"
- end
-
def test_initialize
cache = MemCache.new :namespace => 'my_namespace', :readonly => true

0 comments on commit 9f81841

Please sign in to comment.