mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
Fix excessive enreferencing in jsonb-to-plperl transform.
We want, say, 2 to be transformed as 2, not \\2 which is what the original coding produced. Perl's standard seems to be to add an RV wrapper only for hash and array SVs, so do it like that. This was missed originally because the test cases only checked what came out of a round trip back to SQL, and the strip-all-dereferences loop at the top of SV_to_JsonbValue hides the extra refs from view. As a better test, print the Perl value with Data::Dumper, like the hstore_plperlu tests do. While we can't do that in the plperl test, only plperlu, that should be good enough because this code is the same for both PLs. But also add a simplistic test for extra REFs, which we can do in both. That strip-all-dereferences behavior is now a bit dubious; it's unlike what happens for other Perl-to-SQL conversions. However, the best thing to do seems to be to leave it alone and make the other conversions act similarly. That will be done separately. Dagfinn Ilmari Mannsåker, adjusted a bit by me Discussion: https://postgr.es/m/d8jlgbq66t9.fsf@dalvik.ping.uio.no
This commit is contained in:
@ -26,7 +26,7 @@ JsonbValue_to_SV(JsonbValue *jbv)
|
||||
switch (jbv->type)
|
||||
{
|
||||
case jbvBinary:
|
||||
return newRV(Jsonb_to_SV(jbv->val.binary.data));
|
||||
return Jsonb_to_SV(jbv->val.binary.data);
|
||||
|
||||
case jbvNumeric:
|
||||
{
|
||||
@ -83,7 +83,7 @@ Jsonb_to_SV(JsonbContainer *jsonb)
|
||||
(r = JsonbIteratorNext(&it, &tmp, true)) != WJB_DONE)
|
||||
elog(ERROR, "unexpected jsonb token: %d", r);
|
||||
|
||||
return newRV(JsonbValue_to_SV(&v));
|
||||
return JsonbValue_to_SV(&v);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -95,7 +95,7 @@ Jsonb_to_SV(JsonbContainer *jsonb)
|
||||
av_push(av, JsonbValue_to_SV(&v));
|
||||
}
|
||||
|
||||
return (SV *) av;
|
||||
return newRV((SV *) av);
|
||||
}
|
||||
|
||||
case WJB_BEGIN_OBJECT:
|
||||
@ -120,7 +120,7 @@ Jsonb_to_SV(JsonbContainer *jsonb)
|
||||
}
|
||||
}
|
||||
|
||||
return (SV *) hv;
|
||||
return newRV((SV *) hv);
|
||||
}
|
||||
|
||||
default:
|
||||
@ -268,7 +268,7 @@ jsonb_to_plperl(PG_FUNCTION_ARGS)
|
||||
Jsonb *in = PG_GETARG_JSONB_P(0);
|
||||
SV *sv = Jsonb_to_SV(&in->root);
|
||||
|
||||
return PointerGetDatum(newRV(sv));
|
||||
return PointerGetDatum(sv);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user