Re: D : dmd vs gdc : which one to choose?
On Thursday, 19 February 2015 at 08:46:11 UTC, Mayuresh Kathe wrote: Should I choose DMD or go with GDC? I work with projects whose code is half written in C, half written in D. I use GNU make to build them. I found out that using GDC was a much better choice for several reasons: - project portability 1: under Windows, dmd generates OMF object files that can't be linked by the gcc linker, while gdc generates COFF objet files. Which means: - I can use the same Makefile regardless of the target OS. - I can link mingw-compiled C code with D code. - I avoid the struggle of finding OMF versions of "SDL.lib", "advapi32.lib", etc. - project portability 2: stupid detail, but the weird dmd way of specifying the output file in the command line ( "dmd -ofmyfile.o" ) defeats the heuristics of MSYS2 path conversion. That's a dealbreaker for me. - when I'm running Debian/Ubuntu, the simple ability to natively run "apt-get install gdc" to install/upgrade is very practical. As dmd's compilation speed is blazingly fast, it remains a cool way of writing automation scripts (#!/bin/usr/env rdmd), much better, in my opinion, than Bash, or even Python.
Re: How to make Application bundle from Executable? (Mac)
On Friday, 20 February 2015 at 06:10:51 UTC, Nicholas Wilson wrote: On Friday, 20 February 2015 at 03:26:47 UTC, Gan wrote: Also I can't get my application to load images that I place in the Resources folder(or any folder in the bundle for that matter). I suggest to have a look at the projects generated by SFML regarding locating the resources in C++/ObjC and translate them to C/ObjC/D. As for code (i.e frameworks and .dylibs) i don't know as shared libraries are still a murky area for D. Probably just better to stick to static libs. Is there an official way to turn a D executable into a Mac Application Bundle? Dunno Good luck! Frameworks aren't an issue, I put them into the Frameworks folder in my hand made bundle and they load fine. When running the executable, it loads the image when it's in the same folder but when running the executable through the bundle, it doesn't find the image anywhere.
Re: How to make Application bundle from Executable? (Mac)
On Friday, 20 February 2015 at 03:26:47 UTC, Gan wrote: Also I can't get my application to load images that I place in the Resources folder(or any folder in the bundle for that matter). I suggest to have a look at the projects generated by SFML regarding locating the resources in C++/ObjC and translate them to C/ObjC/D. As for code (i.e frameworks and .dylibs) i don't know as shared libraries are still a murky area for D. Probably just better to stick to static libs. Is there an official way to turn a D executable into a Mac Application Bundle? Dunno Good luck!
Re: How to make Application bundle from Executable? (Mac)
On Friday, 20 February 2015 at 03:26:47 UTC, Gan wrote: I managed to copy an application bundle and change stuff inside it to run my executable, but it was very manual and kinda hackish. Also I can't get my application to load images that I place in the Resources folder(or any folder in the bundle for that matter). Is there an official way to turn a D executable into a Mac Application Bundle? I don't have an answer, but I too am interested in hearing what others have to say about this.
Re: vibe-d basic build errors
On Friday, 20 February 2015 at 04:13:08 UTC, MartinNowak wrote: On Friday, 20 February 2015 at 04:00:21 UTC, Charles wrote: Yes, I have. Here's a pastebin with --force --vverbose: http://pastebin.com/qZEKUN46 Just tried the dub init web vibe.d && cd web && dub thing, works for me. So the most interesting questions. - What version of dub and dmd are you using? - Are those installer versions or did you build anything yourself? They're installer versions, dub is 0.9.22 Nov 22 I want to say, and DMD is 2.066.1
Re: vibe-d basic build errors
On Friday, 20 February 2015 at 04:00:21 UTC, Charles wrote: Yes, I have. Here's a pastebin with --force --vverbose: http://pastebin.com/qZEKUN46 Just tried the dub init web vibe.d && cd web && dub thing, works for me. So the most interesting questions. - What version of dub and dmd are you using? - Are those installer versions or did you build anything yourself?
Re: vibe-d basic build errors
On Friday, 20 February 2015 at 02:55:32 UTC, MartinNowak wrote: On Friday, 20 February 2015 at 02:50:05 UTC, Charles wrote: Pastebin of dub --vverbose: http://pastebin.com/4BcHJM74 Target vibe-d 0.7.22 is up to date. Use --force to rebuild. Have you tried the --force switch to rebuild vibe.d? Looks like the existing vibe.d lib was build against a different build of druntime. Yes, I have. Here's a pastebin with --force --vverbose: http://pastebin.com/qZEKUN46
How to make Application bundle from Executable? (Mac)
I managed to copy an application bundle and change stuff inside it to run my executable, but it was very manual and kinda hackish. Also I can't get my application to load images that I place in the Resources folder(or any folder in the bundle for that matter). Is there an official way to turn a D executable into a Mac Application Bundle?
Re: vibe-d basic build errors
On Friday, 20 February 2015 at 02:50:05 UTC, Charles wrote: Pastebin of dub --vverbose: http://pastebin.com/4BcHJM74 Target vibe-d 0.7.22 is up to date. Use --force to rebuild. Have you tried the --force switch to rebuild vibe.d? Looks like the existing vibe.d lib was build against a different build of druntime.
vibe-d basic build errors
Hi, I'm trying to follow the instructions for vibe-d with: >dub init web vibe.d >cd web >dub and then add the line "subConfigurations": {"vibe-d": "win32"}" to the dub.json file. This however is producing errors during linking. Could I get a hand? Pastebin of dub --vverbose: http://pastebin.com/4BcHJM74 Thanks, Charles
Re: D : dmd vs gdc : which one to choose?
On 20/02/2015 3:11 p.m., ketmar wrote: On Fri, 20 Feb 2015 02:08:19 +, ketmar wrote: On Fri, 20 Feb 2015 13:29:09 +1300, Rikki Cattermole wrote: On 20/02/2015 5:08 a.m., ketmar wrote: On Thu, 19 Feb 2015 22:10:11 +1300, Rikki Cattermole wrote: And anyway, GDC is still hasn't been updated to the latest version of D. And its the last major D compiler that hasn't. LDC is 2.067 already? O_O 'cause GDC is 2.066.1 now. Well according to GDC releases, it is still at 2.065. https://github.com/D-Programming-GDC/GDC/releases I was referring to full releases, not e.g. betas. what is that "full release"? those tarballs are just convient packs for those who don't know what to type after "git" command. 2.066.1 is officially landed in git HEAD some time ago, Iain just didn't wrote "whatsnew" for it (and Johannes wanted to land some ARM fixes). it's not "beta", at least not on x86. but is that release blah-blah really necessary to build the 2.066.1 version from official git? oh. sorry if i was too aggressive, i didn't want to attack you. at least not in D.learn. ;-) There is also no tags for said versions. Or how about http://gdcproject.org/downloads
Re: D : dmd vs gdc : which one to choose?
On Fri, 20 Feb 2015 02:08:19 +, ketmar wrote: > On Fri, 20 Feb 2015 13:29:09 +1300, Rikki Cattermole wrote: > >> On 20/02/2015 5:08 a.m., ketmar wrote: >>> On Thu, 19 Feb 2015 22:10:11 +1300, Rikki Cattermole wrote: >>> And anyway, GDC is still hasn't been updated to the latest version of D. And its the last major D compiler that hasn't. >>> >>> LDC is 2.067 already? O_O 'cause GDC is 2.066.1 now. >> >> Well according to GDC releases, it is still at 2.065. >> https://github.com/D-Programming-GDC/GDC/releases I was referring to >> full releases, not e.g. betas. > > what is that "full release"? those tarballs are just convient packs for > those who don't know what to type after "git" command. 2.066.1 is > officially landed in git HEAD some time ago, Iain just didn't wrote > "whatsnew" for it (and Johannes wanted to land some ARM fixes). it's not > "beta", at least not on x86. but is that release blah-blah really > necessary to build the 2.066.1 version from official git? oh. sorry if i was too aggressive, i didn't want to attack you. at least not in D.learn. ;-) signature.asc Description: PGP signature
Re: D : dmd vs gdc : which one to choose?
On Fri, 20 Feb 2015 13:29:09 +1300, Rikki Cattermole wrote: > On 20/02/2015 5:08 a.m., ketmar wrote: >> On Thu, 19 Feb 2015 22:10:11 +1300, Rikki Cattermole wrote: >> >>> And anyway, GDC is still hasn't been updated to the latest version of >>> D. >>> And its the last major D compiler that hasn't. >> >> LDC is 2.067 already? O_O 'cause GDC is 2.066.1 now. > > Well according to GDC releases, it is still at 2.065. > https://github.com/D-Programming-GDC/GDC/releases I was referring to > full releases, not e.g. betas. what is that "full release"? those tarballs are just convient packs for those who don't know what to type after "git" command. 2.066.1 is officially landed in git HEAD some time ago, Iain just didn't wrote "whatsnew" for it (and Johannes wanted to land some ARM fixes). it's not "beta", at least not on x86. but is that release blah-blah really necessary to build the 2.066.1 version from official git? signature.asc Description: PGP signature
Re: D : dmd vs gdc : which one to choose?
On 20/02/2015 5:08 a.m., ketmar wrote: On Thu, 19 Feb 2015 22:10:11 +1300, Rikki Cattermole wrote: And anyway, GDC is still hasn't been updated to the latest version of D. And its the last major D compiler that hasn't. LDC is 2.067 already? O_O 'cause GDC is 2.066.1 now. Well according to GDC releases, it is still at 2.065. https://github.com/D-Programming-GDC/GDC/releases I was referring to full releases, not e.g. betas.
Re: Problem Instantiating a BinaryHeap with a Comparison Function the needs this
On Thursday, 19 February 2015 at 14:12:51 UTC, Tobias Pankrath wrote: On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote: Please provide reduced examples. This fails: class C { int[] a; alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } This works: class C { int[] a; void foo() { alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } } But will create an instance of BinaryHeap per member function. What to do? Dunno. I modified my algorithm to be more like http://rosettacode.org/wiki/Dijkstra%27s_algorithm#D which doesn't require a special comparison function for RedBlackTree. See update at: https://github.com/nordlow/justd/blob/master/knet/traversal.d#L108 Thanks anyway.
Re: GC deadlocks on linux
On Thu, 19 Feb 2015 17:12:02 -0500, Steven Schveighoffer wrote: > On 2/19/15 12:01 PM, ketmar wrote: >> On Thu, 19 Feb 2015 16:33:58 +, Byron Heads wrote: >> >>> Now I am not sure. This code runs correctly: >> >> as i told you before, `fork()` is hard. you can experiment for monthes >> seeing strange bugs here and there, and seeing no bugs, and strange >> bugs, >> and... > > >> there are alot of things going on under the hood, and alot of things >> aren't. strictly speaking you *CAN'T* get cloned process in the same >> state as it's parent. it may work, though, if stars are in a good >> shape. > > Just as an example, Sociomantic uses a concurrent GC based on forking. it's completely different thing. *this* use of fork -- to make "snapshot" of running application -- is perfectly ok. > I'm not sure what the issue here is, but I don't think forking is as > unstable as you seem to think, or maybe I'm reading this wrong. I can > agree there are many gotchas with forking. forking is stable -- in the sense that it's doing exactly what it was asked to do. but that can be something different from what someone *think* it should do. `fork()` is described as "making a copy of the running process", and it's right... for some extent. but what "copy" is exactly? all threads except the one are lost. pid and tid was changed. what about signal masks? and thousands of other things which are taken as granted -- thread locks, for example, which can store tid of the thread that was aquired the lock? what about other libraries, which can do things you don't know about? and so on... sure, `fork()` is perfectly usable... when you know what is going on and can foresee all consequences. but it's hard, and i'd better recommend to avoid `fork()` at all if programmer is not closely familiar with the thing. in most cases avoiding `fork()` is much easier than trying to find out what (can/is) going wrong with the program that was working ok without forking. what i trying to tell OP is that if his code working ok without forking, it's much easier to just go this way and forget about `fork()`, not wasting time to find out what is wrong with it. signature.asc Description: PGP signature
Re: GC deadlocks on linux
On 2/19/15 12:01 PM, ketmar wrote: On Thu, 19 Feb 2015 16:33:58 +, Byron Heads wrote: Now I am not sure. This code runs correctly: as i told you before, `fork()` is hard. you can experiment for monthes seeing strange bugs here and there, and seeing no bugs, and strange bugs, and... there are alot of things going on under the hood, and alot of things aren't. strictly speaking you *CAN'T* get cloned process in the same state as it's parent. it may work, though, if stars are in a good shape. Just as an example, Sociomantic uses a concurrent GC based on forking. I'm not sure what the issue here is, but I don't think forking is as unstable as you seem to think, or maybe I'm reading this wrong. I can agree there are many gotchas with forking. -Steve
Re: Is this a bug in dmd 2.067 for struct initializers?
On Thursday, 19 February 2015 at 07:46:51 UTC, Ali Çehreli wrote: On 02/18/2015 10:39 PM, stewarth wrote: > This works under dmd 2066.1 but fails under dmd 2.067-b2. I don't know whether it is a bug. > struct B { > A* a; In any case, that must be immutable(A)*. > } > > static immutable B[] someB = [{a:&someA[0]}, {a:&someA[1]}]; > I want it to initialize at runtime before main(). I don't > actually want any CTFE stuff here. Then you need 'static this()' (or 'shared static this()'): static immutable B[] someB; static this() { someB = [ B(&someA[0]), B(&someA[1]) ]; } Note that I could not use the named member syntax because in my case the compiler cannot know what the right-hand side expression is. However, it is still possible with a temporary where the type is explicit as in your case: static this() { immutable B[] tmp = [ {a:&someA[0]}, {a:&someA[1]} ]; someB = tmp; } Ali Hi Ali, Thanks for the help. I've gone with "static this()" approach and it works. In a way it's cleaner because it's explicit that these variables are only initialised at runtime before d_main(). At least that's how I understand things :) It would be nice if the named syntax also worked in static this(), maybe I'll file an ER for it. I'm a big fan of the whole named args thing in Python, which from a quick search has been discussed before in the forums. Cheers, Stew
Re: C++ calling convention only
On Thursday, 19 February 2015 at 21:33:50 UTC, John Colvin wrote: On Thursday, 19 February 2015 at 18:25:10 UTC, Benjamin Thaut wrote: Is it possible to declare a function in D which gets the C++ calling convetion but not the C++ mangling? Kind Regards Benjamin Thaut You can use pragma(mangle, ...) to set whatever mangling you like. I would duplicate the declaration, once without extern(C++), once with, the use the .mangleof from the 1st to set the mangle of the 2nd with pragma(mangle
Re: C++ calling convention only
On Thursday, 19 February 2015 at 18:25:10 UTC, Benjamin Thaut wrote: Is it possible to declare a function in D which gets the C++ calling convetion but not the C++ mangling? Kind Regards Benjamin Thaut You can use pragma(mangle, ...) to set whatever mangling you like.
Re: State of Windows x64 COFF support?
On 2015-02-19 1:41 PM, ketmar wrote: i remember that DMD creates one section for each function (to allow smartlink feature). with templates this can be alot. maybe it needs new cli flag "--collapse-sections" or something like it. I watched the section names and discovered over 20,000 sections named : .debug$S According to the code, a new .debug$S section is created every time it is searched with the flag IMAGE_SCN_LNK_COMDAT in: https://github.com/D-Programming-Language/dmd/blob/de6fccf8391b1dfdb959fa0f089920c2c8e6aff8/src/backend/mscoffobj.c#L1724 I deleted this flag and now the program links correctly with COFF with <50k sections. It would have been easier to debug with an error in mscoffobj.c:1591: assert(scnhdr_cnt < 65536, "Too many symbols for COFF format"); https://github.com/D-Programming-Language/dmd/blob/de6fccf8391b1dfdb959fa0f089920c2c8e6aff8/src/backend/mscoffobj.c#L1591 With this simple patch on the compiler, there are stil some errors compiling Botan on win64, but they are not related to the COFF format anymore.
Re: Is this possible in D?
On Thursday, 19 February 2015 at 17:23:47 UTC, Mike Parker wrote: I agree that string mixins can kill readability. I encountered that when I used them to support both D1 and D2 in Derelict 2 years ago. But I think that when they are kept small and local as in cases like this, they aren't bad at all. Thanks for your example. It's ugly but it's the only solution I've seen that gives me what I'm looking for. I hadn't thought about putting the function body inside a q{ string }
each extern (C) keyword causes ld (OS X) to add a duplicate library entry
Note the last two lines of this list (i am running OS X 10.10.2 and Xcode 6.1.1): clang -v -t cprog.c dprog.a -o cprog Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.1.0 Thread model: posix "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name cprog.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -fdebug-compilation-dir /Users/ernest/dev/inquiries/c_and_d -ferror-limit 19 -fmessage-length 146 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/gc/yfwyjyhn5b15xrsym2fyz6hr000327/T/cprog-897189.o -x c cprog.c clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.1.0 ignoring nonexistent directory "/usr/local/include" #include "..." search starts here: #include <...> search starts here: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list. "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -t -o cprog /var/folders/gc/yfwyjyhn5b15xrsym2fyz6hr000327/T/cprog-897189.o dprog.a -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a /var/folders/gc/yfwyjyhn5b15xrsym2fyz6hr000327/T/cprog-897189.o /usr/lib/libSystem.dylib /usr/lib/system/libcache.dylib /usr/lib/system/libcommonCrypto.dylib ... dprog.a(dprog_1_487.o) dprog.a(dprog_2_495.o) cprog.c includes two symbols exported from dprog.a, which uses the extern(C) keyword on the two functions exported from dprog.a when i remove one of the extern(C) keywords from dprog.a, ld lists only one dprog.a(dprog_x_x.o) at the end should ld be listing multiple instances of dprog.a when dprog.a uses multiple extern C symbols? i built dprog.a with dmd v2.066.1 i didnt include the listings to make this inquiry short, but i can add them if it would help (im new here, and i dont to annoy folks too much)
Re: State of Windows x64 COFF support?
On Thu, 19 Feb 2015 13:29:58 -0500, Etienne wrote: > On 2015-02-19 11:39 AM, Etienne wrote: >> I'm having corrupt symbol table errors on a Win64 build of a big >> application, I can't find a way around it. I'm wondering if the COFF >> support is still experimental in DMD? >> >> Thanks! > > I just counted 67k sections using a printf in DMD... The limit is 65k so > that explains that. i remember that DMD creates one section for each function (to allow smartlink feature). with templates this can be alot. maybe it needs new cli flag "--collapse-sections" or something like it. signature.asc Description: PGP signature
Re: State of Windows x64 COFF support?
On 2015-02-19 11:39 AM, Etienne wrote: I'm having corrupt symbol table errors on a Win64 build of a big application, I can't find a way around it. I'm wondering if the COFF support is still experimental in DMD? Thanks! I just counted 67k sections using a printf in DMD... The limit is 65k so that explains that.
C++ calling convention only
Is it possible to declare a function in D which gets the C++ calling convetion but not the C++ mangling? Kind Regards Benjamin Thaut
Re: Undefined symbol?
On Thursday, 19 February 2015 at 01:29:39 UTC, Tofu Ninja wrote: I am not sure what could be the offending obj. I re downloaded dmd and phobos(pre compiled for windows), cleaned out all my builds and removed all of the tempfiles for dub that I could find. Have you tried running dub with --force?
Re: Is this possible in D?
On 2/20/2015 1:06 AM, tcak wrote: @OP: By using a token string (q{}) for funcBody rather than a WYSIWYG string (r"" or ``), you can still get syntax highlighting in your editor. Based on your example, bye bye readibility. It is like writing rocket taking off procedures. People are complaining about different parts of D languages some structures (there are good ones, there are bad ones), but unfortunately, bad ones are continuously ignored in the name of trying to reach the language a stability. I agree that string mixins can kill readability. I encountered that when I used them to support both D1 and D2 in Derelict 2 years ago. But I think that when they are kept small and local as in cases like this, they aren't bad at all.
Re: GC deadlocks on linux
On Thu, 19 Feb 2015 16:33:58 +, Byron Heads wrote: > Now I am not sure. This code runs correctly: as i told you before, `fork()` is hard. you can experiment for monthes seeing strange bugs here and there, and seeing no bugs, and strange bugs, and... there are alot of things going on under the hood, and alot of things aren't. strictly speaking you *CAN'T* get cloned process in the same state as it's parent. it may work, though, if stars are in a good shape. i can give you a simple test that will tell you if you should avoid `fork ()` in your code: unless you can explain what is going on in kernel, glibc, pthreads and druntime exactly in the moment of forking, without looking to mans, documentation and source code of all components -- avoid using `fork()`. i can explain ~2/3, so i'm not using `fork()` in my code. ;-) signature.asc Description: PGP signature
State of Windows x64 COFF support?
I'm having corrupt symbol table errors on a Win64 build of a big application, I can't find a way around it. I'm wondering if the COFF support is still experimental in DMD? Thanks!
Re: GC deadlocks on linux
On Wednesday, 18 February 2015 at 21:21:11 UTC, Byron Heads wrote: On Wednesday, 18 February 2015 at 21:05:10 UTC, Byron Heads wrote: On Wednesday, 18 February 2015 at 20:55:56 UTC, ketmar wrote: On Wed, 18 Feb 2015 20:35:44 +, Byron Heads wrote: On Wednesday, 18 February 2015 at 20:33:40 UTC, ketmar wrote: On Wed, 18 Feb 2015 20:27:07 +, Byron Heads wrote: are you forking? ;-) I am in the daemonize library https://github.com/NCrashed/daemonize can you drop that and just let the program run on foreground? i suspect that it may solve your problem. you can detach your program with "setsid" and "&" to avoid forking. `fork()` is a very fragile thing, and it may be the source of heisenbugs. stop `fork()`ing may be the easiest solution (if it solves something, of course ;-). By passing daemonize with the GC enabled is working.. going to dig into the signals and see if thats it. My guess is this is going to be related to forking, going to see if I can make a test case. Now I am not sure. This code runs correctly: import std.stdio; import std.concurrency; import core.sys.posix.unistd; import core.sys.posix.sys.stat; import core.memory; import std.c.linux.linux; extern(C) nothrow { int __libc_current_sigrtmin(); int close(int rd); } void foo(Tid tid) { writeln("1"); foreach(i; 0..1024) { ubyte[] buffer = new ubyte[](8_192); auto f = new float[1024]; GC.collect; } writeln("2"); send(tid, true); } extern(C) void sigsig(int sig) nothrow pure @system @nogc { } void main() { auto pid = fork(); if(pid < 0) { writeln("fork failed"); } if (pid > 0) { writeln("Spawned ", pid); return; } umask(0); auto sid = setsid(); if(sid < 0) { writeln("failed to set sid"); } assert(signal(SIGABRT, &sigsig) != SIG_ERR); assert(signal(SIGTERM, &sigsig) != SIG_ERR); assert(signal(SIGQUIT, &sigsig) != SIG_ERR); assert(signal(SIGINT, &sigsig) != SIG_ERR); assert(signal(SIGQUIT, &sigsig) != SIG_ERR); assert(signal(SIGHUP, &sigsig) != SIG_ERR); assert(signal(__libc_current_sigrtmin+1, &sigsig) != SIG_ERR); writeln("spawning"); spawn(&foo, thisTid); spawn(&foo, thisTid); spawn(&foo, thisTid); foreach(i; 0..1024) { auto x = new long[1024]; GC.collect; } receiveOnly!bool; receiveOnly!bool; receiveOnly!bool; GC.collect; writeln("done"); }
Re: Is this possible in D?
On Thu, 19 Feb 2015 08:24:06 +, Jonathan Marler wrote: > I am having a heck of a time trying to figure out how to do this. > How do I change the attributes of a function based on the > version without copying the function body? For example: > > version(StaticVersion) { > static void myLongFunction() > { > // long body ... > } > } else { > void myLongFunction() > { > // same long body copied... > } > } > > In one version I want the function to be static and in another I don't > want it to be static. I cannot figure out how to do this without > copy/pasting the entire function body to both versions. you can turn `myLongFunction()` to a template `myLongFunctionImlp()()`, and then simply declare `myLongFunction()` with required attributes, simply instantiating template in it's body. signature.asc Description: PGP signature
Re: Is this possible in D?
On Thursday, 19 February 2015 at 12:16:18 UTC, Mike Parker wrote: On Thursday, 19 February 2015 at 10:17:47 UTC, Dicebot wrote: Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version): I really like mixins for this sort of thing. ``` enum signature = "void longFunction()"; version( Static ) enum sig = "static " ~ signature; else alias sig = signature; enum funcBody = q{{ import std.stdio : writeln; writeln( "Hi there!" ); version( Static ) writeln( "I'm static!" ); }}; struct Mixed { mixin(sig ~ funcBody); } void main() { version( Static ) Mixed.longFunction(); else { Mixed m; m.longFunction(); } } ``` @OP: By using a token string (q{}) for funcBody rather than a WYSIWYG string (r"" or ``), you can still get syntax highlighting in your editor. Based on your example, bye bye readibility. It is like writing rocket taking off procedures. People are complaining about different parts of D languages some structures (there are good ones, there are bad ones), but unfortunately, bad ones are continuously ignored in the name of trying to reach the language a stability.
Re: D : dmd vs gdc : which one to choose?
On Thu, 19 Feb 2015 22:10:11 +1300, Rikki Cattermole wrote: > And anyway, GDC is still hasn't been updated to the latest version of D. > And its the last major D compiler that hasn't. LDC is 2.067 already? O_O 'cause GDC is 2.066.1 now. signature.asc Description: PGP signature
Re: Problem Instantiating a BinaryHeap with a Comparison Function the needs this
On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote: Please provide reduced examples. This fails: class C { int[] a; alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } This works: class C { int[] a; void foo() { alias BH = BinaryHeap!(int[], (x, y) => (x+a < y)); } } But will create an instance of BinaryHeap per member function. What to do? Dunno.
Re: Problem Instantiating a BinaryHeap with a Comparison Function the needs this
On Thursday, 19 February 2015 at 11:56:19 UTC, Nordlöw wrote: I can understand how to correctly define an instance of BinaryHeap in my class DijkstraWalker at https://github.com/nordlow/justd/blob/master/knet/traversal.d#L264 because the comparsion function can't ge access to the class member distMap I get the error need 'this' for 'distMap' of type 'Tuple!(double, Ref!(Node))[Ref!(Node)]' What to do? I don't know if the lambda form can access the outer scope. Try different forms for the comparer: auto comparer = delegate (a, b) { return this.distMap[a][0] < this.distMap[b][0]; } BinaryHeap!(Nds, comparer) pendingNds; or BinaryHeap!(Nds, "this.distMap[a][0] < this.distMap[b][0]") pendingNds; Caveat: this is off the top of my head and no way even tested or read the docs. :)
Re: Is this possible in D?
On Thursday, 19 February 2015 at 10:17:47 UTC, Dicebot wrote: Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version): I really like mixins for this sort of thing. ``` enum signature = "void longFunction()"; version( Static ) enum sig = "static " ~ signature; else alias sig = signature; enum funcBody = q{{ import std.stdio : writeln; writeln( "Hi there!" ); version( Static ) writeln( "I'm static!" ); }}; struct Mixed { mixin(sig ~ funcBody); } void main() { version( Static ) Mixed.longFunction(); else { Mixed m; m.longFunction(); } } ``` @OP: By using a token string (q{}) for funcBody rather than a WYSIWYG string (r"" or ``), you can still get syntax highlighting in your editor.
Problem Instantiating a BinaryHeap with a Comparison Function the needs this
I can understand how to correctly define an instance of BinaryHeap in my class DijkstraWalker at https://github.com/nordlow/justd/blob/master/knet/traversal.d#L264 because the comparsion function can't ge access to the class member distMap I get the error need 'this' for 'distMap' of type 'Tuple!(double, Ref!(Node))[Ref!(Node)]' What to do?
Re: D : dmd vs gdc : which one to choose?
On 20/02/2015 12:10 a.m., Mayuresh Kathe wrote: On Thursday, 19 February 2015 at 09:10:16 UTC, Rikki Cattermole wrote: On 19/02/2015 9:46 p.m., Mayuresh Kathe wrote: How do I (a newbie to D) figure out which compiler set to use? I am running Ubuntu 14.10, and intend to stick with it in the long term. Should I choose DMD or go with GDC? I would like to know the rationale for suggestions for either. Thanks. Atleast while learning stick with dmd. It is the reference compiler. There are far more developers involved in its production then GDC. And anyway, GDC is still hasn't been updated to the latest version of D. And its the last major D compiler that hasn't. There is a D-apt repository, which will interest you. http://d-apt.sourceforge.net/ I thank you for your response, and thank you for that link. I installed the "dmd_2.066.1-0_amd64.deb" from the dlang.org website, though. :) Figured it best to stick with the official DMD as I am working through "The D Programming Language". In that case, you probably also want to read the errata for TDPL. http://erdani.com/index.php?cID=109 For changes since that book was written.
Re: D : dmd vs gdc : which one to choose?
On Thursday, 19 February 2015 at 09:10:16 UTC, Rikki Cattermole wrote: On 19/02/2015 9:46 p.m., Mayuresh Kathe wrote: How do I (a newbie to D) figure out which compiler set to use? I am running Ubuntu 14.10, and intend to stick with it in the long term. Should I choose DMD or go with GDC? I would like to know the rationale for suggestions for either. Thanks. Atleast while learning stick with dmd. It is the reference compiler. There are far more developers involved in its production then GDC. And anyway, GDC is still hasn't been updated to the latest version of D. And its the last major D compiler that hasn't. There is a D-apt repository, which will interest you. http://d-apt.sourceforge.net/ I thank you for your response, and thank you for that link. I installed the "dmd_2.066.1-0_amd64.deb" from the dlang.org website, though. :) Figured it best to stick with the official DMD as I am working through "The D Programming Language".
Re: Quick help on version function parameter
On Thursday, 19 February 2015 at 01:39:19 UTC, Jonathan Marler wrote: On Wednesday, 18 February 2015 at 23:49:26 UTC, Adam D. Ruppe wrote: I'd write a foo_impl which always takes a parameter. Then do the versioned foo() functions which just forward to it: void foo_impl(int x) { long function using x here } version(globals) { int x; void foo() { foo_impl(x); } } else { void foo(int x) { foo_impl(x); } } Minimal duplication with both interfaces. That kinda defeats the purpose of why I want this. It's for performance reasons. I need one version to have NO arguments and one version to have one ref argument. If it's a `ref` argument (your original example doesn't have one), are you sure there will be a performance problem? Anyway, how about using a template and an alias, respectively: void foo_impl(ref ExpensiveStruct x) { ... } version(globals) { ExpensiveStruct x; void foo()() { foo_impl(x); } } else { alias foo = foo_impl; } That way, you'd force `foo` to be instantiated at the call site, making it more likely to be inlinable. In the non-global case, there will be no overhead at all because of the `alias`. But, as always for things related to performance: profile first, then optimize.
Re: Is this possible in D?
Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version): class Test { private static void foo_() {} version (Static) { static void foo() { foo_(); } } else { void foo() { foo_(); } } private void bar_() shared { } version (Shared) { void bar() shared { bar_(); } } else { void bar() { (cast(shared Test)this).bar_(); } } } But this relies on very careful code review because of casual casts for certain attributes (static and public/private are easy in that regard)
Re: Is this possible in D?
On Thursday, 19 February 2015 at 09:38:48 UTC, Mike Parker wrote: On Thursday, 19 February 2015 at 08:24:08 UTC, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void myLongFunction() { // long body ... } } else { void myLongFunction() { // same long body copied... } } In one version I want the function to be static and in another I don't want it to be static. I cannot figure out how to do this without copy/pasting the entire function body to both versions. You should be able to cobble something together with string mixins. I'm still holding out hope for some sort of .codeof
Re: Is this possible in D?
On Thursday, 19 February 2015 at 08:24:08 UTC, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void myLongFunction() { // long body ... } } else { void myLongFunction() { // same long body copied... } } In one version I want the function to be static and in another I don't want it to be static. I cannot figure out how to do this without copy/pasting the entire function body to both versions. You should be able to cobble something together with string mixins.
Re: D : dmd vs gdc : which one to choose?
On Thursday, 19 February 2015 at 08:46:11 UTC, Mayuresh Kathe wrote: How do I (a newbie to D) figure out which compiler set to use? I am running Ubuntu 14.10, and intend to stick with it in the long term. Should I choose DMD or go with GDC? I would like to know the rationale for suggestions for either. Thanks. GDC: + generates faster code + supports many of low-level GCC flags for code generation tuning + more platforms (ARM, MIPS) - slow compilation - updates to latest language version with considerable delay DMD: + very fast edit/compile cycle + reference compiler - ancient code generation backend - not many ways to affect generated code (outside of -O -inline) It is common to use DMD for development and GDC for building actual release binaries.
Re: D : dmd vs gdc : which one to choose?
Mayuresh Kathe: Should I choose DMD or go with GDC? It's a good idea to use all available compilers. LDC and DMD are both useful. Every one of them has advantages and disadvantages. Bye, bearophile
Re: D : dmd vs gdc : which one to choose?
On 19/02/2015 9:46 p.m., Mayuresh Kathe wrote: How do I (a newbie to D) figure out which compiler set to use? I am running Ubuntu 14.10, and intend to stick with it in the long term. Should I choose DMD or go with GDC? I would like to know the rationale for suggestions for either. Thanks. Atleast while learning stick with dmd. It is the reference compiler. There are far more developers involved in its production then GDC. And anyway, GDC is still hasn't been updated to the latest version of D. And its the last major D compiler that hasn't. There is a D-apt repository, which will interest you. http://d-apt.sourceforge.net/
D : dmd vs gdc : which one to choose?
How do I (a newbie to D) figure out which compiler set to use? I am running Ubuntu 14.10, and intend to stick with it in the long term. Should I choose DMD or go with GDC? I would like to know the rationale for suggestions for either. Thanks.
Re: Is this possible in D?
On Thursday, 19 February 2015 at 08:24:08 UTC, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void myLongFunction() { // long body ... } } else { void myLongFunction() { // same long body copied... } } In one version I want the function to be static and in another I don't want it to be static. I cannot figure out how to do this without copy/pasting the entire function body to both versions. Same problem is seen with "shared" and "non-shared" class methods as well. I hope there is a good solution for it. If it was C, by using #ifdef #else #endif, just the name line of function could be changed, but I am not sure whether that works with "version()" expression.
Is this possible in D?
I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void myLongFunction() { // long body ... } } else { void myLongFunction() { // same long body copied... } } In one version I want the function to be static and in another I don't want it to be static. I cannot figure out how to do this without copy/pasting the entire function body to both versions.