This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
FORMAT prefix parameter '#' not handled properly
- From: Charles Turner <chturne at gmail dot com>
- To: Kawa mailing list <kawa at sourceware dot org>
- Date: Fri, 07 Oct 2011 21:22:32 +0100
- Subject: FORMAT prefix parameter '#' not handled properly
- Reply-to: chturne at gmail dot com
Evaluating (format #t "~#$" 3.14159) should return 3.1, since the length
of the argument list is 1 (3.14159) and the # prefix parameter tells
FORMAT to print that many fractional digits. Here are a couple of
examples with the fix in place,
#|kawa:2|# (format #t "~#$" 3.14159)
3.1
#|kawa:3|# (format #t "~#$" 3.14159 1 2)
3.142
The current behaviour is to throw a NullPointerException, this is
because the call dfmt.resolve(null, 0); in LispFormat#LispFormat calls
getParam, which doesn't handle a args value of null properly. The patch
for LispFormat makes a small modification to avoid calling this
dfmt.resolve method, even if you fix getParam to handle null properly,
this method replaces the LispRealFormat instance with a FixedRealFormat
instance, having done that, we forget to check the paramCount stuff.
I'm not 100% happy with this fix, but it seems to work okay, I'm finding
the logic in LispFormat a bit hard to follow for now.
I seem to have changed the indentation in LispFormat, no matter how I
change the indentation to match the original, svn diff keeps saying it's
different, sorry about that. I just ended up accepting how Emacs indents
the line break in the middle of a param list.
The ReportFormat patch attached includes the fix for getParam. If this
is acceptable, I'll send some test cases and change logs.
Charles.
Index: gnu/text/ReportFormat.java
===================================================================
--- gnu/text/ReportFormat.java (revision 7065)
+++ gnu/text/ReportFormat.java (working copy)
@@ -158,12 +158,12 @@
protected static int getParam(int param, int defaultValue, Object[] args, int start)
{
+ if (args == null || param == PARAM_UNSPECIFIED)
+ return defaultValue;
if (param == PARAM_FROM_COUNT)
return args.length - start;
if (param == PARAM_FROM_LIST)
- return args == null ? defaultValue : getParam(args[start], defaultValue);
- if (param == PARAM_UNSPECIFIED)
- return defaultValue;
+ return getParam(args[start], defaultValue);
// Need to mask off flags etc?
return param;
}
Index: gnu/kawa/functions/LispFormat.java
===================================================================
--- gnu/kawa/functions/LispFormat.java (revision 7065)
+++ gnu/kawa/functions/LispFormat.java (working copy)
@@ -153,7 +153,7 @@
}
dfmt.showPlus = seenAt;
dfmt.internalPad = seenColon;
- if (dfmt.argsUsed == 0)
+ if (dfmt.argsUsed == 0 && dfmt.arg1 != PARAM_FROM_COUNT)
fmt = dfmt.resolve(null, 0);
else
fmt = dfmt;
@@ -919,6 +919,7 @@
return start;
}
+ @Override
public String toString ()
{
StringBuffer sbuf = new StringBuffer();
@@ -1052,8 +1053,8 @@
}
else if (! skipIfFalse)
{
- int index = getParam(this.param, LispFormat.PARAM_FROM_LIST,
- args, start);
+ int index = getParam(this.param, LispFormat.PARAM_FROM_LIST,
+ args, start);
if (param == LispFormat.PARAM_FROM_LIST) start++;
if (index < 0 || index >= choices.length)
{