Click here to get back home

Can't use fopen in C after including Perl Interpreter

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Can't use fopen in C after including Perl Interpreter krg 10-04-2005
Posted by krg on October 4, 2005, 11:35 pm
Please log in for more thread options


Hi List,
And greets to all, wide and far.
I conjured up a C program that uses an instance of a Perl
Interpreter, hence had to include the perl56.lib. Spilling some more,
the program is a DLL and has a method which is being called by a Java
program. This method uses the Perl Interpreter instance to execute some
Perl statements. The C function does some file writing ops in C as
well.
The problem, is that until I include the Perl Interpreter
instance and the associated libraries, the file ops perform real smooth
and ok, but once i include the Perl handling code, the program again
compiles and links well, but crashes at the file opening op. And that's
it, the start of my worries, and before it becomes the end, I want to
be led by some answers.
Thanks in advance to whomever reads this post and even who
answer it. I can provide more details if you want.
My hunch is that maybe the perl56 library has some
implementation of fopen() or something like that ...

Bless,



Posted by Big and Blue on October 5, 2005, 7:18 pm
Please log in for more thread options


krg wrote:

> The problem, is that until I include the Perl Interpreter
> instance and the associated libraries, the file ops perform real smooth
> and ok, but once i include the Perl handling code, the program again
> compiles and links well, but crashes at the file opening op. And that's
> it, the start of my worries, and before it becomes the end, I want to
> be led by some answers.

Use cc -E to see what the pre-processor does to fopen()?


--
Just because I've written it doesn't mean that
either you or I have to believe it.


Posted by Ilya Zakharevich on October 6, 2005, 7:43 am
Please log in for more thread options


[A complimentary Cc of this posting was sent to
krg
> The problem, is that until I include the Perl Interpreter
> instance and the associated libraries, the file ops perform real smooth
> and ok, but once i include the Perl handling code, the program again
> compiles and links well, but crashes at the file opening op. And that's
> it, the start of my worries, and before it becomes the end, I want to
> be led by some answers.

You need a DMZ.
http://en.wikipedia.org/wiki/Demilitarized_zone_%28computing%29

In its baby years, Perl interpeter was using FILE* for its buffered
I/O model. Now it uses PerlIO * instead of FILE *; to simplify
transition from old XSUBs, there is a translation which maps FILE*
operations to be replaced by PerlIO* operations. This translation is
enabled, IIRC, by inclusion of "XSUB.h".

If you need FILE* (e.g., to cooperate to external libraries), you need
to proceed using the normal rules of engagement when an include
conflict arises: use different .c files. Make wrappers for your FILE*
functions in wrappers.c, expose the signature (which now uses no FILE*
stuff) in wrappers.h. Include wrappers.h into wrappers.c (for
consistency checking), and in your .xs. Call the wrappers from your
..xs.

Actually, there may be a layer of helpers in XSUB.h to simplify
working around this common problem. Maybe somebody has more specific
advice than one I gave? Maybe also :stdio IO discipline would somehow
help here?

Hope this helps,
Ilya


Posted by krg on October 22, 2005, 5:39 am
Please log in for more thread options



Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to
> krg
> > The problem, is that until I include the Perl Interpreter
> > instance and the associated libraries, the file ops perform real smooth
> > and ok, but once i include the Perl handling code, the program again
> > compiles and links well, but crashes at the file opening op. And that's
> > it, the start of my worries, and before it becomes the end, I want to
> > be led by some answers.
>
> You need a DMZ.
> http://en.wikipedia.org/wiki/Demilitarized_zone_%28computing%29
>
> In its baby years, Perl interpeter was using FILE* for its buffered
> I/O model. Now it uses PerlIO * instead of FILE *; to simplify
> transition from old XSUBs, there is a translation which maps FILE*
> operations to be replaced by PerlIO* operations. This translation is
> enabled, IIRC, by inclusion of "XSUB.h".
>
> If you need FILE* (e.g., to cooperate to external libraries), you need
> to proceed using the normal rules of engagement when an include
> conflict arises: use different .c files. Make wrappers for your FILE*
> functions in wrappers.c, expose the signature (which now uses no FILE*
> stuff) in wrappers.h. Include wrappers.h into wrappers.c (for
> consistency checking), and in your .xs. Call the wrappers from your
> .xs.
>
> Actually, there may be a layer of helpers in XSUB.h to simplify
> working around this common problem. Maybe somebody has more specific
> advice than one I gave? Maybe also :stdio IO discipline would somehow
> help here?
>
> Hope this helps,
> Ilya

Hi List,
And Thank you Ilya, it really helped. Since I went too far with the
FILE* management
stuff, I instead developed wrappers to Perl funcs and put them in a
separate file.
Ensured that either of FILE* or PerlInterpreter won't have to see each
other's face ever,
atleast in this program ... thank you again, and thanks to all who read
and replied.

<<<<<<<<<<<<<Discussion Closed>>>>>>>>>>>>>>>



Similar ThreadsPosted
RFC: Namespace advice for new VXML interpreter modules October 8, 2007, 9:00 am
Including text files in Modules November 4, 2004, 9:23 pm
ANNOUNCE: Initial release of WSF/Perl (Perl bindings for a WS-* framework) October 4, 2007, 1:37 am
PLJava - Perl embeded into Java (calling Perl from Java) - 1sr release - call for tests and review, please. July 13, 2004, 4:06 am
Perl MakeMaker - how to force Perl linking with the static C library (libcrt.lib) instead of dynamic C library (msvcrt.lib) April 17, 2007, 5:22 pm
MFC with Perl July 19, 2005, 9:38 pm
Net::SSH::Perl October 23, 2005, 11:16 pm
perl with ASP November 9, 2005, 10:19 am
Perl December 30, 2005, 9:28 pm
perl DBI help March 1, 2006, 10:25 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap