unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Automatic value conversion in DBus bindings
@ 2009-07-27  2:44 Jan Moringen
  2009-07-27  4:43 ` Michael Albinus
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Moringen @ 2009-07-27  2:44 UTC (permalink / raw)
  To: emacs-devel

[-- 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-07-27 18:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-27  2:44 Automatic value conversion in DBus bindings Jan Moringen
2009-07-27  4:43 ` Michael Albinus
2009-07-27  5:49   ` Jan Moringen
2009-07-27 10:19     ` Michael Albinus
2009-07-27 18:18       ` Jan Moringen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).