Re: Using vec() from XS
by salva (Canon) on Sep 23, 2008 at 13:48 UTC
|
Some ways to do it:
- Write a wrapper function in Perl and call it.
- There should be a way to create a sequence of OPs (containing the required pp_vec) and run it.
- Copy & paste the source code for pp_vec and its helpers into your code changing the interface to suit your needs.
| [reply] |
|
| [reply] |
|
| [reply] [d/l] [select] |
|
|
|
Most likely, you already know that Perl is compiled to a tree of ops. pp_vec is one such op type -- corresponding to the Perl vec() function.
Now, you could create op structures from XS and inject them into the running program. B::Generate does stuff like that.
The one example I'm aware of where this actually works well is List::Util::shuffle. Instead of repeating what's happening there, check for yourself: List::Util XS code.
I tried to do something similar in order to get caller() in XS, but that experiment mostly failed. I would not suggest going down that route.
Cheers,
Steffen
| [reply] |
Re: Using vec() from XS
by ysth (Canon) on Sep 23, 2008 at 15:37 UTC
|
Just use sv_insert instead?
| [reply] |
|
I'm not sure how that helps? vec doesn't do any inserts, just update in-place or grow if the offest calculates beyond the current end of string.
It isn't too hard to re-code the math and bit-twiddling, the main problem is getting the memory management right. As vec does everything I need (and more), it would have been nice to find a way to re-use that code without having to either c&p or callback to perl in order to do it.
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.
| [reply] |
|
sv_setuv(TARG, do_vecget(src, offset, size));
which should give you what you want.
| [reply] [d/l] |
|