lebje / tomlkit Goto Github PK
View Code? Open in Web Editor NEWA small, simple TOML parser and serializer for Swift. Powered by toml++.
Home Page: https://lebje.github.io/TOMLKit/documentation/tomlkit
License: MIT License
A small, simple TOML parser and serializer for Swift. Powered by toml++.
Home Page: https://lebje.github.io/TOMLKit/documentation/tomlkit
License: MIT License
Why minimum iOS version is 14?Many apps need support iOS 13+, can TOMLKit change to .iOS(.v13),
?
My Code is quit simple:
// a toml string
var tomlString = '''
port = 6789
socks_port = 7890
allow_lan = false
bind_address = '*'
log_level = 'debug'
ipv6 = false
tun_fd = 0
'''
// `NetspeedConfig` is a Swift Struct define in my app
var config = try TOMLDecoder().decode(NetspeedConfig.self, from: tomlString)
// set property etc.
config.tun_fd = 10
...
// convert to toml string
tomlString = try TOMLEncoder().encode(config)
// create a TOMLKit table
let table = try TOMLTable(string: tomlString)
// convert to strings
let output_toml = table.convert(to: .toml)
let output_json = table.convert(to: .json)
let output_yaml = table.convert(to: .yaml)
Xcode Instruments catch this memory leak, please download it and check in Xcode
https://github.com/codingiran/TOMLKit/blob/main/MemoryLeaks/TOMlKit%20Memory%20Leaks.trace.zip
Hi Jeff,
In both of my packages that use TOMLKit, it always takes a lot longer for SwiftPM and Xcode to resolve TOMLKit than any of the other dependencies. I was going to attach a screenshot of the log from resolving dependencies after clearing the cache, but Xcode crashed before I could take the screenshot. However, I did see that all other dependencies were resolved in under 5 seconds, and TOMLKit took 138 seconds to resolve.
I ran swift package resolve -v
and the longest step seems to be the git submodule update --init --recursive
step for TOMLKit
because of tomlplusplus
's json
submodule with over 4300 commits. The tomlplusplus
submodule doesn't seem necessary for building TOMLKit
, so would it be possible to remove it and instead just put the commit of tomlplusplus
that TOMLKit
uses in a file somewhere?
Hi @LebJe,
I have found a reproducible fatal crash in TOMLKit. Here's the minimum code that I have been able to reproduce the crash with:
import Foundation
import TOMLKit
let string = "[[apps.test]]"
struct Child: Codable {
var value: String // if Child is an empty struct it doesn't crash
}
struct Parent: Codable {
var apps: [String: Child] // if this is just `[String: String]` it doesn't crash
}
try? TOMLDecoder().decode(Parent.self, from: string)
The realworld use case I have that runs into this fatal crash (with incorrect TOML input) is decoding this Configuration struct from this string:
[[apps.HelloWorld]]
product = "HelloWorld"
version = "0.1.0"
The TOML is invalid because it's not meant to have double square brackets, however fatal crashes shouldn't occur even with invalid input.
I have done a bit of poking around and I think I have found the issue. TOMLKit thinks that the array at coding path apps.HelloWorld
is both a table and an array (these values are from inside TOMLTable.keys
):
(lldb) po tomlValue.array
▿ Optional<TOMLArray>
▿ some : [ { minimum_macos_version = '11', product = 'HelloWorld', version = '0.1.0' } ]
(lldb) po tomlValue.table
▿ Optional<TOMLTable>
▿ some : [ { minimum_macos_version = '11', product = 'HelloWorld', version = '0.1.0' } ]
For some reason casting the value to both an array and a table succeeds.
I have found a way to fix the crash: checking the type of the node before attempting to cast it so that these invalid type casts can't occur anymore.
I will submit a PR soon with the required changes (once I have run the tests).
I am currently using TOMLKit in a few projects to decode configuration files. It would be extremely useful if TOMLKit's Codable implementation had an option to do strict decoding. By strict decoding I mean throwing an error if any unexpected keys are present. This makes typos of optional keys a lot easier for users to detect (because the typoed key would cause an error to be thrown instead of just silently being ignored).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.