develooper Front page | perl.perl5.porters | Postings from April 2016

Re: Inconsistencies in memory size types

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
April 5, 2016 14:28
Subject:
Re: Inconsistencies in memory size types
Message ID:
20160405142804.GR4160@iabyn.com
On Tue, Mar 01, 2016 at 09:46:17AM +0000, Dagfinn Ilmari Mannsåker wrote:
> Hi porters,
> 
> While investigating [perl #127619] Broken memcpy() fallback to bcopy(),
> I noticed that variables refering to string lengths, array sizes
> etc. are an inconsistent mess of MEM_SIZE, STRLEN, Size_t and size_t
> (and SSize_t/ssize_t for signed variants).  A bit more digging reveals
> that we already use size_t unconditionally all over the codebase (and
> it's required by C89), while ssize_t support is more patchy (it's only
> required by POSIX, not ISO/ANSI C).
> 
> In light of this, I've altered Configure and friends to not probe for
> size_t, and changed SSize_t to ssize_t (guarded by an #ifndef, in case
> it's a #define rather than a typedef) in config_h.SH, and changed uses
> of MEM_SIZE, STRLEN and Size_t to size_t and SSize_t to ssize_t.  I have
> not touched cpan/, and the existing names are still there, guarded by
> #ifndef PERL_CORE.
> 
> I've pushed the result to smoke-me/ilmari/size_t, and the results so far
> look good.  I realise we are approaching full code freeze, so I'm a bit
> wary of merging it, but I think it's a clean-up overall, and keeping
> rebasing it for an extended time would be a pain.

Sorry, no-one's replied to this. We've now passed code-freeze, so it
will have to wait for 5.25.0 if accepted.

SSize_t and Size_t seem to have been added in perl 5.000 in 1994, but
there's no indication of the rationale. The 5.000 src code was still
K&R in at least function signatures, so it may well be the case that
that size_t wasn't universal at that time or was problematic on some
platforms.

I feel slightly twitchy about eliminating Size_t etc, but can't think
of any rational reason why.

Do any C lawyers and/or people who used to port perl to crays, know
whether there are any semantic differences between size_t, MEM_SIZE,
STRLEN etc?


-- 
No man treats a motor car as foolishly as he treats another human being.
When the car will not go, he does not attribute its annoying behaviour to
sin, he does not say, You are a wicked motorcar, and I shall not give you
any more petrol until you go. He attempts to find out what is wrong and
set it right.
    -- Bertrand Russell,
       Has Religion Made Useful Contributions to Civilization?

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