Skip to content

Commit

Permalink
copy all array like feature fields after unsafe_wrap (#442)
Browse files Browse the repository at this point in the history
* `copy` all array like features after `unsafe_wrap`, to prevent GDAL from overwriting the memory

* Revert "`copy` all array like features after `unsafe_wrap`, to prevent GDAL from overwriting the memory"

This reverts commit 3bac8a4.

* copy for specific field types in `fetchfield`

* Update feature.jl
  • Loading branch information
asinghvi17 authored Nov 14, 2024
1 parent c7aa0d6 commit 58e2c03
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/ogr/feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,22 @@ null, it will return `missing`.
"""
function getfield(feature::AbstractFeature, i::Integer)
return if !isfieldset(feature, i)
nothing
return nothing
elseif isfieldnull(feature, i)
missing
return missing
else
_fieldtype = getfieldtype(getfielddefn(feature, i))
try
_fetchfield = _FETCHFIELD[_fieldtype]
_fetchfield(feature, i)
if _fieldtype in (OFTIntegerList, OFTRealList, OFTStringList, OFTInteger64List)
# copy to ensure that GDAL does not free / overwrite the memory.
# the docs for the field fetcher functions mention that the returned
# pointer is not valid for very long.
return Base.copy(_fetchfield(feature, i))
else
# for static types, we can just return the returned value.
return _fetchfield(feature, i)
end
catch e
if e isa KeyError
error(
Expand Down

0 comments on commit 58e2c03

Please sign in to comment.