Re: A DUB Case Study: Compiling DMD as a Library
This is regarding the latest D blog post. Jacob Carlborg is here, so I figured I'd post it. https://dlang.org/blog/2017/08/01/a-dub-case-study-compiling-dmd-as-a-library/#comment-2922 Simply changing the targetType from library to dynamicLibrary breaks the code. What is going on with it ? --dub.sdl-- name "dmd-dub-test" description "Test of the DMD Dub package" license "BSL 1.0" sourcePaths "." targetType "library" dependency "dmd" path="../DSource/dmd/" --end dub.sdl-- -- output -- venkat@venkat-U46E /d/Documents/NetbeansProjects/dmd-test $ dub build Performing "debug" build using dmd for x86_64. -- end output -- --dub.sdl-- name "dmd-dub-test" description "Test of the DMD Dub package" license "BSL 1.0" sourcePaths "." targetType "dynamicLibrary" dependency "dmd" path="../DSource/dmd/" --end dub.sdl-- Performing "debug" build using dmd for x86_64. dmd ~stable: building configuration "library"... ../DSource/dmd/src/ddmd/scanmscoff.d(180,10): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(181,10): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(182,10): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(183,10): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(184,11): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(185,15): Error: undefined identifier BYTE ../DSource/dmd/src/ddmd/scanmscoff.d(185,15): Error: undefined identifier BYTE ../DSource/dmd/src/ddmd/scanmscoff.d(187,14): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(187,14): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(188,11): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(189,11): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(190,11): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(196,11): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(197,11): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(198,11): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(199,11): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(200,11): Error: undefined identifier DWORD ../DSource/dmd/src/ddmd/scanmscoff.d(201,11): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(202,11): Error: undefined identifier WORD ../DSource/dmd/src/ddmd/scanmscoff.d(225,24): Error: undefined identifier BYTE dmd failed with exit code 1.
Re: Using DLLs to extend an existing class
I am afraid to say this has quite a simple answer. TypeInfo (and with that vtables used as part of classes), do not cross the dll boundary (other platforms things mostly work). Which means, can't do what you are wanting I'm afraid. It is an implementation issue that we REALLY REALLY REALLY need to fix.
Re: tuples from text file
On 12/19/17 7:47 PM, codephantom wrote: so I have a text file containing 3 lines(e.g): 5, "hello", 4.3 "hello", 4.3 "hello", "world", 1, 2, 3, 5.5 Now I want to create tuples from each line. However, (using line 1 as example), I get: Tuple!string("5, \"hello\", 4.3") but I really want: Tuple!(int, string, double)(5, "hello", 4.3) I know why - because a line is a string. But anyone got an idea on how to extract the string into separate elements that can be correctly 'tuple'd" according to the type of each element? Well, you need to know at compile time the types you are expecting. Then you just parse them out. You can't decide tuples at runtime. -Steve
tuples from text file
so I have a text file containing 3 lines(e.g): 5, "hello", 4.3 "hello", 4.3 "hello", "world", 1, 2, 3, 5.5 Now I want to create tuples from each line. However, (using line 1 as example), I get: Tuple!string("5, \"hello\", 4.3") but I really want: Tuple!(int, string, double)(5, "hello", 4.3) I know why - because a line is a string. But anyone got an idea on how to extract the string into separate elements that can be correctly 'tuple'd" according to the type of each element? // --- module test; import std.stdio : writeln; import std.typecons; import std.string; import std.file : readText; void main() { string myFile= "tuples.txt"; // contains 3 lines as per examples above auto lineArr = readText(myFile).splitLines(); writeln( tuple(lineArr[0]) ); // doesn't give me the tuple I want. } //---
Re: Alias example should supposedly be illegal, but runs fine
On Tuesday, 19 December 2017 at 10:37:05 UTC, Michael wrote: On Tuesday, 19 December 2017 at 02:12:29 UTC, Mike Franklin wrote: On Tuesday, 19 December 2017 at 02:04:34 UTC, codephantom wrote: writeln(S.j); // Error: Instance symbols cannot be used through types. I don't understand why you would say that is a bug. I meant that the example is wrong, and a bug report should be filed to fix the example. Mike Hmm.. but the example is explicitly dealing with when it is valid to create an alias for a non-static struct member. Should it still not be int? Even if you cannot change it via that alias? I don't quite understand what you mean. `s.i` refers to a symbol in the compiler's symbol table. Therefore, I don't see any reason it can't be aliased. `alias a = b + c;` would be a better example to demonstrate that expressions cannot be aliased. Mike
Using DLLs to extend an existing class
I'm developing a plugin system for a D program. I have a complex class hierarchy which will be complied into our executable, and I want third parties to be able to further extend it with their own DLLs - subject to implementing an API present in the most derived class - which will be provided to the user as a auto generated header (.di) file using "dmd -H [modules]" For example, in our program: --- class A { //Protected and public methods } class B : A { //Protected and public methods. public string apiMethod() { return "Class B"; } } --- And in a typical "Dll to be' plugin: --- import B; //Currently using a 'header' file generated with dmd -H b.d; mixin dllBoilerplate; export class C : B { //Public (export?) API implimentation override public string apiMethod() { return "Class C"; } //Private methods } Currently, when I try to compile the plugin DLL, I get linker errors that mangled symbol for apiMethod is not defined - These are the symbols defined in the header (b.di) file, but are not implemented: by definition intended to be part of the main program, instead. Can anyone explain how I should go about building the plugin - I suspect it involved what I am and am not declaring 'export', but I'm unable to find any material that puts light on my situation. Thanks. ST.
Re: How do I pass a type as parameter in this method?
On Tuesday, 19 December 2017 at 15:52:57 UTC, Dgame wrote: On Tuesday, 19 December 2017 at 15:19:53 UTC, Marc wrote: [...] template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise = D.init; } else { enum otherwise = T[0]; } } template otherwise(alias value) { static if (T.length == 0) { enum otherwise = value; } else { enum otherwise = T[0]; } } } void main() { static assert (FirstOf!(1.5, "hello").otherwise!int == 1.5); static assert (FirstOf!("world", [1]).otherwise!int == "world"); static assert (FirstOf!().otherwise!int == 0); static assert (FirstOf!(1.5, "hello").otherwise!23 == 1.5); static assert (FirstOf!().otherwise!42 == 42); } Didn't know about alias as template paramter. Exactly what I wanted. Thank you!
Re: No of threads
On 12/19/2017 02:24 AM, Vino wrote: > Hi All, > >Request your help in clarifying the below. As per the document > > foreach (d; taskPool.parallel(xxx)) : The total number of threads that > will be created is total CPU -1 ( 2 processor with 6 core : 11 threads) > > foreach (d; taskPool.parallel(xxx,1)) : The total number of threads that > will be created is total CPU -1 ( 2 processor with 6 core : 12 threads) That parameter is workUnitSize, meaning the number of elements each thread will process per work unit. So, when you set it to 100, each thread will work on 100 elements before they go pick more elements to work on. Experiment with different values to find out which is faster for your work load. If each element takes very short amount of time to work on, you need larger values because you don't want to stop a happy thread that's chugging along on elements. It really depends on each program, so try different values. > foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008 whatever > value is set for the parallel the total number of threads does not > increase more than 12. taskPool is just for convenience. You need to create your own TaskPool if you want more threads: import std.parallelism; import core.thread; import std.range; void main() { auto t = new TaskPool(20); foreach (d; t.parallel(100.iota)) { // ... } Thread.sleep(5.seconds); t.finish(); } Now there are 20 + 1 (main) threads. Ali
Re: Write native GUI applications for Windows
On Monday, 18 December 2017 at 07:55:25 UTC, Andrey wrote: I have a question about creating native GUI applications for Windows 7 or/and Windows 10. And what about D? What should I do? Make some kind of wrapper above C WinApi? I've used DFL which is a thin wrapper over WinAPI and its native widgets. Links statically, no dependencies, no code bloat. Examples: http://www.infognition.com/VideoEnhancer/autovideoenhance.png http://www.infognition.com/blogsort/blogsort500.jpg https://bitbucket.org/thedeemon/autovideoenhance https://bitbucket.org/infognition/bsort There are several forks of DFL in github, I'm not sure which one is the most fresh today. I think I used this one: https://github.com/Rayerd/dfl
Re: How do I pass a type as parameter in this method?
On Tuesday, 19 December 2017 at 15:19:53 UTC, Marc wrote: On Tuesday, 19 December 2017 at 00:01:00 UTC, Ali Çehreli wrote: On 12/18/2017 03:54 PM, Ali Çehreli wrote: On 12/18/2017 02:58 PM, Marc wrote: Here's another experiment: template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise = D.init; } else { enum otherwise = T[0]; } } } void main() { static assert (FirstOf!(1.5, "hello").otherwise!int == 1.5); static assert (FirstOf!("world", [1]).otherwise!int == "world"); static assert (FirstOf!().otherwise!int == 0); } Ali Thanks four answer. I'll be using this one. I was messing around and getting multiple arguments to template function too. I like the naming too, it made code clear, imo. It's possible to have overload where one take a type name and the other a variable (constant value actually)? something like this (also imaginary code): template FirstOf(TP...) { template otherwise(D) { static if(TP.length > 0) { enum otherwise = TP[0]; } else { enum otherwise = D.init; } } template otherwise(D value) { static if(TP.length > 0) { enum otherwise = TP[0]; } else { enum otherwise = value; } } } So I can use like this: int index = FirstOf!(myTuple).otherwise!int; int value = FirstOf(myTuple2).otherwise!(10); with my limited template knowledge, I know I can write it like this: template otherwise(D, D value) { static if(TP.length > 0) { enum otherwise = TP[0]; } else { enum otherwise = value; } } So the call would go like this: int value = FirstOf(myTuple2).otherwise!(int, 10); But for simplicity I'd like to infer the type from constant value passed in parameter, in that case, the integer value of 10. template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise = D.init; } else { enum otherwise = T[0]; } } template otherwise(alias value) { static if (T.length == 0) { enum otherwise = value; } else { enum otherwise = T[0]; } } } void main() { static assert (FirstOf!(1.5, "hello").otherwise!int == 1.5); static assert (FirstOf!("world", [1]).otherwise!int == "world"); static assert (FirstOf!().otherwise!int == 0); static assert (FirstOf!(1.5, "hello").otherwise!23 == 1.5); static assert (FirstOf!().otherwise!42 == 42); }
Re: ptr wrapper with dip1000
On 12/19/17 8:22 AM, vit wrote: struct Ptr{ int* ptr; static Ptr create(scope return int* ptr)@safe{ Ptr x; x.ptr = ptr; return x; } /++ This doesn't work: this(scope return int* ptr)scope @safe{ this.ptr = ptr; } +/ } void main()@safe{ int i; auto x = Ptr(); auto y = Ptr.create(); } I think this is a limitation of dip1000 that was not foreseen. I think when you mark the parameter `return`, `this` isn't actually considered a return value, is it? So it doesn't link the lifetime of ptr to the lifetime of this, which it should. Please file an enhancement request, this should be allowed. -Steve
Re: How do I pass a type as parameter in this method?
On Tuesday, 19 December 2017 at 00:01:00 UTC, Ali Çehreli wrote: On 12/18/2017 03:54 PM, Ali Çehreli wrote: On 12/18/2017 02:58 PM, Marc wrote: Here's another experiment: template FirstOf(T...) { template otherwise(D) { static if (T.length == 0) { enum otherwise = D.init; } else { enum otherwise = T[0]; } } } void main() { static assert (FirstOf!(1.5, "hello").otherwise!int == 1.5); static assert (FirstOf!("world", [1]).otherwise!int == "world"); static assert (FirstOf!().otherwise!int == 0); } Ali Thanks four answer. I'll be using this one. I was messing around and getting multiple arguments to template function too. I like the naming too, it made code clear, imo. It's possible to have overload where one take a type name and the other a variable (constant value actually)? something like this (also imaginary code): template FirstOf(TP...) { template otherwise(D) { static if(TP.length > 0) { enum otherwise = TP[0]; } else { enum otherwise = D.init; } } template otherwise(D value) { static if(TP.length > 0) { enum otherwise = TP[0]; } else { enum otherwise = value; } } } So I can use like this: int index = FirstOf!(myTuple).otherwise!int; int value = FirstOf(myTuple2).otherwise!(10); with my limited template knowledge, I know I can write it like this: template otherwise(D, D value) { static if(TP.length > 0) { enum otherwise = TP[0]; } else { enum otherwise = value; } } So the call would go like this: int value = FirstOf(myTuple2).otherwise!(int, 10); But for simplicity I'd like to infer the type from constant value passed in parameter, in that case, the integer value of 10.
ptr wrapper with dip1000
How to manualy declare constructor for struct Ptr which work like Ptr.create? struct Ptr{ int* ptr; static Ptr create(scope return int* ptr)@safe{ Ptr x; x.ptr = ptr; return x; } /++ This doesn't work: this(scope return int* ptr)scope @safe{ this.ptr = ptr; } +/ } void main()@safe{ int i; auto x = Ptr(); auto y = Ptr.create(); }
Re: No of threads
On Tuesday, 19 December 2017 at 11:03:27 UTC, codephantom wrote: On Tuesday, 19 December 2017 at 10:24:47 UTC, Vino wrote: foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008 whatever value is set for the parallel the total number of threads does not increase more than 12. So not sure if this is correct, so can any one explain me on same. something to do with your cacheLineSize perhaps? There are other process running on the same server which use 200+ threads which means the server is capable of running more that 200+ threads, as i suspect is ti something to do with TaskPool From, Vino.B
Re: No of threads
On 19/12/2017 11:03 AM, codephantom wrote: On Tuesday, 19 December 2017 at 10:24:47 UTC, Vino wrote: foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008 whatever value is set for the parallel the total number of threads does not increase more than 12. So not sure if this is correct, so can any one explain me on same. something to do with your cacheLineSize perhaps? The size of the cache line should be 64 in pretty much all 32/64bit x86 cpu's. My suspicion is that TaskPool is limiting itself on purpose (based on what code I read).
Re: No of threads
On Tuesday, 19 December 2017 at 10:24:47 UTC, Vino wrote: foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008 whatever value is set for the parallel the total number of threads does not increase more than 12. So not sure if this is correct, so can any one explain me on same. something to do with your cacheLineSize perhaps?
Re: Alias example should supposedly be illegal, but runs fine
On Tuesday, 19 December 2017 at 02:12:29 UTC, Mike Franklin wrote: On Tuesday, 19 December 2017 at 02:04:34 UTC, codephantom wrote: writeln(S.j); // Error: Instance symbols cannot be used through types. I don't understand why you would say that is a bug. I meant that the example is wrong, and a bug report should be filed to fix the example. Mike Hmm.. but the example is explicitly dealing with when it is valid to create an alias for a non-static struct member. Should it still not be int? Even if you cannot change it via that alias?
Re: Fold in Parallelism
On Monday, 18 December 2017 at 20:53:28 UTC, Russel Winder wrote: Ali, Shouldn't this be a pull request for std.parallelism to be extended? If the function is in std.algorithm, then people should not have to write it for themselves in std.parallelism. On Mon, 2017-12-18 at 11:01 -0800, Ali Çehreli via Digitalmars-d-learn wrote: [...] […] [...] Hi Ali, Sorry, I would like to echo the statement from Russel, as an user(newbie) I personally do not want to fiddle around the libraries even though it is a simple code copy+paste, as this might cause some serious issue in case if anything went wrong, so i would like to leave it to expert's like you to help us. If possible can we added this to the next release (78). From, Vino.B.
Re: Alias example should supposedly be illegal, but runs fine
On Tuesday, 19 December 2017 at 01:29:04 UTC, Meta wrote: On Monday, 18 December 2017 at 23:44:46 UTC, Michael wrote: [...] I think the reason that this works is because i is static, meaning that you don't need the `this` reference of S to access it and thus it can be aliased. Declaring a static class or struct variable is pretty much the same as declaring a global variable, just with a tighter scope. If you look at it that way, then this makes a lot more sense. If you declare a global variable i at module scope, of course you can create an alias for it. Yes I think you're right. I wasn't sure what was going on, just noticed that the example definitely isn't right. I'll file a bug support and try and fix it.
No of threads
Hi All, Request your help in clarifying the below. As per the document foreach (d; taskPool.parallel(xxx)) : The total number of threads that will be created is total CPU -1 ( 2 processor with 6 core : 11 threads) foreach (d; taskPool.parallel(xxx,1)) : The total number of threads that will be created is total CPU -1 ( 2 processor with 6 core : 12 threads) So if I increase the parallel process by any number what would be the no of threads that would be created foreach (d; taskPool.parallel(xxx,20)) : As in Windows 2008 whatever value is set for the parallel the total number of threads does not increase more than 12. So not sure if this is correct, so can any one explain me on same. From, Vino.B
Re: Dub project has both .sdl and .json files. Is this normal or did I do something wrong?
On 2017-12-18 23:36, WhatMeWorry wrote: I've been using Dub for a while but from the very beginning I decided to go with SDL 100% of the time, So I've got a dub.sdl file like: name "01_10_camera_view_space" description "A minimal D application." authors "kheaser" copyright "Copyright © 2017, kheaser" license "proprietary" dependency "derelict-al" version="~>1.0.3" dependency "derelict-assimp3" version="~>1.3.0" dependency "derelict-fi" version="~>2.0.3" dependency "derelict-fmod" version="~>2.0.4" dependency "derelict-ft" version="~>1.1.3" dependency "derelict-gl3" version="~>1.0.23" dependency "derelict-glfw3" version="~>3.1.3" dependency "derelict-util" version="~>2.0.6" dependency "gl3n" version="~>1.3.1" . But when I look the directory that has the dub.sdl file, I also see a file called dub.selections.json { "fileVersion": 1, "versions": { "derelict-al": "1.0.3", "derelict-assimp3": "1.3.0", "derelict-fi": "2.0.3", "derelict-fmod": "2.0.4", "derelict-ft": "1.1.3", "derelict-gl3": "1.0.23", "derelict-glfw3": "3.1.3", "derelict-util": "2.0.6", "gl3n": "1.3.1" } } So how did this .json file get created and can I just delete it? You should keep it. If you have developed an application it should be committed to git, if it's a library it should not be committed. -- /Jacob Carlborg
Re: Dub project has both .sdl and .json files. Is this normal or did I do something wrong?
On 2017-12-18 23:57, WebFreak001 wrote: dub.selections.json is basically broken design The design is fine, not so sure about the implementation. I've explain many time before why it's necessary. -- /Jacob Carlborg