|No such thing as a small change|
Re: Extending perl with C dynamic library.by BrowserUk (Pope)
|on Aug 16, 2013 at 23:20 UTC||Need Help??|
Here is what happens when you write a small pure C function and build it with Inline::C.
Start with the C function and the Inline::C support structure:
When you run that, Inline::C wraps that C function up with an XS function to call it into a .XS file which gets XS-preprocessed to a .c file which is what gets compiled to create the dynamic llibrary (.dll/.so). Here I've thrown away a lot of boilerplate code to make it easier to see what is going on. The resultant .c file contains 3 functions.
The original C function:
A wrapper function that unpacks the input arguments from their Perl variables; calls the C function with the extracted values; and then wraps up the return value from the C function into a Perl variable for returning to the Perl code:
And finally, it adds a bootstrap function who purpose is two-fold:
So, you should be able to see from this that you cannot avoid the XS wrapper functions because the C code would not know what to do with perl variables. And you cannot do away with the 'boot_module' entrypoint because perl would not know what functions are exported by the .dll/.so.
I strongly urge you to play with Inline::C and explore the files it creates. You'll learn far more, far more quickly that banging your head on the wall of ignorance trying to go your own way.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.