#! perl use strict; use warnings; $| = 1; use Inline C => <<'END_C'; void baz(SV* foo_ref) { printf("Begin baz()\n"); fflush(stdin); dSP; ENTER; SAVETMPS; XPUSHs(sv_2mortal(newSVpvf("Plus an extra line"))); PUTBACK; call_pv("destruct", G_DISCARD); printf("Before FREETMPS\n"); fflush(stdin); FREETMPS; LEAVE; printf("-End- baz()\n"); fflush(stdin); } END_C { package Foo; sub new { my ($class, $num) = @_; my $self = { id => $num, }; return bless $self, $class; } sub DESTROY { my ($self) = @_; print 'Foo::DESTROY(', $self->{id}, ")\n"; } } my $foo1 = Foo->new('first'); my $foo2 = Foo->new('second'); bar($foo1); print "Back in main (1)\n"; baz($foo2); print "Back in main (2)\n"; sub bar { print "Begin bar()\n"; destruct($_[0]); print "-End- bar()\n"; } sub destruct { undef $_[0]; }