Re: Compilation depends on class methods order
On 2013-12-20 08:03, kdmult wrote: Hi, Why compilation depends on order of method declarations? The following test case does not compile. However, if we change the order of the 'read' methods in class InputStream below then compilation will not fail. Is it a bug? --- module test; import std.traits : isBasicType; import std.typetuple : TypeTuple; class InputStream { long read( ubyte* bytes, long len ) { return 0; } void read(T)( ref T val ) if (isBasicType!T) { read(cast(ubyte*)&val, cast(long)val.sizeof); } } void main() { auto input = new InputStream; foreach (T; TypeTuple!(long, int, short, byte)) { T v; input.read(v); } } --- I'm wondering if that's because the first "read" isn't a template function. You cannot overload a standard function with a template function, or has that been fixed? If that's not the problem it's probably the template constraint. I have had some problems with that and the "solution" I end up using was to add the same template constraint to the other function but negate the condition. -- /Jacob Carlborg
Compilation depends on class methods order
Hi, Why compilation depends on order of method declarations? The following test case does not compile. However, if we change the order of the 'read' methods in class InputStream below then compilation will not fail. Is it a bug? --- module test; import std.traits : isBasicType; import std.typetuple : TypeTuple; class InputStream { long read( ubyte* bytes, long len ) { return 0; } void read(T)( ref T val ) if (isBasicType!T) { read(cast(ubyte*)&val, cast(long)val.sizeof); } } void main() { auto input = new InputStream; foreach (T; TypeTuple!(long, int, short, byte)) { T v; input.read(v); } } --- Thanks.
Re: [Windows] Building in 64bits
On Thursday, 19 December 2013 at 20:37:32 UTC, Xavier Bigand wrote: I try to build in 64bits with dmd to be able to use VS tools. Please notice on linux our project build fine in 64bits. Here is my error : E:\Dev\Personal\DQuick\src\samples\Minesweeper>dub --arch=x86_64 Checking dependencies in 'E:\Dev\Personal\DQuick\src\samples\Minesweeper' Building configuration "application", build type debug Compiling... Linking... Mine Sweeper.obj : fatal error LNK1179: fichier non valide ou endommagé : '_D6dquick6script5utils162__T31fullyQualifiedNameImplForTypes2TDFC6dquick6script11itemBinding65__T11ItemBindingTC6dquick4item15declarativeItem15DeclarativeItemZ11ItemBindingZvVb0Vb0Vb0Vb0Z29__T20storageClassesStringVk0Z20storageClassesStringFNaNdNfZAya' COMDAT dupliqué --- errorlevel 1179 Error executing command run: Link command failed with exit code 1179 Something hasn't been recompiled. The binary you're trying to link against is an OMF (aka 32bit) library. Microsofts linker use PE-COFF. By my guess recompile DQuick as 64bit. Since you're compiling an example.
[Windows] Building in 64bits
I try to build in 64bits with dmd to be able to use VS tools. Please notice on linux our project build fine in 64bits. Here is my error : E:\Dev\Personal\DQuick\src\samples\Minesweeper>dub --arch=x86_64 Checking dependencies in 'E:\Dev\Personal\DQuick\src\samples\Minesweeper' Building configuration "application", build type debug Compiling... Linking... Mine Sweeper.obj : fatal error LNK1179: fichier non valide ou endommagé : '_D6dquick6script5utils162__T31fullyQualifiedNameImplForTypes2TDFC6dquick6script11itemBinding65__T11ItemBindingTC6dquick4item15declarativeItem15DeclarativeItemZ11ItemBindingZvVb0Vb0Vb0Vb0Z29__T20storageClassesStringVk0Z20storageClassesStringFNaNdNfZAya' COMDAT dupliqué --- errorlevel 1179 Error executing command run: Link command failed with exit code 1179
Re: How to link to libdl under linux
Le 19/12/2013 13:46, MrSmith a écrit : Still need help. I've tried compiling a little test project with dub and it compiled. Then i tried to compile it by hand and got the same error. I think there is some issue in my command with parameter ordering. Here is test project module test; import derelict.glfw3.glfw3; import std.stdio; void main() { DerelictGLFW3.load(); writeln("test"); } with package { "targetName": "test", "dependencies": { "derelict-glfw3": "~master" }, "targetType":"executable", "name": "test", "sourceFiles":["./test.d"] } The dub does two step compilation: dmd -m32 -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test -c -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test.o -debug -g -w -version=Have_test -version=Have_derelict_glfw3 -version=Have_derelict_util -I../../.dub/packages/derelict-glfw3-master/source -I../../.dub/packages/derelict-util-1.0.0/source test.d ../../.dub/packages/derelict-glfw3-master/source/derelict/glfw3/package.d ../../.dub/packages/derelict-glfw3-master/source/derelict/glfw3/glfw3.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/xtypes.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/exception.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/system.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/loader.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/sharedlib.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/wintypes.d Linking... dmd -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test .dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test.o -L-ldl -m32 -g Copying target from /home/andrey/test/.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test to /home/andrey/test So, do i need to use two step compilation or i need proper ordering of parameters? One more question: why dub uses -of flag twice? I use pragma(lib, "dl"), but it doesn't work with DUB cause it separate build and link steps. I like the idea that sources knows them selves how they have to be build. I think it's possible to simply do rdmd main.d when using pragma(lib, "xxx"). For dub, add this line in your package.json : "libs-posix": ["dl"],
Re: how to detect OS architecture?
On Thu, 19 Dec 2013 10:53:12 -0800, Ali Çehreli wrote: On 12/18/2013 05:50 AM, Hugo Florentino wrote: BTW, how could I benchmark the performance of both solutions (lets say for a few thousand runs) to see if one is more efficient than the other? There is std.datetime.benchmark: http://dlang.org/phobos/std_datetime.html#.benchmark Ali Thanks. I don't know why I missed that.
Re: Wrong output of quotes in Windows (encoding?)
On Thu, 19 Dec 2013 19:38:20 +, Simon wrote: Call: SetConsoleOutputCP(65001); Works for me on win7 64bit. Not sure how far back it's supported though. Interesting, thanks.
Re: Wrong output of quotes in Windows (encoding?)
On 18/12/2013 22:11, Ali Çehreli wrote: On 12/18/2013 01:17 PM, Hugo Florentino wrote: > Changing the codepage worked indeed. Thanks. > Now, how could I do that programmatically, so that if my application > runs on a system with a different codepage, the output looks correct? It is not solvable in general because stdout is nothing but a stream that accepts characters. (Well, UTF-8 code units when it comes to Unicode). The program can detect or assume that it is running in a console and change that environment if it is allowed to do so. Google searches like "change code page console programmatically windows" produce some answers but I don't have any experience. :) Ali Call: SetConsoleOutputCP(65001); Works for me on win7 64bit. Not sure how far back it's supported though. http://msdn.microsoft.com/en-us/library/windows/desktop/ms686036(v=vs.85).aspx You might need your own definition of it, don't know it's available in the phobos windows bit. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Re: Type inference and overloaded functions
On 12/17/2013 07:21 PM, bearophile wrote: > But my suggested syntax is not that good, here $ has already a meaning, > that is the whole length of b, So some different idea is needed here :-( > > b[0 .. $] = foo(); Sorry, I can't resist... Golden rule of system programming language syntax: When in doubt, reach for static: b[0 .. $tatic] = foo(); Done! :p Ali
Re: how to detect OS architecture?
On 12/18/2013 05:50 AM, Hugo Florentino wrote: > BTW, how could I benchmark the performance of both solutions (lets say > for a few thousand runs) to see if one is more efficient than the other? There is std.datetime.benchmark: http://dlang.org/phobos/std_datetime.html#.benchmark Ali
Re: Chaining std.algorithm
On 12/19/2013 03:45 AM, Jakob Ovrum wrote: On Monday, 16 December 2013 at 06:07:00 UTC, Ali Çehreli wrote: .find!(data => data.digit.equal([ a ])) Use `std.range.only(a)` instead of `[a]` to avoid allocating GC memory. Thanks. That is the second time I see 'only'. Hopefully, it will stick this time. :) Ali
Re: Embed Windows Internet Explorer
Am Thu, 19 Dec 2013 17:36:57 + schrieb Richard Webb : > On 18/12/2013 20:48, Andre wrote: > > => myURL.bstrVal = SysAllocString(cast(const(wchar*))url); > > > Looks like the problem there is casting a string to a wchar* - I guess > the resulting BSTR will contain garbage instead of the intended value. > > > > > > It only works with statement: > > myURL.bstrVal = cast(wchar*)"http://www.google.de";; > > > > > Treating a wchar* as a BSTR might cause unexpected things to happen - > converting the string to a wchar* and then passing that to > SysAllocString would be safer. Oh yes, you are right and I was totally ignorant of what a BSTR is! It is a data structure for strings consisting of size prefix for the character data (4 bytes), the character data as wchars and a terminating zero wchar. So your first approach was correct: string url = …; BSTR* bstrUrl = enforce(SysAllocString(toUTFz!(const(wchar)*)(url)), "Out of memory or url is null"); myURL.bstrVal = bstrUrl; … SysFreeString(bstrUrl); -- Marco
Re: Embed Windows Internet Explorer
On 18/12/2013 20:48, Andre wrote: > => myURL.bstrVal = SysAllocString(cast(const(wchar*))url); Looks like the problem there is casting a string to a wchar* - I guess the resulting BSTR will contain garbage instead of the intended value. > > It only works with statement: > myURL.bstrVal = cast(wchar*)"http://www.google.de";; > Treating a wchar* as a BSTR might cause unexpected things to happen - converting the string to a wchar* and then passing that to SysAllocString would be safer.
Re: unittests and Windows App
On Thursday, 19 December 2013 at 13:55:41 UTC, ref2401 wrote: I'm using D 2064.2 and VisualD 0.3.37 VisualD "Redirect stdout to output window" checkbox is checked. In simple ConsoleApp unittests work properly. I can debug them and assertion fail results are printed to the Output window. But it seems that unittests don't work at all with any WindowsApp. It's impossible to debug and no assertion fail messages are printed to the Output windows. OutputDebugStringA/OutputDebugStringW[1] WinAPI function should work within visual studio. [1] http://msdn.microsoft.com/en-us/library/aa363362(VS.85).aspx
Re: Embed Windows Internet Explorer
Am 19.12.2013 16:54, schrieb Adam D. Ruppe: On Thursday, 19 December 2013 at 15:45:49 UTC, Andre wrote: Exacactly. But if I have my url in a string variable, how can I get the wchar[].ptr from my string variable, to fill bstrVal? You can use wstring variables and convert them with import std.utf; wchar* str = toUTFz!(wchar*)(another_string_variable); then you can fill it. Or you can also do import std.conv; wstring ws = to!wstring(another_string_variable); The difference is the first one has a zero terminator, so you can easily pass it to C functions. The second one doesn't, but it is a D array so you can use .ptr and .length. Thanks a lot! thats the solution
Re: Embed Windows Internet Explorer
On Thursday, 19 December 2013 at 15:45:49 UTC, Andre wrote: Exacactly. But if I have my url in a string variable, how can I get the wchar[].ptr from my string variable, to fill bstrVal? You can use wstring variables and convert them with import std.utf; wchar* str = toUTFz!(wchar*)(another_string_variable); then you can fill it. Or you can also do import std.conv; wstring ws = to!wstring(another_string_variable); The difference is the first one has a zero terminator, so you can easily pass it to C functions. The second one doesn't, but it is a D array so you can use .ptr and .length.
Re: Embed Windows Internet Explorer
Am 19.12.2013 10:58, schrieb Marco Leise: Did you mean this?: myURL.bstrVal = "http://www.google.de"w.ptr; Exacactly. But if I have my url in a string variable, how can I get the wchar[].ptr from my string variable, to fill bstrVal?
Re: How to link to libdl under linux
dmd -m32 -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test -c -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test.o -debug -g -w -version=Have_test -version=Have_derelict_glfw3 -version=Have_derelict_util -I../../.dub/packages/derelict-glfw3-master/source -I../../.dub/packages/derelict-util-1.0.0/source test.d ../../.dub/packages/derelict-glfw3-master/source/derelict/glfw3/package.d ../../.dub/packages/derelict-glfw3-master/source/derelict/glfw3/glfw3.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/xtypes.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/exception.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/system.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/loader.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/sharedlib.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/wintypes.d Linking... Turns out, dub includes actual dependencies source files into object file. _l-ldl flag with this works fine. but i want to use .a files instead
unittests and Windows App
I'm using D 2064.2 and VisualD 0.3.37 VisualD "Redirect stdout to output window" checkbox is checked. In simple ConsoleApp unittests work properly. I can debug them and assertion fail results are printed to the Output window. But it seems that unittests don't work at all with any WindowsApp. It's impossible to debug and no assertion fail messages are printed to the Output windows.
Re: How to link to libdl under linux
The -of flag tells the compiler which name to use for executable. Yep, but why it is used twice? dmd -m32 -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test -c -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test.o
Re: How to link to libdl under linux
On 2013-12-19 13:46, MrSmith wrote: So, do i need to use two step compilation or i need proper ordering of parameters? You should not need to use two steps. One more question: why dub uses -of flag twice? The -of flag tells the compiler which name to use for executable. -- /Jacob Carlborg
Re: How to link to libdl under linux
Still need help. I've tried compiling a little test project with dub and it compiled. Then i tried to compile it by hand and got the same error. I think there is some issue in my command with parameter ordering. Here is test project module test; import derelict.glfw3.glfw3; import std.stdio; void main() { DerelictGLFW3.load(); writeln("test"); } with package { "targetName": "test", "dependencies": { "derelict-glfw3": "~master" }, "targetType":"executable", "name": "test", "sourceFiles":["./test.d"] } The dub does two step compilation: dmd -m32 -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test -c -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test.o -debug -g -w -version=Have_test -version=Have_derelict_glfw3 -version=Have_derelict_util -I../../.dub/packages/derelict-glfw3-master/source -I../../.dub/packages/derelict-util-1.0.0/source test.d ../../.dub/packages/derelict-glfw3-master/source/derelict/glfw3/package.d ../../.dub/packages/derelict-glfw3-master/source/derelict/glfw3/glfw3.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/xtypes.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/exception.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/system.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/loader.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/sharedlib.d ../../.dub/packages/derelict-util-1.0.0/source/derelict/util/wintypes.d Linking... dmd -of.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test .dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test.o -L-ldl -m32 -g Copying target from /home/andrey/test/.dub/build/application-debug-x86-dmd-DA39A3EE5E6B4B0D3255BFEF95601890AFD80709/test to /home/andrey/test So, do i need to use two step compilation or i need proper ordering of parameters? One more question: why dub uses -of flag twice?
Re: Chaining std.algorithm
On Monday, 16 December 2013 at 06:07:00 UTC, Ali Çehreli wrote: .find!(data => data.digit.equal([ a ])) Use `std.range.only(a)` instead of `[a]` to avoid allocating GC memory.
Re: Can't isolate ICE
On Wednesday, 18 December 2013 at 16:28:48 UTC, H. S. Teoh wrote: On Wed, Dec 18, 2013 at 12:27:01PM +0100, Andrea Fontana wrote: I have an internal compiler error in my code. I can't reduce code to reproduce this problem, but I remember there was a tool that can do this, what's its name? Where can I download that tool? Dustmite, by Vladimir Panteleev. It's actually packaged with the 'tools' repository in Dlang's github organization now; you can get it here: https://github.com/D-Programming-Language/tools.git T Yes just done! And here the problem: https://d.puremagic.com/issues/show_bug.cgi?id=11763
Re: Embed Windows Internet Explorer
Am Wed, 18 Dec 2013 21:48:30 +0100 schrieb Andre : > Am 16.12.2013 19:44, schrieb Andre: > > Hi, > > > > I try to embed Windows Internet Explorer into my application. > > Most of the coding should be availabe. During method navigate2 > > I get an empty white screen. No errors is thrown but also the > > web page is not loaded. Do you have some ideas? > > > > => Is use the windows headers from DSource and the dgui forms library. > > I attached the source code. > > > > Kind regards > > André > > The issue was related to SysAllocString: > > VARIANT myURL; > VariantInit(&myURL); > myURL.vt = cast(VARTYPE)VARENUM.VT_BSTR; > => myURL.bstrVal = SysAllocString(cast(const(wchar*))url); > webBrowser2.Navigate2( &myURL, null, null, null, null); > > It only works with statement: > myURL.bstrVal = cast(wchar*)"http://www.google.de";; Did you mean this?: myURL.bstrVal = "http://www.google.de"w.ptr; -- Marco
Re: Unique IDs for each template instantiation at compile-time?
Am Thu, 19 Dec 2013 00:01:03 +0100 schrieb "Weasel" : > I was wondering if it was possible to generate unique(in order) > IDs for each template instantiation of a class at compile-time. > > A short example of what I'm trying to do: > > static int counter = 0; > class A(T) > { > enum id = counter++; > } > class B : A!B > { > } > > Ofcourse, this doesn't compile because the "counter" variable > can't be read at compile-time. Something like that cannot work. Imagine your template is in a.d and you instantiate it in b.d and c.d. Now you compile: dmd -c b.d dmd -c c.d Both times the counter imported from a.d would start at 0. -- Marco
Re: how to detect OS architecture?
Am Wed, 18 Dec 2013 13:19:09 - schrieb "Regan Heath" : > On Tue, 17 Dec 2013 15:13:20 -, Marco Leise wrote: > > > Am Tue, 17 Dec 2013 13:30:25 - > > schrieb "Regan Heath" : > > > >> On Mon, 16 Dec 2013 21:27:13 -, Hugo Florentino > >> wrote: > >> > >> > On Mon, 16 Dec 2013 20:23:00 +0100, Jacob Carlborg wrote: > >> >> On 2013-12-16 17:46, Marco Leise wrote: > >> >> > >> >>> Hehe, I guess the whole purpose of the launcher is to run in > >> >>> 32-bit and detect at runtime if the 64-bit main executable can > >> >>> be run or the 32-bit version must be used. > >> >> > >> >> The only advantage of that is that only a 32bit launcher needs to be > >> >> distributed. Perhaps that's the whole idea. > >> > > >> > It is. :) > >> > >> "Process Explorer" by sysinternals, now distributed by M$ does something > >> similar. > >> http://technet.microsoft.com/en-gb/sysinternals/bb896653.aspx > >> > >> It is a 32 bit exe, which detects the OS bit width and if it's 64 bit > >> extracts a 64 exe from within itself to run. When you quit that 64 bit > >> exe, it deletes the file it extracted from disk. It's quite a neat > >> solution. > >> > >> R > >> > > > > Only if your executable is self-contained. If you already have > > external DLLs or assets you can as well have a launcher and 2 > > actual binaries. > > I don't see why that changes things? Sure, you cannot extract your > *static* dependent dlls (those linked at compile time with libs), those > have to exist before you can execute your 32 bit launcher. But, if you > really wanted to, you could extract and runtime load dlls no problem. > > R That's my point. If you really wanted, you could do that but you can as well have a launcher and 2 application binaries and avoid this repeated file extraction/deletion and save yourself some troubles at the end of the day. -- Marco