Comments (16)
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.
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.
No, static linking via C API in rust is very troublesome. You should always use dynamic one.
from ttf-parser.
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.
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.
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.
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.
avoid panics from the beginning
It's one of the goals. But it will take a lot of time. Weeks.
from ttf-parser.
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.
Yes, no_std no possible due to
std::panic::catch_unwind
. So meson should be changed tocdylib
.
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.
@notgull can you elaborate?
from ttf-parser.
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.
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.
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.
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.
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)
- Making some internal fields public and allow serialisation of the OwnedFace type. HOT 9
- f32 has too little precision for offsets HOT 3
- When parsing a regular font (not a collection) the index is ignored HOT 4
- C-api in rust 32-bit environment,Test case call failed
- Zero offsets in `parse_at_offset16` HOT 17
- Add essential links to README HOT 2
- Question about parser.rs HOT 2
- Can you add an example of how to create a simple letter and save as a font? HOT 3
- Serde feature HOT 1
- The direction of outline contour? HOT 3
- how to get a variable instance of a variable font HOT 2
- Support woff2 HOT 1
- Does it support monochrome fonts HOT 1
- parse_char_string_width does not take subroutines into account HOT 6
- Support GDEF Ligature Caret List Table HOT 3
- Getting the number of faces HOT 15
- font_collection_num_fonts_overflow test fails on 32-bit architectures HOT 3
- Missing instance records in fvar::Table HOT 3
- Face::set_variation change in behaviour HOT 1
- Request for Addition of an Interface to Extract Basic Font Information from Files to Support Directory Scan of All Fonts for Rendering Unicode Text HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ttf-parser.