Hi Rob,
There was a typo in the previous message. I accidentally called you
'Bob', sorry about that
All the best,
lr
laurentiu rudeanu wrote:
Hi Bob,
Thanks a lot for the reply!
I was going to abandon the whole Inline thing and look for other
ways/tools but because you had succeses with your test it made me pick
it up again and see what's wrong with my code... The problem was really
stupid and it was all my fault: I was passing \$hash as the parameter
instead of \%hash... don't ask me why I changed that :) (it's true that
at some point I was toying with passing various reference arguments)
Good to know it's working so I can still go on with Inline !
Thanks a lot, cheers!
Laurentiu R
Sisyphus wrote:
----- Original Message ----- From: "laurentiu rudeanu"
<[EMAIL PROTECTED]>
To: <inline@perl.org>
Sent: Thursday, November 16, 2006 9:53 PM
Subject: Re: Inline::C with AUTOWRAP to wrap a C library which uses Perl
tools?(perl.h, XSUB.h, EXTERN.h etc)
Hi again,
In fact I've noticed that even if I don't use AUTOWRAP it still
crashes. I've inlined a small C function in the pel script which simply
delegates to the function in the library:
use Inline C => <<'END_OF_C_CODE';
void dumpHash2(SV* hash_ref)
{
dumpHash(hash_ref); // this is the function in the C library
}
END_OF_C_CODE
And it still segfaults in the library, the same as as earlier.
The C code is copied verbatim from the Cookbook. What's different when
running inside the library? Maybe some mysterious changes that Inline::C
does to the inlined C code ?
My cwd is:
D:\pscrpt\inline
plib.c (in the cwd) looks like:
--------------
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
void dumpHash(SV* hash_ref) {
HV* hash;
HE* hash_entry;
int num_keys, i;
SV* sv_key;
SV* sv_val;
if (! SvROK(hash_ref))
croak("hash_ref is not a reference");
hash = (HV*)SvRV(hash_ref);
num_keys = hv_iterinit(hash);
for (i = 0; i < num_keys; i++) {
hash_entry = hv_iternext(hash);
sv_key = hv_iterkeysv(hash_entry);
sv_val = hv_iterval(hash, hash_entry);
printf("%s => %s\n", SvPV(sv_key, PL_na),
SvPV(sv_val,
PL_na));
}
return;
}
--------------
My perl header files and libperl58.a are in D:\perl58_M\5.8.8\lib\CORE
I build libplib.a in the cwd by first running:
gcc -o plib.o -c plib.c -ID:\perl58_M\5.8.8\lib\CORE
followed by:
ar rc libplib.a plib.o
try.pl (in the cwd) looks like:
---------------
use Inline C => Config =>
LIBS =>
'-LD:\pscrpt\inline -lplib -LD:\perl58_M\5.8.8\lib\CORE -lperl58',
BUILD_NOISY => 1; # see the compilation report
use Inline C => <<'END_OF_C_CODE';
void dumpHash2(SV* hash_ref)
{
dumpHash(hash_ref); // this is the function in the C library
}
END_OF_C_CODE
my %hash = (
Author => "Brian Ingerson",
Nickname => "INGY",
Module => "Inline.pm",
Version => "0.30",
Language => "C",
);
dumpHash2(\%hash);
---------------
I run 'perl try.pl' and get the usual compilation output, followed by:
---------------
Version => 0.30
Nickname => INGY
Language => C
Module => Inline.pm
Author => Brian Ingerson
---------------
No problem :-)
Cheers,
Rob