R
Rainer Weikusat
Dave Saville said:[...]
require XSLoader;
#line 1 /opt/perl/lib/5.16.3/amd64-freebsd/POSIX.pm
XSLoader::load("POSIX");
POSIX::setlocale("LC_ALL", "C");
delete $POSIX::{$_} for keys %POSIX::;
The #line line is necessary to prevent XSLoader from falling back to
DynaLoader (which loads vars.pm, which has a 'use VERSION' line). It
must give the correct path to POSIX.pm on your system, with /
separators. Clearing out POSIX:: is necessary to avoid a whole lot of
'subroutine redefined' warnings when you load POSIX properly.
The #line hack could be avoided by using DynaLoader::dl_load_file and
dl_find_symbol directly, but that still needs to know the full path to
POSIX.dll (and you can't load Config to find it properly). I was hoping
it would be possible to avoid needing to clear POSIX:: by just looking
up 'setlocale' and then unloading the DLL, but these days XSUBs are
static functions and the only external symbol in the DLL is boot_POSIX.
Hi Ben
Argument "LC_ALL" isn't numeric in subroutine entry at
d:/usr/lib/perl/lib/5.16.
0/OS2/POSIX.pm line 2.
I could of course hard code the value from the .h file
That's what you have to do (and use the number instead of a string)
because there's no way to get access to the symbolic names without
loading the Perl part. However, what I was thinking was actually rather
something like this:
-----------
/* includes */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <locale.h>
MODULE = set_lc_all
char *set_lc_all(what)
char *what
CODE:
RETVAL = setlocale(LC_ALL, what);
OUTPUT:
RETVAL
----------
This is code written in the Perl eXtenSion language. It can be turned
into C with xsubpp, compiled into a shared object/ DLL and the
individual funtion can then be made available via DynaLoader. This
requires a certain one-time effort (I don't think I can legally post the
code I'm using but all in all, it is a lot less than 100 LOC) but I
found it more than occasionally useful that I can combine Perl and C
freely.