# HG changeset patch # User Mike Miller # Date 1361418691 18000 # Node ID 9439f3b5c5fafe5580e70c48b578c139411f3b14 # Parent 39129305b914ef480e7908a861f66d8cb1b30cbf Restore default floating point state after calling Java * bootstrap.conf (gnulib_modules): Add fpucw gnulib module. * configure.ac: Check for fpu_control.h. * libinterp/octave-value/ov-java.cc (restore_fpu_state): New function. (terminate_jvm, compute_array_dimensions, get_array_elements, set_array_elements, get_invoke_list, convert_to_string, box_more, java_event_hook, initialize_java, octave_java::do_javaMethod, octave_java::do_javaObject, octave_java::do_java_get, octave_java::do_java_set): Use it. diff -r 39129305b914 -r 9439f3b5c5fa bootstrap.conf --- a/bootstrap.conf Wed Feb 20 19:29:41 2013 -0500 +++ b/bootstrap.conf Wed Feb 20 22:51:31 2013 -0500 @@ -36,6 +36,7 @@ floorf fnmatch fopen + fpucw fseek ftell getcwd diff -r 39129305b914 -r 9439f3b5c5fa configure.ac --- a/configure.ac Wed Feb 20 19:29:41 2013 -0500 +++ b/configure.ac Wed Feb 20 22:51:31 2013 -0500 @@ -1897,8 +1897,8 @@ ## C headers dnl Use multiple AC_CHECKs to avoid line continuations '\' in list -AC_CHECK_HEADERS([curses.h direct.h dlfcn.h floatingpoint.h grp.h]) -AC_CHECK_HEADERS([ieeefp.h inttypes.h locale.h memory.h ncurses.h]) +AC_CHECK_HEADERS([curses.h direct.h dlfcn.h floatingpoint.h fpu_control.h]) +AC_CHECK_HEADERS([grp.h ieeefp.h inttypes.h locale.h memory.h ncurses.h]) AC_CHECK_HEADERS([poll.h pthread.h pwd.h sunmath.h sys/ioctl.h]) AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/resource.h ]) AC_CHECK_HEADERS([sys/select.h sys/utsname.h termcap.h]) diff -r 39129305b914 -r 9439f3b5c5fa libinterp/octave-value/ov-java.cc --- a/libinterp/octave-value/ov-java.cc Wed Feb 20 19:29:41 2013 -0500 +++ b/libinterp/octave-value/ov-java.cc Wed Feb 20 22:51:31 2013 -0500 @@ -26,6 +26,11 @@ #include "defun.h" #include "error.h" +#include "fpucw.h" + +#if HAVE_FPU_CONTROL_H +#include +#endif #if defined HAVE_JAVA @@ -392,6 +397,22 @@ return retval; } +#ifndef _FPU_DEFAULT +#if defined __i386__ || defined __x86_64__ +#define _FPU_DEFAULT 0x037f +#else +#define _FPU_DEFAULT 0 +#endif +#endif + +static void +restore_fpu_state (void) +{ + fpucw_t cw = GET_FPUCW (); + if (cw != _FPU_DEFAULT) + SET_FPUCW (_FPU_DEFAULT); +} + static void initialize_jvm (void) { @@ -583,6 +604,8 @@ if (jvm_lib) jvm_lib.close (); + + restore_fpu_state (); } } @@ -742,6 +765,8 @@ idx++; } + restore_fpu_state (); + return dv; } @@ -798,6 +823,8 @@ else retval = check_exception (jni_env); + restore_fpu_state (); + return retval; } @@ -826,6 +853,8 @@ else retval = check_exception (jni_env); + restore_fpu_state (); + return retval; } @@ -862,6 +891,8 @@ jstring_ref fieldName (jni_env, reinterpret_cast (jni_env->CallObjectMethod (field, f_getName_ID))); name_list.push_back (jstring_to_string (jni_env, fieldName)); } + + restore_fpu_state (); } string_vector v (name_list); @@ -921,6 +952,8 @@ } else error ("unable to convert Java object to string"); + + restore_fpu_state (); } return retval; @@ -1155,6 +1188,8 @@ if (retval.is_undefined ()) retval = octave_value (new octave_java (jobj, jcls)); + restore_fpu_state (); + return retval; } @@ -1381,6 +1416,8 @@ jclass_ref cls (current_env, find_octave_class (current_env, "org/octave/Octave")); jmethodID mID = current_env->GetStaticMethodID (cls, "checkPendingAction", "()V"); current_env->CallStaticVoidMethod (cls, mID); + + restore_fpu_state (); } return 0; @@ -1406,6 +1443,8 @@ { error (msg.c_str ()); } + + restore_fpu_state (); } } @@ -1738,6 +1777,8 @@ else retval = check_exception (jni_env); } + + restore_fpu_state (); } return retval; @@ -1768,6 +1809,8 @@ else retval = check_exception (jni_env); } + + restore_fpu_state (); } return retval; @@ -1797,6 +1840,8 @@ else check_exception (jni_env); } + + restore_fpu_state (); } return retval; @@ -1820,6 +1865,8 @@ retval = box (jni_env, resObj); else retval = check_exception (jni_env); + + restore_fpu_state (); } return retval; @@ -1844,6 +1891,8 @@ retval = box (jni_env, resObj); else retval = check_exception (jni_env); + + restore_fpu_state (); } return retval; @@ -1869,6 +1918,8 @@ jni_env->CallStaticObjectMethod (helperClass, mID, to_java (), jstring (fName), jobject (jobj)); check_exception (jni_env); } + + restore_fpu_state (); } return retval; @@ -1895,6 +1946,8 @@ jni_env->CallStaticObjectMethod (helperClass, mID, jstring (cName), jstring (fName), jobject (jobj)); check_exception (jni_env); } + + restore_fpu_state (); } return retval;