develooper Front page | perl.perl5.porters | Postings from July 2012

[PATCH] fix (m)XPUSH* usage in perlxstut

Thread Next
From:
Steffen Schwigon
Date:
July 2, 2012 07:27
Subject:
[PATCH] fix (m)XPUSH* usage in perlxstut
Message ID:
87vci65jcw.fsf@renormalist.net
From 6f3791045ad20341ac83e57537edc532a839947c Mon Sep 17 00:00:00 2001
From: Steffen Schwigon <ss5@renormalist.net>
Date: Mon, 2 Jul 2012 15:53:06 +0200
Subject: [PATCH] perlxstut.pod: fix (m)XPUSH* usage

Using the plain XPUSH* macros triggers

  error: 'targ' undeclared

Since commit d82b684c it is recommended to use mXPUSH* anyway
which does not use TARG and takes care of declaring mortality.

Adapt perlxstut to those changes.
---
 dist/ExtUtils-ParseXS/lib/perlxstut.pod |   23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/dist/ExtUtils-ParseXS/lib/perlxstut.pod b/dist/ExtUtils-ParseXS/lib/perlxstut.pod
index 93c1bfb..a38da5b 100644
--- a/dist/ExtUtils-ParseXS/lib/perlxstut.pod
+++ b/dist/ExtUtils-ParseXS/lib/perlxstut.pod
@@ -977,15 +977,15 @@ Mytest.xs:
 	    PPCODE:
 		i = statfs(path, &buf);
 		if (i == 0) {
-			XPUSHs(sv_2mortal(newSVnv(buf.f_bavail)));
-			XPUSHs(sv_2mortal(newSVnv(buf.f_bfree)));
-			XPUSHs(sv_2mortal(newSVnv(buf.f_blocks)));
-			XPUSHs(sv_2mortal(newSVnv(buf.f_bsize)));
-			XPUSHs(sv_2mortal(newSVnv(buf.f_ffree)));
-			XPUSHs(sv_2mortal(newSVnv(buf.f_files)));
-			XPUSHs(sv_2mortal(newSVnv(buf.f_type)));
+			mXPUSHs(newSVnv(buf.f_bavail));
+			mXPUSHs(newSVnv(buf.f_bfree));
+			mXPUSHs(newSVnv(buf.f_blocks));
+			mXPUSHs(newSVnv(buf.f_bsize));
+			mXPUSHs(newSVnv(buf.f_ffree));
+			mXPUSHs(newSVnv(buf.f_files));
+			mXPUSHs(newSVnv(buf.f_type));
 		} else {
-			XPUSHs(sv_2mortal(newSVnv(errno)));
+			mXPUSHs(newSVnv(errno));
 		}
 
 You'll also need to add the following code to the top of the .xs file, just
@@ -1032,19 +1032,20 @@ put on the argument stack by ourselves.
 =item *
 
 When we want to place values to be returned to the caller onto the stack,
-we use the series of macros that begin with "XPUSH".  There are five
+we use the series of macros that begin with "mXPUSH".  There are five
 different versions, for placing integers, unsigned integers, doubles,
 strings, and Perl scalars on the stack.  In our example, we placed a
 Perl scalar onto the stack.  (In fact this is the only macro which
 can be used to return multiple values.)
 
-The XPUSH* macros will automatically extend the return stack to prevent
+The *XPUSH* macros will automatically extend the return stack to prevent
 it from being overrun.  You push values onto the stack in the order you
 want them seen by the calling program.
 
 =item *
 
-The values pushed onto the return stack of the XSUB are actually mortal SV's.
+The leading "m" in "mXPUSH*" stands for "mortal". By this
+the values pushed onto the return stack of the XSUB are actually mortal SV's.
 They are made mortal so that once the values are copied by the calling
 program, the SV's that held the returned values can be deallocated.
 If they were not mortal, then they would continue to exist after the XSUB
-- 
1.7.10


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About