I don't neccessarily need a FILE*. I've tried the following: IO* io = GvIOp(PL_defoutgv); PerlIO* ofp = IoOFP(io); PerlIO_printf(ofp, ...);
I didn't know I can work with the IO pointer so I changed it into an PerlIO*. These things seem rather poorly documented to me. Anyway, this doesn't work, but I think I finally figured out what the problem is. After a few hours of searching and trying and so on, I think there's not enough space allocated for the string I'm trying to print in. If I redirect it to a file, it works perfectly, but with a string I get a segmentation fault. I thought somehow the C-space functions would know to work with the perl-magic of dynamically allocating memory for strings, but now I believe it's not so. I've tried passing a string from Perl to a C-function and sprintf'ing to that string, and I saw that you can only have as much space as you have "allocated" from Perl. So basically, my conclusion is that what I'm trying to do is only doable if you know how much you will write in the string and allocate enough space for it from perl or C-space. Since that's not the case here I'll need a workaround. I can't determine how long the string will be, before I print to it, since it's a recursive function that keeps adding to the string. So I'll have to keep realloc'ing as I write to it, or write everything to a temporary file and read it from Perl. Maybe these conclusions will be of help to somebody. If any of you think I'm wrong and can figure out another way, please let me know. Thanks Ken and Marvin for your help. Alex p.s. Sorry Ken, you'll be getting this mail twice, I forgot to hit reply-all the first time :) On 7/11/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > -----Original Message----- > > From: Alexandru Palade [mailto:[EMAIL PROTECTED] > > Sent: Monday, July 11, 2005 4:54 AM > > To: Williams, Ken (TLR Corp) > > Cc: inline@perl.org > > Subject: Re: accesing the C-space stdout > > > > Yes, I can modify enum_files and I tried to do as you > > suggested. To get a FILE* to the currently selected > > filehandle I tried the following, in enum_files(): > > > > IO* io = GvIOp(PL_defoutgv); > > PerlIO* ofp = IoOFP(io); > > fout = PerlIO_exportFILE(ofp, "w"); > > Can you print directly to the IO* object, like so? > > IO* io = GvIOp(PL_defoutgv); > PerlIO_printf(io, fmt, ...); > > Or do you need to pass true file descriptors to a lower-level function? > > -Ken >