public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* kawa 1.14: java.io.PrintWriter prints everything as "true"
@ 2013-10-08  4:19 Ito Kazumitsu
  2013-10-08  7:05 ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Ito Kazumitsu @ 2013-10-08  4:19 UTC (permalink / raw)
  To: kawa

I have found another case where kawa 1.14 behaves differently from kawa 1.13.
The script used for this test is attached below.

=================================================================
$ java -cp /mnt/ph/javalib/kawa-1.13.jar:/mnt/ph/javalib/sqlite-jdbc.jar kawa.repl --no-warn-unknown-member test.scm
1
End of List
$ java -cp /mnt/ph/javalib/kawa-1.13.jar:/mnt/ph/javalib/sqlite-jdbc.jar kawa.repl --no-warn-unknown-member --script test.scm
1
End of List
$ java -cp /mnt/ph/javalib/kawa-1.14.jar:/mnt/ph/javalib/sqlite-jdbc.jar kawa.repl --no-warn-unknown-member test.scm
1
End of List
$ java -cp /mnt/ph/javalib/kawa-1.14.jar:/mnt/ph/javalib/sqlite-jdbc.jar kawa.repl --no-warn-unknown-member --script test.scm
truetrue
true
=================================================================

As seen from the last case, using kawa 1.14 with the command line option
"--script", java.io.PrintWriter prints everything as "true".

The test script depends on SQLite JDBC Driver:
     https://bitbucket.org/xerial/sqlite-jdbc

I could not make a simpler test script without using SQLite JDBC Driver.
But since it works fine with kawa 1.13, I am afraid there is something
wrong whith kawa 1.14.

Here is the test script:

(define driverName "org.sqlite.JDBC")
(define connectionURL "jdbc:sqlite:test.db")
(define userID "sa")
(define passwd "")
(define outenc "UTF-8")
(define wtr
   (java.io.PrintWriter
       (java.io.OutputStreamWriter (java.lang.System:.out) outenc)))

(java.lang.Class:forName driverName)
(define c ::java.sql.Connection
   (java.sql.DriverManager:getConnection connectionURL userID passwd))

(define (show-rs rs colmax)
    (let loop ((i 1))
       (cond
          ((> i colmax)
             (wtr:println))
          (#t
             (let ((o (java.sql.ResultSet:getObject rs i)))
                (cond
                   ((equal? o #!null)
                       (wtr:print "NULL"))
                   (#t
                       (wtr:print (o:toString))))
                (wtr:print "\t")
                (loop (+ i 1)))))))

(define (exec-sql s)
    (let ((st ::java.sql.Statement (c:createStatement)))
      (try-catch
        (begin
         (cond
             ((st:execute s)
                (let* ((rs ::java.sql.ResultSet (st:getResultSet))
                       (meta ::java.sql.ResultSetMetaData (rs:getMetaData))
                       (colmax (meta:getColumnCount)))
                  (let rsloop ()
                    (cond
                      ((rs:next)
                         (show-rs rs colmax)
                         (rsloop))))
                  (wtr:println "End of List")))
             (#t
                (let ((uc (st:getUpdateCount)))
                   (wtr:print "Update Count =")
                   (wtr:println uc))))
         (st:close))
      (e <java.lang.Exception>
             (begin
                (wtr:println e)))))
    (wtr:flush))

(exec-sql "SELECT 1")

(c:close)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: kawa 1.14: java.io.PrintWriter prints everything as "true"
  2013-10-08  4:19 kawa 1.14: java.io.PrintWriter prints everything as "true" Ito Kazumitsu
@ 2013-10-08  7:05 ` Per Bothner
  2013-10-09  1:51   ` Ito Kazumitsu
  0 siblings, 1 reply; 5+ messages in thread
From: Per Bothner @ 2013-10-08  7:05 UTC (permalink / raw)
  To: Ito Kazumitsu; +Cc: kawa

On 10/07/2013 09:18 PM, Ito Kazumitsu wrote:

> As seen from the last case, using kawa 1.14 with the command line option
> "--script", java.io.PrintWriter prints everything as "true".
>
> The test script depends on SQLite JDBC Driver:
>       https://bitbucket.org/xerial/sqlite-jdbc
>
> I could not make a simpler test script without using SQLite JDBC Driver.
> But since it works fine with kawa 1.13, I am afraid there is something
> wrong whith kawa 1.14.

That doesn't quite follow - there are all kinds other possibilities.

I can't really debug your script, and I don't see any obvious problems.
Some suggestions:

* Try using the latest Subversion of Kawa - it's possible the fix
I checked in for your previous bug report may be relevant.

* Simplify your script as much as you can.  For example:

                 (cond
                    ((equal? o #!null)
                        (wtr:print "NULL"))
                    (#t
                        (wtr:print (o:toString))))

becomes:
                 (wtr:print o)

* Try to figure out where in your script the "true" is coming from.

* Try replacing each 'define' by 'define-constant' or adding a type
specifier.  If there is one specific define where that fixes it, look
for where that variable is used, especially in the argument to a
method invocation (where overload resolution may be an issue).

* Try removing the --no-warn-unknown-member flags - that warning
tells you useful information.

* If you're adventurous, try adding the --debug-print-final-expr
flag.  That tells you how Kawa has analyzed your code - i.e.
what it looks like just before bytecode generation.

* If you want me to try to debug your script you have to give me
specific instructions.  I don't have jdbc experience, so you would
need to tell me exactly what to do: What to download, which
commands to run, etc etc.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: kawa 1.14: java.io.PrintWriter prints everything as "true"
  2013-10-08  7:05 ` Per Bothner
@ 2013-10-09  1:51   ` Ito Kazumitsu
  2013-10-09  5:56     ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Ito Kazumitsu @ 2013-10-09  1:51 UTC (permalink / raw)
  To: kawa

From: Per Bothner <per@bothner.com>
Subject: Re: kawa 1.14: java.io.PrintWriter prints everything as "true"
Date: Tue, 08 Oct 2013 00:05:14 -0700

> * Try using the latest Subversion of Kawa - it's possible the fix
> I checked in for your previous bug report may be relevant.

I tried the latest Subversion of Kawa, but it did not help.

> * Simplify your script as much as you can.  For example:

I succeeded in simplifying the script significantly.

> * Try removing the --no-warn-unknown-member flags - that warning
> tells you useful information.
> 
> * If you're adventurous, try adding the --debug-print-final-expr
> flag.  That tells you how Kawa has analyzed your code - i.e.
> what it looks like just before bytecode generation.

Here it is.

$ cat test.scm
(define wtr
   (java.io.PrintWriter
       (java.io.OutputStreamWriter (java.lang.System:.out) "UTF-8")))
(define (print-it)
    (wtr:println "PRINT ME"))
(print-it)
(wtr:flush)

$ java -cp kawa-1.14.1-svn.jar kawa.repl --debug-print-final-expr  --script test.scm
[Compiling final atInteractiveLevel$1 to atInteractiveLevel$1:
(Module/atInteractiveLevel$1/1/ (Declarations: wtr/15/fl:40809)
  (Define line:1:1 /Declaration[wtr/15]
    (Apply => ClassType java.io.PrintWriter line:2:4
      (Quote
        java.io.PrintWriter java.io.PrintWriter.<init>(java.io.Writer) ::gnu.expr.PrimProcedure)
      (Quote class java.io.PrintWriter ::class)
      (Apply => ClassType java.io.OutputStreamWriter line:3:8
        (Quote
          java.io.OutputStreamWriter java.io.OutputStreamWriter.<init>(java.io.OutputStream,java.lang.String) ::gnu.expr.PrimProcedure)
        (Quote class java.io.OutputStreamWriter ::class)
        (Apply => ClassType java.io.PrintStream line:3:36
          (Quote #<procedure static-field> ::gnu.kawa.reflect.SlotGet)
          (Quote ClassType java.lang.System ::class-type)
          (Quote Field:java.lang.System.out ::gnu.bytecode.Field))
        (Quote "UTF-8" ::java.lang.String)))))]
test.scm:5:6: warning - no known slot 'println' in java.lang.Object
[Compiling final atInteractiveLevel$2 to atInteractiveLevel$2:
(Module/atInteractiveLevel$2/6/
  (Declarations: print-it/26/fl:408c8::gnu.mapping.Procedure)
  (Define line:4:1 /Declaration[print-it/26]
    (Lambda/print-it/8/fl:3 line:4:9 ()
      (Apply [tailcall] line:5:5 (Ref/15/Declaration[applyToArgs/2])
        (Apply line:5:6
          (Quote
            #<procedure gnu.kawa.functions.GetNamedPart> ::gnu.kawa.functions.GetNamedPart)
          (Ref/13/Declaration[wtr/15])
          (Quote println ::gnu.mapping.SimpleSymbol))
        (Quote "PRINT ME" ::java.lang.String)))))]
[Compiling final atInteractiveLevel$3 to atInteractiveLevel$3:
(Module/atInteractiveLevel$3/10/ ()
  (Apply [tailcall] line:6:1 (Ref/17/Declaration[print-it/26])))]
test.scm:7:2: warning - no known slot 'flush' in java.lang.Object
[Compiling final atInteractiveLevel$4 to atInteractiveLevel$4:
(Module/atInteractiveLevel$4/11/ ()
  (Apply [tailcall] line:7:1 (Ref/24/Declaration[applyToArgs/2])
    (Apply line:7:2
      (Quote
        #<procedure gnu.kawa.functions.GetNamedPart> ::gnu.kawa.functions.GetNamedPart)
      (Ref/22/Declaration[wtr/15])
      (Quote flush ::gnu.mapping.SimpleSymbol))))]
true

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: kawa 1.14: java.io.PrintWriter prints everything as "true"
  2013-10-09  1:51   ` Ito Kazumitsu
@ 2013-10-09  5:56     ` Per Bothner
  2013-10-13  7:03       ` Per Bothner
  0 siblings, 1 reply; 5+ messages in thread
From: Per Bothner @ 2013-10-09  5:56 UTC (permalink / raw)
  To: Ito Kazumitsu; +Cc: kawa

On 10/08/2013 06:51 PM, Ito Kazumitsu wrote:
> I succeeded in simplifying the script significantly.

Indeed, that is a helpful testcase.  Thanks.

The bug war introduced 2013-06-02 when fixing Savannah bug #39047
"Wrong incompatible type (boolean) with expected int".
Specifically the changes in the compare method in LangPrimType.java.
"Fixing" that method fixes your bug, but causes other issues
I'm looking at.

The underlying issue is that Scheme allows any value to
used as a boolean.  Kawa generalizes this so that any value
can be converted to boolean - which then leads to some
awkwardness with overload resolution: Which is the
"more specific method" of:

PrintWriter#println(boolean)
PrintWriter#println(Object)

They are equally general, in that any value can be converted to boolean,
and any value can be converted to Object.  I think we have this ok
when it comes to compile-time method selection (bug #39047 was partly
about fixing this), but it may be harder to get it right for run-time
method selection.  However, I will keep looking at the problem.

To work around the problem you can do:

(define-constant wtr
    (java.io.PrintWriter
        (java.io.OutputStreamWriter (java.lang.System:.out) "UTF-8")))

or:

(define wtr ::java.io.PrintWriter
    (java.io.PrintWriter
        (java.io.OutputStreamWriter (java.lang.System:.out) "UTF-8")))

-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: kawa 1.14: java.io.PrintWriter prints everything as "true"
  2013-10-09  5:56     ` Per Bothner
@ 2013-10-13  7:03       ` Per Bothner
  0 siblings, 0 replies; 5+ messages in thread
From: Per Bothner @ 2013-10-13  7:03 UTC (permalink / raw)
  To: Ito Kazumitsu; +Cc: kawa

On 10/08/2013 10:56 PM, Per Bothner wrote:
> The bug war introduced 2013-06-02 when fixing Savannah bug #39047
> "Wrong incompatible type (boolean) with expected int".
> Specifically the changes in the compare method in LangPrimType.java.
> "Fixing" that method fixes your bug, but causes other issues
> I'm looking at.
>
> The underlying issue is that Scheme allows any value to
> used as a boolean.  Kawa generalizes this so that any value
> can be converted to boolean - which then leads to some
> awkwardness with overload resolution: Which is the
> "more specific method" of:
>
> PrintWriter#println(boolean)
> PrintWriter#println(Object)
>
> They are equally general, in that any value can be converted to boolean,
> and any value can be converted to Object.  I think we have this ok
> when it comes to compile-time method selection (bug #39047 was partly
> about fixing this), but it may be harder to get it right for run-time
> method selection.  However, I will keep looking at the problem.

I have one idea for how to handle boolean in overloading. but it's
not a small change, so I need to let the idea simmer some more.
Furthermore,   I'm working on a big change involving pattern-matching,
tweaks to the way unknown functions get called, and parameter passing.
The current issue is related to this bigger change, so I think it is
best to focus on the bigger issue first.

To remind me to not forget about this issue I created a
bug report on Savannah:
https://savannah.gnu.org/bugs/index.php?40253
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-10-13  7:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-08  4:19 kawa 1.14: java.io.PrintWriter prints everything as "true" Ito Kazumitsu
2013-10-08  7:05 ` Per Bothner
2013-10-09  1:51   ` Ito Kazumitsu
2013-10-09  5:56     ` Per Bothner
2013-10-13  7:03       ` Per Bothner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).