passing FILE pointers to a non-MSVC++ compiled extension type???

doug doug_bartholomew99 at yahoo.com
Thu Aug 9 20:04:14 EDT 2001


hello,

bottomline: 
is there someway i can write an extenstion type's print method so that
instead of fprintf-ing to the FILE* directly, i call back to some
python c api function with the c string of what i want to print???

explanation:
i have written an extension type which defines its own print method. 
when it is compiled/linked under MSVC++ 6.0, the resulting .pyd works
correctly.  however, when compiled/lined with borland's command line
compiler/linker, the print method causes the python session to crash. 
in particular, the offending line within the print method is:

fprintf(fp, "%s", (Self->Data).ReturnCString());  // fp causes crash

i have read that other people have had the same problem, bc FILE
pointers (which the variable fp is) cannot be passed between between
MSVC++ compiled code and Borland-compiled code.

a not-so-elegant workaround is to replace the above offending line in
the print method with:

std::cout << (Self->Data).ReturnCString();  // notice no fp is used
here

but this only works when python is run in a console window and doesnt
work when the interpretter is embedded in a windows app (like
PythonWin) where python redirects its own output.

i absolutely have to use the borland compiler bc for the rest of my
project, i use fairly intricate (though perfectly standard) c++ code
which MSVC++ cant compile but borland will.  i have read in a long ago
post that this is because borland and msvc++ use different RTLs.  is
there a workaround within the python c api for this???  is there
someway i can rewrite my print method so that instead of fprintf-ing
to the FILE* directly, i call back to some python c api function with
the c string of what i want to print to the console???

many thanks,

doug_bartholomew99 at yahoo.com



More information about the Python-list mailing list