开发者

No strictfp in Scala - workarounds?

I searched the web for how to enforce srictfp in Scala but could not find any hint of it. There are some people complaining about it, but real solutions cannot be found. There is a bugtracker entry about it which is almost two years old. As it seems there is no elegant fix for it on the way I'm looking for workarounds.

My current idea is to set the appropiate method flag ACC_STRICT in the generated bytecode by myself somehow but I have no idea what would be the best solution to do so. A Scala Compiler Plugin comes to mind or just hacking flags i开发者_如何学JAVAn a hex editor. Maybe someone faced the same challenge and can tell me his or her solution?


You could add a post-processor in your build process that would add the strictfp modifier to the generated class (i.e. setting the ACC_STRICT flag as you say).

You can implement such a post-processor using Javassist for example. This could look like this:

CtClass clazz = ClassPool.getDefault().makeClass(
                    new FileInputStream("old/HelloWorld.class"));

CtMethod method = clazz.getDeclaredMethod("testMethod");

method.setModifiers(method.getModifiers() | Modifier.STRICT);

clazz.detach();
clazz.toBytecode(new DataOutputStream(new FileOutputStream(
    "new/HelloWorld.class")));

You would then have to find a way to configure which classes/method need to be modified this way.


Scala has a strictfp annotation now:

@strictfp
def f() = …
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜