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

XSUB.h: excess overwrites?

Thread Next
From:
Felipe Gasper
Date:
March 31, 2022 13:24
Subject:
XSUB.h: excess overwrites?
Message ID:
F0C7B8BD-6C94-4DE9-8CCD-0D71362DB38A@felipegasper.com
(Repost from https://github.com/Perl/perl5/issues/19571, 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 … */

int
do_htons(SV* somenum)
    CODE:
        UV mynum = SvUV(somenum);
        RETVAL _my_htons((int) mynum);
    OUTPUT:
        RETVAL
}
```
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!

-FG

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