use warnings; use strict; use RPi::Const qw(:all); use Inline ('C' => 'DATA' => libs => '-lwiringPi -lrt -lwiringPiDev -lpthread'); my $continue = 1; $SIG{INT} = sub { $continue = 0; }; sub cref_handler { print "cref handler\n"; } my $cref = \&cref_handler; init(); pin_mode(3, INPUT); setInterruptCref(3, EDGE_FALLING, $cref); my $running; while ($continue){ print "running\n" if ! $running; $running = 1; } __DATA__ __C__ #include #include void init (){ wiringPiSetupGpio(); } PerlInterpreter* mine; SV* perl_callback_cref; void interruptHandlerCref(){ PERL_SET_CONTEXT(mine); dSP; ENTER; SAVETMPS; PUSHMARK(SP); PUTBACK; call_sv(perl_callback_cref, G_DISCARD|G_NOARGS); FREETMPS; LEAVE; } int setInterruptCref(int pin, int edge, SV* callback){ mine = Perl_get_context(); perl_callback_cref = callback; int interrupt = wiringPiISR(pin, edge, &interruptHandlerCref); return interrupt; } void pin_mode (int pin, int mode){ pinMode(pin, mode); } #### running cref handler cref handler cref handler running dler running dler Segmentation fault #### $ gdb perl GNU gdb (Raspbian 7.12-6) 7.12.0.20161007-git (gdb) r int.pl [New Thread 0x76af7470 (LWP 26138)] running cref handler Thread 1 "perl" received signal SIGSEGV, Segmentation fault. 0x000c09ec in Perl_pp_and () (gdb) bt #0 0x000c09ec in Perl_pp_and () #1 0x000c0434 in Perl_runops_standard () #2 0x000500a4 in perl_run () #3 0x0002ab50 in main ()