Giter VIP home page Giter VIP logo

Comments (16)

RazrFalcon avatar RazrFalcon commented on May 23, 2024

can c-api also become no_std

Not sure if it's possible. Will take a look.

You should use dynamic linking. Static linking is kinda broken in Rust. At least for me. That's why c-api doesn't build static at all. I guess it should be fixed in meson too.

from ttf-parser.

ebraminio avatar ebraminio commented on May 23, 2024

Not sure if it's possible. Will take a look.

Thank you so much. I will also.

You should use dynamic linking. Static linking is kinda broken in Rust. At least for me. That's why c-api doesn't build static at all. I guess it should be fixed in meson too.

Apparently I were able to somehow maybe at some limited cases, static linking is very convenient, am imagining some C library embeds a rust library and itself can be static linked to another library easily.

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on May 23, 2024

No, static linking via C API in rust is very troublesome. You should always use dynamic one.

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on May 23, 2024

Yes, no_std no possible due to std::panic::catch_unwind. So meson should be changed to cdylib.

Afaik, the problem with static linking is that rust links its own std with specific system libraries, which can cause conflicts during linking.

Personally, I always use dynamic linking for C API.

from ttf-parser.

ebraminio avatar ebraminio commented on May 23, 2024

Rust claims able to run on bare metal hardware but doesn't support static linking a c-api, that's very unfortunate :/ I wished it had some solution, maybe we should bring this to the rust development community and maybe I'm getting it also as a dylib also and I'm unaware of it?

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on May 23, 2024

It does support static linking. The problem is that you have to provide required libraries manually. pthread in your case.

dylib is a Rust dynamic library. You need cdylib, which is a C dynamic library.

from ttf-parser.

ebraminio avatar ebraminio commented on May 23, 2024

Oh I see, so its use is on catch_unwind, This method invokes a lot of parsing, so let's catch any panics just in case., is there someway to avoid panics from the beginning somehow? And is there anything worth to investigate? rust-lang/rfcs#2810 is related I guess.

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on May 23, 2024

avoid panics from the beginning

It's one of the goals. But it will take a lot of time. Weeks.

from ttf-parser.

ebraminio avatar ebraminio commented on May 23, 2024

It's one of the goals. But it will take a lot of time. Weeks.

Thank you so much, so there is a hope which is great! I will also try so to improve my Rust experience. Thanks

from ttf-parser.

notgull avatar notgull commented on May 23, 2024

Yes, no_std no possible due to std::panic::catch_unwind. So meson should be changed to cdylib.

As an alternative to catch_unwind, you can use a drop-then-abort guard to prevent panics from unwinding into other code. This is no_std.

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on May 23, 2024

@notgull can you elaborate?

from ttf-parser.

staticintlucas avatar staticintlucas commented on May 23, 2024

I think what he means is something like:

struct DropAbortGuard;

impl DropAbortGuard {
    fn new() -> Self {
        Self
    }
    
    fn end(self) {
        core::mem::forget(self); // Ensures drop doesn't run for self
    }
}

impl Drop for DropAbortGuard {
    fn drop(&mut self) {
        panic!(); // Panic while panicing becomes an abort
    }
}

let guard = DropAbortGuard::new();

some_code_that_might_panic();

guard.end();

It's not pretty, but it seems to work.

from ttf-parser.

notgull avatar notgull commented on May 23, 2024

Yeah, you can find an example of this pattern here. Since you don't expect the code to panic anyways it should be a good fit

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on May 23, 2024

Hmm... it simply replaces panic with abort, which is not what I want.
The whole point behind using catch_unwind is that I cannot statically prove that ttf-parser will not panic. Sadly, this is the current Rust limitation. We need language-level #[no-panic] attribute first.

from ttf-parser.

notgull avatar notgull commented on May 23, 2024

Hmm... it simply replaces panic with abort, which is not what I want.

Are you sure? In your README, you say that any panic is a critical bug. Therefore, I would think that replacing the panic with an snort would be the best option, since unwinding into the C stack frames is unsound behavior.

In fact, I'd say that wrapping every C API function in an abort guard like this is required for soundness. While, in theory, many of the function you use don't panic, there may be devils hidden in those details, and a core dump is preferable to corrupting the stack.

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on May 23, 2024

I threat every function as panicking in Rust. Which is true until we get #[no-panic].

In your README, you say that any panic is a critical bug.

It doesn't mean that there are no panics in ttf-parser. ttf-parser is like 15 KLOC. I cannot guarantee anything at this scale.

from ttf-parser.

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.