Re: How to list all process directories under /proc/
On Sunday, 17 September 2017 at 08:37:33 UTC, Ky-Anh Huynh wrote: The official documentation here https://dlang.org/phobos/std_path.html#.globMatch refers to the wiki page https://en.wikipedia.org/wiki/Glob_%28programming%29 . However I think the popular glob rules (man 7 glob) are not supported. The problem with matching "[0123456789]*" is that it will match files like "1blah" and "8stuff". It looks like glob patterns are not robust enough to handle match patterns you want. A regex would probably be enough. Something like this works: string[] getProcNumbers() { import std.file : dirEntries, SpanMode; import std.path : baseName; import std.regex : regex, match; import std.algorithm : map, filter; import std.array : array; auto r = regex(`^/proc/[0-9]*$`); string[] entries = dirEntries("/proc/", SpanMode.shallow) .map!(n => n.name) .filter!(n => match(n, r)) .array(); return entries; } int main() { import std.stdio : stdout; foreach (entry ; getProcNumbers()) { stdout.writefln("%s", entry); } return 0; }
Re: Binary serialization of a struct
On Saturday, 16 September 2017 at 03:30:51 UTC, Joseph wrote: Are there any simple direct serialization libraries where I can mark elements of a class or struct that I want serialized with an attribute and it will take care of all the rest(including recursive structures, arrays, etc) then deserialize back in to the structs? I want something straight forward without allot of plumbing on my end. https://github.com/msgpack/msgpack-d is about as simple as it can get: import std.file; import msgpack; struct S { int x; float y; string z; } void main() { S input = S(10, 25.5, "message"); // serialize data ubyte[] inData = pack(input); // write data to a file write("file.dat", inData); // read data from a file ubyte[] outData = cast(ubyte[])read("file.dat"); // unserialize the data S target = outData.unpack!S(); // verify data is the same assert(target.x == input.x); assert(target.y == input.y); assert(target.z == input.z); }
Re: Binary serialization of a struct
On Saturday, 16 September 2017 at 03:30:51 UTC, Joseph wrote: Are there any simple direct serialization libraries where I can mark elements of a class or struct that I want serialized with an attribute and it will take care of all the rest(including recursive structures, arrays, etc) then deserialize back in to the structs? I want something straight forward without allot of plumbing on my end. https://github.com/huntlabs/common/blob/master/source/zhang2018/common/Serialize.d only a single file . can serialize/deserialize struct,class,array.
Re: cannot access frame of function
On Monday, 18 September 2017 at 18:49:54 UTC, ag0aep6g wrote: Doesn't work for me. This still fails compilation with the same error: import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; auto asum = 1.23; auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum); } So, this is a bug, isn't it? I assume, I should file it then...
Re: scope(exit) and destructor prioity
On Monday, 18 September 2017 at 20:55:21 UTC, Sasszem wrote: If I write "auto a = new De()", then it calls the scope first, no matter where I place it. Because with `new` a) your struct object is located on the heap (and referred to by pointer - `De*`) instead of the stack (which means no destructors for it are called at function scope end), and b) the lifetime of your struct object is determined by D's garbage collector, which may or may not eventually collect it, finalizing it in the process (calling the destructor, as D doesn't separate finalizers and destructors a.t.m.). In your case, it sounds like the GC collection cycle that (in the current implementation) occurs just before druntime shutdown collects it. I highly recommend reading The GC Series on the D blog [1]. [1] https://dlang.org/blog/the-gc-series/
Re: scope(exit) and destructor prioity
On Monday, 18 September 2017 at 20:55:21 UTC, Sasszem wrote: On Monday, 18 September 2017 at 20:30:20 UTC, Jerry wrote: On Monday, 18 September 2017 at 20:26:05 UTC, Sasszem wrote: [...] It's called inbetween the destructors of wherever you put the scope(exit). import std.stdio; struct De { ~this() { writeln("De"); } } void main() { De a; scope(exit) writeln("scope exit"); De b; } Output: De scope exit De If I write "auto a = new De()", then it calls the scope first, no matter where I place it. If I write "auto a = new De()" I have the same behaviour. If I have "auto b = new De()" aswell, then yes, destructors are called after scope exit. Because you allocate on the heap with new, the destructor isn't called at the end of the scope at all. It is called later by the GC. Try to put variable declarations with destructor after "scope exit" or destroy them manually with "destroy(a)". See https://dlang.org/spec/statement.html#scope-guard-statement for order of calling destructors at the end of scope.
Re: scope(exit) and destructor prioity
On Monday, 18 September 2017 at 20:30:20 UTC, Jerry wrote: On Monday, 18 September 2017 at 20:26:05 UTC, Sasszem wrote: [...] It's called inbetween the destructors of wherever you put the scope(exit). import std.stdio; struct De { ~this() { writeln("De"); } } void main() { De a; scope(exit) writeln("scope exit"); De b; } Output: De scope exit De If I write "auto a = new De()", then it calls the scope first, no matter where I place it.
Re: scope(exit) and destructor prioity
On Monday, 18 September 2017 at 20:26:05 UTC, Sasszem wrote: I'm currently working on a project and for that I've created a thin OO-wrapper on top of derelict-sdl. However, when I close my app, the program terminates with a segfault. I've managed to track down the source, and found that the destructors of my objects are called AFTER the scope(exit) statements. This causes my program to call TTF_CloseFont() after TTF_Quit(), resulting in a segfault. My questions: - Can I force D to call the destructors BEFORE the scope(exit) statements? - If not, is there a way around? It's called inbetween the destructors of wherever you put the scope(exit). import std.stdio; struct De { ~this() { writeln("De"); } } void main() { De a; scope(exit) writeln("scope exit"); De b; } Output: De scope exit De
scope(exit) and destructor prioity
I'm currently working on a project and for that I've created a thin OO-wrapper on top of derelict-sdl. However, when I close my app, the program terminates with a segfault. I've managed to track down the source, and found that the destructors of my objects are called AFTER the scope(exit) statements. This causes my program to call TTF_CloseFont() after TTF_Quit(), resulting in a segfault. My questions: - Can I force D to call the destructors BEFORE the scope(exit) statements? - If not, is there a way around?
Re: cannot access frame of function
On Monday, 18 September 2017 at 18:49:54 UTC, ag0aep6g wrote: On 09/18/2017 08:25 PM, user1234 wrote: On Monday, 18 September 2017 at 14:45:25 UTC, Alex wrote: [...] import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; [...]>> auto asum = a[].sum; [...] asum is a lazy range and the error comes from this. asum is not a range. It's a double. Let's say that if you replace asum by 1.23 then the code compiles. Doesn't work for me. This still fails compilation with the same error: import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; auto asum = 1.23; auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum); } Aw right, i had put 1.23 directly in the lambda. So, OP, you can dismiss my comment.
Re: Looking for instructions on how to make a Derelict library
On Monday, 18 September 2017 at 11:27:01 UTC, jmh530 wrote: On Monday, 18 September 2017 at 00:33:25 UTC, Matt Jones wrote: I've been reading the DerelictSDL2 source code. I think I have a handle on it. I'll have to look more at the wiki too. Thanks. Might be interesting to write up your experience with doing it as either blog post or part of the Derelict documentation (which is already quite good, IMO). I was thinking of doing that. I'll have to figure out the best way to do that, once I get a better understanding of how Derelict works.
Re: cannot access frame of function
On 09/18/2017 08:25 PM, user1234 wrote: On Monday, 18 September 2017 at 14:45:25 UTC, Alex wrote: [...] import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; [...]>> auto asum = a[].sum; [...] asum is a lazy range and the error comes from this. asum is not a range. It's a double. Let's say that if you replace asum by 1.23 then the code compiles. Doesn't work for me. This still fails compilation with the same error: import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; auto asum = 1.23; auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum); }
Re: cannot access frame of function
On Monday, 18 September 2017 at 14:45:25 UTC, Alex wrote: Hi all, given this code: import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; a = 0; foreach(el; a) assert(el == 0); a[0] = 1.0; a[1] = 2.0; a[2] = 3.0; a[3] = 4.0; a[4] = 5.0; foreach(el; a) assert(el != 0); auto asum = a[].sum; auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum); } the last line does not compile. I found http://forum.dlang.org/post/mailman.4097.1499105927.31550.digitalmars-d-b...@puremagic.com and https://issues.dlang.org/show_bug.cgi?id=11886 What I do not understand, how my example differs from the fixed bug? asum is a lazy range and the error comes from this. Let's say that if you replace asum by 1.23 then the code compiles.
Re: OpIndex/OpIndexAssign strange order of execution
void main() { auto s = S(); s["b", "c"] = s["a"]; } Prints a ["b", "c"] Ali I thought about this too, thanks!
Re: OpIndex/OpIndexAssign strange order of execution
Have you considered the multiple indexes? https://dlang.org/spec/operatoroverloading.html#index_assignment_operator It may give you some power in execution order. import std.stdio; struct S { auto opIndex(string index) { writeln(index); return 42; } auto opIndexAssign(int value, string[] indexes...) { writeln(indexes); } } void main() { auto s = S(); s["b", "c"] = s["a"]; } Prints a ["b", "c"] Ali
Re: OpIndex/OpIndexAssign strange order of execution
On Monday, 18 September 2017 at 15:14:20 UTC, Moritz Maxeiner wrote: On Monday, 18 September 2017 at 15:11:34 UTC, Moritz Maxeiner wrote: gets rewritten to --- t.opIndex("b").opIndexAssign(t["a"].value, "c"); --- Sorry, forgot one level of rewriting: --- t.opIndex("b").opIndexAssign(t.opIndex("a").value, "c"); --- Nice, thanks for the explanation :) This will be a problem for me because in my use case the internal operations of the structs are stack-like manipulations. So in this case t["b"]["c"] = t["a"].value; instead of manipulating the internal stack with "a" then "b" and "c" I got this weird order of "b", "a", "c" messing with the internal stack logic. Well, back to work :)
Re: My friend can't install DMD 2.076.0 after he deleted contents of C:\D
On Sunday, 17 September 2017 at 05:33:12 UTC, rikki cattermole wrote: Skip Revo-Uninstaller, no idea why you'd ever use such trial software. Anyway what you want is CCleaner, standard software that all Windows installs should have on hand. http://blog.talosintelligence.com/2017/09/avast-distributes-malware.html https://www.piriform.com/news/blog/2017/9/18/security-notification-for-ccleaner-v5336162-and-ccleaner-cloud-v1073191-for-32-bit-windows-users
Re: My friend can't install DMD 2.076.0 after he deleted contents of C:\D
On 2017-09-16 10:33 PM, rikki cattermole wrote: On 17/09/2017 6:30 AM, Enjoys Math wrote: Series of messages from installer: DMD v2.076.0 is installed on your system Press 'OK' to replace by DMD 2.076.0 An error occurred when removing DMD v2.076.0 Run 'dmd-2.076.0.exe /f to force install And using the command line has no effect - it repeats the above. He got into this situation by accidentally installing Visual Studio and / or Visual D to C:\D where I told him to install D to. At one point I told him to delete everything in C:\D and start over. *That* was a mistake... He's used a trial version of Revo-Uninstaller to remove contents of registry. The issue remains. How can we repair his system so that we can install D on it again? Thanks. Skip Revo-Uninstaller, no idea why you'd ever use such trial software. Anyway what you want is CCleaner, standard software that all Windows installs should have on hand. That should remove all references to VS quite happily. It does a lot more than just modify the registry too :) Be sure to check the latest news on CCleaner... it's been reported as being compromised. Be sure to get a clean version. (I've not used it as I'm not on a Windows machine.)
Re: OpIndex/OpIndexAssign strange order of execution
On Monday, 18 September 2017 at 15:11:34 UTC, Moritz Maxeiner wrote: gets rewritten to --- t.opIndex("b").opIndexAssign(t["a"].value, "c"); --- Sorry, forgot one level of rewriting: --- t.opIndex("b").opIndexAssign(t.opIndex("a").value, "c"); ---
Re: OpIndex/OpIndexAssign strange order of execution
On Sunday, 17 September 2017 at 18:52:39 UTC, SrMordred wrote: struct Test{ [...] } Test t; As described in the spec [1] t["a"] = 100; gets rewritten to --- t.opIndexAssign(100, "a"); --- , while t["b"]["c"] = t["a"].value; gets rewritten to --- t.opIndex("b").opIndexAssign(t["a"].value, "c"); --- , which has to result in your observed output (left-to-right evaluation order): //OUTPUT: opIndexAssign : index : a , value : 100 opIndex : index : b opIndex : index : a property value : 100 opIndexAssign : index : c , value : 100 //EXPECTED OUTPUT opIndexAssign : index : a , value : 100 opIndex : index : a property value : 100 opIndex : index : b opIndexAssign : index : c , value : 100 Is this right? AFAICT from the spec, yes. Your expected output does not match D's rewriting rules for operator overloading. I find unexpected this mix of operations on left and right side of an equal operator. Adding some more examples to the spec to show the results of the rewriting rules could be useful, but AFAICT it's unambiguous. On Monday, 18 September 2017 at 13:38:48 UTC, SrMordred wrote: Should I report this as a bug? Not AFAICT. I tried a C++ equivalent code and it execute in the expected order. D does not (in general) match C++ semantics. [1] https://dlang.org/spec/operatoroverloading.html
cannot access frame of function
Hi all, given this code: import std.algorithm.iteration : sum, cumulativeFold; void main() { double[5] a; a = 0; foreach(el; a) assert(el == 0); a[0] = 1.0; a[1] = 2.0; a[2] = 3.0; a[3] = 4.0; a[4] = 5.0; foreach(el; a) assert(el != 0); auto asum = a[].sum; auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum); } the last line does not compile. I found http://forum.dlang.org/post/mailman.4097.1499105927.31550.digitalmars-d-b...@puremagic.com and https://issues.dlang.org/show_bug.cgi?id=11886 What I do not understand, how my example differs from the fixed bug?
Re: Looking for instructions on how to make a Derelict library
I used to have a guide to creating "Derelictified" bindings for an older version. I should write one up for the current version. +1
Re: Looking for instructions on how to make a Derelict library
On Monday, 18 September 2017 at 11:27:01 UTC, jmh530 wrote: On Monday, 18 September 2017 at 00:33:25 UTC, Matt Jones wrote: I've been reading the DerelictSDL2 source code. I think I have a handle on it. I'll have to look more at the wiki too. Thanks. Might be interesting to write up your experience with doing it as either blog post or part of the Derelict documentation (which is already quite good, IMO). I used to have a guide to creating "Derelictified" bindings for an older version. I should write one up for the current version.
Re: OpIndex/OpIndexAssign strange order of execution
Should I report this as a bug? I tried a C++ equivalent code and it execute in the expected order.
Re: Question on Container Array.
On Monday, 18 September 2017 at 11:47:07 UTC, Vino.B wrote: Hi All, Can some one explain me on the below question. Q1: void main (Array!string args) : Why can't we use container array in void main? Q2: What is the difference between the below? insert, insertBack stableInsert, stableInsertBack linearInsert, stableLinearInsert, stableLinearInsert Q3: Storing the data in a container array store's the data in memory which is managed by malloc/free, where as operation such as appending data using any of the above nor "~=" is managed by gc, is my understanding correct. From, Vino.B Q1: I think that someone could explain it better, but basically a program gets its arguments as an array of C strings. So a C main looks like: main(int argc, char **argv); To make this a bit safer, D's main works with an array of strings instead of pointers. D's main function is called from druntime: https://github.com/dlang/druntime/blob/95fd6e1e395e6320284a22f5d19fa41de8e1dcbb/src/rt/dmain2.d#L301. And it wouldn't be that cool to make the druntime depend on phobos and containers. But theoretically it would be possible to make 'void main (Array!string args)' with custom dmd and druntime. Q2: They are the same for Array. But theoretically they can be defined differently. "stable" in "stableInsert" just means that a range got from container can be used after changing the container. So if you get an Array range with Array[], you can still use this range after stableInsert. "insert" is just shorter than "insertBack". Q3: "~=" uses GC only for built-in arrays. You can define your own "~=" for containers. "~=" for Array calls insertBack. So it will use malloc here.
Question on Container Array.
Hi All, Can some one explain me on the below question. Q1: void main (Array!string args) : Why can't we use container array in void main? Q2: What is the difference between the below? insert, insertBack stableInsert, stableInsertBack linearInsert, stableLinearInsert, stableLinearInsert Q3: Storing the data in a container array store's the data in memory which is managed by malloc/free, where as operation such as appending data using any of the above nor "~=" is managed by gc, is my understanding correct. From, Vino.B
Re: Looking for instructions on how to make a Derelict library
On Monday, 18 September 2017 at 00:33:25 UTC, Matt Jones wrote: I've been reading the DerelictSDL2 source code. I think I have a handle on it. I'll have to look more at the wiki too. Thanks. Might be interesting to write up your experience with doing it as either blog post or part of the Derelict documentation (which is already quite good, IMO).
Re: extern(C) enum
On Monday, 18 September 2017 at 02:04:49 UTC, bitwise wrote: The following code will run fine on Windows, but crash on iOS due to the misaligned access: Interesting, does iOS crash such a process intentionally, or is it a side effect? char data[8]; int i = 0x; int* p = (int*)&data[1]; Isn't this already undefined behaviour (6.3.2.3 p.7 of C11 [1] - present in earlier versions also, IIRC)? *p++ = i; *p++ = i; *p++ = i; The last of these is also a buffer overflow. [1] http://iso-9899.info/n1570.html