[Monetdb-developers] M4 Automatic multiplex version of .tostr: weird behavior
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@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.
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@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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-developers
-- Sjoerd Mullender
I will use lng instead of long long:)
goto's are needed in the fromstr to make a faster and easier to read parser.
The nil value should be indeed lng_nil, i had changed that but did not
checked it in.
After debugging more, I saw that tostr is called twice and yes, I have
changed it to 0 in the process.. I didn't knew that tostr is called
twice for the same value, but now I know. I was surprised by that, but
now from your email I understand that you already know that and
apparently this is the correct behavior:)
I fixed it by indeed copying val to some temp variable.
Thank you very much.
lefteris
On Sun, Feb 1, 2009 at 1:55 PM, Sjoerd Mullender
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@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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-developers
-- Sjoerd Mullender
On Sun, Feb 01, 2009 at 02:15:06PM +0100, Lefteris wrote:
I will use lng instead of long long:)
goto's are needed in the fromstr to make a faster and easier to read parser.
The nil value should be indeed lng_nil, i had changed that but did not checked it in.
After debugging more, I saw that tostr is called twice and yes, I have changed it to 0 in the process.. I didn't knew that tostr is called twice for the same value, but now I know. I was surprised by that, but now from your email I understand that you already know that and apparently this is the correct behavior:)
If I recall correcly, printing of a BAT first samples some values and converts the to str (*_tostr()) to estimate the column width for ome "nice" rendering, and then calls *_tostr() for all values to do the actual printing --- in you case with only one tuple in the BAT, this one is obviously randomly chosen by sampling ... ;-) ... it is usually indeed no good idea to use no non-local memory location as/like a local varible in a function --- unless the side effects are required and intended ... ;-) Stefan
I fixed it by indeed copying val to some temp variable.
Thank you very much.
lefteris
On Sun, Feb 1, 2009 at 1:55 PM, Sjoerd Mullender
wrote: 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@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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-developers
-- Sjoerd Mullender
------------------------------------------------------------------------------ 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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-developers
-- | Dr. Stefan Manegold | mailto:Stefan.Manegold@cwi.nl | | CWI, P.O.Box 94079 | http://www.cwi.nl/~manegold/ | | 1090 GB Amsterdam | Tel.: +31 (20) 592-4212 | | The Netherlands | Fax : +31 (20) 592-4312 |
On Sun, Feb 01, 2009 at 01:03:43PM +0100, 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; ^^^^^^^^^ why not "lng" as above?
(well, yes, "lng" is defined as "long long", so it should not make a difference other than looking more consistent, and hence, being easier to maintain ...) also #define dtduration_nil ((dtduration) int_nil) ^^^ should probabaly read #define dtduration_nil ((dtduration) lng_nil) ^^^ right?
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@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).
a) your example are casting from str to dtduration --- so what has dtduration_*to*str() to do with this? Typo? IMHO, casting from str to dtduration should be handled by dtduration_*from*str(), right? ... of course, printing then IMHO uses dtduration_*to*str() to turn the dtduration into a (printable) string, again... b) hence, you'd need to check all input and output parameters of both dtduration_tostr and dtduration_fromstr to check whether things might go wrong ... ... if *val in dtduration_tostr (usd by print) is 0, then the (multiplxed) cast from a [void,str] BAT to a [void,dtduration] BAT using dtduration_fromstr might already have introduced the problem ...
So, could that be some bug with correct dealing of long values in the multiplex creation (btw. where is that happening?)
MonetDB4/src/monet/monet_multiplex.mx
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.
check, whether there are more place where the int->lng translation did not go well like with dtduration_nil above ... Stefan
------------------------------------------------------------------------------ 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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-developers
-- | Dr. Stefan Manegold | mailto:Stefan.Manegold@cwi.nl | | CWI, P.O.Box 94079 | http://www.cwi.nl/~manegold/ | | 1090 GB Amsterdam | Tel.: +31 (20) 592-4212 | | The Netherlands | Fax : +31 (20) 592-4312 |
On Sun, Feb 1, 2009 at 2:00 PM, Stefan Manegold
On Sun, Feb 01, 2009 at 01:03:43PM +0100, 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; ^^^^^^^^^ why not "lng" as above?
fixed
(well, yes, "lng" is defined as "long long", so it should not make a difference other than looking more consistent, and hence, being easier to maintain ...)
also #define dtduration_nil ((dtduration) int_nil) ^^^ should probabaly read #define dtduration_nil ((dtduration) lng_nil) ^^^ right?
right, fixed
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@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).
a) your example are casting from str to dtduration --- so what has dtduration_*to*str() to do with this? Typo? IMHO, casting from str to dtduration should be handled by dtduration_*from*str(), right?
yes but the .print() is casting back to string:P so it goes str->dtduration->str The process was going wrong not from string to dtduration, but when it was printed back, the dtduration had the correct long value.
... of course, printing then IMHO uses dtduration_*to*str() to turn the dtduration into a (printable) string, again...
b) hence, you'd need to check all input and output parameters of both dtduration_tostr and dtduration_fromstr to check whether things might go wrong ... ... if *val in dtduration_tostr (usd by print) is 0, then the (multiplxed) cast from a [void,str] BAT to a [void,dtduration] BAT using dtduration_fromstr might already have introduced the problem ...
the fromstr was ok, it was just the tostr that I was changing the val to 0 and the multiplex called again the tostr with 0. Thank for your fast replies:) lefteris
So, could that be some bug with correct dealing of long values in the multiplex creation (btw. where is that happening?)
MonetDB4/src/monet/monet_multiplex.mx
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.
check, whether there are more place where the int->lng translation did not go well like with dtduration_nil above ...
Stefan
------------------------------------------------------------------------------ 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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-developers
-- | Dr. Stefan Manegold | mailto:Stefan.Manegold@cwi.nl | | CWI, P.O.Box 94079 | http://www.cwi.nl/~manegold/ | | 1090 GB Amsterdam | Tel.: +31 (20) 592-4212 | | The Netherlands | Fax : +31 (20) 592-4312 |
participants (3)
-
Lefteris
-
Sjoerd Mullender
-
Stefan Manegold