-
-
17 Sep 2009 23:21:27 UTC
- Distribution: B-Hooks-XSUB-CallAsOp
- Module version: 0.02
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (1)
- Testers (500 / 15 / 11)
- Kwalitee
Bus factor: 1- 100.00% Coverage
- License: perl_5
- Perl: v5.8.1
- Activity
24 month- Tools
- Download (59.67KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors- Yuval Kogman, Florian Ragwitz
- Dependencies
- parent
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
Take me over?
The maintainer of this distribution is looking for someone to take over! If you're interested then please contact them via email.NAME
B::Hooks::XSUB::CallAsOp - Invoke code from an XSUB in opcode context
SYNOPSIS
#include "hook_xsub_callasop.h" static TRAMPOLINE_HOOK(foo) { printf("IM IN UR CALLER MUNGING UR STACK\n"); return NORMAL; /* you must always return like from a PP function, see also the RETURN macro */ /* or you can also delegate: */ return PL_ppaddr[OP_FOO](aTHX); } MODULE = Some::XS PACKAGE = Some::XS void foo () PPCODE: TRAMPOLINE(foo); # later, in Perl land... # the trampoline hook is invoked in an opcode context, instead of as an XSUB Some::XS::foo();
USAGE
This module requires ExtUtils::Depends to be used in your XS modules.
See B::Utils for an explanation.
MACROS
- TRAMPOLINE_HOOK(hook_name)
-
Declares a function with PP's calling conventions. It's the same as perl's own PP macro but without the Perl_ prefix (you can also use it for declaring a function pointer)
- TRAMPOLINE(hook)
-
Given a function pointer
hook
, trampoline to it on the next PL_op dispatch.This will
PUTBACK
, invokeb_hooks_xsub_callasop_setup_trampoline
, and then return from the current XSUB with no value. - TRAMPOLINE_SAVE_OP
-
Save the value of
PL_op
.Must be called before the
TRAMPOLINE
macro, and followed byTRAMPOLINE_RESTORE_OP
- TRAMPOLINE_RESTORE_OP
-
Must be called inside your
TRAMPOLINE_HOOK
to setPL_op
to what it was just before the trampiline.The
op_next
of the restored op and the trampoline op are the same, so you should still usereturn NORMAL
. - TRAMPOLINE_SAVE_ARGS
-
Saves the args given to the xsub in a temporary buffer.
This must be called before the
TRAMPOLINE
macro, and followed byTRAMPOLINE_RESTORE_ARGS
.Requires
ax
anditems
to be defined, callsSPAGAIN
. - TRAMPOLINE_RESTORE_ARGS
-
Appends the args from the buffer back to the stack, and then invokes
SPAGAIN
.Does not modify ax, you need to add a mark yourself and use it if you need it.
TYPES
- b_hooks_xsub_callasop_hook_t
-
A function pointer type describing a Perl push/pop function:
OP *(*foo) (pTHX)
FUNCTION
- void b_hooks_xsub_callasop_setup_trampoline (pTHX_ b_hooks_xsub_callasop_setup_trampoline)
-
The underlying implementation of the
TRAMPOLINE
macro.Using the macro is reccomended.
VERSION CONTROL
http://github.com/nothingmuch/b-hooks-xsub-callasop
AUTHOR
Yuval Kogman, Florian Ragwitz
COPYRIGHT & LICENSE
Copyright (c) 2009 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install B::Hooks::XSUB::CallAsOp, copy and paste the appropriate command in to your terminal.
cpanm B::Hooks::XSUB::CallAsOp
perl -MCPAN -e shell install B::Hooks::XSUB::CallAsOp
For more information on module installation, please visit the detailed CPAN module installation guide.