changeset 5854:68f8017ef077

[project @ 2006-06-12 15:54:27 by jwe]
author jwe
date Mon, 12 Jun 2006 15:54:27 +0000
parents 169b5538840b
children 92d2be71e7cc
files ChangeLog aclocal.m4 configure.in src/ChangeLog src/dynamic-ld.cc src/load-path.cc src/unwind-prot.h
diffstat 7 files changed, 49 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-06-12  John W. Eaton  <jwe@octave.org>
+
+	* aclocal.m4 (OCTAVE_CXX_BROKEN_REINTERPRET_CAST): New macro.
+	* configure.in: Use it.
+	* AH_BOTTOM: Conditionally define FCN_PTR_CAST here.
+
 2006-06-08  John W. Eaton  <jwe@octave.org>
 
 	* Makeconf.in (do-subst-default-vals): Also substitute
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -709,6 +709,27 @@
   AC_DEFINE_UNQUOTED(CXX_ABI, $octave_cv_cxx_abi, [Define to the C++ ABI your compiler uses.])
 ])
 dnl
+dnl Check to see if C++ reintrepret cast works for function pointers.
+dnl
+dnl OCTAVE_CXX_BROKEN_REINTERPRET_CAST
+dnl
+AC_DEFUN(OCTAVE_CXX_BROKEN_REINTERPRET_CAST, [
+  AC_REQUIRE([AC_PROG_CXX])
+  AC_LANG_PUSH(C++)
+  AC_CACHE_CHECK([for broken C++ reinterpret_cast],
+    octave_cv_cxx_broken_reinterpret_cast, [
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <cmath>]], [[
+      typedef double (*fptr) (double);
+      fptr psin = sin;
+      void *vptr = reinterpret_cast<void *> (psin);
+      psin = reinterpret_cast<fptr> (vptr);]])],
+      octave_cv_cxx_broken_reinterpret_cast=no,
+      octave_cv_cxx_broken_reinterpret_cast=yes)])
+  if test $octave_cv_cxx_broken_reinterpret_cast = yes ; then
+    AC_DEFINE(CXX_BROKEN_REINTERPRET_CAST, 1, [Define if C++ reinterpret_cast fails for function pointers.])
+fi
+  AC_LANG_POP(C++)])
+dnl
 dnl Determine if mkdir accepts only one argument instead dnl of the usual 2.
 dnl
 AC_DEFUN(OCTAVE_MKDIR_TAKES_ONE_ARG,
--- a/configure.in
+++ b/configure.in
@@ -29,7 +29,7 @@
 EXTERN_CXXFLAGS="$CXXFLAGS"
 
 AC_INIT
-AC_REVISION($Revision: 1.513 $)
+AC_REVISION($Revision: 1.514 $)
 AC_PREREQ(2.57)
 AC_CONFIG_SRCDIR([src/octave.cc])
 AC_CONFIG_HEADER(config.h)
@@ -207,6 +207,7 @@
 
 OCTAVE_CXX_NEW_FRIEND_TEMPLATE_DECL
 OCTAVE_CXX_ISO_COMPLIANT_LIBRARY
+OCTAVE_CXX_BROKEN_REINTERPRET_CAST
 
 # Determine the ABI used the C++ compiler, needed by the dynamic loading
 # code. Currently supported ABIs are GNU v2, GNU v3 and Sun Workshop.
@@ -1632,6 +1633,12 @@
 
 #define X_CAST(T, E) (T) (E)
 
+#if defined (CXX_BROKEN_REINTERPRET_CAST)
+#define FCN_PTR_CAST(T, E) (T) (E)
+#else
+#define FCN_PTR_CAST(T, E) reinterpret_cast<T> (E)
+#endif
+
 #if defined(HAVE_F2C) && !defined(F77_FUNC)
 #  define F77_FUNC(x,X) x ## _
 #  define F77_FUNC_(x,X) x ## __
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2006-06-12  John W. Eaton  <jwe@octave.org>
+
+	* unwind-prot.h (unwind_protect_fptr): New macro.
+	* load-path.cc (load_path::do_set): Use it instead of
+	unwind_protect_ptr when protecting add_hook function pointer.
+	* dynamic-ld.cc (octave_dynamic_loader::do_load): Use FCN_PTR_CAST
+	here instead of reinterpret_cast.
+
 2006-06-09  John W. Eaton  <jwe@octave.org>
 
 	* version.h (OCTAVE_VERSION): Now 2.9.5+.
--- a/src/dynamic-ld.cc
+++ b/src/dynamic-ld.cc
@@ -265,7 +265,7 @@
   if (function)
     {
       octave_dld_fcn_installer f
-	= reinterpret_cast<octave_dld_fcn_installer> (function);
+	= FCN_PTR_CAST (octave_dld_fcn_installer, function);
 
       retval = f (oct_file);
 
--- a/src/load-path.cc
+++ b/src/load-path.cc
@@ -424,7 +424,7 @@
 
   // Temporarily disable add hook.
 
-  unwind_protect_ptr (add_hook);
+  unwind_protect_fptr (add_hook);
 
   add_hook = 0;
 
--- a/src/unwind-prot.h
+++ b/src/unwind-prot.h
@@ -125,6 +125,10 @@
   unwind_protect::save_ptr (reinterpret_cast<void **> (&(p)), \
                             reinterpret_cast<void *> (p))
 
+#define unwind_protect_fptr(p) \
+  unwind_protect::save_ptr (reinterpret_cast<void **> (&(p)), \
+                            FCN_PTR_CAST (void *, p))
+
 #define unwind_protect_const_ptr(p) \
   unwind_protect::save_ptr (const_cast<void **> (reinterpret_cast<const void **> (&(p))), \
                             const_cast<void *> (reinterpret_cast<const void *> (p)))