Re: when I run dub within git bash, dub prompts are not displayed. For instance...
On Saturday, 10 June 2017 at 16:11:31 UTC, WhatMeWorry wrote: kheaser@IT-ASST-SB MINGW64 /c/Users/kheaser/Git/Delivery/projects (master) $ dub init 00_01_print_ogl_ver ... All this white space here is me just pressing the Enter key ... to get the default values. If the problem is that the text doesn't show until you've entered past all the prompts and the program exits, then it's the terminal you're using not playing well with D. With the default Cygwin terminal this will not show a delayed countdown, but rather all numbers at once after the combined pause: import std.stdio; import core.thread; void main() { foreach (i; 0..5) { writeln(i); Thread.sleep(1.seconds); } } With the normal Windows command prompt, it behaves as it should. Someone else will have to explain what the problem is, but it's something about the terminal not acting like a proper tty or something along those lines.
Re: Zero-cost version-dependent function call at -O0.
On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: How would you solve this problem: do an optional function call depending on some version(X). If version(X) is not defined, there should be no call and no extra code at -O0. ``` { ... foo(); // either compiles to a function call, or to _nothing_. ... } ``` In C, you could do something like: ``` #if X void foo() {..} #else #define foo() #endif ``` How would you do this in D? I can think of `mixin(foo())` but there is probably a nicer way that preserves normal function calling syntax. Cheers, Johan Am I missing something, or can't you just version both the function and the function ćall? version(X) void foo() { /* ... */ } void main() { version(X) { foo(); } }
Re: opEquals nothrow
On Thursday, 20 July 2017 at 15:10:24 UTC, Aldo wrote: extern(C) nothrow { void onMouseClick(GLFWwindow* window, int button, int action, int d) { try { // my code } catch { } } } Tangent but an easy way of nothrowing: extern(C) nothrow { void onMouseClick(GLFWwindow* window, int button, int action, int d) { scope(failure) return; // my throwing code } } or scope(failure) return -1; if working with error codes.
Re: It makes me sick!
On Friday, 28 July 2017 at 05:14:16 UTC, FoxyBrown wrote: If dmd breaks in strange and unpredictable ways IT IS DMD's fault! No exceptions, no matter what you believe, what you say, what lawyer you pay to create a law for you to make you think you are legally correct! You can make any claim you want like: "The end user should install in to a clean dir so that DMD doesn't get confused and load a module that doesn't actually have any implementation" but that's just your opinion. At the end of the day it only makes you and dmd look bad when it doesn't work because of some lame minor issue that could be easily fixed. But it's not being installed, it's being manually extracted, meaning you can't even have cleanup scripts. Compare keeping an installation of audio files in mp3 (bird calls), and then getting an upgrade where they are in ogg in a new neat directory hierarchy. There's an installer that properly and cleanly removes the old mp3s before extracting the new files, as well as a bonus archive if you want to unzip it yourself. Manually extracting it onto the old directory puts the oggs next to the mp3s, leaving it with twice the number of original audio files. Meanwhile, the official upgrade path (installer) properly removes the stale ones. You can't reasonably expect your audio player to not list them all there.
Re: It makes me sick!
On Friday, 28 July 2017 at 21:23:22 UTC, FoxyBrown wrote: So, the program, if it is updated shouldn't use the mp3's then. Why the hell is the program that you say was upgraded to use the ogg still searching and using mp3's? You are trying to make up reasons why it shouldn't work... at least come up with valid reasons. I'm sorry if I'm not expressing it in a way that agrees with you but you're looking at the wrong side of the example. You're pasting one set of files onto another and expect the software to somehow know to ignore some of them.
Re: Compile Time versus Run Time
On Monday, 31 July 2017 at 15:46:47 UTC, inevzxui wrote: On Monday, 31 July 2017 at 15:43:21 UTC, Martin Tschierschke wrote: As a rookie in D programming I try to understand the power of templated functions with compile time parameters. With DMD 2.074 a compile time format (auto output = format!("Print this %s")(var);) was introduced, now we all know that very many of this format strings are immutable, so wouldn't it be cool to automatically detect this and use the compile time version? Without the need to think about it and to use an other syntax? Is this theoretically possible? Regards mt. That's what writeln() does. The format is detected for each element of the variadic. But the parameters are not checked at compile-time unless you specifically pass the pattern string as a template parameter. I think its immutability implicitly converting it into a template parameter is what's what he's talking about. import std.stdio; void main(string[] args) { writefln!"%s"(); // compile-time assert writefln("%s"); // runtime exception, though everything needed for a compile-time assert was inferable during compilation }
Re: Efficiently streaming data to associative array
On Tuesday, 8 August 2017 at 16:00:17 UTC, Steven Schveighoffer wrote: I wouldn't use formattedRead, as I think this is going to allocate temporaries for a and b. What would you suggest to use in its stead? My use-case is similar to the OP's in that I have a string of tokens that I want split into variables. import std.stdio; import std.format; void main() { string abc, def; int ghi, jkl; string s = "abc,123,def,456"; s.formattedRead!"%s,%d,%s,%d"(abc, ghi, def, jkl); writeln(abc); writeln(def); writeln(ghi); writeln(jkl); }
Re: Estimating free system resource at runtime
On Sunday, 20 August 2017 at 15:49:09 UTC, seany wrote: However, i cant find anything on google to tell me how to estimate system resource using D. for C++ and windowes, i could find some API-s Can e do this in D? You can just use those C APIs. I believe the GC does, unless I'm reading it wrong. https://github.com/dlang/druntime/blob/acd2c55095ec039be2a9c20a8891ee40e4a393c3/src/gc/os.d#L173-L175 https://github.com/dlang/druntime/blob/acd2c55095ec039be2a9c20a8891ee40e4a393c3/src/core/sys/windows/winbase.d#L1383-L1392
Re: Remove all blank lines from a file
On Thursday, 31 August 2017 at 14:44:07 UTC, vino wrote: Hi All, Can some provide me a example of how to remove all blank lines from a file. From, Vino.B Super verbose, but: import std.stdio; import std.file; import std.algorithm.iteration; enum inFilename = "in.txt"; enum outFilename = "out.txt"; void main() { immutable lines = readText(inFilename); char[] outbuffer; outbuffer.reserve(lines.length); foreach (line; lines.splitter("\n")) { if (!line.length) continue; outbuffer ~= line; outbuffer ~= "\n"; } auto outfile = File(outFilename, "w"); outfile.write(outbuffer); }
How do I use Socket.select?
I've been using blocking Sockets with timeouts for a while now, but wherever I look the word is "do consider using a non-blocking socket". Even the docs for std.socket.setOption; In a typical application, you might also want to consider using a non-blocking socket instead of setting a timeout on a blocking one. So I'm trying to wrap my head around select but I can't get it to work in any way that's better than my current blocking reads. A SocketSet is a bundle of Sockets that you can add to and remove from, but you can't index. They're just there but out of reach. A call to Socket.select(SocketSet readers, SocketSet writers, SocketSet error) *blocks* (unless supplied a timeout), and when something happens returns a number telling you how many sockets changed status, but not which. The Sockets of those three SocketSets now magically disassociated themselves if they weren't one of those that changed status. You then have to call {readers,writers,error}.isSet(mySocket) and manually delve which one is still in there, and by extension, which one did change. But a "status change" for a reading Socket is "stuff can now connect", for a writing one "connection established", and not sure about the error ones. It doesn't seem to be "there's data waiting to be read" which I'd hoped for, since my program (IRC bot) in essence connects once and stays such throughout its life. What else is there to select that I'm missing? Or is it mostly a thing for programs with lots of Sockets, lots of connections?
dmd/ldc failed with exit code -11
I have a large named enum (currently 645 members) of IRC event types. It's big by neccessity[1]. I'm using dub, and both dmd and ldc successfully build it in test and debug modes, but choke and die on plain and release. I bisected it down to when I did a big addition to the enum to encompass virtually all event types there are. dmd -v: [...] code common function kameloso.common.Separator.__xopEquals function kameloso.common.Separator.__xtoHash function kameloso.common.Settings.__xopEquals function kameloso.common.Settings.__xtoHash function kameloso.common.scopeguard function kameloso.common.scopeguard.scopeString function kameloso.common.scopeguard.entryString function kameloso.common.KamelosoLogger.this function kameloso.common.KamelosoLogger.writeLogMsg function kameloso.common.KamelosoLogger.beginLogMsg function kameloso.common.KamelosoLogger.logMsgPart function kameloso.common.KamelosoLogger.finishLogMsg zsh: segmentation fault (core dumped) dmd -c -v -w -d -version=Have_kameloso -Isource/ source/arsd/dom.d Where it stops here varies if I comment stuff out, so I don't think the Logger is at fault. ldc -v: [...] code irc code constants code connection code config code common /usr/lib/libLLVM-5.0.so(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x2b)[0x7f09953839bb] /usr/lib/libLLVM-5.0.so(_ZN4llvm3sys17RunSignalHandlersEv+0x56)[0x7f0995381806] /usr/lib/libLLVM-5.0.so(+0x808953)[0x7f0995381953] /usr/lib/libpthread.so.0(+0x11da0)[0x7f099496cda0] ldc(_ZN16TemplateInstance12needsCodegenEv+0x8)[0x561fe42fc128] ldc(_ZN16TemplateInstance12needsCodegenEv+0x103)[0x561fe42fc223] ldc(_ZN16TemplateInstance12needsCodegenEv+0x103)[0x561fe42fc223] ldc(_ZN16TemplateInstance12needsCodegenEv+0x103)[0x561fe42fc223] ldc(_ZN16TemplateInstance12needsCodegenEv+0x103)[0x561fe42fc223] ldc(_ZN16TemplateInstance12needsCodegenEv+0x103)[0x561fe42fc223] ldc(_ZN16TemplateInstance12needsCodegenEv+0x103)[0x561fe42fc223] [...] zsh: segmentation fault (core dumped) ldc -v -w -d -oq -od=.dub/obj -d-version=Have_kameloso -Isource/ What can I do? Merely copying the enum into a test file and compiling with an empty main does nothing, it doesn't seem to be enough to replicate the bug. (Arch/Manjaro 64-bit, dmd 2.077.0, ldc 1.5.0 based on 2.075.1) [1] http://defs.ircdocs.horse/defs/numerics.html
Re: dmd/ldc failed with exit code -11
On Tuesday, 21 November 2017 at 00:36:00 UTC, rikki cattermole wrote: Source code please. https://github.com/zorael/kameloso.git I'm not proud of some of the early bits there (main.d) so don't judge me, please. I'm learning as I go. The offending bits are IRCEvent.Type in ircstructs.d[1]. If I comment out part of it[2] making the enum smaller, it compiles. dub build always works, dub build -b plain doesn't. [1] https://github.com/zorael/kameloso/blob/master/source/kameloso/ircstructs.d#L22 [2] https://github.com/zorael/kameloso/blob/mite/source/kameloso/ircstructs.d#L417-L700
Re: dmd/ldc failed with exit code -11
On Tuesday, 21 November 2017 at 10:12:11 UTC, Petar Kirov [ZombineDev] wrote: On Tuesday, 21 November 2017 at 10:10:59 UTC, Petar Kirov [ZombineDev] wrote: On Tuesday, 21 November 2017 at 00:15:04 UTC, Anonymouse wrote: I have a large named enum (currently 645 members) of IRC event types. It's big by neccessity[1]. I'm using dub, and both dmd and ldc successfully build it in test and debug modes, but choke and die on plain and release. I bisected it down to when I did a big addition to the enum to encompass virtually all event types there are. Try using https://github.com/CyberShadow/DustMite/wiki to obtain a minimal test case which reproduces the issue and file bug report(s). This tool can actually be used straight from dub itself: http://code.dlang.org/docs/commandline#dustmite I'm having trouble constructing a dustmite test of that, as I can only pass it a initial known good state by removing the parts I know exhibit the segfault. Looking at the dmd command dub issues and testing them myself I notice that if I reorder the arguments it builds. $ dmd -d -oftest source/arsd/*.d source/kameloso/plugins/*.d source/kameloso/*.d zsh: segmentation fault (core dumped) dmd -d -ofkek source/arsd/*.dd source/kameloso/plugins/*.d source/kameloso/*.d $ dmd -d -oftest source/kameloso/plugins/*.d source/kameloso/*.d source/arsd/*.d $ echo $? 0
Re: dmd/ldc failed with exit code -11
On Tuesday, 21 November 2017 at 13:28:44 UTC, Anonymouse wrote: Looking at the dmd command dub issues and testing them myself I notice that if I reorder the arguments it builds. $ dmd -d -oftest source/arsd/*.d source/kameloso/plugins/*.d source/kameloso/*.d zsh: segmentation fault (core dumped) dmd -d -ofkek source/arsd/*.dd source/kameloso/plugins/*.d source/kameloso/*.d $ dmd -d -oftest source/kameloso/plugins/*.d source/kameloso/*.d source/arsd/*.d $ echo $? 0 Compiling a debug dmd and running the build command in gdb, it seems to be a stack overflow at ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen(). Program received signal SIGSEGV, Segmentation fault. 0x557ef1f7 in TemplateInstance::needsCodegen() (this=0x7f7feff8>) at ddmd/dtemplate.d:6181 (gdb) bt [...58165 all the way to 1...] #58166 0x557ef351 in TemplateInstance::needsCodegen() (this=0x7fff4a8f1eb0) at ddmd/dtemplate.d:6241 #58167 0x557ef351 in TemplateInstance::needsCodegen() (this=0x7fff4a8f2640) at ddmd/dtemplate.d:6241 #58168 0x557ef351 in TemplateInstance::needsCodegen() (this=0x7fff4a8f4480) at ddmd/dtemplate.d:6241 #58169 0x557ef351 in TemplateInstance::needsCodegen() (this=0x7fff4a8f4c10) at ddmd/dtemplate.d:6241 #58170 0x557ef642 in TemplateInstance::needsCodegen() (this=0x72553280) at ddmd/dtemplate.d:6335 #58171 0x558d7851 in toObjFile::ToObjFile::visit(TemplateInstance*) (this=0x7fffc128, ti=0x72553280) at ddmd/toobj.d:1126 #58172 0x557f2426 in TemplateInstance::accept(Visitor*) (this=0x72553280, v=0x7fffc128) at ddmd/dtemplate.d:7438 #58173 0x558d59c2 in toObjFile(Dsymbol*, bool) (ds=0x72553280, multiobj=false) at ddmd/toobj.d:1335 #58174 0x558c6f19 in genObjFile(Module*, bool) (m=0x77e95bf0, multiobj=false) at ddmd/glue.d:402 #58175 0x5585f7e8 in ddmd.mars.tryMain(ulong, const(char)**) (argv=0x7fffd928, argc=36) at ddmd/mars.d:1013 #58176 0x5586003f in D main () at ddmd/mars.d:1115 This part (function final bool needsCodegen(), line 6181): 6233│ // Determine necessity of tinst before tnext. 6234│ if (tinst && tinst.needsCodegen()) 6235│ { 6236│ minst = tinst.minst; // cache result 6237│ assert(minst); 6238│ assert(minst.isRoot() || minst.rootImports()); 6239│ return true; 6240│ } 6241│--> if (tnext && (tnext.needsCodegen() || tnext.minst)) 6242│ { 6243│ minst = tnext.minst; // cache result 6244│ assert(minst); 6245│ return minst.isRoot() || minst.rootImports(); 6246│ }
Re: dmd/ldc failed with exit code -11
On Tuesday, 21 November 2017 at 19:22:47 UTC, Anonymouse wrote: Compiling a debug dmd and running the build command in gdb, it seems to be a stack overflow at ddmd/dtemplate.d:6241, TemplateInstance::needsCodegen(). After a lot of trial and error I managed to find /a/ line which lets it compile under -b plain and release. void colour(Sink, Codes...)(auto ref Sink sink, const Codes codes) { // Sink is a LockingTextWriter or an Appender!string // Codes is a tuple of named enum members foreach (const code; codes) { import std.conv : to; if (++numCodes > 1) sink.put(';'); sink.put((cast(size_t)code).to!string); // <-- } Change size_t to uint and it compiles, keep it size_t and the compiler segfaults. Tested on two machines, both running up-to-date Arch linux, both with dmd and ldc. The bug is too ephemeral to reduce well, if a thing like order of arguments matters. If this is an emergent property of the rest of the program, and the size_t merely fells the house of cards, is it even worth reporting when I can't reduce it?
Re: Does D have class' attributes like C#'s?
On Saturday, 16 December 2017 at 19:57:30 UTC, Marc wrote: C# has a quite nice way to store metadata about a property by a feature called atributes[1]. For example, I can write something like this: class A { [TextSize(256)] string Name { get; set; } } So using runtime/reflection I can retrieve the TextSize value associated to A.name property. Does D have something similar? UDAs? User Defined Attributes. https://dlang.org/spec/attribute.html#UserDefinedAttribute http://ddili.org/ders/d.en/uda.html class A { @TextSize(256) string name() { /* ... */ } }
Re: Scope failure is not preventing application crush in case of uncaught exceptions
On Saturday, 16 December 2017 at 21:56:49 UTC, Jonathan M Davis wrote: The only way to catch an exception is with a catch block, and if you do If you return inside a scopeguard though, the exception (or error!) is swallowed. https://run.dlang.io/is/GEtQ6D void main() { foo(); writeln("no error!"); } int foo() { scope(failure) return -1; assert(0); }
Re: Scope failure is not preventing application crush in case of uncaught exceptions
On Sunday, 17 December 2017 at 08:10:06 UTC, codephantom wrote: On Sunday, 17 December 2017 at 00:10:27 UTC, Anonymouse wrote: If you return inside a scopeguard though, the exception (or error!) is swallowed. https://run.dlang.io/is/GEtQ6D The scope guard will not 'swallow' it, if you use -release mode. Which suggests to me, that assert(0) operates differently when 'not' using -release mode. My 'guess' is, that release mode issues a halt instruction, whereas in non-release mode it is just an exception like any other exception. Apologies. I chose assert(0) just to show that it catches Errors too, so just replace it with throw new Exception and it behaves the same without opening that can of worms.
Version Cygwin
Cygwin is a reserved version[1], alongside Windows and linux and the like. However it doesn't seem to be automatically recognised. import std.stdio; void main() { version(Cygwin) writeln("Cygwin"); } Compiled from a Cygwin prompt this prints nothing. So I thought to add versions: [ "Cygwin" ] to dub.json, but dub refuses. Error: version identifier `Cygwin` is reserved and cannot be set Is there any way to force Cygwin or should I resign to creating an alternative lowercase "cygwin" version? The use-case is to version stdout.flush() here and there to counter that the default Cygwin terminal (mintty) doesn't update when text is written to the terminal. I forget the reason why it doesn't. [1]: https://dlang.org/spec/version.htm
Re: It's possible to declare a variable inside a static foreach()?
On Thursday, 21 December 2017 at 16:25:00 UTC, Marc wrote: For example, I'd like to declare a variable inside a static foreach like in below code, just for better organization, otherwise, I have to use the value directly instead of the variable. If the value is used more than once, it might be inviable. enum allMembers = __traits(derivedMembers, C); static foreach(enum string member; allMembers) { enum attributes = __traits(getAttributes, __traits(getMember, C, member)); static foreach(C c; attributes) { writeln(c); } } I got redefinition erros of "atributes" on this. Can I have this only at compile time? I don't think you need static for foreach of __traits allMembers/derivedMembers and .tupleof. It unrolls at compile-time and builds fine for me if I just remove the statics. https://run.dlang.io/is/Ln3kVZ /*static*/ foreach(C c; attributes) Mind that c will not be of type C but of the type of the attribute.
Re: Version Cygwin
On Friday, 22 December 2017 at 03:24:15 UTC, rikki cattermole wrote: You are not using a Cygwin build. It doesn't matter who calls a process, it doesn't change the version's by itself. As far as I know, nobody supports Cygwin like this. I see, thank you.
Error: out of memory
I've been building and testing my project on linux, juggling the ~5GB+ RAM needed to actually compile, but it's been working. I want to test it on a Windows 10 PC now but compilation with dmd (2.078.1) fails, both with --arch x86 and x86_64. LDC works, but it easily takes twice the time to build. $ dub test Running custom 'unittest' configuration. Performing "unittest" build using dmd for x86. requests 0.6.0: target for configuration "std" is up to date. kameloso 1.0.0-beta.2+commit.56.g8ecd737: building configuration "unittest"... [... deprecation spam ...] Error: out of memory dmd failed with exit code 1. The machine has 32 gigabytes of memory[1], so I don't believe that for a second. Any ideas? [1]: https://i.imgur.com/l5L6BIF.png
Re: Error: out of memory
On Wednesday, 10 January 2018 at 19:15:00 UTC, Anonymouse wrote: I've been building and testing my project on linux, juggling the ~5GB+ RAM needed to actually compile, but it's been working. I want to test it on a Windows 10 PC now but compilation with dmd (2.078.1) That's naturally supposed to be 2.078.0.
invalid or corrupt file: duplicate COMDAT / Previous Definition Different
I haven't been testing my project on Windows for a while, and on top of having issues with out of memory errors when unittesting I see I can't build it normally either. dmd is 2.078.0. $ dub build -c cygwin -a x86_64 Performing "debug" build using dmd for x86_64. kameloso 1.0.0-beta.2+commit.57.g90fdd1d: building configuration "cygwin"... Linking... kameloso.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '_D8kameloso7plugins6common8BotRegex6__ctorMFNcxEQBuQBoQBj10NickPolicyS3std5regex8internal2ir__T5RegexTaZQjZSQEcQDwQDrQDn' Error: linker exited with status 1179 dmd failed with exit code 1179. $ dub build -c cygwin Performing "debug" build using dmd for x86. kameloso 1.0.0-beta.2+commit.57.g90fdd1d: building configuration "cygwin"... Linking... OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html .dub\build\cygwin-debug-windows-x86-dmd_2078-270D5D6B34387418CFDA6A068E7A60D9\kameloso.obj(kameloso) Offset 7A92EH Record Type 00C3 Error 1: Previous Definition Different : _D8kameloso7plugins6common8BotRegex6__ctorMFNcxEQBuQBoQBj10NickPolicyS3std5regex8internal2ir__T5RegexTaZQjZSQEcQDwQDrQDn .dub\build\cygwin-debug-windows-x86-dmd_2078-270D5D6B34387418CFDA6A068E7A60D9\kameloso.obj(kameloso) Offset 7AE18H Record Type 00C3 Error 1: Previous Definition Different : _D8kameloso7plugins6common8BotRegex6__ctorMFNcS3std5regex8internal2ir__T5RegexTaZQjZSQDfQCzQCuQCq Error: linker exited with status 2 dmd failed with exit code 2. LDC 1.7.0 builds just fine. There are similar error messages when compiling on linux, but they don't error out (linking succeeds despite them). /usr/bin/ld: Warning: size of symbol `_D8kameloso7plugins6common8BotRegex6__ctorMFNcxEQBuQBoQBj10NickPolicyS3std5regex8internal2ir__T5RegexTaZQjZSQEcQDwQDrQDn' changed from 46 in .dub/build/posix-debug-linux.posix-x86_64-dmd_2078-8E23DC2771FEB27EF0FE1CC8F3984CAA/kameloso.o to 49 in .dub/build/posix-debug-linux.posix-x86_64-dmd_2078-8E23DC2771FEB27EF0FE1CC8F3984CAA/kameloso.o /usr/bin/ld: Warning: size of symbol `_D8kameloso7plugins6common8BotRegex6__ctorMFNcS3std5regex8internal2ir__T5RegexTaZQjZSQDfQCzQCuQCq' changed from 40 in .dub/build/posix-debug-linux.posix-x86_64-dmd_2078-8E23DC2771FEB27EF0FE1CC8F3984CAA/kameloso.o to 43 in .dub/build/posix-debug-linux.posix-x86_64-dmd_2078-8E23DC2771FEB27EF0FE1CC8F3984CAA/kameloso.o I don't have a reduced testcase yet. I figured I'd ask if it's something known before making the effort.
Re: Error: out of memory
On Wednesday, 10 January 2018 at 19:21:21 UTC, Adam D. Ruppe wrote: On Wednesday, 10 January 2018 at 19:15:00 UTC, Anonymouse wrote: I want to test it on a Windows 10 PC now but compilation with dmd (2.078.1) fails, both with --arch x86 and x86_64. LDC works, but it easily takes twice the time to build. In both cases, it is running a 32 bit dmd, just generating 64 bit code. I don't see a 64 bit release though... might have to try to build it yourself from source using visual studio. (and ugh dmd REALLY needs to get its memory consumption under control! maybe just enabling the GC would help sometimes.) Ugh, okay. Thanks, I'll try that.
Re: invalid or corrupt file: duplicate COMDAT / Previous Definition Different
On Wednesday, 10 January 2018 at 20:19:50 UTC, Benjamin Thaut wrote: Am 10.01.2018 um 20:32 schrieb Anonymouse: I don't have a reduced testcase yet. I figured I'd ask if it's something known before making the effort. Are you by any chance mixing debug and release builds? Or are the -version specifiers different when compiling the various parts of your program? Check your compiler flags and ansure that they are the same over your entire build process. Especiall -debug -relase -inline -O -version Admittedly I am alternating between building debug and unittest builds, but I'm only using dub, no separate compilation. I have limited control of the version specifiers other than through the build configurations, so there's not a whole lot to mix. $ dub clean Cleaning package at C:\cygwin\home\zorael\src\kameloso... $ dub build -c cygwin -a x86_64 Performing "debug" build using dmd for x86_64. kameloso 1.0.0-beta.2+commit.57.g90fdd1d: building configuration "cygwin"... Linking... kameloso.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '_D8kameloso7plugins6common8BotRegex6__ctorMFNcxEQBuQBoQBj10NickPolicyS3std5regex8internal2ir__T5RegexTaZQjZSQEcQDwQDrQDn' Error: linker exited with status 1179 dmd failed with exit code 1179. None of the (version specifiers in the) build configurations I have touch upon the part of the fairly innocent code mentioned in the error message, if I'm reading it right. (https://github.com/zorael/kameloso/blob/c00ca4489e39348bd4b1678c95c1b12636df307c/source/kameloso/plugins/common.d#L424)
Re: invalid or corrupt file: duplicate COMDAT / Previous Definition Different
On Wednesday, 10 January 2018 at 20:53:24 UTC, Anonymouse wrote: None of the (version specifiers in the) build configurations I have touch upon the part of the fairly innocent code mentioned in the error message, if I'm reading it right. (https://github.com/zorael/kameloso/blob/c00ca4489e39348bd4b1678c95c1b12636df307c/source/kameloso/plugins/common.d#L424) struct Foo { this(Regex!char) { /* ... */ } this(StaticRegex!char) { /* ... */ } } It seems like the problem there is that StaticRegex is only an alias to Regex, so I'm overloading it twice. It rhymes well with the linked bug. /++ A $(D StaticRegex) is $(D Regex) object that contains D code specially generated at compile-time to speed up matching. No longer used, kept as alias to Regex for backwards compatibility. +/ public alias StaticRegex = Regex; // <-- Reducing it to just that doesn't reproduce the error message though. As long as Regex!char can house both ctRegex!"foo" and "foo".regex it works for me.
Re: getSymbolsByUDA does not take private symbols under consideration. Should I file a bug?
On Friday, 16 February 2018 at 09:26:47 UTC, Piotr Mitana wrote: Hello, The code below: import std.traits; enum Attr; class MyClass { private @Attr int a; static assert(getSymbolsByUDA!(typeof(this), MyClass).length == 1); } does not compile as static assertion fails. Making the filed a public makes it compile properly. Should I file a bug or is by design? getSymbolsByUDA seems to have some visibility thing going on. Related to https://issues.dlang.org/show_bug.cgi?id=17973 perhaps? Though that only gives deprecation warnings, not errors.
Re: Is there something special required to use Appender.clear
On Tuesday, 27 March 2018 at 12:17:58 UTC, Ellie Harper wrote: Sorry if this is a stupid question, but is there something special required to call Appender.clear? When I attempt even just a simple use I am getting compile errors relating to `template object.clear`. When I try: import std.array; void main(string[] args){ auto foo = appender!string; foo.clear; } Appender only implements clear for mutable types, and string is an array of immutables. I'm not sure but it looks like you're hitting the associative array clear by UFCS instead? Make it Appender!(char[]) and it will work. // only allow overwriting data on non-immutable and non-const data static if (isMutable!T) { /** * Clears the managed array. This allows the elements of the array to be reused * for appending. * * Note: clear is disabled for immutable or const element types, due to the * possibility that $(D Appender) might overwrite immutable data. */ void clear() @trusted pure nothrow { if (_data) { _data.arr = _data.arr.ptr[0 .. 0]; } } [...] https://github.com/dlang/phobos/blob/master/std/array.d#L3140
utf.d codeLength asserts false on certain input
My IRC bot is suddenly seeing crashes. It reads characters from a Socket into an ubyte[] array, then idups parts of that (full lines) into strings for parsing. Parsing involves slicing such strings into meaningful segments; sender, event type, target channel/user, message content, etc. I can assume all of them to be char[]-compliant except for the content field. Running it in a debugger I see I'm tripping an assert in utf.d[1] when calling stripRight on a content slice[2]. /++ Returns the number of code units that are required to encode the code point $(D c) when $(D C) is the character type used to encode it. +/ ubyte codeLength(C)(dchar c) @safe pure nothrow @nogc if (isSomeChar!C) { static if (C.sizeof == 1) { if (c <= 0x7F) return 1; if (c <= 0x7FF) return 2; if (c <= 0x) return 3; if (c <= 0x10) return 4; assert(false); // <-- } // ... This trips it: import std.string; void main() { string s = "\355\342\256 \342\245\341⮢\256\245 ᮮ\241饭\250\245".stripRight; // <-- asserts false } The real backtrace: #0 _D3std3utf__T10codeLengthTaZQpFNaNbNiNfwZh (c=26663461) at /usr/include/dlang/dmd/std/utf.d:2530 #1 0x5578d7aa in _D3std6string__T10stripRightTAyaZQrFQhZ14__foreachbody2MFNaNbNiNfKmKwZi (this=0x7fff99c0, __applyArg1=@0x7fff9978: 26663461, __applyArg0=@0x7fff9970: 17) at /usr/include/dlang/dmd/std/string.d:2918 #2 0x77a47014 in _aApplyRcd2 () from /usr/lib/libphobos2.so.0.78 #3 0x5578d731 in _D3std6string__T10stripRightTAyaZQrFNaNiNfQnZQq (str=...) at /usr/include/dlang/dmd/std/string.d:2915 #4 0x558e0cc7 in _D8kameloso3irc17parseSpecialcasesFNaNfKSQBnQBh9IRCParserKSQCf7ircdefs8IRCEventKAyaZv (slice=..., event=...,parser=...) at source/kameloso/irc.d:1184 Should that not be an Exception, as it's based on input? I'm not sure where the character 26663461 came from. Even so, should it assert? I don't know what to do right now. I'd like to avoid sanitizing all lines. I could catch an Exception but not so much an AssertError. [1]: https://github.com/dlang/phobos/blob/master/std/utf.d#L2522 [2]: https://github.com/zorael/kameloso/blob/master/source/kameloso/irc.d#L1184
dustmite watch shell script (.test vs .lookahead.*)
The dustmite wiki[0] lists the following example script for use to monitor the reduction progress: #!/bin/sh watch -cn 0.1 "zsh -c 'ls -al $1.reduced/**/*.d ; colordiff -ru $1.reduced $1.test'" This repeatedly compares the $1.reduced directory with a $1.test directory. The dustmite run however doesn't seem to produce a (stable) $1.test, only several $1.lookahead.* directories. drwxr-xr-x 1 zorael zorael 362 apr 6 17:21 . drwxr-xr-x 1 zorael zorael 24 apr 6 17:21 source.lookahead.7170 drwxr-xr-x 1 zorael zorael 24 apr 6 17:21 source.lookahead.7169 drwxr-xr-x 1 zorael zorael 24 apr 6 17:21 source -rwxr-xr-x 1 zorael zorael 186 apr 6 10:23 tester The command used was `dustmite -j2 --strip-comments source /abs/path/to/tester`. I'm limiting the number of jobs to 2 so as not to run out of memory. dmd is a bit unreasonable. Why is there no .test directory? Changing the script to $1.lookahead.* doesn't work as it passes (jobs+1) arguments to colordiff, which only accepts 2. Is there any way to glob only one .lookahead.* directory? Some other solution? [0]: https://github.com/CyberShadow/DustMite/wiki
Re: dustmite watch shell script (.test vs .lookahead.*)
On Friday, 6 April 2018 at 15:42:04 UTC, Vladimir Panteleev wrote: On Friday, 6 April 2018 at 15:35:59 UTC, Anonymouse wrote: The dustmite wiki[0] lists the following example script for use to monitor the reduction progress: Here's a more complete version that also works with -j: https://gist.github.com/CyberShadow/2e8f01895c248111c171e982313bb008 Thanks!
Re: Ascii string literal.
On Friday, 6 May 2016 at 20:29:35 UTC, Adam D. Ruppe wrote: On Friday, 6 May 2016 at 20:01:27 UTC, Alexandru Ermicioi wrote: Is it possible somehow to convert implicitly a string literal Not implicitly (well, unless you just use string, ascii is a strict subset of utf-8 anyway), but you could do it explicitly easily. immutable(ubyte)[] ascii(string s) { return cast(typeof(return)) s; } Is this different from what std.string.representation does?
Re: Confusion with anonymous functions and method overloads
On Saturday, 21 May 2016 at 14:39:59 UTC, pineapple wrote: void clean(in void delegate(in T value) func){ this.clean((in T values[]) => { foreach(value; values) func(value); }); This doesn't do what you think it does. It passes a lambda that *returns* that foreach function (that returns void). void clean(in void delegate(in T value) func){ this.clean((in T values[]){ foreach(value; values) func(value); }); } This passes a lambda (that returns void). See https://dpaste.dzfl.pl/f93b9c0c8426
Re: binary expression...
On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote: Please forgive if asked before. My google skills seemed to fail me and didn't see any result from search. My problem is simple (though not my understanding LOL). struct D { int value; bool opEquals()(bool value) const { return (value == value); } } D aD; if (aD == 1) { // OK } if (aD) { // Error: expression aD of type D does not have a boolean value } Is there a way to overload for this? What am I missing? struct D { int value; bool opEquals(T)(T value) const { return value == this.value; } bool opCast(T : bool)() const { return this != this.init; // or some such } } Not tested, written on my phone so might have missed something.
Re: Emulate C's (polymorphic) NULL type
On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote: A extern( C ) function should be able to take it as either one. Missed this bit. Not sure about that one.
Re: Emulate C's (polymorphic) NULL type
On Monday, 6 June 2016 at 09:43:23 UTC, ParticlePeter wrote: In C NULL can be used as integer as well as null pointer. Is there a way to create such a type in D? The type should have only one value which is obviously (0/null). A extern( C ) function should be able to take it as either one. Overloaded enum pops into my mind as example: enum NULL = 0; enum NULL = null; Is this possible somehow? If you want it for use in logical expressions then implicit boolean conversion will treat them as the same. https://dpaste.dzfl.pl/d82f60657c37
Re: Emulate C's (polymorphic) NULL type
On Monday, 6 June 2016 at 12:09:33 UTC, ParticlePeter wrote: I don't see the connection here, you introduced two symbols with two different types. I want one symbol which can pose as two different (constant) types. Ah, my apologies, I misunderstood the question.
Re: how to mark an extern function @nogc?
On Monday, 11 July 2016 at 15:54:02 UTC, Seb wrote: On Monday, 11 July 2016 at 01:59:51 UTC, Adam Sansier wrote: On Monday, 11 July 2016 at 01:58:23 UTC, Adam Sansier wrote: I'm using some win functions that don't use the gc and are not marked, specifically CLSIDFromString that I imported myself(it's not marked nogc in objbase). I went ahead and copied the import and added nogc. Shouldn't someone add that to objbase? Why don't you fork it & add it yourself? Otherwise to quote Walter: "a bug only exists if it's on Bugzilla [issues.dlang.org]" ;-) Unreported bugs can only be fixed by accident.
Re: aspects on methods?
On Tuesday, 12 July 2016 at 11:26:20 UTC, jj75607 wrote: I want to use aspect-like annotations to transform [...] Two methods spring to mind but both create new types. You can either write a function that iterates through the members of your class, generating a string mixin that selectively hijacks calls to functions you have annotated with some UDA. Then it would just forward the function call inside synchronized blocks. alias this should hopefully be enough to forward other members. See https://dpaste.dzfl.pl/6a9cc4946caf for a rough example. It's not robust, doesn't work with overloads (needs an additional foreach over __traits(getOverloads, C, memberstring)), but I hope it conveys the idea. The alternative is to write a wrapper that similarly hijacks and wraps calls inside synchronized blocks, but by using opDispatch. The approach is less complex but sadly doesn't work as well; alias this seems to be more or less mutually exclusive to opDispatch, which makes sense. See https://dpaste.dzfl.pl/a5dac71ab4f8. Accessing enums and other types is also iffy since functions can't return types. As long as you make the base class instance public you can always bypass things that way. In both examples it may make sense to have the generated functions return via auto ref, it depends on your use cases.
Re: alias to function literal, call without () not possible
On Wednesday, 3 August 2016 at 17:16:10 UTC, Andre Pany wrote: Hi, I just stumbled over this behavior. I am not sure whether the behavior is correct or not. [...] alias foo = () => new Object; ...is an alias for a delegate/function returning an Object. It is analogous to alias foo = () { return new Object; }; void bar(Object o){} ...is a function accepting an Object parameter. In main you are trying to call this overload void bar(Object function() o){} ...which is essentially void bar(typeof(foo) o) {} You can use pragma(msg, typeof(symbol).stringof) to inspect what types are being thrown around. void bar(T)(T t) { pragma(msg, T.stringof); // "Object function() pure nothrow @safe" } void main() { auto n1 = foo; pragma(msg, typeof(foo).stringof); // "Object function() pure nothrow @safe" bar(foo); } You could argue that parameterless function call rules should apply here and have it implicitly converted to bar(foo()), but it doesn't. I imagine the ambiguity (of delegate vs function return value) would just cause more problems than it would solve.
Re: Static CT Factory
On Friday, 19 August 2016 at 01:10:42 UTC, Engine Machine wrote: I have a template that is suppose to create a type based on a template parameter static if (T == "int") { auto x = New!int(); } else static if (T == "double") { auto x = New!double(); } x = 1.234; This is just an example, I use custom types. The static if's prevent x's scope from being after them, even though it should work perfectly fine. I can't declare x before because I don't know the type. I'm not sure I understand. static if shouldn't introduce a new scope that way. https://dpaste.dzfl.pl/7b63a6e52309 Mind that x might be a pointer.
Re: Getting a String Literal From an Aliased Template Mixin Parameter
On Thursday, 15 September 2016 at 00:15:42 UTC, jsako wrote: I was making a quick mocking infrastructure for internal mocks so I wouldn't have to pass in objects to constructors all the time and came up with this: [...] This works great as long as there is only one mock object. I thought about using string mixins to generate the properties on a per-variable basis, but the problem is that I can't figure out how to get the string of the variable name from the aliased template mixin parameter. Is there a way to do this? If not, I'll have to pass in the strings of the variables seperately (as in: mixin internalMockRig!(thing, "thing", testThing, "testThing", testThingMock, "testThingMock"); ), but that seems inelegant (and a bit error prone). You mean, the literal string name of the original symbol you passed as an alias? If so then you want the .stringof property. void main () { int first; bool second; string third; mixin Foo!(first, second, third); } mixin template Foo(alias abc, alias def, alias ghi) { static assert(abc.stringof == "first"); static assert(def.stringof == "second"); static assert(ghi.stringof == "third"); }
Re: What exactly does the compiler switch -betterC do?
On Monday, 20 June 2016 at 06:35:32 UTC, Jacob Carlborg wrote: On 2016-06-19 21:53, Gary Willoughby wrote: When compiling, what exactly does the -betterC flag do? The command help says "omit generating some runtime information and helper functions" but what does this really mean? Is there any specifics somewhere? It is intended to allow you to link an application without druntime. [...] What is the equavilent in gdc and ldc?
Re: Dustmite can't handle my memory segfault
On Friday, 21 October 2016 at 10:13:23 UTC, Nordlöw wrote: #!/usr/bin/env python3 import sys import pty stat = pty.spawn(sys.argv[1:]) if stat == 256: exit(42)# remap to 42 else: exit(stat) Assuming you want to remap 134 to 0 (success): #!/bin/bash cmd="$1" shift 2>/dev/null $cmd "$@" [ $? = 134 ] && exit 0 || exit 1
Re: Correct way to create singleton?
On Thursday, 10 November 2016 at 17:17:51 UTC, Konstantin Kutsevalov wrote: Hi, what is a correct (and simple) way to create an singleton? https://wiki.dlang.org/Low-Lock_Singleton_Pattern
Re: Impressed with Appender - Is there design/implementation description?
On Tuesday, 6 December 2016 at 10:52:44 UTC, thedeemon wrote: It's rather simple, just take a look at its source code in std.array. It's an ordinary linear array partially filled with your data. [...] 2. Up until 4 KB it reallocates when growing, but after 4 KB the array lives in a larger pool of memory where it can often grow a lot without reallocating, so in many scenarios where other allocations do not interfere, the data array of appender grows in place without copying any data, thanks to GC.extend() method. I always assumed it kept its own manually allocated array on a malloc heap :O Hence a practice of using .dup and .idup on the .data member when you're happy with the result?
Re: Separate IP parts
On Saturday, 10 December 2016 at 03:51:34 UTC, brocolis wrote: How do I separate IP parts with dlang? I found this very cool trick, with C++: http://stackoverflow.com/a/5328190 std::string ip ="192.168.1.54"; std::stringstream s(ip); int a,b,c,d; //to store the 4 ints char ch; //to temporarily store the '.' s >> a >> ch >> b >> ch >> c >> ch >> d; std::cout << a << " " << b << " " << c << " "<< d; I wonder what's the equivalent D code. Not much of a trick, but: import std.algorithm : splitter, map; import std.range : take; import std.conv : to; import std.array : array; string ip = "192.168.1.54"; auto parts = ip .splitter('.') .take(4) .map!((a) => a.to!int) .array; assert(parts[0] == 192); assert(parts[1] == 168); assert(parts[2] == 1); assert(parts[3] == 54); Remove the .array to keep it lazy, but then you can't index it for the values, only walk through them in a foreach.
Standard output does not get flushed in cygwin?
Try this in a cygwin terminal: import std.stdio; import core.thread; void main() { foreach (i; 0..10) { writeln(i); Thread.sleep(1.seconds); } } This program will not output i, wait a second and then output i+1, etc. It will be silent for ten seconds and then spam the complete output in one go. If you hit Ctrl+C to break it in the middle of execution, nothing will be output at all. Is there a way to work around this? The only thing I found was to tack stdout.flush() after every writeln call.
Re: Standard output does not get flushed in cygwin?
On Sunday, 1 January 2017 at 13:04:30 UTC, rikki cattermole wrote: What is your terminal emulator? Poderosa has a known problem for this. Where as ConEmu (which I have since moved over to) works fine. Fun fact, I had a similar file to the yours in /tmp/test.d :) The default mintty. I tried ConEmu now and it works with cygwin's bash shell! But then mosh and tmux break, unless I use the cygwin terminal connector[1], with which I get the same results as earlier. Maybe I'll just have to paste version (Windows) stdout.flush() everywhere. Or maybe I can hijack calls to my own writeln wrapper. [1]: https://conemu.github.io/en/CygwinMsysConnector.html
Re: String characters not extended
On Monday, 2 January 2017 at 21:07:37 UTC, Ignacious wrote: [...] Assuming Windows: version(Windows) shared static this() { import core.sys.windows.windows; SetConsoleCP(65001); SetConsoleOutputCP(65001); }
Re: String characters not extended
On Tuesday, 3 January 2017 at 19:40:20 UTC, Daniel Kozák wrote: Why do not use CP_UTF8 constant instead of 65001? It is safer, easier to read and understand I have no reason to back it up with. I'm literally just copy/pasting what others have suggested I use.
Re: alias and UFCS
On Tuesday, 24 January 2017 at 13:11:41 UTC, ixid wrote: This code: T tFunc(alias F, T)(T n) { n.F; return n; } Produces this error: Error: no property 'F' for type 'int[]' (or whatever type I use). I believe UFCS is supposed to only work with top-level functions. I don't remember the rationale behind the decision.
Re: is char[] faster than string?
On Wednesday, 5 April 2017 at 22:05:07 UTC, H. S. Teoh wrote: If you are doing lots of concatenation and produce a single big string at the end, take a look at std.array.appender. Though if you're concerned about performance, you really should run a profiler. Last I heard, appender may not be that much faster than using ~=, but I could be wrong. If my understanding serves, and it's very likely that it doesn't, then it works precisely as normally appending does but keeps track of array capacity on its own, so the GC doesn't have to do (expensive?) queries upon every append. But when it comes to optimization, my advice is, profile, profile, profile. This. valgrind --tool=callgrind, ddemangle and QCachegrind are your best friends.
Deprecation: foo.bar is not visible from module traits
I'm reworking my code to use UDAs, and I'm running into a wall of text of deprecation warnings when compiling. import std.traits; private: struct SomeUDA {} @SomeUDA void foo() {} @SomeUDA void bar() {} @SomeUDA void etc() {} public: void main() { mixin("static import thisModule = " ~ __MODULE__ ~ ";"); foreach (symbol; getSymbolsByUDA!(thisModule, SomeUDA)) { static if (isSomeFunction!symbol) { pragma(msg, symbol.stringof); } } } See https://wandbox.org/permlink/6Z01koyGGRxjsNWG for the output it gives. In the real code it's unmanageably many lines. Is there any way to get rid of these warnings except by making everything public? Ideally I wouldn't want to copy the source of getSymbolsByUDA into each file doing this either.
Re: No tempFile() in std.file
On Tuesday, 16 May 2017 at 05:09:12 UTC, Era Scarecrow wrote: On Monday, 15 May 2017 at 22:38:15 UTC, Jonathan M Davis wrote: Personally, I think that it would be very much worth making hello world larger, since hello world really doesn't matter, but because there are plenty of folks checking out D who write hello world and then look at the executable size, it was considered unacceptable for it to get much larger. I'm reminded of doing the same thing with C++ using streams and saw the size explode from 60k or so to something like 400k, for seemingly no good reason at all. Hmmm while we're on the subject of size, is there a tool to strip out functions that are never used from the final executable? Linker --gc-sections, though in my experience it doesn't cull much. Add --print-gc-sections to see what it does remove.
Searching strings with indexOf vs countUntil
I was profiling my program with callgrind and saw that a lot of time was spent in countUntil (std.algorithm.searching) on strings. I had chosen to use it instead of indexOf (std.string), with the plain assumption that countUntil wouldn't decode, while indexOf would. Comparing microbenchmarks between the two I see that countUntil is some 7x slower. import std.stdio : writeln; import std.string : indexOf; import std.algorithm.searching : countUntil; import std.datetime; enum line = ":zorael!~n...@asdf.asdf.asdf PRIVMSG #d :Hello world!"; enum iterations = 1_000_000; void main() { StopWatch sw; sw.start(); foreach (i; 0..iterations) { line.indexOf(" :"); } sw.stop(); immutable usecsIndexOf = sw.peek().usecs; sw.reset(); sw.start(); foreach (i; 0..iterations) { line.countUntil(" :"); } sw.stop(); immutable usecsCountUntil = sw.peek().usecs; writeln("indexOf:", usecsIndexOf.usecs); writeln("countUntil: ", usecsCountUntil.usecs); writeln(cast(double)usecsCountUntil/usecsIndexOf, "x"); } https://dpaste.dzfl.pl/0319edb79ec8 gives the output: indexOf:160 ms and 534 μs countUntil: 1 sec, 146 ms, and 842 μs 7.14392x What is the fundamental difference between the two? When should I ever use countUntil on strings?
Re: Searching strings with indexOf vs countUntil
On Thursday, 25 May 2017 at 11:55:21 UTC, Kagamin wrote: I would guess indexOf returns a value suitable for indexing, therefore it counts code units, while countUntil counts range elements - code points in case of a string. Also number of code points is not suitable for indexing an utf8 string, it can be used to allocate a dstring, but not so much for anything else. What do you use the resulting value for? I see. I would have thought indexOf would be more keen to decode, but that's bias talking. The project is an IRC bot. I use indexOf/used countUntil to slice up strings into one part leading up to some separator (" :" in that example), and another into everything after it. See https://dpaste.dzfl.pl/326e450058c1. On Thursday, 25 May 2017 at 12:46:43 UTC, Basile B. wrote: To get rid of decoding he can cast to ubyte[]. I would do that if sure that the input is only made of ascii chars. Part of the strings I'm working with can be assumed to be only ASCII, yes. indexOf only wants strings or char[]s, but interestingly if I use the same benchmark but have countUntil work on raw ubyte[]s, it is faster. See https://dpaste.dzfl.pl/2e095f7d18be.
Avast virus warning?
I just sent a pre-compiled .exe of my project to a friend, and his Avast anti-virus promptly quarantined it and sent it off for analysis. I tried sending him a Hello World[1] with the same results. Is this something common for d programs? Anything I can do to work around it from my end? [1]: http://www.mediafire.com/file/fc51qz141r3ns6r/helloworld.exe
Re: Avast virus warning?
On Monday, 5 June 2017 at 16:40:25 UTC, rikki cattermole wrote: It would be nice to get in touch with their engineers to find out what is really going on. Tried an email and hit a paywall. :c "We’re sorry, but we can’t seem to find a record of your license in our system."
digger: Failed to spawn new process (The system cannot find the file specified.)
I'm trying to bisect a dmd compilation error on Windows 10 and I can't get digger to do more than one initial test. When preparing to compile the next dmd build (the BAD revision) it errors out. This is in a normal cmd console. The bisect ini has nothing weird in it: ``` bad = v2.088.1 good = v2.087.1 reverse = false tester = cd C:\Temp\init2 && C:\D\dmd2\windows\bin\dub.exe build 2>&1 | findstr /C:"Memory allocation failed" ``` Console log excerpt: ``` [...] digger: -- Running test command... --- core.exception.OutOfMemoryError@src\core\exception.d(647): Memory allocation failed digger: - Test command exited with status 0 (GOOD). -- digger: Sanity-check, testing BAD revision b7a303005afce50f317c768311b71bc21d47090d... digger: Testing revision: b7a303005afce50f317c768311b71bc21d47090d digger: Starting at meta repository commit b7a303005afce50f317c768311b71bc21d47090d digger: Building components dmd, druntime, phobos-includes, phobos, rdmd digger: needInstalled: dmd-8a2067c4bd9c720098c8acb5429f189b12b32ab6-07d4846ed48eb28d158e52488e305015 digger: Cache miss. digger: needBuild: dmd-8a2067c4bd9c720098c8acb5429f189b12b32ab6-07d4846ed48eb28d158e52488e305015 digger: Cleaning repository dmd... HEAD is now at 758722e42 bump VERSION to v2.087.1 digger: Checking out dmd commit 8a2067c4bd9c720098c8acb5429f189b12b32ab6... Previous HEAD position was 758722e42 bump VERSION to v2.087.1 HEAD is now at 8a2067c4b bump VERSION to v2.088.1 digger: Building dmd-8a2067c4bd9c720098c8acb5429f189b12b32ab6-07d4846ed48eb28d158e52488e305015 digger: DMC=C:\Temp\work\dl\dm857-snn2074-optlink80017\bin digger: Preparing DMD v2.079.0 digger: hostDC=C:\Temp\work\dl\dmd-2.079.0\dmd2/windows/bin\dmd.exe digger: Cleaning repository dmd... HEAD is now at 8a2067c4b bump VERSION to v2.088.1 digger: Environment: SystemDrive=C: digger: Environment: TMPDIR=C:\Temp\work\tmp digger: Environment: HOME=C:\Temp\work\home digger: Environment: SystemRoot=C:\WINDOWS digger: Environment: PATH=C:\Temp\work\dl\dm857-snn2074-optlink80017\bin;C:\WINDOWS\system32;C:\WINDOWS digger: Environment: TEMP=C:\Temp\work\tmp digger: Environment: TMP=C:\Temp\work\tmp digger: Environment: DMC=C:\Temp\work\dl\dm857-snn2074-optlink80017\bin digger: Working directory: C:\Temp\work\repo\dmd\src digger: Running: "make" -f win32.mak ^"MODEL=32^" HOST_DC=C:\Temp\work\dl\dmd-2.079.0\dmd2/windows/bin\dmd.exe dmd if not exist "..\generated\windows\release\32" mkdir ..\generated\windows\release\32 make -fwin32.mak C=dmd\backend ROOT=dmd\root MAKE="make" HOST_DC="C:\Temp\work\dl\dmd-2.079.0\dmd2/windows/bin\dmd.exe" MODEL=32 CC="" LIB="lib" OBJ_MSVC="" "OPT=-o" "DEBUG=" "DDEBUG=" "DOPT=-O -release -inline" "LFLAGS=-L/delexe/la" ..\generated\windows\release\32\dmd.exe [...] Digital Mars Librarian Version 8.02n Copyright (C) Digital Mars 2000-2007 All Rights Reserved http://www.digitalmars.com/ctg/lib.html Digital Mars Librarian complete. C:\Temp\work\dl\dmd-2.079.0\dmd2/windows/bin\dmd.exe -of..\generated\build.exe -debug build.d ..\generated\build.exe --called-from-make OS=windows BUILD=release MODEL=32 HOST_DMD= HOST_DC=C:\Temp\work\dl\dmd-2.079.0\dmd2/windows/bin\dmd.exe ..\generated\windows\release\32\lexer.lib std.process.ProcessException@std\process.d(752): Failed to spawn new process (The system cannot find the file specified.) [...] --- errorlevel 1 --- errorlevel 1 digger: Saving to cache. digger: Clearing temporary cache digger: Build failed: object.Exception@C:\Users\zorael\AppData\Local\dub\packages\ae-0.0.2413\ae\sys\d\manager.d(850): Command ["make", "-f", "win32.mak", "MODEL=32", "HOST_DC=C:\\Temp\\work\\dl\\dmd-2.079.0\\dmd2/windows/bin\\dmd.exe", "dmd"] failed with status 1 [...] object.Exception@C:\Users\zorael\AppData\Local\dub\packages\digger-3.0.0-alpha-8\digger\bisect.d(89): BAD revision b7a303005afce50f317c768311b71bc21d47090d is not testable [...] Program exited with code 1 ``` It does a `dmd.exe -of..\generated\build.exe`, but then the immediately following call to `..\generated\build.exe` fails? What am I doing wrong?
Re: digger: Failed to spawn new process (The system cannot find the file specified.)
On Monday, 3 February 2020 at 20:09:43 UTC, MoonlightSentinel wrote: On Monday, 3 February 2020 at 16:54:20 UTC, Anonymouse wrote: It does a `dmd.exe -of..\generated\build.exe`, but then the immediately following call to `..\generated\build.exe` fails? What am I doing wrong? The executable was launched because make would yield a different error message otherwise. This seems to be an error during the environment processing of build.d, could you provide the full stack trace for this exception? std.process.ProcessException@std\process.d(752): Failed to spawn new process (The system cannot find the file specified.) It doesn't seem to include debugging symbols. Does digger not build its dmds with -g? ``` std.process.ProcessException@std\process.d(752): Failed to spawn new process (The system cannot find the file specified.) 0x004386D0 0x00441132 0x00454B5C 0x00444994 0x0042C808 0x004039BD 0x0040257D 0x004353FB 0x0043537D 0x00435218 0x0042948B 0x76C96359 in BaseThreadInitThunk 0x77457B74 in RtlGetAppContainerNamedObjectPath 0x77457B44 in RtlGetAppContainerNamedObjectPath ``` Here's the full log: https://pastebin.com/raw/6MyVDFPc
Re: digger: Failed to spawn new process (The system cannot find the file specified.)
On Monday, 3 February 2020 at 20:54:46 UTC, Vladimir Panteleev wrote: On Monday, 3 February 2020 at 20:41:00 UTC, Anonymouse wrote: It doesn't seem to include debugging symbols. Is your Digger version up-to-date? https://github.com/CyberShadow/ae/commit/48ee31a3b0d47e52769ee87b0e673034abe4add5 I was on beta 8. I forced dub to download the latest now (3.0.0-alpha-9), wiped the work directory and retried, but to similar results. https://pastebin.com/raw/zF39VKzc
Re: digger: Failed to spawn new process (The system cannot find the file specified.)
On Monday, 3 February 2020 at 21:33:09 UTC, Vladimir Panteleev wrote: On Monday, 3 February 2020 at 21:30:57 UTC, Anonymouse wrote: I was on beta 8. I forced dub to download the latest now (3.0.0-alpha-9), wiped the work directory and retried, but to similar results. The latest is v3.0.0-alpha-11. Oh, I guess that's not how semantic versioning works. Probably I should make a normal stable release. For now you can clone and build from source. New log: https://pastebin.com/raw/uUMNQjEN ``` ..\generated\build.exe --called-from-make OS=windows BUILD=release MODEL=32 HOST_DMD= HOST_DC=C:\Temp\work\dl\dmd-2.079.0\dmd2/windows/bin\dmd.exe ..\generated\windows\release\32\lexer.lib (TX) VERSION std.process.ProcessException@std\process.d(752): Failed to spawn new process (The system cannot find the file specified.) 0x00448EDC in @trusted std.process.Pid std.process.spawnProcessImpl(const(char[]), std.stdio.File, std.stdio.File, std.stdio.File, const(immutable(char)[][immutable(char)[]]), std.process.Config, const(char[])) 0x0044D6AA in @trusted std.process.Pid std.process.spawnProcess(const(char[][]), std.stdio.File, std.stdio.File, std.stdio.File, const(immutable(char)[][immutable(char)[]]), std.process.Config, const(char[])) 0x0046E114 in @trusted std.process.ProcessPipes std.process.pipeProcessImpl!(std.process.spawnProcess, const(char[])[]).pipeProcessImpl(const(char[])[], std.process.Redirect, const(immutable(char)[][immutable(char)[]]), std.process.Config, const(char[])) 0x004555A4 in @safe std.process.ProcessPipes std.process.pipeProcess(const(char[][]), std.process.Redirect, const(immutable(char)[][immutable(char)[]]), std.process.Config, const(char[])) 0x0043B160 in @trusted std.typecons.Tuple!(int, "status", immutable(char)[], "output").Tuple std.process.execute(const(char[][]), const(immutable(char)[][immutable(char)[]]), std.process.Config, uint, const(char[])) 0x0041DEAF in void build.__funcliteral51().__lambda1() at C:\Temp\work\repo\dmd\src\build.d(278) 0x00406D0B in void build.DependencyRef.runSynchronized() at C:\Temp\work\repo\dmd\src\build.d(1092) 0x0040347F in void build.DependencyRef.run() at C:\Temp\work\repo\dmd\src\build.d(1065) 0x00406C1D in void build.DependencyRef.runSynchronized() at C:\Temp\work\repo\dmd\src\build.d(1078) 0x0040347F in void build.DependencyRef.run() at C:\Temp\work\repo\dmd\src\build.d(1065) 0x00402783 in _Dmain at C:\Temp\work\repo\dmd\src\build.d(138) 0x004375B3 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().__lambda1() 0x00437535 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() 0x004373D0 in _d_run_main 0x004371C8 in main at C:\Temp\work\repo\dmd\src\build.d(7) 0x004B4B91 in mainCRTStartup 0x74D36359 in BaseThreadInitThunk 0x77337B74 in RtlGetAppContainerNamedObjectPath 0x77337B44 in RtlGetAppContainerNamedObjectPath ```
Re: digger: Failed to spawn new process (The system cannot find the file specified.)
On Monday, 3 February 2020 at 21:58:31 UTC, Vladimir Panteleev wrote: On Monday, 3 February 2020 at 21:44:20 UTC, Anonymouse wrote: New log: https://pastebin.com/raw/uUMNQjEN It looks like it fails to execute git (to get the current version for the build). I don't know why that fails, as I see C:\Temp\work\dl\git\cmd is in PATH in the environment that build.exe is invoked with. I assume that that directory does contain a git.exe? You may have some luck further debugging the cause of the error with a strace-like tool such as Process Monitor. No, C:\Temp\work\dl\git does not exist. :o ``` Directory of C:\Temp\work\dl 03/02/2020 22:20 . 03/02/2020 22:20 .. 03/02/2020 22:20 7z 03/02/2020 22:20 384,846 7za920.zip 03/02/2020 22:20 dm857-snn2074-optlink80017 03/02/2020 22:19 3,057,337 dm857c.zip 03/02/2020 22:20 dmd-2.079.0 03/02/2020 22:2020,614,650 dmd.2.074.0.windows.7z 03/02/2020 22:2041,903,965 dmd.2.079.0.windows.zip 4 File(s) 65,960,798 bytes 5 Dir(s) 42,867,355,648 bytes free ```
Re: digger: Failed to spawn new process (The system cannot find the file specified.)
On Monday, 3 February 2020 at 22:08:50 UTC, Vladimir Panteleev wrote: On Monday, 3 February 2020 at 22:01:18 UTC, Anonymouse wrote: No, C:\Temp\work\dl\git does not exist. :o OK, that makes sense. Please try the latest Digger version (24cd4168956dad382d05984b4b8d37d9e8ebe3ae). Works great. Thanks for your help!
Re: Some impressions/notes from a new D programmer
On Wednesday, 12 February 2020 at 13:36:13 UTC, mark wrote: Some cargo packages are applications. If I do 'cargo install someapp' it will be installed in $HOME/.cargo/bin. So by simply adding that to my PATH, I can easily use all installed rust apps. But dub doesn't appear to have an equivalent of this. There is 'dub run someapp', which is good enough for some cases, like digger[1]. But no 'dub install someapp', no. Maybe there are some hard design decisions again $HOME/.dub/bin, unsure. It might be difficult to globally pull off if programs expect the binary to be placed in the source tree (for resources). [1]: https://github.com/CyberShadow/Digger
Re: Overfflow in Assert error messages
On Thursday, 13 February 2020 at 07:49:13 UTC, Adnan wrote: However my test fails saying something like: source/binary_search.d(33): [unittest] 18446744073709551615 != 1 core.exception.AssertError@source/binary_search.d(33): 18446744073709551615 != 1 What's causing this underflow? It's ulong -1, which is the type idx is of on 64-bit systems. On 32-bit systems it will be uint -1 and say "4294967295 != 0". indexOf is probably not doing what you think it's doing. int indexOf(T)(const T[] list, const T key) { return -1; } void main() { int[] arr = [ 0 ]; foreach (idx, i; arr) assert(indexOf(arr, i) == idx); // 18446744073709551615 != 0 }
Re: How to get to body of HTTP 500 error with std.net.curl.get()?
On Saturday, 15 February 2020 at 16:25:42 UTC, Gregor Mückl wrote: Unfortunately, this is not true. The msg only contains the text information in the status line of the HTTP reply. If I'm not mistaken, the exception is created in this line in std/net/curl.d: enforce(statusLine.code / 100 == 2, new HTTPStatusException(statusLine.code, format("HTTP request returned status code %d (%s)", statusLine.code, statusLine.reason))); If anything is wrong, the server I'm interested in tends to reply with a status code 500 and a generic status line text and a bloated XML body containing the actual error message. Not that it answers your question but requests[1] can do this, if you don't mind adding some dependencies. Request req; Response res = req.get(urlRespondingWith500); assert(res.code == 500); writeln(res.responseBody); // Buffer!ubyte; use .to!string to get a string When testing to confirm I ran into a bug[2] where the body is sometimes empty, but outside of fringe cases it should work. [1]: https://code.dlang.org/packages/requests [2]: https://github.com/ikod/dlang-requests/issues/115
Re: How to get to body of HTTP 500 error with std.net.curl.get()?
On Sunday, 16 February 2020 at 09:13:54 UTC, ikod wrote: Just a note - this is not a bug, server really send empty body: < HTTP/1.1 500 Internal Server Error < cache-control: private < server: Microsoft-IIS/10.0 < x-aspnetmvc-version: 5.1 < access-control-allow-origin: * < x-aspnet-version: 4.0.30319 < request-context: appId=cid-v1:7585021b-2db7-4da6-abff-2cf23005f0a9 < access-control-expose-headers: Request-Context < x-powered-by: ASP.NET < date: Sat, 15 Feb 2020 20:44:03 GMT < content-length: 0 < 0 bytes of body received Yes, my bad. I was assuming curl's output was what was sent.
dub and -lowmem: does nothing
Manjaro/Arch x86_64, dmd v2.091.0, dub 1.19.0. I have a project which dmd on Windows fails to compile, throwing an OutOfMemoryError[1]. Up until recently it could be worked around by using `--build-mode=singleFile`, but now that's no longer enough and errors out too (on AppVeyor). The obvious solution is to set `-lowmem` in dub.sdl, but it seems to do nothing, as measured *in Linux* by the amount of memory used with zsh's `time` shell built-in. If using zsh time, you may need the following environmental variable to get the required output: ``` TIMEFMT='%J %U user %S system %P cpu %*E total avg shared (code): %X KB avg unshared (data/stack): %D KB total (sum): %K KB max memory:%M MB page faults from disk: %F other page faults: %R' ``` A gutted test branch: (has two dependencies) git clone https://github.com/zorael/tests.git -b lowmem 1. `dub build` on a default configuration without -lowmem defined shows some ~2011 Mb used. 2. If I run dub with -v, then copy the dmd command it runs and execute it manually, I get the same ~2012 Mb used. Close enough, makes sense. 3. `dub build -c lowmem` for an identical configuration but with dflags "-lowmem" added, nothing changes and I still get ~2011 Mb used. 4. If I run dub with -v on the lowmem configuration and copy/paste *the same command it ran*, unmodified, I suddenly get the more expected ~1183 Mb used. Log: https://pastebin.com/raw/yDnCj1KJ -lowmem is visibly present in the dmd command listed with -v, but it seems to do nothing through dub. How? Why? dub remove lu --version="*" dub remove dialect --version="*" [1]: https://issues.dlang.org/show_bug.cgi?id=20562
Re: dub and -lowmem: does nothing
On Saturday, 21 March 2020 at 00:17:37 UTC, kinke wrote: Most likely because dub doesn't actually invoke the listed command, but uses a response file to work around cmdline length limits. -lowmem in response files is ignored by DMD (needs to be parsed and set before druntime initialization, but response file parsing needs druntime + GC). It works for LDC though. So there is no way to do -lowmem with dub and dmd? I'm not having out-of-memory problems with ldc, luckily.
Re: How to create an array with custom length?
On Friday, 27 March 2020 at 19:30:39 UTC, Quantium wrote: Code int n=0; readf(" %d", &n); int[n] m; generated an error (DMD compiler): Cannot read n at compile time. How to create an array with custom length? The tour has a page for this: https://tour.dlang.org/tour/en/basics/arrays int n=0; readf(" %d", &n); int[] m = new int[n];
dub sourceFiles
I have a library package that I split up into subpackages, but I'm having to do mental gymnastics to make it only compile the files I want. The problem is that even if you specify some `sourceFiles`, it will build everything under the sun inside `sourcePaths`, which defaults to "source" or "src" depending on availability. There's no way to set it to an empty string, or something that doesn't exist. ```sdl name "stuff" targetType "library" subPackage { name "foo" sourceFiles \ "source/foo.d" } subPackage { name "bar" sourceFiles \ "source/bar.d" \ "source/common.d" } ``` $ dub build -v :foo [...] /usr/bin/dmd -Isource source/foo.d source/bar.d source/common.d Since I didn't specify any `sourcePaths`, it here defaults to "source" and my subpackage only asking for "foo.d" was handed all of the files anyway. What is the preferred solution here? 1. Use `excludedSourceFiles` and exclude files not to be compiled. Mental gymnastics needed when you have 12 files (the actual case). 2a. Keep source tree in something that isn't named "source" or "src", but keep an empty one around for dub to auto-include nothing from. I kind of want to avoid this. 2b. Keep real source files in "source", but declare `sourcePaths` to point to a dummy empty "ignoreme" directory. Crude but technically works. 3. Something else? Surely I'm not the first to run into this. I could set up the subpackages to each have its own directory (2a), but I'd end up with twelve, not including the empty "source" acting as bait for dub.
@safe function with __gshared as default parameter value
``` import std.stdio; @safe: __gshared int gshared = 42; void foo(int i = gshared) { writeln(i); } void main() { foo(); } ``` This currently works; `foo` is `@safe` and prints the value of `gshared`. Changing the call in main to `foo(gshared)` errors. Should it work, and can I expect it to keep working?
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 19:22:11 UTC, jmh530 wrote: On Wednesday, 8 April 2020 at 18:50:16 UTC, data pulverizer wrote: On Wednesday, 8 April 2020 at 16:53:05 UTC, Anonymouse wrote: ``` import std.stdio; @safe: __gshared int gshared = 42; void foo(int i = gshared) { writeln(i); } void main() { foo(); } ``` This currently works; `foo` is `@safe` and prints the value of `gshared`. Changing the call in main to `foo(gshared)` errors. Should it work, and can I expect it to keep working? According to the manual it shouldn't work at all https://dlang.org/spec/function.html#function-safety where it says Safe Functions: "Cannot access __gshared variables.", I don't know why calling as `foo()` works. You still wouldn't be able to manipulate gshared within the function. Though it may still be a problem for @safe... It works with `ref int` too. ``` __gshared int gshared = 42; void foo(ref int i = gshared) @safe { ++i; } void main() { assert(gshared == 42); foo(); assert(gshared == 43); } ```
Re: @safe function with __gshared as default parameter value
On Wednesday, 8 April 2020 at 19:53:03 UTC, jmh530 wrote: Well that definitely shouldn't happen. I would file a bug report. Filed as https://issues.dlang.org/show_bug.cgi?id=20726
docs.json is incomplete
I'm trying to get docs for my project hosted, and everything works, except there are entries missing. Looking at the generated docs.json there's simply a lot of omitted stuff. Example: http://kameloso.dpldocs.info/kameloso.plugins.sedreplace.html http://kameloso.dpldocs.info/source/kameloso.plugins.sedreplace.d.html https://zorael.github.io/kameloso/kameloso/plugins/sedreplace/SedReplacePlugin.html (TL;DR: the module contains one public class and (private) two structs, three free functions and one module-level mixin, but only the class is shown. I have more elaborate examples where some free functions make it and some don't, showing that public/private visibility is not the cause.) ```json { "kind": "module", "file": "source/kameloso/plugins/sedreplace.d", "members": [ { "line": 449, "kind": "class", "char": 7, "members": [], "name": "SedReplacePlugin", "interfaces": [ "kameloso.plugins.ircplugin.IRCPlugin" ], "comment": "[...]" }, { "line": 449, "kind": "class", "char": 7, "members": [], "name": "SedReplacePlugin", "interfaces": [ "kameloso.plugins.ircplugin.IRCPlugin" ], "comment": "[...]" }, { "line": 449, "kind": "class", "char": 7, "members": [], "name": "SedReplacePlugin", "interfaces": [ "kameloso.plugins.ircplugin.IRCPlugin" ], "comment": "[...]" }, { "line": 449, "kind": "class", "char": 7, "members": [], "name": "SedReplacePlugin", "interfaces": [ "kameloso.plugins.ircplugin.IRCPlugin" ], "comment": "[...]" } ], "comment": "[module ddoc ...]", "name": "kameloso.plugins.sedreplace" }, ``` The fact that it is listed four times seems to have to do with the use of `version(Something):` at the top of the module, to allow for opt-in enabling it based on dub build configuration. Commenting them out does not bring the missing stuff back. Is there a syntax error somewhere? I can't see it. Is the docs.json generator at fault?
Re: docs.json is incomplete
On Saturday, 11 April 2020 at 13:13:45 UTC, Adam D. Ruppe wrote: On Saturday, 11 April 2020 at 06:49:21 UTC, Anonymouse wrote: (TL;DR: the module contains one public class and (private) two structs, three free functions and one module-level mixin, but only the class is shown. It is all under a `private:` thing for this file. http://kameloso.dpldocs.info/source/kameloso.plugins.sedreplace.d.html#L34 Then there's a `public:` directly above the class. My doc generator skips private members unless you run the generator yourself and pass `-p` to the command line. This makes sense. I have more elaborate examples where some free functions make it and some don't, showing that public/private visibility is not the cause.) Have an example there? My parser has been known to get off track before on things and just give up on the rest of the file. The D parser I have is pretty hacky. Yes, http://kameloso.dpldocs.info/kameloso.plugins.seen.html. onBusMessage is private like the other functions, but it shows up. (Additionally the public imports are private.) In http://kameloso.dpldocs.info/kameloso.plugins.admin.html, http://kameloso.dpldocs.info/kameloso.plugins.automode.html, http://kameloso.dpldocs.info/kameloso.plugins.chatbot.html, http://kameloso.dpldocs.info/kameloso.plugins.connect.html, http://kameloso.dpldocs.info/kameloso.plugins.notes.html, ...; in nearly all modules listed in http://kameloso.dpldocs.info/kameloso.plugins.html private members are partly included. The idea is for every plugin module to only expose the public IRCPlugin class and hide the rest. Some, correctly then, only show the plugin (e.g. http://kameloso.dpldocs.info/kameloso.plugins.ctcp.html). The fact that it is listed four times seems to have to do with the use of `version(Something):` at the top of the module, to allow for opt-in enabling it based on dub build configuration. Commenting them out does not bring the missing stuff back. Is there a syntax error somewhere? I can't see it. Is the docs.json generator at fault? That repetition sounds like a bug in the other thing. Their weird handling of `version` is why I actually decided to write my own parser! my version at least shows it kinda sanely: version(WithSedReplacePlugin) class SedReplacePlugin : IRCPlugin {} Yeah, I like yours more, I just imagined it used docs.json too.
Re: Bug in std.json or my problem
On Wednesday, 22 April 2020 at 17:48:18 UTC, Craig Dillabaugh wrote: The crash is caused because the 'income' field with value 0.0 is output as 0 (rather than 0.0) and when it is read this is interpreted as an integer. Shouldn't this work? Yes, it's just buggy. Giving it a value of an even 1.0 will make it throw the same exception (js["income"].type is JSONType.integer), but a value of 1.1 will make it pass (.type properly becomes JSONType.float_). I don't know of a solution other than to check js["income"].type beforehand and use .floating or .integer as befits, or simply use an alternative JSON library (asdf?). File an issue if you have the time, maybe it will get attention. Unreported bugs can only be fixed by accident.
Re: Can't get dub dustmite to work
On Saturday, 25 April 2020 at 09:38:59 UTC, aliak wrote: Then I run this dub dustmite command: dub dustmite -b unittest ../dubdust --compiler-regex="never matches" I have had zero luck with dustmite via dub. I would honestly recommend that you create a shell script that does `dub test 2>&1 | grep "never matches"`, and just use that as a tester with dustmite directly.
Re: Can't get dub dustmite to work
On Sunday, 26 April 2020 at 22:05:20 UTC, aliak wrote: On Saturday, 25 April 2020 at 19:00:55 UTC, Anonymouse wrote: On Saturday, 25 April 2020 at 09:38:59 UTC, aliak wrote: Then I run this dub dustmite command: dub dustmite -b unittest ../dubdust --compiler-regex="never matches" I have had zero luck with dustmite via dub. I would honestly recommend that you create a shell script that does `dub test 2>&1 | grep "never matches"`, and just use that as a tester with dustmite directly. Ok I got it working with that but it resulted in the wrong output (it was a bad test case basically" But expanding the shell script to dub test 2>&1 | grep 'Error: static assert: \"handler #0 of type `Optional!(Exception) function(FailureContainer container) pure nothrow @nogc @safe` never matches\"' now results in ... Loading ./source/result/failure.d Loading ./source/result/package.d Loading ./source/result/result.d Loading ./tests/result.d None => No Hint: use --no-redirect to see test script output Hint: read https://github.com/CyberShadow/DustMite/wiki#initial-test-fails object.Exception@DustMite/dustmite.d(295): Initial test fails: Test script "dub test 2>&1 | grep 'Error: static assert: \"handler #0 of type never matches\"'" exited with exit code 1 (failure) ??:? _Dmain [0x10c56cf5e] This is the full dustmite command: dustmite --force . "dub test 2>&1 | grep 'Error: static assert: \"handler #0 of type `Optional!(Exception) function(FailureContainer container) pure nothrow @nogc @safe` never matches\"'" I'm not at the computer but I expect what's happening is backtick command substitution. It's difficult to get right since you want to nest quotes here, but you may be able to get around it by just escaping the backticks too. The easy solution is a shell script. I'll test it some more once I have something better to type on than the phone.
Compilation memory use
TL;DR: Is there a way to tell what module or other section of a codebase is eating memory when compiling? I'm keeping track of compilation memory use using zsh `time` with some environmental variables. It typically looks like this. ``` $ time dub build -c dev Performing "debug" build using /usr/bin/dmd for x86_64. [...] Linking... To force a rebuild of up-to-date targets, run again with --force. dub build -c dev 9.47s user 1.53s system 105% cpu 10.438 total avg shared (code): 0 KB avg unshared (data/stack): 0 KB total (sum): 0 KB max memory:4533 MB page faults from disk: 1 other page faults: 1237356 ``` So it tells me the maximum memory that was required to compile it all. However, it only tells me just that; there's no way to know what part of the code is expensive and what part isn't. I can copy dub's dmd command and run it with `-v` and try to infer that the modules that are slow to pass semantic3 are also the hungry ones. But are they? Is there a better metric?
Re: Is there a way to tell if an auto ref parameter is by ref or by value?
On Sunday, 10 May 2020 at 00:33:07 UTC, NaN wrote: Ie something like.. auto Foo(T)(auto ref T x) { static if (isByRef(x)) { } else { } } __traits(isRef, x)
Re: Dub platform probes
On Monday, 25 May 2020 at 22:58:54 UTC, Tim wrote: [...] Same here, but /tmp. $ ls /tmp/dub* | wc -l 174
Re: std.concurrency.receive and shared const(char)[]?
On Sunday, 28 June 2020 at 16:11:50 UTC, BakedPineapple wrote: import std.stdio; import std.concurrency; void main() { auto t = spawn((){ receive((shared const(char)[] char_arr) { ownerTid.send(true); }); }); shared const(char)[] char_arr = "cut my code into pieces"; t.send(char_arr); assert(receiveOnly!(bool) == true); } When I run this program, it blocks on the receive() inside the spawned thread. What am I doing wrong? Make the parameter shared(const(char))[] and it will work. I'll leave it to someone who knows more to explain why it behaves that way.
Re: Send empty assoc array to function
On Thursday, 9 July 2020 at 19:53:42 UTC, JN wrote: void foo(int[int] bar) { // ... } Is it possible to send an empty array literal? foo( [ 0 : 2 ] ) works foo( [] ) doesn't int[int] empty; foo(empty); works but it's two lines I always did foo((int[int]).init);
Re: getopt: How does arraySep work?
On Tuesday, 14 July 2020 at 11:12:06 UTC, Andre Pany wrote: [...] Steven Schveighoffer already answered while I was composing this, so discarding top half. As far as I can tell the default arraySep of "" splitting the argument by whitespace is simply not the case. https://github.com/dlang/phobos/blob/master/std/getopt.d#L923 // ... else static if (isArray!(typeof(*receiver))) { // array receiver import std.range : ElementEncodingType; alias E = ElementEncodingType!(typeof(*receiver)); if (arraySep == "") { *receiver ~= to!E(val); } else { foreach (elem; val.splitter(arraySep).map!(a => to!E(a))()) *receiver ~= elem; } } So you will probably want an arraySep of " " if you want --modelicalibs "a b".
Re: My RPN calculator code review?
On Friday, 17 July 2020 at 21:37:46 UTC, AB wrote: Hello, inspired by the "Tiny RPN calculator" example seen on the dlang homepage, I wanted to create my own version. I'd appreciate your opinions regarding style, mistakes/code smell/bad practice. Thank you. I generally don't know what I'm talking about, but nothing stands out as outright wrong. Style is unique from person to person. valid_ops is a compile-time constant and can be made an enum. I'm not happy about the looping and allocating replacements of spaced_args, but it's an easy solution where alternatives quickly become tricky or involve regular expressions (something like `spaced_args.matchAll("[0-9]+|[+*/-]".regex)`). Regex is neat but heavy. You can use std.algorithm.iteration.splitter instead of std.array.split to lazily foreach spaced_args. I don't know enough to say if `case [o]` will allocate at runtime. If so, it could be replaced with `case to!string(o)`, but maybe the compiler is smart enough to not consider [o] a runtime literal. For a program this short it doesn't really matter, but for a longer one it might be worth looking up. You're not checking for array size before slicing stack, and as such the program range errors out on operator-operand count mismatch. The rest is micro-optimisation and nit-picking. If valid_ops is an enum, you could foreach over it as an AliasSeq with a normal foreach (`foreach (o; aliasSeqOf!valid_ops)`; see std.meta). You could use std.array.Appender instead of appending to a real[]. etc.
Re: Cannot call @system funciton (stdout)
On Sunday, 16 August 2020 at 10:07:02 UTC, Simen Kjærås wrote: On Saturday, 15 August 2020 at 23:59:36 UTC, Joel wrote: ../../JMiscLib/source/jmisc/base.d(176,2): Error: @safe function jmisc.base.upDateStatus!string.upDateStatus cannot call @system function std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal /Library/D/dmd/src/phobos/std/stdio.d(4837,20): std.stdio.makeGlobal!"core.stdc.stdio.stdout".makeGlobal is declared here I got around it by avoiding 'stdout'. First, what's wrong with using writeln and friends instead of directly mucking about with stdout? :p Just as a drive-by comment, the main stdio thing I came across that I couldn't do from within @safe was stdout.flush(), which I need to call manually for Cygwin terminals and some terminals embedded in editors (vscode). If someone knows why, please tell me.
Introspecting a package for submodules
I have some modules, and then one `package.d` file that publicly imports them all. I have reason to access them individually however, with hopes of being able to enumerate them and introspect with `__traits(allMembers, someModule)`. Concretely, I want to express "find all module-level classes in all submodules of this package". As an analogy, I have `std.algorithm` and I want to programmatically get `std.algorithm.comparison`, `std.algorithm.iteration`, `std.algorithm.mutation`, etc -- either as symbols or as strings. `__traits(allMembers, std.algorithm)` evaluates to nothing, but replace it with `std.algorithm.searching` and it does. How do I do this? (Is there some other way?)
Re: Introspecting a package for submodules
On Monday, 24 August 2020 at 22:32:52 UTC, Anonymouse wrote: `__traits(allMembers, std.algorithm)` evaluates to nothing, but replace it with `std.algorithm.searching` and it does. `std.algorithm` makes for a bad example as it is actually empty save for imports. Just read it as `std.datetime` please, which has struct members. `__traits(allMembers, std.datetime)` evaluates to nothing, but replace it with `std.datetime.systime` and it does. This makes everything really difficult. Is it intentional? https://run.dlang.io/is/UAHiAo
Re: Cannot call @system funciton (stdout)
On Tuesday, 18 August 2020 at 06:25:31 UTC, Kagamin wrote: On Sunday, 16 August 2020 at 18:13:07 UTC, Anonymouse wrote: Just as a drive-by comment, the main stdio thing I came across that I couldn't do from within @safe was stdout.flush(), which I need to call manually for Cygwin terminals and some terminals embedded in editors (vscode). If someone knows why, please tell me. Cygwin terminals are not recognized as terminals, you should set line buffered mode, then it will flush every line. How do I do this?
Re: Cannot call @system funciton (stdout)
On Saturday, 19 September 2020 at 13:32:07 UTC, Paul Backus wrote: On Saturday, 19 September 2020 at 13:23:29 UTC, Anonymouse wrote: On Tuesday, 18 August 2020 at 06:25:31 UTC, Kagamin wrote: On Sunday, 16 August 2020 at 18:13:07 UTC, Anonymouse wrote: Just as a drive-by comment, the main stdio thing I came across that I couldn't do from within @safe was stdout.flush(), which I need to call manually for Cygwin terminals and some terminals embedded in editors (vscode). If someone knows why, please tell me. Cygwin terminals are not recognized as terminals, you should set line buffered mode, then it will flush every line. How do I do this? http://dpldocs.info/experimental-docs/std.stdio.File.setvbuf.1.html Thanks. I don't have a clone of druntime/Phobos available to me right now, so some follow-up questions. It looks like full buffering _IOFBF is the default setting, but "normal" non-Cygwin stdio certainly seems to do line buffering. Is it getting set to line buffering _IOLBF during initialisation of stdout? (Why then is Cygwin exempt?) Is there a way to detect programmatically if I'm in an environment where I need to manually set line buffering?
Re: Cannot call @system funciton (stdout)
On Saturday, 19 September 2020 at 14:14:46 UTC, Paul Backus wrote: You can check the TERM environment variable [2], or you can use the POSIX uname() function [3] to see if you're running under Cygwin specifically. If there are any other environments where you need to manually set line-buffering, you'll probably have to check for those individually as well. All right, thanks. Yes, currently I'm doing the TERM and uname thing on program start and flushing manually after every writeln if I detected Cygwin or vscode. I think I can work with this.
Re: Cannot call @system funciton (stdout)
On Saturday, 19 September 2020 at 14:08:39 UTC, Adam D. Ruppe wrote: On Saturday, 19 September 2020 at 13:56:53 UTC, Anonymouse wrote: Is there a way to detect programmatically if I'm in an environment where I need to manually set line buffering? Part of the problem is the IDE console and cygwin too I believe both *look* like a pipe to the program instead of like an interactive terminal, thus why it gets block instead of line buffered. Someone once told me of a trick to detect cygwin specifically but I can't access it right now and I'm not sure it would work reliably anyway Just yeah set your expectations low because if it was easy to tell programmatically the libc would already do it right. Also makes sense, thanks. I already expose the option to force flushing with a --flush command-line argument, so I guess I'll keep that around (but use setvbuf when the TERM/uname thing detects a whitelisted environment).
Re: Struct initializer in UDA
On Saturday, 26 September 2020 at 16:05:58 UTC, realhet wrote: Hi, struct S{int a, b, c=9, d, e, f;} Is there a way or a trick to declare an UDA by using a nice struct initializer? It would be nice to be able to use the form: @S{f:42} int a; //or something similar to this. instead of this longer and error-prone way: @S(0, 0, 0, 9, 0, 42) int a; I don't think you can currently, no, but I'd be happy to be proven wrong. The closest I can get is @(S.init.c(9).f(42)) with use of opDispatch, which is easier to read but still ugly.
Re: Struct initializer in UDA
On Sunday, 27 September 2020 at 10:17:39 UTC, realhet wrote: On Saturday, 26 September 2020 at 17:13:17 UTC, Anonymouse wrote: On Saturday, 26 September 2020 at 16:05:58 UTC, realhet wrote: The closest I can get is @(S.init.c(9).f(42)) with use of opDispatch, which is easier to read but still ugly. All I can get is that the - an identifier of a member is stronger than the opDispatch. -> Error: function expected before (), not S(0, 0).c of type int - and if I prefix it with '_' it ruins toString. -> Error: no property toString for type onlineapp.S import std.stdio, std.range, std.algorithm, std.traits, std.meta, std.conv, std.string, std.uni, std.meta, std.functional, std.exception; struct S{ int a, b; auto opDispatch(string name, T)(T value) if(name.startsWith("_")) { mixin(name[1..$], "= value;"); return this; } } void main(){ S.init._a(5).writeln; } Now I'm more confused, as the compiler completely ignores the if(name.startsWith("_")) constraint o.O It works if you specialise opDispatch to take an int parameter instead of a type T. It smells like a bug but I don't know enough to say. I used two opDispatches to be able to avoid having to use _a and _b, and std.algorithm.comparison.among to constrain them. struct S{ private int _a, _b; auto opDispatch(string name)(int value) if (name.among("a", "b")) { mixin("_", name, "= value;"); return this; } auto opDispatch(string name)() if (name.among("a", "b")) { mixin("return _", name, ";"); } } void main(){ S.init.a(123).b(456).writeln; S().b(456).a(123).writeln; // Alternative syntax, may not work if opCall is defined } It's brittle in that you have to update and sync the two among("a", "b") constraints every time you add or remove a field, but I can't seem to get the names by introspection without it endlessly recursing over opDispatch again.
Re: Safe to remove AA elements while iterating over it via .byKeyValue?
On Sunday, 27 September 2020 at 13:02:04 UTC, Per Nordlöw wrote: Is it safe to remove AA-elements from an `aa` I'm iterating over via aa.byKeyValue? I'm currently doing this: foreach (ref kv; aa.byKeyValue) { if (pred(kv.key)) aa.remove(kv.key); // ok? } if (aa.length == 0) aa = null; Is there a better way? The boring way is to store an array of the spent keys and remove afterwards. KeyType!(typeof(aa))[] garbage; garbage.reserve(aa.length); foreach (ref kv; aa.byKeyValue) { if (pred(kv.key)) garbage ~= kv.key; } foreach (const key; garbage) { aa.remove(key); } This works with normal arrays too (and std.algorithm.mutation.remove), if you foreach_reverse the garbage array.
Taking arguments by value or by reference
I'm passing structs around (collections of strings) whose .sizeof returns 432. The readme for 2.094.0 includes the following: This release reworks the meaning of in to properly support all those use cases. in parameters will now be passed by reference when optimal, [...] * Otherwise, if the type's size requires it, it will be passed by reference. Currently, types which are over twice the machine word size will be passed by reference, however this is controlled by the backend and can be changed based on the platform's ABI. However, I asked in #d a while ago and was told to always pass by value until it breaks, and only then resort to ref. [18:32:16] at what point should I start passing my structs by ref rather than by value? some are nested in others, so sizeofs range between 120 and 620UL [18:33:43] when you start getting stack overflows [18:39:09] so if I don't need ref for the references, there's no inherent merit to it unless I get in trouble without it? [18:39:20] pretty much [18:40:16] in many cases the copying is merely theoretical and doesn't actually happen when optimized I've so far just been using const parameters. What should I be using?