From: Jan Moringen <jan.moringen@uni-bielefeld.de>
To: emacs-devel@gnu.org
Subject: Automatic value conversion in DBus bindings
Date: Mon, 27 Jul 2009 04:44:21 +0200 [thread overview]
Message-ID: <22440_1248662818_ZZg0A4O3jD8Bt.00_1248662661.13837.61.camel@localhost.localdomain> (raw)
[-- Attachment #1: Type: text/plain, Size: 1850 bytes --]
While playing around with the DBus bindings, I came across some problems
related to the automatic conversion between LISP and DBus values.
The first problem can be demonstrated by running the following code:
(require 'dbus)
(defun test ()
nil)
(dbus-register-method
:session "org.gnu.emacs" "/org/gnu/emacs" "org.gnu.Emacs" "test"
#'test)
(dbus-call-method-non-blocking
:session "org.gnu.emacs" "/org/gnu/emacs" "org.gnu.Emacs" "test")
The last call never returns. The problem is in
`dbus-call-method-non-blocking':
(while (not (gethash key dbus-return-values-table nil))
(read-event nil nil 0.1))
Here, the return value nil cannot be distinguished from "no return value
yet". A suggestion for a fix is in the attached patch.
I am writing to emacs-devel rather than reporting a bug because I think
the fix for this particular problem should be accompanied by a small
change of the DBus interface. The original motivation for my experiments
was writing a function that should receive DBus calls but not return a
value. This was necessary since another process (Empathy) would call the
method via DBus and complain if it returned anything.
The current LISP -> DBus conversion rules make it impossible (from what
I understand at least) to not return a value, since an empty list, which
would represent zero return values, is interpreted as a single 'false'
value. I think this special treatment of values that are null or not
lists should be removed, thus always requiring a list as the return
value of a DBus-invokable function. This change is also included in the
attached patch. Note that the documentation would need corresponding
changes.
Since the proposed changes could break existing software, a different
approach may be better. I would be glad to here opinions on the subject.
Kind regards,
Jan Moringen
[-- Attachment #2: emacs-dbus-return-values.patch --]
[-- Type: text/x-patch, Size: 1253 bytes --]
--- lisp/net/dbus.el.orig 2009-01-28 17:10:02.000000000 +0100
+++ list/net/dbus.el 2009-07-27 03:18:10.429481853 +0200
@@ -162,7 +162,7 @@
The result will be made available in `dbus-return-values-table'."
(puthash (list (dbus-event-bus-name last-input-event)
(dbus-event-serial-number last-input-event))
- (if (= (length args) 1) (car args) args)
+ args
dbus-return-values-table))
(defun dbus-call-method-non-blocking
@@ -184,8 +184,9 @@
'dbus-call-method-non-blocking-handler args)))
;; Wait until `dbus-call-method-non-blocking-handler' has put the
;; result into `dbus-return-values-table'.
- (while (not (gethash key dbus-return-values-table nil))
- (read-event nil nil 0.1))
+ (let ((marker (make-symbol "marker")))
+ (while (eq (gethash key dbus-return-values-table marker) marker)
+ (read-event nil nil 0.1)))
;; Cleanup `dbus-return-values-table'. Return the result.
(prog1
@@ -370,7 +371,7 @@
(dbus-ignore-errors
(apply 'dbus-method-return-internal
(nth 1 event) (nth 3 event) (nth 4 event)
- (if (consp result) result (list result))))))
+ result))))
;; Error handling.
(dbus-error
;; Return an error message when it is a message call.
next reply other threads:[~2009-07-27 2:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-27 2:44 Jan Moringen [this message]
2009-07-27 4:43 ` Automatic value conversion in DBus bindings Michael Albinus
2009-07-27 5:49 ` Jan Moringen
2009-07-27 10:19 ` Michael Albinus
2009-07-27 18:18 ` Jan Moringen
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=22440_1248662818_ZZg0A4O3jD8Bt.00_1248662661.13837.61.camel@localhost.localdomain \
--to=jan.moringen@uni-bielefeld.de \
--cc=emacs-devel@gnu.org \
/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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.