www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dmd path handling is a bit dated

reply Laeeth Isharc <laeethnospam nospam.laeeth.com> writes:
DMD path handling is a bit dated, and it's causing build problems 
for us because on Windows it's easy to end up breaking DMD's 
limit - particularly given how dub likes to turn everything into 
a relative path.

Windows has so many beautiful example of the costs of legacy 
compat.  I just wrote down 5 ways it handles paths, and then 
realised there's another.  There's a 260 char limit (less a bit, 
depending) in the old Windows API, but looking at the ddmd code 
there's a more restrictive limit of 131 chars + null for windows 
when it builds paths for the base directory.

I think if you use Windows 32 file namespaces (eg 
\?\C:\D\foo\bar, and note the difference from \?C\D\foo\bar ) and 
the unicode library calls then you get up to 32,767 chars.

We already have much better code in Phobos (for Windows it's 
hard-coded at 4K) getcwd, and I think either we should call 
Phobos or copy/paste the Phobos function into ddmd.

And I'm posting here because we can submit a pull request, but I 
didn't know whether to call Phobos or copy/paste as I haven't 
submitted more than trivial doc changes to compiler.  I've 
written all of this up but on an internal gitlab.

https://github.com/dlang/dmd/blob/2bf9a9d731e88ebd8a175bd0a990a3b651e8df82/src/ddmd/tk/filespec.c
(c) 1986-1987 by NorthWest Software.  It could do with an update!


"
So there's an obvious set of related problems.  Line 119 - 
current working dir is 131 chars + null.  and on linux it's 
restricted to 255+null (not sure if that limit applies anymore to 
linux, but who cares for now).

getcwd prototype is defined here:
https://github.com/dlang/dmd/blob/ebd6606840afea0034ce599815ed950fd558981c/src/ddmd/dmodule.d

and this is the prototype:
extern (C) char* getcwd(char* buffer, size_t maxlen);

it's deprecated and replaced by the ISO function:
https://docs.microsoft.com/en-gb/cpp/c-runtime-library/reference/getcwd-wgetcwd

okay - so:


it's wrong to use that limit on linux and OSX.  Linux PATH_MAX is 
4096.  OpenBSD is 1024.  Linux paths are unlimited, apparently 
(OSX can have several k chars at least).  And the Windows one 
should at least be PATH_MAX less a bit even without using long 
paths. (But then if you are going to use old winapi need to check 
its less than PATH_MAX if you extend).


https://insanecoding.blogspot.co.uk/2007/11/pathmax-simply-isnt.html


on Windows and indeed other operating systems we already have the 
correct code to get current working directory. so we just need to 
update dmd to use this.
https://github.com/dlang/phobos/blob/v2.076.0/std/file.d#L2681
"
Oct 06 2017
next sibling parent Laeeth Isharc <laeethnospam nospam.laeeth.com> writes:
On Friday, 6 October 2017 at 20:11:25 UTC, Laeeth Isharc wrote:
 DMD path handling is a bit dated, and it's causing build
I mean I imagine getcwd and tk/filespec.c might not be the only places that need updating, but I was going to start with those and see what happened.
Oct 06 2017
prev sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Friday, October 06, 2017 20:11:25 Laeeth Isharc via Digitalmars-d-learn 
wrote:
 And I'm posting here because we can submit a pull request, but I
 didn't know whether to call Phobos or copy/paste as I haven't
 submitted more than trivial doc changes to compiler.  I've
 written all of this up but on an internal gitlab.
dmd is not currently allowed to use Phobos, because they don't want that dependency. But it shouldn't be a problem to copy over Phobos' implementation of something where appropriate. - Jonathan M Davis
Oct 06 2017