Turn globals.argv0 into a DArray#8575
Conversation
|
Thanks for your pull request and interest in making D better, @Geod24! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour 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 locallyIf 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#8575" |
1400745 to
5e9fe05
Compare
src/dmd/mars.d
Outdated
| extern(C) void printGlobalConfigs(FILE* stream) | ||
| { | ||
| stream.fprintf("binary %s\n", global.params.argv0); | ||
| stream.fprintf("binary %*s\n", global.params.argv0.length, global.params.argv0.ptr); |
There was a problem hiding this comment.
%.*s - if memory serves me right.
da80538 to
71e023f
Compare
ibuclaw
left a comment
There was a problem hiding this comment.
Is github loosing my reviews?
Answer, yes. This is twice now I've written something and it's gone. |
eef083e to
dcd7960
Compare
I experienced that yesterday as well; started questioning my sanity. |
src/dmd/frontend.d
Outdated
| import std.string : fromStringz, toStringz; | ||
|
|
||
| auto f = findConfFile(dmdFilePath.toStringz, "dmd.conf"); | ||
| auto f = findConfFile(dmdFilePath.toStringz[0 .. dmdFilePath.length], "dmd.conf"); |
There was a problem hiding this comment.
This is converted to a C string then back to a D string. Am I missing something?
There was a problem hiding this comment.
It was a leftover. findConfFile was still dependent on \0 termination, as one of the function was not converted to const(char)[]. I converted it and now \0 termination isn't required anymore.
15a277c to
13a29aa
Compare
Those are somewhat connected and not worth the hassle of breaking down this commit.
|
This finally passes and is ready for review |
src/dmd/frontend.d
Outdated
| return null; | ||
|
|
||
| return f.fromStringz.idup; | ||
| return f.idup; |
There was a problem hiding this comment.
You can idup a string that is null, which will save you the if statement.
There was a problem hiding this comment.
diff --git a/src/dmd/frontend.d b/src/dmd/frontend.d
index 93c5a8a94..9ae64a51a 100644
--- a/src/dmd/frontend.d
+++ b/src/dmd/frontend.d
@@ -79,11 +79,7 @@ string findDMDConfig(const(char)[] dmdFilePath)
import dmd.dinifile : findConfFile;
import std.string : fromStringz, toStringz;
- auto f = findConfFile(dmdFilePath, "dmd.conf");
- if (f is null)
- return null;
-
- return f.idup;
+ return findConfFile(dmdFilePath, "dmd.conf").idup;
}
/**Updated thanks
| Strings* paths = FileName.splitPath(getenv("PATH")); | ||
| if (auto p = FileName.searchPath(paths, "link.exe", false)) | ||
| return p; | ||
| if (auto p = FileName.searchPath(paths, "link.exe"[], false)) |
There was a problem hiding this comment.
Why is this slice needed?
There was a problem hiding this comment.
Otherwise the call is ambiguous, since we have a const(char)* and a const(char)[] overload, and manifest constant convert to both.
In a later PR (because this is already quite big) I'll remove the const(char)* overload
This is more of a proof of concept for future conversion. Here's a few principles used to do the conversion from `T*` to `T[]`: - If it's a string, the character at `s[$]` must be `'\0'`. It allows code to freely go back and forth between `char*` and `char[]`. - Move the implementation to extern(D) and slices, and provide C++ wrapper. - Stay on topic: those changes only focus on one parameter / module / function, because it's very easy to end up with a giant change that doesn't work. - If `'\0'` termination is required (e.g. calling a C function), changing from `char*` to `char[]` should can be done using `toCStringThen`.
| } | ||
|
|
||
| /// Ditto | ||
| extern (D) static int exists(const(char)[] name) |
There was a problem hiding this comment.
Should probably return an enum instead of an int, but that might be something for a separate PR.
| { | ||
| import core.sys.posix.stdlib: realpath, free; | ||
| auto absPath = realpath(fileName, null /* realpath allocates */); | ||
| char* absPath = fileName.toCStringThen!((fn) => realpath(&fn[0], null /* realpath allocates */)); |
There was a problem hiding this comment.
It is freed later, so I'd have to cast away the const.
|
This causes a regression : https://issues.dlang.org/show_bug.cgi?id=19510. |
|
EDIT: Or not, since you submitted #9142 |
|
BTW, sorry since i discovered that your not responsible for the regression. It's more a Windows API call that was not used correctly... the problem was only revealed by your changes. |
This is a step towards converting
globalsto use D array.There is currently no way to call a function accepting a D string from C++ (thanks to ABI issues on i386 / Win64) but it does not matter for
globalsAFAICS.So I resorted to providing trivial C++ wrapper to the D functions, and gradually removing the wrapper as they become unused, as can be seen in filename.