develooper Front page | perl.perl5.porters | Postings from December 2013

Re: An article on writing Perl extensions without XS

Thread Previous | Thread Next
From:
Zefram
Date:
December 17, 2013 11:43
Subject:
Re: An article on writing Perl extensions without XS
Message ID:
20131217114300.GK21945@fysh.org
Christian Walde wrote:
>The i do not understand what "stereotyped use" means in simple
>english.

The variables are used in ways that tend to be the same between xsubs and
are also peculiar to those particular variables.  That they are used in
the same peculiar ways does not happen merely because that's how we've
always done it, which is what "tradition" implies.  It happens because
of the particular jobs they serve, which arises mainly from the problem
space supplied by the Perl runtime's unique system of multiple stacks,
which was partially described in Steffen's article.

If you were to throw away all knowledge of XS and start from scratch,
to write an xsub to operate in the Perl runtime, you would need the
same concepts that XS already has.  You would reinvent the variables.
You wouldn't come up with the same names, of course.  You wouldn't even
necessarily name exactly the same things; for example, if your functions
mostly have fixed arity, you likely wouldn't give the argument count
a name.  But for the most part you would find the same quantities are
significant, and the exigencies of writing in C and attempting to be
efficient would lead to you mostly putting the same ones into C variables.

The only part that's really tradition is the specific names of the
variables.  As I said, you wouldn't naturally reinvent the same names
if you were approaching the problem afresh.  (A lot of people would
come up with "items" and "sp", or at least names close to those, but
"ax" is utterly arbitrary.)  Outside the context of the code generated
by XS, we use the same names for these variables just because they're
the established names.

-zefram

Thread Previous | 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