Re: How to modify process environment variables
Ky-Anh Huynh wrote: Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive: http://man7.org/linux/man-pages/man3/putenv.3.html (FIXME) I come to this question as I want to set some custom variables for my unittests. My program reads some tokens from system environments, and it's convenient if I can simulate different cases for testings. Thanks for your reading and support. you can use libc's `putenv()` in D too, it is ok. just import `core.sys.posix.stdlib`, it is there. D is not antagonistic to C, and doesn't try to replace the whole libc with it's own libraries. so if you see something that libc has and you'd like to use -- just do it! ;-)
How to modify process environment variables
Hi, Is it possible to change the current process's environment variables? I have looked at `std/process.d` source code, and there is only a private method `createEnv` used when new (sub)process is created. In C `putEnv` the answer is positive: http://man7.org/linux/man-pages/man3/putenv.3.html (FIXME) I come to this question as I want to set some custom variables for my unittests. My program reads some tokens from system environments, and it's convenient if I can simulate different cases for testings. Thanks for your reading and support.
Re: Tango + D2 + Mac
On Tuesday, 17 October 2017 at 03:25:53 UTC, Neia Neutuladh wrote: I take it you're using https://github.com/SiegeLord/Tango-D2 ? I tried it out about a year ago and it worked, but your mileage may vary. For the most part, Phobos and various Dub packages have superseded it. Tango's main benefit was that it was code that was well maintained over the course of several years, and that's no longer true. Yeah I tried installing Tango-D2 but the installation page is throwing me off... too many steps that don't work for me. Do you by any chance know anything that replaced std.xml? Everything I look up on it suggests not to use it.
Re: Tango + D2 + Mac
On Tuesday, 17 October 2017 at 02:52:41 UTC, Fat_Umpalumpa wrote: I am having a lot of trouble trying to install Tango to use with D2 on my mac os Sierra. Is this even possible? Thanks! I take it you're using https://github.com/SiegeLord/Tango-D2 ? I tried it out about a year ago and it worked, but your mileage may vary. For the most part, Phobos and various Dub packages have superseded it. Tango's main benefit was that it was code that was well maintained over the course of several years, and that's no longer true.
Re: debugging in vs code on Windows
On Tuesday, 17 October 2017 at 02:32:49 UTC, Domain wrote: Can you share your tasks.json and launch.json? tasks.json - I don't have this file. launch.json: { "version": "0.2.0", "configurations": [ { "name": "(Windows) Launch", "type": "cppvsdbg", "request": "launch", "program": "${workspaceRoot}\\parser.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true } ] } Also I have changed preferences: "debug.allowBreakpointsEverywhere": true, Status bar: x86_64 debug dmd
Tango + D2 + Mac
I am having a lot of trouble trying to install Tango to use with D2 on my mac os Sierra. Is this even possible? Thanks!
Re: debugging in vs code on Windows
On Sunday, 15 October 2017 at 13:54:49 UTC, Dmitry wrote: On Friday, 13 October 2017 at 12:55:09 UTC, piotrklos wrote: Has anyone been able to debug in VS code on Windows? What am I doing wrong? Yep, it work for me. How do you start debugging? I noticed that the bottom button (small bug) at status bar doesn't work for me. But when I use Debug → Start Debugging (F5), it works. Can you share your tasks.json and launch.json?
partiallyQualifiedName?
using fullyQualifiedName [here] (https://github.com/libmir/dcompute/blob/master/source/dcompute/driver/ocl/util.d#L120) leads to a large compilation slowdown, but I only need it to disambiguate up to the module level i.e. so that struct Context { enum Properties {} static struct Info { @(0) Properties p; // <--- } } ... partiallyQualifiedName!p ... resolves to Context.Properties instead of dcompute.driver.ocl.context.Context.Properties, thus avoiding many template instantiations. Alas typeof(p).stringof, which yields Properties, errors "No such identifier Properties" (and subsequently crashes the CTFE engine). I tried looking at the fullyQualifiedName but got lost pretty quick. Thanks Nic
Re: How do I convert a LPVOID (void*) to string?
On Monday, 16 October 2017 at 21:48:35 UTC, Nieto wrote: How do I convert/create a D string from LPVOID (void*)? There is no one answer to this, but for the specific function are are looking at, the ALLOCATE_BUFFER argument means it puts the pointer in the pointer. So the way I'd do it is: char* lpMsgBuf; instead of LPVOID. You might as well keep some type info there; no need to call it VOID yet (it will implicitly cast to that when it is necessary). You still need to cast at the function call point, so the rest remains the same, but you should keep the return value of FormatMessageA. Then, you can do something like this: string s = lpMsgBuf[0 .. returned_value].idup; and it will copy it into the D string. You could also skip that ALLOCATE_BUFFER argument and pass it a buffer yourself, soemthing like: char[400] buffer; auto ret = FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer.ptr, buffer.length, NULL); return buffer[0 .. ret].idup; would also work.
Re: How do I convert a LPVOID (void*) to string?
On Monday, 16 October 2017 at 21:48:35 UTC, Nieto wrote: How do I convert/create a D string from LPVOID (void*)? string GetLastErrorMessage() { LPVOID lpMsgBuf; DWORD errorMessageID = GetLastError(); FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), cast(LPSTR) , 0, NULL); return ?? } I forget to call LocalFree(lpMsgBuf); here...
How do I convert a LPVOID (void*) to string?
How do I convert/create a D string from LPVOID (void*)? string GetLastErrorMessage() { LPVOID lpMsgBuf; DWORD errorMessageID = GetLastError(); FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), cast(LPSTR) , 0, NULL); return ?? }
Re: Temporary objects as function parameters or when-is-this-shit-going-to-end?
On Monday, 16 October 2017 at 03:49:18 UTC, ketmar wrote: Michael V. Franklin wrote: [...] judging from my several decades of expirience, bounties almost never works. there are alot of reasons for that, but the fact still stands: it is *almost* impossible to make something happen with boundy. it may work by accident ;-), but i myself wouldn't count on that. either bounty is too small ("hey, my time worth much more! i'd better spend it playing videogames!"), or it is too big ("hey, this is a Really Huge Problem, if somebody wants to pay than much! that means that i'll inevitably spend more time on that, and... the bounty is too small. oops." ;-). [...] True, that's how Eric Niebler gets to work on Range V1, V2, V3 as he was the only hired programmer by ISO CPP.
Re: What's the best way to programmatically detect the most recent release of DMD and others?
On Monday, 16 October 2017 at 18:21:46 UTC, Jacob Carlborg wrote: On 2017-10-16 17:13, Andrew Edwards wrote: Is there a better way? The official download script [1] is using the following: You're a godsend. Thank you very much.
Re: What's the best way to programmatically detect the most recent release of DMD and others?
On 2017-10-16 17:13, Andrew Edwards wrote: The best way I know to determine the latest DMD release is http://ftp.digitalmars.com/LATEST. I'm not aware that such a file exists for LDC and GDC so I'm currently doing: string latest(string url) { return executeShell("git ls-remote --tags " ~ url ~ " | cut -d 'v' -f 2 | cut -d '-' -f 1 | cut -d '^' -f 1 | uniq | tail -n 1").output.strip; } Is there a better way? The official download script [1] is using the following: dmd - http://downloads.dlang.org/releases/LATEST dmd beta - http://downloads.dlang.org/pre-releases/LATEST ldc - https://ldc-developers.github.io/LATEST ldc beta - https://ldc-developers.github.io/LATEST_BETA gdc - http://gdcproject.org/downloads/LATEST [1] https://dlang.org/install.sh -- /Jacob Carlborg
Re: what operator(s) should I overload to prevent this?
On 10/16/17 8:00 AM, drug wrote: I refactored `MyStructure` added own implementation of malloced array based on pureRealloc/pureFree instead of dynamic array I used before and now I have error: Error: cannot implicitly convert expression get(msg.getData()) of type const(MyStructure) to MyStructure. What operators should I overload to let this conversion? I've tryed opCast and it fails in other call sites, also I've tried opAssign - it didn't works, what worked is wrapping in ctor - MyStruct(const_var). But using ctor is not convenient. The issue is: int[] -> const(int)[]. This is an implicit cast from a mutable array of mutable data to a mutable array of const data. There is no way to "hook" this properly. What you need is: MyArray!int -> MyArray!(const(int)) But D doesn't do this implicitly. It can't, as you could implement MyArray!(const(int)) to be completely different from MyArray!int. If you define opCast(T : MyArray!(const(T))), then it requires an explicit cast, you need an implicit one. You could use alias this, but I don't think it's as smooth. Complicating things further, you have template functions like this: foo(T)(const(T)[]) Where D is smart enough to pull out the T there. I don't think it works with MyArray. -Steve
Re: Why isn't IID_ITaskbarList3 defined?
On Monday, 16 October 2017 at 05:06:26 UTC, evilrat wrote: On Sunday, 15 October 2017 at 15:13:09 UTC, Nieto wrote: I'm trying to write a blinding and I found both IID_ITaskbarList and IID_ITaskbarList2 are defined but IID_ITaskbarList3 isn't. Any reason why it isn't defined? sorry if it sounds such a naive question, I'm new to COM and D interop. I knew a thing or two about PInvokes with C#. Then how do I define it myself? I've tried this: GUID IID_ITaskbarList3 = createGUIDFromString("{ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf}"); GUID createGUIDFromString(string guidStr) { GUID guid; wchar* GUID_STR = toUTFz!(wchar*)(guidStr); HRESULT hr = IIDFromString(GUID_STR, ); assert(SUCCEEDED(hr)); return guid; } I'm unsure if it's the proper way to do it (if not, please show me the right one) But the call to CoCreateInstance() still fails to access any member of m_pITaskBarList3 object, so I'm making sure I'm passing the correct arguments to the function. The memory access error is: object.Error@(0): Access Violation HRESULT hr = CoCreateInstance(_TaskbarList, null, CLSCTX_INPROC_SERVER, _ITaskbarList3, cast(void **) _pITaskBarList3); assert(hr == S_OK); The assert() doesn't run, so the error is somewhere else... I guess. Did you call CoInitialize before creating anything? Is your ITaskbarList3 defined as interface? Here is the simple example anyway https://gist.github.com/Superbelko/277d86a17d497eae85a7f1788bfd83b4 There are no predefined GUID's and declarations for some stuff because standard WinAPI bindings is incomplete, you can probably contribute and add some https://github.com/dlang/druntime Yes, I did call CoInitialize(null) before call CoCreateInstance(). I thoguht the GUID was some kind of constant value to identify the ITaskbarList3 (the struct name is even IID). I was dead wrong lol but I was just starting with the COM world. I defined CLSID_ITaskbarList3 like your IID_ITaskbarList3. I realized my mistake: out of C++ habit, I declared the ITaskbarList3 as a pointer! That's why it wasn't working. I didn't realized it until I read your code. Again, thank you very much. I'll try contibute to the WinAPI binding once mine is complete. Have a nice day! :)
What's the best way to programmatically detect the most recent release of DMD and others?
The best way I know to determine the latest DMD release is http://ftp.digitalmars.com/LATEST. I'm not aware that such a file exists for LDC and GDC so I'm currently doing: string latest(string url) { return executeShell("git ls-remote --tags " ~ url ~ " | cut -d 'v' -f 2 | cut -d '-' -f 1 | cut -d '^' -f 1 | uniq | tail -n 1").output.strip; } Is there a better way? Thanks, Andrew
Re: How to embed static strings to a D program?
On Monday, 16 October 2017 at 06:03:40 UTC, evilrat wrote: can cast to ubyte[] for binary too, be careful with enums though, because enum arrays will allocate every time you access it Arrays yes, but not strings. So you can do `enum data = import("strings.txt");`.
Re: Range tee()?
On Monday, 16 October 2017 at 07:28:03 UTC, Nick Sabalausky (Abscissa) wrote: Does Phobos have a way to "tee" a range? use my dpldocs search engine http://dpldocs.info/tee std.range pops right up!
Re: what operator(s) should I overload to prevent this?
16.10.2017 15:18, Biotronic пишет: On Monday, 16 October 2017 at 12:00:13 UTC, drug wrote: I refactored `MyStructure` added own implementation of malloced array based on pureRealloc/pureFree instead of dynamic array I used before and now I have error: Error: cannot implicitly convert expression get(msg.getData()) of type const(MyStructure) to MyStructure. What operators should I overload to let this conversion? I've tryed opCast and it fails in other call sites, also I've tried opAssign - it didn't works, what worked is wrapping in ctor - MyStruct(const_var). But using ctor is not convenient. The reason this doesn't work is you have some sort of non-immutable pointer, reference or array in your struct. I'm not sure why this worked before, since I have no idea what your code looks like. Hence, I can only give limited advice. Notably, the reasons this gives you a warning is because it would be unsafe to do a simple cast. You might have turned immutable(T)[] into T[] (where T is int, byte, char, what-have-you). If this is the case, consider why this happened, and try to turn it back into immutable(T)[]. The same goes for immutable(T)*. Remember that an alias can make something immutable, so it might not be immediately obvious. If you're fine with being unsafe, and can't find a solution like the above, consider this: struct MyStruct { MyStruct getUnsafe() const { return cast(MyStruct)this; } alias getUnsafe this; } -- Biotronic Hmm, I started to write reduced case and probably found the reason - I've changed slice to const data by slice to mutable data. Will investigate further. Thank you for your answer!
Re: what operator(s) should I overload to prevent this?
On Monday, 16 October 2017 at 12:00:13 UTC, drug wrote: I refactored `MyStructure` added own implementation of malloced array based on pureRealloc/pureFree instead of dynamic array I used before and now I have error: Error: cannot implicitly convert expression get(msg.getData()) of type const(MyStructure) to MyStructure. What operators should I overload to let this conversion? I've tryed opCast and it fails in other call sites, also I've tried opAssign - it didn't works, what worked is wrapping in ctor - MyStruct(const_var). But using ctor is not convenient. The reason this doesn't work is you have some sort of non-immutable pointer, reference or array in your struct. I'm not sure why this worked before, since I have no idea what your code looks like. Hence, I can only give limited advice. Notably, the reasons this gives you a warning is because it would be unsafe to do a simple cast. You might have turned immutable(T)[] into T[] (where T is int, byte, char, what-have-you). If this is the case, consider why this happened, and try to turn it back into immutable(T)[]. The same goes for immutable(T)*. Remember that an alias can make something immutable, so it might not be immediately obvious. If you're fine with being unsafe, and can't find a solution like the above, consider this: struct MyStruct { MyStruct getUnsafe() const { return cast(MyStruct)this; } alias getUnsafe this; } -- Biotronic
what operator(s) should I overload to prevent this?
I refactored `MyStructure` added own implementation of malloced array based on pureRealloc/pureFree instead of dynamic array I used before and now I have error: Error: cannot implicitly convert expression get(msg.getData()) of type const(MyStructure) to MyStructure. What operators should I overload to let this conversion? I've tryed opCast and it fails in other call sites, also I've tried opAssign - it didn't works, what worked is wrapping in ctor - MyStruct(const_var). But using ctor is not convenient.
Re: Range tee()?
On 10/16/2017 03:30 AM, lobo wrote: On Monday, 16 October 2017 at 07:28:03 UTC, Nick Sabalausky (Abscissa) wrote: Does Phobos have a way to "tee" a range? For example, suppose you had something like this: [...] https://dlang.org/phobos/std_range.html#tee ? Ahh, thanks, I was only looking in std.algorithm. Didn't expect it to be in std.range.
Re: Range tee()?
On Monday, 16 October 2017 at 07:28:03 UTC, Nick Sabalausky (Abscissa) wrote: Does Phobos have a way to "tee" a range? For example, suppose you had something like this: [...] https://dlang.org/phobos/std_range.html#tee ?
Range tee()?
Does Phobos have a way to "tee" a range? For example, suppose you had something like this: - // Do something with each file in a dir dirEntries(selectedDir, SpanMode.shallow) .filter!someFilterCriteria .doSomethingWithFile; - It would be really nice to be able to "wiretap" that, to trace/debug/etc by nothing more than ADDING a single statement at any desired wiretap point: - // Do something with each file in a dir dirEntries(selectedDir, SpanMode.shallow) //.tee(a => writeln("FOUND: ", a)) // DEBUG: TRACE ALL FILES FOUND! .filter!someFilterCriteria //.tee(a => writeln("SELECTED: ", a)) // DEBUG: TRACE RESULT OF FILTER! .doSomethingWithFile; - Does something like this already exist Phobos? I tried looking for a "tee" in st.algorithm but came up nothing. If not, it seems like a pretty glaring omission.
Re: How to embed static strings to a D program?
On Monday, 16 October 2017 at 05:34:13 UTC, Ky-Anh Huynh wrote: Hello, I want to use some static contents in my program, e.g, a CSS file, a long listing. To help deployment process I'd like to have them embedded in the final binary file. Is there any convenient way to support this? Maybe I need a tool/library to load file contents and generate D-code at run-time ? Thanks for your reading. import can do this, basically it gives you an array that you can cast to ubyte[] for binary too, be careful with enums though, because enum arrays will allocate every time you access it string data = import("strings.txt"); more https://dlang.org/spec/expression.html#import_expressions However for security reasons it only looks in folders which you pass with -J flag or with dub using "stringImportPaths" http://code.dlang.org/package-format?lang=json