Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_sharedContextCache is not thread safe #4634

Open
dadadong opened this issue May 30, 2024 · 1 comment
Open

_sharedContextCache is not thread safe #4634

dadadong opened this issue May 30, 2024 · 1 comment

Comments

@dadadong
Copy link

I am using the swift version of ANTLR4.13.1 to parse the objc code file, and I always encounter a crash. My code structure is as follows:

        let queue = OperationQueue()
        for path in paths {
            let opt = BlockOperation {
                guard let input = try? ANTLRFileStream(path) else {
                    return nil
                }
                let lexer = ObjectiveCLexer(input)
                let tokens = CommonTokenStream(lexer)
                guard let parser = try? ObjectiveCParser(tokens) else {
                    return nil
                }
                parser.setErrorHandler(BailErrorStrategy())
                guard let unit = try? parser.translationUnit(),
                      unit.exception == nil
                else {
                    return nil
                }
                // soming....
            }
            queue.addOperation(opt)
        }

Crash stack:
image

@dadadong
Copy link
Author

dadadong commented Jun 21, 2024

I use the following code to solve the thread-safety problem and do not know if there is a risk,any help me :)

private class OC_Parsor: ObjectiveCParser {
    private let _cache = PredictionContextCache()

    override init(_ input: TokenStream) throws {
        RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION)
        try super.init(input)
        _interp = ParserATNSimulator(self, ObjectiveCParser._ATN, ObjectiveCParser._decisionToDFA, _cache)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant