How to pass an array from perl to inline C ++?

I can’t say if this is a mistake or what.

The following code works with Inline::C , but not Inline::CPP

 #!/usr/bin/perl use warnings; use Inline C; my @array = (1..10); print findAvLen(\@array), "\n"; __END__ __C__ int findAvLen(AV* arrayIn) { return av_len(arrayIn); } 

The above works fine, but replace C with CPP and I get the error Can't locate auto/main/findAvLen.al in @INC...

I can use other C ++ inline code. For example, you can pass a list of variables into inline code with an ellipsis, since they are in this example , but I wonder why AV * does not work! For example, I want to use a routine to convert perl arrays passed in C ++ to vectors, for example. void perl2vector(AV* ar, std::vector<T> &v) {...} , instead of inserting code to perform such a conversion into every C ++ function, I write that takes an array argument. How can I use this example syntax to pass a perl array to such a converter?


This seems like an error, but at the same time, uesp discovered a workaround:

 int findAvLen(SV* arrRef) { AV * arr = MUTABLE_AV(SvRV(arrRef)); return av_len(arr); } 

arr now equivalent to arrayIn specified in the above example.

+6
source share
1 answer

This is similar to this Perl bug that exists in 5.10.0 and should have been fixed in version 5.10.29. If you are using 5.10.0-28, try updating. If you are not using these versions and still get the error, you can try to do what is mentioned in this forum post by changing AV to SV .

+4
source

Source: https://habr.com/ru/post/912421/


All Articles