develooper Front page | perl.perl5.porters | Postings from April 2003

CvFILE for constant subs

Thread Next
Stephen McCamant
April 6, 2003 13:39
CvFILE for constant subs
Message ID:
During the 5.7.x development cycle, constant subroutines were changed
to be XSUBs, making them more memory efficient. Normally when XSUBs
are created, their CvFILE is set to the name of the C source file in
which they were defined; apparently following that logic, the CvFILE
for all constant subroutines was set to "op.c".

It would seem more logical to me for the CvFILE to be set to the name
of the perl file in which the subroutine was defined, since the
XSUBness is an implementation detail. The attached patch makes that
change, and seems to pass the test suite, though I'm not sure if it
should have a savepv() or something else to make sure the string
sticks around long enough.

I noticed this because B::Deparse uses CvFILE to tell which
subroutines to print, and constant subs were disappearing. It looks
like the right file information is available in the GV corresponding
to the CV, though, so Deparse can be fixed even without this change.

 -- Stephen

--- op.c.orig	2003-04-05 02:53:54.000000000 -0500
+++ op.c	2003-04-05 02:55:30.000000000 -0500
@@ -4273,7 +4273,7 @@
-    cv = newXS(name, const_sv_xsub, __FILE__);
+    cv = newXS(name, const_sv_xsub, CopFILE(PL_curcop));
     CvXSUBANY(cv).any_ptr = sv;
     sv_setpv((SV*)cv, "");  /* prototype is "" */

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About