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

deprecate bytes.pm?

Thread Next
From:
Dave Mitchell
Date:
June 24, 2017 13:55
Subject:
deprecate bytes.pm?
Message ID:
20170624135531.GH3074@iabyn.com
I would like to deprecate bytes.pm.

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:

    bytes::length
    bytes::chr
    bytes::ord
    bytes::substr
    bytes::index
    bytes::rindex

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

I would like to deprecate bytes.pm and eventually remove it.

In particular, the pragma part of bytes.pm 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
    120

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 bytes.pm 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About