Perl::Inline compiling problems

  • Thread starter Brian K. Michalk
  • Start date
B

Brian K. Michalk

I posted this over in perl.inline, but there's not much traffic there.

I've been porting some time critical code over to C, making C
libraries for reuse in Perl and C. Pure C compiles, and Perl syntax
compiles, but something's going wrong with autoload, I think.

At this point I'm just confused, and my code looks more like spagetti
than normal.

When I step it through the debugger, it halts at the line where I
call C_sn, which is a C subroutine embedded in the perl code.

With the message:
Can't locate auto/calc_texture/C_sn.al in @INC (@INC contains:
/mnt/bigun/ideraid/samba/functions/develop/bin/_Inline/lib .
/mnt/bigun/ideraid/samba/functions/develop/bin
/usr/lib/perl5/i386-linux
/usr/lib/perl5
/usr/lib/perl5/site_perl/i386-linux
/usr/lib/perl5/site_perl) at calc_texture.pm line 109

I looked, and there is no file: C_sn.al. Any suggestions?

package calc_texture;
$VERSION = '1.00';
use lib qw(
 
B

Brian K. Michalk

I posted this over in perl.inline, but there's not much traffic there.

Replying to myself here, I want to say that I've managed to resolve
most of the issues. I still have some problems though. When I
compile the C to test my code, I use the following command:

gcc -lm -o testnnlibs testnnlibs.c 110in1outa.c nnsn.c

This pulls in code from two other libraries, and magically makes the
executable. It works.

I have yet to find a way to tell Inline::C how to pull in my other
source files.
 
S

Sisyphus

Yeah - it's generally pretty quiet over there. Got a nice little note
from ezmlm just this morning, informing me that my mail from that list
is being bounced by my ISP. (That should help to maintain the
peacefulness - for me, at least :)
Replying to myself here, I want to say that I've managed to resolve
most of the issues. I still have some problems though. When I
compile the C to test my code, I use the following command:

gcc -lm -o testnnlibs testnnlibs.c 110in1outa.c nnsn.c

This pulls in code from two other libraries, and magically makes the
executable. It works.

I have yet to find a way to tell Inline::C how to pull in my other
source files.

By way of example, this works (code transcribed - beware of typos):

The perl file:
----------------------
#try.pl

use Inline (C => 'test/s1.c');
use Inline (C => 'test/s2.c');
use Inline C => <<'EOC';
void dumb3() {
printf("Hello from main\n");
}

EOC

dumb1();
dumb2();
dumb3();
__END__
----------------------

The first C file:
----------------------
/* test/s1.c */

void dumb1() {
printf("Hello from s1.c\n");
}
----------------------

The second C file:
----------------------
/* test/s2.c */

void dumb2() {
printf("Hello from s2.c\n");
}
----------------------

Running 'perl try.pl' produces:

Hello from s1.c
Hello from s2.c
Hello from main

Caveat:
1) The source file ('s1.c') needs to be in a separate directory from
'try.pl'. (Or maybe it just needs to be in a directory other than the
cwd - haven't tested.)

I would think that the 2 opening Config statements in the perl script
could be combined into one - but I lost interest after my first 2
attempts to do just that failed :)

Hope there's something there that helps you find a satisfactory solution.

Incidentally, passing an AV* as an arg to an inline function won't work
on perl 5.6.0/1. (Just in case it matters.)

Cheers,
Rob
 
S

Sisyphus

Sisyphus said:
Caveat:
1) The source file ('s1.c') needs to be in a separate directory from
'try.pl'. (Or maybe it just needs to be in a directory other than the
cwd - haven't tested.)

'perldoc inline-faq' tells us that the C source files must be in a
subdirectory of the perl script.

Cheers,
Rob
 
B

Brian K. Michalk

Thank you so much. Who would have thought about the subdirectory
thing. I guess it's symlinks for me.

Strange about the AV* thing. I'm doing it for execution efficiency
.... why else would I use C? Perl -v says I'm using 5.6.1. Is there
some documentation on this "feature"?
 
S

Sisyphus

Brian said:
Thank you so much. Who would have thought about the subdirectory
thing. I guess it's symlinks for me.

Strange about the AV* thing. I'm doing it for execution efficiency
... why else would I use C? Perl -v says I'm using 5.6.1. Is there
some documentation on this "feature"?

I've always had to use the Stack to pass arrays to Inline C. (See
'perldoc Inline::C-Cookbook' on how to pass varying size argument
lists.) Afaik it wasn't until 5.8 that you could pass AV*s, courtesy of
a fixed typemap. But if you're experiencing no problem .... maybe you've
got a 5.6 with a fixed typemap.

(I'll check my facts, too - and report back if I've got it wrong.)

Cheers,
Rob
 
S

Sisyphus

Sisyphus said:
I've always had to use the Stack to pass arrays to Inline C. (See
'perldoc Inline::C-Cookbook' on how to pass varying size argument
lists.) Afaik it wasn't until 5.8 that you could pass AV*s, courtesy of
a fixed typemap. But if you're experiencing no problem .... maybe you've
got a 5.6 with a fixed typemap.

(I'll check my facts, too - and report back if I've got it wrong.)

I tried the following (transcribed) code:

use Inline C => <<'EOC';
SV ** elem;
int ret;

int dumb(AV* arref) {
elem = av_fetch(arref, 2, 0);
ret = SvIV(*elem);
return ret;
}

EOC

print dumb([7..15]); #line 16

On 5.6.1 I get:
'arref is not of type AVPtr at try.pl line 16'.

On 5.8.0 I get (the correct response):
9

I've also seen it stated in 'Extending and Embedding Perl' by Jenness
and Cousins (footnote on page 243) that you can't pass AV*s to Inline
with pre-5.8 versions of perl.

Interesting that it's not posing any problems for you - and half your
luck :)

Incidentally, I've not detected any speed advantage using an AV* instead
of the stack - but far be it for me to say whether that's simply because
I haven't looked properly, or whether it's because there's little
difference in efficiency between the 2 methods :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top