Re: How to get a screenshot?

2016-09-21 Thread Konstantin Kutsevalov via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 16:36:32 UTC, Adam D. Ruppe 
wrote:
On Wednesday, 21 September 2016 at 16:33:58 UTC, Konstantin 
Kutsevalov wrote:
do anybody know how to get screenshot (for now in Linux only)? 
May be some library , examples?


simplest might be to just call out to `shellExec("import 
-window root filename.png");` and it will write the file.


Hmm, that's good idea as fast solution. Thank you Adam.


Re: Module Clarification

2016-09-21 Thread tcak via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 14:17:56 UTC, Jonathan Marler 
wrote:
I'm working on a code generation tool and wanted to make sure 
my module approach was correct.  The generated code has a 
module hierarchy, where modules can appear at any level of the 
hierarchy.


module foo;
module foo.bar;

In this case, module foo and foo.bar are independent modules.  
The foo module does not publicly import foo.bar, like a typical 
package.d module would do. At first I organized the modules 
like this:


foo.d (module foo)
foo/bar.d (module foo.bar)

But this doesn't work because the module file foo.d, cannot 
have the same name as a the directory foo.  So now I organize 
it like this:


foo/package.d (module foo)
foo/bar.d (module foo.bar)

This is not the typical usage for the "package.d" file.  
Normally, package.d would publicly import other modules, 
however, in this case, package.d is an independent module.  
This also means that if another module was added, say 
foo.bar.baz, the new file system would have to look like this:


foo/package.d (module foo)
foo/bar/package.d (module foo.bar)
foo/bar/baz.d (module foo.bar.baz)

This technique seems a bit odd, but it works.  I'm just 
wondering if there's a better way to achieve these semantics, 
or if this is the appropriate solution?


I can be wrong, but if I remember correctly, when I used 
package.d as you do a while ago (~1.5 years ago), it was acting a 
little different compared to a normal module file. Some 
declarations were not working as in a normal module. It could be 
my bad observation as well. I hope it works for you, but your 
design might break at some point.


Vibe.d help

2016-09-21 Thread Gestalt Theory via Digitalmars-d-learn
1. I get this error when trying to run a project in VS. dub 
doesn't give the error.


First-chance exception: core.exception.AssertError free() called 
with null array. at vibe-d-0.7.26\source\vibe\utils\memory.d(110)


It constantly pops up then I get an access violation and crash.


2. Many vibe.d HTTP Server options seem not to be implemented. Is 
this still the case? e.g., 
http://vibed.org/api/vibe.http.server/HTTPServerSettings.maxRequestTime


3. How to serve static files properly?

void images(HTTPServerRequest req, HTTPServerResponse res)
{
writeln("images Request");
write("Path = "); writeln(req.fullURL);
// Somehow reship request out
}

...

router.get("/images/*", );


I would like to be able to serve them but also log or redirect if 
possible. The messages are written. I tried to also serve 
directly and it didn't work, which is why I used a handler in the 
first place.


router.get("/images/*", serveStaticFiles("images/"));

I imagine the path is not correct. I am on windows and created an 
images sub dir in the projects(same depth as views, etc) but the 
images were not served. I didn't want to hard code this path, 
maybe it should be?



4. How to setup load balancing and virtual hosts? I know one can 
use a front end to do this but I saw a vibedist project that 
seems to be dead. Obviously one can make multiple HTTPServers, 
but this might get a bit messy.


What I want to eventually do is server multiple secure virtual 
domains with http's being redirected to https. I'd like to 
probably use one vibe.d instance unless there is good reason not 
to. The sites, at this point, won't have many req/sec. Maybe 
eventually I'll need to separate in to multiple processes.



5. Many other frameworks seem to support "hot swapping" of files 
while the sever is running rather than having to recompile. 
Recompiling the diet templates/project is slow and requires 
restarting the server and all that. Is there any way to get 
vibe.d to automatically monitor the projects folder or templates 
for changes and then somehow recompile and update/etc?


Thanks.



Re: Stacktrace on Null Pointer Derefence

2016-09-21 Thread Jonathan Marler via Digitalmars-d-learn

On Wednesday, 21 September 2016 at 23:36:08 UTC, Nordlöw wrote:

Doing a null deref such as

int* y = null;
*y = 42;// boom

[...]


Can you include compiler command line?  I use -g -gs -debug to 
get stack traces on windows.


Re: Stacktrace on Null Pointer Derefence

2016-09-21 Thread ketmar via Digitalmars-d-learn

On Wednesday, 21 September 2016 at 23:36:08 UTC, Nordlöw wrote:


Is there a way to get a stacktrace instead?


{ import etc.linux.memoryerror; registerMemoryErrorHandler(); }

warning: this is hightly system-specific, and may work or not 
work depending of the moon phase, and may broke on any system 
upgrade.


Stacktrace on Null Pointer Derefence

2016-09-21 Thread Nordlöw via Digitalmars-d-learn

Doing a null deref such as

int* y = null;
*y = 42;// boom

currently outputs

/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x406474]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x113d0)[0x7f08cf25e3d0]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x40233a]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x4023b9]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x4064c1]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x405704]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x40be2b]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x40c2d2]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x40bdbc]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x4056e0]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x4063b3]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x402a97]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x402a39]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x4029aa]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x402540]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f08ce77c830]
/home/per/.emacs.d/auto-builds/dmd/Debug-Unittest-Require-Full-Coverage/home/per/foo[0x402219]

Is there a way to get a stacktrace instead?

I'm using dmd git master.


Re: Vibe.d compilation error: backend/cgelem.c 5018 dmd failed with exit code 1.

2016-09-21 Thread Rene Zwanenburg via Digitalmars-d-learn

On Wednesday, 21 September 2016 at 20:22:42 UTC, llaine wrote:

The project is pretty big, DustMite would handle this?


Yes, but it may take some time. For large projects, running it on 
a server is advisable. 3K LOC should be doable on a desktop 
machine.


Dub has built-in support for running Dustmite. I'm not very 
familiar with it, but it looks like you'll want to use 'dub 
dustmite' with the --compiler-regex switch with a regex matching 
the ICE assert message.


Re: Vibe.d compilation error: backend/cgelem.c 5018 dmd failed with exit code 1.

2016-09-21 Thread llaine via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 15:24:08 UTC, Saurabh Das 
wrote:

On Wednesday, 21 September 2016 at 14:15:30 UTC, llaine wrote:
I'm sure some more experienced forum readers will weigh in 
soon, but my understanding is that:


All ICEs are errors in the compiler. You should submit it as a 
bug at https://issues.dlang.org/


If you can use DustMite to narrow down the error, that would 
help track it down much faster.


Thanks,
Saurabh


The project is pretty big, DustMite would handle this?


Re: Question about __treats

2016-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/21/16 3:38 AM, Suliman wrote:

On Wednesday, 21 September 2016 at 07:09:01 UTC, rikki cattermole wrote:

On 21/09/2016 7:06 PM, Suliman wrote:

It's seems that __treats is language keyword that help to get info from
compile-time. But there is also lib named std.traits

and I can't understand difference

https://dlang.org/spec/traits.html
https://dlang.org/phobos/std_traits.html

Could you explain the difference?


Simple, __traits or __treats as you called it is implemented by the
compiler.
But std.traits is all implemented in the standard library as user D code.

If you can do it with std.traits you should. Otherwise __traits.
So std.traits is a bit higher level and there are more things
available there as adding more __traits is a bit rare.


So for example to get All Members of class I should use allMembers from
__traits, because it's seems that std.traits do not have such future.


Yes, you can think of __traits as the basic building blocks the compiler 
provides, and std.traits as providing more features using those building 
blocks.


-Steve


Re: thisExePath purity

2016-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn

On 9/20/16 3:42 PM, crimaniak wrote:

On Tuesday, 20 September 2016 at 13:35:27 UTC, Steven Schveighoffer wrote:

Note that if you don't import the module that contains the static
ctor, it should be trimmed by the linker.

 Let's imagine linker can trim even imported module with static ctor, if
we have something like:

immutable string executablePath;

@local shared static this()
{
import std.file : thisExePath;
executablePath = thisExePath();
}

and there is no references to executablePath. Here it would be useful, I
think. Attribute @local (or @module? the name does not matter) mean this
block used only to init other symbols in this module so it can be
skipped if no references.


But if this is all that is in the module, why import the module if you 
aren't going to use any of it?



I would absolutely caution you from putting static this() inside any
template. Unfortunately, due to the way D generates these static
constructors, any module that uses staticMemoize, or *imports a module
that uses it*, will be marked as having a static constructor, and will
potentially create cycles.

 Please be more detail about cycles. Do you mean something like this?
https://isocpp.org/wiki/faq/ctors#static-init-order


Sort of, I mean this: 
https://dlang.org/spec/module.html#order_of_static_ctor


In other words, because the template has a static ctor in it, just 
instantiating it in your unrelated module puts static ctor in your 
module. And then cycles can appear that you wouldn't expect to happen.


-Steve





Re: Using Libraries

2016-09-21 Thread Karabuta via Digitalmars-d-learn

On Wednesday, 21 September 2016 at 16:23:35 UTC, Darren wrote:
Also I've been making a bit of a mess in dub apparently.  I'm 
getting:


Locally registered package gl3n ~master was not found. Please 
run "dub remove-local C:\Users\Darren\D stuff\opengl\lib".


whenever dub gets used.  Then if I run what it says I get: 
"Missing path to package."


Is there a way to return this to a default setting?


If you have not changed anything in the dub.json file, then run 
"dub build" to rebuild the packages OR try clearing the dub cache 
and rebuild.


I'm not really familiar with C++ - D bindings (I never wrote C++ 
code beyond printing a helloworld to the screen). The How To 
tutorials at https://wiki.dlang.org/Tutorials may help you with 
bindings and linking process.




Re: How to get a screenshot?

2016-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 16:33:58 UTC, Konstantin 
Kutsevalov wrote:
do anybody know how to get screenshot (for now in Linux only)? 
May be some library , examples?


simplest might be to just call out to `shellExec("import -window 
root filename.png");` and it will write the file.


How to get a screenshot?

2016-09-21 Thread Konstantin Kutsevalov via Digitalmars-d-learn

Hello everyone,

do anybody know how to get screenshot (for now in Linux only)? 
May be some library , examples?


Re: Vibe.d compilation error: backend/cgelem.c 5018 dmd failed with exit code 1.

2016-09-21 Thread Saurabh Das via Digitalmars-d-learn

On Wednesday, 21 September 2016 at 14:15:30 UTC, llaine wrote:
Using dmd every day and since one day I'm getting this error 
when I'm compiling using the -b release flag (dub build -b 
release).


I'm compiling a vibe.d application that has roughly 3k LoC.

Removing the -b flag solves the problem.

Dmd version : v2.071.0
Vibe.d version : 0.7.26


I'm sure some more experienced forum readers will weigh in soon, 
but my understanding is that:


All ICEs are errors in the compiler. You should submit it as a 
bug at https://issues.dlang.org/


If you can use DustMite to narrow down the error, that would help 
track it down much faster.


Thanks,
Saurabh



Re: Custom test runner

2016-09-21 Thread Nick Sabalausky via Digitalmars-d-learn

On 09/21/2016 02:26 AM, Jacob Carlborg wrote:

On 2016-09-21 07:51, Nick Sabalausky wrote:

IIRC, there is some way to hook in and use a custom unittest-runner. How
does one go about that?


http://dlang.org/phobos/core_runtime.html#.Runtime.moduleUnitTester



Cool, thanks.

I got that to work, and FWIW submitted a PR to add an example to the 
docs for that: https://github.com/dlang/druntime/pull/1656




Module Clarification

2016-09-21 Thread Jonathan Marler via Digitalmars-d-learn
I'm working on a code generation tool and wanted to make sure my 
module approach was correct.  The generated code has a module 
hierarchy, where modules can appear at any level of the hierarchy.


module foo;
module foo.bar;

In this case, module foo and foo.bar are independent modules.  
The foo module does not publicly import foo.bar, like a typical 
package.d module would do. At first I organized the modules like 
this:


foo.d (module foo)
foo/bar.d (module foo.bar)

But this doesn't work because the module file foo.d, cannot have 
the same name as a the directory foo.  So now I organize it like 
this:


foo/package.d (module foo)
foo/bar.d (module foo.bar)

This is not the typical usage for the "package.d" file.  
Normally, package.d would publicly import other modules, however, 
in this case, package.d is an independent module.  This also 
means that if another module was added, say foo.bar.baz, the new 
file system would have to look like this:


foo/package.d (module foo)
foo/bar/package.d (module foo.bar)
foo/bar/baz.d (module foo.bar.baz)

This technique seems a bit odd, but it works.  I'm just wondering 
if there's a better way to achieve these semantics, or if this is 
the appropriate solution?


Vibe.d compilation error: backend/cgelem.c 5018 dmd failed with exit code 1.

2016-09-21 Thread llaine via Digitalmars-d-learn
Using dmd every day and since one day I'm getting this error when 
I'm compiling using the -b release flag (dub build -b release).


I'm compiling a vibe.d application that has roughly 3k LoC.

Removing the -b flag solves the problem.

Dmd version : v2.071.0
Vibe.d version : 0.7.26




Re: What is the best way to store bitarray (blob) for pasting in database?

2016-09-21 Thread Vadim Lopatin via Digitalmars-d-learn

On Wednesday, 6 April 2016 at 12:56:39 UTC, Suliman wrote:

I have next task.
There is PostgreSQL DB. With field like: id, mydata.

mydata - is binary blob. It can be 10MB or even more.

I need load all data from PostgreSQL to SQLLite.

I decided ti create struct that and fill it with data. And then 
do INSERT operation in sqllite.


But I do not know is it's good way, and if it's ok what data 
type should I use for blob (binary data).


struct MyData
{
string  id;
string  mydata; // what datatype I should use here??
}   

MyData [] mydata;

MyData md;


while (rs.next())
{

 md.id = to!string(rs.getString(1));
 md.mydata = to!string(rs.getString(2)); //??

 mydata ~= md;
}



stmtLite.executeUpdate(`insert into MySyncData(id,mydata) 
values(md.id,md.data)`); //ddbc driver

is it's normal way to insert data?


Use ubyte[] or byte[] for blob, and setUbytes/getUbytes 
(setBytes/getBytes) to set/get value
There was issue in `bytea` type support in PostgreSQL driver. Now 
it's fixed.


Re: PostgreSQL. Unknown parameter of configuration : "autocommit"

2016-09-21 Thread Vadim Lopatin via Digitalmars-d-learn

On Tuesday, 5 April 2016 at 07:53:20 UTC, Suliman wrote:
Is there anybody who have success connect to PostgreSQL with 
ddbc?


I am getting next error: 
https://github.com/buggins/ddbc/issues/22


Fixed.


Re: Using Libraries

2016-09-21 Thread Darren via Digitalmars-d-learn

On Tuesday, 20 September 2016 at 19:45:57 UTC, Karabuta wrote:

On Tuesday, 20 September 2016 at 15:38:55 UTC, Darren wrote:
On Tuesday, 20 September 2016 at 15:07:53 UTC, rikki 
cattermole wrote:



Ok lets start at the very beginning...


I think I need to start before that, haha.

I might need more of a step-by-step guide.  I'm a complete 
beginner to programming, not just D.  I worked through 
Programming in D, where I was just compiling with dmd, then 
when I decided to learn OpenGL I seem to be using dub for 
everything.


There have been a few libraries I've wanted to use but 
couldn't because they didn't have a pre-compiled binary, which 
is all I've been able to get working through sheer trial and 
error.  Some sites say to use things like CMake and cygwin, 
but I'm uncomfortable using things I have no idea about.


Dub is like a package manager for D (like what npm is to 
node.js). All dub libraries are hosted at code.dlang.org. When 
you see a library at code.dlang.org you want to use, you could 
either type "dub install packagename" whilst in the dub project 
ROOT or specify dependencies in the dub.json file.
You can then run "dub run" which will take care of fetching and 
building dependencies/libraries from code.dlang.org (including 
linking and running the binary).


For example, there is a web framework called vibe.d. If I want 
to use vide.d, I can specify dependencies as;


dependencies: {
"vide-d":"^0.7.29"
}


In my app.d file (which is available for any dub project 
created using "dub init projectname") I can import vibe.d using;


import vide.d;
void main() {
...
}

I can now compile and run the program with "dub run" or "dub 
build" to only build and link without running.


Thank you!  This does seem to work for packages listed on the dub 
page (tested it with gl3n).


Would you be able to tell me how to install libraries that aren't 
written in D?  A lot of what I need to use are written in C/C++, 
and I've use dub for bindings to those binaries.  But what if I 
need to compile/build those libraries from scratch, or use/link a 
static library?


I'm not sure if there's a simple answer to this question but I 
could do with guidance with how to use those libraries with D 
(other tutorials just focus on C++ with Visual Studio, etc).


Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:39:57 UTC, Johan Engelen 
wrote:
It should really be mentioned in the documentation of 
toHexString, with an actual example instead of a unittest.


Do you use my dpldocs.info? I add such notes there from time to 
time:


http://dpldocs.info/experimental-docs/std.digest.digest.toHexString.1.html



I guess `ubyte[] hash = md5.finish();` would have fixed it too.


Yes, though IMO that's still depending on the same language 
design flaw. I'd prefer to just explicitly pass `hash[]` to the 
function call so it is clear right there.


Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 13:06:08 UTC, Adam D. Ruppe 
wrote:


the variable you are assigning the result to never does 
anything with regard to overloads or template args.


Gotcha, thanks.



Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:29:54 UTC, Johan Engelen 
wrote:

Wouldn't something like this be possible?

`T toHexString(string toHexString(Order order = 
Order.increasing, LetterCase letterCase = LetterCase.upper, 
T)(.) if (T == string)`


I'm not sure what that's supposed to be but in any case, 
you'd still need to specify T somewhere in the call, the variable 
you are assigning the result to never does anything with regard 
to overloads or template args.


Allocating Heap/GC Storage upon Default Construction of RC Containers

2016-09-21 Thread Nordlöw via Digitalmars-d-learn
Is there any way to make a default constructor of a struct 
container allocate/initialize an internal pointer?


I need this in a container with RC behaviour similar to

struct Container
{
this()// this is currently forbidden:
{
_rcStore = emplace(cast(RCStore*)malloc(RCStore.size), 
null, 0);

}

private:
static struct RCStore
{
T* store;
size_t refCount;
}
RCStore* _rcStore;
}

If I can't modify default construction in containers such as 
`Container` it is gonna behave in the same confusing way as empty 
AA's do for (novel) D developers. Namely that the assignment of 
uninitialized AA's has copy semantics and non-empty AA's have 
reference semantics.


I believe Andralex has spoken about this being a problem that 
should be fixed if possible.


Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:20:14 UTC, Adam D. Ruppe 
wrote:


This is a pretty common pitfall (and IMO one of the most 
egregious design flaws in the language), I see it all the time.


I write very little D code, so I guess it had to happen at some 
point then. Man, this is really bad :((


toHexString, when given a static array, returns a static array, 
but the language allows you to implicitly slice that into a 
pointer (mistaken design in any case, doubly so since it a 
stack pointer)... and moreover it is implicitly cast to 
immutable!


Thanks for the explanation.
It should really be mentioned in the documentation of 
toHexString, with an actual example instead of a unittest.

The original code was doing:
```
MD5 md5;
md5.start();
md5.put(cast(const(ubyte)[]) "some interesting data");
auto hash = md5.finish();
return toHexString!(LetterCase.lower)(hash);
```

I guess `ubyte[] hash = md5.finish();` would have fixed it too.


Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:20:14 UTC, Adam D. Ruppe 
wrote:


It is neither, the compiler chose the right overload (remember, 
overloads are chosen based on the arguments alone, the type you 
specify for the variable holding the return value isn't a 
consideration there) and the implementation of each overload is 
correct.


Wouldn't something like this be possible?

`T toHexString(string toHexString(Order order = Order.increasing, 
LetterCase letterCase = LetterCase.upper, T)(.) if (T == 
string)`


Re: Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 12:07:31 UTC, Johan Engelen 
wrote:

string a = toHexString(hash);


This is a pretty common pitfall (and IMO one of the most 
egregious design flaws in the language), I see it all the time.


toHexString, when given a static array, returns a static array, 
but the language allows you to implicitly slice that into a 
pointer (mistaken design in any case, doubly so since it a stack 
pointer)... and moreover it is implicitly cast to immutable!


So it will implicitly cast that char[x] to string in a LOT of 
places... and it is almost always wrong.


If you passed `hash[]` it should then do what you want... so 
arguably the implicit slice rule is confusing you here too, I'd 
LOVE to kill that rule entirely.


I don't know whether this is a compiler bug (choosing the wrong 
overload) or a Phobos bug (overloads don't work like that).


It is neither, the compiler chose the right overload (remember, 
overloads are chosen based on the arguments alone, the type you 
specify for the variable holding the return value isn't a 
consideration there) and the implementation of each overload is 
correct.


But the horribly wrong implicit slice and cast rules make it do 
the totally wrong thing while looking fine at first glance.


Template overloads involving `string` and `char[constant]` return value

2016-09-21 Thread Johan Engelen via Digitalmars-d-learn

What's the bug in the following code:

```d
import std.digest.md;
import std.stdio;

pragma(inline, false) // just in case
string getHash()
{
ubyte[16] hash = [1,2,3,4,5,6,6,78,8,8,7,7,6,3,2,3];
string a = toHexString(hash);
return a;
}

pragma(inline, false) // just in case
void destroystack()
{
writeln("asd","asd","asd","asd","asd","asd");
}

void main()
{
string a = getHash();
destroystack();
writeln(a);
}
```

Hint: when changing
```
string a = toHexString(hash);
return a;
```
to
```
return toHexString(hash);
```
the compiler errors with:
`Error: escaping reference to stack allocated value returned by 
toHexString(hash)`.


So:
-  the documentation of toHexString says that the overloads 
returning a string return a GC allocated string
- the _implementation_ of `string toHexString(...)` does a `new 
char[16]`, so GC allocates.
- `string a = toHexString(hash);` calls `char[num*2] 
toHexString(...)` instead of `string toHexString(...)`.   OOPS.


https://issues.dlang.org/show_bug.cgi?id=16519

I don't know whether this is a compiler bug (choosing the wrong 
overload) or a Phobos bug (overloads don't work like that).
How are template overloads involving `string` and 
`char[constant]` return values supposed to work?


Still can't believe I am the first one to run into this, what am 
I doing wrong?


-Johan


Re: Error: no property 'select' for type 'ddbc.core.Statement'

2016-09-21 Thread Vadim Lopatin via Digitalmars-d-learn

On Sunday, 31 January 2016 at 09:15:04 UTC, Suliman wrote:
I hope that here I will get answer faster then on 
https://github.com/buggins/ddbc/issues/18


I am using ddbc diver for access to mysql. I need to return 
result of request to struct. My code is next:


import std.stdio;
import ddbc.all;
import std.stdio;
import std.conv;

void main()
{
string[string] params;
MySQLDriver driver = new MySQLDriver();
string url = MySQLDriver.generateUrl("localhost", 3306, 
"test");

params = MySQLDriver.setUserAndPassword("root", "pass");
	DataSource ds = new ConnectionPoolDataSourceImpl(driver, url, 
params);


// creating Connection
auto conn = ds.getConnection();
scope(exit) conn.close();

// creating Statement
auto stmt = conn.createStatement();
scope(exit) stmt.close();

string sql = "select * from test.imgs";
auto images = stmt.executeQuery(sql);

struct myData
{
 int id;
 string date;
}

foreach(ref e; stmt.select!myData)
{

}

/* this code is work
while(images.next())
{
string mydata = images.getString(4);
writeln(mydata);
readln;
}
*/

}

I am getting error: Error: no property 'select' for type 
'ddbc.core.Statement'


What I am doing wrong?


You forgot to add "import ddbc.pods;"
Sorry for late answer :)
Closing issue.




Re: D and math, can you isolate this ?

2016-09-21 Thread Basile B. via Digitalmars-d-learn

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:

The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)


Forget to say yesterday that actually the original equation is

x = pow(cos(angle), 0.25*c);
y = pow(sin(angle), 0.25*c);

But I couldn't use this form.


Re: D and math, can you isolate this ?

2016-09-21 Thread Nicholas Wilson via Digitalmars-d-learn

On Wednesday, 21 September 2016 at 08:21:29 UTC, Basile B. wrote:
On Wednesday, 21 September 2016 at 01:34:06 UTC, Nicholas 
Wilson wrote:

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:

[...]


So if we rearrange and take the logs of both sides and divide 
by c we get


2*log(1-y)/c = log(1-2^(-2/c))

and then that we have one occurrence of c on each side do an 
iterative back substitution to find the intersection given 
that you know for y=0.5 ,c = 2.
We used this method for finding voltages and currents in 
circuits with semiconductors.


Y is a floating point value. I think I'm gonna make a LUT for 
let's say 100 values to find the initial range where the result 
stands.


What does Y being float have to do with this? LUT is a good idea, 
a round number like 64 or 128 (or even 32) is probably better.


then do
g = 2*log(1-y);//constant
c(n+1) = g/log(1-2^(-2/c(n)))
where c(1) is a guess from the LUT.
the iteration should converge very fast.


Re: D and math, can you isolate this ?

2016-09-21 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 01:34:06 UTC, Nicholas Wilson 
wrote:

On Tuesday, 20 September 2016 at 12:35:18 UTC, Basile B. wrote:
I've recently started an easing/interpolation family of 
function in my D user library. It's based on something I know 
well since I've already used them in 2012 in a VST plugin 
called GrainPlot (RIP).


However for one of the function, I can't manage to get the 
inverse.


A function that's fully implemented:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L598
- f(x,c) = x*x*x - x*x*c + x*c;
- c(f(0.5)) = 4 * (y - 0.125));

Another:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L749
- f(x,c) = pow(x, c);
- c(f(0.5)) = log(y) / log(0.5));

The problem is here:
https://github.com/BBasile/iz/blob/master/import/iz/math.d#L849
- f(x,c) = 1.0 - pow(1.0 - pow(x, 2.0/c), c * 0.5);
- c(f0.5)) = ?

Which means that I ask you if you can isolate c for

y = 1.0 - pow(1.0 - pow(0.5, 2.0/c), c * 0.5);

y is always f(0.5,c)


So if we rearrange and take the logs of both sides and divide 
by c we get


2*log(1-y)/c = log(1-2^(-2/c))

and then that we have one occurrence of c on each side do an 
iterative back substitution to find the intersection given that 
you know for y=0.5 ,c = 2.
We used this method for finding voltages and currents in 
circuits with semiconductors.


Y is a floating point value. I think I'm gonna make a LUT for 
let's say 100 values to find the initial range where the result 
stands.


Re: Question about __treats

2016-09-21 Thread rikki cattermole via Digitalmars-d-learn

On 21/09/2016 7:38 PM, Suliman wrote:

On Wednesday, 21 September 2016 at 07:09:01 UTC, rikki cattermole wrote:

On 21/09/2016 7:06 PM, Suliman wrote:

It's seems that __treats is language keyword that help to get info from
compile-time. But there is also lib named std.traits

and I can't understand difference

https://dlang.org/spec/traits.html
https://dlang.org/phobos/std_traits.html

Could you explain the difference?


Simple, __traits or __treats as you called it is implemented by the
compiler.
But std.traits is all implemented in the standard library as user D code.

If you can do it with std.traits you should. Otherwise __traits.
So std.traits is a bit higher level and there are more things
available there as adding more __traits is a bit rare.


So for example to get All Members of class I should use allMembers from
__traits, because it's seems that std.traits do not have such future.


Yeah exactly.


Re: Question about __treats

2016-09-21 Thread Suliman via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 07:09:01 UTC, rikki cattermole 
wrote:

On 21/09/2016 7:06 PM, Suliman wrote:
It's seems that __treats is language keyword that help to get 
info from

compile-time. But there is also lib named std.traits

and I can't understand difference

https://dlang.org/spec/traits.html
https://dlang.org/phobos/std_traits.html

Could you explain the difference?


Simple, __traits or __treats as you called it is implemented by 
the compiler.
But std.traits is all implemented in the standard library as 
user D code.


If you can do it with std.traits you should. Otherwise __traits.
So std.traits is a bit higher level and there are more things 
available there as adding more __traits is a bit rare.


So for example to get All Members of class I should use 
allMembers from __traits, because it's seems that std.traits do 
not have such future.


Re: Question about __treats

2016-09-21 Thread rikki cattermole via Digitalmars-d-learn

On 21/09/2016 7:06 PM, Suliman wrote:

It's seems that __treats is language keyword that help to get info from
compile-time. But there is also lib named std.traits

and I can't understand difference

https://dlang.org/spec/traits.html
https://dlang.org/phobos/std_traits.html

Could you explain the difference?


Simple, __traits or __treats as you called it is implemented by the 
compiler.

But std.traits is all implemented in the standard library as user D code.

If you can do it with std.traits you should. Otherwise __traits.
So std.traits is a bit higher level and there are more things available 
there as adding more __traits is a bit rare.


Question about __treats

2016-09-21 Thread Suliman via Digitalmars-d-learn
It's seems that __treats is language keyword that help to get 
info from compile-time. But there is also lib named std.traits


and I can't understand difference

https://dlang.org/spec/traits.html
https://dlang.org/phobos/std_traits.html

Could you explain the difference?


Re: Custom test runner

2016-09-21 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-09-21 07:51, Nick Sabalausky wrote:

IIRC, there is some way to hook in and use a custom unittest-runner. How
does one go about that?


http://dlang.org/phobos/core_runtime.html#.Runtime.moduleUnitTester

--
/Jacob Carlborg


Re: What exactly does the compiler switch -betterC do?

2016-09-21 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-09-21 02:25, Anonymouse wrote:

On Monday, 20 June 2016 at 06:35:32 UTC, Jacob Carlborg wrote:

It is intended to allow you to link an application without druntime.
[...]


What is the equavilent in gdc and ldc?


No idea, try ldc/gdc --help ;)

--
/Jacob Carlborg


Re: setting fields of object using traits

2016-09-21 Thread Jacob Carlborg via Digitalmars-d-learn

On 2016-09-20 21:45, Ram_B wrote:

I'm trying to set fields of object from JSON with traits library. How i
can to it properly?

import std.stdio;
import std.json;
import std.traits;
import std.meta:  Alias;

class Obj{
void fromJSON(this T)(JSONValue j){
foreach(field; FieldNameTuple!T){
alias member = Alias!(__traits(getMember, T, field));
static if (__traits(hasMember, member, "fromJSON")){
member.fromJSON(j[field]);
} else {
member = j[field];


I'm pretty sure this won't work. You need to use "this.tupleof[index] = 
value" to set a value. You can iterate all fields using "T.tupleof" and 
then get the name of a field using "__traits(identifier, 
T.tupleof[index]);". Or you can use a string mixin.


--
/Jacob Carlborg