GNU bug report logs - #63196
sxml or guile bug?

Previous Next

Package: guile;

Reported by: Christopher Lam <christopher.lck <at> gmail.com>

Date: Mon, 1 May 2023 02:34:02 UTC

Severity: normal

To reply to this bug, email your comments to 63196 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#63196; Package guile. (Mon, 01 May 2023 02:34:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christopher Lam <christopher.lck <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Mon, 01 May 2023 02:34:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Christopher Lam <christopher.lck <at> gmail.com>
To: guile-user <guile-user <at> gnu.org>, bug-guile <at> gnu.org
Subject: sxml or guile bug?
Date: Mon, 1 May 2023 10:32:26 +0800
[Message part 1 (text/plain, inline)]
Hi, we've identified an unusual behaviour in writing a test in gnucash. Can
anyone reproduce and confirmit?

I paste a simple .scm file, and its input test-file.html. Now, in
sxml-bug.scm, modify the <tr> index - from -1 to -2 i.e. access the
last/penultimate row etc.

Odd negative indices work, even negative indices lead to error. Odd (haha)
bug. See report for (tr -2) for example, pasted below.

==== sxml-bug.scm =====
(use-modules (sxml simple))
(use-modules (sxml xpath))
(use-modules (ice-9 textual-ports))
(define html (call-with-input-file "/tmp/test-file.html" get-string-all))
(define sx (xml->sxml html))

;; note this path: try different indices for the tr tag:
;; odd numbers -1 -3 -5 are ok
;; even numbers -2 -4 -6 will fail
(define path '(// (table 1) // (tr -1)))

(format #t "html=[~s]\n" html)
(format #t "sxpath is [~s]\n" path)
(format #t "result is [~s]\n" ((sxpath path) sx))
====

And the backtrace with -2

=====
Backtrace:
In ice-9/boot-9.scm:
  1752:10 18 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
          17 (apply-smob/0 #<thunk 7f7fd530d2e0>)
In ice-9/boot-9.scm:
    724:2 16 (call-with-prompt _ _ #<procedure default-prompt-handle…>)
In ice-9/eval.scm:
    619:8 15 (_ #(#(#<directory (guile-user) 7f7fd5312c80>)))
In ice-9/boot-9.scm:
   2836:4 14 (save-module-excursion _)
  4388:12 13 (_)
In /home/user/sources/sxml-bug.scm:
    20:30 12 (_)
In sxml/xpath.scm:
   254:18 11 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18 10 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18  9 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18  8 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   254:18  7 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   252:22  6 (map-union #<procedure 7f7fd18e8280 at sxml/xpath.scm:…> …)
   252:22  5 (map-union #<procedure 7f7fd18f2ea0 at sxml/xpath.scm:…> …)
   254:18  4 (map-union #<procedure 7f7fd1901420 at sxml/xpath.scm:…> …)
   254:18  3 (map-union #<procedure 7f7fd1901420 at sxml/xpath.scm:…> …)
   252:22  2 (map-union #<procedure 7f7fd1901420 at sxml/xpath.scm:…> …)
   484:19  1 (loop _ ((tr -6)))
   181:24  0 (_ _)

sxml/xpath.scm:181:24: yikes!
=====
[Message part 2 (text/html, inline)]
[test-file.html (text/html, attachment)]

Information forwarded to bug-guile <at> gnu.org:
bug#63196; Package guile. (Mon, 01 May 2023 02:45:01 GMT) Full text and rfc822 format available.

Message #8 received at 63196 <at> debbugs.gnu.org (full text, mbox):

From: Christopher Lam <christopher.lck <at> gmail.com>
To: 63196 <at> debbugs.gnu.org
Subject: Further on this error message
Date: Mon, 1 May 2023 10:44:18 +0800
[Message part 1 (text/plain, inline)]
The source seems to be sxpath.scm -- see "yikes" error which triggers when
n is -2 -4 -6 etc. I don't know how to build guile from sources and cannot
debug further.


(define (node-pos n)
  (lambda (nodeset)
    (cond
     ((not (nodeset? nodeset)) '())
     ((null? nodeset) nodeset)
     ((eqv? n 1) (list (car nodeset)))
     ((negative? n) ((node-pos (+ n 1 (length nodeset))) nodeset))
     (else
      (or (positive? n) (error "yikes!"))
      ((node-pos (1- n)) (cdr nodeset))))))
[Message part 2 (text/html, inline)]

Information forwarded to bug-guile <at> gnu.org:
bug#63196; Package guile. (Sat, 06 May 2023 12:39:02 GMT) Full text and rfc822 format available.

Message #11 received at 63196 <at> debbugs.gnu.org (full text, mbox):

From: <tomas <at> tuxteam.de>
To: Christopher Lam <christopher.lck <at> gmail.com>
Cc: 63196 <at> debbugs.gnu.org
Subject: Re: bug#63196: Further on this error message
Date: Sat, 6 May 2023 14:38:06 +0200
[Message part 1 (text/plain, inline)]
On Mon, May 01, 2023 at 10:44:18AM +0800, Christopher Lam wrote:
> The source seems to be sxpath.scm -- see "yikes" error which triggers when
> n is -2 -4 -6 etc. I don't know how to build guile from sources and cannot
> debug further.
> 
> 
> (define (node-pos n)
>   (lambda (nodeset)
>     (cond
>      ((not (nodeset? nodeset)) '())
>      ((null? nodeset) nodeset)
>      ((eqv? n 1) (list (car nodeset)))
>      ((negative? n) ((node-pos (+ n 1 (length nodeset))) nodeset))
>      (else
>       (or (positive? n) (error "yikes!"))
>       ((node-pos (1- n)) (cdr nodeset))))))

Hm. It seems that calling `node-pos' with n == 0 runs straight into the
"yikes" case (unless `nodeset' is #f or null, that is).

And we would get this when n ==-2 and (length nodeset) equals 1 on the
next recursive call. Or when n == -3 and (length nodeset) == 2, and so
on -- i.e. when n == -1 - (length nodeset).

We reach such a point again when n == 2*(-1 - (length nodeset)): it runs
into the case (negative? n), retries with n' = (+ n 1 (length nodeset))
which is still negative, next try is 0 => yikes.

So in your case I guess your (length nodeset) is 1, because you have
a cycle length of two :-)

Reading between the lines in the code above for the positive case, I
gather that the intention is to return an empty nodeset (i.e. '())
when n runs off the nodeset. So I'd extend the ((negative? n) ...)
case like so:

  ((negative? n)
    (let ((nn (+ 1 (length nodeset))))
      (if (positive? nn) (node-pos nn) '())))

Comments?

Cheers
-- 
t
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 355 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.