diff --git a/History.txt b/History.txt index 75f0698..17507e1 100644 --- a/History.txt +++ b/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) diff --git a/ext/crc32/crc32.c b/ext/crc32/crc32.c deleted file mode 100644 index a6a1b7a..0000000 --- a/ext/crc32/crc32.c +++ /dev/null @@ -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); -} diff --git a/ext/crc32/extconf.rb b/ext/crc32/extconf.rb deleted file mode 100644 index f14de51..0000000 --- a/ext/crc32/extconf.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'mkmf' - -dir_config("crc32") - -create_makefile("crc32") diff --git a/lib/memcache.rb b/lib/memcache.rb index c445d79..2c6a412 100644 --- a/lib/memcache.rb +++ b/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 ## diff --git a/memcache-client.gemspec b/memcache-client.gemspec index 3e69c0d..9cccb81 100644 --- a/memcache-client.gemspec +++ b/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 diff --git a/test/test_mem_cache.rb b/test/test_mem_cache.rb index d9316b8..769aade 100644 --- a/test/test_mem_cache.rb +++ b/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