This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: defmacro: Null pointer exceptions with compiled files
Try the attached patch.
It's safe and simple, but it does cause us to sometimes generate
a needless $literals$ method. This isn't a big deal - it's only
called at class initialiation time, but it's a minor irritation.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
Index: Compilation.java
===================================================================
RCS file: /cvs/kawa/kawa/gnu/expr/Compilation.java,v
retrieving revision 1.105
diff -u -r1.105 Compilation.java
--- Compilation.java 20 May 2004 00:25:59 -0000 1.105
+++ Compilation.java 31 May 2004 09:52:10 -0000
@@ -465,9 +465,13 @@
}
- private void emitLiterals()
+ private void emitLiterals(Method emitLiteralsMethod)
{
- if (! immediate && litTable.literalsChain != null)
+ method = emitLiteralsMethod;
+ // We need to startCode even if there are no literals,
+ // once we've created the emitLiteralsMethod.
+ CodeAttr code = method.startCode();
+ if (litTable.literalsChain != null)
{
try
{
@@ -479,6 +483,7 @@
ex.printStackTrace(System.err);
}
}
+ code.emitReturn();
}
private void dumpInitializers (Initializer inits)
@@ -1678,15 +1683,8 @@
}
Method emitLiteralsMethod = null;
- if (curClass == mainClass
- && (staticModule || clinitChain != null
- || litTable.literalsChain != null || module.applyMethods != null
- || generateMain || generateApplet || generateServlet))
- {
- emitLiteralsMethod
- = curClass.addMethod("$literals$", Access.PRIVATE|Access.STATIC,
- Type.typeArray0, Type.void_type);
-
+ if (curClass == mainClass)
+ {
Method save_method = method;
startClassInit();
@@ -1698,7 +1696,13 @@
code.emitInvokeSpecial(curClass.constructor);
code.emitPutStatic(instanceField);
}
- code.emitInvokeStatic(emitLiteralsMethod);
+ if (! immediate)
+ {
+ emitLiteralsMethod
+ = curClass.addMethod("$literals$", Access.PRIVATE|Access.STATIC,
+ Type.typeArray0, Type.void_type);
+ code.emitInvokeStatic(emitLiteralsMethod);
+ }
dumpInitializers(clinitChain);
if (staticModule && ! generateMain && ! immediate)
@@ -1727,12 +1731,7 @@
}
if (emitLiteralsMethod != null)
- {
- method = emitLiteralsMethod;
- code = method.startCode();
- emitLiterals();
- code.emitReturn();
- }
+ emitLiterals(emitLiteralsMethod);
if (generateMain && curClass == mainClass)
{