public inbox for guile-gtk@sourceware.org
 help / color / mirror / Atom feed
* gdk-event-string and NULL
@ 2003-08-05  0:42 Kevin Ryde
  0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2003-08-05  0:42 UTC (permalink / raw)
  To: guile-gtk

[-- Attachment #1: Type: text/plain, Size: 755 bytes --]

I propose to made a change,

        * gdk-1.2.defs, gdk-support.c (gdk_event_string): Return #f for
        key.string == NULL as occurs for GDK_KEY_RELEASE, previously returned
        an empty string, but only due to a of 0 bytes from NULL.  Use
        scm_mem2string to return whole key.length, since string can contain
        '\0' bytes.

I think this can be regarded as a bug fix.  Returning an empty string
for GDK_KEY_RELEASE looks like only a happy coincidence, not an
intended feature.  Certainly #f for NULL corresponds to the general
behaviour in other places.

I think it's unlikely anyone would be depending on an empty string,
since it's the key press where one is interested in the string,
there's nothing useful to get on the release.


[-- Attachment #2: gdk-support.c.event-string.diff --]
[-- Type: text/plain, Size: 967 bytes --]

--- gdk-support.c.~1.30.~	2003-08-05 10:32:59.000000000 +1000
+++ gdk-support.c	2003-08-05 10:38:34.000000000 +1000
@@ -548,22 +548,22 @@
     }
 }
 
-gchar *
+/* key.string should be NULL in GDK_KEY_RELEASE and non-NULL in
+   GDK_KEY_PRESS, but there's no need to be concerned about that, just
+   return a string or #f according to what the field contains.  */
+SCM
 gdk_event_string (GdkEvent *event)
 {
-  switch (event->any.type)
-    {
-    case GDK_KEY_PRESS:
-    case GDK_KEY_RELEASE:
-      {
-	gchar *str = g_malloc (event->key.length+1);
-	strncpy (str, event->key.string, event->key.length);
-	str[event->key.length] = '\0';
-	return str;
-      }
-    default:
-      return NULL;
-    }
+  switch (event->any.type) {
+  case GDK_KEY_PRESS:
+  case GDK_KEY_RELEASE:
+    if (event->key.string != NULL)
+      return scm_mem2string (event->key.string, event->key.length);
+    break;
+  default:
+    break;
+  }
+  return SCM_BOOL_F;
 }
 
 GdkWindow *

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-08-05  0:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-05  0:42 gdk-event-string and NULL 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).