Live data from Hacker News

Rust for Filesystems

lwn.net

201–206 of 206 posts

Re: Rust for Filesystems

#201

Earlier quoted context omitted.

> Even if they're the same calling convention, that should fail, but it doesn't. It's an interesting question. According to the standard, functions with different language linkage are indeed considered different types. As a consequence, should declare two overloads for qsort() that only differ in the type of the sort function. However, modern compilers don't seem to care: "The only modern compiler that differentiates…

As long as I can't silently get wrong behavior or runtime crashes, I'm happy enough. Is it guaranteed that an incorrect calling convention will always cause a compiler error? I wasn't aware the calling convention was considered part of the pointer type. Anyway, thanks for engaging with me so earnestly. I guess I had some assumptions about calling conventions that needed to be straightened out, which is important, as…

> Is it guaranteed that an incorrect calling convention will always cause a compiler error?

A standard-conforming C++ compiler must not allow implicit pointer casts, so yes!

> I wasn't aware the calling convention was considered part of the pointer type.

Some well-designed C APIs define a macro for the calling convention that they add to all API functions and function pointer declarations. The user can then use the same macro when supplying their callbacks, which guarantees that the calling conventions match. (On modern platforms, the macro would be typically empty.)

Here's an example: https://github.com/Celemony/ARA_API/blob/1f68fba7a374b14df19.... As you can see, it is part of the function pointer type: https://github.com/Celemony/ARA_API/blob/1f68fba7a374b14df19...

Another famous example is, of course, the WINAPI macro in the Win32 API.

That's also what I tend to do with my own C APIs.

> I guess I had some assumptions about calling conventions that needed to be straightened out

I also learned a few things in this discussion, so thanks for that!

Re: Rust for Filesystems

#202
post #189
post #177

Earlier quoted context omitted.

Now imagine a hundred or two functions, structures and callbacks, some of them exposed only as CPP macros over internal implementation. PJSIP low level API is one example.

But... that's what bindgen is for. Which I mentioned. I said it "can be quite simple"; for simple use cases, just using extern and translating the declarations by hand is perfectly viable. For more complex cases, you use bindgen.

Bindings generators exist in most other languages with same limitations.

I would love to see how bindgen would handle a function call defined as a preprocessor macro that I mentioned. Because most likely it won't.

Re: Rust for Filesystems

#203
post #166

Earlier quoted context omitted.

How well does it handle preprocessor macros in APIs?

I have used it successfully against header files for Win32 COM interfaces generated from IDL which include major parts of the infamous "windows.h". Almost every type is a macro. This is an extremely well-understood space. Just open the docs and do it.

Not types, functions. Where the macro is essentially a forward declaration but the implementation is deep inside the code and is not exposed via headers.

Re: Rust for Filesystems

#205
post #86

Earlier quoted context omitted.

Hmmm. Is this serious or facetious? Or could be either, depending on the response? There already is rust code in the Linux kernel (some drivers), afaik.

Someone's gotta get the word out, I'm seriously sick of all these ridiculous LARPers trying to magic Rust into existence Rust is a joke, it's a complete waste of time and effort to try and use it. It's the EU cookie law of native code - well-intentioned nonsense that doesn't work at all in reality

> ... trying to magic Rust into existence

What do you mean? Rust does not exist? No useful projects have been built in it?

Re: Rust for Filesystems

#206
post #205

Earlier quoted context omitted.

Someone's gotta get the word out, I'm seriously sick of all these ridiculous LARPers trying to magic Rust into existence Rust is a joke, it's a complete waste of time and effort to try and use it. It's the EU cookie law of native code - well-intentioned nonsense that doesn't work at all in reality

> ... trying to magic Rust into existence What do you mean? Rust does not exist? No useful projects have been built in it?

That is what they mean. It’s contrary to the actual reality, where Rust is already being used for real, important things.
Post reply on HN