Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming clash generated by a macro define in the XML parser #1997

Closed
Foxei opened this issue Jun 4, 2021 · 1 comment · Fixed by #2305
Closed

Naming clash generated by a macro define in the XML parser #1997

Foxei opened this issue Jun 4, 2021 · 1 comment · Fixed by #2305
Labels
bug Issue to report a bug

Comments

@Foxei
Copy link
Contributor

Foxei commented Jun 4, 2021

General Problem

The macro draw defined in the XMLParserCommon.h should be renamed to not replace code of other libraries. #defines do not take into account the namespace in which they were defined. Thus the macro is defined globally. Since it is a very generic name this can lead to problems if your own code or other libraries use the word draw in their code.

Link to the file in question: https://github.com/eProsima/Fast-DDS/blob/master/include/fastrtps/xmlparser/XMLParserCommon.h
Link to a stack overflow discussion about the issue with macros and namespaces: https://stackoverflow.com/questions/1088290/define-statements-within-a-namespace

Known libraries that have a naming clash

  • Gtk 3.0

Suggested solution

Rename the macro so that it follows the structure of the namespaces.

Old Code

namespace eprosima {
namespace fastrtps {
namespace xmlparser {

#define draw(ident, text, ...) for (uint8_t i = ident + 1; i > 0; --i)(i == 1) ? printf(text, ## __VA_ARGS__) : printf( \        "\t")

[...]

New Code

namespace eprosima {
namespace fastrtps {
namespace xmlparser {

#define eprosima_fastrtps_xmlparser_draw(ident, text, ...) for (uint8_t i = ident + 1; i > 0; --i)(i == 1) ? printf(text, ## __VA_ARGS__) : printf( \        "\t")

[...]
@MiguelCompany MiguelCompany added the bug Issue to report a bug label Jun 4, 2021
@MiguelCompany
Copy link
Member

The basic problem here is that macro shouldn't be on a public header.

In fact, I have checked and that macro is not being used, so we could remove it completely.

@MiguelCompany MiguelCompany linked a pull request Nov 3, 2021 that will close this issue
MiguelCompany pushed a commit that referenced this issue Nov 4, 2021
As discussed in issue #1997 this macro was clashing with function from the Gtk3 UI library. As it is not needed it was proposed by MiguelCompany to remove it.

Signed-off-by: Simon Schaefer <simon.schaefer@rwth-aachen.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue to report a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants