Git Product home page Git Product logo

Comments (4)

al8n avatar al8n commented on June 3, 2024 1

Thanks for reporting! Fixed in 0.2.5.

from caches-rs.

wfraser avatar wfraser commented on June 3, 2024

Probably the simplest fix is to just:

diff --git a/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs b/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs
index c9485f6d2f3a1..ca73e069ed8e4 100644
--- a/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs
+++ b/rust/vendor/caches-0.2.3/src/lfu/tinylfu/bloom.rs
@@ -96,7 +96,9 @@ impl Bloom {
         let offset = ((idx % 64) >> 3) as u64;
         let ptr = (raw + offset) as *mut u64;
         unsafe {
-            *ptr |= MASK[idx % 8] as u64;
+            ptr.write_unaligned(ptr.read_unaligned() | MASK[idx % 8] as u64);
         }
     }

@@ -106,7 +108,7 @@ impl Bloom {
         let offset = ((idx % 64) >> 3) as u64;
         let ptr = (raw + offset) as *mut u64;
         unsafe {
-            let r = (*ptr >> (idx % 8)) & 1;
+            let r = (ptr.read_unaligned() >> (idx % 8)) & 1;
             r == 1
         }
     }

also note, the tests in bloom.rs are currently broken, but I commented out the last 3 and it passes with this change.

from caches-rs.

wfraser avatar wfraser commented on June 3, 2024

Thanks! Amazing quick fix!

Just one small question: the 0.2.5 release seems to have also added a dependency on getrandom (which also pulls in more deps), but I don't see this being used anywhere in the code. Is this something that can be removed?

from caches-rs.

al8n avatar al8n commented on June 3, 2024

Thanks! Amazing quick fix!

Just one small question: the 0.2.5 release seems to have also added a dependency on getrandom (which also pulls in more deps), but I don't see this being used anywhere in the code. Is this something that can be removed?

Ah, It is a feature gate for supporting the target wasm32 family (rand requires). It should only be compiled for wasm family targets.

from caches-rs.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.