develooper Front page | perl.perl5.porters | Postings from March 2022

XSUB.h: excess overwrites?

Thread Next
Felipe Gasper
March 31, 2022 13:24
XSUB.h: excess overwrites?
Message ID:
(Repost from, in response to a suggestion that the mailing list might be a better forum for discussion.)

Hi all,

Earlier today I discovered that XSUB.h overwrites functions like htons. With Leon’s help I learned that it has to do with the implicit-sys logic, which itself depends on NO_XSLOCKS being undefined. While perlguts discusses NO_XSLOCKS, it makes no mention of its role vis-à-vis implicit-sys.

The overwrite is problematic because Perl’s versions of these functions require the thread-context local variable (aTHX), which means C functions that lack that local variable will break when calling these. For example:
static int _my_htons(int myint) {
    return htons(myint);

/* Then, later … */

do_htons(SV* somenum)
        UV mynum = SvUV(somenum);
        RETVAL _my_htons((int) mynum);
The overwrite’s rationale of things like open(), per Leon, is that it allows different Perl interpreters to implement those differently. The problems are:

• It’s undocumented, as far as I can tell.
• It seems unclear what purpose a per-interpreter override of something like htons(), which is a pure function, would serve.

It seems to me:

- The documentation--perlguts?--should discuss this part of implicit-sys.

- Maybe it’s reasonable to shrink the set of functions that implicit-sys overrides?

Thank you!


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