Re: AA struct hashing bug?

2015-12-08 Thread Ivan Kazmenko via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 11:45:25 UTC, Random D user wrote:
Ok. This is minimal app that crashes for me. If someone could 
try this:


At the very least, there is no crash when changing `struct Foo` 
to `static struct Foo`, so it is perhaps related to `Foo` being 
an inner struct with a pointer to parent class.


Re: AA struct hashing bug?

2015-12-08 Thread Ivan Kazmenko via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 11:45:25 UTC, Random D user wrote:
Ok. This is minimal app that crashes for me. If someone could 
try this:


OK, this at least reproducibly crashes here, too (-m32 and -m64 
on Windows, tried dmd 2.069.0 and 2.067.1).


Re: AA struct hashing bug?

2015-12-08 Thread Random D user via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 11:04:49 UTC, Random D user wrote:

I need to look into this more.


Ok. This is minimal app that crashes for me. If someone could try 
this:


class App
{
this()
{
}

void crash( int val )
in
{
assert( val == 1 );
}
body
{
struct Foo
{
this( int k )
{
a = k;
}
int a;
}

Foo foo;
int[ Foo ] map;

map[ foo ] = 1;  // Crash! bug?
}
}

int main( char[][] args )
{
App a = new App;
a.crash( 1 );

return 0;
}

And the previous case for the crash looks like this:
asm:
_D6object14TypeInfo_Class7getHashMxFNbNexPvZm:
7ff6d9e4b500  push rbp
7ff6d9e4b501  mov rbp, rsp
7ff6d9e4b504  sub rsp, 0x30
7ff6d9e4b508  mov [rbp-0x8], rsi
7ff6d9e4b50c  mov rsi, [rdx]
7ff6d9e4b50f  test rsi, rsi
7ff6d9e4b512  jz 
_D6object14TypeInfo_Class7getHashMxFNbNexPvZm+0x20 
(0x7ff6d9e4b520)

7ff6d9e4b514  mov rcx, rsi
7ff6d9e4b517  mov rax, [rsi]
7ff6d9e4b51a  call qword near [rax+0x10] < 
crash here
7ff6d9e4b51e  jmp 
_D6object14TypeInfo_Class7getHashMxFNbNexPvZm+0x22 
(0x7ff6d9e4b522)

7ff6d9e4b520  xor eax, eax
7ff6d9e4b522  mov rsi, [rbp-0x8]
7ff6d9e4b526  lea rsp, [rbp]
7ff6d9e4b52a  pop rbp

stack:

_D6object14TypeInfo_Class7getHashMxFNbNexPvZm() + 0x1e bytesD
_D6object14TypeInfo_Const7getHashMxFNbNfxPvZm() + 0x13 bytesD
application.Application.startup.Foo.__xtoHash( 
application.Application.startup.Foo* p, ulong h ) + 0x55 bytes	D

_D6object15TypeInfo_Struct7getHashMxFNaNbNfxPvZm() + 0x22 bytes D
_aaGetY() + 0xa0 bytes  D
application.Application.startup() Line 159 + 0x26 bytes D


Re: AA struct hashing bug?

2015-12-08 Thread Ivan Kazmenko via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 11:45:25 UTC, Random D user wrote:
Ok. This is minimal app that crashes for me. If someone could 
try this:


Interesting.

With dmd 2.064.2, your example compiles and runs fine.

With dmd 2.065.0, it does not compile, complaining that there is 
no opCmp for `Foo`s.


With dmd 2.066.0, and up to the current version, it compiles fine 
but crashes at runtime.


So I'd say it's a regression.

The tracker at issues.dlang.org does not report much bugs related 
to inner structs.

Can you please file a new issue there?


Re: AA struct hashing bug?

2015-12-08 Thread Random D user via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 01:23:40 UTC, Ivan Kazmenko wrote:

On Monday, 7 December 2015 at 22:03:42 UTC, Alex Parrill wrote:

On Monday, 7 December 2015 at 18:48:18 UTC, Random D user
Tested the same code with -m32 and -m64 on Windows.  Works for 
me, too.


I tried this again. And it seems it might be my bug or that the 
runtime somehow corrupts it's state. Scary.


So I have an App class that gets created in main.
Basically
App = new App
App.start();

If I put that code as the first thing in the constructor 
everything works.
If I put that code as the first thing in the first method after 
constructor it crashes.

And that code is completely unrelated to everything else.
Without the code snippet the whole app works fine.
Also if I wrap the code in a local funtion or class, it works 
fine even in the first method.


I need to look into this more.


Re: AA struct hashing bug?

2015-12-08 Thread Ivan Kazmenko via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 11:04:49 UTC, Random D user wrote:
On Tuesday, 8 December 2015 at 01:23:40 UTC, Ivan Kazmenko 
wrote:

On Monday, 7 December 2015 at 22:03:42 UTC, Alex Parrill wrote:

On Monday, 7 December 2015 at 18:48:18 UTC, Random D user
Tested the same code with -m32 and -m64 on Windows.  Works for 
me, too.


I tried this again. And it seems it might be my bug or that the 
runtime somehow corrupts it's state. Scary.


So I have an App class that gets created in main.
Basically
App = new App
App.start();

If I put that code as the first thing in the constructor 
everything works.
If I put that code as the first thing in the first method after 
constructor it crashes.

And that code is completely unrelated to everything else.
Without the code snippet the whole app works fine.
Also if I wrap the code in a local funtion or class, it works 
fine even in the first method.


Well, if you manage to reduce the code to a minimal example 
reproducing the bug, and then post it, only then we can try to 
help.  Otherwise, other people will have nothing but guesses.




Re: benchmark on binary trees

2015-12-08 Thread visitor via Digitalmars-d-learn


using Apache Portable Runtime(APR) like in the C version :
http://dpaste.dzfl.pl/6ca8b5ffd6dc

works like a charm, 2.061s on my machine !

if file name is binarytrees.d
dmd -w -inline -O -release -I/usr/include/apr-1.0 
-L/usr/lib/x86_64-linux-gnu/libapr-1.so -of"binarytrees" 
"binarytrees.d"


measured with "time ./binarytrees 20" on command line:
real0m2.061s
user0m8.156s
sys 0m0.181s

C version gives :
real0m1.892s
user0m9.087s
sys 0m0.188s

Not bad !!! :-D

Still i would like to know what i'm doing wrong with the 
allocator's version, besides the fact that apr tools are doing 
more sophisticated work than my naive approach :-D ?


Re: How to make a transparent wrapper type?

2015-12-08 Thread Random D user via Digitalmars-d-learn

On Monday, 7 December 2015 at 20:03:07 UTC, Namespace wrote:

This seems to work:

struct RefVal(T) {
private T* ptr;

this(T* val) {
ptr = val;
}

ref auto opAssign(U)(auto ref U value) {
*ptr = value;

return *ptr;
}

auto get() inout {
return ptr;
}
}



Yes. It works for assignment as expected. Thanks. I don't know 
why I didn't try that. I mean I tried something like this:


struct RefVal(T)
{

}


Re: How to make a transparent wrapper type?

2015-12-08 Thread Random D user via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 10:26:18 UTC, Random D user wrote:

On Monday, 7 December 2015 at 20:03:07 UTC, Namespace wrote:

This seems to work:

struct RefVal(T) {
private T* ptr;

this(T* val) {
ptr = val;
}

ref auto opAssign(U)(auto ref U value) {
*ptr = value;

return *ptr;
}

auto get() inout {
return ptr;
}
}



Yes. It works for assignment as expected. Thanks. I don't know 
why I didn't try that. I mean I tried something like this:


struct RefVal(T)
{

}


Whoops. For some reason lost focus to window while typing and 
accidentally sent the message.


Well. Anyway, I tried something similar using alias this and 
template functions, but obviously it didn't work.


Unfortunately. Your version doesn't work with methods. For 
example if Ref!T is Ref!Struct then ref.method() doesn't work. 
That's the reason for alias this.

But it's good enough with public ptr.

Maybe opDispatch could help here. I haven't really used it so far.


Re: Reset all Members of a Aggregate Instance

2015-12-08 Thread Marc Schütz via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 05:13:51 UTC, Chris Wright wrote:

On Tue, 08 Dec 2015 14:12:02 +1100, Daniel Murphy wrote:


On 4/12/2015 8:38 AM, Chris Wright wrote:
An object reference is just a pointer, but we can't directly 
cast it. So we make a pointer to it and cast that; the type 
system allows it. Now we can access the data that the object 
reference refers to directly.


Casting is fine too: cast(void*)classRef


Amazing. I assumed that this wouldn't be allowed because it's 
not exactly nice to the type system, but apparently you can 
cast anything but a user- defined value type to void*. Bool, 
dchar, associative arrays, normal arrays, the good void* casts 
them all.


A class can theoretically overload `opCast`. Therefore, to be 
100% sure it works in all cases, you should use `*cast(void**) 
`.


Re: benchmark on binary trees

2015-12-08 Thread visitor via Digitalmars-d-learn

C++ version :
real0m3.587s
user0m9.211s
sys 0m7.341s




Re: Question about mysql-d Object

2015-12-08 Thread Martin Tschierschke via Digitalmars-d-learn

On Monday, 7 December 2015 at 16:11:19 UTC, Daniel Kozak wrote:
On Monday, 7 December 2015 at 14:40:12 UTC, Martin Tschierschke 
wrote:

When I do the following:

auto mysql = new Mysql("localhost", 3306, "mt", "", 
"verwaltung");

auto rows = mysql.query("select field from my_table limit 50");

foreach(row;rows){
 writeln(row["field"]);}

// second time same loop

foreach(row;rows){
 writeln(row["field"]);}


[...]

A nested loop, did not worked either:

foreach(row;rows){
 foreach(field;row){
 writeln(field);}
}

Which other ways to access the elements of rows do I have?


[...]

what if you make array from it:
import std.array: array;
auto rows = mysql.query("select field from my_table limit 
50").array;

Thank you both for your answers!
This worked, for the first part of my question.
Now I took a work around, getting the field names in a separate 
mysql-request,

but they should be available in the row object, too?



Re: Question about mysql-d Object

2015-12-08 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 08 Dec 2015 14:34:53 +
Martin Tschierschke via Digitalmars-d-learn
 napsáno:

> On Monday, 7 December 2015 at 16:11:19 UTC, Daniel Kozak wrote:
> > On Monday, 7 December 2015 at 14:40:12 UTC, Martin Tschierschke 
> > wrote:  
> >> When I do the following:
> >>
> >> auto mysql = new Mysql("localhost", 3306, "mt", "", 
> >> "verwaltung");
> >> auto rows = mysql.query("select field from my_table limit 50");
> >>
> >> foreach(row;rows){
> >>  writeln(row["field"]);}
> >>
> >> // second time same loop
> >>
> >> foreach(row;rows){
> >>  writeln(row["field"]);}
> >>  
> [...]
> >> A nested loop, did not worked either:
> >>
> >> foreach(row;rows){
> >>  foreach(field;row){
> >>  writeln(field);}
> >> }
> >>
> >> Which other ways to access the elements of rows do I have?
> >>  
> [...]
> > what if you make array from it:
> > import std.array: array;
> > auto rows = mysql.query("select field from my_table limit 
> > 50").array;  
> Thank you both for your answers!
> This worked, for the first part of my question.
> Now I took a work around, getting the field names in a separate 
> mysql-request,
> but they should be available in the row object, too?
> 
rows.fields();



Re: Question about mysql-d Object

2015-12-08 Thread Daniel Kozak via Digitalmars-d-learn
V Tue, 08 Dec 2015 14:34:53 +
Martin Tschierschke via Digitalmars-d-learn
 napsáno:

> On Monday, 7 December 2015 at 16:11:19 UTC, Daniel Kozak wrote:
> > On Monday, 7 December 2015 at 14:40:12 UTC, Martin Tschierschke 
> > wrote:  
> >> When I do the following:
> >>
> >> auto mysql = new Mysql("localhost", 3306, "mt", "", 
> >> "verwaltung");
> >> auto rows = mysql.query("select field from my_table limit 50");
> >>
> >> foreach(row;rows){
> >>  writeln(row["field"]);}
> >>
> >> // second time same loop
> >>
> >> foreach(row;rows){
> >>  writeln(row["field"]);}
> >>  
> [...]
> >> A nested loop, did not worked either:
> >>
> >> foreach(row;rows){
> >>  foreach(field;row){
> >>  writeln(field);}
> >> }
> >>
> >> Which other ways to access the elements of rows do I have?
> >>  
> [...]
> > what if you make array from it:
> > import std.array: array;
> > auto rows = mysql.query("select field from my_table limit 
> > 50").array;  
> Thank you both for your answers!
> This worked, for the first part of my question.
> Now I took a work around, getting the field names in a separate 
> mysql-request,
> but they should be available in the row object, too?
> 

rows.fieldNames() this one is better result type is string[]



Re: Real Time-ing

2015-12-08 Thread Kagamin via Digitalmars-d-learn

prev=now;
call();
wait(prev+dur-now);
call();


Re: Real Time-ing

2015-12-08 Thread Taylor Hillegeist via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 15:50:35 UTC, Kagamin wrote:

Oops, no.

next+=dur;
wait(next-now);
call();


what calls does this use from the std library? to get the current 
time? Wait a amount of time?


Re: Question about mysql-d Object

2015-12-08 Thread Martin Tschierschke via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 15:14:06 UTC, Daniel Kozak wrote:
[...]

>> A nested loop, did not worked either:
>>
>> foreach(row;rows){
>>  foreach(field;row){
>>  writeln(field);}
>> }

[...]

Now I took a work around, getting the field names in a separate
mysql-request,
but they should be available in the row object, too?



rows.fieldNames() this one is better result type is string[]

Thank you!!!



Real Time-ing

2015-12-08 Thread Taylor Hillegeist via Digitalmars-d-learn
So, I mostly do programming that is of run to completion verity. 
But I have a dream of calling functions periodically. So my 
question is:


What is the best (most time accurate) way to call a function 
every n time units?

What is the best way to measure the jitter of these calls?


I'm also interested in waiting vs calling periodically eg.

call
wait(1 ms)
call

is not the same as 1 ms from call to call, due to the time 
duration of the function call.


Thanks!


Re: Real Time-ing

2015-12-08 Thread Kagamin via Digitalmars-d-learn

Oops, no.

next+=dur;
wait(next-now);
call();


Re: Real Time-ing

2015-12-08 Thread Taylor Hillegeist via Digitalmars-d-learn
On Tuesday, 8 December 2015 at 15:35:18 UTC, Taylor Hillegeist 
wrote:

So, I mostly do programming that is of run to completion


I took a stab at the problem:

http://dpaste.dzfl.pl/2eef530d00fc


0 nsecs with jitter of :5 nsecs
498937256 nsecs with jitter of :1062744 nsecs
499036173 nsecs with jitter of :963827 nsecs
500025650 nsecs with jitter of :25650 nsecs
500020735 nsecs with jitter of :20735 nsecs
499057062 nsecs with jitter of :942938 nsecs
498932033 nsecs with jitter of :1067967 nsecs
591037317 nsecs with jitter of :91037317 nsecs
499032794 nsecs with jitter of :967206 nsecs
499034637 nsecs with jitter of :965363 nsecs
499022963 nsecs with jitter of :977037 nsecs
498976577 nsecs with jitter of :1023423 nsecs
499076723 nsecs with jitter of :923277 nsecs
499023885 nsecs with jitter of :976115 nsecs
499018048 nsecs with jitter of :981952 nsecs
499004224 nsecs with jitter of :995776 nsecs
499048461 nsecs with jitter of :951539 nsecs
499013747 nsecs with jitter of :986253 nsecs
499018048 nsecs with jitter of :981952 nsecs
499007604 nsecs with jitter of :992396 nsecs

However i seem to get jitter of around 1 ms. Is there anything 
else i can do to improve?


Re: Real Time-ing

2015-12-08 Thread Chris Wright via Digitalmars-d-learn
On Tue, 08 Dec 2015 15:35:18 +, Taylor Hillegeist wrote:

> So, I mostly do programming that is of run to completion verity.
> But I have a dream of calling functions periodically. So my question is:
> 
> What is the best (most time accurate) way to call a function every n
> time units?

Busy-wait and access the CPU's high precision clock.

If you have an extended wait and don't want to busy-wait the whole time, 
sleep up to, say, 5ms before the time you want to call the function, then 
busy-wait.


Re: Regression?

2015-12-08 Thread Jack Stouffer via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 01:35:26 UTC, Sebastiaan Koppe 
wrote:


Thanks for your advice. But that is not what I asked for.

The question was, why doesn't this work anymore with the latest 
(2.068.0 and 2.068.1) compiler:


```
auto ls = 
File("../languages.json","r").byLineCopy().joiner.parseJSON();

```

It should. Right?


I just ran into this as well. This seems like a regression.


Re: The @@@BUG@@@ the size of China - std.conv.d - Target parse(Target, Source)(ref Source s, uint radix)

2015-12-08 Thread John Carter via Digitalmars-d-learn

On Tuesday, 8 December 2015 at 00:40:29 UTC, tsbockman wrote:


Someone still needs to review the PR, though.


Thanks! Looks like it's been merged already.

It was a double problem... I failed to read the bit about 
advancing the ref and then the old big @@@BUG@@@ comment in the 
unit test made me think it was a bug.


Thanks! Great response, I appreciate it!



Re: Regression?

2015-12-08 Thread Jack Stouffer via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 01:35:26 UTC, Sebastiaan Koppe 
wrote:


Thanks for your advice. But that is not what I asked for.

The question was, why doesn't this work anymore with the latest 
(2.068.0 and 2.068.1) compiler:


```
auto ls = 
File("../languages.json","r").byLineCopy().joiner.parseJSON();

```

It should. Right?


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


Using gdb by some process to let this process monitor its state by itself

2015-12-08 Thread drug via Digitalmars-d-learn
Is it possible to invoke gdb by some process that using data from gdb 
this process can inspect itself?
For example I'd like to generate breakpoints for gdb with conditions and 
if this conditions meet get for example pointer to some data structure 
from gdb and process it by means of D, not gdb, then continue running 
under control of gdb until another breakpoint condition meets and so on? 
My purpose is to join abilities of gdb and D together.


Re: Real Time-ing

2015-12-08 Thread BBaz via Digitalmars-d-learn
On Tuesday, 8 December 2015 at 16:40:04 UTC, Taylor Hillegeist 
wrote:
On Tuesday, 8 December 2015 at 15:35:18 UTC, Taylor Hillegeist 
wrote:

So, I mostly do programming that is of run to completion


I took a stab at the problem:

http://dpaste.dzfl.pl/2eef530d00fc


0 nsecs with jitter of :5 nsecs
498937256 nsecs with jitter of :1062744 nsecs
499036173 nsecs with jitter of :963827 nsecs
500025650 nsecs with jitter of :25650 nsecs
500020735 nsecs with jitter of :20735 nsecs
499057062 nsecs with jitter of :942938 nsecs
498932033 nsecs with jitter of :1067967 nsecs
591037317 nsecs with jitter of :91037317 nsecs
499032794 nsecs with jitter of :967206 nsecs
499034637 nsecs with jitter of :965363 nsecs
499022963 nsecs with jitter of :977037 nsecs
498976577 nsecs with jitter of :1023423 nsecs
499076723 nsecs with jitter of :923277 nsecs
499023885 nsecs with jitter of :976115 nsecs
499018048 nsecs with jitter of :981952 nsecs
499004224 nsecs with jitter of :995776 nsecs
499048461 nsecs with jitter of :951539 nsecs
499013747 nsecs with jitter of :986253 nsecs
499018048 nsecs with jitter of :981952 nsecs
499007604 nsecs with jitter of :992396 nsecs

However i seem to get jitter of around 1 ms. Is there anything 
else i can do to improve?


1) a computer is not real-time, for example audio is always 
buffered (e.g 512 samples)


2) thread are not good for timing. In a simple test you could get 
satisfying results while in a stressed IRL environment it won't 
work as well. so you should rather use the OS API to make a timer 
(or the one proposed by a framework if it applies, for example 
gui app with SDL: SDL timer).


However if you want to have better times you can use core.time in 
a thread callback:


~
// to, t1 and interval are uint;
if (!t0) t0 = TickDuration.currSystemTick.msecs;
t1 = TickDuration.currSystemTick.msecs;

if ((t1 - t0) > interval)
{
t0 = 0;
onTimer();
}
~