#define X_SHRT_MIN (-1 - X_SHRT_MAX)
#define X_LONG_MAX 0x7fffffff
#define X_LONG_MIN (-1 - X_LONG_MAX)
+#define X_ULONG_MAX 0xffffffffUL
/* If this is a smaller number than the max-request-size of the display,
emacs will use INCR selection transfer when the selection is larger
\f
/* Given a selection-name and desired type, look up our local copy of
the selection value and convert it to the type.
- The value is nil or a string.
+ Return nil, a string, a vector, a symbol, an integer, or a cons
+ that CONS_TO_INTEGER could plausibly handle.
This function is used both for remote requests (LOCAL_REQUEST is zero)
and for local x-get-selection-internal (LOCAL_REQUEST is nonzero).
}
}
+/* Convert OBJ to an X long value, and return it as unsigned long.
+ OBJ should be an integer or a cons representing an integer.
+ Treat values in the range X_LONG_MAX + 1 .. X_ULONG_MAX as X
+ unsigned long values: in theory these values are supposed to be
+ signed but in practice unsigned 32-bit data are communicated via X
+ selections and we need to support that. */
+static unsigned long
+cons_to_x_long (Lisp_Object obj)
+{
+ if (X_ULONG_MAX <= INTMAX_MAX
+ || XINT (INTEGERP (obj) ? obj : XCAR (obj)) < 0)
+ return cons_to_signed (obj, X_LONG_MIN, min (X_ULONG_MAX, INTMAX_MAX));
+ else
+ return cons_to_unsigned (obj, X_ULONG_MAX);
+}
/* Use xfree, not XFree, to free the data obtained with this function. */
|| (CONSP (XCDR (obj))
&& INTEGERP (XCAR (XCDR (obj)))))))
{
- *data_ret = (unsigned char *) xmalloc (sizeof (long) + 1);
+ *data_ret = (unsigned char *) xmalloc (sizeof (unsigned long) + 1);
*format_ret = 32;
*size_ret = 1;
- (*data_ret) [sizeof (long)] = 0;
- (*(long **) data_ret) [0] = cons_to_signed (obj, X_LONG_MIN, X_LONG_MAX);
+ (*data_ret) [sizeof (unsigned long)] = 0;
+ (*(unsigned long **) data_ret) [0] = cons_to_x_long (obj);
if (NILP (type)) type = QINTEGER;
}
else if (VECTORP (obj))
if (NILP (type)) type = QINTEGER;
for (i = 0; i < size; i++)
{
- intmax_t v = cons_to_signed (XVECTOR (obj)->contents[i],
- X_LONG_MIN, X_LONG_MAX);
- if (X_SHRT_MIN <= v && v <= X_SHRT_MAX)
+ if (! RANGED_INTEGERP (X_SHRT_MIN, XVECTOR (obj)->contents[i],
+ X_SHRT_MAX))
{
/* Use sizeof (long) even if it is more than 32 bits.
See comment in x_get_window_property and
x_fill_property_data. */
data_size = sizeof (long);
format = 32;
+ break;
}
}
*data_ret = xnmalloc (size, data_size);
*size_ret = size;
for (i = 0; i < size; i++)
{
- long v = cons_to_signed (XVECTOR (obj)->contents[i],
- X_LONG_MIN, X_LONG_MAX);
if (format == 32)
- (*((long **) data_ret)) [i] = v;
+ (*((unsigned long **) data_ret)) [i] =
+ cons_to_x_long (XVECTOR (obj)->contents[i]);
else
- (*((short **) data_ret)) [i] = v;
+ (*((short **) data_ret)) [i] =
+ XINT (XVECTOR (obj)->contents[i]);
}
}
}