Skip to content

Conversation

@NeilMonday
Copy link
Contributor

Defining the constexpr DEBUG caused problems when building SNMALLOC into our project. This change simply changes the constexpr's name to SNMALLOC_DEBUG.

@NeilMonday
Copy link
Contributor Author

@microsoft-github-policy-service agree

@microsoft-github-policy-service agree

@mjp41
Copy link
Member

mjp41 commented Jan 8, 2025

@NeilMonday, Could you elaborate a bit more on this. The constexpr is already in a namespace:

snmalloc::DEBUG

Are you including the whole namespace, and then getting conflicts?

@NeilMonday
Copy link
Contributor Author

@NeilMonday, Could you elaborate a bit more on this. The constexpr is already in a namespace:

snmalloc::DEBUG

Are you including the whole namespace, and then getting conflicts?

In my project, I have a preprocessor definition "DEBUG=1" for debug builds. So, I think this is conflicting with the snmalloc::DEBUG even though it is in its own namespace?

@SchrodingerZhu
Copy link
Collaborator

SchrodingerZhu commented Jan 8, 2025

is it possible to use DDEBUG or other prefixed DEBUG macro in your project?

Or use #pragma macro_push to guard around the inclusion of snmalloc header?

@SchrodingerZhu
Copy link
Collaborator

See https://gcc.gnu.org/onlinedocs/gcc/Push_002fPop-Macro-Pragmas.html

@NeilMonday
Copy link
Contributor Author

is it possible to use DDEBUG or other prefixed DEBUG macro in your project? Or use #pragma macro_push to guard around the inclusion of snmalloc header?

Sure, I will look at some alternatives and see what I can do.

@NeilMonday NeilMonday marked this pull request as draft January 8, 2025 14:50
@mjp41
Copy link
Member

mjp41 commented Jan 8, 2025

So at one point I tried to use the convention that

  • constexpr were capitalised, and
  • macros were all caps and preceeded with SNMALLOC_.

So if we did

snmalloc::Debug

Then I would be happy, and I think that would no longer conflict with the pre-processor expansion. That would hopefully fix your issue. It would tidy the code to the unwritten convention.

@NeilMonday
Copy link
Contributor Author

NeilMonday commented Jan 8, 2025

I think snmalloc::Debug would be a great solution. Let me try that now.

While looking online it seems like #define DEBUG is a common thing in some generic C++ examples (even though it isn't a default from msvc or gcc). So it seems like it could happen to someone else in the future.

@NeilMonday NeilMonday force-pushed the debug_name_collision branch from 5d847c1 to d9b6bfd Compare January 8, 2025 15:12
Copy link
Member

@mjp41 mjp41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution @NeilMonday.

@mjp41
Copy link
Member

mjp41 commented Jan 8, 2025

@NeilMonday if you're happy can you mark as "Ready for review" and we'll merge this.

@mjp41
Copy link
Member

mjp41 commented Jan 8, 2025

@SchrodingerZhu thanks for the suggestions. I think it is probably best to avoid DEBUG. If one person has an issue, others will.

@NeilMonday NeilMonday marked this pull request as ready for review January 8, 2025 15:21
@mjp41 mjp41 merged commit 6a3c575 into microsoft:main Jan 8, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants