After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 711300 - Take a const foo * when we can warrant this behavior
Take a const foo * when we can warrant this behavior
Status: RESOLVED WONTFIX
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other All
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-11-02 17:39 UTC by Reynaldo H. Verdejo Pinochet
Modified: 2013-11-13 09:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
change implemented for GstBuffer getsize()s (2.97 KB, patch)
2013-11-02 17:39 UTC, Reynaldo H. Verdejo Pinochet
rejected Details | Review

Description Reynaldo H. Verdejo Pinochet 2013-11-02 17:39:28 UTC
Created attachment 258812 [details] [review]
change implemented for GstBuffer getsize()s

Some of the base API funcs like the GstBuffer's getsize()s ones could easily be reprotyped so they explicitly state they are going to leave the memory some of their params point to unchanged (the GstBuffer * ones in these cases).

Patch attached should be harmless and help the developer better predict these function's behavior regarding the passed on pointer's mem. Should also help
easily spot problems (in this regard and at compile time) with these function's
implementations.

Arguably trivial, I stumbled at this while porting a func that was getting
a const GstBuffer *foo and tried to get the size of it afterwards.
Comment 1 Tim-Philipp Müller 2013-11-11 16:01:41 UTC
I don't know if this makes sense in general, e.g. can we really guarantee that we will never have to take a lock on the buffer in future ? (taking a lock would modify the structure data, so would not really be const).

It should be obvious to anyone from the name already that this does not "modify" the buffer, so I don't really see the point of doing this either.
Comment 2 Reynaldo H. Verdejo Pinochet 2013-11-12 20:26:21 UTC
(In reply to comment #1)

I'm of course OK waiting for agreement on this one but unless
my English is wrong here, your two paragraphs are contradictory.
If it's obvious that these funcs won't modify the buffer then
we can and should guarantee (and enforce) this behavior. Using
const * seems like a correct way forward to ensure both.
Comment 3 Tim-Philipp Müller 2013-11-12 20:40:26 UTC
There's a strict sense of modifying the buffer (which the compiler might care about) , and a less strict sense (which the user might care about). Both are not necessarily the same.

For example: we might want cache the size in future. This might involve writes to the buffer struct in get_size(), but the user might not care about that because it doesn't touch anything visible to her.
Comment 4 Reynaldo H. Verdejo Pinochet 2013-11-12 21:08:53 UTC
I see but, wouldn't it make more sense to cache the
size only on functions that are actually meant to modify
the buffer's mem and are then expected to modify the
buffer size (if needed) in both the strict and non-strict
senses you mention? The idea of writing to anything on
a get_size() func keeps sounding wrong to me, API-wise
that is.

I must confess that I am missing a few implementation
details here (taking a look now) so sry if what I'm
saying or my understanding of what you meant is wrong.
Comment 5 Wim Taymans 2013-11-13 08:58:35 UTC
We have had problems in the past with using const for refcounted objects. In general, const works for simple structs and types but not so for objects.
Comment 6 Sebastian Dröge (slomo) 2013-11-13 09:00:24 UTC
Agreed, let's not do this then. We can do that once we upgrade to C++ and can use the mutable keyword in combination with const ;)