On Sunday 16 October 2016 12:34:10 Father Chrysostomos wrote: > Here are some observations concerning your patch. I do not have time to confirm that my observations are correct. Sorry. Hi! Thank you very much for review. I need to rework this patch as it has problems... I already figured out that SvGETMAGIC() must be called before SvOK(). This is also reason why tests are failing under Devel::Cover. I also see that get magic is processed more times (as you pointed) so this needs to be fixed. Now I wrote additional tests with tie where object counts number of FETCH and STORE to verify that only once they was called. All those XS functions modify "src" scalar ("eats" all processed characters) unless "check" contains ENCODE_LEAVE_SRC bit or "check" is zero or "check" is reference to sub. In case readonly variable is passed to any of those XS functions without ENCODE_LEAVE_SRC (or zero "check" or ref "check") then code should croak on error that caller tries to modify readonly variable. What I need in *encode* functions is: 1) return undef unless defined $src; 2) do mortal copy of $src if $check prevents modification 3) upgrade $src to utf8 if $src is not utf8 4) do real encoding 5) modify $src according to real encoding function *decode* functions are similar (instead it calls downgrade and croak on error). Can you help me how to achieve above correctly? It must work correctly with and without $check with prevents modification (croaks when trying to modify readonly $src) and also on globs like this: my $val = 'str'; *a = $val; encode_function(*a); (this is in one of unit test...) To answer your question, I used following construction for code when $src argument is going to be modified: "if (check && !(check & ENCODE_LEAVE_SRC))" (check is nonzero and check does not contains ENCODE_LEAVE_SRC bit)Thread Previous | Thread Next