From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daiki Ueno Newsgroups: gmane.emacs.bugs Subject: bug#20193: 25.0.50; declarative type specification for D-Bus args Date: Wed, 25 Mar 2015 12:31:33 +0900 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1427254348 15851 80.91.229.3 (25 Mar 2015 03:32:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Mar 2015 03:32:28 +0000 (UTC) Cc: Michael Albinus To: 20193@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 25 04:32:11 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Yac36-0006sC-SQ for geb-bug-gnu-emacs@m.gmane.org; Wed, 25 Mar 2015 04:32:09 +0100 Original-Received: from localhost ([::1]:35986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yac35-0007PS-Uq for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Mar 2015 23:32:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yac31-0007P9-Cv for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 23:32:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yac30-0004pi-BU for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 23:32:03 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:45660) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yac30-0004pd-89 for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 23:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Yac30-0004ws-3S for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 23:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Daiki Ueno Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 25 Mar 2015 03:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 20193 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.142725431118998 (code B ref -1); Wed, 25 Mar 2015 03:32:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Mar 2015 03:31:51 +0000 Original-Received: from localhost ([127.0.0.1]:35436 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yac2o-0004wM-Pd for submit@debbugs.gnu.org; Tue, 24 Mar 2015 23:31:51 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52748) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Yac2l-0004w8-W4 for submit@debbugs.gnu.org; Tue, 24 Mar 2015 23:31:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yac2f-0004mN-PO for submit@debbugs.gnu.org; Tue, 24 Mar 2015 23:31:42 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:42945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yac2f-0004mJ-MT for submit@debbugs.gnu.org; Tue, 24 Mar 2015 23:31:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yac2e-0007Nf-If for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 23:31:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yac2d-0004ll-IJ for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 23:31:40 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:33195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yac2d-0004lh-Ez for bug-gnu-emacs@gnu.org; Tue, 24 Mar 2015 23:31:39 -0400 Original-Received: from du-a.org ([2001:e41:db5e:fb14::1]:35886 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1Yac2c-0006Nm-DZ; Tue, 24 Mar 2015 23:31:39 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:100908 Archived-At: --=-=-= Content-Type: text/plain Severity: wishlist Hello Michael, While using dbus.el, I found it a bit cumbersome to specify type symbols for the arguments of dbus-call-method and dbus-send-signal. Suppose a simple D-Bus signature "a{si}". Since dbusbind treats positive integers as uint32, one would need to write: (dbus-call-method :session "org.example.Foo" "/org/example/Foo" "org.example.Foo" "Test" '(:array (:dict-entry :string "a" :int32 1) (:dict-entry :string "b" :int32 2))) This is simple if the arguments are "fixed", but if one wants a wrapper, she would need to write a loop by herself. (defun example-foo (alist) (dbus-call-method :session "org.example.Foo" "/org/example/Foo" "org.example.Foo" "Test" (list :array (mapcar (lambda (entry) (list :dict-entry :string (car entry) :int32 (cdr entry))) alist)))) So I would like to propose an alternative syntax, similar to the `:type' keyword of `defcustom', like this: (dbus-call-method :session "org.example.Foo" "/org/example/Foo" "org.example.Foo" "Test" '(:type (:array (:dict-entry :string :int32))) '(("a" . 1) ("b" . 2))) That is, if a type symbol is a cons cell and the car is :type, treat the cdr as the type specification of the following value. The the wrapper can be written as: (defun example-foo (alist) (dbus-call-method :session "org.example.Foo" "/org/example/Foo" "org.example.Foo" "Test" '(:type (:array (:dict-entry :string :int32))) alist)) Would this kind of change be considered? As a proof-of-concept, I'm attaching a small Elisp snippet that augments the argument value with the given type information (though I guess it should be implemented in the C level, to avoid duplication of signature computation code). Comments appreciated. Regards, -- Daiki Ueno --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=dbus--annotate-arg.el ;; (setq lexical-binding t) ;; (dbus--annotate-arg '(:array :int32) '(1 2 3)) ;; ;=> ((:array :int32 1 :int32 2 :int32 3)) ;; (dbus--annotate-arg '(:array (:dict-entry :string :int32)) '(("a" . 1) ("b" . 2))) ;; ;=> ((:array (:dict-entry :string "a" :int32 1) (:dict-entry :string "b" :int32 2))) ;; (dbus--annotate-arg '(:struct :object-path (:array :signature) :string) ;; '("path" ("sig") "password")) ;; ;=> ((:struct :object-path "path" (:array :signature "sig") :string "password")) (defun dbus--annotate-arg (type arg) (pcase type ((and basic (or :byte :boolean :int16 :uint16 :int32 :uint32 :double :string :object-path :signature :unix-fd)) (list basic arg)) (`(:array ,elttype) (list (cons :array (apply #'nconc (mapcar (lambda (subarg) (dbus--annotate-arg elttype subarg)) arg))))) (`(,(and symbol (or :variant :struct)) . ,memtypes) (list (cons symbol (apply #'nconc (cl-mapcar (lambda (memtype subarg) (dbus--annotate-arg memtype subarg)) memtypes arg))))) (`(:dict-entry ,keytype ,valtype) (list (cons :dict-entry (nconc (dbus--annotate-arg keytype (car arg)) (dbus--annotate-arg valtype (cdr arg)))))) (_ (error "Unknown type specification: %S" type)))) --=-=-=--