41ef34
From 5b167cc12daf9ea275c17fedaefc975450613ab2 Mon Sep 17 00:00:00 2001
41ef34
From: Karl Wette <karl.wette@ligo.org>
41ef34
Date: Mon, 13 Jan 2014 18:24:17 +1300
41ef34
Subject: [PATCH] octave: update support to Octave version 3.8.0
41ef34
41ef34
---
41ef34
 CHANGES.current           |  26 ++++++++++++
41ef34
 Doc/Manual/Octave.html    |   7 +---
41ef34
 Lib/octave/octrun.swg     | 104 ++++++++++++++++++++++++++++++++++++++--------
41ef34
 Lib/octave/octruntime.swg |  14 +++----
41ef34
 4 files changed, 122 insertions(+), 29 deletions(-)
41ef34
41ef34
SKIP diff --git a/CHANGES.current b/CHANGES.current
41ef34
SKIP index a4fc5db..c711536 100644
41ef34
SKIP --- a/CHANGES.current
41ef34
SKIP +++ b/CHANGES.current
41ef34
SKIP @@ -5,6 +5,32 @@ See the RELEASENOTES file for a summary of changes in each release.
41ef34
SKIP  Version 3.0.0 (in progress)
41ef34
SKIP  ============================
41ef34
SKIP  
41ef34
SKIP +2014-01-13: kwwette
41ef34
SKIP +            [Octave] update support to Octave version 3.8.0
41ef34
SKIP +
41ef34
SKIP +            - Octave 3.8.0 no longer defines OCTAVE_API_VERSION_NUMBER, but 3.8.1
41ef34
SKIP +              will define OCTAVE_{MAJOR,MINOR,PATCH}_VERSION instead: see
41ef34
SKIP +                http://hg.savannah.gnu.org/hgweb/octave/rev/b6b6e0dc700e
41ef34
SKIP +              So we now use a new macro SWIG_OCTAVE_PREREQ(major,minor,patch) to
41ef34
SKIP +              enable features requiring Octave version major.minor.patch or later.
41ef34
SKIP +
41ef34
SKIP +              For Octave versions prior to 3.8.1, we reconstruct values for
41ef34
SKIP +              OCTAVE_{MAJOR,MINOR,PATCH}_VERSION based on OCTAVE_API_VERSION_NUMBER,
41ef34
SKIP +              extracted from Octave's ChangeLogs. An additional hack is needed to
41ef34
SKIP +              distinguish between Octave <= 3.2.x and 3.8.0, neither of which define
41ef34
SKIP +              OCTAVE_API_VERSION_NUMBER.
41ef34
SKIP +
41ef34
SKIP +            - Octave 3.8.0 deprecates symbol_table::varref(), so remove its use
41ef34
SKIP +              for this and future versions of Octave.
41ef34
SKIP +
41ef34
SKIP +            - Octave 3.8.0 removes octave_value::is_real_nd_array(), used in
41ef34
SKIP +              octave_swig_type::dims(). Its use is not required here, so remove it.
41ef34
SKIP +
41ef34
SKIP +            - Retested against Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0.
41ef34
SKIP +
41ef34
SKIP +            - Updated Octave documentation with tested Octave versions, and added a
41ef34
SKIP +              warning against using versions <= 3.x.x, which are no longer tested.
41ef34
SKIP +
41ef34
SKIP  2014-01-11: wsfulton
41ef34
SKIP              Fix and document the naturalvar feature override behaviour - the naturalvar
41ef34
SKIP              feature attached to a variable name has precedence over the naturalvar
41ef34
diff --git a/Doc/Manual/Octave.html b/Doc/Manual/Octave.html
41ef34
index 84c0a0f..3e12ce6 100644
41ef34
--- a/Doc/Manual/Octave.html
41ef34
+++ b/Doc/Manual/Octave.html
41ef34
@@ -59,11 +59,8 @@
41ef34
 
41ef34
 
41ef34
 

41ef34
-The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux.
41ef34
-

41ef34
-
41ef34
-

41ef34
-As of SWIG 2.0.7, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, and 3.6.1.
41ef34
+As of SWIG 3.0.0, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0.
41ef34
+Use of Octave versions older than 3.x.x is not recommended, as these versions are no longer tested with SWIG.
41ef34
 

41ef34
 
41ef34
 

30.2 Running SWIG

41ef34
diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg
41ef34
index 41d1c7a..2174a0f 100644
41ef34
--- a/Lib/octave/octrun.swg
41ef34
+++ b/Lib/octave/octrun.swg
41ef34
@@ -1,20 +1,88 @@
41ef34
 
41ef34
 #include <octave/version.h>
41ef34
-#ifndef OCTAVE_API_VERSION_NUMBER
41ef34
-
41ef34
-  // Hack to distinguish between Octave 3.2 and earlier versions before OCTAVE_API_VERSION_NUMBER existed
41ef34
-  #define ComplexLU __ignore
41ef34
-  #include <octave/CmplxLU.h>
41ef34
-  #undef ComplexLU
41ef34
-  #ifdef octave_Complex_LU_h
41ef34
-  # define OCTAVE_API_VERSION_NUMBER 36
41ef34
-  #else
41ef34
-  # define OCTAVE_API_VERSION_NUMBER 37
41ef34
-  #endif
41ef34
 
41ef34
-#endif
41ef34
+// Macro for enabling features which require Octave version >= major.minor.patch
41ef34
+#define SWIG_OCTAVE_PREREQ(major, minor, patch) \
41ef34
+  ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + OCTAVE_PATCH_VERSION >= ((major)<<16) + ((minor)<<8) + (patch) )
41ef34
+
41ef34
+// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1
41ef34
+#if !defined(OCTAVE_MAJOR_VERSION)
41ef34
+
41ef34
+# if !defined(OCTAVE_API_VERSION_NUMBER)
41ef34
+
41ef34
+// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet
41ef34
+// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER
41ef34
+#  include <octave/ov.h>
41ef34
+#  if defined(octave_ov_h)
41ef34
+#   define OCTAVE_MAJOR_VERSION 3
41ef34
+#   define OCTAVE_MINOR_VERSION 8
41ef34
+#   define OCTAVE_PATCH_VERSION 0
41ef34
+#  else
41ef34
+
41ef34
+// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed
41ef34
+#   define ComplexLU __ignore
41ef34
+#   include <octave/CmplxLU.h>
41ef34
+#   undef ComplexLU
41ef34
+#   if defined(octave_Complex_LU_h)
41ef34
+
41ef34
+// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37
41ef34
+#    define OCTAVE_MAJOR_VERSION 3
41ef34
+#    define OCTAVE_MINOR_VERSION 1
41ef34
+#    define OCTAVE_PATCH_VERSION 99
41ef34
+
41ef34
+#   else
41ef34
+
41ef34
+// OCTAVE_API_VERSION_NUMBER == 37
41ef34
+#    define OCTAVE_MAJOR_VERSION 3
41ef34
+#    define OCTAVE_MINOR_VERSION 2
41ef34
+#    define OCTAVE_PATCH_VERSION 0
41ef34
+
41ef34
+#   endif // defined(octave_Complex_LU_h)
41ef34
+
41ef34
+#  endif // defined(octave_ov_h)
41ef34
 
41ef34
-#if OCTAVE_API_VERSION_NUMBER < 37
41ef34
+// Correlation between Octave API and version numbers extracted from Octave's
41ef34
+// ChangeLogs; version is the *earliest* released Octave with that API number
41ef34
+# elif OCTAVE_API_VERSION_NUMBER >= 48
41ef34
+#  define OCTAVE_MAJOR_VERSION 3
41ef34
+#  define OCTAVE_MINOR_VERSION 6
41ef34
+#  define OCTAVE_PATCH_VERSION 0
41ef34
+
41ef34
+# elif OCTAVE_API_VERSION_NUMBER >= 45
41ef34
+#  define OCTAVE_MAJOR_VERSION 3
41ef34
+#  define OCTAVE_MINOR_VERSION 4
41ef34
+#  define OCTAVE_PATCH_VERSION 1
41ef34
+
41ef34
+# elif OCTAVE_API_VERSION_NUMBER >= 42
41ef34
+#  define OCTAVE_MAJOR_VERSION 3
41ef34
+#  define OCTAVE_MINOR_VERSION 3
41ef34
+#  define OCTAVE_PATCH_VERSION 54
41ef34
+
41ef34
+# elif OCTAVE_API_VERSION_NUMBER >= 41
41ef34
+#  define OCTAVE_MAJOR_VERSION 3
41ef34
+#  define OCTAVE_MINOR_VERSION 3
41ef34
+#  define OCTAVE_PATCH_VERSION 53
41ef34
+
41ef34
+# elif OCTAVE_API_VERSION_NUMBER >= 40
41ef34
+#  define OCTAVE_MAJOR_VERSION 3
41ef34
+#  define OCTAVE_MINOR_VERSION 3
41ef34
+#  define OCTAVE_PATCH_VERSION 52
41ef34
+
41ef34
+# elif OCTAVE_API_VERSION_NUMBER >= 39
41ef34
+#  define OCTAVE_MAJOR_VERSION 3
41ef34
+#  define OCTAVE_MINOR_VERSION 3
41ef34
+#  define OCTAVE_PATCH_VERSION 51
41ef34
+
41ef34
+# else // OCTAVE_API_VERSION_NUMBER == 38
41ef34
+#  define OCTAVE_MAJOR_VERSION 3
41ef34
+#  define OCTAVE_MINOR_VERSION 3
41ef34
+#  define OCTAVE_PATCH_VERSION 50
41ef34
+
41ef34
+# endif // !defined(OCTAVE_API_VERSION_NUMBER)
41ef34
+
41ef34
+#endif // !defined(OCTAVE_MAJOR_VERSION)
41ef34
+
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,2,0)
41ef34
 #define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, FS ## cname, args, nargout, doc)
41ef34
 #else
41ef34
 #define SWIG_DEFUN(cname, wname, doc) DEFUNX_DLD(#cname, wname, G ## cname, args, nargout, doc)
41ef34
@@ -427,7 +495,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
41ef34
           if (error_state) return dim_vector(1,1);
41ef34
         }
41ef34
         return d;
41ef34
-      } else if (out.is_matrix_type() || out.is_real_nd_array() || out.is_numeric_type() ) {
41ef34
+      } else if (out.is_matrix_type() || out.is_numeric_type() ) {
41ef34
         if (out.rows()==1 || out.columns()==1) {
41ef34
            Array<int> a = out.int_vector_value();
41ef34
            if (error_state) return dim_vector(1,1);
41ef34
@@ -746,7 +814,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
41ef34
       return outarg(0).string_value();
41ef34
     }
41ef34
 
41ef34
-#if OCTAVE_API_VERSION_NUMBER >= 40
41ef34
+#if SWIG_OCTAVE_PREREQ(3,3,52)
41ef34
     virtual octave_map map_value() const {
41ef34
       return octave_map();
41ef34
     }
41ef34
@@ -982,7 +1050,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
41ef34
     virtual std::string string_value(bool force = false) const 
41ef34
       { return ptr->string_value(force); }
41ef34
 
41ef34
-#if OCTAVE_API_VERSION_NUMBER >= 40
41ef34
+#if SWIG_OCTAVE_PREREQ(3,3,52)
41ef34
     virtual octave_map map_value() const
41ef34
       { return ptr->map_value(); }
41ef34
 #else
41ef34
@@ -1293,10 +1361,12 @@ SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value
41ef34
 }
41ef34
 
41ef34
 SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) {
41ef34
-#if OCTAVE_API_VERSION_NUMBER < 37
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,2,0)
41ef34
   link_to_global_variable(curr_sym_tab->lookup(name, true));
41ef34
 #else
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,8,0)
41ef34
   symbol_table::varref(name);
41ef34
+#endif
41ef34
   symbol_table::mark_global(name);
41ef34
 #endif
41ef34
 }
41ef34
diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg
41ef34
index 43313c3..fbf2007 100644
41ef34
--- a/Lib/octave/octruntime.swg
41ef34
+++ b/Lib/octave/octruntime.swg
41ef34
@@ -25,7 +25,7 @@ static bool SWIG_init_user(octave_swig_type* module_ns);
41ef34
 SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) {
41ef34
   bool retn;
41ef34
   {
41ef34
-#if OCTAVE_API_VERSION_NUMBER < 38
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,3,50)
41ef34
     unwind_protect::begin_frame("SWIG_Octave_LoadModule");
41ef34
     unwind_protect_int(error_state);
41ef34
     unwind_protect_int(warning_state);
41ef34
@@ -44,7 +44,7 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) {
41ef34
     discard_warning_messages = true;
41ef34
     feval(name, octave_value_list(), 0);
41ef34
     retn = (error_state == 0);
41ef34
-#if OCTAVE_API_VERSION_NUMBER < 38
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,3,50)
41ef34
     unwind_protect::run_frame("SWIG_Octave_LoadModule");
41ef34
 #endif
41ef34
   }
41ef34
@@ -57,7 +57,7 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) {
41ef34
 SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) {
41ef34
   bool retn;
41ef34
   {
41ef34
-#if OCTAVE_API_VERSION_NUMBER < 38
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,3,50)
41ef34
     unwind_protect::begin_frame("SWIG_Octave_InstallFunction");
41ef34
     unwind_protect_int(error_state);
41ef34
     unwind_protect_int(warning_state);
41ef34
@@ -80,7 +80,7 @@ SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::st
41ef34
     error_state = 0;
41ef34
     feval("autoload", args, 0);
41ef34
     retn = (error_state == 0);
41ef34
-#if OCTAVE_API_VERSION_NUMBER < 38
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,3,50)
41ef34
     unwind_protect::run_frame("SWIG_Octave_InstallFunction");
41ef34
 #endif
41ef34
   }
41ef34
@@ -196,7 +196,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
41ef34
   // definitely affects version 3.2.*, not sure about 3.3.*, seems to be fixed in
41ef34
   // version 3.4.* and above. can be turned off with macro definition.
41ef34
 #ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK
41ef34
-#if 36 < OCTAVE_API_VERSION_NUMBER && OCTAVE_API_VERSION_NUMBER < 45
41ef34
+#if SWIG_OCTAVE_PREREQ(3,2,0) && !SWIG_OCTAVE_PREREQ(3,4,1)
41ef34
   octave_exit = ::_Exit;
41ef34
 #endif
41ef34
 #endif
41ef34
@@ -212,7 +212,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
41ef34
 
41ef34
     // workaround bug in octave where installing global variable of custom type and then
41ef34
     // exiting without explicitly clearing the variable causes octave to segfault.
41ef34
-#if OCTAVE_API_VERSION_NUMBER > 36
41ef34
+#if SWIG_OCTAVE_PREREQ(3,2,0)
41ef34
     octave_value_list eval_args;
41ef34
     eval_args.append("base");
41ef34
     eval_args.append("function __swig_atexit__; "
41ef34
@@ -297,7 +297,7 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
41ef34
       }
41ef34
     }
41ef34
 
41ef34
-#if OCTAVE_API_VERSION_NUMBER < 37
41ef34
+#if !SWIG_OCTAVE_PREREQ(3,2,0)
41ef34
     mlock(me->name());
41ef34
 #else
41ef34
     mlock();