From: Petr N. <Pet...@am...> - 2006-11-07 15:26:47
|
> From: Petr Novotny=0D > Sent: 06 November 2006 19:02 > To: swi...@li... > Subject: typemap(out) for Perl and FILE* >=0D > Folks, >=0D > before I start reinventing a wheel, I'd like to ask - is=0D > there a kind soul out there who wrote a %typemap(out) for=0D > FILE* for Perl and is willing to share it?=0D I've done some scavenging on the internet and compiled together the= following typemap. It seems to work with Perl 5.8. %typemap(out) FILE* { /* first, an empty glob */ GV *gv =3D (GV*)SvREFCNT_inc(newGVgen("main")); hv_delete(GvSTASH(gv), GvNAME(gv), GvNAMELEN(gv), G_DISCARD); /* get its IO */ IO *io=3DGvIOn(gv); /* convert the FILE* into PERLIO* */ PerlIO *perlio=3DPerlIO_importFILE($1,NULL); /* put the PERLIO into the glob */ IoIFP(io)=3Dperlio; IoOFP(io)=3Dperlio; /* return a reference to the glob */ ST(argvi++) =3D sv_2mortal(newRV_noinc((SV*)gv)); } I am sure it contains hardcoded assumptions that are not fully correct= (e.g., it doesn't check for gv=3D=3DNULL). 1. Is there some kind soul who can comment on it, and perhaps suggest= improvements? 2. Whoever wants to use this typemap: Feel free to use it. Just note that= the typemap assumes ownership of the FILE* in a way - for example, you are= no longer allowed to fclose() it. (If you need to keep ownership, you may= want to fdopen() it if you solve buffering issued.) Also, it doesn't solve= test/binary mode of the FILE (I'm on UNIX and therefore I don't have to). Regards, -- Petr Novotn=FD Prague Development Center, AMDOCS +420266773112, +420608711517 "The power of accurate observation is commonly called cynicism by those who= have not got it." - G.B.Shaw This message and the information contained herein is proprietary and= confidential and subject to the Amdocs policy statement, you may review at http://www.amdocs.com/email_disclaimer.asp |