Skip to content

Conversation

@ibuclaw
Copy link
Member

@ibuclaw ibuclaw commented Jan 13, 2019

For Posix platforms, canonicalName relies on that most libc implementations return an internally malloc'd buffer for us when passing realpath a null destination pointer.

However, the specification does not guarantee this, and broken behaviour is observed on some platforms, such as Solaris.

Always providing a buffer is the only way to ensure that calling realpath is consistent across platforms.

See dlang/druntime#2460 for PR that adds PATH_MAX to druntime.

Each static path has been tested for correctness on Linux 64bit using glibc.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ibuclaw!

Bugzilla references

Your 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 locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#9261"

For Posix platforms, canonicalName relies on that most libc
implementations return an internally malloc'd buffer for us when passing
realpath a null destination pointer.

However, the specification does not guarantee this, and broken behaviour
is observed on some platforms, such as Solaris.

Always providing a buffer is the only way to ensure that calling
realpath is consistent across platforms.
@dlang-bot dlang-bot merged commit 64ed602 into dlang:master Jan 14, 2019
// unless there is nothing to copy from.
if (!name.length)
return null;
return mem.xstrdup(name.ptr)[0 .. name.length];
Copy link
Member

Choose a reason for hiding this comment

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

Why not a static assert instead of doing nothing ? It does not look like a good default behavior and might be hard to track.

Copy link
Member Author

@ibuclaw ibuclaw Jan 14, 2019

Choose a reason for hiding this comment

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

Just returning null would mean nothing would compile. We already have the relative paths to druntime and phobos, let the compiler use them instead of erroring that it can't find any sources.

import core.sys.posix.stdlib: free;
auto absPath = FileName.canonicalName(fileName);
scope(exit) free(cast(void*)absPath.ptr);
return F(cast(char[])absPath);
Copy link
Member

Choose a reason for hiding this comment

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

It would be simpler just to swap lines 1130 and 1131:

F(..)
free(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

If this was a void function, then I'd agree.

@ibuclaw ibuclaw deleted the realpathbug branch January 14, 2019 07:56
@jondegenhardt
Copy link

@ibuclaw I'm not sure, but this PR may be the cause of this regression: https://issues.dlang.org/show_bug.cgi?id=19684. Summary: In 2.085.0-beta.1 DMD can no longer find dmd.conf located in the same directory as the executable if dmd is invoked through a symlink. This is on OS X.

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 19, 2019

@jondegenhardt - could you bisect or confirm with a static assert(0) in the fallback case?

@jondegenhardt
Copy link

@ibuclaw - It'll be a day before I can try to do any debugging. Sorry I can't be more definitive about whether this PR is the cause. It seemed the mostly likely of all the PRs that went into the 2.085 release.

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 19, 2019

OK. If there's any problem, it may be to do with the version of dmd used to build 2.085. The static paths work just fine, but the conditions may evaluate to false if druntime is too old.

The release binaries for 2.085 should be bootstrapped from 2.085 itself, otherwise I'd argue that dmd maintainers are doing something wrong.

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 19, 2019

On OSX, druntime 2.085 defines PATH_MAX (prior versions didn't).

There is no definition for _PC_PATH_MAX for OSX in druntime at all (this would be a bug in the OSX port).

@wilzbach
Copy link
Contributor

The release binaries for 2.085 should be bootstrapped from 2.085 itself, otherwise I'd argue that dmd maintainers are doing something wrong.

Currently the latest stable release (e.g. 2.084.1) is used to build DMD and as we will hopefully eventually build the shipped binaries with LDC this assumption won't hold in this future either.

@ibuclaw
Copy link
Member Author

ibuclaw commented Feb 20, 2019

Currently the latest stable release (e.g. 2.084.1) is used to build DMD and as we will hopefully eventually build the shipped binaries with LDC this assumption won't hold in this future either.

Building with LDC won't fix the problem Jon found if I understood what's going on correctly.

@jacob-carlborg
Copy link
Contributor

Building with LDC won't fix the problem Jon found if I understood what's going on correctly.

No, building with LDC would be to get better performance. I'm pretty sure that if/when LDC is used they will have caught up with the 2.085.0 fronted version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants