Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
runtime: inconsistent filename separators between Unix/Windows with runtime.Caller #18151
While writing the test code for another issue (https://go-review.googlesource.com/#/c/33799/), I noticed that filenames defined via //line filename:line directives when returned from runtime.Caller always contained '/' (forward) slashes on Windows, even if the filename in the directive used '\' (backward) slashes. Both these line directives:
return "c:/foo/bar.go" when followed by a runtime.Caller(0) call on Windows. On Unix, the filename reported matches the filename in the directive ( https://play.golang.org/p/7E_bDYfhy4 ).
There's an inconsistency somewhere that should be addressed.
This is purely historical.
All code written in Go always produced file paths delimited by \ and happily accepted paths delimited by both \ and /. But paths read by runtime.Caller are generated by cmd/link, and cmd/link was written in C. Originally cmd/link code was for non-windows paths, like /a/b. Windows is quite OK with these paths, so some people just put drive letter in front, like c:/a/b, and that was that.
It is, probably, quite easy to change cmd/link to use \. I just wonder who will be affected.
referenced this issue
Dec 2, 2016
Seconded. This issue continues to crop up over and over because it is always addressed in a piece meal fashion. Windows can work with forward slashes, so we should just standardise on that everywhere.…
On Fri, 2 Dec 2016, 11:20 Minux Ma ***@***.***> wrote: I still think the right fix is to always use forward-slash '/' consistently on all platforms. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#18151 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAAcA1U0oR1q6Hp_d6b98w-hdF2stXL6ks5rD4B8gaJpZM4LB8Ul> .