Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Cpanel-JSON-XS 4.09
Browse files Browse the repository at this point in the history
Silence Gconvert -Wunused-result.

Add unblessed_bool property (PR #118 by Pali)

Add seperate allow_dupkeys property, in relaxed (#122),
Fixed allow_dupkeys for the XS slow path,
Silence 2 -Wunused-value warnings,
Fix ->unblessed_bool to produce modifiable perl structures (PR #121 by Pali).
  • Loading branch information
rurban committed Feb 15, 2019
1 parent db1076d commit d308747
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
2 changes: 1 addition & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,5 @@
}
},
"version" : "5.029001c",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.07"
"x_serialization_backend" : "Cpanel::JSON::XS version 4.09"
}
2 changes: 1 addition & 1 deletion Porting/Maintainers.pl
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ package Maintainers;
},

'Cpanel::JSON::XS' => {
'DISTRIBUTION' => 'RURBAN/Cpanel-JSON-XS-4.07.tar.gz',
'DISTRIBUTION' => 'RURBAN/Cpanel-JSON-XS-4.09.tar.gz',
'FILES' => q[cpan/Cpanel-JSON-XS],
'EXCLUDED' => [
'.appveyor.yml',
Expand Down
35 changes: 32 additions & 3 deletions cpan/Cpanel-JSON-XS/XS.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package Cpanel::JSON::XS;
our $VERSION = '4.07';
our $VERSION = '4.09';
our $XS_VERSION = $VERSION;
# $VERSION = eval $VERSION;

Expand Down Expand Up @@ -645,11 +645,12 @@ L</allow_barekey> option.
{ foo:"bar" }
=item * duplicate keys
=item * allow_dupkeys
With relaxed decoding of duplicate keys does not error and are silently accepted.
Allow decoding of duplicate keys in hashes. By default duplicate keys are forbidden.
See L<http://seriot.ch/parsing_json.php#24>:
RFC 7159 section 4: "The names within an object should be unique."
See the L</allow_dupkeys> option.
=back
Expand Down Expand Up @@ -701,6 +702,18 @@ C<"\/">.
This setting has no effect when decoding JSON texts.
=item $json = $json->unblessed_bool ([$enable])
=item $enabled = $json->get_unblessed_bool
$json = $json->unblessed_bool([$enable])
If C<$enable> is true (or missing), then C<decode> will return
Perl non-object boolean variables (1 and 0) for JSON booleans
(C<true> and C<false>). If C<$enable> is false, then C<decode>
will return C<Cpanel::JSON::XS::Boolean> objects for JSON booleans.
=item $json = $json->allow_singlequote ([$enable])
=item $enabled = $json->get_allow_singlequote
Expand Down Expand Up @@ -812,6 +825,22 @@ This option does not affect C<decode> in any way.
This option is special to this module, it is not supported by other
encoders. So it is not recommended to use it.
=item $json = $json->allow_dupkeys ([$enable])
=item $enabled = $json->get_allow_dupkeys
If C<$enable> is true (or missing), then the C<decode> method will not
die when it encounters duplicate keys in a hash.
C<allow_dupkeys> is also enabled in the C<relaxed> mode.
The JSON spec allows duplicate name in objects but recommends to
disable it, however with Perl hashes they are impossible, parsing
JSON in Perl silently ignores duplicate names, using the last value
found.
See L<http://seriot.ch/parsing_json.php#24>:
RFC 7159 section 4: "The names within an object should be unique."
=item $json = $json->allow_blessed ([$enable])
=item $enabled = $json->get_allow_blessed
Expand Down
28 changes: 19 additions & 9 deletions cpan/Cpanel-JSON-XS/XS.xs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,12 @@ mingw_modfl(long double x, long double *ip)
#define F_ESCAPE_SLASH 0x00080000UL
#define F_SORT_BY 0x00100000UL
#define F_ALLOW_STRINGIFY 0x00200000UL
#define F_UNBLESSED_BOOL 0x00400000UL
#define F_ALLOW_DUPKEYS 0x00800000UL
#define F_HOOK 0x80000000UL /* some hooks exist, so slow-path processing */

#define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER
#define SET_RELAXED (F_RELAXED | F_ALLOW_BAREKEY | F_ALLOW_SQUOTE)
#define SET_RELAXED (F_RELAXED | F_ALLOW_BAREKEY | F_ALLOW_SQUOTE | F_ALLOW_DUPKEYS)

#define INIT_SIZE 32 /* initial scalar size to be allocated */
#define INDENT_STEP 3 /* default spaces per indentation level */
Expand Down Expand Up @@ -3253,7 +3255,7 @@ decode_hv (pTHX_ dec_t *dec, SV *typesv)
SV *typerv;
int allow_squote = dec->json.flags & F_ALLOW_SQUOTE;
int allow_barekey = dec->json.flags & F_ALLOW_BAREKEY;
int relaxed = dec->json.flags & F_RELAXED;
int allow_dupkeys = dec->json.flags & F_ALLOW_DUPKEYS;
char endstr = '"';

DEC_INC_DEPTH;
Expand Down Expand Up @@ -3313,14 +3315,16 @@ decode_hv (pTHX_ dec_t *dec, SV *typesv)
if (!key)
goto fail;

if (!allow_dupkeys && UNLIKELY(hv_exists_ent (hv, key, 0))) {
ERR ("Duplicate keys not allowed");
}
decode_ws (dec); EXPECT_CH (':');

decode_ws (dec);

if (typesv)
{
value_typesv = newSV (0);
hv_store_ent (typehv, key, value_typesv, 0);
(void)hv_store_ent (typehv, key, value_typesv, 0);
}

value = decode_sv (aTHX_ dec, value_typesv);
Expand All @@ -3330,7 +3334,7 @@ decode_hv (pTHX_ dec_t *dec, SV *typesv)
goto fail;
}

hv_store_ent (hv, key, value, 0);
(void)hv_store_ent (hv, key, value, 0);
SvREFCNT_dec (key);

break;
Expand All @@ -3350,14 +3354,12 @@ decode_hv (pTHX_ dec_t *dec, SV *typesv)
if (UNLIKELY(p - key > I32_MAX))
ERR ("Hash key too large");
#endif
if (!relaxed && UNLIKELY(hv_exists (hv, key, len))) {
if (!allow_dupkeys && UNLIKELY(hv_exists (hv, key, len))) {
ERR ("Duplicate keys not allowed");
}

dec->cur = p + 1;

decode_ws (dec); if (*p != ':') EXPECT_CH (':');

decode_ws (dec);

if (typesv)
Expand Down Expand Up @@ -3600,6 +3602,8 @@ decode_sv (pTHX_ dec_t *dec, SV *typesv)
dec->cur += 4;
if (typesv)
sv_setiv_mg (typesv, JSON_TYPE_BOOL);
if (dec->json.flags & F_UNBLESSED_BOOL)
return newSVsv (&PL_sv_yes);
return newSVsv(MY_CXT.json_true);
}
else
Expand All @@ -3614,6 +3618,8 @@ decode_sv (pTHX_ dec_t *dec, SV *typesv)
dec->cur += 5;
if (typesv)
sv_setiv_mg (typesv, JSON_TYPE_BOOL);
if (dec->json.flags & F_UNBLESSED_BOOL)
return newSVsv (&PL_sv_no);
return newSVsv(MY_CXT.json_false);
}
else
Expand Down Expand Up @@ -4103,6 +4109,8 @@ void ascii (JSON *self, int enable = 1)
allow_bignum = F_ALLOW_BIGNUM
escape_slash = F_ESCAPE_SLASH
allow_stringify = F_ALLOW_STRINGIFY
unblessed_bool = F_UNBLESSED_BOOL
allow_dupkeys = F_ALLOW_DUPKEYS
PPCODE:
if (enable)
self->flags |= ix;
Expand Down Expand Up @@ -4131,7 +4139,9 @@ void get_ascii (JSON *self)
get_allow_singlequote = F_ALLOW_SQUOTE
get_allow_bignum = F_ALLOW_BIGNUM
get_escape_slash = F_ESCAPE_SLASH
get_allow_stringify = F_ALLOW_STRINGIFY
get_allow_stringify = F_ALLOW_STRINGIFY
get_unblessed_bool = F_UNBLESSED_BOOL
get_allow_dupkeys = F_ALLOW_DUPKEYS
PPCODE:
XPUSHs (boolSV (self->flags & ix));

Expand Down
4 changes: 2 additions & 2 deletions dist/Module-CoreList/lib/Module/CoreList.pm
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ our %released :const = (
5.029002 => '2018-08-20',
5.029003 => '2018-09-20',
5.029004 => '2018-10-20',
'5.029001c' => '2018-11-27',
'5.029001c' => '????',
);

sub version_sort {
Expand Down Expand Up @@ -17949,7 +17949,7 @@ our %delta :const = (
'Module::CoreList' => '5.20181019c',
'Module::CoreList::Utils'=> '5.20181019c',
'B::C' => '1.55_10',
'Cpanel::JSON::XS' => '4.07',
'Cpanel::JSON::XS' => '4.09',
'ExtUtils::Embed' => '1.36',
'ExtUtils::MakeMaker' => '8.35_07',
'ExtUtils::MM_Unix' => '8.35_07',
Expand Down
9 changes: 8 additions & 1 deletion pod/perlcdelta.pod
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,17 @@ under 10min.

Added a C<is_CI()> test detection.

=item L<Cpanel::JSON::XS> 4.07
=item L<Cpanel::JSON::XS> 4.09

Silence Gconvert -Wunused-result.

Add unblessed_bool property (PR #118 by Pali)

Add seperate allow_dupkeys property, in relaxed (#122),
Fixed allow_dupkeys for the XS slow path,
Silence 2 -Wunused-value warnings,
Fix ->unblessed_bool to produce modifiable perl structures (PR #121 by Pali).

=item L<ExtUtils::Embed> 1.36

Added optimize to ccopts, required for C<-flto>.
Expand Down

0 comments on commit d308747

Please sign in to comment.