Merge branch 'mr524-followup' into 'main'

Make it more obvious that negative timeouts are handled correctly

See merge request dbus/dbus!525
This commit is contained in:
Simon McVittie 2025-05-23 10:36:45 +00:00
commit 6bba6c58c5
5 changed files with 22 additions and 13 deletions

View file

@ -83,10 +83,6 @@ void _dbus_connection_toggle_timeout_unlocked (DBusConnection
DBusTimeout *timeout,
dbus_bool_t enabled);
DBusConnection* _dbus_connection_new_for_transport (DBusTransport *transport);
void _dbus_connection_do_iteration_unlocked (DBusConnection *connection,
DBusPendingCall *pending,
unsigned int flags,
int timeout_milliseconds);
void _dbus_connection_close_possibly_shared (DBusConnection *connection);
void _dbus_connection_close_if_only_one_ref (DBusConnection *connection);

View file

@ -1085,7 +1085,7 @@ _dbus_connection_acquire_io_path (DBusConnection *connection,
if (connection->io_path_acquired)
{
if (timeout_milliseconds != -1)
if (timeout_milliseconds >= 0)
{
_dbus_verbose ("waiting %d for IO path to be acquirable\n",
timeout_milliseconds);
@ -1198,14 +1198,17 @@ _dbus_connection_release_io_path (DBusConnection *connection)
* @param flags iteration flags.
* @param timeout_milliseconds maximum blocking time, or -1 for no limit.
*/
void
static void
_dbus_connection_do_iteration_unlocked (DBusConnection *connection,
DBusPendingCall *pending,
unsigned int flags,
int timeout_milliseconds)
{
_dbus_verbose ("start\n");
/* All callers should have checked this */
_dbus_assert (timeout_milliseconds >= -1);
HAVE_LOCK_CHECK (connection);
if (connection->n_outgoing == 0)
@ -3694,6 +3697,9 @@ _dbus_connection_read_write_dispatch (DBusConnection *connection,
DBusDispatchStatus dstatus;
dbus_bool_t progress_possible;
/* All callers should have checked this */
_dbus_assert (timeout_milliseconds >= -1);
/* Need to grab a ref here in case we're a private connection and
* the user drops the last ref in a handler we call; see bug
* https://bugs.freedesktop.org/show_bug.cgi?id=15635

View file

@ -257,7 +257,7 @@ _dbus_condvar_wait (DBusCondVar *cond,
*
* @param cond the condition variable
* @param mutex the mutex
* @param timeout_milliseconds the maximum time to wait
* @param timeout_milliseconds the maximum time to wait, must be non-negative
* @returns #FALSE if the timeout occurred, #TRUE if not
*/
dbus_bool_t
@ -265,6 +265,8 @@ _dbus_condvar_wait_timeout (DBusCondVar *cond,
DBusCMutex *mutex,
int timeout_milliseconds)
{
_dbus_assert (timeout_milliseconds >= 0);
if (cond == NULL || mutex == NULL)
return TRUE;

View file

@ -42,7 +42,7 @@
struct DBusTimeout
{
int refcount; /**< Reference count */
int interval; /**< Timeout interval in milliseconds. */
int interval; /**< Timeout interval in milliseconds, always non-negative */
DBusTimeoutHandler handler; /**< Timeout handler. */
void *handler_data; /**< Timeout handler data. */
@ -56,11 +56,11 @@ struct DBusTimeout
/**
* Creates a new DBusTimeout, enabled by default.
* @param interval the timeout interval in milliseconds.
* @param interval the timeout interval in milliseconds, which must be non-negative
* @param handler function to call when the timeout occurs.
* @param data data to pass to the handler
* @param free_data_function function to be called to free the data.
* @returns the new DBusTimeout object,
* @returns the new DBusTimeout object, or #NULL if out of memory
*/
DBusTimeout*
_dbus_timeout_new (int interval,
@ -70,6 +70,8 @@ _dbus_timeout_new (int interval,
{
DBusTimeout *timeout;
_dbus_assert (interval >= 0);
timeout = dbus_new0 (DBusTimeout, 1);
if (timeout == NULL)
return NULL;
@ -134,7 +136,7 @@ _dbus_timeout_unref (DBusTimeout *timeout)
* but it cannot be used in conjunction with an application main loop.
*
* @param timeout the timeout
* @param interval the new interval
* @param interval the new interval, which must be non-negative
*/
void
_dbus_timeout_restart (DBusTimeout *timeout,
@ -438,7 +440,7 @@ _dbus_timeout_restarted (DBusTimeout *timeout)
* to notify you of the change.
*
* @param timeout the DBusTimeout object.
* @returns the interval in milliseconds.
* @returns the interval in milliseconds, which is always non-negative
*/
int
dbus_timeout_get_interval (DBusTimeout *timeout)

View file

@ -1003,6 +1003,9 @@ _dbus_transport_do_iteration (DBusTransport *transport,
unsigned int flags,
int timeout_milliseconds)
{
/* All callers should have checked this */
_dbus_assert (timeout_milliseconds >= -1);
_dbus_assert (transport->vtable->do_iteration != NULL);
_dbus_verbose ("Transport iteration flags 0x%x timeout %d connected = %d\n",