Re: How can I hide implementation details when make a library
On Tuesday, 25 September 2012 at 17:54:39 UTC, Jonathan M Davis wrote: On Tuesday, September 25, 2012 13:58:00 Daniel Kozak wrote: Yes, it works. Thanks a lot. However I still dont get it, why dmd generates all sources instead of just public symbols and functions declarations A number of features do not work if not all of the source is available. In particular, functions can't be inlined if the compiler doesn't have their source, and any function which is used at compile time (using CTFE - compile time function evaluation) needs its full source and the source of every function that it calls. So, in general, it's pretty crippling to not have the full source available. Also, templates tend to be used quite heavily in D, and because templates aren't actually instantiated until they're used, their entire source must be in the .di file regardless, making it so that you _can't_ hide their code (C++ has exactly the same issue). So, in general, .di files don't make a lot of sense. But if all that anyone is doing is calling the functions at runtime, and it doesn't matter that they're not inlinable, and you don't need any of them to be templated (or it's okay for the few that are templated to have their full source in the .di file), then you can strip out the function bodies in .di files, and that _can_ be useful if you really need that, but pretty much no one's going to do that unless they have to (or just don't understand what they lose by doing so). - Jonathan M Davis Thanks for explanation.
Re: Testing for template argument being result of takeExactly
On 09/25/2012 08:41 AM, monarch_dodra wrote: On Monday, 24 September 2012 at 22:13:51 UTC, Timon Gehr wrote: On 09/24/2012 09:41 AM, monarch_dodra wrote: > [SNIP] I don't think this does what you think it does. The 'is(R r)' declares r to be an alias for R. So 'r' is a type in that code snippet. Darn :( Also, is(typeof(takeExactly(R, 1))) && is(R == typeof(takeExactly(R, 1))) can be written in a more compact way as is(typeof(takeExactly(R, 1)) == R) Technically, no: That was my first try, and as mentioned in the first reply, this returns true when the types of takeExactly and R are equal comparable, but does not make sure they are the actually the same types. ... I assume you messed up the parentheses. is(typeof(takeExactly(R, 1) == R)) // test for equal-comparable is(typeof(takeExactly(R, 1)) == R) // test for type identity alias float flt; static assert(is(typeof(1==flt))); static assert(!is(typeof(1)==flt));
Re: Testing for template argument being result of takeExactly
On Wednesday, 26 September 2012 at 13:19:13 UTC, Timon Gehr wrote: On 09/25/2012 08:41 AM, monarch_dodra wrote: On Monday, 24 September 2012 at 22:13:51 UTC, Timon Gehr wrote: On 09/24/2012 09:41 AM, monarch_dodra wrote: > [SNIP] I don't think this does what you think it does. The 'is(R r)' declares r to be an alias for R. So 'r' is a type in that code snippet. Darn :( Also, is(typeof(takeExactly(R, 1))) && is(R == typeof(takeExactly(R, 1))) can be written in a more compact way as is(typeof(takeExactly(R, 1)) == R) Technically, no: That was my first try, and as mentioned in the first reply, this returns true when the types of takeExactly and R are equal comparable, but does not make sure they are the actually the same types. ... I assume you messed up the parentheses. is(typeof(takeExactly(R, 1) == R)) // test for equal-comparable is(typeof(takeExactly(R, 1)) == R) // test for type identity alias float flt; static assert(is(typeof(1==flt))); static assert(!is(typeof(1)==flt)); Yes sorry. I miss read that. Kind of weird though, could you explain why: struct S{}; is(typeof(takeExactly(S, 1)) == S) //false is(S == typeof(takeExactly(S, 1))) //Error: template std.range.takeExactly does not match any function template declaration I was under the understanding that == was a commutative operation. Not the case in an is block?
Re: Linking OpenSSL on Windows
I think this thread is not TOO old to use as a place to beg for help :) I've wandered into this nightmare, and I'm hoping someone who's been down this road can point the way back to the light. Summary: "no OPENSSL_Applink" runtime error when executing D openssl application. I have managed to get basic linking and loading going on the sample programs posted here (http://forum.dlang.org/thread/yvogpmdjsoproggie...@forum.dlang.org). I'm using Win32_Openssl_v1.0.0j from Shining Light Productions (SLP) at http://slproweb.com/products/Win32OpenSSL.html (suggested by klickverbot's DThrift build instructions). I then ran C:\Tools\D\dmd2\windows\local\lib>..\..\bin\coffimplib C:\Tools\OpenSSL-Win32\li b\libeay32.lib libeay32.omf.lib C:\Tools\D\dmd2\windows\local\lib>..\..\bin\coffimplib C:\Tools\OpenSSL-Win32\li b\ssleay32.lib ssleay32.omf.lib to convert the given import libs to OMF as suggested. (Note, I suspect these are not the VC import libs, but I don't know what compiler they came from. Gcc?) I have deimos openssl D bindings in my import path and the above windows\local\lib folder in my link path. I compile with: C:\DSockets>dmd server.d ssleay32.omf.lib libeay32.omf.lib and all is well. If I then put the OpenSsl .DLLs from in the same directory When I run the server program, I quickly get a run-time error: C:\DSockets>server OPENSSL_Uplink(005A,08): no OPENSSL_Applink The openssl.org faq says: "Note that debug and release libraries are NOT interchangeable. If you built OpenSSL with /MD your application must use /MD and cannot use /MDd. "As per 0.9.8 the above limitation is eliminated for .DLLs. OpenSSL .DLLs compiled with some specific run-time option [we insist on the default /MD] can be deployed with application compiled with different option or even different compiler. But there is a catch! Instead of re-compiling OpenSSL toolkit, as you would have to with prior versions, you have to compile small C snippet with compiler and/or options of your choice. The snippet gets installed as /include/openssl/applink.c and should be either added to your application project or simply #include-d in one [and only one] of your application source files. Failure to link this shim module into your application manifests itself as fatal "no OPENSSL_Applink" run-time error. An explicit reminder is due that in this situation [mixing compiler options] it is as important to add CRYPTO_malloc_init prior first call to OpenSSL." Ignoring this last cryptic reminder, I *do* see applink.c in the SLP Openssl include directory. But I don't see any D binding/equivalent file for it. I also don't see any ?pplink strings in the map file when compiling server.d so it's certainly not provided if it's required. The question is where should it come from and whether it's always required. The faq answer makes me think if I had a different version of the import libs, I might not need any applink stuff. And I don't see any of the other "howto" pages suggesting this is needed. If I *do* need to supply it myself, how should I do that? Just compile their .c to a .obj and add it to the dmd command line? Surely some D binding would be better... Count this as another vote for a little more comprehensive documentation on how to get OpenSSL DLLs working under windows. This is the kinda thing that makes folks think maybe C++ is still tolerable... For completeness, I'm running C:\DSockets>dmd --help DMD32 D Compiler v2.060 on Windows 7 64-bit Any input greatly appreciated. Jason On Monday, 9 July 2012 at 13:45:18 UTC, David Nadlinger wrote: I described the installation of Thrift (which also uses OpenSSL) on Windows here: https://github.com/klickverbot/thrift/wiki/Building-Thrift-D-on-Windows In the build system, I just add the generated import libraries to the command lines afterwards (like a source file, without any special switch).
Re: Testing for template argument being result of takeExactly
On 09/26/2012 03:50 PM, monarch_dodra wrote: On Wednesday, 26 September 2012 at 13:19:13 UTC, Timon Gehr wrote: On 09/25/2012 08:41 AM, monarch_dodra wrote: On Monday, 24 September 2012 at 22:13:51 UTC, Timon Gehr wrote: On 09/24/2012 09:41 AM, monarch_dodra wrote: > [SNIP] I don't think this does what you think it does. The 'is(R r)' declares r to be an alias for R. So 'r' is a type in that code snippet. Darn :( Also, is(typeof(takeExactly(R, 1))) && is(R == typeof(takeExactly(R, 1))) can be written in a more compact way as is(typeof(takeExactly(R, 1)) == R) Technically, no: That was my first try, and as mentioned in the first reply, this returns true when the types of takeExactly and R are equal comparable, but does not make sure they are the actually the same types. ... I assume you messed up the parentheses. is(typeof(takeExactly(R, 1) == R)) // test for equal-comparable is(typeof(takeExactly(R, 1)) == R) // test for type identity alias float flt; static assert(is(typeof(1==flt))); static assert(!is(typeof(1)==flt)); Yes sorry. I miss read that. Kind of weird though, could you explain why: struct S{}; is(typeof(takeExactly(S, 1)) == S) //false is(S == typeof(takeExactly(S, 1))) //Error: template std.range.takeExactly does not match any function template declaration I was under the understanding that == was a commutative operation. Not the case in an is block? It is special syntax, not an == operator. is-expressions suppress errors in the first argument only.
Re: Testing for template argument being result of takeExactly
On 9/26/12 9:50 AM, monarch_dodra wrote: struct S{}; is(typeof(takeExactly(S, 1)) == S) //false is(S == typeof(takeExactly(S, 1))) //Error: template std.range.takeExactly does not match any function template declaration Neither should work. The expression should be takeExactly(S.init, 1). Andrei
Re: GUI development libraries in D?
On Tuesday, 25 September 2012 at 21:51:40 UTC, Matthew Turner wrote: Hello, I'm wondering if there is any library for making a GUI with D. If not, what would you recommend for that? Could I just use c++ libraries? Thank you, Matt http://www.prowiki.org/wiki4d/wiki.cgi?GuiLibraries Sorry it seems abrupt but that is where the information resides.
Re: Testing for template argument being result of takeExactly
On 09/26/2012 05:08 PM, Andrei Alexandrescu wrote: On 9/26/12 9:50 AM, monarch_dodra wrote: struct S{}; is(typeof(takeExactly(S, 1)) == S) //false is(S == typeof(takeExactly(S, 1))) //Error: template std.range.takeExactly does not match any function template declaration Neither should work. The expression should be takeExactly(S.init, 1). Andrei http://d.puremagic.com/issues/show_bug.cgi?id=8220 https://github.com/D-Programming-Language/dmd/pull/1007
Re: function is not function
On 21/09/12 21:59, Ellery Newcomer wrote: solution is to use std.traits, but can someone explain this to me? import std.stdio; void main() { auto a = { writeln("hi"); }; pragma(msg, typeof(a)); // void function() pragma(msg, is(typeof(a) == delegate)); // nope! pragma(msg, is(typeof(a) == function)); // nope! } The 'function' keyword is an ugly wart in the language. In void function() 'function' means 'function pointer'. But in is (X == function) 'function' means 'function'. Which is actually pretty much useless. You always want 'function pointer'. This is the only case where "function type" still exists in the language.
Re: object.error: Privileged Instruction
On 22/09/12 21:49, Jonathan M Davis wrote: On Saturday, September 22, 2012 21:19:27 Maxim Fomin wrote: Privilege instruction is an assembly instruction which can be executed only at a certain executive process context, typically os kernel. AFAIK assert(false) was claimed to be implemented by dmd as a halt instruction, which is privileged one. However, compiled code shows that dmd generates int 3 instruction for assert(false) statement and 61_6F_65_75 which is binary representation of "aoeu" for assert(false, "aoeu") statement and the latter is interpreted as privileged i/o instruction. It's a normal assertion without -release. With -release, it's a halt instruction on Linux but IIRC it's something slightly different (albeit similar) on Windows, though it might be halt there too. - Jonathan M Davis I implemented the code runtime code that does it, at least on Windows. You get much better diagnostics on Windows. IMHO it is a Linux misfeature, they conflate a couple of unrelated hardware exceptions together into one signal, making it hard to identify which it was.
Re: GUI development libraries in D?
On Tuesday, 25 September 2012 at 21:51:40 UTC, Matthew Turner wrote: Hello, I'm wondering if there is any library for making a GUI with D. If not, what would you recommend for that? Could I just use c++ libraries? Thank you, Matt GtkD is probably your best bet. I wrote a blog post here on how to get things working on Windows and Linux: http://kalekold.net/index.php?post=17 I guess now that GtkD has been updated to support Gtk3 things will be slightly different?
read single characters from stdin
Hi, to learn D, I'd like to write a simple type trainer. It should write a line to stdout and then read single characters from stdin and only accept the correct characters How can I read single characters? A similar question has been asked before without a working answer: http://forum.dlang.org/thread/jl79f7$2083$1...@digitalmars.com But I can't beliebe that there isn't a simple solution in D for this problem... Regards, Thomas Koch
Re: read single characters from stdin
On Wednesday, 26 September 2012 at 17:51:03 UTC, Thomas Koch wrote: How can I read single characters? The way I'd do it is with the C call fgetc(stdin). You can do it in D the same way if you import core.stdc.stdio; But, if you are on Linux, it isn't going to be that simple. The Linux terminal/operating system will buffer input, not sending any data to you until the user presses enter. You'll probably want to use a library like ncurses on linux... you can do without too, turning on raw mode to the terminal I think, but I don't remember how to do it right now. Are you on Linux or Windows? (I'm pretty sure it just works on windows but it's been a while since I've done an app like this.)
enum of tuples
Hi, I faced a little trouble and can not decide if it is a my mistake, a bug in std library or in compiler… Look: $ cat enum_of_structs.d struct T { int v; int opCmp( T rhs ) { return v == rhs.v ? 0 : ( v < rhs.v ? -1 : +1 ); }; }; enum E : T { A = T( 1 ), B = T( 2 ), }; $ dmd -c -w enum_of_structs.d Output is empty — there is no warnings and/or errors. In the next example I decide to use std.typecons module instead of declaring struct manually: $ cat enum_of_tuples.d import std.typecons; alias Tuple!( int, "v" ) T; enum E : T { A = T( 1 ), B = T( 2 ), }; $ dmd -c -w enum_of_tuples.d enum_of_tuples.d(5): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp does not match any function template declaration /usr/include/d/dmd/phobos/std/typecons.d(423): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp(R) if (isTuple!(R)) cannot deduce template function from argument types !()(E) enum_of_tuples.d(5): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp does not match any function template declaration /usr/include/d/dmd/phobos/std/typecons.d(423): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp(R) if (isTuple!(R)) cannot deduce template function from argument types !()(E) Oops. What the problem?
Re: enum of tuples
BTW, I use DMD64 D Compiler v2.060 on Fedora 17. ldc2 compiler (LLVM D Compiler LDC trunk, based on DMD v2.059 and LLVM 3.0) produces similar results: $ ldc2 -c -w enum_of_tuples.d enum_of_tuples.d(5): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp does not match any function template declaration /usr/include/d/std/typecons.d(422): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp(R) if (isTuple!(R)) cannot deduce template function from argument types !()(E) enum_of_tuples.d(5): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp does not match any function template declaration /usr/include/d/std/typecons.d(422): Error: template std.typecons.Tuple!(int,"v").Tuple.opCmp(R) if (isTuple!(R)) cannot deduce template function from argument types !()(E)
Re: enum of tuples
Van de Bugger: Oops. What the problem? I seems one or more bugs. D named enums are adapted from the C language, they were first of all meant to contain simple values like ints or chars. The more complex things you keep trying to put in them, the more bugs you will find :-) People in D.learn keep trying to put complex things in them, but maybe Walter has not even tested them with more complex types, like class instances. Bye, bearophile
append element to variantArray
Is it possible to append elements to a variantArray after it has been created? I have tuples of type: alias Tuple!(float[][][string], "data", ulong[string], "nSegs") aveNSegsTuple; I would like to append these tuples to a variantArray in a for loop, as more results come in. Thank you in advance for any help!
Re: enum of tuples
On Wednesday, September 26, 2012 23:24:08 bearophile wrote: > Van de Bugger: > > Oops. What the problem? > > I seems one or more bugs. D named enums are adapted from the C > language, they were first of all meant to contain simple values > like ints or chars. The more complex things you keep trying to > put in them, the more bugs you will find :-) People in D.learn > keep trying to put complex things in them, but maybe Walter has > not even tested them with more complex types, like class > instances. Classes will not work for the same reason that you can never use a class object as an enum with manifest constants. It's a long-standing bug that structs don't work as enums (other than manifest constants) even though they're supposed to according to TDPL: http://d.puremagic.com/issues/show_bug.cgi?id=4423 >From the sounds of it though, if Tuple fixes its signatures for opCmp, it can be made to work. Regardless, it should be reported that tuples don't work as enums other than manifest constants. - Jonathan M Davis
importing executables
I'm trying to make an installer application in D. I've checked with various hashes and the file it's outputting is different to the original, and therefore Windows is saying it's not a valid Win32 application. I'm sure it's me doing something wrong and not DMD's fault. Any help is appreciated. Here's the code: -installer.d- import std.stdio; immutable auto testFile = import("test.exe"); void main() { File f = File("installDir\\test.exe", "w"); f.write(testFile); f.close; } - -test.d- import std.stdio; void main() { writeln("Hello World"); } I'm compiling using: dmd test.d dmd installer.d -J%cd% DMD is version 2.060, Windows 7 64 bit.
Finite state machine in D
Hello Could someone help me with FSM (like boost MSM but simpler and in D of course) - where should I start from? I found good paper about FSM implementation in c++ (with type list and so on), but I'm not sure it is applicable in D. What is the D-way to implement fsm with code generation?
Re: read single characters from stdin
On Wednesday, 26 September 2012 at 17:51:03 UTC, Thomas Koch wrote: Hi, to learn D, I'd like to write a simple type trainer. It should write a line to stdout and then read single characters from stdin and only accept the correct characters How can I read single characters? A similar question has been asked before without a working answer: http://forum.dlang.org/thread/jl79f7$2083$1...@digitalmars.com But I can't beliebe that there isn't a simple solution in D for this problem... Regards, Thomas Koch http://dpaste.dzfl.pl/eb1387cc ;-)