-
Notifications
You must be signed in to change notification settings - Fork 13
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
return nothing for NULL strings #75
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments:
- Is the name
unsafe_string_or_nothing
better? - Maybe we could document this change somewhere?
- You could also return an empty string for example, as that is at least the same type.
- Does the
C_NULL
indicate different things for different function (i.e. an error or nothing)?
That always does error checking, string loading and possible string freeing.
Thanks, your comments made me think about this again, and try something different. First my replies to your points:
From the
Yeah, I think we just need to make a changelog for going from v0.2 to v1.0. I'd prefer at this point to do that all at once I think. (Going forward we should keep it up to date)
Yeah but then you cannot distinguish it from an actual empty string result. And since this method is used by Base as well it seems like a better choice.
It seems like it, from the docs:
Especially the last point made me think, currently we only check for errors when we get a
So the new commit here effectively switches to always checking for errors, but only throwing on This also introduces a list of functions that return Cstring and are known to need their memory freed. For now I only put in
|
I ran into something similar with https://github.com/JuliaGeo/Proj4.jl/blob/882b48a9ea75198bc3325a35a93cac36e3f1ceec/test/proj6api.jl#L11-L13 and agree with the motive of this PR, but might need a few days to properly review it (if my input is needed). |
Yeah the main reason I requested your review was not to check if I implemented my ideas correctly, Maarten could check that as well, but to make sure you are on board with this direction. If you'd like to go over it properly, that's also welcome of course, no need to rush this in. Even if this doesn't nail it 100%, we can easily opt out of checking for errors or free more strings going forward without breaking code. To me it was a good sign that I didn't have to change any tests, just add one for the returning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I very much like the approach we're taking here. Just a few naming issues left.
This seems it's worth its own issue? From testing (on stable GDAL), it can handle one emergencyerror, but not two. julia> using GDAL
julia> GDAL.cplemergencyerror("things are bad")
ERROR: GDALError (CE_Fatal, code 1):
things are bad
Stacktrace:
[1] gdaljl_errorhandler(::GDAL.CPLErr, ::Int32, ::Cstring) at /Users/me/.julia/packages/GDAL/VqKWA/src/error.jl:26
[2] cplemergencyerror(::String) at /Users/me/.julia/packages/GDAL/VqKWA/src/cpl_error.jl:14
[3] top-level scope at none:0
julia> GDAL.cplemergencyerror("things are bad")
FATAL: things are bad
signal (6): Abort trap: 6
in expression starting at no file:0
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 1954108 (Pool: 1953578; Big: 530); GC: 3
[1] 81882 abort /Applications/Julia-1.1.app/Contents/Resources/julia/bin/julia |
Yeah I noticed the same thing. Though I believe it's not even supposed to be able to handle it once? See also the comment here: Lines 42 to 54 in 147f624
Could be it's own issue, but I've never encountered a |
Fixes #67.
Currently this errors with
ArgumentError: cannot convert NULL to string
inunsafe_string
, even though many functions are documented to return NULL in certain cases, that are not errors. This now works similarly to many Base functions likefindfirst
, that returnnothing
in case nothing is found.