Leverage std::string_view overloads in pugixml 1.15#253
Conversation
|
Thanks! |
Hi! @cboulay Thank you for your review. I am trying to fix the CI failures. |
|
I have fixed the compilation error on Ubuntu. Specifically, this error occurs when liblsl/.github/workflows/cppcmake.yml Line 43 in 63741a9 pugixml 1.15 added std::string overloads (in fact, std::string_view) for some APIs, but older versions of pugixml do not support them. When liblsl is built against a non-bundled pugixml prior to 1.15, these issues arise. Therefore, to use the new overloads while remaining compatible with older pugixml versions, it is necessary to check whether the https://github.com/zeux/pugixml/blob/v1.15/src/pugixml.hpp#L445-L447 |
|
We can see in #254 that the Apple actions runners pass. The issue is either due to rebasing on some recent change I made or because only my commits can access the secrets. Either way, this PR will pass the tests. |
There was a problem hiding this comment.
Pull request overview
This PR updates the codebase to leverage the new std::string_view overloads introduced in pugixml 1.15. The changes remove unnecessary c_str() calls when passing std::string values to pugixml methods, using conditional compilation to maintain backward compatibility with older versions.
Changes:
- Added conditional compilation blocks using
PUGIXML_HAS_STRING_VIEWto distinguish between new and legacy pugixml versions - Removed redundant
c_str()calls when the new string_view overloads are available - Updated multiple setter functions and a template specialization to use the cleaner API
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| template <> void append_text_node(xml_node &node, const char *name, const std::string &value) { | ||
| #if defined(PUGIXML_HAS_STRING_VIEW) | ||
| node.append_child(name).append_child(node_pcdata).set_value(value); | ||
| #else | ||
| node.append_child(name).append_child(node_pcdata).set_value(value.c_str()); | ||
| #endif | ||
| } | ||
|
|
There was a problem hiding this comment.
The code has significant duplication across multiple functions with identical conditional compilation patterns. Consider creating a wrapper function or macro to eliminate this repetition and improve maintainability.
| template <> void append_text_node(xml_node &node, const char *name, const std::string &value) { | |
| #if defined(PUGIXML_HAS_STRING_VIEW) | |
| node.append_child(name).append_child(node_pcdata).set_value(value); | |
| #else | |
| node.append_child(name).append_child(node_pcdata).set_value(value.c_str()); | |
| #endif | |
| } | |
| namespace { | |
| inline void set_node_value_from_string(xml_node &node, const std::string &value) { | |
| #if defined(PUGIXML_HAS_STRING_VIEW) | |
| node.set_value(value); | |
| #else | |
| node.set_value(value.c_str()); | |
| #endif | |
| } | |
| } | |
| template <> void append_text_node(xml_node &node, const char *name, const std::string &value) { | |
| xml_node child = node.append_child(name).append_child(node_pcdata); | |
| set_node_value_from_string(child, value); | |
| } |
|
Thanks for this PR! I think the copilot bot missed something... (Or we could just use #254 where I made this change.) |
|
Sorry, I'm multitasking (debugging some noise issues in the lab) and completely missed / forgot about your comment:
I'll see if I can update the dependency and/or not rely on system pugixml. I'll need a bit of time to look into that. |
|
OK we can leave the #ifdef in here for now. However, that requires some more configuration -- static linking? make sure we hide all the pugixml symbols to not conflict, etc. It's well beyond the scope of this PR. I'm satisfied with this as is. I'll merge it in this evening or tomorrow. |
|
Hi! @cboulay Thank you for your review. Currently, the versions of pugixml available across various Linux distributions and package managers. Once pugixml 1.15 is everywhere, we can remove the |
|
That's pretty cool! How did you generate those images? 1.17 came out like a week ago so I expect it will take some time to propagate to these other distribution channels (that I have no control over). |
|
|
Hi! @cboulay Do you like the idea of adding a packaging status badge to liblsl? Here is a preview of how it would look: https://github.com/myd7349/liblsl/tree/update-readme This would make it easy for maintainers and users to see which package managers provide liblsl and which versions are available. The badge would also be updated automatically. |
Remove unnecessary c_str() calls and rely on the new std::string overloads introduced in pugixml 1.15.
Close #247