Ticket #1610 (closed proposal: fixed)

Opened 5 years ago

Last modified 3 years ago

Make arrays safer

Reported by: igloo Owned by: igloo
Priority: high Milestone: 6.8.1
Component: libraries (other) Version: 6.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

This is a proposal to make arrays safer (e.g. see #1046).

This is a divergence from Haskell 98.

The patches:

  • Add (numElements :: Ix i => a i e -> Int) to IArray class
  • Array types get an extra field for numElements, e.g.
       -data UArray i e = UArray !i !i ByteArray#
       +data UArray i e = UArray !i !i !Int ByteArray#
    
    This is a cache of rangeSize(l,u)
  • Add safeRangeSize (always returns >= 0)
  • Add safeIndex (use unsafeIndex (no Ix inRange check), but check index < numElements)
  • unsafeForeignPtrToStorableArray gained an (Ix i) context
  • Use the new functions in various places

Suggested deadline: 24 Aug 2007.

Attachments

1610.ghc.1.patch Download (98.7 KB) - added by igloo 5 years ago.
1610.base.1.patch Download (73.1 KB) - added by igloo 5 years ago.
1610.array.1.patch Download (103.6 KB) - added by igloo 5 years ago.

Change History

Changed 5 years ago by igloo

Changed 5 years ago by igloo

Changed 5 years ago by igloo

Changed 4 years ago by igloo

  • owner set to igloo

Changed 4 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Isaac Dupree pointed out a small bug; other than that, no discussion.

Changed 4 years ago by igloo

  • milestone changed from 6.8 branch to 6.8.1

Changed 4 years ago by amthrax

The implementation of safeIndex in this change makes it possible to perform array references that are not inRange. I've detailed the bug and one resolution in ticket #2120.

Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 3 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.