Commit 2d1fc3c7 authored by Paul Eggert's avatar Paul Eggert
Browse files

* dbusbind.c: Use XFASTINT rather than XUINT, and check for nonneg.

(Fdbus_call_method, Fdbus_call_method_asynchronously):
Use XFASTINT rather than XUINT when numbers are nonnegative.
(xd_append_arg, Fdbus_method_return_internal):
(Fdbus_method_error_internal): Likewise.  Also, for unsigned
arguments, check that Lisp number is nonnegative, rather than
silently wrapping negative numbers around.
parent c8a9ca5a
2011-05-24 Paul Eggert <eggert@cs.ucla.edu> 2011-05-24 Paul Eggert <eggert@cs.ucla.edu>
* dbusbind.c: Use XFASTINT rather than XUINT, and check for nonneg.
(Fdbus_call_method, Fdbus_call_method_asynchronously):
Use XFASTINT rather than XUINT when numbers are nonnegative.
(xd_append_arg, Fdbus_method_return_internal):
(Fdbus_method_error_internal): Likewise. Also, for unsigned
arguments, check that Lisp number is nonnegative, rather than
silently wrapping negative numbers around.
* data.c (arith_driver, Flsh): Avoid unnecessary casts to EMACS_UINT. * data.c (arith_driver, Flsh): Avoid unnecessary casts to EMACS_UINT.
2011-05-23 Paul Eggert <eggert@cs.ucla.edu> 2011-05-23 Paul Eggert <eggert@cs.ucla.edu>
......
...@@ -431,9 +431,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) ...@@ -431,9 +431,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
switch (dtype) switch (dtype)
{ {
case DBUS_TYPE_BYTE: case DBUS_TYPE_BYTE:
CHECK_NUMBER (object); CHECK_NATNUM (object);
{ {
unsigned char val = XUINT (object) & 0xFF; unsigned char val = XFASTINT (object) & 0xFF;
XD_DEBUG_MESSAGE ("%c %d", dtype, val); XD_DEBUG_MESSAGE ("%c %d", dtype, val);
if (!dbus_message_iter_append_basic (iter, dtype, &val)) if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object); XD_SIGNAL2 (build_string ("Unable to append argument"), object);
...@@ -460,9 +460,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) ...@@ -460,9 +460,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
} }
case DBUS_TYPE_UINT16: case DBUS_TYPE_UINT16:
CHECK_NUMBER (object); CHECK_NATNUM (object);
{ {
dbus_uint16_t val = XUINT (object); dbus_uint16_t val = XFASTINT (object);
XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val); XD_DEBUG_MESSAGE ("%c %u", dtype, (unsigned int) val);
if (!dbus_message_iter_append_basic (iter, dtype, &val)) if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object); XD_SIGNAL2 (build_string ("Unable to append argument"), object);
...@@ -483,9 +483,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) ...@@ -483,9 +483,9 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
#ifdef DBUS_TYPE_UNIX_FD #ifdef DBUS_TYPE_UNIX_FD
case DBUS_TYPE_UNIX_FD: case DBUS_TYPE_UNIX_FD:
#endif #endif
CHECK_NUMBER (object); CHECK_NATNUM (object);
{ {
dbus_uint32_t val = XUINT (object); dbus_uint32_t val = XFASTINT (object);
XD_DEBUG_MESSAGE ("%c %u", dtype, val); XD_DEBUG_MESSAGE ("%c %u", dtype, val);
if (!dbus_message_iter_append_basic (iter, dtype, &val)) if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object); XD_SIGNAL2 (build_string ("Unable to append argument"), object);
...@@ -503,10 +503,10 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter) ...@@ -503,10 +503,10 @@ xd_append_arg (unsigned int dtype, Lisp_Object object, DBusMessageIter *iter)
} }
case DBUS_TYPE_UINT64: case DBUS_TYPE_UINT64:
CHECK_NUMBER (object); CHECK_NATNUM (object);
{ {
dbus_uint64_t val = XUINT (object); dbus_uint64_t val = XFASTINT (object);
XD_DEBUG_MESSAGE ("%c %"pI"u", dtype, XUINT (object)); XD_DEBUG_MESSAGE ("%c %"pI"d", dtype, XFASTINT (object));
if (!dbus_message_iter_append_basic (iter, dtype, &val)) if (!dbus_message_iter_append_basic (iter, dtype, &val))
XD_SIGNAL2 (build_string ("Unable to append argument"), object); XD_SIGNAL2 (build_string ("Unable to append argument"), object);
return; return;
...@@ -1110,7 +1110,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI ...@@ -1110,7 +1110,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI
if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout))) if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout)))
{ {
CHECK_NATNUM (args[i+1]); CHECK_NATNUM (args[i+1]);
timeout = XUINT (args[i+1]); timeout = XFASTINT (args[i+1]);
i = i+2; i = i+2;
} }
...@@ -1186,7 +1186,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI ...@@ -1186,7 +1186,7 @@ usage: (dbus-call-method BUS SERVICE PATH INTERFACE METHOD &optional :timeout TI
/* Return the result. If there is only one single Lisp object, /* Return the result. If there is only one single Lisp object,
return it as-it-is, otherwise return the reversed list. */ return it as-it-is, otherwise return the reversed list. */
if (XUINT (Flength (result)) == 1) if (XFASTINT (Flength (result)) == 1)
RETURN_UNGCPRO (CAR_SAFE (result)); RETURN_UNGCPRO (CAR_SAFE (result));
else else
RETURN_UNGCPRO (Fnreverse (result)); RETURN_UNGCPRO (Fnreverse (result));
...@@ -1292,7 +1292,7 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE ...@@ -1292,7 +1292,7 @@ usage: (dbus-call-method-asynchronously BUS SERVICE PATH INTERFACE METHOD HANDLE
if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout))) if ((i+2 <= nargs) && (EQ ((args[i]), QCdbus_timeout)))
{ {
CHECK_NATNUM (args[i+1]); CHECK_NATNUM (args[i+1]);
timeout = XUINT (args[i+1]); timeout = XFASTINT (args[i+1]);
i = i+2; i = i+2;
} }
...@@ -1382,11 +1382,11 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */) ...@@ -1382,11 +1382,11 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
serial = args[1]; serial = args[1];
service = args[2]; service = args[2];
CHECK_NUMBER (serial); CHECK_NATNUM (serial);
CHECK_STRING (service); CHECK_STRING (service);
GCPRO3 (bus, serial, service); GCPRO3 (bus, serial, service);
XD_DEBUG_MESSAGE ("%"pI"u %s ", XUINT (serial), SDATA (service)); XD_DEBUG_MESSAGE ("%"pI"d %s ", XFASTINT (serial), SSDATA (service));
/* Open a connection to the bus. */ /* Open a connection to the bus. */
connection = xd_initialize (bus, TRUE); connection = xd_initialize (bus, TRUE);
...@@ -1394,7 +1394,7 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */) ...@@ -1394,7 +1394,7 @@ usage: (dbus-method-return-internal BUS SERIAL SERVICE &rest ARGS) */)
/* Create the message. */ /* Create the message. */
dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_RETURN); dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_METHOD_RETURN);
if ((dmessage == NULL) if ((dmessage == NULL)
|| (!dbus_message_set_reply_serial (dmessage, XUINT (serial))) || (!dbus_message_set_reply_serial (dmessage, XFASTINT (serial)))
|| (!dbus_message_set_destination (dmessage, SSDATA (service)))) || (!dbus_message_set_destination (dmessage, SSDATA (service))))
{ {
UNGCPRO; UNGCPRO;
...@@ -1470,11 +1470,11 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */) ...@@ -1470,11 +1470,11 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
serial = args[1]; serial = args[1];
service = args[2]; service = args[2];
CHECK_NUMBER (serial); CHECK_NATNUM (serial);
CHECK_STRING (service); CHECK_STRING (service);
GCPRO3 (bus, serial, service); GCPRO3 (bus, serial, service);
XD_DEBUG_MESSAGE ("%"pI"u %s ", XUINT (serial), SDATA (service)); XD_DEBUG_MESSAGE ("%"pI"d %s ", XFASTINT (serial), SSDATA (service));
/* Open a connection to the bus. */ /* Open a connection to the bus. */
connection = xd_initialize (bus, TRUE); connection = xd_initialize (bus, TRUE);
...@@ -1483,7 +1483,7 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */) ...@@ -1483,7 +1483,7 @@ usage: (dbus-method-error-internal BUS SERIAL SERVICE &rest ARGS) */)
dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR); dmessage = dbus_message_new (DBUS_MESSAGE_TYPE_ERROR);
if ((dmessage == NULL) if ((dmessage == NULL)
|| (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED)) || (!dbus_message_set_error_name (dmessage, DBUS_ERROR_FAILED))
|| (!dbus_message_set_reply_serial (dmessage, XUINT (serial))) || (!dbus_message_set_reply_serial (dmessage, XFASTINT (serial)))
|| (!dbus_message_set_destination (dmessage, SSDATA (service)))) || (!dbus_message_set_destination (dmessage, SSDATA (service))))
{ {
UNGCPRO; UNGCPRO;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment