From: Nick Ing-Simmons Date: Sat, 6 Jan 2001 21:47:52 +0000 (+0000) Subject: FILE * in XS code for PerlIO world: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f7e7eb72c805f1b630a3d1a32ed33c0f6da60bea;p=p5sagit%2Fp5-mst-13.2.git FILE * in XS code for PerlIO world: - make PERLIO_NOT_STDIO 0 (co-existance) default for non PERL_CORE case. - Add FILE * T_STDIO typemap. - Finish PerlIO_findFILE() and PerlIO_extprtFILE() p4raw-id: //depot/perlio@8356 --- diff --git a/lib/ExtUtils/typemap b/lib/ExtUtils/typemap index a5d06ca..c59c3dc 100644 --- a/lib/ExtUtils/typemap +++ b/lib/ExtUtils/typemap @@ -40,7 +40,8 @@ Boolean T_IV double T_DOUBLE SysRet T_SYSRET SysRetLong T_SYSRET -FILE * T_IN +FILE * T_STDIO +PerlIO * T_INOUT FileHandle T_PTROBJ InputStream T_IN InOutStream T_INOUT @@ -138,7 +139,7 @@ T_PTROBJ T_PTRDESC if (sv_isa($arg, \"${ntype}\")) { IV tmp = SvIV((SV*)SvRV($arg)); - ${type}_desc = (\U${type}_DESC\E*) tmp; + ${type}_desc = (\U${type}_DESC\E*) tmp; $var = ${type}_desc->ptr; } else @@ -173,6 +174,8 @@ T_ARRAY while (items--) { DO_ARRAY_ELEM; } +T_STDIO + $var = PerlIO_findFILE(IoIFP(sv_2io($arg))) T_IN $var = IoIFP(sv_2io($arg)) T_INOUT @@ -267,6 +270,15 @@ T_ARRAY DO_ARRAY_ELEM } SP += $var.size - 1; +T_STDIO + { + GV *gv = newGVgen("$Package"); + PerlIO *fp = PerlIO_importFILE($var,0); + if ( fp && do_open(gv, "+<&", 3, FALSE, 0, 0, fp) ) + sv_setsv($arg, sv_bless(newRV((SV*)gv), gv_stashpv("$Package",1))); + else + $arg = &PL_sv_undef; + } T_IN { GV *gv = newGVgen("$Package"); diff --git a/perlio.c b/perlio.c index 8db2b96..72efa36 100644 --- a/perlio.c +++ b/perlio.c @@ -1767,15 +1767,31 @@ PerlIO_funcs PerlIO_stdio = { FILE * PerlIO_exportFILE(PerlIO *f, int fl) { + FILE *stdio; PerlIO_flush(f); - /* Should really push stdio discipline when we have them */ - return fdopen(PerlIO_fileno(f),"r+"); + stdio = fdopen(PerlIO_fileno(f),"r+"); + if (stdio) + { + PerlIOStdio *s = PerlIOSelf(PerlIO_push(f,&PerlIO_stdio,"r+",Nullch,0),PerlIOStdio); + s->stdio = stdio; + } + return stdio; } #undef PerlIO_findFILE FILE * PerlIO_findFILE(PerlIO *f) { + PerlIOl *l = *f; + while (l) + { + if (l->tab == &PerlIO_stdio) + { + PerlIOStdio *s = PerlIOSelf(&l,PerlIOStdio); + return s->stdio; + } + l = *PerlIONext(&l); + } return PerlIO_exportFILE(f,0); } diff --git a/perlio.h b/perlio.h index a0672be..b144b24 100644 --- a/perlio.h +++ b/perlio.h @@ -106,6 +106,10 @@ extern void PerlIO_pop (PerlIO *f); #ifndef PERLIO_NOT_STDIO #define PERLIO_NOT_STDIO 1 #endif +#else +#ifndef PERLIO_NOT_STDIO +#define PERLIO_NOT_STDIO 0 +#endif #endif #ifdef PERLIO_NOT_STDIO