-
-
Notifications
You must be signed in to change notification settings - Fork 664
define __FUNCTION__ macro
#22241
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
base: master
Are you sure you want to change the base?
define __FUNCTION__ macro
#22241
Conversation
|
Thanks for your pull request and interest in making D better, @Emmankoko! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22241" |
thewilsonator
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about __PRETTY_FUNCTION__. Also tests?
Added! |
compiler/test/runnable/func.c
Outdated
| void foo() | ||
| { | ||
| assert(strcmp(__FUNCTION__, "foo") == 0); | ||
| assert(strcmp(__PRETTY_FUNCTION__, "func.foo") == 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a quick Google search, it seems that gcc would actually print void foo() here, not func.foo. However, since this macro is intended as an informative debug string it probably doesn't matter what it is exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, was easier to use what D already does and not reinventing the wheel.
good to go ?
@thewilsonator @dkorpel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test must be runnable to test the asserts. I suspect it will fail, because in the parser code __FUNCTION__ and __PRETTY_FUNCTION__ are treated identically while the test asserts two different strings are produced.
wait, I think that's true. I just re run printf on |
|
Maybe instead of generating a |
A |
Yes exactly, since C behaves differently than D here it makes sense to give it its own implementation rather than trying to re-use the D implementation. |
okay, latest commit handles the |
|
okay, latest commit handles the FUNCTION well now. the parser treats references to func as a static const char and creates stringexp and stores in a variable and adds to the function body. done in createfuncname. createfuncname was very specific to func and I have now made it general. |
compiler/test/runnable/func.c
Outdated
| void foo() | ||
| { | ||
| assert(strcmp(__FUNCTION__, "foo") == 0); | ||
| //assert(strcmp(__PRETTY_FUNCTION__, "void foo") == 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this test be enabled again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have it working for __FUNCTION__
I am now about to make it work for __PRETTY_FUNCTION__. I just wanted to be sure I was on the right path. That's why pretty function is commended out. I think it will be good if I get pretty function work exactly as it is in C. so I will enable in my next commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enabled
|
@dkorpel I installed a linux VM locally today to check why ubuntu fails and realized ubuntu treats |
|
Your test file is supposed to be testing what you implemented for dmd. How does that give different results on different platforms, are the tests being run with gcc as well? Or is the preprocessor intercepting it? |
I think its because my test is moved to runtime. and That's because they are generated by the systems based on its own implementation and our internally created variable is extern C and so at runtime it picks the system generated version. I printed them at printed them at compile time and they don't change. I run separately with gcc and I get exactly what it is expecting from DMD. only function name for PRETTY_FUNCTION on ubuntu. |
Tried compiling s7 library and
__FUNCTION__was reportedly unresolved.define it as
__func__which literally does the same thing.