Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Complex extensions in C

Reply
Thread Tools

Complex extensions in C

 
 
arne.muller@gmail.com
Guest
Posts: n/a
 
      09-16-2006
Hello,

I'm looking for some resources (books, web-sites, docs ...) on how to
write complex perl extensions in C. I've read the perlxstut, but still
don't understand how to convert complex types.

Specificly, my C-routine needs a pointer to a structure, some members
of this structure are pointers to type double arrays. On the perl side
this structure is an object. The return value of the C function is a
different type of structure, but again containing pointers to array (on
the perl side this is an object).

Maybe you can point out some places on the web or news grou articles (I
didn't find much!).

greetings,

Arne

 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      09-16-2006
<> wrote in comp.lang.perl.misc:
> Hello,
>
> I'm looking for some resources (books, web-sites, docs ...) on how to
> write complex perl extensions in C. I've read the perlxstut, but still
> don't understand how to convert complex types.
>
> Specificly, my C-routine needs a pointer to a structure, some members
> of this structure are pointers to type double arrays. On the perl side
> this structure is an object. The return value of the C function is a
> different type of structure, but again containing pointers to array (on
> the perl side this is an object).


So you want to translate Perl objects (which presumably contain lists of
numbers) into C structs for consumption by XS routines. The basic
method is to use pack() to build the struct in a string. You pass the
string to the XS routine as such and cast it to a (pointer to) the type
of struct you have built. If you have got it right (which will be
non-trivial), you'll find a workable struct in your XS program.

You'll have to use the cumbersome "p" template to create pointers
from one part of the string to another.

Anno

> Maybe you can point out some places on the web or news grou articles (I
> didn't find much!).
>
> greetings,
>
> Arne
>



 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      09-16-2006

Quoth :
> <> wrote in comp.lang.perl.misc:
> > Hello,
> >
> > I'm looking for some resources (books, web-sites, docs ...) on how to
> > write complex perl extensions in C. I've read the perlxstut, but still
> > don't understand how to convert complex types.
> >
> > Specificly, my C-routine needs a pointer to a structure, some members
> > of this structure are pointers to type double arrays. On the perl side
> > this structure is an object. The return value of the C function is a
> > different type of structure, but again containing pointers to array (on
> > the perl side this is an object).

>
> So you want to translate Perl objects (which presumably contain lists of
> numbers) into C structs for consumption by XS routines. The basic
> method is to use pack() to build the struct in a string. You pass the
> string to the XS routine as such and cast it to a (pointer to) the type
> of struct you have built. If you have got it right (which will be
> non-trivial), you'll find a workable struct in your XS program.
>
> You'll have to use the cumbersome "p" template to create pointers
> from one part of the string to another.


Note that there are nontrivial issues regarding struct packing and the
like (you will likely need a little C program to construct the pack
template for you using offsetof). You can also pass a hash to an XS
routine that then builds the struct by pulling the members out of the
hash in C.

It may be easier to make the Perl side properly OO, or implement a tied
hash/array, and keep the data in 'C format' all the time.

Ben

--
The cosmos, at best, is like a rubbish heap scattered at random.
Heraclitus

 
Reply With Quote
 
Sisyphus
Guest
Posts: n/a
 
      09-17-2006

<> wrote in message
..
..
>
> Specificly, my C-routine needs a pointer to a structure, some members
> of this structure are pointers to type double arrays. On the perl side
> this structure is an object.


For some basics on objects see
http://search.cpan.org/~ingy/Inline-...riented_Inline .
There might be some other basic information on the same page that's useful,
too.

Cheers,
Rob


 
Reply With Quote
 
arne.muller@gmail.com
Guest
Posts: n/a
 
      09-17-2006

wrote:
> wrote:
> > Hello,
> >
> > I'm looking for some resources (books, web-sites, docs ...) on how to
> > write complex perl extensions in C. I've read the perlxstut, but still
> > don't understand how to convert complex types.
> >
> > Specificly, my C-routine needs a pointer to a structure, some members
> > of this structure are pointers to type double arrays. On the perl side
> > this structure is an object.

>
> A Perl object or merely an opaque object held in Perl? I.E. does Perl have
> to do anything with it, other than just pass the root pointer back into C?


Well, this should be a real perl object. The part that I'd like to
implement in C is just part of a larger application in which this
object lives ...

Arne

> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB


 
Reply With Quote
 
arne.muller@gmail.com
Guest
Posts: n/a
 
      09-17-2006
Ben Morrow wrote:
> Quoth :
> > <> wrote in comp.lang.perl.misc:
> > > Hello,
> > >
> > > I'm looking for some resources (books, web-sites, docs ...) on how to
> > > write complex perl extensions in C. I've read the perlxstut, but still
> > > don't understand how to convert complex types.
> > >
> > > Specificly, my C-routine needs a pointer to a structure, some members
> > > of this structure are pointers to type double arrays. On the perl side
> > > this structure is an object. The return value of the C function is a
> > > different type of structure, but again containing pointers to array (on
> > > the perl side this is an object).

> >
> > So you want to translate Perl objects (which presumably contain lists of
> > numbers) into C structs for consumption by XS routines. The basic
> > method is to use pack() to build the struct in a string. You pass the
> > string to the XS routine as such and cast it to a (pointer to) the type
> > of struct you have built. If you have got it right (which will be
> > non-trivial), you'll find a workable struct in your XS program.
> >
> > You'll have to use the cumbersome "p" template to create pointers
> > from one part of the string to another.

>
> Note that there are nontrivial issues regarding struct packing and the
> like (you will likely need a little C program to construct the pack
> template for you using offsetof). You can also pass a hash to an XS
> routine that then builds the struct by pulling the members out of the
> hash in C.
>
> It may be easier to make the Perl side properly OO, or implement a tied
> hash/array, and keep the data in 'C format' all the time.


Maybe it's easier to write a wrapper routine in perl that takes the
perl object, extracts it's attributes (scalars and arrays) and passes
it to a C-wrapper routine which re-creates the proper C-structs from
it's function arguments. Finally the C-routine that takes athe pointe
rargument is called from this wrapper. This means the perl object gets
copied, and there's a perl object and a C struct. This may just be fine
for me.

regards,

Arne

> Ben
>
> --
> The cosmos, at best, is like a rubbish heap scattered at random.
> Heraclitus
>


 
Reply With Quote
 
Peter Scott
Guest
Posts: n/a
 
      09-18-2006
On Sat, 16 Sep 2006 07:32:26 -0700, arne.muller wrote:
> I'm looking for some resources (books, web-sites, docs ...) on how to
> write complex perl extensions in C. I've read the perlxstut, but still
> don't understand how to convert complex types.


Try
http://www.amazon.com/Extending-Embe.../dp/1930110820

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How complex is complex? Kottiyath Python 22 03-28-2009 10:11 PM
wsdl2java: method parameter a complex type that extends another complex type Robert Mark Bram Java 0 02-04-2007 10:06 AM
Unable to access extensions menu or add extensions (I've tried past suggestions) nospam@spam.com Firefox 8 12-01-2005 01:33 AM
[XML Schema] Content type of complex type definition with complex content Stanimir Stamenkov XML 2 10-25-2005 10:16 AM
For expert on complex loops (reposted) - complex looping problem news.amnet.net.au Java 1 04-13-2004 07:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57