Skip to content

crc32 is overridden by another library when using bundler #38

@n-nishizawa

Description

@n-nishizawa

I inserted the same input, but I got different bitmap on Linux and Mac.

I ran the following code.

  • test.rb
require 'cbloomfilter'

bf = CBloomFilter.new(16, 1, 7, 1)

puts "m #{bf.m}"
puts "k #{bf.k}"
puts "b #{bf.b}"

bf.insert 'a'
puts "bitmap: #{bf}"
  • Result on Linux
$ bundle exec ruby test.rb
m 16
k 1
b 1
bitmap: 1000000000000000
  • Result on Mac
m 16
k 1
b 1
bitmap: 0000000000000100

I added rb_warn into crc32 to check if the function crc32 in your gem is called.


... snip ...

#include "crc32.h"

unsigned int crc32(unsigned int crc, char *buf, int len) {
    while (len > 0) {
        crc = crc_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
        rb_warn("crc: %d\n", crc);
        --len;
        ++buf;
    }
    return crc;
}

And I ran test.rb with bundler, but I got no warning output by rb_warn.
From this result, maybe crc32 in your gem is not called.

I also ran test.rb without bundler specifying LOAD_PATH explicitly.

$ ruby -I./vendor/bundle/ruby/2.2.0/bundler/gems/bloomfilter-rb-8c9da9516796/ext/cbloomfilter test.rb
m 16
k 1
b 1
test.rb:9: warning: crc: -1529756563

bitmap: 0000000000000100

The waning output came out and I got the same bitmap as that on Mac.

So crc32 seems to be overridden by another library when using bundler on Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions