libgolang: Expose defer as public C++ API
Libgolang, since 3b241983 (Port/move channels to C/C++/Pyx), already had defer macro implemented and used, but only internally. The reason it was not yet exposed as public API is that there is a difference with Go's defer in that deferred function is called at end of current scope instead of end of current function, and I was a bit reluctant to expose defer with different-than-Go semantic. However even with this difference defer is useful, and the difference can be documented. Unfortunately it is not easy to correctly fix the difference, so the most practical way for now is to expose defer as it is. I've also contemplated how to avoid using macro, but without a macro, users will have to explicitly declare placeholder variable for every defer call which goes against usability. Since defer is exposed as macro, I've also contemplated to expose it as something like `libgolang_defer` with the idea to avoid name conflicts, and so that users - that are using defer - will be doing `#define defer libgolang_defer`. However I ended up not doing that and exposing `defer` macro with its own name. My rationale is: - grepping /usr/include/ for \<defer\> on my system did not showed any real usage. - Qt also #defines `slots` and `signals` and that does not cause problems in practice. -> expose `defer` macro into public C++ API as is, so that it can be used not only inside libgolang.cpp . For example I myself need defer functionality in C++ part of wendelin.core.
Showing
Please register or sign in to comment