From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wolfgang Jenkner Newsgroups: gmane.emacs.bugs Subject: bug#19401: 25.0.50; metar.el (metar-convert-temperature) wrong type argument stringp nil Date: Tue, 13 Jan 2015 15:34:49 +0100 Message-ID: <85mw5m91um.fsf@iznogoud.viz> References: <87oar2x9is.fsf@udel.edu> <87egrx1162.fsf@web.de> <87egrxqaeb.fsf@udel.edu> <87a92k28rk.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1421160385 32693 80.91.229.3 (13 Jan 2015 14:46:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 13 Jan 2015 14:46:25 +0000 (UTC) Cc: Mario Lang , Mark Oteiza , 19401@debbugs.gnu.org To: Ulf Jasper Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 13 15:46:19 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 1YB2jV-00012h-C1 for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Jan 2015 15:46:13 +0100 Original-Received: from localhost ([::1]:39691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB2jU-0003Ak-U0 for geb-bug-gnu-emacs@m.gmane.org; Tue, 13 Jan 2015 09:46:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB2jR-0003AL-0p for bug-gnu-emacs@gnu.org; Tue, 13 Jan 2015 09:46:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YB2jK-0004jx-Ux for bug-gnu-emacs@gnu.org; Tue, 13 Jan 2015 09:46:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YB2jK-0004jm-RN for bug-gnu-emacs@gnu.org; Tue, 13 Jan 2015 09:46:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YB2jK-0001tD-8M for bug-gnu-emacs@gnu.org; Tue, 13 Jan 2015 09:46:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <87oar2x9is.fsf@udel.edu> Resent-From: Wolfgang Jenkner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Jan 2015 14:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19401 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 19401-submit@debbugs.gnu.org id=B19401.14211603057197 (code B ref 19401); Tue, 13 Jan 2015 14:46:02 +0000 Original-Received: (at 19401) by debbugs.gnu.org; 13 Jan 2015 14:45:05 +0000 Original-Received: from localhost ([127.0.0.1]:55146 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YB2iO-0001s0-Cp for submit@debbugs.gnu.org; Tue, 13 Jan 2015 09:45:04 -0500 Original-Received: from b2bfep15.mx.upcmail.net ([62.179.121.60]:52969) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YB2iI-0001r7-Us for 19401@debbugs.gnu.org; Tue, 13 Jan 2015 09:45:01 -0500 Original-Received: from edge12.upcmail.net ([192.168.13.82]) by b2bfep15.mx.upcmail.net (InterMail vM.8.01.05.05 201-2260-151-110-20120111) with ESMTP id <20150113144450.PXSI24061.b2bfep15-int.chello.at@edge12.upcmail.net> for <19401@debbugs.gnu.org>; Tue, 13 Jan 2015 15:44:50 +0100 Original-Received: from iznogoud.viz ([85.127.90.213]) by edge12.upcmail.net with edge id fSkp1p01U4cBfQ50CSkpSM; Tue, 13 Jan 2015 15:44:50 +0100 X-SourceIP: 85.127.90.213 Original-Received: from wolfgang by iznogoud.viz with local (Exim 4.84 (FreeBSD)) (envelope-from ) id 1YB2i9-0000vu-Fw; Tue, 13 Jan 2015 15:44:49 +0100 User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (berkeley-unix) 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:98294 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Dec 18 2014, Ulf Jasper wrote: > It appears that the temperature value -1 =C2=B0C ("M01") is causing the e= rror > > (metar-convert-temperature "M07") =3D> (-7 . degC) > (metar-convert-temperature "M01") =3D> error (wrong-type-argument str= ingp nil) > > I suspect that this is the result of `math-mul-symb-fancy' (which > metar.el calls via calc-units) treating "-1" in a special way > > (math-mul-symb-fancy -7 '(var degC var-degC)) =3D> (* -7 (var degC va= r-degC)) > (math-mul-symb-fancy -1 '(var degC var-degC)) =3D> (neg (var degC var= -degC)) There are problems in calc (Bug#19582) here. There's also a small problem in metar, viz., the string "-degC" is not parsed in the same way as "-1 degC". Since `metar-convert-unit' has (at least potentially) the same problem, the attached patch does a little refactoring of those two functions, where the actual conversion function from the calc library is passed as an additional optional argument to `metar-convert-unit', so that `metar-convert-temperature' reduces to just a call to the latter. The actual bug is simply resolved by passing t as the last argument to `math-convert-units' resp. `math-convert-temperature', so that these functions return the number without a unit. After all, we already know which unit we get... Please note that this patch assumes that the patch from (Bug#19582) has been applied. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-metar-Fix-the-case-where-the-metar-record-contains-M.patch Content-Description: M01 bug fix >From 4d72d28ead8f864fad08a3d05f216de940be6b8f Mon Sep 17 00:00:00 2001 From: Wolfgang Jenkner Date: Sat, 3 Jan 2015 00:34:33 +0100 Subject: [PATCH] [metar] Fix the case where the metar record contains M01 (bug#19401). * packages/metar/metar.el (metar-convert-unit): New optional argument. (metar-convert-temperature): Use it to rewrite this function in terms of metar-convert-unit. Pass t as last argument to the underlying calc conversion functions so that they return only the number, not the unit, thereby fixing the bug in question. --- packages/metar/metar.el | 66 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/metar/metar.el b/packages/metar/metar.el index 7b78f07..9575313 100644 --- a/packages/metar/metar.el +++ b/packages/metar/metar.el @@ -239,45 +239,43 @@ If no match if found, nil is returned." (when station-code (cons station-code (round best-distance)))))) -(defun metar-convert-unit (value new-unit) +(defun metar-convert-unit (value new-unit &optional convert-units-function) "Convert VALUE to NEW-UNIT. VALUE is a string with the value followed by the unit, like \"5 knot\" -and NEW-UNIT should be a unit name like \"kph\" or similar." +and NEW-UNIT should be a unit name like \"kph\" or similar. +CONVERT-UNITS-FUNCTION designates the function actually doing the conversion. +It must have the signature of `math-convert-units', which is the default." (cl-check-type value string) - (cl-check-type new-unit (or string symbol)) - (cl-multiple-value-bind (value unit) - (split-string - (math-format-value - (math-convert-units (math-simplify (math-read-expr value)) - (math-read-expr - (cl-etypecase new-unit - (string new-unit) - (symbol (symbol-name new-unit)))))) - " ") - (cons (string-to-number value) (intern unit)))) + (unless (symbolp new-unit) + (setq new-unit (intern new-unit))) + (let ((expr (math-simplify (math-read-expr value)))) + (cl-assert (or (math-zerop expr) + (not (memq (math-single-units-in-expr-p expr) '(nil wrong)))) + nil + "Metar: Not exactly one unit in expression: %S" expr) + (let ((res (math-simplify-units + (funcall (or convert-units-function 'math-convert-units) + expr + (math-build-var-name new-unit) + t)))) + (cl-assert (math-realp res) nil + "Metar: Not a Calc real number: %S" res) + (cons (string-to-number (math-format-value (if (integerp res) + res + (math-float res)))) + new-unit)))) (defun metar-convert-temperature (string &optional unit) - (let* ((value (concat (if (= (aref string 0) ?M) - (concat "-" (substring string 1)) - string) - "degC")) - (expr (math-read-expr value)) - (old-unit (math-single-units-in-expr-p expr)) - (new-unit (or unit (cdr (assq 'temperature metar-units))))) - (if old-unit - (cl-multiple-value-bind (value unit) - (split-string - (math-format-value - (math-simplify-units - (math-convert-temperature - expr - (list 'var - (car old-unit) - (intern (concat "var-" (symbol-name (car old-unit))))) - (math-read-expr (cl-etypecase new-unit - (string new-unit) - (symbol (symbol-name new-unit))))))) " ") - (cons (string-to-number value) (intern unit)))))) + (metar-convert-unit (concat (if (= (aref string 0) ?M) + (concat "-" (substring string 1)) + string) + "degC") + (or unit (cdr (assq 'temperature metar-units))) + (lambda (expr new-unit-var pure) + (math-convert-temperature expr + (math-build-var-name 'degC) + new-unit-var + pure)))) (defcustom metar-url "http://weather.noaa.gov/pub/data/observations/metar/stations/%s.TXT" -- 2.2.1 --=-=-=--