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: gdk-event-string and NULL
Date: Tue, 05 Aug 2003 00:42:00 -0000	[thread overview]
Message-ID: <87vftd0wb0.fsf@zip.com.au> (raw)

[-- 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 *

                 reply	other threads:[~2003-08-05  0:42 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=87vftd0wb0.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).