Skip to content

D100: std's unchecked helpers become unsafe fn #2208

Closed

Description

@ehartford

D100 (spec v7.27): "an unchecked helper should also be an unsafe fn, so even code inside std has to acknowledge the risk when calling it". Privacy now keeps user code out (package-wide visibility); this is the second guard, inside std.

Survey (non-pub std functions whose safety rests on what the caller passes: a raw pointer, a length, an unchecked index):

  • collections/sorted_vec.w slot_at(index) -> *mut Slot[T]; collections/hash_index.w find(key) -> *mut HashSlot; collections/trie.w lookup, prefix_node, trie_key_bytes
  • json.w json_skip(tokens: *const JsonToken, idx)
  • crypto: Aes128.new(key: *const u8), AesGcm.new(key, iv, iv_len), HmacSha256.new(key, key_len), hmac_sha256(key, key_len, data, …)
  • sys.w _read_pass(buf, size), _write_pass(buf, size)
  • regex.w helpers over a raw pcre2 code pointer (regex_match_data, regex_pattern_info, regex_match_spans_at, regex_group_index, regex_substitute*, …)

Each either becomes unsafe fn (callers in std wrap the call in unsafe) or checks its own inputs and stays safe. Drop/deref impls that encapsulate their unsafe are out of scope.

Done already (e09e29d8d, on branch method-privacy): the HashMap slot accessors (slot_key/slot_value/slot_take) are checked in both backends and panic on a dead slot. BTreeMap.key_at (#2186's segfault) is a bounds-checked indexed read on main.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions