diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-06-18 17:39:57 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-06-18 17:39:57 -0400 |
commit | 93b6e03ab4794272986a11a427c6c391eafa5dea (patch) | |
tree | d47064e64f9edbe30fdaacee3ba56c81d6b74147 /contrib/jsonb_plperl/jsonb_plperl.c | |
parent | e3b7f7cc50630dac958a48b533cce04e4222892b (diff) | |
download | postgresql-93b6e03ab4794272986a11a427c6c391eafa5dea.tar.gz |
Fix jsonb_plperl to convert Perl UV values correctly.
Values greater than IV_MAX were incorrectly converted to SQL,
for instance ~0 would become -1 rather than 18446744073709551615
(on a 64-bit machine).
Dagfinn Ilmari Mannsåker, adjusted a bit by me
Discussion: https://postgr.es/m/d8jtvskjzzs.fsf@dalvik.ping.uio.no
Diffstat (limited to 'contrib/jsonb_plperl/jsonb_plperl.c')
-rw-r--r-- | contrib/jsonb_plperl/jsonb_plperl.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/contrib/jsonb_plperl/jsonb_plperl.c b/contrib/jsonb_plperl/jsonb_plperl.c index 1b63fc4b30..e847ae5369 100644 --- a/contrib/jsonb_plperl/jsonb_plperl.c +++ b/contrib/jsonb_plperl/jsonb_plperl.c @@ -198,7 +198,24 @@ SV_to_JsonbValue(SV *in, JsonbParseState **jsonb_state, bool is_elem) break; default: - if (SvIOK(in)) + if (SvUOK(in)) + { + /* + * If UV is >=64 bits, we have no better way to make this + * happen than converting to text and back. Given the low + * usage of UV in Perl code, it's not clear it's worth working + * hard to provide alternate code paths. + */ + const char *strval = SvPV_nolen(in); + + out.type = jbvNumeric; + out.val.numeric = + DatumGetNumeric(DirectFunctionCall3(numeric_in, + CStringGetDatum(strval), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1))); + } + else if (SvIOK(in)) { IV ival = SvIV(in); |