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

Params::Util XS version of _HASH0 does not return undef for a blessed hash #3

Open
wolfsage opened this issue Jan 5, 2023 · 2 comments

Comments

@wolfsage
Copy link

wolfsage commented Jan 5, 2023

_HASH0 says:

  The "_HASH0" function is intended to be imported into your package, and
    provides a convenient way to test for a raw and unblessed "HASH"
    reference, regardless of the "HASH" content.

And yet:

$ perl -MParams::Util=_HASH0 -E 'say _HASH0(bless {}, "cat")'
cat=HASH(0x11cd408)

Compared with the pure perl version:

$ PERL_PARAMS_UTIL_PP=1 perl -MParams::Util=_HASH0 -E 'say _HASH0(bless {}, "cat")'


@zmughal
Copy link

zmughal commented Jan 27, 2023

The same applies to _HASH, _ARRAY, and _ARRAY0. Looking at the XS, it appears that it should also check ! sv_isobject(ref) for all of these just as done for the _SCALAR0 XS.

@zmughal
Copy link

zmughal commented Jan 27, 2023

echo "_HASH0" ; for i in `seq 0 1`; do echo -en "PP=$i\n> "; PERL_PARAMS_UTIL_PP=$i perl -MParams::Util=_HASH0  -E 'say _HASH0(bless {}, "cat")'; done; echo "---"
echo "_HASH"  ; for i in `seq 0 1`; do echo -en "PP=$i\n> "; PERL_PARAMS_UTIL_PP=$i perl -MParams::Util=_HASH   -E 'say _HASH(bless { a => 1 }, "cat")'; done;  echo "---"
echo "_ARRAY0"; for i in `seq 0 1`; do echo -en "PP=$i\n> "; PERL_PARAMS_UTIL_PP=$i perl -MParams::Util=_ARRAY0 -E 'say _ARRAY0(bless [], "cat")'; done;  echo "---"
echo "_ARRAY" ; for i in `seq 0 1`; do echo -en "PP=$i\n> "; PERL_PARAMS_UTIL_PP=$i perl -MParams::Util=_ARRAY  -E 'say _ARRAY(bless [0], "cat")'; done; echo "---"

gives

_HASH0
PP=0
> cat=HASH(0x55c8da203420)
PP=1
> 
---
_HASH
PP=0
> cat=HASH(0x55e357605420)
PP=1
> 
---
_ARRAY0
PP=0
> cat=ARRAY(0x5558eeec0420)
PP=1
> 
---
_ARRAY
PP=0
> cat=ARRAY(0x55e1263a8420)
PP=1
> 
---

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

No branches or pull requests

2 participants