stack trace output on exception

2014-07-08 Thread Stephan Schiffels via Digitalmars-d-learn

Hi,

I am using dmd with version: DMD64 D Compiler v2.065-devel-db2a73d

My program throws a custom exception with a custom error message 
at some point. The stack trace (below) is very uninformative. Is 
there a way to output the function names of each position in the 
stack?


I already compile using -g and I also tried -gc and -gs and all 
three of them together. I also tried -debug. The stack trace 
looks always like this:


popGenFunc.IllegalParametersException@popGenFunc.d(556): gamma 
out of range


/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x42752b]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x423ee7]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x404bab]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x402d7e]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x4028d6]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433cc4]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433c1e]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433c84]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433c1e]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433b9f]
/nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x421121]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) 
[0x7ffe8440e76d]


Thanks for your help,
Stephan



Re: stack trace output on exception

2014-07-08 Thread Stephan Schiffels via Digitalmars-d-learn
Ah nice. That worked. Thanks!



2014-07-08 9:25 GMT+02:00 JR via Digitalmars-d-learn 
digitalmars-d-learn@puremagic.com:

 On Tuesday, 8 July 2014 at 07:11:26 UTC, Stephan Schiffels wrote:

 Hi,

 I am using dmd with version: DMD64 D Compiler v2.065-devel-db2a73d

 My program throws a custom exception with a custom error message at some
 point. The stack trace (below) is very uninformative. Is there a way to
 output the function names of each position in the stack?

 I already compile using -g and I also tried -gc and -gs and all three of
 them together. I also tried -debug. The stack trace looks always like this:

 popGenFunc.IllegalParametersException@popGenFunc.d(556): gamma out of
 range
 
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x42752b]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x423ee7]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x404bab]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x402d7e]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x4028d6]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433cc4]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433c1e]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433c84]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433c1e]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x433b9f]
 /nfs/users/nfs_s/ss27/Projects/hfit/build/hfit() [0x421121]
 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7ffe8440e76d]

 Thanks for your help,
 Stephan


 Tried building with -L--export-dynamic?



Re: std.range.chunk without length

2014-02-18 Thread Stephan Schiffels
On Thursday, 13 February 2014 at 17:41:37 UTC, monarch_dodra 
wrote:

On Thursday, 13 February 2014 at 14:45:44 UTC, bearophile wrote:

Stephan Schiffels:

It would be actually easy to implement chunks without the 
save function, by using an internal buffer, which would 
however make this algorithm's memory burden linear in the 
chunk size. Would that be acceptable?


I think it's acceptable. But perhaps you need to add one more 
optional argument for the buffer :-)


Bye,
bearophile


Users andralex:
https://github.com/D-Programming-Language/phobos/pull/1186

And quickfur:
https://github.com/D-Programming-Language/phobos/pull/1453

Have submitted different algorithms for a similar problem: 
Basically, bu being 2-dimensional lazy (each subrange is 
itself a lazy range). However, both come with their own 
pitfalls.


Andrei's still requires forward ranges. quickfur's doesn't, 
and, arguably, has a simpler design. However, if I remember 
correctly, it is also less efficient (it does double work). 
Implementing Quickfur's solution in Chunks for input ranges 
only could be a good idea.


It *is* extra work, more code, more code to cover (that is 
difficult to cover). I'm not sure we have the man power to 
support such complexity: I was able to make chunks work with 
forward ranges, but I still haven't even fixed Splitter yet! I 
think that should take precedence.


Yeah, nevermind, I won't do it. I realised that you had good 
reasons to require a ForwardRange. Chunking really needs some 
sort of save implemented. And what I had in mind to make it 
work on File.byLine with a buffer is actually a hack that 
effectively adds save functionality to the InputRange… so I 
agree it's logically not reasonable to do it here.


Thanks anyway.
Stephan


Re: std.range.chunk without length

2014-02-13 Thread Stephan Schiffels
On Thursday, 31 October 2013 at 10:35:54 UTC, Stephan Schiffels 
wrote:

On Wednesday, 30 October 2013 at 20:43:54 UTC, qznc wrote:
On Wednesday, 30 October 2013 at 00:20:12 UTC, Stephan 
Schiffels wrote:

Hi,

I'd like a version of std.range.chunk that does not require 
the range to have the length property.


As an example, consider a file that you would like parse by 
lines and always lump together four lines, i.e.


import std.stdio;
void main() {
auto range = File(test.txt, r).byLine();
foreach(c; range.chunks(4)) { //doesn't compile
  writefln(%s %s, c[0], c[1]);
}
}


Your wish was granted. Monarchdodra was sent back in time [0], 
so it is already fixed in HEAD. You could try the dmd beta [1].



[0] https://github.com/D-Programming-Language/phobos/pull/992
[1] 
http://forum.dlang.org/thread/526dd8c5.2040...@digitalmars.com


Ah, awesome! Should have updated my github clone then.
Thanks,
Stephan


Sorry for the late follow up, but it turns out that 
std.range.chunks needs a ForwardRange, and hence does not work on 
File.byLine(). The referenced pull request claims that it does in 
the comments, but of course the current implementation needs a 
save() function which doesn't exist for the byLine range.


It would be actually easy to implement chunks without the save 
function, by using an internal buffer, which would however make 
this algorithm's memory burden linear in the chunk size. Would 
that be acceptable? If so, I'd be happy to make that change and 
push it.


Stephan


Re: std.range.chunk without length

2013-10-31 Thread Stephan Schiffels

On Wednesday, 30 October 2013 at 20:43:54 UTC, qznc wrote:
On Wednesday, 30 October 2013 at 00:20:12 UTC, Stephan 
Schiffels wrote:

Hi,

I'd like a version of std.range.chunk that does not require 
the range to have the length property.


As an example, consider a file that you would like parse by 
lines and always lump together four lines, i.e.


import std.stdio;
void main() {
 auto range = File(test.txt, r).byLine();
 foreach(c; range.chunks(4)) { //doesn't compile
   writefln(%s %s, c[0], c[1]);
 }
}


Your wish was granted. Monarchdodra was sent back in time [0], 
so it is already fixed in HEAD. You could try the dmd beta [1].



[0] https://github.com/D-Programming-Language/phobos/pull/992
[1] 
http://forum.dlang.org/thread/526dd8c5.2040...@digitalmars.com


Ah, awesome! Should have updated my github clone then.
Thanks,
Stephan



std.range.chunk without length

2013-10-29 Thread Stephan Schiffels

Hi,

I'd like a version of std.range.chunk that does not require the 
range to have the length property.


As an example, consider a file that you would like parse by lines 
and always lump together four lines, i.e.


import std.stdio;
void main() {
  auto range = File(test.txt, r).byLine();
  foreach(c; range.chunks(4)) { //doesn't compile
writefln(%s %s, c[0], c[1]);
  }
}

Thanks,
Stephan


this() immutable

2013-06-13 Thread Stephan Schiffels

Hi,

I have some problems with adopting my code to a breaking change 
introduced in version 2.063. Apparently, now it's not anymore 
possible to instantiate an immutable object via:


auto object = new immutable(SomeClass)(contructor_args...);

without also defining either

this(constructor_args...) immutable {...}

or

this(constructor_args...) pure {...}


As much as I think that this change will make the system more 
consistent, I don't know how to fix my code. Often, in a 
constructor you pass other objects (via constructor dependency 
injection), and it seems that I have to fix a hell of a lot of 
dependency code that way. Is there a simple way of emulating the 
way it just magically worked in version 2.062?


For example, is there a way of instantiating an object normally 
(i.e. mutable), and then later freeze it to immutable via a 
simple cast or so?


Thanks,

Stephan


Re: this() immutable

2013-06-13 Thread Stephan Schiffels

On Thursday, 13 June 2013 at 12:29:57 UTC, Simen Kjaeraas wrote:
On Thu, 13 Jun 2013 14:17:22 +0200, Stephan Schiffels 
stephan_schiff...@mac.com wrote:


For example, is there a way of instantiating an object 
normally (i.e. mutable), and then later freeze it to 
immutable via a simple cast or so?


In std.exception there is assumeUnique. It's basically just a 
cast, but

might be good enough for you.


I see, will look at that. I actually need it immutable since I am 
using it across multiple threads.




open a range of files - segfault

2013-05-22 Thread Stephan Schiffels

Hi,

this code crashes with a segfault. I need help to understand what 
might be wrong with it.


import std.array;
import std.algorithm;

void main() {
  auto names = [file1.txt, file2.txt, file3.txt];  // let 
these files exist

  auto files = names.map!(f = File(f, r))().array();
}

Thanks,

Stephan


Re: open a range of files - segfault

2013-05-22 Thread Stephan Schiffels

On Wednesday, 22 May 2013 at 11:09:49 UTC, John Colvin wrote:

On Wednesday, 22 May 2013 at 11:07:39 UTC, bearophile wrote:

Stephan Schiffels:

this code crashes with a segfault. I need help to understand 
what might be wrong with it.


import std.array;
import std.algorithm;

void main() {
auto names = [file1.txt, file2.txt, file3.txt];  // let 
these files exist

auto files = names.map!(f = File(f, r))().array();
}


If I use the latest 2.063beta5 compiler, and I also import 
std.stdio, then I see no crash on Windows32.


Bye,
bearophile


With git master on linux x64 I get a segfault, see my other
comment.


OK, thanks for confirming. I updated to the latest git master and 
still get a segfault. I'll file a bug report.


Stephan



joiner and map, strange behavior

2013-03-12 Thread Stephan Schiffels

Hi,

I am struggling with understanding this behavior. In the code 
below, the function getVec is called 8 times, but it should be 
called only 4 times (once for each call inside of map).


Any explanations?

Stephan


import std.stdio;
import std.algorithm;
import std.array;

int[] getVec(size_t i) {
  writeln(getVec is called);
  auto vals = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
  ];
  return vals[i];
}


void main() {

  auto result = [0, 1, 2, 3].map!(getVec).joiner.array;
  writeln(result);

}


Re: joiner and map, strange behavior

2013-03-12 Thread Stephan Schiffels

On Tuesday, 12 March 2013 at 17:43:43 UTC, bearophile wrote:

Stephan Schiffels:

I am struggling with understanding this behavior. In the code 
below, the function getVec is called 8 times, but it should 
be called only 4 times (once for each call inside of map).


Any explanations?


Maybe it's a matter of calling front() more times, as in filter 
in a recent thread. To be sure take a look inside phobos 
sources.


By the way, your code is quite inefficient, because it 
allocates a new matrix at each call to getVec.


Bye,
bearophile


Thanks, I had a brief look at std.algorithm.joiner but couldn't 
find anything obvious, maybe I should look deeper into it.


And yes, the example is quite bad. This version of getVec would 
have been better to illustrate:


import std.range;
auto getVec(size_t i) {
  writeln(getVec is called);
  return iota(i * 4, (i + 1) * 4);
}

Stephan


Re: joiner and map, strange behavior

2013-03-12 Thread Stephan Schiffels

Am 12.03.13 20:22, schrieb Timon Gehr:

On 03/12/2013 06:51 PM, Stephan Schiffels wrote:

...

Thanks, I had a brief look at std.algorithm.joiner but couldn't find
anything obvious, maybe I should look deeper into it.
...


I guess it is because of the following:

Eg (similar code occurs two times):
...
 if (_sep.empty)
 {
 // Advance to the next range in the
 // input
 //_items.popFront();
 for (;; _items.popFront())
 {
 if (_items.empty) return;
 if (!_items.front.empty) break; // front called
 }
 _current = _items.front; // front called again
 _items.popFront();
 }
...

The code should only call front once for the first non-empty range.

Presumed example fix (though the implementation seems rather clumsy and
should probably be replaced completely):

...
 if (_sep.empty)
 {
 // Advance to the next range in the
 // input
 //_items.popFront();
 for (;; _items.popFront())
 {
 if (_items.empty) return;
 _current = _items.front;
 if (!_current.empty) break;
 }
 _items.popFront();
 }
...


Thanks, that's very clear now. I stumbled over it because the function I 
call loads a lot of data and a factor 2 makes all the difference in 
runtime. Maybe I should file a bug report or at least a request to 
improve this.


Stephan


Re: Best way to handle settings files (ini file syntax or similar)

2013-02-28 Thread Stephan Schiffels

Am 27.02.13 21:36, schrieb Dicebot:
For anything even remotely complex I would have probably chosen JSON, 
either new std.json pending for review (not current std.json!) or 
vibe.data.json from vibed.org project.


Which std.json are you referring to? There is no std.json2 or something 
in the review queue.


void[] and ubyte[]

2013-02-04 Thread Stephan

Hi,

In phobos there are places with void[] and places with ubyte[], 
and I can't really understand why there is this difference. I 
don't even see why D has a void array or void pointer anyway.
For example, in std.base64, ubyte[] is used as the basic quantity 
for encoding, while in std.zlib, it's void[]. Both libraries have 
a similar pair of functions like encode/decode or 
compress/uncompress. Both act on raw memory. So why not use 
ubyte[] all the time? Isn't any stretch of bare data on the heap 
in the end an array of bytes? Void[] seems like a C-anachronism 
to me. I have no experience with void pointers or arrays, so I am 
probably missing something.


Thanks,

Stephan


anonymous static array

2012-03-21 Thread Stephan

Hi,

I have an associative array with strings as keys and static 
arrays as values. When I access a new key, it gives me Range 
Error, so I think I should initialise the associative array, but 
how?


here is the code that fails:

int[100][string] counts;
counts[some_key][20]++;
// core.exception.RangeError@freqSpec(26): Range violation


Thanks,

Stephan




Re: anonymous static array

2012-03-21 Thread Stephan
Thanks everyone. OK, so a temporary variable seems to be the most 
obvious workaround, thanks Jesse. Thanks also to the others in 
pointing out this issue.


All the best,

Stephan


On Wednesday, 21 March 2012 at 14:19:03 UTC, Jesse Phillips wrote:

On Wednesday, 21 March 2012 at 10:51:05 UTC, Stephan wrote:

Hi,

I have an associative array with strings as keys and static 
arrays as values. When I access a new key, it gives me Range 
Error, so I think I should initialise the associative array, 
but how?


here is the code that fails:

int[100][string] counts;
counts[some_key][20]++;
// core.exception.RangeError@freqSpec(26): Range violation


Thanks,

Stephan


int[100][string] counts;
int[100] a;
counts[some_key] = a;
counts[some_key][20]++;





Re: Nightly builds

2012-01-03 Thread Stephan

On 02.01.2012 14:15, simendsjo wrote:

Is it possible for the autotester to allow downloading the latest build
that passed testing?


better post this in D newsgroup instead of D.learn


typedef deprecated - now what ?

2011-12-30 Thread Stephan
is there a template or something in phobos to get the same typesafe 
behaviour of good old typedef ?


S.


Re: typedef deprecated - now what ?

2011-12-30 Thread Stephan

On 30.12.2011 12:09, Trass3r wrote:

is there a template or something in phobos to get the same typesafe
behaviour of good old typedef ?


I've brought this up several times.
People just don't give a shit.

http://d.puremagic.com/issues/show_bug.cgi?id=5467


thats too bad. pull request looks good. i voted for the ticket, but i 
guess that no one gives shit about that either :(


Re: optlink options to reduce file size?

2011-07-27 Thread Stephan

On 27.07.2011 13:26, simendsjo wrote:

On 27.07.2011 13:21, simendsjo wrote:

A simple hello world like dfl application takes 1.2mb. Upx does a great
job packing this to 200k, but I wonder if there is a way to make optlink
generate smaller executables?

I couldn't find a way to get help on the numerous options in optlink,
and the help page at digitalmars doesn't list them either.


Nevermind. I found the switches here:
http://www.digitalmars.com/ctg/ctgLinkSwitches.html


So what switched did you use to make it link smaller ?


Re: template instance cannot use local 'f' as parameter to non-global template

2011-07-13 Thread Stephan

On 12.07.2011 15:06, Trass3r wrote:

Is this a bug? If not, how do you make it work?

void h() {}

class Bla
{
mixin wrap!h;
}

mixin template wrap(alias f)
{
void blub(alias g = f)()
{
}
}

void main()
{
Bla b = new Bla();
b.blub();
}

test.d(18): Error: template instance cannot use local 'f' as parameter
to non-global template blub(alias g = f)
test.d(18): Error: template instance forward reference of f
test.d(18): Error: template instance test.Bla.wrap!(h).blub!(f) error
instantiating


I am not sure but i am not that used to those template aliases anyway.


Re: How to web programming with D2?

2011-02-10 Thread Stephan Soller

On 10.02.2011 10:29, canalpay wrote:

I am trying to write the web framework(but not to write, to gain experience.). 
Maybe the framework can has got a MVC  desing pattern. But first, the D2 is not 
has got for the web library and I am decided write to library for web.

I am writed a function for post and get methods. (I am not tried to functions. 
But I think, they are works.)
POST: https://github.com/canalpay/turna/blob/master/library/post.d
GET  :  https://github.com/canalpay/turna/blob/master/library/get.d

Environment variables are easy to write for the function.
But How to write a cookie and session?
I looked at the codes of tango. However, don't understand.(I'm new to d 
programming language.)


From your code I assume you're using CGI. To set a cookie you have to 
set the Set-Cookie header with a string a specific format (see 
Cookies on Wikipedia link). In CGI the standard output of the program 
is used as HTTP response and therefore you can set headers by printing 
them first to stdout. After you're done writing headers (one per line 
usually) output an empty line. This marks the rest of the output as 
actual content of the response. So basically your program should output 
something like this:


Content-Type: text/html
Set-Cookie: name=value

html
…
/html

Depending on how you like to develop the RFCs for CGI and HTTP might 
come in handy. I sometimes also use Wikipedia to get an overview of the 
topic.


- Cookies on Wikipedia: http://en.wikipedia.org/wiki/HTTP_cookie
- HTTP on Wikipedia: http://en.wikipedia.org/wiki/Http
- CGI on Wikipedia: http://en.wikipedia.org/wiki/Common_Gateway_Interface
- CGI RFC: http://tools.ietf.org/html/rfc3875
- HTTP RFC: http://tools.ietf.org/html/rfc2616


Happy programming
Stephan Soller


to! fails with fixed length char array for dmd 2.051

2011-01-06 Thread stephan

The following code worked fine with dmd 2.050, but fails to compile for dmd
2.051. Any reason for this (other than a bug)?

import std.conv;

void main() {
char[4] t = test;
auto s = to!(dstring)(t);
}

Error message seems to indicate that two templates match, one checking for
isStaticArray, and one checking for isSomeString:

C:\D2\dmd2\windows\bin\..\..\src\phobos\std\conv.d(99): Error: template
std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T)  isSomeString!(T) 
isInputRange!(Unqual!(S))  isSomeChar!(ElementType!(S))) toImpl(T,S) if
(!implicitlyConverts!(S,T)  isSomeString!(T)  isInputRange!(Unqual!(S))
 isSomeChar!(ElementType!(S))) matches more than one template declaration,
C:\D2\dmd2\windows\bin\..\..\src\phobos\std\conv.d(114):toImpl(T,S) if
(!implicitlyConverts!(S,T)  isSomeString!(T)  isInputRange!(Unqual!(S))
 isSomeChar!(ElementType!(S))) and
C:\D2\dmd2\windows\bin\..\..\src\phobos\std\conv.d(224):toImpl(T,S) if
(isStaticArray!(S))