* don't scm_must_malloc temp memory
@ 2003-09-09 23:43 Kevin Ryde
0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2003-09-09 23:43 UTC (permalink / raw)
To: guile-gtk
[-- Attachment #1: Type: text/plain, Size: 567 bytes --]
With this change gdk-mbstowcs actually works.
* gdk-support.c (gdk_property_change_list, gdk_property_change_vector,
gdk_mbstowcs_interp, gdk_colormap_alloc_colors_interp): Use g_new
rather than scm_must_malloc for temporary memory, since it's not
subject to gc the way scm_must_malloc is meant to express, and
negatives don't work with scm_done_malloc in Guile 1.6.4.
gdk_property_change_list and gdk_property_change_vector were in fact
missing scm_done_malloc, making scm_mallocated increase indefinitely.
[-- Attachment #2: gdk-support.c.must-malloc.diff --]
[-- Type: text/plain, Size: 4432 bytes --]
--- gdk-support.c.~1.44.~ 1970-01-01 10:00:01.000000000 +1000
+++ gdk-support.c 2003-09-09 15:58:53.000000000 +1000
@@ -66,34 +66,31 @@
if (nelements < 1) BAD_DATA (data);
switch (format) {
case 8:
- dc = duchar = (guchar *) scm_must_malloc (nelements * sizeof *duchar,
- "temporary data");
+ dc = duchar = g_new (guchar, nelements);
for (; SCM_CONSP (data); data = SCM_CDR (data))
*dc++ = scm_num2long (SCM_CAR (data), SCM_ARG6, FUNCNAME);
if (!SCM_NULLP (data)) BAD_DATA (data);
gdk_property_change (window, property, type, format, mode,
duchar, nelements);
- free (duchar);
+ g_free (duchar);
break;
case 16:
- ds = dushort = (gushort *) scm_must_malloc (nelements * sizeof *dushort,
- "temporary data");
+ ds = dushort = g_new (gushort, nelements);
for (; SCM_CONSP (data); data = SCM_CDR (data))
*ds++ = scm_num2long (SCM_CAR (data), SCM_ARG6, FUNCNAME);
if (!SCM_NULLP (data)) BAD_DATA (data);
gdk_property_change (window, property, type, format, mode,
(guchar *) dushort, nelements);
- free (dushort);
+ g_free (dushort);
break;
case 32:
- dl = dulong = (gulong *) scm_must_malloc (nelements * sizeof *dulong,
- "temporary data");
+ dl = dulong = g_new (gulong, nelements);
for (; SCM_CONSP (data); data = SCM_CDR (data))
*dl++ = scm_num2long (SCM_CAR (data), SCM_ARG6, FUNCNAME);
if (!SCM_NULLP (data)) BAD_DATA (data);
gdk_property_change (window, property, type, format, mode,
(guchar *) dulong, nelements);
- free (dulong);
+ g_free (dulong);
break;
default:
BAD_FORMAT (format);
@@ -112,34 +109,31 @@
SCM *velts = SCM_VELTS (data);
switch (format) {
case 8:
- dc = duchar = (guchar *) scm_must_malloc (nelements * sizeof *duchar,
- "temporary data");
+ dc = duchar = g_new (guchar, nelements);
for (i = 0; i < nelements; i++)
*dc++ = scm_num2long (velts[i], SCM_ARG6, FUNCNAME);
if (!SCM_NULLP (data)) BAD_DATA (data);
gdk_property_change (window, property, type, format, mode,
duchar, nelements);
- free (duchar);
+ g_free (duchar);
break;
case 16:
- ds = dushort = (gushort *) scm_must_malloc (nelements * sizeof *dushort,
- "temporary data");
+ ds = dushort = g_new (gushort, nelements);
for (i = 0; i < nelements; i++)
*ds++ = scm_num2long (velts[i], SCM_ARG6, FUNCNAME);
if (!SCM_NULLP (data)) BAD_DATA (data);
gdk_property_change (window, property, type, format, mode,
(guchar *) dushort, nelements);
- free (dushort);
+ g_free (dushort);
break;
case 32:
- dl = dulong = (gulong *) scm_must_malloc (nelements * sizeof *dulong,
- "temporary data");
+ dl = dulong = g_new (gulong, nelements);
for (i = 0; i < nelements; i++)
*dl++ = scm_num2long (velts[i], SCM_ARG6, FUNCNAME);
if (!SCM_NULLP (data)) BAD_DATA (data);
gdk_property_change (window, property, type, format, mode,
(guchar *) dulong, nelements);
- free (dulong);
+ g_free (dulong);
break;
default:
BAD_FORMAT (format);
@@ -1038,8 +1032,7 @@
gint rv,i;
GdkWChar *space;
gint length = strlen (src);
- size_t size = (length + 1) * sizeof (GdkWChar);
- space = (GdkWChar *) scm_must_malloc (size, "temporary GdkWChar array");
+ space = g_new (GdkWChar, length + 1);
rv = gdk_mbstowcs (space, src, length + 1);
if (rv < 0) {
free (space);
@@ -1049,8 +1042,7 @@
vector = scm_c_make_vector (i, SCM_UNSPECIFIED);
for (i = 0; i < length && space[i]; i++)
SCM_VECTOR_SET (vector, i, scm_long2num (space[i]));
- free (space);
- scm_done_malloc (-size);
+ g_free (space);
return vector;
}
@@ -1359,10 +1351,8 @@
gboolean *success,*sp;
SCM flist,flast;
int i;
- size_t size;
cvec = sgtk_scm2cvec (colors, sgtk_color_copy, sizeof (GdkColor));
- size = cvec.count * sizeof (gboolean);
- success = (gboolean *) scm_must_malloc (size, "temporary gboolean array");
+ success = g_new (gboolean, cvec.count);
failures = gdk_colormap_alloc_colors (colormap, (GdkColor *) cvec.vec,
cvec.count, writable, best_match,
success);
@@ -1380,8 +1370,7 @@
sgtk_append_element (&flist, &flast, SCM_VELTS (colors)[i]);
failures--;
}
- free (success);
- scm_done_malloc (-size);
+ g_free (success);
free (cvec.vec);
return flist;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-09-09 23:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-09 23:43 don't scm_must_malloc temp memory Kevin Ryde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).