Skip Menu |

This queue is for tickets about the Variable-Magic CPAN distribution.

Report information
The Basics
Id: 127572
Status: open
Priority: 0/
Queue: Variable-Magic

People
Owner: Nobody in particular
Requestors: felix.ostmann [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.62
Fixed in: (no value)



Subject: require Variable::Magic VS use Variable::Magic
Hello, we investigate a strange segfault problem in Dios (see https://rt.cpan.org/Ticket/Display.html?id=123015) and i can reproduce this segfault in Variable::Magic by a simple "require Variable::Magic;". $ perl -e 'require Variable::Magic; my $s = "test"; Variable::Magic::cast($s, Variable::Magic::wizard(set => sub { print STDERR "TEST\n"; })); $s = "demo";' Speicherzugriffsfehler (Speicherabzug geschrieben) $ perl -e 'use Variable::Magic; my $s = "test"; Variable::Magic::cast($s, Variable::Magic::wizard(set => sub { print STDERR "TEST\n"; })); $s = "demo";' TEST I can reproduce this behavior in all major perls since 5.14 (not tested below this version) under Ubuntu 16.04 build with perlbrew. Also with 5.28.0 on a FreeBSD with perlbrew. Have a nice day Felix Also someone find a problem with a SvRV() call on a non-reference, please investigate this too (see the linked ticket).
On 2018-11-05 00:31:59, felix.ostmann@gmail.com wrote: Show quoted text
> Hello, > > we investigate a strange segfault problem in Dios (see > https://rt.cpan.org/Ticket/Display.html?id=123015) and i can reproduce > this segfault in Variable::Magic by a simple "require > Variable::Magic;". > > $ perl -e 'require Variable::Magic; my $s = "test"; > Variable::Magic::cast($s, Variable::Magic::wizard(set => sub { print > STDERR "TEST\n"; })); $s = "demo";' > Speicherzugriffsfehler (Speicherabzug geschrieben) > $ perl -e 'use Variable::Magic; my $s = "test"; > Variable::Magic::cast($s, Variable::Magic::wizard(set => sub { print > STDERR "TEST\n"; })); $s = "demo";' > TEST > > I can reproduce this behavior in all major perls since 5.14 (not > tested below this version) under Ubuntu 16.04 build with perlbrew. > Also with 5.28.0 on a FreeBSD with perlbrew. > > Have a nice day > Felix > > Also someone find a problem with a SvRV() call on a non-reference, > please investigate this too (see the linked ticket).
It seems that the Variable::Magic::cast prototype is not enforced if Variable::Magic was not loaded at compile time. To workaround the "require" case, $s could be turned into a \$s.
Le Lun 05 Nov 2018 01:24:25, SREZIC a écrit : Show quoted text
> On 2018-11-05 00:31:59, felix.ostmann@gmail.com wrote:
> > Hello, > > > > we investigate a strange segfault problem in Dios (see > > https://rt.cpan.org/Ticket/Display.html?id=123015) and i can > > reproduce > > this segfault in Variable::Magic by a simple "require > > Variable::Magic;". > > > > $ perl -e 'require Variable::Magic; my $s = "test"; > > Variable::Magic::cast($s, Variable::Magic::wizard(set => sub { print > > STDERR "TEST\n"; })); $s = "demo";' > > Speicherzugriffsfehler (Speicherabzug geschrieben) > > $ perl -e 'use Variable::Magic; my $s = "test"; > > Variable::Magic::cast($s, Variable::Magic::wizard(set => sub { print > > STDERR "TEST\n"; })); $s = "demo";' > > TEST > > > > I can reproduce this behavior in all major perls since 5.14 (not > > tested below this version) under Ubuntu 16.04 build with perlbrew. > > Also with 5.28.0 on a FreeBSD with perlbrew. > > > > Have a nice day > > Felix > > > > Also someone find a problem with a SvRV() call on a non-reference, > > please investigate this too (see the linked ticket).
> > It seems that the Variable::Magic::cast prototype is not enforced if > Variable::Magic was not loaded at compile time. To workaround the > "require" case, $s could be turned into a \$s.
This is correct, and is a limitation in perl itself rather than in Variable::Magic. The perl compiler can only enforce prototypes on subroutine calls when he's aware of them, and that happens only when the module is loaded at compile-time by the "use" keyword. If you still need to load the module at run-time with require then, as Slaven explained, you should pass a reference to the variable to Variable::Magic's functions. Vincent
OK, perhaps this should be at least explained in the documentation within the caveats section. Using require to load a module late is nowadays popular. Suggestion: Due to limitations in perl itself combining "require" with non-reference variables in Variable::Magic function calls could produce segfaults (this is a problem with prototypes only working correct when processing at compile-time). Don't do it, you are warned.