Thread: [HACKERS] T_Float morph to T_Integer after nodeRead
I noticed a strange behavior when T_Float value is serialized, then deserialized on the worker process for cpu parallel execution. Simplified description of what I did is: fval = makeFloat(psprintf("%.0f", plan_nrows)); custom_scan->custom_private = list_make1(fval); This string expression contains no dot, then Float value was written out as if it is an integer value, like "654321". nodeRead() calls nodeTokenType() to determine the token type. It determines a numeric token with no dot an Integer value, even if it is generated by makeFloat(). Then, the worker process reference this value using floatVal() and gets SEGV. A workaround is that we never use "%.0f" format for makeFloat(). It may be sufficient because we have small number of makeFloat() call all around the source tree. Or, do we have any other systematic solution to prevent numeric cstring without dot? Thanks, ---- PG-Strom Project / NEC OSS Promotion Center KaiGai Kohei <kaigai@ak.jp.nec.com>
Kouhei Kaigai <kaigai@ak.jp.nec.com> writes: > Simplified description of what I did is: > fval = makeFloat(psprintf("%.0f", plan_nrows)); > custom_scan->custom_private = list_make1(fval); So don't do that. The lexer would never produce T_Float for an integer-looking string, so I think it's out of scope for nodeRead() to be able to reconstitute such a thing. You could use %.1f, perhaps. But actually, if you're worried about reconstituting exactly what you had, aren't you risking precision loss anyway? Maybe something like psprintf("%.*e", DBL_DIG+3, plan_nrows) would be safer. regards, tom lane
> Kouhei Kaigai <kaigai@ak.jp.nec.com> writes: > > Simplified description of what I did is: > > fval = makeFloat(psprintf("%.0f", plan_nrows)); > > custom_scan->custom_private = list_make1(fval); > > So don't do that. The lexer would never produce T_Float for an > integer-looking string, so I think it's out of scope for nodeRead() to be > able to reconstitute such a thing. You could use %.1f, perhaps. > But actually, if you're worried about reconstituting exactly what you had, > aren't you risking precision loss anyway? Maybe something like > psprintf("%.*e", DBL_DIG+3, plan_nrows) would be safer. > Ah, indeed, it is a good idea to avoid the problem. Thanks, ---- PG-Strom Project / NEC OSS Promotion Center KaiGai Kohei <kaigai@ak.jp.nec.com>