Re: Download a file into array (using std.net.curl.download)
On Wednesday, 7 July 2021 at 13:49:50 UTC, MoonlightSentinel wrote: On Wednesday, 7 July 2021 at 10:27:47 UTC, notna wrote: On Windows: [...] Nice and helpful Error messages is on the top of our desires list, right? It's hard to give proper error backtraces without debug information (-g). Anyways, I can reproduce the error when compiling with `-m32` (the default), using `-m32mscoff` and `-m64` works as expected. You should probably avoid `-m32` in general (as dub does btw). for what it's worth... due to license restrictions and costs we are not allowed to have the MS toolchain installed on our office clients... tried it now @HOME with the '-m64' switch anabled, as suggested by you, and can confirm, it also "just works"...
Re: Download a file into array (using std.net.curl.download)
On Wednesday, 7 July 2021 at 11:54:39 UTC, z wrote: On 64 bits you don't even get a stack trace or description. Sad, i know. If you want better i could recommend you to compile with `-g` and hook up a debugger, then just let it run and it should triger a breakpoint on 0xC009(access violation). Well, that's an option, for those who want and are knowledgeable to debug ;) Anyhow, compiling it with ```dmd -v -g``` results in ``` λ .\curl_get.exe object.Error@(0): Access Violation 0x028DCA66 0x004211E1 in ref void* std.concurrency.initOnce!(std.net.curl.CurlAPI._handle).initOnce(lazy void*) 0x00402449 in char[] std.net.curl.get!(std.net.curl.AutoProtocol, char).get(const(char)[], std.net.curl.AutoProtocol) at c:\d\dmd2\windows\bin\..\..\src\phobos\std\net\curl.d(588) 0x00402308 in _Dmain at C:\Programming\D_playground\curl_get.d(6) 0x00417E0B in void rt.dmain2._d_run_main2(char[][], uint, extern (C) int function(char[][])*).runAll().__lambda1() 0x00417D85 in void rt.dmain2._d_run_main2(char[][], uint, extern (C) int function(char[][])*).runAll() 0x00417C20 in _d_run_main2 0x0040FD63 in _d_run_main 0x00402404 in main at c:\d\dmd2\windows\bin\..\..\src\druntime\import\core\internal\entrypoint.d(29) 0x0048ADC9 in mainCRTStartup 0x74B96359 in BaseThreadInitThunk 0x773887A4 in RtlGetAppContainerNamedObjectPath 0x77388774 in RtlGetAppContainerNamedObjectPath ```
Re: Download a file into array (using std.net.curl.download)
On Wednesday, 7 July 2021 at 12:07:26 UTC, rikki cattermole wrote: With ldc you can turn on address sanitizer which will give you that information (and a LOT more!) without a debugger (but you still need -g). http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html compiling with ldc2 "just works"! thanks for the hint ;)
Re: Download a file into array (using std.net.curl.download)
On Monday, 5 July 2021 at 15:08:45 UTC, MoonlightSentinel wrote: On Monday, 5 July 2021 at 14:57:20 UTC, BoQsc wrote: Let's say I can't store information into files. Is it possible to download a file into an array. Yes, use [`get`](https://dlang.org/phobos/std_net_curl.html#.get): ```d import std.net.curl; void main() { char[] content = get("https://gist.githubusercontent.com/deekayen/4148741/raw/98d35708fa344717d8eee15d11987de6c8e26d7d/1-1000.txt";); } ``` On Windows: ``` ::> dmd curl_get.d ::> .\curl_get.exe object.Error@(0): Access Violation 0x0283CA66 0x0041DE8D 0x004023A2 0x00402308 0x00414D33 0x00414CAD 0x00414B48 0x0040D41F 0x00402363 0x74B96359 in BaseThreadInitThunk 0x773887A4 in RtlGetAppContainerNamedObjectPath 0x77388774 in RtlGetAppContainerNamedObjectPath ``` Nice and helpful Error messages is on the top of our desires list, right?
Re: Good way to send/receive UDP packets?
On Tuesday, 21 July 2020 at 13:05:21 UTC, wjoe wrote: On Sunday, 19 July 2020 at 09:48:24 UTC, notna wrote: Someone once wrote about a UDP library, which was used to sync data to somewhere in APAC (Hongkong?) and by doing so the data transfer was magnitudes faster then before (over TCP)... In the best case scenario, and orders of magnitude more unreliable otherwise. Choosing UDP over TCP because speed is like choosing a hammer over a screwdriver to drive in a screw because it works and is faster. But it's still the wrong tool for the job. UDP is a protocol for broadcasting messages which means it's connection less, unreliable (as in no guarantees for delivery of datagrams or that they'll be delivered only once, order i.e. datagrams sent in order A B C D can be delivered like e.g B C A D), and data integrity. It's insecure (as in everyone who listens can receive it). Once you need any of these features/guarantees you'll lose performance just as you would by using TCP, plus you pay the cost for re-inventing the wheel, bugs, testing, maintenance, support and all. UDP is the protocol of choice when you want to broadcast, the data you send isn't important or the TCP overhead is bigger than the transmitted message. Like broadcasting radio/podcasts, weather updates for your status bar or some such or DNS queries. If you need reliable transmission you need to use a reliable protocol. well, I guess all your remarks are true... and irrelevant at the same time. please go back and read his first post starts with "I have a project where I need to take and send UDP packets over the Internet"...
Re: Good way to send/receive UDP packets?
On Saturday, 18 July 2020 at 16:00:09 UTC, Dukc wrote: I have a project where I need to take and send UDP packets over the Internet. Only raw UDP - my application uses packets directly, with their starting `[0x5a, packet.length.to!ubyte]` included. And only communication with a single address, no need to communicate with multiple clients concurrently. I understand that I could do it either with the Curl library bundled with Phobos, or use Vibe.D or Hunt instead. But it's the first time I'm dealing with low-level networking like this, and my knowledge about it is lacking. So seek opinions about what library I should use, and more importantly, why. Other advice about projects like this is also welcome, should anyone wish to share it. Someone once wrote about a UDP library, which was used to sync data to somewhere in APAC (Hongkong?) and by doing so the data transfer was magnitudes faster then before (over TCP)... I couldn't find this info now, neither in the forum not something meaningful in code.dlang.org... Maybe the author is still around or someone else has this post at hand and could share it?! Beside this, there is: - https://dlang.org/blog/2016/10/21/project-highlight-libasync/ Hope this helps...
Re: sort a string
On Friday, 1 May 2020 at 19:25:43 UTC, Steven Schveighoffer wrote: Nice! Yeah, I was sloppy in my newsgroup coding, sorry. One minor nit here, the to!(dchar[])(word.dup), the dup is not necessary, you are going to end up allocating a temporary array and throwing it away. Just do word.to!(dchar[]). `to` takes care of all the formalities. -Steve THANK YOU for all the great hints and explanations here and in general in this NG, Steve! No blaming for the "sloopy code" at all. I should have seen the missing [] by myself, but... _AND_ btw. your hint with the "release" was key to the discussion / solution anyhow! :)
Re: sort a string
On Friday, 1 May 2020 at 15:17:53 UTC, drug wrote: 01.05.2020 18:04, notna пишет: hmmm, whích results in: Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() { string word = "Привет"; dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range of mutable char // and convert char to dchar .sort // sort it .release; // get the sorted range assert(line3 == "Пвеирт"); } ``` THANKS, this looks even cleaner :)
Re: sort a string
On Friday, 1 May 2020 at 15:15:29 UTC, bachmeier wrote: On Friday, 1 May 2020 at 15:04:01 UTC, notna wrote: On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote: dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release; https://dlang.org/phobos/std_range.html#.SortedRange.release hmmm, whích results in: Error: cannot use [] operator on expression of type dchar Working program: import std.algorithm, std.conv, std.string, std.stdio; void main() { string word = "bar"; string line2 = toLower!(string)(word); dchar[] line3 = sort(line2.to!(dchar[])).release; writeln(line3); } You need to add parens. well, this makes very much sense ;) THANKS a lot, works and helped to adopt some old code
Re: sort a string
On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote: dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release; https://dlang.org/phobos/std_range.html#.SortedRange.release hmmm, whích results in: Error: cannot use [] operator on expression of type dchar
Re: readln of german Umlaute (terminal.d) / readln)
On Tuesday, 17 October 2017 at 15:02:29 UTC, Adam D. Ruppe wrote: Or try this newest commit https://github.com/adamdruppe/arsd/blob/master/terminal.d and see if it works better for you. - Here is what I use in one of my tools... and I never had problems with German password so far ;) string getPassword(char mask = '*') { import std.stdio; import libs.terminal; auto term = Terminal(ConsoleOutputType.linear); auto input = RealTimeConsoleInput(&term, ConsoleInputFlags.raw); string pass; dchar ch; ch = input.getch(); while(ch != '\r' && ch != '\n') { import std.range; if(ch == '\b' && !pass.empty) { pass = pass[0..$-1]; write('\b'); stdout.flush; } else { pass ~= ch; write(mask); stdout.flush(); } ch = input.getch(); } return pass; }
Re: "Rolling Hash computation" or "Content Defined Chunking"
On Saturday, 6 May 2017 at 07:21:51 UTC, Johannes Pfau wrote: Am Mon, 01 May 2017 21:01:43 + schrieb notna : Hi Dlander's. Found some interesting reads ([1] [2] [3]) about the $SUBJECT and wonder if there is anything available in the Dland?! If yes, pls. share. If not, how could it be done (D'ish) [1] - https://moinakg.wordpress.com/2013/06/22/high-performance-content-defined-chunking/ - https://github.com/moinakg/pcompress/blob/master/rabin/rabin_dedup.c [2] - https://restic.github.io/blog/2015-09-12/restic-foundation1-cdc [3] - http://www.infoarena.ro/blog/rolling-hash Thanks & regards Interesting concept. I'm not aware of any D implementation but it shouldn't be difficult to implement this in D: https://en.wikipedia.org/wiki/Rolling_hash#Cyclic_polynomial There's a BSD licensed haskell implementation, so a BSD licensed port would be very easy to implement: https://hackage.haskell.org/package/optimal-blocks-0.1.0 https://hackage.haskell.org/package/optimal-blocks-0.1.0/docs/src/Algorithm-OptimalBlocks-BuzzHash.html To make an implementation D'ish it could integrate with either std.digest or process input ranges. If you want to use it exclusively for chunking your code can be more efficient (process InputRange until a boundary condition is met). When using input ranges, prefer some kind of buffered approach, Range!ubyte[] instead of Range!ubyte for better performance. If you really want the rolling hash value for each byte in a sequence this will be less efficient as you'll have to enter data byte-by-byte. In this case it's extremely important for performance that your function can be inlined, so use templates: ubyte[] data; foreach(b; data) { // This needs to be inlined for performance reasons rollinghash.put(b); } -- Johannes Thanks for the feedback, Johannes. I hoped there may already be something in Mir or Weka.io or somewhere else... Will read the Golang, C and C++ source and see if my Dlang is good enough for ranges and the like magic...
"Rolling Hash computation" or "Content Defined Chunking"
Hi Dlander's. Found some interesting reads ([1] [2] [3]) about the $SUBJECT and wonder if there is anything available in the Dland?! If yes, pls. share. If not, how could it be done (D'ish) [1] - https://moinakg.wordpress.com/2013/06/22/high-performance-content-defined-chunking/ - https://github.com/moinakg/pcompress/blob/master/rabin/rabin_dedup.c [2] - https://restic.github.io/blog/2015-09-12/restic-foundation1-cdc [3] - http://www.infoarena.ro/blog/rolling-hash Thanks & regards
Re: Separate IP parts
On Saturday, 10 December 2016 at 13:25:13 UTC, Nicholas Wilson wrote: On Saturday, 10 December 2016 at 13:21:40 UTC, notna wrote: Those statements need to be inside a function. Feel free to post a working example or, even better, a pull request with one ;)
Re: Separate IP parts
On Saturday, 10 December 2016 at 08:03:00 UTC, biozic wrote: This would do the same. I wouldn't say it's a trick. import std.format : formattedRead; import std.stdio : writefln; string ipAddr = "192.168.1.54"; int a, b, c, d; formattedRead(ipAddr, "%d.%d.%d.%d", &a, &b, &c, &d); writefln("%s %s %s %s", a, b, c, d); Well, you know, that's one of the not so great things about Dlang... you cannot even trust the provided examples, if there are any: C:\Temp\D>more formattedReadIps.d import std.format; string s = "hello!124:34.5"; string a; int b; double c; formattedRead(s, "%s!%s:%s", &a, &b, &c); assert(a == "hello" && b == 124 && c == 34.5); C:\Temp\D>dmd -v formattedReadIps.d binaryC:\D\dmd2\windows\bin\dmd.exe version v2.072.1 configC:\D\dmd2\windows\bin\sc.ini parse formattedReadIps formattedReadIps.d(6): Error: unexpected ( in declarator formattedReadIps.d(6): Error: basic type expected, not "%s!%s:%s" formattedReadIps.d(6): Error: found '"%s!%s:%s"' when expecting ')' formattedReadIps.d(6): Error: no identifier for declarator formattedRead(s, _error_) formattedReadIps.d(6): Error: semicolon expected following function declaration formattedReadIps.d(6): Error: declaration expected, not ',' formattedReadIps.d(7): Error: declaration expected, not 'assert'
Re: Why can't static arrays be sorted?
On Thursday, 6 October 2016 at 09:23:19 UTC, pineapple wrote: On Thursday, 6 October 2016 at 09:17:08 UTC, pineapple wrote: On Wednesday, 5 October 2016 at 19:30:01 UTC, Jonathan M Davis wrote: Would just like to point out that this is design weirdness on Phobos' part - the library I've been writing does not have this problem. It doesn't even make conceptual sense for a static array to be a range, because you can't remove elements from it. - Jonathan M Davis Just because the static array itself isn't a range doesn't mean that it should be necessary to do unintuitive gymnastics with it just to pass it to functions like `sort`. I mean, people post here how often asking why static or dynamic arrays aren't being accepted by Phobos' range functions in their code? Maybe Phobos really ought to consider another approach. Accepting things that are _valid_ as ranges and not only things that are ranges themselves has proven to be an effective strategy in mach. +1000
Re: Request assistance binding to Windows dsound.{lib, dll}
On Friday, 27 May 2016 at 12:26:19 UTC, Andrew Edwards wrote: http://ftp.dlang.org/ctg/implib.html The above URL suggests that, on Windoze, I can create a D compatible lib from a dll file by issuing the command: [...] If you haven't done so, you need to copy your resulting LIB file to your standard LIBs folder, which under Windows_X86 should be: - C:\D\dmd2\windows\lib regards
Re: curl and proxy
Cool,thanks. Btw., there could be more special chars to encode...replace beside ":"... like / @ and so on... see also http://www.cyberciti.biz/faq/unix-linux-export-variable-http_proxy-with-special-characters/ for the background Regards notna On Friday, 3 October 2014 at 11:13:11 UTC, Marc Schütz wrote: On Friday, 3 October 2014 at 10:53:27 UTC, Marc Schütz wrote: On Friday, 3 October 2014 at 04:57:28 UTC, AntonSotov wrote: auto http = HTTP("dlang.org"); http.onReceive = (ubyte[] data) { writeln(cast(string) (data)); return data.length; }; http.proxy = "192.168.111.111"; http.proxyPort = 1788; WHAT HERE ? http.perform(); // how to make Сurl authorize on a proxy. I specify proxyUser and proxyPassword? I think there's currently no way. curl provides this as an option (CurlOption.proxyuserpwd): curl.set(CurlOption.proxyuserpwd, "myuser:mypasswd"); But unfortunately the `curl` struct is a private member of `HTTP`... https://github.com/D-Programming-Language/phobos/pull/2581 If you're able to build Phobos, could you give this PR a try? I cannot test it myself, because I don't know of a proxy requiring authentication.
Re: core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value
Thanks AsmMan, Found http://msdn.microsoft.com/en-us/library/windows/desktop/ms724432%28v=vs.85%29.aspx and with your help, now understand :) The syntax below prints a blank after my username, so the slice seems a bit too long :O So my "final solution" looks like: module main; import std.stdio; import std.c.windows.windows; pragma(lib, "user32.lib"); pragma(lib, "Advapi32"); void main(string[] args) { WCHAR lpwszUsername[254]; DWORD dUsername2 = 254; GetUserNameW(lpwszUsername.ptr, &dUsername2); writefln("Welcome userW %s", lpwszUsername[0..(dUsername2 - 1)); writeln(); } THANKS again!!! On Tuesday, 16 September 2014 at 00:03:55 UTC, AsmMan wrote: GetUserNameW() return a zero on error and non-zero on success. The actual number of bytes copied into lpwszUsernam is in dUsername2. auto userName = lpwszUsername[0..dUsername2];
Re: core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value
Thanks Ali. As always, your examples and explanations are amazingly clear and "easy to understand". On Monday, 15 September 2014 at 23:57:59 UTC, Ali Çehreli wrote: You must make use of the returned value to slice your wstring. Something like this (not compiled): auto actualLength = GetUserNameW(lpwszUsername.ptr, &dUsername2); auto userName = lpwszUsername[0..actualLength]; Otherwise, D knows that lpwszUsername is a 254-char string and will try to print all of it. Ali
Re: core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value
btw., thats the only thing I found for the given error... which is +10years old: http://forum.dlang.org/thread/ccto20$18bq$1...@digitaldaemon.com On Monday, 15 September 2014 at 23:36:53 UTC, notna wrote: Hi all. ... OUTPUT incl. "ERROR": - core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value 0x0041022C 0x004074B7 0x004074A1 0x00406E66 0x00406DCF 0x00406D28 0x00406C41 0x00406828 0x0040678C 0x0040B66E 0x0040B643 0x0040B559 0x00408737 0x754D338A in BaseThreadInitThunk 0x7714BF32 in RtlInitializeExceptionChain 0x7714BF05 in RtlInitializeExceptionChain Welcome userW
Re: How do I properly exit from a D program (outside main)?
how about "return"? :) there is also "assert"... and pls note, scope could also be your friend :O On Monday, 15 September 2014 at 23:36:56 UTC, AsmMan wrote: Someone said somewhere that call std.c.process.exit() isn't the proper way to exit from a D program since it doesn't terminate some phobos stuff. So what should I use instead of? or there's no a replacement?
core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value
Hi all. somehow, for me, the following is against the "DMD philosophy", because this code builds successfully with DMD and the executable gives the expected result... but also the below strange messages... CODE: - module main; import std.stdio; import std.c.windows.windows; pragma(lib, "user32.lib"); pragma(lib, "Advapi32"); void main(string[] args) { WCHAR lpwszUsername[254]; debug writefln("lpwszUsername.sizeof is %s, WCHAR.sizeof is %s", lpwszUsername.sizeof, WCHAR.sizeof); // DWORD dUsername2 = lpwszUsername.sizeof / WCHAR.sizeof; DWORD dUsername2 = 254; GetUserNameW(lpwszUsername.ptr, &dUsername2); writefln("Welcome userW %s", lpwszUsername); writeln(); } build command: -- - dmd -v -w main.d OUTPUT incl. "ERROR": - core.exception.UnicodeException@src\rt\util\utf.d(400): illegal UTF-16 value 0x0041022C 0x004074B7 0x004074A1 0x00406E66 0x00406DCF 0x00406D28 0x00406C41 0x00406828 0x0040678C 0x0040B66E 0x0040B643 0x0040B559 0x00408737 0x754D338A in BaseThreadInitThunk 0x7714BF32 in RtlInitializeExceptionChain 0x7714BF05 in RtlInitializeExceptionChain Welcome userW environment: - DMD32 D Compiler v2.066.0 - Win7 Enterprise, SP1, 64bit Any ideas?
Re: dmd & dub from git master
I had the same problem just now... on Win8.1 with - DMD32 D Compiler v2.066.0 - DUB version 0.9.21 The workaround is to manually update the "dub.json" file of your project, which was written from "dub init", to the latest vibe-d info on "http://code.dlang.org/packages/vibe-d";, so "dependencies": { "vibe-d": ">=0.7.21-beta.1" }, Regards Anton Oks On Monday, 7 July 2014 at 17:00:30 UTC, Nordlöw wrote: I got things to work after some cleanups of the DUB installations. I don't know exactly how...but no things work :)