Front page | perl.perl5.porters |
Postings from June 2012
Re: Time for a 64-bit perl API?
Thread Previous
|
Thread Next
From:
Rev. Chip
Date:
June 16, 2012 21:50
Subject:
Re: Time for a 64-bit perl API?
Message ID:
20120617045020.GA10595@tytlal.tinsaucer.com
On Sun, Jun 10, 2012 at 12:46:06PM +0100, Dave Mitchell wrote:
> Perhaps its time to bite the bullet and give perl a whole new 64-bit-clean
> API? For example, an av_fetch64() with IV rather than I32 args.
It would be a serious flaw to put or leave fixed bit width integral values
in the API, be they 32, 64, or 128 -- with one exception, namely, flag
values which aren't really integers, they're bit vectors in integer form, so
fixed width is fine. With the exception of flags, if the numbers "32", "64",
or "128" appear in our API, we have failed as designers.
It's an old saying that the only reasonable numbers in programming are zero,
one, and infinity. This principle applies to integer types thusly: The only
reasonable sizes for integral APIs (except flag fields where we assign the
bits manually) are char, size_t, ssize_t[*], ptrdiff_t, intptr_t, and
intmax_t. Add signed and unsigned to taste.
For the most part we can widen parameters in existing functions at will to
use C-provided and Configure-provided types, and no further handwaving is
required. We do need to introduce new functions for two cases:
1. Widened return values. Otherwise silent truncation kills.
2. Where the value-preserving rule of ANSI C bites. Consider the below,
assuming for the sake of explanation that sizeof(long) > sizeof(int):
UINT_MAX passed as an int parameter becomes (int)-1
while
UINT_MAX passed as a long parameter becomes (long)UINT_MAX
so widening a paramter from int (or a typedef thereof) to long (or a typedef
thereof) could introduce a bug, if the API depended on the conversion to -1.
These should be quite rare, and possibly nonexistent.
[*] Since ssize_t is POSIX, we can use ptrdiff_t as a substitute (since it
is the same on all systems, as a practical matter) or use SSize_t, the
typedef that Configure discovers on our behalf. I favor ptrdiff_t as a
signed memory index (e.g. for array lookup), and SSize_t for I/O results
(i.e. the return value of read()).
--
Chip Salzenberg
Thread Previous
|
Thread Next