www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.algorithm Map using a external variable

reply "Zardoz" <luis.panadero gmail.com> writes:
I'm trying to use Map with a code like this :

...
   immutable int m = 10;
   int[] caca = [1,2,3,4];

   auto caca2 = map!( (a) {return a * m;})(caca);

   writeln(caca2);
...

I get a Segmentation fault some times:
The most interesting point it's that depends of the code around 
of it ins the same  program. for example If a use getopt at the 
begin of my program, then seg fault, etc...
  Looks that there some weird error in gdc 4.6.3

PD: Later I will put the whole code so any can see if I doing 
some weird thing that make map crazy
Dec 10 2012
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2012-12-10 19:21, Zardoz wrote:
 I'm trying to use Map with a code like this :

 ...
    immutable int m = 10;
    int[] caca = [1,2,3,4];

    auto caca2 = map!( (a) {return a * m;})(caca);

    writeln(caca2);
 ...

 I get a Segmentation fault some times:
 The most interesting point it's that depends of the code around of it
 ins the same  program. for example If a use getopt at the begin of my
 program, then seg fault, etc...
   Looks that there some weird error in gdc 4.6.3

 PD: Later I will put the whole code so any can see if I doing some weird
 thing that make map crazy

std.getopt uses module variables, don't know if that has anything to do with it. -- /Jacob Carlborg
Dec 10 2012
prev sibling next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Dec 10, 2012 at 07:21:47PM +0100, Zardoz wrote:
 I'm trying to use Map with a code like this :
 
 ...
   immutable int m = 10;
   int[] caca = [1,2,3,4];
 
   auto caca2 = map!( (a) {return a * m;})(caca);
 
   writeln(caca2);
 ...
 
 I get a Segmentation fault some times:
 The most interesting point it's that depends of the code around of
 it ins the same  program. for example If a use getopt at the begin
 of my program, then seg fault, etc...

Do you have a compilable sample (possibly reduced from your full sources) that exhibits this error? It would help track down the problem. There are some known bugs related to map in older releases of D that may be affecting you. T -- Give me some fresh salted fish, please.
Dec 10 2012
prev sibling next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Monday, 10 December 2012 at 18:21:48 UTC, Zardoz wrote:
 I'm trying to use Map with a code like this :

 ...
   immutable int m = 10;
   int[] caca = [1,2,3,4];

   auto caca2 = map!( (a) {return a * m;})(caca);

   writeln(caca2);
 ...

 I get a Segmentation fault some times:
 The most interesting point it's that depends of the code around 
 of it ins the same  program. for example If a use getopt at the 
 begin of my program, then seg fault, etc...
  Looks that there some weird error in gdc 4.6.3

 PD: Later I will put the whole code so any can see if I doing 
 some weird thing that make map crazy

Looks like template lambda bug (http://d.puremagic.com/issues/show_bug.cgi?id=8899). It might depend not only on surrounding code, but on importing some phobos module (issue 8854).
Dec 10 2012
prev sibling parent "Zardoz" <luis.panadero gmail.com> writes:
Well. I just try it again and I noticed this things :
-Changind the lambda function from :
   auto caca2 = map!((a) {return a * iDeltaT;})(caca);
  to :
   auto caca2 = map!((a) {return a + iDeltaT;})(caca);
  Avoid the segmentation fault
-Using dmd 2.60 avoid the segmentation fault.

The source code is in 
http://dl.dropbox.com/u/2716434/CodeThatCrash.tgz
The makefile only builds againts gdc, so to test it with dmd, I 
manually compiled the faulty code of serie2Sim.d with :
   dmd serie2Sim.d entity.d vector.d -ofserie2Sim
And I launch it with ./serie2Sim --rand 10 --seed 123
With dmd works, but with gdc not.


On Monday, 10 December 2012 at 18:59:31 UTC, H. S. Teoh wrote:
 On Mon, Dec 10, 2012 at 07:21:47PM +0100, Zardoz wrote:
 I'm trying to use Map with a code like this :
 
 ...
   immutable int m = 10;
   int[] caca = [1,2,3,4];
 
   auto caca2 = map!( (a) {return a * m;})(caca);
 
   writeln(caca2);
 ...
 
 I get a Segmentation fault some times:
 The most interesting point it's that depends of the code 
 around of
 it ins the same  program. for example If a use getopt at the 
 begin
 of my program, then seg fault, etc...

Do you have a compilable sample (possibly reduced from your full sources) that exhibits this error? It would help track down the problem. There are some known bugs related to map in older releases of D that may be affecting you. T

Dec 10 2012