www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.c.stdio FILE * under Linux

reply James Dunne <jdunne4 bradley.edu> writes:
I've been wrestling with libvorbisfile's C API which requires use of
std.c.stdio's old FILE *s.  This works fine when I fopen() and then fclose()...
However, if I try to fopen() again, the program runs into an infinite loop, and
I don't know where since debugging is terrible.

I received slightly more success with std.gc.addRoot(my FILE *) after fopen()
which got rid of the infinite loop but after 3 iterations of this i got a
seg-fault while trying to read from the file.  This leads me to believe its a
garbage collector issue that is either a) a bug, or b) my fault for not fully
understanding what the hell I'm doing :-P.

I'll try to write a simple test case to demonstrate what I'm saying here.

If you know what I'm trying to get at, please let me know how to work correctly
with std.c.stdio and the garbage collector!

Regards,
James Dunne
Dec 05 2004
parent James Dunne <jdunne4 bradley.edu> writes:
In article <cp0jpm$10r5$1 digitaldaemon.com>, James Dunne says...
I've been wrestling with libvorbisfile's C API which requires use of
std.c.stdio's old FILE *s.  This works fine when I fopen() and then fclose()...
However, if I try to fopen() again, the program runs into an infinite loop, and
I don't know where since debugging is terrible.

I received slightly more success with std.gc.addRoot(my FILE *) after fopen()
which got rid of the infinite loop but after 3 iterations of this i got a
seg-fault while trying to read from the file.  This leads me to believe its a
garbage collector issue that is either a) a bug, or b) my fault for not fully
understanding what the hell I'm doing :-P.

I'll try to write a simple test case to demonstrate what I'm saying here.

If you know what I'm trying to get at, please let me know how to work correctly
with std.c.stdio and the garbage collector!

Regards,
James Dunne
Yeah, so, I'm a retard. It wasn't apparent that the libvorbisfile took over the FILE * and fclose()'d when i called ov_clear() on its related context. So I was essentially double fclose()-ing the FILE *. Geez... Ignore me. It works fine now :). Regards, James Dunne
Dec 05 2004