TheHobbit has asked for the wisdom of the Perl Monks concerning the following question:

Reverends monks, I humbly ask for your wisdom to elighten me.....
I found this weird behavior of a C program embedding perl. If you compile the enclosed program by
cc -o test test.c -Wall `perl -MExtUtils::Embed -e ccopts -e ldopts`
and then execute the resulting executable, then: This looks weird :( Should I fill a bug report, or simply I made a mess? :)))
humbly waiting for a reply :)

/*test.c*/ #include <EXTERN.h> /* from the Perl distribution */ #include <perl.h> /* from the Perl distribution */ #include <stdio.h> #include <locale.h> static PerlInterpreter *my_perl; /*** The Perl interpreter ***/ static char *perl_args[] = { "", "-e", "0", "-w" }; static char perl_script[] = { "use IO::Socket;\n" "my $sock = new IO::Socket::INET or die qq/Can't create socket!/;\n" "print qq/Done\n/;" }; extern void xs_init _((void)); extern void boot_DynaLoader _((CV * cv)); void xs_init () { char *file = __FILE__; /* this allows using dynamicaly loaded modules... see perlembed manpage*/ newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); } int main(int argc, char **argv, char **env) { setlocale (LC_ALL, ""); fprintf(stderr,"Locale value for NUMERIC is %s\n",setlocale(LC_NUMER +IC,NULL)); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, xs_init, 4, perl_args, (char **)NULL); perl_eval_pv(perl_script,(I32) NULL); perl_destruct(my_perl); perl_free(my_perl); exit(0); }


TheHobbit

Replies are listed 'Best First'.
Re: Embedded Perl, LC_NUMERIC and the $ variable.
by dchetlin (Friar) on Dec 10, 2000 at 22:07 UTC
    I believe you will find this to be fixed in 5.6.0 and onward. It was most certainly a bug. I am fairly certain that it was change #3542 that fixed this, but I'm unable to put my hands on the patch. Read here about the change if you're interested.

    Sorry for not having noticed this node earlier; I only just found it because of your other excellent question. Keep up the good work.

    -dlc

Re: Embedded Perl, LC_NUMERIC and the $ variable.
by Fastolfe (Vicar) on Dec 07, 2000 at 00:43 UTC
    Are you changing your local information between executions or between rebuilds of the executable?

    I believe there is a "C" locale specifically for reasons like this (ensuring the compile/build process is predictable), but if you're getting different results between executions of the app, depending on your locale settings, I'd be tempted to wonder if this were a bug as you suggest.

    Unfortunately, I'm no embedded C expert, nor am I a locale expert. Perhaps someone else can give more information.