summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-05-14 09:38:43 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-05-14 09:38:43 +0000
commit88037a85d6a4b105a485a30b7ae673eff41a9098 (patch)
treec2c89faaa65003520ecc71336430ad11558a3696
parent7aa207d6d833e60be59e41514013c4c54b091533 (diff)
downloadperl-88037a85d6a4b105a485a30b7ae673eff41a9098.tar.gz
Add new dUNDERBAR and UNDERBAR macros, to help XS writers to
access the $_ variable, even when there is a lexical one in scope. p4raw-id: //depot/perl@22819
-rw-r--r--XSUB.h13
-rw-r--r--pod/perlapi.pod18
2 files changed, 31 insertions, 0 deletions
diff --git a/XSUB.h b/XSUB.h
index b4c241aa3e..a1e48dd47c 100644
--- a/XSUB.h
+++ b/XSUB.h
@@ -67,6 +67,14 @@ This is usually handled automatically by C<xsubpp>.
Sets up the C<ix> variable for an XSUB which has aliases. This is usually
handled automatically by C<xsubpp>.
+=for apidoc Ams||dUNDERBAR
+Sets up the C<padoff_du> variable for an XSUB that wishes to use
+C<UNDERBAR>.
+
+=for apidoc AmU||UNDERBAR
+The SV* corresponding to the $_ variable. Works even if there
+is a lexical $_ in scope.
+
=cut
*/
@@ -106,6 +114,11 @@ handled automatically by C<xsubpp>.
#define XSINTERFACE_FUNC_SET(cv,f) \
CvXSUBANY(cv).any_dxptr = (void (*) (pTHX_ void*))(f)
+#define dUNDERBAR I32 padoff_du = pad_findmy("$_")
+#define UNDERBAR ((padoff_du == NOT_IN_PAD \
+ || PAD_COMPNAME_FLAGS(padoff_du) & SVpad_OUR) \
+ ? DEFSV : PAD_SVl(padoff_du))
+
/* Simple macros to put new mortal values onto the stack. */
/* Typically used to return values from XS functions. */
diff --git a/pod/perlapi.pod b/pod/perlapi.pod
index b0381fe1e4..27daa64407 100644
--- a/pod/perlapi.pod
+++ b/pod/perlapi.pod
@@ -5418,6 +5418,16 @@ This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
=for hackers
Found in file XSUB.h
+=item dUNDERBAR
+
+Sets up the C<padoff_du> variable for an XSUB that wishes to use
+C<UNDERBAR>.
+
+ dUNDERBAR;
+
+=for hackers
+Found in file XSUB.h
+
=item dXSARGS
Sets up stack and mark pointers for an XSUB, calling dSP and dMARK.
@@ -5498,6 +5508,14 @@ L<perlxs/"Using XS With C++">.
=for hackers
Found in file XSUB.h
+=item UNDERBAR
+
+The SV* corresponding to the $_ variable. Works even if there
+is a lexical $_ in scope.
+
+=for hackers
+Found in file XSUB.h
+
=item XS
Macro to declare an XSUB and its C parameter list. This is handled by