develooper Front page | perl.perl5.porters | Postings from June 2017


Thread Next
Dave Mitchell
June 24, 2017 13:55
Message ID:
I would like to deprecate

This module has two uses: first, as a pragma: while it's in scope, pp
functions 'forget' that SV's have the SvUTF8 flag set:

    my $x = "\x{100}";
    print length $x;
    { use bytes; print length $x; }
    print length $x;

outputs 1,2,1.

Secondly it defines a series of functions:


which work on bytes rather than characters, for some definition of

I would like to deprecate and eventually remove it.

In particular, the pragma part of infects large parts of the core.
Lots of internals do extra checks for whether 'use bytes' is in scope,
e.g. the IN_BYTES and DO_UTF8 macros:

    #define IN_BYTES UNLIKELY(CopHINTS_get(PL_curcop) & HINT_BYTES)
    #define DO_UTF8(sv) (SvUTF8(sv) && !IN_BYTES)

    $ git grep -w DO_UTF8 | wc -l

so lots of code, rather than doing a just quick check of the SVf_UTF8
flag of an SV, have to do a check of the hints too.

A lot of the core code which tests for IN_BYTES is probably broken, and is
certainly untested. And perl-level code which makes use of the bytes
pragma is probably broken too.

As far as I'm aware, the only vaguely legitimate part of these
days is bytes::length(), which could be used by code wanting to
discover how many bytes would be written if an SV was output.

There seem to be three possible levels of deprecation:

1) Just deprecate the pragma:

    use bytes;    # warns
    use bytes (); # ok

2) in addition, deprecate all bytes::foo functions except bytes::length() -
    the others would emit a deprecation warning the first time they're
    called, perhaps.

3) in addition deprecate bytes::length() and explain other ways of
achieving it, e.g.utf8::encode/decode

Hofstadter's Law: It always takes longer than you expect, even when you
take into account Hofstadter's Law.

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