stack depth in XSUB?

Hello,

	How can I get the current Perl stack depth from an XSUB?

	I see that CvDEPTH(find_runcv(NULL)) works, but is CvDEPTH =
considered part of the API?

	Thank you!

cheers,
-Felipe=
0
felipe
1/13/2021 3:05:19 AM
perl.perl5.porters 48287 articles. 1 followers. Follow

3 Replies
223 Views

Similar Articles

[PageSpeed] 47

On Tue, Jan 12, 2021 at 10:05:19PM -0500, Felipe Gasper wrote:
> Hello,
> 
> 	How can I get the current Perl stack depth from an XSUB?
> 
> 	I see that CvDEPTH(find_runcv(NULL)) works, but is CvDEPTH considered part of the API?

That's the recursion depth for the CV:

$ perl -MB -E 'sub foo { say (my $d = $_[0]->DEPTH); foo($_[0]) if $d < 5 } foo(B::svref_2object(\&foo))'
1
2
3
4
5

The depth of the argument stack is SP (or PL_stack_sp) less the base PL_stack_base.

See Perl_debstackptrs() or PL_debstack() in deb.c for example.

Tony
0
tony
1/13/2021 3:26:26 AM

> On Jan 12, 2021, at 10:26 PM, Tony Cook <tony@develop-help.com> wrote:
>=20
> On Tue, Jan 12, 2021 at 10:05:19PM -0500, Felipe Gasper wrote:
>> Hello,
>>=20
>> 	How can I get the current Perl stack depth from an XSUB?
>>=20
>> 	I see that CvDEPTH(find_runcv(NULL)) works, but is CvDEPTH =
considered part of the API?
>=20
> That's the recursion depth for the CV:
>=20
> $ perl -MB -E 'sub foo { say (my $d =3D $_[0]->DEPTH); foo($_[0]) if =
$d < 5 } foo(B::svref_2object(\&foo))'
> 1
> 2
> 3
> 4
> 5
>=20
> The depth of the argument stack is SP (or PL_stack_sp) less the base =
PL_stack_base.
>=20
> See Perl_debstackptrs() or PL_debstack() in deb.c for example.

Thank you!

=E2=80=A6 and thank you also to Paul, who (as I now see) documented this =
stuff in perlguts after my workstation=E2=80=99s default perl (5.26) was =
published.

cheers,
-Felipe=
0
felipe
1/13/2021 11:16:43 AM
On Wed, 13 Jan 2021 06:16:43 -0500
Felipe Gasper <felipe@felipegasper.com> wrote:

> =E2=80=A6 and thank you also to Paul, who (as I now see) documented this
> stuff in perlguts after my workstation=E2=80=99s default perl (5.26) was
> published.

:)

--=20
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/
0
leonerd
1/13/2021 2:46:53 PM
Reply: