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

Passing alias this with function returning chain to tempCString hangs up the program #9782

Open
dlangBugzillaToGithub opened this issue Oct 21, 2019 · 3 comments
Labels
Arch:x86_64 Issues specific to x86_64 OS:Linux Issues specific to Linux Severity:Major

Comments

@dlangBugzillaToGithub
Copy link

d.bugs reported this on 2019-10-21T10:55:33Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20309

CC List

Description

The following minimal test case will result in a binary which hangs up:

import std.range : chain;
import std.internal.cstring : tempCString;

struct Test {
    auto filename() const { return chain("a", "b"); }
    alias filename this;
}

void main() {
    auto name = Test();
    auto namez = name.tempCString!char();
    // should return fine or crash if doesn't exist, but not hang
}

See https://run.dlang.io/is/8AlJO5

This is a bug because with `name.filename.tempCString!char()` it works fine, so it has an issue with the alias this on that range.

This causes calls to the std.file functions like isFile or getAttributes to hang up if called with a struct like this.

This only happens when it is indirected via an alias this on the argument which is passed.

Another test to test it with public APIs: `std.file.getAttributes(Test())`
@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2019-12-08T09:50:30Z

Reduced example:

```
import std.stdio;
import std.range : chain;

struct Test 
{
    auto filename() const { return chain("a", "b"); }
    alias filename this;
}

void main() 
{
    auto name = Test();
    writeln(name.front);
    name.popFront();
    writeln(name.front);
}
```

name.front and name.popFront always call filename(), which returns a new range object... This is IMHO not a phobos bug.

@dlangBugzillaToGithub
Copy link
Author

d.bugs commented on 2019-12-08T12:46:26Z

you are right, it makes sense that it creates a new object for each instantiation. However this would mean that maybe the isInputRange check or whatever tempCString and others are using, should not allow such a construct which always returns a new instance

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2019-12-08T13:11:36Z

IMHO this is a problem burried deep into alias this. My solution would be, to remove alias this completely. Creates a lot of problems...

@LightBender LightBender removed the P2 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86_64 Issues specific to x86_64 OS:Linux Issues specific to Linux Severity:Major
Projects
None yet
Development

No branches or pull requests

2 participants