Re: Memory management
On Tuesday, 29 September 2020 at 10:57:07 UTC, novice3 wrote: Naive newbie question: Can we have (in theory) in D lang memory management like V lang? I don't know V so can't be sure, but doing it the same way as in the examples sounds possible. The first two calls are easy. D string literals are stored in the read-only memory that is uploaded together with the machine code before execution. So the naive implementation wouldn't allocate any more than the V version. The third one is more difficult. To allocate without using GC or RC means using an owning container, that releases memory when exiting the scope. While they can be checked against leaking referenced using the `-dip1000` feature, it's practical only when the memory has a single clear owner and there is no need to store references to it elsewhere. The GC and RC are better as a general-purpose solution. On the other hand, D could avoid all allocation in the third example by using ranges. That would cause the printing function to figure out the message as it prints.
Re: Whats going on with this?
On 10/2/20 7:28 PM, claptrap wrote: Why would putting in the writeln cause it to fail? Is it maybe trying to create the foo at compile time? Yes, it is. Any static initialization of static variables happens at compile-time. https://dlang.org/spec/declaration.html#global_static_init -Steve
Whats going on with this?
--- import std; import std.stdio; struct Foo { int a = 0, b = 0; this(int[2] vars) { this.a = vars[0]; this.b = vars[1]; //writeln("constructor called"); } } Foo foo = [300,300]; void main() { writeln(foo.a); } --- Compiles and works OK. I cant see anything in the struct docs explaining why that array on the right hand side is automatically converted to a constructor call. Weird thing is if you un-comment the writeln in the constructor it wont compile. You get this... /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d(4839): Error: variable impl cannot be modified at compile time /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d(3806): called from here: makeGlobal() /dlang/dmd/linux/bin64/../../src/phobos/std/stdio.d(3896): called from here: trustedStdout() onlineapp.d(13):called from here: writeln("constructor called") onlineapp.d(18):called from here: Foo(0, 0).this([300, 300]) How ever if you move Point foo declaration into the main function it works OK. What exactly is going on? I mean it looks like the Foo is default constructed and then constructed on top with a call to the arary constructor? But why? Why would putting in the writeln cause it to fail? Is it maybe trying to create the foo at compile time?
Re: std.net.curl get json_encode
On Friday, 2 October 2020 at 21:12:09 UTC, Vino wrote: Hi All, Request your help, the below code is working but we need the output as a json array, in PHP we have json_encode(content), so how to do the same in D, the output is as below, as we need to store this output into database table which contains columns' (Id, Hostname, pool,email_id,username) [...] I also suggest you take a look at other "json packages" as well: https://code.dlang.org/search?q=json For example std_data_json or asdf
Re: std.net.curl get json_encode
On Friday, 2 October 2020 at 21:12:09 UTC, Vino wrote: Hi All, Request your help, the below code is working but we need the output as a json array, in PHP we have json_encode(content), so how to do the same in D, the output is as below, as we need to store this output into database table which contains columns' (Id, Hostname, pool,email_id,username) [...] JSONValue jv = parseJSON(content);
std.net.curl get json_encode
Hi All, Request your help, the below code is working but we need the output as a json array, in PHP we have json_encode(content), so how to do the same in D, the output is as below, as we need to store this output into database table which contains columns' (Id, Hostname, pool,email_id,username) *** PHP $jdata = json_encode(content); foreach($jdata as $j) { print_r($j["items"]["hostname"]); * OUTPUT: {"items": [ {"id":"1", "hostname":"server1", "pool":"dev", "options":[ {"optionValue":"te...@mail.com,test1"}, {"optionValue":"123"} ] }, {"id":"2", "hostname":"server2", "pool":"dev", "options":[ {"optionValue":"te...@mail.com,test2"}, {"optionValue":"124"} ] } ] } import std.net.curl, std.conv, std.stdio, std.json; void main() { auto https = HTTP(); https.handle.set(CurlOption.userpwd, "user:pass"); https.handle.set(CurlOption.connecttimeout, 600); https.handle.set(CurlOption.tcp_nodelay, 1); https.handle.set(CurlOption.buffersize, 1073741824); https.handle.set(CurlOption.http_version, 2); https.handle.set(CurlOption.sslversion, 1); https.handle.set(CurlOption.use_ssl, 3); https.handle.set(CurlOption.ssl_verifypeer, 0); https.handle.set(CurlOption.url, "https://test.com/userlist";); https.method(HTTP.Method.get); https.StatusLine status; https.onReceiveStatusLine = (https.StatusLine s) { status = s; }; auto content = https.perform(); https.shutdown; writeln(to!string(content)); } From, Vino.B
Re: Can opDollar support a jagged 2D array?
On 10/2/20 1:24 PM, James Blachly wrote: On 10/2/20 9:32 AM, Steven Schveighoffer wrote: This seems like an oversight. But it's not impossible. Thank you Steve. Is there any chance that this mechanism will ever be revised? Presumably it would require a DIP. The problem is, how do you pass enough context to the opDollar? The nice thing about opDollar is it's a simple mechanism. But as a simple mechanism, it's hard to say how to give it enough context in this case. In this specific case, you would need to know the index of the first parameter. But what if the first parameter depended on the index of the second? Really, you need opIndex to get the whole expression, with the dollar sign being processed there. But that's really hard to do, because now you are delaying the expression evaluation until later. What I meant by an oversight is, at one point, opDollar just was a single property. And opIndex did not take a slice parameter, but rather you just had opSlice(beg, end), which wasn't a template. The multi-parameter version of opIndex (and the column-specialized version of opSlice version) was added to aid in building the Mir library (I think), and I don't know if anyone brought up the possibility of a jagged array like this. Just curry the information to the receiver. opDollar doesn't have to return a size_t. This is indeed pretty clever; I would not have ever though to have opDollar return a non-integral value. This again suggests the whole thing needs to be revised, but this will work for now -- thanks again! I think this is probably the best solution you are going to get. Maybe someone already has done something like this and has a better answer? Maybe Mir does something like this too, I'd take a look at it if I were you. Long ago, I used opDollar to return something other than a size_t for dcollections, which worked awesome. I had asked for an opCaret, so that you could use slicing from beginning when `0` isn't the first element. Like imagine a RBTree, I might like to say "range of all elements up to key 5" like rbt[^ .. 5] instead of rbt[rbt.begin .. 5]. But opCaret was deemed to be not useful enough. Oh well. -Steve
Re: Can opDollar support a jagged 2D array?
On 10/2/20 9:32 AM, Steven Schveighoffer wrote: This seems like an oversight. But it's not impossible. Thank you Steve. Is there any chance that this mechanism will ever be revised? Presumably it would require a DIP. Just curry the information to the receiver. opDollar doesn't have to return a size_t. This is indeed pretty clever; I would not have ever though to have opDollar return a non-integral value. This again suggests the whole thing needs to be revised, but this will work for now -- thanks again!
Re: Can opDollar support a jagged 2D array?
On 10/1/20 10:34 PM, James Blachly wrote: Suppose I have a data structure encoding sequence lengths: seq1: 0 1 2 ... N seq2: 0 1 2 3 4 ... M seq3: 0 1 ... P I would like to write opIndex and opDollar to support the notation obj[seq, x .. $] to retrieve sequences. However, given that opDollar is templated on dimension (always 1 in this example) and has no information calling function's context/dimension 0 parameter, this seems impossible. Am I missing an easy solution? This seems like an oversight. But it's not impossible. Just curry the information to the receiver. opDollar doesn't have to return a size_t. Something like: struct FromEnd { ptrdiff_t offset; FromEnd opBinary(string s, T)(T val) { mixin("return FromEnd(offset " ~ s ~ " val);"); } } struct MyStructure { FromEnd opDollar(size_t col)() if(col == 1) { return FromEnd.init; } } And then inside your opIndex, you have to handle that type specially according to context. The saving grace here is that opDollar doesn't exist except in an indexing operation, so you don't need to worry about it except in that context. opDollar is really kind of a hacky way to do this. It was added back when multi-dimensional indexing was not yet solid. -Steve
Re: vibe.d / experience / feedback
On Thursday, 1 October 2020 at 06:32:23 UTC, Robert M. Münch wrote: 4. Vide uses an own JSON type, not the standard one. We don't understand why, this just makes things much more complicated and one has to mess around with this. Because standard implementation worse? 5. One can't access the raw HTTP request body, things must be go through Vibe's JSON parser. To get access to the raw body, a lot of workarounds are necessary. Can you create PR?
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On 02/10/2020 9:33 PM, Imperatorn wrote: Did you create a D-partition just for D. Pro You can mount directories as a drive on Windows. https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/subst
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On Friday, 2 October 2020 at 08:33:25 UTC, Imperatorn wrote: On Friday, 2 October 2020 at 08:07:33 UTC, Ferhat Kurtulmuş wrote: On Friday, 2 October 2020 at 07:34:03 UTC, WhatMeWorry wrote: On Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote: [...] Yes, I've been doing that. [...] The only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019 it talks about a ucrt.lib? Here are the steps I used with success: in a VCx64 cmd -> set PATH=%PATH%;D:\dlang\dmd.2.094.0.windows\dmd2\windows\bin64 Did you create a D-partition just for D. Pro Haha. Yes my c compiler is also located at c:\c
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On Friday, 2 October 2020 at 08:07:33 UTC, Ferhat Kurtulmuş wrote: On Friday, 2 October 2020 at 07:34:03 UTC, WhatMeWorry wrote: On Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote: On Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote: [...] 1) try running your commands in Visual Studio Native x64 CMD. Yes, I've been doing that. 2) try link with msvcrt.lib The only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019 it talks about a ucrt.lib? Here are the steps I used with success: in a VCx64 cmd -> set PATH=%PATH%;D:\dlang\dmd.2.094.0.windows\dmd2\windows\bin64 Did you create a D-partition just for D. Pro
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On Friday, 2 October 2020 at 07:34:03 UTC, WhatMeWorry wrote: On Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote: On Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote: On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote: [...] Thanks all. I've gotten it to work with: [...] [...] [...] total = 12 [...] 1) try running your commands in Visual Studio Native x64 CMD. Yes, I've been doing that. 2) try link with msvcrt.lib The only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019 it talks about a ucrt.lib? Here are the steps I used with success: in a VCx64 cmd -> set PATH=%PATH%;D:\dlang\dmd.2.094.0.windows\dmd2\windows\bin64 module user; import std.stdio; import mydll; // Yes, I imported the dll here //export { int myAddSeven(int a, int b); } void main() { int total = mydll.myAddSeven(2, 3); writeln(total); } - module mydll; export extern(D) { int myAddSeven(int a, int b) { return a+b+7; } /* <-- function body */ } --- dmd -m64 -ofmydll.dll mydll.d -L/NOENTRY -L/DLL dmd -m64 user.d mydll.lib
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote: On Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote: On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote: [...] Thanks all. I've gotten it to work with: [...] [...] [...] total = 12 [...] 1) try running your commands in Visual Studio Native x64 CMD. Yes, I've been doing that. 2) try link with msvcrt.lib The only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019 it talks about a ucrt.lib?