in reply to Sending PerlIO* to the stack for call_sv()?

Update: I've managed to get it working - the C code now passes in a real filehandle glob which is already blessed to IO::Socket::INET. However, I'm not entirely sure that my code to do so is entirely sane and correct. It's more or less what I managed to cobble together by reading the source to pp_socket in pp_sys.c and staring at the perlapi/perlguts/etc docs. I don't entirely understand the purpose of some things, and I'm not sure that I'm not leaking memory:
[...] IO* conn_pio; SV* connrv; GV* fhglob; HV* our_stash; HV* isn_stash; isn_stash = gv_stashpv("IO::Socket::INET",1); our_stash = gv_stashpv("MyModule::Name",1); fhglob = gv_fetchmethod(our_stash,"myfilehandle"); conn_pio = GvIOn(fhglob); IoIFP(conn_pio) = PerlIO_fdopen(conn, "r"SOCKET_OPEN_MODE); IoOFP(conn_pio) = PerlIO_fdopen(conn, "w"SOCKET_OPEN_MODE); IoTYPE(conn_pio) = IoTYPE_SOCKET; connrv = newRV_inc((SV*)fhglob); sv_bless(connrv,isn_stash); ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(connrv); PUTBACK; cpretval = call_sv(kid_conn_coderef, G_SCALAR|G_EVAL|G_KEEPERR); [....]