<commit_before>//===--- DarwinExtras.swift -----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Darwin

var _stdlib_FD_SETSIZE: CInt {
  return 1024
}

struct _stdlib_fd_set {
  var _data: ContiguousArray<UInt32>
  static var _wordBits: Int {
    return sizeof(UInt32) * 8
  }

  init() {
    _data = ContiguousArray<UInt32>(
      count: Int(_stdlib_FD_SETSIZE) / _stdlib_fd_set._wordBits,
      repeatedValue: 0)
  }

  func isset(fd: CInt) -> Bool {
    let fdInt = Int(fd)
    return (
        _data[fdInt / _stdlib_fd_set._wordBits] &
          UInt32(1 << (fdInt % _stdlib_fd_set._wordBits))
      ) != 0
  }

  mutating func set(fd: CInt) {
    let fdInt = Int(fd)
    _data[fdInt / _stdlib_fd_set._wordBits] |=
      UInt32(1 << (fdInt % _stdlib_fd_set._wordBits))
  }

  mutating func clear(fd: CInt) {
    let fdInt = Int(fd)
    _data[fdInt / _stdlib_fd_set._wordBits] &=
      ~UInt32(1 << (fdInt % _stdlib_fd_set._wordBits))
  }

  mutating func zero() {
    let count = _data.count
    return _data.withUnsafeMutableBufferPointer {
      (_data) in
      for i in 0..<count {
        _data[i] = 0
      }
      return
    }
  }
}

func _stdlib_select(
  inout readfds: _stdlib_fd_set, inout writefds: _stdlib_fd_set,
  inout errorfds: _stdlib_fd_set, timeout: UnsafeMutablePointer<timeval>
) -> CInt {
  return readfds._data.withUnsafeBufferPointer {
    (readfds) in
    writefds._data.withUnsafeBufferPointer {
      (writefds) in
      errorfds._data.withUnsafeBufferPointer {
        (errorfds) in
        return select(
          _stdlib_FD_SETSIZE,
          readfds.baseAddress.asPointerTo(fd_set.self).asMutablePointer,
          writefds.baseAddress.asPointerTo(fd_set.self).asMutablePointer,
          errorfds.baseAddress.asPointerTo(fd_set.self).asMutablePointer,
          timeout)
      }
    }
  }
}

/// Calls POSIX `pipe()`.
func posixPipe() -> (readFD: CInt, writeFD: CInt) {
  var fds: [CInt] = [ -1, -1 ]
  var _: Void = fds.withUnsafeMutableBufferPointer {
    (fds) in<commit_msg>Use withUnsafeMutableBufferPointer when mutating the buffer instead of getting an immutable buffer and casting it<commit_after>//===--- DarwinExtras.swift -----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Darwin

var _stdlib_FD_SETSIZE: CInt {
  return 1024
}

struct _stdlib_fd_set {
  var _data: ContiguousArray<UInt32>
  static var _wordBits: Int {
    return sizeof(UInt32) * 8
  }

  init() {
    _data = ContiguousArray<UInt32>(
      count: Int(_stdlib_FD_SETSIZE) / _stdlib_fd_set._wordBits,
      repeatedValue: 0)
  }

  func isset(fd: CInt) -> Bool {
    let fdInt = Int(fd)
    return (
        _data[fdInt / _stdlib_fd_set._wordBits] &
          UInt32(1 << (fdInt % _stdlib_fd_set._wordBits))
      ) != 0
  }

  mutating func set(fd: CInt) {
    let fdInt = Int(fd)
    _data[fdInt / _stdlib_fd_set._wordBits] |=
      UInt32(1 << (fdInt % _stdlib_fd_set._wordBits))
  }

  mutating func clear(fd: CInt) {
    let fdInt = Int(fd)
    _data[fdInt / _stdlib_fd_set._wordBits] &=
      ~UInt32(1 << (fdInt % _stdlib_fd_set._wordBits))
  }

  mutating func zero() {
    let count = _data.count
    return _data.withUnsafeMutableBufferPointer {
      (_data) in
      for i in 0..<count {
        _data[i] = 0
      }
      return
    }
  }
}

func _stdlib_select(
  inout readfds: _stdlib_fd_set, inout writefds: _stdlib_fd_set,
  inout errorfds: _stdlib_fd_set, timeout: UnsafeMutablePointer<timeval>
) -> CInt {
  return readfds._data.withUnsafeMutableBufferPointer {
    (readfds) in
    writefds._data.withUnsafeMutableBufferPointer {
      (writefds) in
      errorfds._data.withUnsafeMutableBufferPointer {
        (errorfds) in
        return select(
          _stdlib_FD_SETSIZE,
          readfds.baseAddress.asPointerTo(fd_set.self),
          writefds.baseAddress.asPointerTo(fd_set.self),
          errorfds.baseAddress.asPointerTo(fd_set.self),
          timeout)
      }
    }
  }
}

/// Calls POSIX `pipe()`.
func posixPipe() -> (readFD: CInt, writeFD: CInt) {
  var fds: [CInt] = [ -1, -1 ]
  var _: Void = fds.withUnsafeMutableBufferPointer {
    (fds) in
{'fraction_non_alphanumeric': 0.1561122244488978, 'fraction_numerical': 0.014428857715430862, 'mean_word_length': 2.3860244233378562, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '954588', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1662, 'n_words': 371}