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 332312 - [PATCH] g_unicode_canonical_decomposition_to_buffer function
[PATCH] g_unicode_canonical_decomposition_to_buffer function
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: i18n
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2006-02-23 11:52 UTC by Jorn Baayen
Modified: 2012-06-13 11:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (3.06 KB, patch)
2006-02-23 11:52 UTC, Jorn Baayen
none Details | Review
Fixes an issue in the prev one (3.07 KB, patch)
2006-02-23 12:03 UTC, Jorn Baayen
needs-work Details | Review
Testcase (789 bytes, text/plain)
2006-03-02 09:30 UTC, Jorn Baayen
  Details
Patch with requested changes (5.09 KB, patch)
2007-09-17 12:12 UTC, Jorn Baayen
none Details | Review
Rename 'malloc' variable to 'do_malloc'. (5.80 KB, patch)
2009-11-09 09:19 UTC, Jorn Baayen
none Details | Review
0001-Minor-fixes-to-new-g_unicode_canonical_decomposition.patch (4.94 KB, patch)
2010-03-05 14:24 UTC, Claudio Saavedra
none Details | Review

Description Jorn Baayen 2006-02-23 11:52:01 UTC
g_unicode_canonical_decomposition malloc()s, which is not great when used in loops. Attached patch introduces a g_unicode_canonical_decomposition_to_buffer() function which does the same thing as g_unicode_canonical_decomposition(), but to a buffer.
Comment 1 Jorn Baayen 2006-02-23 11:52:22 UTC
Created attachment 59995 [details] [review]
Patch
Comment 2 Jorn Baayen 2006-02-23 12:03:53 UTC
Created attachment 59996 [details] [review]
Fixes an issue in the prev one
Comment 3 Behdad Esfahbod 2006-02-23 20:40:02 UTC
A probably more useful function is one that takes a GString and fills it in.
Comment 4 Jorn Baayen 2006-02-28 08:28:52 UTC
A GString still uses mallocs. I do not need to build a string at all, just inspect a string unichar by unichar.
Comment 5 Jorn Baayen 2006-03-02 09:30:45 UTC
Created attachment 60471 [details]
Testcase

A testcase for the patch.
Comment 6 Behdad Esfahbod 2007-09-14 20:19:08 UTC
If not anything else, the patch should avoid such code duplication.  Make both functions call another one, with a flag to malloc or not.
Comment 7 Jorn Baayen 2007-09-17 12:12:04 UTC
Created attachment 95725 [details] [review]
Patch with requested changes
Comment 8 Behdad Esfahbod 2009-11-02 05:08:08 UTC
Should not use 'malloc' as variable name.  I'll see if I can cleanup and commit this this week.
Comment 9 Behdad Esfahbod 2009-11-08 17:01:55 UTC
Instead of promising and not delivering, I'll promise to commit this if a finished patch is submitted :).
Comment 10 Jorn Baayen 2009-11-09 09:19:09 UTC
Created attachment 147259 [details] [review]
Rename 'malloc' variable to 'do_malloc'.
Comment 11 Behdad Esfahbod 2009-11-09 16:31:14 UTC
Needs to add new symbol to list of symbols and docs, but I can do that part.

Matthias, does this look good to go?
Comment 12 Matthias Clasen 2009-11-09 16:45:09 UTC
Not too fond of the real_g_ prefix. I'd prefer something like do_canconical_decomposition or decompose_canonically, but not a biggie. I'll let you pick...

And I wonder if we really need the separate do_malloc parameter. 
Can't out == NULL used to signal this ?


Other nitpicks: 

+ * @result_len: location to store the length of the return value.

Would be good to add a clarifying 'in bytes' - if it is in bytes after all. 
This line makes me think it is not:

-      r = g_malloc (*result_len * sizeof (gunichar));


Other than that, looks ok
Comment 13 Behdad Esfahbod 2009-11-09 16:56:34 UTC
Yeah, I'll do a cleanup/review before committing.  I was more interested in your opinion re the function name.
Comment 14 Claudio Saavedra 2010-03-05 14:24:28 UTC
Created attachment 155313 [details] [review]
0001-Minor-fixes-to-new-g_unicode_canonical_decomposition.patch

From b12038fdea2da56795917a7b24879fb5637dd779 Mon Sep 17 00:00:00 2001
From: Claudio Saavedra <csaavedra@igalia.com>
Date: Fri, 5 Mar 2010 16:15:23 +0200
Subject: [PATCH] Minor fixes to new g_unicode_canonical_decomposition_with_buffer()

Add it to the documentation, set its "Since:" mark, rename internal
method, get rid of unneeded parameter, minor documentation fixes,
and fix indentation.
---
 docs/reference/glib/glib-sections.txt |    1 +
 glib/gunidecomp.c                     |   61 ++++++++++++++++-----------------
 2 files changed, 31 insertions(+), 31 deletions(-)
Comment 15 Claudio Saavedra 2010-03-05 14:25:53 UTC
Above patch addresses concerns raised here and also fixes indentation and minor doc. issues.

(In reply to comment #12)
> Would be good to add a clarifying 'in bytes' - if it is in bytes after all. 
> This line makes me think it is not:
> 
> -      r = g_malloc (*result_len * sizeof (gunichar));

It's not in bytes, as far as I can tell.

I'd be glad to commit, since we have this patch in maemo and I'd like to get rid of it.
Comment 16 Behdad Esfahbod 2010-03-05 17:03:00 UTC
(In reply to comment #15)
> Above patch addresses concerns raised here and also fixes indentation and minor
> doc. issues.

Thanks.

> (In reply to comment #12)
> > Would be good to add a clarifying 'in bytes' - if it is in bytes after all. 
> > This line makes me think it is not:
> > 
> > -      r = g_malloc (*result_len * sizeof (gunichar));
> 
> It's not in bytes, as far as I can tell.

Then lets make it clearn in the docs that it's number of characters.

> I'd be glad to commit, since we have this patch in maemo and I'd like to get
> rid of it.

Fine with me.  Maybe while at it add a couple unit tests too?

Matthias?
Comment 17 Claudio Saavedra 2012-06-13 08:07:10 UTC
Going through some of my old patches.. does this make any sense or can I pull the plug on it? I won't have time to add unit tests unfortunately tho.
Comment 18 Behdad Esfahbod 2012-06-13 11:37:53 UTC
Oh I actually independently added something like this.  See:

gsize g_unichar_fully_decompose (gunichar  ch, 
                                 gboolean  compat, 
                                 gunichar *result, 
                                 gsize     result_len);