I believe the Python bindings purposely return references here because that's 
what C++ does -- and you definitely don't want to copy the whole spec every 
time.

C++ has spec() and specmod() to distinguish between a const reference and a 
mutable reference. (It could overload spec() to have a const and non-const 
version, but we do it this way because some fields should NOT be changed in a 
live ImageBuf, so by using a different name to get the mutable copy, I hoped 
that it would be obvious that it was something you needed to be careful with.)

Python doesn't really have the "const vs mutable reference" concept as far as I 
know, or at least, there is no mapping in pybind11 for such a thing. So I guess 
in some sense, having both spec and specmod on the Python side is redundant. I 
suppose it's just for symmetry with the C++ side, but you can do it all with 
spec.


> On Apr 14, 2021, at 12:26 AM, Alister Chowdhury <krax.po...@gmail.com> wrote:
> 
> I'm not totally sure if this is a bug or intentional, but when the python 
> bindings were rewritten `spec()` and `nativespec()` seem to have stopped 
> returning copies and began returning references.
> 
> I remember in the before time, that you would have to use `specmod()` in the 
> past if you wanted to directly modify a `ImageBuf` in the before time and as 
> `spec()` now returns a reference `specmod()` seems somewhat redundant.
> 
> Many thanks,
> Alister

--
Larry Gritz
l...@larrygritz.com




_______________________________________________
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to