public inbox for guile-gtk@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: guile-gtk@sources.redhat.com
Subject: don't scm_must_malloc temp memory
Date: Tue, 09 Sep 2003 23:43:00 -0000	[thread overview]
Message-ID: <8765k1sf3c.fsf@zip.com.au> (raw)

[-- 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;
 }

                 reply	other threads:[~2003-09-09 23:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8765k1sf3c.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=guile-gtk@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).