Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: perl->c->perl

by philcrow (Priest)
on Dec 12, 2005 at 17:43 UTC ( [id://516071]=note: print w/replies, xml ) Need Help??


in reply to perl->c->perl

This may seem completely unrelated, but what you are attempting would almost certainly be easier with Inline::C which handles all the details you are describing, but with a simple API.

Phil

Replies are listed 'Best First'.
Re^2: perl->c->perl
by jpollack (Novice) on Dec 12, 2005 at 18:02 UTC
    I don't think that would be possible. As I understand, Inline::C is useful for calling C functions from perl, but how would you call a function that requires a function pointer as an argument? For instance, how would I write a callback function using Inline::C? The libraries register_callback routine needs a (*)(void *, void*, unsigned long, Timestamp, void *). What function pointer could I then pass it?

      Inline::C lets you write plain C functions too, and to callback from C to Perl you need a plain C function that calls one of the "call into Perl" subroutines. So callbacks from C to Perl are just as possible (and easier to write) with Inline::C instead of XS.

      The trick is getting at context. If you are lucky, then the callback interface allows you to have a context indicator passed to the callback. If not, then things get ratherr complicated...

      Unfortunately, I've run out of time for now...

      - tye        

        Thanks for the advice.

        I tried using Inline::C, but it's still not quite working. The wrappers around a few of the library routines (initialization, for example) do appear to be working correctly, however, it crashes whenever running the C callback function. In the C callback function, what it should be doing is copying the necessary data to perl variables, doing a "perl_call_sv" to call the user specified perl callback function, then copying the data back from perl variables. What's happening though is that the program crashes whenever I try to do anything in the C language callback function.

        No matter what code I put in the C callback, I get ``unhandled exception...: access violation reading location...''

        I can confirm that the callback function is actually being called because I've made a counter variable that increments each time its run. Upon close, I have the program print the contents, and it looks like its being run the right number of times. However, anything more complicated than that and it crashes.

        Any thoughts?

Re^2: perl->c->perl
by Intrepid (Deacon) on Dec 12, 2005 at 17:57 UTC

    Inline::C is brilliant and useful and is not a substitute for XS, nor is it magical. It is a means of having a number of steps which used to be performed manually or semi-manually by the user, done automatically behind the scenes. My impression, having used Inline::C a bit, is that what the OP wants to do is something that requires real manual XS programming.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://516071]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-03-29 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found