-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
Work On Issue 18172 - add scope to pointers in getopt to allow @safe #6281
Conversation
Thanks for your pull request, @JackStouffer! Bugzilla references
|
@@ -459,6 +459,19 @@ GetoptResult getopt(T...)(ref string[] args, T opts) | |||
} | |||
} | |||
|
|||
version(DIP1000) |
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'm not sure how we want to handle DIP1000 regressions, but we need a way to ensure things stay @safe
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.
By #6278 and thus gradually enabling -dip1000?
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.
But this unittest
needs to be annotated with @safe
when -dip1000
is passed and @system
when it's not to prevent any DIP1000 regressions. #6278 Doesn't have a mechanism for that.
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.
Argh fair enough - there still might be issues as long as -deps
compiles all unittests of its dependencies :/
Anyhow, for the time being #6278 (or similar could set DIP1000
by hand).
std/getopt.d
Outdated
{ | ||
// allocate a new string so as to remove the | ||
// scope restriction | ||
string option = "" ~ opts[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.
this is due to the fact that to!(string)(string)
acts as a pass through.
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.
.idup?
aa2b739
to
23e191e
Compare
static if (is(typeof(opts[0]) == string)) | ||
{ | ||
// allocate a new string so as to remove the | ||
// scope restriction |
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.
That really sucks. Safety shouldn't result in a performance overhead :/
Especially because in this case
getoptImpl
doesn't store anything, but modifiesconfiguration
andrslt
- it's a GC allocated string
Here's an idea how to programmatically detect void main()
{
enum isDIP1000 = __traits(compiles, () @safe {
int x;
int* p;
p = &x;
});
pragma(msg, isDIP1000);
} normal: https://run.dlang.io/is/RID7vh Of course that could be fancier. (based on the recent forum thread: https://forum.dlang.org/post/ayemvxctmpqqsokbmqeb@forum.dlang.org) |
If people want to tackle the DIP1000 returning a struct issue, I'd be glad to see their solution. Until then, I'm closing this as this isn't going to go anywhere. |
No description provided.