├── .github └── workflows │ └── ci.yaml ├── .gitignore ├── .swiftformat ├── CODE_OF_CONDUCT.md ├── IntegrationTests ├── allocation-counter-tests-framework │ ├── run-allocation-counter.sh │ └── template │ │ ├── AtomicCounter │ │ ├── Package.swift │ │ └── Sources │ │ │ └── AtomicCounter │ │ │ ├── include │ │ │ └── atomic-counter.h │ │ │ └── src │ │ │ └── atomic-counter.c │ │ ├── HookedFunctionsDoHook │ │ ├── Package.swift │ │ └── Sources │ │ │ └── HookedFunctions │ │ │ ├── include │ │ │ └── hooked-functions.h │ │ │ └── src │ │ │ └── hooked-functions.c │ │ ├── HookedFunctionsDoNotHook │ │ ├── Package.swift │ │ └── Sources │ │ │ └── HookedFunctions │ │ │ ├── include │ │ │ └── hooked-functions.h │ │ │ └── src │ │ │ └── hooked-functions.c │ │ ├── Sources │ │ ├── bootstrapDoHook │ │ │ └── main.c │ │ └── bootstrapDoNotHook │ │ │ └── main.c │ │ └── scaffolding.swift ├── plugin_echo.sh ├── plugin_junit_xml.sh ├── run-single-test.sh ├── run-tests.sh ├── test_functions.sh ├── tests_03_linker_things │ ├── defines.sh │ └── test_01_check_we_do_not_link_Foundation.sh └── tests_04_performance │ ├── defines.sh │ ├── test_01_allocation_counts.sh │ └── test_01_resources │ ├── README.md │ ├── run-nio-alloc-counter-tests.sh │ ├── shared.swift │ └── test_jsonvalue_to_bytes.swift ├── LICENSE.txt ├── Package.swift ├── PerfTests ├── Package.resolved ├── Package.swift └── Sources │ └── CodingPerfTests │ ├── SampleStructure.swift │ └── main.swift ├── README.md ├── Sources └── ExtrasJSON │ ├── ArrayKey.swift │ ├── Decoding │ ├── JSONDecoder.swift │ ├── JSONKeyedDecodingContainer.swift │ ├── JSONSingleValueDecodingContainer.swift │ └── JSONUnkeyedDecodingContainer.swift │ ├── Encoding │ ├── JSONEncoder.swift │ ├── JSONKeyedEncodingContainer.swift │ ├── JSONSingleValueEncodingContainer.swift │ └── JSONUnkeyedEncodingContainer.swift │ ├── JSONError+DecodingError.swift │ ├── JSONValue.swift │ └── Parsing │ ├── DocumentReader.swift │ └── JSONParser.swift ├── Tests ├── ExtrasJSONTests │ ├── ArrayKeyTests.swift │ ├── DateCodingTests.swift │ ├── Decoding │ │ ├── JSONDecoderTests.swift │ │ ├── JSONKeyedDecodingContainerTests.swift │ │ ├── JSONSingleValueDecodingContainerTests.swift │ │ └── JSONUnkeyedDecodingContainerTests.swift │ ├── Encoding │ │ ├── JSONEncoderTests.swift │ │ ├── JSONKeyedEncodingContainerTests.swift │ │ ├── JSONSingleValueEncodingContainerTests.swift │ │ └── JSONUnkeyedEncodingContainerTests.swift │ └── Parsing │ │ ├── ArrayParserTests.swift │ │ ├── BoolParserTests.swift │ │ ├── JSONParserTests.swift │ │ ├── JSONValueTests.swift │ │ ├── NullParserTests.swift │ │ ├── NumberParserTests.swift │ │ ├── ObjectParserTests.swift │ │ └── StringParserTests.swift ├── LearningTests │ ├── FoundationJSONDecoderTests.swift │ ├── FoundationJSONEncoderTests.swift │ └── FoundationJSONSerializationTests.swift └── LinuxMain.swift ├── codecov.yml └── scripts └── validity.sh /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | branches: 8 | - "*" 9 | 10 | jobs: 11 | 12 | "validity-Tests": 13 | runs-on: macOS-latest 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2 17 | - name: Install swiftformat 18 | run: brew install swiftformat 19 | - name: Run validity 20 | run: ./scripts/validity.sh . 21 | 22 | "tuxOS-Tests": 23 | runs-on: ubuntu-latest 24 | strategy: 25 | fail-fast: false 26 | matrix: 27 | images: 28 | - swift:5.1 29 | - swift:5.2 30 | - swift:5.3 31 | - swiftlang/swift:nightly-master-focal 32 | container: 33 | image: ${{ matrix.images }} 34 | steps: 35 | - name: Checkout 36 | uses: actions/checkout@v2 37 | - name: Test 38 | run: swift test --enable-code-coverage --enable-test-discovery 39 | - name: Convert coverage files 40 | run: llvm-cov export -format="lcov" .build/debug/swift-extras-jsonPackageTests.xctest -instr-profile .build/debug/codecov/default.profdata > info.lcov 41 | - name: Install curl 42 | run: apt-get update && apt-get install -y curl # required by the codecov action. 43 | - name: Upload to codecov.io 44 | uses: codecov/codecov-action@v1 45 | with: 46 | file: info.lcov 47 | 48 | "tuxOS-Performance-Tests": 49 | runs-on: ubuntu-latest 50 | strategy: 51 | fail-fast: false 52 | matrix: 53 | images: 54 | - swift:5.1 55 | - swift:5.2 56 | - swift:5.3 57 | - swiftlang/swift:nightly-master-focal 58 | container: 59 | image: ${{ matrix.images }} 60 | steps: 61 | - name: Checkout 62 | uses: actions/checkout@v2 63 | - name: Build 64 | run: swift build -c release 65 | working-directory: ./PerfTests 66 | - name: Run test 67 | run: swift run -c release 68 | working-directory: ./PerfTests 69 | 70 | "tuxOS-Integration-Tests": 71 | runs-on: ubuntu-latest 72 | strategy: 73 | fail-fast: false 74 | matrix: 75 | images: 76 | - swift:5.1 77 | - swift:5.2 78 | - swift:5.3 79 | - swiftlang/swift:nightly-master-focal 80 | container: 81 | image: ${{ matrix.images }} 82 | env: 83 | MAX_ALLOCS_ALLOWED_jsonvalue_to_bytes: 0 84 | steps: 85 | - name: Checkout 86 | uses: actions/checkout@v2 87 | - name: Test 88 | run: ./run-tests.sh 89 | working-directory: ./IntegrationTests 90 | 91 | "macOS-Tests": 92 | runs-on: macOS-latest 93 | strategy: 94 | fail-fast: false 95 | matrix: 96 | xcode: 97 | - Xcode_11.2.app 98 | - Xcode_11.6.app 99 | - Xcode_12.2.app 100 | steps: 101 | - name: Checkout 102 | uses: actions/checkout@v2 103 | - name: Show all Xcode versions 104 | run: ls -an /Applications/ | grep Xcode* 105 | - name: Change Xcode command line tools 106 | run: sudo xcode-select -s /Applications/${{ matrix.xcode }}/Contents/Developer 107 | - name: Swift version 108 | run: swift --version 109 | - name: Xcode Tests 110 | run: | 111 | swift package generate-xcodeproj --skip-extra-files --enable-code-coverage 112 | xcodebuild -quiet -parallel-testing-enabled YES -scheme swift-extras-json-Package -enableCodeCoverage YES build test 113 | - name: Codecov 114 | run: bash <(curl -s https://codecov.io/bash) -t ${{secrets.CODECOV_TOKEN}} -f *.coverage.txt 115 | 116 | "macOS-Performance-Tests": 117 | runs-on: macOS-latest 118 | strategy: 119 | fail-fast: false 120 | matrix: 121 | xcode: 122 | - Xcode_11.2.app 123 | - Xcode_11.6.app 124 | - Xcode_12.2.app 125 | steps: 126 | - name: Checkout 127 | uses: actions/checkout@v2 128 | - name: Change Xcode command line tools 129 | run: sudo xcode-select -s /Applications/${{ matrix.xcode }}/Contents/Developer 130 | - name: Swift version 131 | run: swift --version 132 | - name: Build 133 | run: swift build -c release 134 | working-directory: ./PerfTests 135 | - name: Run test 136 | run: swift run -c release 137 | working-directory: ./PerfTests 138 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .build 3 | /*.xcodeproj 4 | xcuserdata 5 | -------------------------------------------------------------------------------- /.swiftformat: -------------------------------------------------------------------------------- 1 | # file options 2 | 3 | --swiftversion 5.1 4 | --exclude .build 5 | 6 | # format options 7 | 8 | --self insert 9 | --patternlet inline 10 | --stripunusedargs unnamed-only 11 | --ifdef no-indent 12 | 13 | # rules 14 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at fabianfett@mac.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /IntegrationTests/allocation-counter-tests-framework/run-allocation-counter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ##===----------------------------------------------------------------------===## 3 | ## 4 | ## This source file is part of the SwiftNIO open source project 5 | ## 6 | ## Copyright (c) 2019 Apple Inc. and the SwiftNIO project authors 7 | ## Licensed under Apache License v2.0 8 | ## 9 | ## See LICENSE.txt for license information 10 | ## See CONTRIBUTORS.txt for the list of SwiftNIO project authors 11 | ## 12 | ## SPDX-License-Identifier: Apache-2.0 13 | ## 14 | ##===----------------------------------------------------------------------===## 15 | 16 | set -eu 17 | here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 18 | build_opts=( -c release ) 19 | 20 | function die() { 21 | echo >&2 "ERROR: $*" 22 | exit 1 23 | } 24 | 25 | function make_git_commit_all() { 26 | git init > /dev/null 27 | git checkout -b main 28 | if [[ "$(git config user.email)" == "" ]]; then 29 | git config --local user.email does@really-not.matter 30 | git config --local user.name 'Does Not Matter' 31 | fi 32 | git add . > /dev/null 33 | git commit -m 'everything' > /dev/null 34 | } 35 | 36 | # 37 | function hooked_package_swift_start() { 38 | local extra_dependencies_file=$1 39 | local swiftpm_pkg_name=$2 40 | shift 2 41 | 42 | cat <<"EOF" 43 | // swift-tools-version:5.0 44 | import PackageDescription 45 | 46 | let package = Package( 47 | name: "allocation-counter-tests", 48 | products: [ 49 | EOF 50 | for f in "$@"; do 51 | local module 52 | module=$(module_name_from_path "$f") 53 | echo ".executable(name: \"$module\", targets: [\"bootstrap_$module\"])," 54 | done 55 | cat < 71 | function hooked_package_swift_target() { 72 | local target_name="$1" 73 | shift 74 | local deps="" 75 | for dep in "$@"; do 76 | deps="$deps \"$dep\"," 77 | done 78 | cat < Package.swift <