ingydotnet / inline-c-pm

10 stars 19 forks source link

Inline::C doesn't know when to sv_force_normal or to respect SvREADONLY #57

Open wchristian opened 7 years ago

wchristian commented 7 years ago

Found in https://github.com/devel-chm/OpenGL-Modern/issues/16

This code does not work reliably: https://gist.github.com/wchristian/6df5740d442002a311cbeb8282cfca4d

Zefram and mst opined in #p5p that this might be fixable:

(Zefram) your four() function doesn't sv_force_normal() or otherwise respect SvREADONLY
(mst) I guess nobody realised they needed to teach Inline::C about that
(Zefram) Inline::C can't tell whether the function body is going to try to mutate the string. XS has the same problem
(Mithaldu) is there a quick and common way to declare those inputs as "gonna mutate those"?
(Zefram) no, it's a rare need
(Zefram) you'll have to take an SV* and do it yourself, or create a custom typemap to do it if you need it a lot
(Zefram) the failure to respect SvREADONLY is a reportable bug in any case
(Mithaldu) how does one normally respect SvREADONLY?
(Zefram) if(SvREADONLY(argsv)) croak("woah nelly!");
(Zefram) sv_force_normal() is a better way, because COWed strings are SvREADONLY but may actually be mutatable
(Zefram) sv_force_normal() will de-COW and remove the SvREADONLY status if you're allowed to mutate the scalar