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 501853 - g_checksum_get_digest docs
g_checksum_get_digest docs
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal trivial
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-12-05 18:43 UTC by Christian Persch
Modified: 2007-12-20 15:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (5.43 KB, patch)
2007-12-19 14:39 UTC, Christian Persch
reviewed Details | Review

Description Christian Persch 2007-12-05 18:43:39 UTC
The docs for g_checksum_get_digest don't mention that the data returned in the |digest| location needs to be g_free'd after use. And it also should note that one needs to initialise it to NULL before the function call.

(Also IMHO a signature like

guint8 *g_checksum_get_digest (GChecksum*, gsize *len)

would have been more natural for this function.)
Comment 1 Matthias Clasen 2007-12-07 16:14:30 UTC
I also wonder what the motivation is for the descrepancy between
get_digest (which returns allocated memory) and
get_string (where the checksum retains ownership of the memory)
Comment 2 Emmanuele Bassi (:ebassi) 2007-12-07 16:27:30 UTC
(In reply to comment #0)
> The docs for g_checksum_get_digest don't mention that the data returned in the
> |digest| location needs to be g_free'd after use. And it also should note that
> one needs to initialise it to NULL before the function call.

yeah, my fault. I'll update the documentation.

> (Also IMHO a signature like
> 
> guint8 *g_checksum_get_digest (GChecksum*, gsize *len)
> 
> would have been more natural for this function.)

I really wish you had commented on bug 443648 - now I have to dig out why I did that. :-)

the get_digest() function original signature was:

  boolean get_digest (out byte digest, out size_t len)

but back then the function had the ability to fail, so I guess it just remained like that even though I removed the boolean return value.

as I said on bug 443648, I have no strong feelings on the get_digest() API so it can be changed to

  guint8* g_checksum_get_digest (GChecksum *checksum,
                                 gsize     *digest_len);

as far as I'm concerned.

(In reply to comment #1)
> I also wonder what the motivation is for the descrepancy between
> get_digest (which returns allocated memory) and
> get_string (where the checksum retains ownership of the memory)

get_digest() copies the contents of the digest buffer, while get_string() just returns a pointer to the internal data. instead of copying using allocated memory I guess it could take a guint8** and memcpy() the buffer.
Comment 3 Christian Persch 2007-12-19 14:39:41 UTC
Created attachment 101254 [details] [review]
proposed patch

Add g_checksum_type_get_length().
Change g_checksum_get_digest to use a passed-in buffer instead of allocating memory.
Comment 4 Emmanuele Bassi (:ebassi) 2007-12-19 14:44:09 UTC
the patch looks fine for me
Comment 5 Matthias Clasen 2007-12-19 15:36:57 UTC
I wonder if the g_assert_not_reached () is optimal in the switch statements, considering we may expand the enum later. How about we make get_length() 
return -1 in that case, and document that to mean "type not supported" ?

Other than that, looks fine.
Comment 6 Christian Persch 2007-12-19 18:57:33 UTC
        * glib/gchecksum.c: (g_checksum_type_get_length),
        (g_checksum_get_digest):
        * glib/gchecksum.h:
        * glib/glib.symbols:
        * tests/checksum-test.c: (test_checksum): Add
        g_checksum_type_get_length, and change g_checksum_get_digest to use a
        provided buffer instead of returning allocated memory. Bug #501853.


Should g_checksum_new return NULL for unsupported types, instead of the current g_return_val_if_fail() ?
Comment 7 Matthias Clasen 2007-12-20 15:15:58 UTC
2007-12-20  Matthias Clasen  <mclasen@redhat.com>

        * glib/gchecksum.[hc] (g_checksum_new): Return NULL when
        the checksum_type is unknown.  (#501853)