Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Problem trying to use Device::USB

by gwadej (Chaplain)
on Jul 22, 2010 at 03:52 UTC ( #850762=note: print w/replies, xml ) Need Help??

in reply to Problem trying to use Device::USB

I've just had to revisit the code after applying the patch that resulted from this conversation. I wanted to update this discussion in case someone else had a similar issue.

The patched code was resulting in segfaults for some people. After reading the discussion and looking at the code more carefully, I realized that the C code was using void* in two different situations and that the reported type problem was only an issue for one of them.

In C, it is not unusual to use void* for both an opaque pointer and for a generic buffer. However, when passing these through Inline::C, we get (and need) very different behaviors.

All of the opaque pointer cases needed to remain void*, since the Perl code can never look inside the structure to inspect it directly. More importantly, we need to be returning the exact same pointer, not a different pointer with the same data, so the conversion to/from an IV makes sense here.

On the other hand, any generic buffer that we are expecting the Perl code to inspect must be changed to a char* for the reasons outlined in this thread.

Unfortunately, the submitted patch confused these uses in the opposite direction of my original mistake. Thanks to all of you for helping me understand this aspect of Inline::C somewhat better.

G. Wade

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://850762]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-01-23 04:27 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (238 votes). Check out past polls.