Re: Using systemDependencies in DUB
On Sunday, 24 June 2018 at 12:15:42 UTC, Timoses wrote: What about the "libs" build settings (or "lflags")? (http://code.dlang.org/package-format?lang=json) "libs": "clang" There it was, hidden in plain sight. Thanks for the extra pair of eyes Timoses. I don't know how I missed it. Successfully linking against 6.0 now. Cheers!
Using systemDependencies in DUB
Hi, I'm trying to use dub to compile a quick experiment that uses Deimos libclang bindings, which of course requires linking against an installed libclang. I believe this is what I need to include in dub.json: "systemDependencies": "libclang-6.0" But it just won't link against the lib in the compilation process. Using the -v option reveals the linking stage call: /usr/bin/dmd -of.dub/build/application-debug-linux.posix-x86_64-dmd_2081-7C29937BC9011750CFA15D7325224156/damnc .dub/build/application-debug-linux.posix-x86_64-dmd_2081-7C29937BC9011750CFA15D7325224156/damnc.o -L--no-as-needed -g It does not mention libclang at all. I've tried with all "clang", "libclang-6.0.so.1", but I just don't seem to be able to make it work. Would anyone mind helping me out? BTW, I am aware Deimos bindings for libclang are based on v3.7 and not 6.0, but 3.7 is not available for Ubuntu 18.04 and I was wagering the interface probably hasn't changed much.
Re: value of 'this' is not know at CT for typeof(this)
On Friday, 26 January 2018 at 20:13:14 UTC, Simen Kjærås wrote: I can't reproduce the problem. Could you give us some more code - preferably a compilable segment that gives the same problem? -- Simen https://github.com/Dechcaudron/dserialize/tree/6c67e44dedf81d9cb8c0d9d80cf4eb85e9abecd0 There it goes, dub test to see it. Tests are not expected to pass, but they should compile.
value of 'this' is not know at CT for typeof(this)
So I'm trying to get this to compile: ``` static foreach (alias member; getSymbolsByUDA!(typeof(this), Serialize)) serializeMember!member(bundle); ``` And I'm getting the following error: value of 'this' is not known at compile time for the line on top. typeof(this) to get the type of the calling object seems to work everywhere else (this happens inside a method definition inside a mixin template). Can anyone tell me why?
Re: Question about destructor of database and multiple use access
On Thursday, 28 July 2016 at 15:18:24 UTC, Lodovico Giaretta wrote: 3) at program end, live objects are not scheduled for finalization; 4) at program end, pending finalizations from previous collections may not be run. I didn't know these two, can I get source on them? Also, I'm assuming what I said about calling destroy(instance) is as correct as calling a cleanup method?
Re: Question about destructor of database and multiple use access
On Thursday, 28 July 2016 at 14:24:16 UTC, Suliman wrote: void dbInsert(string login, string uploading_date, string geometry_type, string data) { Statement stmt = conn.createStatement(); //stmt.executeUpdate("..."); // some processing of request scope(exit) stmt.close(); // closing } void getIMGsMetadataFromDB(Json request) { Statement stmt = conn.createStatement(); //stmt.executeWuery("..."); // some processing of request scope(exit) stmt.close(); // closing } Is this code is more correct? You'd have to go with Statement stmt = conn.createStatement(); scope(exit) stmt.close(); //stmt.executeUpdate... //some processing stmt.close will be called only when leaving the scope, although it appears right after stmt initialization. Check this out: https://dlang.org/spec/statement.html#scope-guard-statement
Re: Question about destructor of database and multiple use access
On Thursday, 28 July 2016 at 14:43:32 UTC, Lodovico Giaretta wrote: No! Never run important finalization in a class destructor! The GC is not obliged to run the destructors, so you may end up with your objects destroyed but the connections still open. For this kind of important things, you have to do them manually. I always thought that the moment of finalization is undetermined, but that the GC does indeed run the destructor... Weird, I'll have to look into that. After all what would be the point of destructors if they are not guaranteed to be run? Still, if you are to manually call a cleanup method, you might as well call destroy on the instance to force the destructor to run right away, right? Not that it makes any difference to call instance.cleanup() or destroy(instance) so long as cleanup and the destructor contain the same code.
Re: Question about destructor of database and multiple use access
I don't know anything about the driver you are using, but from my general experience with DBs I'll try to give you some insight. On Thursday, 28 July 2016 at 14:01:45 UTC, Suliman wrote: 1. Should declaration of them be field of class? I'd say so. If you intend to use each instance of the class for more than db operation (which you probably do), you'll probably want to keep the connection alive between method calls, connecting in the constructor. As for the statement, I don't really know what it is about. 2. Should I call destructor and how it's should like? You certainly want to close the connection to the db. Basically, the destructor is intended to free resources such as dynamic memory, closing connections... the GC will take care of dynamic memory, but closing the connection to the DB is up to you. So do that in the destructor. As for the rest of the fields, I don't know if manual cleanup will be required, sorry. 3. If I will not call it would it wrong? It would go wrong. Each instance would open a connection to the DB and it would never be closed, which is a very bad thing. The open connections would go adding up until the DB would not be able to accept anymore connections and would probably refuse to function. 4. If 100 users will come to my site, my code will open 100 connections? And would open every new connection for every request? Can I open single connection and use it for all users? It depends where you use this class and how you use it. If you create an instance upon receiving a network request, a connection would be open for each request, then closed in the destructor. So if 100 users go to your site and they all start sending requests at the same time, each request would open a db connection. If you want to avoid this, either process the requests sequentially (I don't recommend this) and create and instance of this class beforehand, which you will use for all of them. If you don't want to do sequential processing (which is likely your case), and you still want to keep connections to a minimum, create a shared instace of GDB and use it across the threads in which requests are processed (syncronization will be required). If you want to avoid syncronization issues while still maintaining the benefits of shared instances, you could go with an instance pool [1]. But opening connections upon request receiving is not -that bad-, especially for a start, so long as the maximum number of connections doesn't exceed a certain limit. But I'd go with the pool. As for the scope(exit) conn.close(); you don't have to worry about that so long as you manage it in the destructor. If you don't, and open the connection in a method, that line would go right after the connection opening, so you ensure it is close upon scope exit. Cheers! [1] https://en.wikipedia.org/wiki/Object_pool_pattern
Re: Broken TLS?
On Wednesday, 27 July 2016 at 20:54:00 UTC, ag0aep6g wrote: Looks pretty bad. There's an open issue on this: https://issues.dlang.org/show_bug.cgi?id=16095 Giving my 20 votes to the issue (are votes even taken into account?). At least now I know the source of attribute-enforcements breakdown is basically delegate management. That should help me out enough so I don't have this issue anymore. Thanks a bunch. Can I get your votes on that issue?
Broken TLS?
I keep getting data from within a struct shared across threads for apparently no reason: the code is the following: import std.stdio; import std.concurrency; import core.thread : Thread, thread_joinAll; struct Foo { int a; int b; this(int a, int b) { this.a = a; this.b = b; writefln("Constructor -> a: %s, b: %s, is %s, : %s, this: %s, Thread: %s", this.a, this.b, , , , Thread.getThis.id); } ~this() { writefln("Final values were a:%s, b:%s", a, b); } void ping() shared { import core.time: dur; writefln("a: %s, b: %s, : %s, : %s, this: %s, Thread: %s", a, b, , , , Thread.getThis.id); a = 0; b = 0; } void fire() { spawn(); } void explode() shared { ping(); } } void main() { auto a = Foo(1, 2); a.fire(); thread_joinAll(); } What I get on screen is the following: Constructor -> a: 1, b: 2, is 7FFD5D9E3928, : 7FFD5D9E392C, this: 7FFD5D9E3928, Thread: 139774191032448 a: 1, b: 2, : 7FFD5D9E3928, : 7FFD5D9E392C, this: 7FFD5D9E3928, Thread: 139774178481920 Final values were a:0, b:0 So effectively, the thread spawned does have access to the original struct and is able to modify it. Is there anything I'm doing wrong? I won't lie, data sharing is the only thing about D I don't find quite usable yet. Can anybody help me out on this?
Re: Why can't I assign a mixin to an alias?
On Saturday, 11 June 2016 at 01:53:10 UTC, David Nadlinger wrote: This might be a gratuitous grammar restriction. There are a few of those surrounding alias "targets". A template that simply returns its parameter might work, though, such as std.meta.Alias (alias foo = Alias!(mixin(…));). It seems to be that it would be a good idea to file this in as a suggested change/fix. Do I have support?
Why can't I assign a mixin to an alias?
I have the following code: private string getVariableSignalWrappersName(VarType)() { return VarType.stringof ~ "SignalWrappers"; } void addVariableListener(VarType)(int variableIndex, void delegate(int, VarType)) { alias typeSignalWrappers = mixin(getVariableSignalWrappersName!VarType); } On compilation, the following error is issued: Error: basic type expected, not mixin Why should it be like that? I believe the compiler should not impose restrictions on what mixins can or cannot do :/