From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jan Moringen Newsgroups: gmane.emacs.devel Subject: Automatic value conversion in DBus bindings Date: Mon, 27 Jul 2009 04:44:21 +0200 Message-ID: <22440_1248662818_ZZg0A4O3jD8Bt.00_1248662661.13837.61.camel@localhost.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary_(ID_qz+w9gRrnU0oQYSHuwGw1g)" X-Trace: ger.gmane.org 1248663541 18886 80.91.229.12 (27 Jul 2009 02:59:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Jul 2009 02:59:01 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 27 04:58:54 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MVGQP-0005dv-Tb for ged-emacs-devel@m.gmane.org; Mon, 27 Jul 2009 04:58:54 +0200 Original-Received: from localhost ([127.0.0.1]:44554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MVGQP-0003Bm-Ei for ged-emacs-devel@m.gmane.org; Sun, 26 Jul 2009 22:58:53 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MVGF1-0005cb-U6 for emacs-devel@gnu.org; Sun, 26 Jul 2009 22:47:07 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MVGEw-0005YW-0S for emacs-devel@gnu.org; Sun, 26 Jul 2009 22:47:07 -0400 Original-Received: from [199.232.76.173] (port=49021 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MVGEv-0005YC-R1 for emacs-devel@gnu.org; Sun, 26 Jul 2009 22:47:01 -0400 Original-Received: from mux1-unibi-smtp.hrz.uni-bielefeld.de ([129.70.204.65]:38886) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MVGEv-0007cM-Cs for emacs-devel@gnu.org; Sun, 26 Jul 2009 22:47:01 -0400 Original-Received: from pmxchannel-daemon.mux1-unibi-smtp.hrz.uni-bielefeld.de by mux1-unibi-smtp.hrz.uni-bielefeld.de (Sun Java(tm) System Messaging Server 6.3-6.03 (built Mar 14 2008; 32bit)) id <0KNF00K006EAAS00@mux1-unibi-smtp.hrz.uni-bielefeld.de> for emacs-devel@gnu.org; Mon, 27 Jul 2009 04:46:58 +0200 (CEST) Original-Received: from [192.168.36.101] ([212.100.50.62]) by mux1-unibi-smtp.hrz.uni-bielefeld.de (Sun Java(tm) System Messaging Server 6.3-6.03 (built Mar 14 2008; 32bit)) with ESMTPPSA id <0KNF00EQ169YP380@mux1-unibi-smtp.hrz.uni-bielefeld.de> for emacs-devel@gnu.org; Mon, 27 Jul 2009 04:46:58 +0200 (CEST) X-Mailer: Evolution 2.27.4 X-EnvFrom: jan.moringen@uni-bielefeld.de X-PMX-Version: 5.5.1.360522, Antispam-Engine: 2.6.1.350677, Antispam-Data: 2009.7.27.23620, pmx7 X-Connecting-IP: 212.100.50.62 X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-Mailman-Approved-At: Sun, 26 Jul 2009 22:58:08 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:113196 Archived-At: --Boundary_(ID_qz+w9gRrnU0oQYSHuwGw1g) Content-type: text/plain; CHARSET=ISO-8859-1 Content-transfer-encoding: 7BIT 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 --Boundary_(ID_qz+w9gRrnU0oQYSHuwGw1g) Content-type: text/x-patch; name=emacs-dbus-return-values.patch; charset=UTF-8 Content-transfer-encoding: 7BIT Content-disposition: attachment; filename=emacs-dbus-return-values.patch --- 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. --Boundary_(ID_qz+w9gRrnU0oQYSHuwGw1g)--