Re: Apparent bug in Win32::API if function returns a float or a double
- From: sisyphus <sisyphus359@xxxxxxxxx>
- Date: Fri, 23 May 2008 02:09:47 -0700 (PDT)
On May 23, 12:39 pm, "Trevor Magnusson"
<trevor.magnus...@xxxxxxxxxxxxxx> wrote:
.
.
One of my colleagues has suggested I investigate something called XS...
Yes, Inline::C auto-generates the XS code for you - saves you the
trouble of writing the XS file (and the other files that you need to
write in order to create the extension).
I'm using the MinGW prot of gcc as my Windows compiler.
First up I created double.c:
-------------------------
#include <stdlib.h>
double __declspec(dllexport) my_double(char * num) {
char * foo;
double ret;
ret = strtod(num, &foo);
return ret;
}
-------------------------
Then built the object file by running:
gcc -o double.o -c double.c
Then built the dll (and the import lib, libdouble.a) by running:
gcc -shared -o double.dll double.o -Wl,--out-implib,libdouble.a
I tried to get it to work with Win32::API ... but kept getting
segfaults. I even tried using VC 7.0 (on another machine) to build the
dll, but couldn't get that to work, either. (I still think it should
be workable - but I don't personally care all that much, and got sick
of trying.)
With Inline::C, it's fairly trivial:
----------------------------
use warnings;
#use Devel::Peek;
use Inline C => Config =>
LIBS => '-LC:/_32/C -ldouble', # relative path won't do
BUILD_NOISY => 1; # view build output
use Inline C => <<'EOC';
double my_double(char*); // prototype
double foo(char * x) {
return my_double(x);
}
EOC
$ret = foo('123');
print $ret;
#Dump($ret);
----------------------------
With MS compilers, Inline::C (and XS) will need to access the import
lib. Win32::API can access the dll directly.
With the gcc compiler, Inline::C (and XS) can access the dll directly,
though the above script accesses the import lib (libdouble.a) instead.
If you have Devel::Peek installed you can uncomment those 2 lines in
the above script and verify that the returned value is, in fact, of
type NV (SVNV) - which is the perl equivalent of a double.
Cheers,
Rob
.
- References:
- Apparent bug in Win32::API if function returns a float or a double
- From: Trevor Magnusson
- Re: Apparent bug in Win32::API if function returns a float or a double
- From: sisyphus
- Re: Apparent bug in Win32::API if function returns a float or a double
- From: Trevor Magnusson
- Apparent bug in Win32::API if function returns a float or a double
- Prev by Date: Re: Apparent bug in Win32::API if function returns a float or a double
- Next by Date: error: field ‘_crypt_struct’ has incomplete type
- Previous by thread: Re: Apparent bug in Win32::API if function returns a float or a double
- Next by thread: Apparent bug in Win32::API if function returns a float or a double
- Index(es):
Relevant Pages
|
|