bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Lifting size limitation on X-to-GS copy & paste (was Re: [bug #4658] Bro


From: Kazunobu Kuriyama
Subject: Lifting size limitation on X-to-GS copy & paste (was Re: [bug #4658] Broken gpbs when doing pb operations between GS and X)
Date: Sat, 09 Aug 2003 04:06:01 +0900
User-agent: Mozilla/5.0 (X11; U; Linux i686; ja-JP; rv:1.4) Gecko/20030624 Netscape/7.1

Hi,

Attached is the patch fixing the bug that is pointed out by part of
the bug report #4658:

2. It is not possible to copy from X and paste in GNUstep strings longer than 1024 characters.

The patch is slightly better in memory management (preventing possible
memory leak resulting from an error) than the one I sent a few hours ago.
2003-08-09  Kazunobu Kuriyama  <kazunobu.kuriyama@nifty.com>

        * Tools/xpbs.m ([XPbOwner -xSelectionNotify:]): Lift the size
        limitation imposed on XGetWindowProperty().

--- xpbs.m      2003-08-09 03:41:55.000000000 +0900
+++ xpbs.m.rev  2003-08-09 03:41:41.000000000 +0900
@@ -711,6 +711,7 @@
   int          actual_format;
   unsigned long        bytes_remaining;
   unsigned long        number_items;
+  long         full_length;
 
   if ([self waitingForSelection] > xEvent->time)
     {
@@ -722,62 +723,70 @@
   /*
    * Read data from property identified in SelectionNotify event.
    */
-  status = XGetWindowProperty(xDisplay,
-                               xEvent->requestor,
-                               xEvent->property,
-                               0L,                             // offset
-                               FULL_LENGTH,
-                               True,               // Delete prop when read.
-                               new_target,
-                               &actual_target,
-                               &actual_format,
-                               &number_items,
-                               &bytes_remaining,
-                               &data);
+  full_length = FULL_LENGTH;
+  bytes_remaining = 0;
+  data = NULL;
+  do
+    {
+      status = XGetWindowProperty(xDisplay,
+                                 xEvent->requestor,
+                                 xEvent->property,
+                                 0L,                 // offset
+                                 full_length,
+                                 True,               // Delete prop when read.
+                                 new_target,
+                                 &actual_target,
+                                 &actual_format,
+                                 &number_items,
+                                 &bytes_remaining,
+                                 &data);
+
+      if (status != Success ||
+         actual_target == None ||
+         actual_format == 0 ||
+         number_items == 0 ||
+         actual_target != new_target)
+       {
+         NSLog(@"Unsupported data type from X selection.");
+         break;
+       }
+      else if (bytes_remaining > 0)
+       {
+         if (data)
+           {
+             XFree(data);
+             data = NULL;
+           }
+         full_length *= 2;
+       }
+    }
+  while (bytes_remaining > 0);
 
-  if ((status == Success) && (number_items > 0))
+  if (status == Success && actual_target == new_target && number_items > 0)
     {
-// Convert data to text string.
-// string = PropertyToString(xDisplay,new_target,number_items,(char*)data);
+      NSData   *d;
+      NSString *s;
 
+      d = [[NSData alloc] initWithBytes: (void *)data
+                                length: number_items];
 #ifdef X_HAVE_UTF8_STRING
-      if (actual_target == XG_UTF8_STRING)
-       {
-         NSData        *d;
-         NSString      *s;
-
-         d = [[NSData alloc] initWithBytes: (void *)data
-                                    length: number_items];
-         s = [[NSString alloc] initWithData: d
-                                   encoding: NSUTF8StringEncoding];
-         RELEASE(d);
-         d = [NSSerializer serializePropertyList: s];
-         RELEASE(s);
-         [self setData: d];
-       }
+      s = [[NSString alloc] initWithData: d
+                               encoding: NSUTF8StringEncoding];
 #else // X_HAVE_UTF8_STRING not defined
-      if (new_target == XA_STRING)
-       {
-         NSData        *d;
-         NSString      *s;
-
-         d = [[NSData alloc] initWithBytes: (void*)data 
-                             length: number_items];
-         s = [[NSString alloc] initWithData: d
-                               encoding: NSISOLatin1StringEncoding];
-         RELEASE(d);
-         d = [NSSerializer serializePropertyList: s];
-         RELEASE(s);
-         [self setData: d];
-       }
+      s = [[NSString alloc] initWithData: d
+                               encoding: NSISOLatin1StringEncoding];
 #endif // X_HAVE_UTF8_STRING not defined
-      else
-       {
-         NSLog(@"Unsupported data type from X selection.");
-       }
+      RELEASE(d);
+      d = [NSSerializer serializePropertyList: s];
+      RELEASE(s);
+      [self setData: d];
+
+    }
 
-      if (data)
-       XFree(data);
+  if (data)
+    {
+      XFree(data);
+      data = NULL;
     }
 }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]