New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
call_sv's docs are misleading #13481
Comments
From @bulk88Created by @bulk88call_sv's docs currently say --------------------------------------------------------------- Performs a callback to the Perl sub whose name is in the SV. See =cut That says it is exactly equivalent to "call_pv(SvPV_nolen(sv),0);" perlcall says "This allows you to specify the Perl subroutine to be So my question is, what is the all inclusive list of what call_sv can be I put a warn on SvTYPE into XS-APITest, ------------------------------------------------------ Test Summary Report C:\p519\src\ext\XS-APItest> I got types as far as I can see. 1 (SVt_IV, probably these are refs to The pod needs fixes. I'm still researching whether to add something to Perl Info
|
From @ikegamiOn Thu, Dec 19, 2013 at 4:47 AM, bulk88 <perlbug-followup@perl.org> wrote:
[Assumes neither G_METHOD nor G_METHOD_NAMED was provided as a flag.] A comment in the source says "May be called with any of a CV, a GV, or an But it also accepts a code reference. Specifically, when neither G_METHOD - AV*, HV* and undef are errors. Note: "GV*" is defined as: SvTYPE(sv) == SVt_PVGV or SvTYPE(sv) == SVt_PVLV |
The RT System itself - Status changed from 'new' to 'open' |
From zefram@fysh.orgEric Brine wrote:
Freaky: $ perl -lwe '1->(); print "OK"' -zefram |
From @bulk88On Thu Dec 19 06:26:12 2013, ikegami@adaelis.com wrote:
Not testing this.
HV and undef are tested. AV should be pointless to test.
Tested.
Tested.
Tested.
IDK how to get a LV/isGV_with_GP. APITest patch attached. Note, some of things being tested are not (and I don't think they should) be public API or documented. If some of the tests are broken in the future, the tests should be fixed or removed, not the future code. -- |
From @bulk880001-test-various-types-of-SVs-with-call_sv.patchFrom 56fb4c381666bfa4f5db22cfd063056f8433b739 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Sun, 22 Dec 2013 00:45:35 -0500
Subject: [PATCH] test various types of SVs with call_sv
call_sv takes RVs, PVs, CVs, GVs, and an immortal. This isn't well
documented. CVs and immortals can't, or can't easily be tested from
pure perl, so do it from XS. SVt_PVLV with isGV_with_GP is one thing
call_sv takes but is not tested by this commit. Part of [perl #120826] .
---
ext/XS-APItest/APItest.pm | 2 +-
ext/XS-APItest/APItest.xs | 77 +++++++++++++++++++++++++++++++++++++++++++++
ext/XS-APItest/t/call.t | 9 +++++-
3 files changed, 86 insertions(+), 2 deletions(-)
diff --git a/ext/XS-APItest/APItest.pm b/ext/XS-APItest/APItest.pm
index 0a07d0e..e454b01 100644
--- a/ext/XS-APItest/APItest.pm
+++ b/ext/XS-APItest/APItest.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Carp;
-our $VERSION = '0.58';
+our $VERSION = '0.59';
require XSLoader;
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs
index f877047..b2ca380 100644
--- a/ext/XS-APItest/APItest.xs
+++ b/ext/XS-APItest/APItest.xs
@@ -1942,6 +1942,83 @@ mxpushu()
mXPUSHu(3);
XSRETURN(3);
+# indent me todo
+
+void
+call_sv_C()
+PREINIT:
+ CV * i_sub;
+ GV * i_gv;
+ I32 retcnt;
+ SV * errsv;
+ char * errstr;
+ SV * miscsv = sv_newmortal();
+ HV * hv = (HV*)sv_2mortal((SV*)newHV());
+CODE:
+ i_sub = get_cv("i", 0);
+ PUSHMARK(SP);
+ /* PUTBACK not needed since this sub was called with 0 args, and is calling
+ 0 args, so global SP doesn't need to be moved before a call_* */
+ retcnt = call_sv((SV*)i_sub, 0); /* try a CV* */
+ SPAGAIN;
+ SP -= retcnt; /* dont care about return count, wipe everything off */
+ sv_setpvs(miscsv, "i");
+ PUSHMARK(SP);
+ retcnt = call_sv(miscsv, 0); /* try a PV */
+ SPAGAIN;
+ SP -= retcnt;
+ /* no add and SVt_NULL are intentional, sub i should be defined already */
+ i_gv = gv_fetchpvn_flags("i", sizeof("i")-1, 0, SVt_NULL);
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_gv, 0); /* try a GV* */
+ SPAGAIN;
+ SP -= retcnt;
+ /* the tests below are not declaring this being public API behavior,
+ only current internal behavior, these tests can be changed in the
+ future if necessery */
+ PUSHMARK(SP);
+ retcnt = call_sv(&PL_sv_yes, 0); /* does nothing */
+ SPAGAIN;
+ SP -= retcnt;
+ PUSHMARK(SP);
+ retcnt = call_sv(&PL_sv_no, G_EVAL);
+ SPAGAIN;
+ SP -= retcnt;
+ errsv = ERRSV;
+ errstr = SvPV_nolen(errsv);
+ if(strnEQ(errstr, "Undefined subroutine &main:: called at",
+ sizeof("Undefined subroutine &main:: called at") - 1)) {
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
+ SPAGAIN;
+ SP -= retcnt;
+ }
+ PUSHMARK(SP);
+ retcnt = call_sv(&PL_sv_undef, G_EVAL);
+ SPAGAIN;
+ SP -= retcnt;
+ errsv = ERRSV;
+ errstr = SvPV_nolen(errsv);
+ if(strnEQ(errstr, "Can't use an undefined value as a subroutine reference at",
+ sizeof("Can't use an undefined value as a subroutine reference at") - 1)) {
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
+ SPAGAIN;
+ SP -= retcnt;
+ }
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)hv, G_EVAL);
+ SPAGAIN;
+ SP -= retcnt;
+ errsv = ERRSV;
+ errstr = SvPV_nolen(errsv);
+ if(strnEQ(errstr, "Not a CODE reference at",
+ sizeof("Not a CODE reference at") - 1)) {
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
+ SPAGAIN;
+ SP -= retcnt;
+ }
void
call_sv(sv, flags, ...)
diff --git a/ext/XS-APItest/t/call.t b/ext/XS-APItest/t/call.t
index 7ff9933..54f45ec 100644
--- a/ext/XS-APItest/t/call.t
+++ b/ext/XS-APItest/t/call.t
@@ -11,7 +11,7 @@ use strict;
BEGIN {
require '../../t/test.pl';
- plan(436);
+ plan(437);
use_ok('XS::APItest')
};
@@ -28,6 +28,13 @@ sub f {
@_, defined wantarray ? wantarray ? 'x' : 'y' : 'z';
}
+our $call_sv_count = 0;
+sub i {
+ $call_sv_count++;
+}
+call_sv_C();
+is($call_sv_count, 6, "call_sv_C passes");
+
sub d {
die "its_dead_jim\n";
}
--
1.7.9.msysgit.0
|
From @bulk88On Sat Dec 21 21:53:42 2013, bulk88 wrote:
Stray leftover comment was in the last patch, new patch attached. -- |
From @bulk880001-test-various-types-of-SVs-with-call_sv.patchFrom f98fa5e1bf43e0fe8fd05a38a40ff9ce4da5c2fa Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Sun, 22 Dec 2013 00:54:14 -0500
Subject: [PATCH] test various types of SVs with call_sv
call_sv takes RVs, PVs, CVs, GVs, and an immortal. This isn't well
documented. CVs and immortals can't, or can't easily be tested from
pure perl, so do it from XS. SVt_PVLV with isGV_with_GP is one thing
call_sv takes but is not tested by this commit. Part of [perl #120826] .
---
ext/XS-APItest/APItest.pm | 2 +-
ext/XS-APItest/APItest.xs | 75 +++++++++++++++++++++++++++++++++++++++++++++
ext/XS-APItest/t/call.t | 9 +++++-
3 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/ext/XS-APItest/APItest.pm b/ext/XS-APItest/APItest.pm
index 0a07d0e..e454b01 100644
--- a/ext/XS-APItest/APItest.pm
+++ b/ext/XS-APItest/APItest.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Carp;
-our $VERSION = '0.58';
+our $VERSION = '0.59';
require XSLoader;
diff --git a/ext/XS-APItest/APItest.xs b/ext/XS-APItest/APItest.xs
index f877047..e352195 100644
--- a/ext/XS-APItest/APItest.xs
+++ b/ext/XS-APItest/APItest.xs
@@ -1942,6 +1942,81 @@ mxpushu()
mXPUSHu(3);
XSRETURN(3);
+void
+call_sv_C()
+PREINIT:
+ CV * i_sub;
+ GV * i_gv;
+ I32 retcnt;
+ SV * errsv;
+ char * errstr;
+ SV * miscsv = sv_newmortal();
+ HV * hv = (HV*)sv_2mortal((SV*)newHV());
+CODE:
+ i_sub = get_cv("i", 0);
+ PUSHMARK(SP);
+ /* PUTBACK not needed since this sub was called with 0 args, and is calling
+ 0 args, so global SP doesn't need to be moved before a call_* */
+ retcnt = call_sv((SV*)i_sub, 0); /* try a CV* */
+ SPAGAIN;
+ SP -= retcnt; /* dont care about return count, wipe everything off */
+ sv_setpvs(miscsv, "i");
+ PUSHMARK(SP);
+ retcnt = call_sv(miscsv, 0); /* try a PV */
+ SPAGAIN;
+ SP -= retcnt;
+ /* no add and SVt_NULL are intentional, sub i should be defined already */
+ i_gv = gv_fetchpvn_flags("i", sizeof("i")-1, 0, SVt_NULL);
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_gv, 0); /* try a GV* */
+ SPAGAIN;
+ SP -= retcnt;
+ /* the tests below are not declaring this being public API behavior,
+ only current internal behavior, these tests can be changed in the
+ future if necessery */
+ PUSHMARK(SP);
+ retcnt = call_sv(&PL_sv_yes, 0); /* does nothing */
+ SPAGAIN;
+ SP -= retcnt;
+ PUSHMARK(SP);
+ retcnt = call_sv(&PL_sv_no, G_EVAL);
+ SPAGAIN;
+ SP -= retcnt;
+ errsv = ERRSV;
+ errstr = SvPV_nolen(errsv);
+ if(strnEQ(errstr, "Undefined subroutine &main:: called at",
+ sizeof("Undefined subroutine &main:: called at") - 1)) {
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
+ SPAGAIN;
+ SP -= retcnt;
+ }
+ PUSHMARK(SP);
+ retcnt = call_sv(&PL_sv_undef, G_EVAL);
+ SPAGAIN;
+ SP -= retcnt;
+ errsv = ERRSV;
+ errstr = SvPV_nolen(errsv);
+ if(strnEQ(errstr, "Can't use an undefined value as a subroutine reference at",
+ sizeof("Can't use an undefined value as a subroutine reference at") - 1)) {
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
+ SPAGAIN;
+ SP -= retcnt;
+ }
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)hv, G_EVAL);
+ SPAGAIN;
+ SP -= retcnt;
+ errsv = ERRSV;
+ errstr = SvPV_nolen(errsv);
+ if(strnEQ(errstr, "Not a CODE reference at",
+ sizeof("Not a CODE reference at") - 1)) {
+ PUSHMARK(SP);
+ retcnt = call_sv((SV*)i_sub, 0); /* call again to increase counter */
+ SPAGAIN;
+ SP -= retcnt;
+ }
void
call_sv(sv, flags, ...)
diff --git a/ext/XS-APItest/t/call.t b/ext/XS-APItest/t/call.t
index 7ff9933..54f45ec 100644
--- a/ext/XS-APItest/t/call.t
+++ b/ext/XS-APItest/t/call.t
@@ -11,7 +11,7 @@ use strict;
BEGIN {
require '../../t/test.pl';
- plan(436);
+ plan(437);
use_ok('XS::APItest')
};
@@ -28,6 +28,13 @@ sub f {
@_, defined wantarray ? wantarray ? 'x' : 'y' : 'z';
}
+our $call_sv_count = 0;
+sub i {
+ $call_sv_count++;
+}
+call_sv_C();
+is($call_sv_count, 6, "call_sv_C passes");
+
sub d {
die "its_dead_jim\n";
}
--
1.7.9.msysgit.0
|
From perl5-porters@perl.orgbulk88 wrote:
Return a glob from a tied array element. sub { |
From @bulk88On Sat Dec 21 21:56:28 2013, bulk88 wrote:
this got a commit by FC but no confirmation post in this ticket, this bug is to stay open since the commit didnt fix the docs for call_sv -- |
From perl5-porters@perl.orgDaniel Dragan wrote:
Sorry, I ran out of time when I was about to say so. The commit id was a85ce6f. |
From @tonycozOn Mon Dec 23 13:40:49 2013, bulk88 wrote:
Patch for the docs attached. Tony |
From @tonycoz0001-perl-120826-correct-documentation-of-sv-parameter-of.patchFrom 134f355583aaad80e6de89bd5e975d5fe22ba481 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Thu, 9 Jul 2015 11:49:31 +1000
Subject: [PATCH] [perl #120826] correct documentation of sv parameter of
call_sv()
---
perl.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/perl.c b/perl.c
index cbb66e0..fad0cbf 100644
--- a/perl.c
+++ b/perl.c
@@ -2664,8 +2664,22 @@ Perl_call_method(pTHX_ const char *methname, I32 flags)
/*
=for apidoc p||call_sv
-Performs a callback to the Perl sub whose name is in the SV. See
-L<perlcall>.
+Performs a callback to the Perl sub specified by the SV.
+
+If neither the G_METHOD or G_METHOD_NAMED flag is supplied, the SV may
+be any of a CV, a GV, a reference to a CV, a reference to a GV or the
+name of the sub to call.
+
+If the G_METHOD flag is supplied, the SV may be a refernce to a CV of
+the name of the method to call.
+
+If the G_METHOD_NAMED flag is supplied, the SV must be the name of the
+method.
+
+Some other values are treated specially for internal use and should
+not be depended on.
+
+See L<perlcall>.
=cut
*/
--
1.7.10.4
|
From @bulk88On Wed Jul 08 18:55:41 2015, tonyc wrote:
No objections. -- |
From @bulk88On Wed Jul 08 20:39:54 2015, bulk88 wrote:
Okay, maybe I have some objections. +Performs a callback to the Perl sub specified by the SV. "the SVPV name of the sub to call", name is not a technical term, it isn't obvious what a name is in Perl API. Instead of SVPV, "PV" is okay too. +If the G_METHOD flag is supplied, the SV may be a refernce to a CV of "name" is ambiguous, see above. +If the G_METHOD_NAMED flag is supplied, the SV must be the name of the "name" is ambiguous, see above. -- |
From @tonycozOn Sun Aug 02 21:54:28 2015, bulk88 wrote:
Updated patch attached. Tony |
From @tonycoz0001-perl-120826-correct-documentation-of-sv-parameter-of.patchFrom a91d260a0ab22a37a1706f0b8cb6369705a5d175 Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Mon, 3 Aug 2015 16:48:01 +1000
Subject: [PATCH] [perl #120826] correct documentation of sv parameter of
call_sv()
---
perl.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/perl.c b/perl.c
index 1af5e29..1823c99 100644
--- a/perl.c
+++ b/perl.c
@@ -2664,8 +2664,22 @@ Perl_call_method(pTHX_ const char *methname, I32 flags)
/*
=for apidoc p||call_sv
-Performs a callback to the Perl sub whose name is in the SV. See
-L<perlcall>.
+Performs a callback to the Perl sub specified by the SV.
+
+If neither the C<G_METHOD> or C<G_METHOD_NAMED> flag is supplied, the
+SV may be any of a CV, a GV, a reference to a CV, a reference to a GV
+or C<SvPV(sv)> will be used as the name of the sub to call.
+
+If the C<G_METHOD> flag is supplied, the SV may be a reference to a CV or
+C<SvPV(sv)> will be used as the name of the method to call.
+
+If the C<G_METHOD_NAMED> flag is supplied, C<SvPV(sv)> will be used as
+the name of the method to call.
+
+Some other values are treated specially for internal use and should
+not be depended on.
+
+See L<perlcall>.
=cut
*/
--
1.7.10.4
|
From @bulk88On Sun Aug 02 23:49:25 2015, tonyc wrote:
New version is okay. Once this patch is applied, this 1 yr 7 mo old ticket can finally be closed. -- |
@tonycoz - Status changed from 'open' to 'resolved' |
From @ikegamiThat text contains "neither..or" instead of "neither..nor". If neither the C<G_METHOD> or C<G_METHOD_NAMED> flag is supplied should be If neither the C<G_METHOD> flag nor the C<G_METHOD_NAMED> flag is supplied or If neither of the C<G_METHOD> and C<G_METHOD_NAMED> flags are supplied On Wed, Aug 5, 2015 at 12:57 AM, Tony Cook via RT <perlbug-followup@perl.org
|
From @wolfsageOn Wed, Aug 5, 2015 at 3:22 PM, Eric Brine <ikegami@adaelis.com> wrote:
Fixed in 7c0c544. Thanks. -- Matthew Horsfall (alh) |
Migrated from rt.perl.org#120826 (status was 'resolved')
Searchable as RT120826$
The text was updated successfully, but these errors were encountered: