-
Notifications
You must be signed in to change notification settings - Fork 20
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
_is_arrayref, _is_hashref and _is_coderef is incorrectly defined #12
Comments
Can you write that as a macro? As inline is not supported on all compilers, and I'd hate to make those slow just because gcc can do a better job |
@pali do you have a test case that fails under the current code? |
For test case you need to take scalar which do not have SVs_RMG, but has SVs_GMG. Then mg_get() would never be called. |
Yes, just rewrite commands via standard boolean logic into one if statement. E.g.: #define _is_arrayref(sv) ((sv) && (SvGETMAGICAL(sv), 1) && (SvROK(sv)) && (SvTYPE(SvRV(sv)) == SVt_PVAV)) |
#define _is_reftype(f,x) \
(f && (SvGETMAGIC (f), 1) && SvROK (f) && SvTYPE (SvRV (f)) == x)
#define _is_arrayref(f) _is_reftype (f, SVt_PVAV)
#define _is_hashref(f) _is_reftype (f, SVt_PVHV)
#define _is_coderef(f) _is_reftype (f, SVt_PVCV) Still passed all tests. I could not come up with a new test in |
For example magic variable |
Sure, but I still could not (yet) come up with a test :) |
Change passed all tests on all 200+ perl versions I have that should be supported and all 858 modules on CPAN that directly or indirectly depend on my still pass. The speed test did not show a slowdown. |
Released in 1.37. Closing |
See implementation: https://github.com/Tux/Text-CSV_XS/blob/master/CSV_XS.xs#L60:
Code first checks for
SvRMAGICAL()
and then callsmg_get()
. ButSvRMAGICAL
checks forSVs_RMG
-- magic different fromget
/set
, in most cases uses for clear function. So it does not make sense to call mg_get() method based onSVs_RMG
result.Instead
SvRMAGICAL()
there should be usedSvGMAGICAL()
, check forSVs_GMG
that scalar hasget
magic which means thatmg_get
needs to be called.To simplify code I would propose to use
SvGETMAGIC()
macro which callsmg_get()
when it is needed. E.g._is_arrayref(f)
could looks like this:The text was updated successfully, but these errors were encountered: