A clearer implementation of B::SV::object_2svref()
authorNicholas Clark <nick@ccl4.org>
Fri, 29 Oct 2010 09:59:23 +0000 (10:59 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 29 Oct 2010 09:59:23 +0000 (10:59 +0100)
The same number of lines of code, but it avoids using 2 #defines simply to
take advantage of typemap entries, which the reader may not be familiar with.

ext/B/B.xs

index 1b93e7d6056515f948dee9f71143a9d77886e203..6f1e17ec035fbc3c5715a9bdafa764b7942de519 100644 (file)
@@ -1293,13 +1293,13 @@ REFCNT(sv)
     OUTPUT:
        RETVAL
 
-#define object_2svref(sv)      sv
-#define SVREF SV *
-       
-SVREF
+void
 object_2svref(sv)
        B::SV   sv
-
+    PPCODE:
+       ST(0) = sv_2mortal(newRV(sv));
+       XSRETURN(1);
+       
 MODULE = B     PACKAGE = B::IV         PREFIX = Sv
 
 IV