Object lifetimes and references #10
jim-easterbrook
started this conversation in
General
Replies: 1 comment
-
Not long after writing this I thought of a better way to do it! Setting an attribute on the
A user could mess this up by deleting the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A common pattern in libexiv2 is for an object method to return a reference to some data held by the object. For example,
Exiv2::Image::io()
returns a reference to theExiv2::BasicIo
object being used for input/output. If theExiv2::Image
object is deleted the reference becomes invalid, and attempting to use theExiv2::BasicIo
object will cause a segmentation fault.In the Python interface some Exiv2 classes, such as
Exiv2::ExifData
, have customised wrappers that increment the reference count of the Pythonexiv2.Image
object. This stops theExiv2::Image
being deleted while the Pythonexiv2.ExifData
object exists. These wrappers make it easier to use exiv2, but add complexity to the interface. Many classes, such asExiv2::BasicIo
, don't have custom wrappers and will cause segmentation faults if not used with care.I would like to drop use of these extra wrappers completely. This would simplify the interface and make it easier to maintain, but users would need to take care not to delete objects while holding references to their data. (This care is already needed for "advanced" uses such as
Exiv2::Image::io()
.) Do let me know what you think about this.Beta Was this translation helpful? Give feedback.
All reactions