harless@sdd.hp.com (Mike Harless) (01/31/91)
Was there some change with perl and passing file descriptors in and out of subroutines? I've applied the 42-44 patches and now one of my backup scripts is failing with 'memory fault, core dump'. In it, I'm creating a socket, and then passing it by reference to various subroutines. If I make the socket descriptor global or go back to 3.0@41 the problem goes away. I'm on an HP 9000/370 with hp-ux 7.0. Here's an example of what I'm doing: ... make_socket(S) ; ... where subroutine make_socket() looks like: sub make_socket() { local(*S) = shift(@_) ; # what socket to connect with local($them) ; local($this, $that) ; local($sockaddr) = 'S n a4 x8' ; local($name,$aliases,$proto) ; local($type,$len,$thataddr) ; ($name,$aliases,$proto) = getprotobyname('tcp') ; ($name,$aliases,$port) = getservbyname($port,'tcp') unless $port =~ /^\d+$/ ; ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($host) ; ($name,$aliases,$type,$len,$thataddr) = gethostbyname($server) ; $this = pack($sockaddr, &AF_INET, 0, $thisaddr) ; $that = pack($sockaddr, &AF_INET, $port, $thataddr) ; socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket failed, $!" ; ... Running things under 'perl -d', I get the core dump with the socket() call. Getting rid of the 'local(*S) = shift(@_)', gets around the problem and life goes on. Any ideas of what the problem can be? ...Mike
tchrist@convex.COM (Tom Christiansen) (01/31/91)
From the keyboard of harless@sdd.hp.com (Mike Harless): :Was there some change with perl and passing file descriptors in and out of :subroutines? I've applied the 42-44 patches and now one of my backup :scripts is failing with 'memory fault, core dump'. In it, I'm creating a :socket, and then passing it by reference to various subroutines. If I make :the socket descriptor global or go back to 3.0@41 the problem goes away. :I'm on an HP 9000/370 with hp-ux 7.0. : : :Here's an example of what I'm doing: : : make_socket(S) ; : :where subroutine make_socket() looks like: : : sub make_socket() { : : local(*S) = shift(@_) ; # what socket to connect with : : socket(S, &PF_INET, &SOCK_STREAM, $proto) || : die "socket failed, $!" ; I assume you mean &make_socket(S); That's actually the same as &make_socket('S'); which isn't a very good symbol table entry to absorb with your local(*S) assignment. Make sure that if you to a local(*x) that you're assigning a *y to it, not a plain $y. You probably want one of these: &make_socket(*S); ... local(*sock) = shift; socket(sock, ...) or &make_socket('S'); ... local($sock) = shift; socket($sock, ...) I don't personally like passing naked file handles around and letting them turn into strings. I also like to name my subroutine local different than what gets passed into them. --tom -- "Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now he can finally have the whole O/S built-in to his editor like he always wanted!" --me (Tom Christiansen <tchrist@convex.com>)