perl.h seems to interfere with fopen or stdio.h

Discussion in 'Perl Misc' started by talan, Apr 15, 2007.

  1. talan

    talan Guest

    Hi. I'm using ActivePerl and Visual Studio C++ on a win32 machine.
    I'm starting to work with embedded perl (in my C++ program). I get a
    run-time error on the line with "fopen". Any clues? Thanks:

    #include "EXTERN.h"
    #include "perl.h"
    #pragma comment(lib, "perl58.lib") //link with perl library

    int main(int argc, char* argv[]) {
    FILE* fp = fopen("showtime.pl", "w");
    fclose(fp);
    return 0;
    }
    talan, Apr 15, 2007
    #1
    1. Advertising

  2. talan

    Mirco Wahab Guest

    talan wrote:
    > Hi. I'm using ActivePerl and Visual Studio C++ on a win32 machine.
    > I'm starting to work with embedded perl (in my C++ program). I get a
    > run-time error on the line with "fopen". Any clues? Thanks:
    >
    > #include "EXTERN.h"
    > #include "perl.h"
    > #pragma comment(lib, "perl58.lib") //link with perl library
    >
    > int main(int argc, char* argv[]) {
    > FILE* fp = fopen("showtime.pl", "w");
    > fclose(fp);
    > return 0;
    > }


    I linked perl58 into executables in several projects
    produced by VC++6 (VS98) and VS2005. Never ever
    there was any problem mit MS' stdio, so I guess
    you should check for the existence or writeability
    of "showtime.pl".

    What exactly are you trying to do on
    write-opening a perl script?


    Regards

    M.
    Mirco Wahab, Apr 15, 2007
    #2
    1. Advertising

  3. [A complimentary Cc of this posting was sent to
    talan
    <>], who wrote in article <>:
    > Hi. I'm using ActivePerl and Visual Studio C++ on a win32 machine.
    > I'm starting to work with embedded perl (in my C++ program). I get a
    > run-time error on the line with "fopen". Any clues? Thanks:
    >
    > #include "EXTERN.h"
    > #include "perl.h"
    > #pragma comment(lib, "perl58.lib") //link with perl library
    >
    > int main(int argc, char* argv[]) {
    > FILE* fp = fopen("showtime.pl", "w");
    > fclose(fp);
    > return 0;
    > }
    >


    One is expected to not work with StdIO under influence of perl.h -
    these calls are redirected to PerlIO instead. Use separate
    compilation units for the stuff which uses StdIO and perl.h.

    Hope this helps,
    Ilya
    Ilya Zakharevich, Apr 15, 2007
    #3
  4. talan

    Mirco Wahab Guest

    Ilya Zakharevich wrote:
    > <>], who wrote in article <>:
    >> Hi. I'm using ActivePerl and Visual Studio C++ on a win32 machine.
    >> I'm starting to work with embedded perl (in my C++ program). I get a
    >> run-time error on the line with "fopen". Any clues? Thanks:
    >>
    >> #include "EXTERN.h"
    >> #include "perl.h"
    >> #pragma comment(lib, "perl58.lib") //link with perl library
    >>
    >> int main(int argc, char* argv[]) {
    >> FILE* fp = fopen("showtime.pl", "w");
    >> fclose(fp);
    >> return 0;
    >> }
    >>

    >
    > One is expected to not work with StdIO under influence of perl.h -
    > these calls are redirected to PerlIO instead. Use separate
    > compilation units for the stuff which uses StdIO and perl.h.


    After reading this, I waded through embed.h and perl.h
    but couldn't find anything related (one spot mentioned
    a broken fflush on Solaris).

    I have some programs which read/write through stdio
    under perl.h (which is included *after* stdio) in the
    same compilation unit. (Win32, console program, Visual
    Studio/98 and /2005).

    Can you help me out here in what exactly is
    the weak point?

    Thanks & Regards

    M.
    Mirco Wahab, Apr 15, 2007
    #4
  5. [A complimentary Cc of this posting was sent to
    Mirco Wahab
    <>], who wrote in article <evu9pj$bnd$-halle.de>:
    > > One is expected to not work with StdIO under influence of perl.h -
    > > these calls are redirected to PerlIO instead. Use separate
    > > compilation units for the stuff which uses StdIO and perl.h.

    >
    > After reading this, I waded through embed.h and perl.h
    > but couldn't find anything related (one spot mentioned
    > a broken fflush on Solaris).
    >
    > I have some programs which read/write through stdio
    > under perl.h (which is included *after* stdio) in the
    > same compilation unit. (Win32, console program, Visual
    > Studio/98 and /2005).


    Why do you think they go through stdio? Did you check the names in
    the object file? I would expect them work through PerlIO (unless some
    magic #define is done); but this might have been changed in recent
    Perls - AFAIU, this was just a protective measure during transition to
    PerlIO (to break things coded to a wrong standard as early as
    possible).

    > Can you help me out here in what exactly is
    > the weak point?


    I do not know anything about any "weak point". With gcc, one can see
    redefinitions via -E -dD.

    Hope this helps,
    Ilya
    Ilya Zakharevich, Apr 16, 2007
    #5
  6. talan

    Mirco Wahab Guest

    Ilya Zakharevich wrote:
    > Mirco Wahab wrote in article <evu9pj$bnd$-halle.de>:
    >> I have some programs which read/write through stdio
    >> under perl.h (which is included *after* stdio) in the
    >> same compilation unit. (Win32, console program, Visual
    >> Studio/98 and /2005).

    >
    > Why do you think they go through stdio? Did you check the names in
    > the object file? I would expect them work through PerlIO (unless some
    > magic #define is done); but this might have been changed in recent
    > Perls - AFAIU, this was just a protective measure during transition to
    > PerlIO (to break things coded to a wrong standard as early as
    > possible).


    You are right, I missed some #defines at one point,
    and checked the application now.

    Plain stdio calls like fopen *do go* through the perl
    layer, under conditions mentioned above, its win32_fopen()
    from /win32/win32.c which contains the replacement.

    But that layer seems rather thin ( #define PERLIO_NOT_STDIO 0 ),
    it does some checks and goes straight into something denoted
    by [__imp__fopen(123)] (Win32?) then (at least here,
    stock 32bit Activeperl/820).

    Thanks & Regards

    Mirco
    Mirco Wahab, Apr 16, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SGFyYWxk?=

    How does a static interfere between sessions

    =?Utf-8?B?SGFyYWxk?=, Jun 22, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    389
    Ignacio Machin \( .NET/ C# MVP \)
    Jun 22, 2004
  2. Ken Dopierala Jr.

    Will SP2 interfere with the webservice.htc?

    Ken Dopierala Jr., Jul 19, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    369
    Ken Dopierala Jr.
    Jul 19, 2004
  3. Nonee
    Replies:
    2
    Views:
    2,636
    Neredbojias
    Oct 25, 2005
  4. Replies:
    18
    Views:
    1,883
    crazzybugger
    Oct 22, 2006
  5. Michel Rouzic
    Replies:
    4
    Views:
    1,820
    Michel Rouzic
    Apr 28, 2008
Loading...

Share This Page