Skip to content

With Xcode 14.1 beta 1 there is a memory crashΒ #9

@doozMen

Description

@doozMen

I guess because `free()1Password nulls out freed memory there is a memory problem as when I use the following code

import Foundation
import Syntax


public enum JSON {
  case object([String : JSON])
  case array([JSON])
  case int(Int)
  case double(Double)
  case bool(Bool)
  case string(String)
  case null
}


public struct TokenParser: RecursiveParser {
  public init() {}
  
  public var body: any Parser<JSON> {
    Either {
      JSONDictionaryParser().map(JSON.object)
      JSONArrayParser().map(JSON.array)
      
      StringLiteral().map(JSON.string)
      IntLiteral().map(JSON.int)
      DoubleLiteral().map(JSON.double)
      BooleanLiteral().map(JSON.bool)
      
      Word("null").map(to: JSON.null)
    }
  }
}

public struct JSONArrayParser: Parser {
  // reference to the JSON parser
  
  public var body: any Parser<[JSON]> {
    "["
    
    TokenParser().separated(by: ",")
    
    "]"
  }
}

public struct JSONDictionaryParser: Parser {  
  public var body: any Parser<[String : JSON]> {
    "{"
    
    // Group acts kinda like parenthesis here.
    // It groups the key-value pair into one parser
    Group {
      StringLiteral()
      
      ":"
      
      TokenParser()
    }
    .separated(by: ",")
    .map { values in
      // put the pairs in a dictionary
      return Dictionary(values) { $1 }
    }
    
    "}"
  }
}

To run a simple test

final class SyntaxTokenParsing: XCTestCase {
  func testSyntax() throws {
    
    let test = """
    {
    "key1" : { "value": 1 },
    "key2" : { "value": 2 }
    }
    """
    let jsonParsed = try TokenParser().parse(test)
    
    XCTAssertEqual("\(jsonParsed)", "")
  }
}

This works on Xcode 14.0 but not on 14.1
Screenshot 2022-09-23 at 11 16 09

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions