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

Improve safety and idiomaticity of API #1

Merged
merged 2 commits into from
Apr 8, 2018
Merged

Improve safety and idiomaticity of API #1

merged 2 commits into from
Apr 8, 2018

Conversation

Ortham
Copy link
Contributor

@Ortham Ortham commented Apr 7, 2018

Hi, thanks for writing and publishing this library, I'm using it as part of an SVG -> ICO conversion. I've made a few improvements to the API:

  • Fix memory leaks due to NanoSVG memory never getting freed.
  • Remove unwrap() usage outside tests, propagate errors to the caller.
  • Add a Units enum to safely represent the allowed values for the units
    parameter.
  • Expose methods to get SVG image width and height.

I initially only wanted the width and height access, but the memory leaks and unwrap() usage were pretty serious issues, and representing a fixed set of units values using an enum is more ergonomic than letting the user pass in any nonsense, so I stuck that in too.

Ortham added 2 commits April 7, 2018 22:48
- Fix memory leaks due to NanoSVG memory never getting freed.
- Remove unwrap() usage outside tests, propagate errors to the caller.
 - Add a Units enum to safely represent the allowed values for the units
  parameter.
- Expose methods to get SVG image width and height.
The C library doesn't handle such paths correctly (which is unreasonably
hard to do in C/C++) so read the SVG file in Rust and pass its content
to NanoSVG for parsing.
@nickbrowne
Copy link
Owner

I've been meaning to make changes along these lines for a while (exposing width/height safely, better error handling) but I've been a bit busy, so thanks very much!

I also wasn't aware of the memory leak, so thanks for finding and dealing with that.

👍 I'll try to publish a new version later today.

@nickbrowne nickbrowne merged commit af5a081 into nickbrowne:master Apr 8, 2018
@nickbrowne
Copy link
Owner

I've published a new version (0.4.0) which includes your changes. Thanks again!

@Ortham
Copy link
Contributor Author

Ortham commented Apr 8, 2018

That was fast, thanks!

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

Successfully merging this pull request may close these issues.

2 participants