diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi index c0a478d6ff6..e5d867acd40 100644 --- a/doc/misc/dbus.texi +++ b/doc/misc/dbus.texi @@ -1083,8 +1083,8 @@ elements of this array. Example: @defun dbus-string-to-byte-array string Sometimes, D-Bus methods require as input parameter an array of bytes, -instead of a string. If it is guaranteed, that @var{string} is a -UTF-8 string, this function performs the conversion. Example: +instead of a string. This function converts @var{string} into an array +of bytes of the UTF-8 encoding of @var{string}. Example: @lisp (dbus-string-to-byte-array "/etc/hosts") @@ -1156,8 +1156,9 @@ The signal @code{PropertyModified}, discussed as an example in @defun dbus-byte-array-to-string byte-array If a D-Bus method or signal returns an array of bytes, which are known -to represent a UTF-8 string, this function converts @var{byte-array} -to the corresponding UTF-8 string. Example: +to represent a UTF-8 string, this function converts @var{byte-array} to +the corresponding Lisp string. The contents of @var{byte-array} should +be the byte sequence of a UTF-8 encoded string. Example: @lisp (dbus-byte-array-to-string '(47 101 116 99 47 104 111 115 116 115)) diff --git a/etc/NEWS b/etc/NEWS index c2c510f2f93..30b1cceb2cb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1775,9 +1775,15 @@ Instead, use 'eshell-process-wait-time', which supports floating-point values. +++ -** 'dbus-{string-to-byte-array,byte-array-to-string}' are strict UTF-8 conform. -Both work over UTF-8 raw bytes only. The optional parameter MULTIBYTE -of 'dbus-byte-array-to-string' is obsolete now. +** Conversion of strings to and from byte-arrays works with multibyte strings. +The functions 'dbus-string-to-byte-array' and +'dbus-byte-array-to-string}' now accept and return multibyte Lisp +strings, encoding to UTF-8 and decoding from UTF-8 internally. This +means that the argument to 'dbus-byte-array-to-string' must be a valid +UTF-8 byte sequence, and the optional parameter MULTIBYTE of +'dbus-byte-array-to-string' is now obsolete and unused. The argument of +'dbus-string-to-byte-array' should be a regular Lisp string, not a +unibyte string. * Lisp Changes in Emacs 30.1 diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index 31a5eae5182..dd5f0e88859 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el @@ -995,7 +995,7 @@ association to the service from D-Bus." (defun dbus-string-to-byte-array (string) "Transform STRING to list (:array :byte C1 :byte C2 ...). The resulting byte array contains the raw bytes of the UTF-8 encoded -STRING.." +STRING." (if (length= string 0) '(:array :signature "y") (cons :array @@ -1004,9 +1004,10 @@ STRING.." (encode-coding-string string 'utf-8 'nocopy)))))) (defun dbus-byte-array-to-string (byte-array &optional _multibyte) - "Transform BYTE-ARRAY into UTF-8 coded string. + "Transform BYTE-ARRAY with UTF-8 byte sequence into a string. BYTE-ARRAY must be a list of structure (c1 c2 ...), or a byte array as -produced by `dbus-string-to-byte-array'." +produced by `dbus-string-to-byte-array', and the individual bytes must +be a valid UTF-8 byte sequence." (declare (advertised-calling-convention (byte-array) "30.1")) (if-let ((bytes (seq-filter #'characterp byte-array)) (string (apply #'unibyte-string bytes)))