3 ms·
> From the top of my head, Qt (QtPlugin) does C++ ABI plugins This? https://wiki.qt.io/Plugins https://wiki.qt.io/Plugins > provides a bunch of macros that h
by matheusmoreira 4y ago
> From the top of my head, Qt (QtPlugin) does C++ ABI plugins
This?
https://wiki.qt.io/Plugins https://wiki.qt.io/Plugins
> provides a bunch of macros that helps us create the C-function that generates the plugin object
Looks like it uses the C ABI.
> At one point I could even catch C++ exceptions from Java, and viceversa (see gcj).
I'm interested in the details of that. Perhaps the GCJ compiler generated some sort of bridge between the languages?
- flohofwoe 4y agoAs far as I'm aware, the Qt DLLs themselves just expose C++ class APIs directly without going through a C API wrapper, that's why there's a separate Qt SDK for every MSVC version (and all hell breaks loose if you accidentally mismatch DLLs).
- matheusmoreira 4y agoYes, Qt itself is a C++ library. AshamedCaptain was talking about the plugin interface though which is just dynamically loadable modules for Qt applications. I looked it up and those things export C functions that return the C++ objects and meta-object system data.
- AshamedCaptain 4y agoThey export _C++_ functions. You can't return a C++ object from a C function (unless you start making assumptions from the C++ ABI).
- AshamedCaptain 4y ago> looks like it uses the C ABI. Only in the sense that C++ itself "uses the C ABI". This is still C++ ABI; most if not all of the plugin types inherit from C++ classes and there are no code wrappers generated whatsoever (except the usual moc slot unmarshallers if you want to be really picky, but these are not going to be ones you'll be calling). These macros are there for discovery and enumeration/reflection. After you have constructed the root plugin object, you are calling it through the C++ ABI, vtables included (since actually you call it through the base class). > I'm interested in the details of that. Perhaps the GCJ compiler generated some sort of bridge between the languages? The C++ exception/"personality" ABI is kind of designed for this, which is one of the reasons it may appear complex and/or slow. Just search for gcj exceptions for examples.
- matheusmoreira 4y ago> Only in the sense that C++ itself "uses the C ABI" Not at all. Qt literally uses the C ABI as a protocol for plugins. I have no doubt they chose it because it's the only inferface simple and stable enough for the task. It is relatively simple and stable precisely because there are zero C++ features involved. I thought that alone was damning enough so I didn't elaborate further. What you said is absolutely true: the objects returned by those C functions are accessed by the real C++ ABI with vtables and everything. That's a massive problem and they shouldn't have been designed this way. Look at the mess this causes: https://forum.qt.io/topic/119767/qt-plugin-fixing-c-abi-problems-with-external-c https://forum.qt.io/topic/119767/qt-plugin-fixing-c-abi-prob... > I know that C++ don't have Aplication Binary Interface - ABI compatibility between compilers (example: MSVC, MingW, Clang and ICC). > Besides that, the C++ ABI compatibility can be broken even using the same compiler with different version (example: MSVC 2003 and MSVC 2019). > Example: If the main C++ application was compiled using MSVC 2003, all plugin developers MUST HAVE and MUST USE the exactly same compiler to build your projects, in this case MSVC 2003. Which is not good. > Looking in the internet I found a way to fix that: Creating a C Wrapper of my C++ Interface Abstract Class. The solution is, of course, to get rid of all this C++ business and restrict yourself to the C ABI. This is apparently the fate of every ABI that isn't C. When even that is annoying enough to deal with, nobody is ever going to want to deal with anything more complex.
- AshamedCaptain 4y agoI don't understand this point. You say "Qt uses the C ABI for plugins", then immediately claim that "because they use the real C++ ABI with vtables and everything" it is a "massive problem" that shouldn't have been designed this way. First, Qt is using the C++ ABI, even for dynamically loaded plugins. This much should be obvious: it is calling C++ methods through a C++ abstract base class, passing C++ objects as arguments, on which C++ methods are going to be invoked. How is this not the C++ ABI? The one thing that may be confusing is that one uses C APIs (dl, etc.) for discovery, but this is because C++ _is_ using the C ABI. C++ symbols are in the platform executable format's symbol table, after all. How is one going to export and GetProcAddress a plugin object factory method in C++? Second, it is not really a "massive problem": it simply works, and it is used by Qt itself for critical functionality such as the image format loaders (which I think people would rather notice if they were not working). The usual MSVC++ stuff you mention applies for _all_ Windows based development (even C! you are not supposed to mix MSVCRT versions in Windows!), and specifically applies for _linking to Qt itself_. Why would it now become an issue for plugins, which obviously must all link to a compatible version of Qt? Ensuring one uses the same version of the MSVC compiler is not so different as ensuring the use of the same version of MSVC that was used to build Qt, or even to use the same version of Qt for the base and gui libraries... There is really not that many more issues with the C++ ABI than with the C ABI; they are more visible because people tend to use & expose more of the C++ ABI. E.g. it is rather unlikely to pass FILE objects to libraries, while it is rather common to pass std::string objects. If you send to a module with a different ABI, you are going to crash (if you are lucky enough).