[Monetdb-developers] M4 Automatic multiplex version of .tostr: weird behavior

Sjoerd Mullender sjoerd at acm.org
Sun Feb 1 13:55:15 CET 2009

There are several issues.

- Use lng instead of long long for the typedef.  The Visual Studio 
compiler doesn't know long long.
- You're using a lot of goto's...
- The nil value for dtduration should be lng_nil, not int_nil.

But the real reason that it fails is that for some reason 
dtduration_tostr is called twice with the same argument, and the 
*second* time it is called, the value of *val == 0.  That is because the 
*first* time it was called, you set it to 0 in the process of figuring 
out what string to produce.
So the solution is probably to make a copy of *val into a local variable 
and change that instead of *val.

On 2009-02-01 13:03, Lefteris wrote:
> The following behavior is strange to me, but I am not sure if it is a
> bug or I have done something wrong.
> dayTimeDuration (dtduration) is defined in mil as:
> .ATOM dtduration = lng;
>      .FROMSTR = dtduration_fromstr;
>      .TOSTR = dtduration_tostr;
> .END;
> and in c as :
> typedef long long dtduration;
> also .tostr has the following sign.
> int dtduration_tostr(str *buf, int *len, dtduration *val)
> you can find all this in MonetDB4/src/modules/plain/monettime.mx
> Now, if I do either:
> dtduration("P12DT1H").print()
> [dtduration]("P12DT1H").print()
> I get the correct value printed. But if I create a BAT (void,str):
> var a0006 := new (void,str).seqbase (0 at 0);
> a0006.append("P12DT1H");
> and do:
> [dtduration](a0006).print();
> It gives back "PT0S", which means 0 duration, and thus the value of
> *val in dtduration_tostr is 0 (I checked that).
> So, could that be some bug with correct dealing of long values in the
> multiplex creation (btw. where is that happening?) Or am I missing
> some special case that I should take into consideration with long
> values?
> Thank you,
> lefteris
> P.S. yearMonthDuration which is defined as int works like a charm.
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Monetdb-developers mailing list
> Monetdb-developers at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/monetdb-developers

Sjoerd Mullender

More information about the developers-list mailing list