GithubHelp home page GithubHelp logo

Comments (4)

cramertj avatar cramertj commented on July 25, 2024

AFAIK, you'll need double-boxing if you want to store unsized data with a single-width pointer. Presumably you're getting the size to dealloc from vtable? I don't believe there's a user-facing way to free an object of a dynamic size, but @dtolnay would know better.

You could still do struct Inner { backtrace: Backtrace, data: Box<Fail> }.

from failure.

withoutboats avatar withoutboats commented on July 25, 2024

AFAIK, you'll need double-boxing if you want to store unsized data with a single-width pointer.

Aren't we essentially going to be leaking the data (because of the bitmasking) and then reconstructing the address of it every time? We can make the second pointer null (and then swap it with the vtable pointer)?

Stuff about how to free the object is a good question, we would probably want to store the size inline.

from failure.

withoutboats avatar withoutboats commented on July 25, 2024

Basically what we're talking about doing is reimplementing dynamic dispatch in unsafe code instead of using real trait objects.

from failure.

withoutboats avatar withoutboats commented on July 25, 2024

This isn't really related but its also about doing unsafe vtable shenanigans:

it would be great to be able to follow the std::error::Error::cause chain to its conclusion instead of just bottoming out at the first non-Fail error we come to. We could do that if we could manufacture a fake vtable somehow.

The Fail vtable has two methods: backtrace (which in the fake one would use the default implementation) and cause. cause is the tricky method. We'd have to call the std::Error::Error::cause method from the original vtable and then perform this very same vtable swap on the result.

No idea how to implement this even if it were possible on stable today.

from failure.

Related Issues (20)

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.