Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prototype mismatch warning for JSON functions. #182

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

deven
Copy link
Contributor

@deven deven commented Mar 17, 2020

The prototypes used in RapidApp::JSON::MixedEncoder for encode_json()
and decode_json() match the respective prototypes in JSON::XS, but they
don't match the prototypes used for those functions in Cpanel::JSON::XS,
which JSON::MaybeXS will use in preference to JSON::XS.

This can be easily demonstrated by including both modules:

$ perl -MJSON::MaybeXS -MRapidApp::JSON::MixedEncoder -e 0
Prototype mismatch: sub main::encode_json ($;$) vs ($) at /usr/share/perl/5.26/Exporter.pm line 66.
at -e line 0.
Prototype mismatch: sub main::decode_json ($;$$) vs ($) at /usr/share/perl/5.26/Exporter.pm line 66.
at -e line 0.

RapidApp uses Catalyst, which uses JSON::MaybeXS, causing this prototype
mismatch warning. This commit fixes this problem by using JSON::MaybeXS
where the JSON module was previously used, and changing the prototypes
for encode_json() and decode_json() in RapidApp::JSON::MixedEncoder to
match the prototypes in Cpanel::JSON::XS, rather than JSON::XS.

Note that this change means that using RapidApp::JSON::MixedEncoder with
either JSON::XS or JSON will now cause a prototype mismatch warning!

@nrdvana
Copy link
Collaborator

nrdvana commented Mar 17, 2020

I'm not sure that fixing the warning is the right thing to do. The RapidApp MixedEncoder is not compatible with the JSON module in the first place (MixedEncoder is writing javascript, where JSON module is strictly json) and it depends on using JSON::PP internally. So, if you use JSON::XS and use RapidApp::JSON::MixedEncoder in the same file, one of those is not going to have the desired effect. Probably the names of the functions exported by MixedEncoder should have been named something different, like "encode_javascript", but its a bit late to change now. maybe.

The prototypes used in RapidApp::JSON::MixedEncoder for encode_json()
and decode_json() match the respective prototypes in JSON::XS, but they
don't match the prototypes used for those functions in Cpanel::JSON::XS,
which JSON::MaybeXS will use in preference to JSON::XS.

This can be easily demonstrated by including both modules:

$ perl -MJSON::MaybeXS -MRapidApp::JSON::MixedEncoder -e 0
Prototype mismatch: sub main::encode_json ($;$) vs ($) at /usr/share/perl/5.26/Exporter.pm line 66.
 at -e line 0.
Prototype mismatch: sub main::decode_json ($;$$) vs ($) at /usr/share/perl/5.26/Exporter.pm line 66.
 at -e line 0.

RapidApp uses Catalyst, which uses JSON::MaybeXS, causing this prototype
mismatch warning.  This commit fixes this problem by using JSON::MaybeXS
where the JSON module was previously used, and changing the prototypes
for encode_json() and decode_json() in RapidApp::JSON::MixedEncoder to
match the prototypes in Cpanel::JSON::XS, rather than JSON::XS.

Note that this change means that using RapidApp::JSON::MixedEncoder with
either JSON::XS or JSON will now cause a prototype mismatch warning!
@deven deven force-pushed the fix_prototype_mismatch branch from d66826c to 37c10d5 Compare March 19, 2020 08:53
@vanstyn
Copy link
Owner

vanstyn commented Aug 2, 2020

@nrdvana - looks like @deven has made some changes since your comment, can you comment to see if this PR is a good thing to merge now in your opinion. Also, why does CI show failure? I'm not going to merge a PR thats failing in Travis

@vanstyn
Copy link
Owner

vanstyn commented Dec 13, 2020

@nrdvana - looks like @deven has made some changes since your comment, can you comment to see if this PR is a good thing to merge now in your opinion. Also, why does CI show failure? I'm not going to merge a PR thats failing in Travis

@nrdvana - is it a good thing to merge in your opinion? I haven't found the time to look closely and probably won't for a while. as I recall you wrote MixedEncoder not me...

@vanstyn
Copy link
Owner

vanstyn commented Dec 13, 2020

@deven - also and separately, one of you will need to investigate the CI test fails before it can be considered for merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants