From a2d9a24f4da36a454e116c03f710f62e3ae1c9f8 Mon Sep 17 00:00:00 2001 From: Markus Friedrich Date: Tue, 24 Dec 2019 14:06:25 +0100 Subject: Changed return type of swig_this() to size_t. The type long may be 4 bytes but swig_this() must return the address of the object as an integer. Using size_t ensures that the return type can store a pointer. --- Lib/octave/octrun.swg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Lib/octave') diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index ff614e681..325a4cca3 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -507,10 +507,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); delete this; } - long swig_this() const { + size_t swig_this() const { if (!types.size()) - return (long) this; - return (long) types[0].second.ptr; + return (size_t) this; + return (size_t) types[0].second.ptr; } const char* help_text() const { if (!types.size()) -- cgit v1.2.1 From 30132bf77730addafb6150ecd751b855c05394f3 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 1 May 2020 21:29:41 +1000 Subject: octrun.swg: remove octave_value type-id from octave_swig_bound_func - The {DECLARE|DEFINE}_OV_TYPEID_FUNCTIONS_AND_DATA declarations attached to this class cause a seg-fault in the module_load Octave example. Removing these declarations fixes the seg-fault. - While cause of seg-fault is unknown, note that (in Octave 5.1.0) the declaration of octave_function, which is the base class for octave_swig_bound_func, does not use these declarations. So it's possible they simply are not required for this type of subclass. --- Lib/octave/octrun.swg | 4 ---- Lib/octave/octruntime.swg | 7 ------- 2 files changed, 11 deletions(-) (limited to 'Lib/octave') diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 325a4cca3..162772d98 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -203,11 +203,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); std::set dispatch_classes; - private: - - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; - DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(octave_swig_bound_func, "octave_swig_bound_func", "octave_swig_bound_func"); #else #define SWIG_OCTAVE_BOUND_FUNC(func, args) octave_value(func) #endif diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index f98bf4fe4..6e07aaa70 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -376,7 +376,6 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { string_vector types = typeinfo.installed_type_names(); bool register_octave_swig_ref = true; bool register_octave_swig_packed = true; - bool register_octave_swig_bound_func = true; for (int i = 0; i < types.numel(); ++i) { if (types(i) == octave_swig_ref::static_type_name()) { register_octave_swig_ref = false; @@ -384,9 +383,6 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { if (types(i) == octave_swig_packed::static_type_name()) { register_octave_swig_packed = false; } - if (types(i) == octave_swig_bound_func::static_type_name()) { - register_octave_swig_bound_func = false; - } } if (register_octave_swig_ref) { octave_swig_ref::register_type(); @@ -394,9 +390,6 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { if (register_octave_swig_packed) { octave_swig_packed::register_type(); } - if (register_octave_swig_bound_func) { - octave_swig_bound_func::register_type(); - } } #else octave_swig_ref::register_type(); -- cgit v1.2.1 From 26423d06b3934b5e584beeca62b56e4a861e45a2 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 1 May 2020 21:19:53 +1000 Subject: octruntime.swg: do not use atexit() to quit Octave - This reverts commit 931656bcbe7c2bf37bb5d831b47fab9a38695e91 - Since atexit() does not pass along the desired exit status, __swig_atexit__() always exits with status zero, regardless of whether Octave completed successfully or raised an error. - This means the success/failure of Octave scripts which load SWIG modules cannot be determined by other programs, which makes them unusable. - Instead, provide a Octave function swig_exit() which calls ::_Exit() with a given exit status. This way at least a clean exit from Octave can be guaranteed for future versions if the seg-fault problem is not fixed. --- Lib/octave/octruntime.swg | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'Lib/octave') diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 6e07aaa70..2f0cf58aa 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -315,13 +315,29 @@ DEFUN_DLD( swig_octave_prereq, args, nargout, swig_octave_prereq_usage ) { return octave_value(prereq); } +static const char *const swig_exit_usage = "-*- texinfo -*- \n\ +@deftypefn {Loadable Function} {} swig_exit([@var{exit_status}])\n\ +Exit Octave without performing any memory cleanup.\n\ +@end deftypefn"; + +DEFUN_DLD( swig_exit, args, nargout, swig_exit_usage ) { + if (args.length() > 1) { + error("swig_exit: must be called with at most one arguments"); + return octave_value_list(); + } + int exit_status = 0; + if (args.length() == 1) { + exit_status = args(0).int_value(); + } + ::_Exit(exit_status); + return octave_value(); +} + static const char *const SWIG_name_usage = "-*- texinfo -*- \n\ @deftypefn {Loadable Module} {} " SWIG_name_d "\n\ Loads the SWIG-generated module `" SWIG_name_d "'.\n\ @end deftypefn"; -void __swig_atexit__(void) { ::_Exit(0); } - DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { static octave_swig_type* module_ns = 0; @@ -329,14 +345,15 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { // workaround to prevent octave seg-faulting on exit: set Octave exit function // octave_exit to _Exit, which exits immediately without trying to cleanup memory. // definitely affected version 3.2.*, not sure about 3.3.*, seems to be fixed in - // version 3.4.*, but reappeared in 4.2.*, so turn on for all versions after 3.2.*. + // version 3.4.*, reappeared in 4.2.*, hack not possible in 4.4.* or later due to + // removal of octave_exit, so turn on for all versions between 3.2.*. and 4.4.*. // can be turned off with macro definition. #ifndef SWIG_OCTAVE_NO_SEGFAULT_HACK -#if SWIG_OCTAVE_PREREQ(4,4,0) - atexit(__swig_atexit__); -#elif SWIG_OCTAVE_PREREQ(3,2,0) +#if !SWIG_OCTAVE_PREREQ(4,4,0) +#if SWIG_OCTAVE_PREREQ(3,2,0) octave_exit = ::_Exit; #endif +#endif #endif // check for no input and output args @@ -420,6 +437,9 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { if (!SWIG_Octave_InstallFunction(me, "swig_octave_prereq")) { return octave_value_list(); } + if (!SWIG_Octave_InstallFunction(me, "swig_exit")) { + return octave_value_list(); + } octave_swig_type* cvar_ns=0; if (std::string(SWIG_global_name) != ".") { -- cgit v1.2.1 From d11e29615d43a5962129724b4097422282ebd8fa Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Fri, 29 May 2020 17:05:01 +1000 Subject: Octave: use pre-compiled headers to speed up test suite, if supported --- Lib/octave/director.swg | 2 - Lib/octave/extra-install.list | 2 + Lib/octave/octcontainer.swg | 7 --- Lib/octave/octheaders.hpp | 130 ++++++++++++++++++++++++++++++++++++++++++ Lib/octave/octrun.swg | 4 -- Lib/octave/octruntime.swg | 109 ++--------------------------------- Lib/octave/std_complex.i | 4 -- 7 files changed, 136 insertions(+), 122 deletions(-) create mode 100644 Lib/octave/extra-install.list create mode 100644 Lib/octave/octheaders.hpp (limited to 'Lib/octave') diff --git a/Lib/octave/director.swg b/Lib/octave/director.swg index bf71d18e8..5b9cd86e0 100644 --- a/Lib/octave/director.swg +++ b/Lib/octave/director.swg @@ -7,8 +7,6 @@ # define SWIG_DIRECTOR_CAST(ARG) dynamic_cast(ARG) -#include - namespace Swig { class Director { diff --git a/Lib/octave/extra-install.list b/Lib/octave/extra-install.list new file mode 100644 index 000000000..41ef94778 --- /dev/null +++ b/Lib/octave/extra-install.list @@ -0,0 +1,2 @@ +# see top-level Makefile.in +octheaders.hpp diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index 310a849d9..80d593f4f 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -11,12 +11,6 @@ * be the case. * ----------------------------------------------------------------------------- */ -%{ -#include -#include -%} - - #if !defined(SWIG_NO_EXPORT_ITERATOR_METHODS) # if !defined(SWIG_EXPORT_ITERATOR_METHODS) # define SWIG_EXPORT_ITERATOR_METHODS SWIG_EXPORT_ITERATOR_METHODS @@ -64,7 +58,6 @@ namespace swig { %fragment("OctSequence_Base","header",fragment="") { -%#include namespace std { template <> diff --git a/Lib/octave/octheaders.hpp b/Lib/octave/octheaders.hpp new file mode 100644 index 000000000..abf6428e7 --- /dev/null +++ b/Lib/octave/octheaders.hpp @@ -0,0 +1,130 @@ +// +// This header includes all C++ headers required for generated Octave wrapper code. +// Using a single header file allows pre-compilation of Octave headers, as follows: +// * Check out this header file: +// swig -octave -co octheaders.hpp +// * Pre-compile header file into octheaders.hpp.gch: +// g++ -c ... octheaders.hpp +// * Use pre-compiled header file: +// g++ -c -include octheaders.hpp ... +// + +#if !defined(_SWIG_OCTAVE_OCTHEADERS_HPP) +#define _SWIG_OCTAVE_OCTHEADERS_HPP + +// Required C++ headers +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Minimal headers to define Octave version +#include +#include + +// Macro for enabling features which require Octave version >= major.minor.patch +// - Use (OCTAVE_PATCH_VERSION + 0) to handle both '' (released) and '+' (in development) patch numbers +#define SWIG_OCTAVE_PREREQ(major, minor, patch) \ + ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + (OCTAVE_PATCH_VERSION + 0) >= ((major)<<16) + ((minor)<<8) + (patch) ) + +// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1 +#if !defined(OCTAVE_MAJOR_VERSION) + +# if !defined(OCTAVE_API_VERSION_NUMBER) + +// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet +// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER +# include +# if defined(octave_ov_h) +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 8 +# define OCTAVE_PATCH_VERSION 0 +# else + +// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed +# define ComplexLU __ignore +# include +# undef ComplexLU +# if defined(octave_Complex_LU_h) + +// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 1 +# define OCTAVE_PATCH_VERSION 99 + +# else + +// OCTAVE_API_VERSION_NUMBER == 37 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 2 +# define OCTAVE_PATCH_VERSION 0 + +# endif // defined(octave_Complex_LU_h) + +# endif // defined(octave_ov_h) + +// Correlation between Octave API and version numbers extracted from Octave's +// ChangeLogs; version is the *earliest* released Octave with that API number +# elif OCTAVE_API_VERSION_NUMBER >= 48 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 6 +# define OCTAVE_PATCH_VERSION 0 + +# elif OCTAVE_API_VERSION_NUMBER >= 45 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 4 +# define OCTAVE_PATCH_VERSION 1 + +# elif OCTAVE_API_VERSION_NUMBER >= 42 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 54 + +# elif OCTAVE_API_VERSION_NUMBER >= 41 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 53 + +# elif OCTAVE_API_VERSION_NUMBER >= 40 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 52 + +# elif OCTAVE_API_VERSION_NUMBER >= 39 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 51 + +# else // OCTAVE_API_VERSION_NUMBER == 38 +# define OCTAVE_MAJOR_VERSION 3 +# define OCTAVE_MINOR_VERSION 3 +# define OCTAVE_PATCH_VERSION 50 + +# endif // !defined(OCTAVE_API_VERSION_NUMBER) + +#endif // !defined(OCTAVE_MAJOR_VERSION) + +// Required Octave headers +#include +#include +#include +#include +#include +#include +#include +#if SWIG_OCTAVE_PREREQ(4,2,0) +#include +#else +#include +#endif +#include +#if SWIG_OCTAVE_PREREQ(4,2,0) +#include +#endif + +#endif // !defined(_SWIG_OCTAVE_OCTHEADERS_HPP) diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 162772d98..944b72a63 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -89,10 +89,6 @@ SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *point // Runtime API implementation -#include -#include -#include - typedef octave_value_list(*octave_func) (const octave_value_list &, int); class octave_swig_type; diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index 2f0cf58aa..a397fb7c1 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -1,111 +1,10 @@ +#ifdef SWIG_OCTAVE_EXTERNAL_OCTHEADERS %insert(runtime) %{ - -#include -#include - -#include -#include - -// Macro for enabling features which require Octave version >= major.minor.patch -// - Use (OCTAVE_PATCH_VERSION + 0) to handle both '' (released) and '+' (in development) patch numbers -#define SWIG_OCTAVE_PREREQ(major, minor, patch) \ - ( (OCTAVE_MAJOR_VERSION<<16) + (OCTAVE_MINOR_VERSION<<8) + (OCTAVE_PATCH_VERSION + 0) >= ((major)<<16) + ((minor)<<8) + (patch) ) - -// Reconstruct Octave major, minor, and patch versions for releases prior to 3.8.1 -#if !defined(OCTAVE_MAJOR_VERSION) - -# if !defined(OCTAVE_API_VERSION_NUMBER) - -// Hack to distinguish between Octave 3.8.0, which removed OCTAVE_API_VERSION_NUMBER but did not yet -// introduce OCTAVE_MAJOR_VERSION, and Octave <= 3.2, which did not define OCTAVE_API_VERSION_NUMBER -# include -# if defined(octave_ov_h) -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 8 -# define OCTAVE_PATCH_VERSION 0 -# else - -// Hack to distinguish between Octave 3.2 and earlier versions, before OCTAVE_API_VERSION_NUMBER existed -# define ComplexLU __ignore -# include -# undef ComplexLU -# if defined(octave_Complex_LU_h) - -// We know only that this version is prior to Octave 3.2, i.e. OCTAVE_API_VERSION_NUMBER < 37 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 1 -# define OCTAVE_PATCH_VERSION 99 - -# else - -// OCTAVE_API_VERSION_NUMBER == 37 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 2 -# define OCTAVE_PATCH_VERSION 0 - -# endif // defined(octave_Complex_LU_h) - -# endif // defined(octave_ov_h) - -// Correlation between Octave API and version numbers extracted from Octave's -// ChangeLogs; version is the *earliest* released Octave with that API number -# elif OCTAVE_API_VERSION_NUMBER >= 48 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 6 -# define OCTAVE_PATCH_VERSION 0 - -# elif OCTAVE_API_VERSION_NUMBER >= 45 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 4 -# define OCTAVE_PATCH_VERSION 1 - -# elif OCTAVE_API_VERSION_NUMBER >= 42 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 54 - -# elif OCTAVE_API_VERSION_NUMBER >= 41 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 53 - -# elif OCTAVE_API_VERSION_NUMBER >= 40 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 52 - -# elif OCTAVE_API_VERSION_NUMBER >= 39 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 51 - -# else // OCTAVE_API_VERSION_NUMBER == 38 -# define OCTAVE_MAJOR_VERSION 3 -# define OCTAVE_MINOR_VERSION 3 -# define OCTAVE_PATCH_VERSION 50 - -# endif // !defined(OCTAVE_API_VERSION_NUMBER) - -#endif // !defined(OCTAVE_MAJOR_VERSION) - -#include -#include -#include -#include -#include -#include -#include -#if SWIG_OCTAVE_PREREQ(4,2,0) -#include +#include "octheaders.hpp" +%} #else -#include +%insert(runtime) "octheaders.hpp"; #endif -#include -#if SWIG_OCTAVE_PREREQ(4,2,0) -#include -#endif - -%} %insert(runtime) "swigrun.swg"; %insert(runtime) "swigerrors.swg"; diff --git a/Lib/octave/std_complex.i b/Lib/octave/std_complex.i index 30c188244..461e2fdfc 100644 --- a/Lib/octave/std_complex.i +++ b/Lib/octave/std_complex.i @@ -4,10 +4,6 @@ %include -%{ -#include -%} - namespace std { %naturalvar complex; template class complex; -- cgit v1.2.1 From d73ef20475ac77e5f0fe4f641759e4bebcdc2428 Mon Sep 17 00:00:00 2001 From: Karl Wette Date: Sun, 31 May 2020 10:26:15 +1000 Subject: octrun.swg: ensure type_id() is set correctly --- Lib/octave/octrun.swg | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Lib/octave') diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 944b72a63..1069e0e54 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1058,7 +1058,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); octave_swig_type *ptr; public: octave_swig_ref(octave_swig_type *_ptr = 0) - :ptr(_ptr) { } + :ptr(_ptr) + { + // Ensure type_id() is set correctly + if (t_id == -1) { + t_id = octave_swig_ref::static_type_id(); + } + } ~octave_swig_ref() { if (ptr) ptr->decref(); } @@ -1199,8 +1205,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); public: octave_swig_packed(swig_type_info *_type = 0, const void *_buf = 0, size_t _buf_len = 0) - : type(_type), buf((const char*)_buf, (const char*)_buf + _buf_len) { - } + : type(_type), buf((const char*)_buf, (const char*)_buf + _buf_len) + { + // Ensure type_id() is set correctly + if (t_id == -1) { + t_id = octave_swig_packed::static_type_id(); + } + } bool copy(swig_type_info *outtype, void *ptr, size_t sz) const { if (outtype && outtype != type) -- cgit v1.2.1 From 4b5baf0a601c23061b6606426619ac7a13851ce6 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 10 Oct 2020 12:36:39 +0100 Subject: 0.0 float warning fix --- Lib/octave/octcomplex.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/octave') diff --git a/Lib/octave/octcomplex.swg b/Lib/octave/octcomplex.swg index a3e9ebf77..87e77a62e 100644 --- a/Lib/octave/octcomplex.swg +++ b/Lib/octave/octcomplex.swg @@ -73,7 +73,7 @@ int res = SWIG_AddCast(SWIG_AsVal(float)(ov, &d)); if (SWIG_IsOK(res)) { if (val) - *val = Constructor(d, 0.0); + *val = Constructor(d, 0.0f); return res; } } -- cgit v1.2.1 From f586d920f72aeedd8d4c9504415f4251005ef4bf Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Sat, 13 Nov 2021 21:23:08 +0200 Subject: Fix typos --- Lib/octave/octcomplex.swg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/octave') diff --git a/Lib/octave/octcomplex.swg b/Lib/octave/octcomplex.swg index 87e77a62e..553c25a3d 100644 --- a/Lib/octave/octcomplex.swg +++ b/Lib/octave/octcomplex.swg @@ -2,7 +2,7 @@ Defines the As/From conversors for double/float complex, you need to provide complex Type, the Name you want to use in the conversors, the complex Constructor method, and the Real and Imag complex - accesor methods. + accessor methods. See the std_complex.i and ccomplex.i for concrete examples. */ -- cgit v1.2.1 From 852eab7db33c5cfe073a9c8af983b7482a854075 Mon Sep 17 00:00:00 2001 From: Robert Fries Date: Wed, 12 May 2021 19:44:17 -0400 Subject: Allow swig wrapped modules to compile with -Bsymbolic --- Lib/octave/octrun.swg | 8 ++++++++ Lib/octave/octruntime.swg | 2 ++ 2 files changed, 10 insertions(+) (limited to 'Lib/octave') diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 1069e0e54..a7291df14 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1178,6 +1178,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); #endif { return ptr->print(os, pr_as_read_syntax); } +#if SWIG_OCTAVE_PREREQ(4,4,0) + static void set_type_id(int type_id) { t_id=type_id; } +#endif + virtual type_conv_info numeric_conversion_function(void) const { return octave_base_value::type_conv_info (default_numeric_conversion_function, octave_scalar::static_type_id ()); @@ -1285,6 +1289,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); # endif #endif +#if SWIG_OCTAVE_PREREQ(4,4,0) + static void set_type_id(int type_id) { t_id=type_id; } +#endif + private: #if !SWIG_OCTAVE_PREREQ(4,0,0) DECLARE_OCTAVE_ALLOCATOR; diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index a397fb7c1..ca69e44c4 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -295,9 +295,11 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { for (int i = 0; i < types.numel(); ++i) { if (types(i) == octave_swig_ref::static_type_name()) { register_octave_swig_ref = false; + octave_swig_ref::set_type_id(i); } if (types(i) == octave_swig_packed::static_type_name()) { register_octave_swig_packed = false; + octave_swig_packed::set_type_id(i); } } if (register_octave_swig_ref) { -- cgit v1.2.1 From 81f9e6600f2b4a53465aa07991834d8239e82fb7 Mon Sep 17 00:00:00 2001 From: Robert Fries Date: Wed, 12 May 2021 19:45:24 -0400 Subject: Octave module lets examples and tests work with Octave-6 * Try-catch replacement for check of error_state * Add execute method in addition to call * Replace oct_mach_info with octave::mach_info * Call from interpreter: global_varval global_assign * Assign a global name requires locating the stack which requires interpreter to tree evaluator to callStack * Do not use discard_error_messages or discard_warning_messages --- Lib/octave/octcontainer.swg | 11 +++++++- Lib/octave/octrun.swg | 69 +++++++++++++++++++++++++++++++++++++++++---- Lib/octave/octruntime.swg | 12 ++++++-- 3 files changed, 83 insertions(+), 9 deletions(-) (limited to 'Lib/octave') diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg index 80d593f4f..394c90bac 100644 --- a/Lib/octave/octcontainer.swg +++ b/Lib/octave/octcontainer.swg @@ -569,8 +569,17 @@ namespace swig { } else { return octseq.check() ? SWIG_OK : SWIG_ERROR; } - } catch (std::exception& e) { + } +%#if SWIG_OCTAVE_PREREQ(6,0,0) + catch (octave::execution_exception& exec) { + } +%#endif + catch (std::exception& e) { +%#if SWIG_OCTAVE_PREREQ(6,0,0) + if (seq) // Know that octave is not in an error state +%#else if (seq&&!error_state) +%#endif error("swig type error: %s",e.what()); return SWIG_ERROR; } diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index a7291df14..5100825e7 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -171,7 +171,16 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); octave_function* function_value(bool = false) { return this; } +#if SWIG_OCTAVE_PREREQ(6,0,0) octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) { + return execute(tw,nargout,args); + } +#endif +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave_value_list execute(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) { +#else + octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) { +#endif octave_value_list all_args; all_args.append(first_args); all_args.append(args); @@ -456,10 +465,20 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); // Fill in dim_vector for (int k=0;k a; + try { + a = out.int_vector_value(); + } + catch (octave::execution_exception& oee) { + return dim_vector(1,1); + } +#else Array a = out.int_vector_value(); if (error_state) return dim_vector(1,1); +#endif dim_vector d; d.resize(a.numel() < 2 ? 2 : a.numel()); d(0) = d(1) = 1; @@ -874,7 +903,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } virtual bool load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) { +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::mach_info::float_format fmt) { +#else + oct_mach_info::float_format fmt) { +#endif return true; } @@ -1142,7 +1175,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); { return ptr->save_binary(os, save_as_floats); } virtual bool load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::mach_info::float_format fmt) +#else + oct_mach_info::float_format fmt) +#endif { return ptr->load_binary(is, swap, fmt); } #if defined (HAVE_HDF5) @@ -1261,7 +1298,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); } virtual bool load_binary (std::istream& is, bool swap, - oct_mach_info::float_format fmt) { +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::mach_info::float_format fmt) { +#else + oct_mach_info::float_format fmt) { +#endif return true; } @@ -1515,16 +1556,24 @@ SWIGRUNTIMEINLINE void SWIG_Octave_SetConstant(octave_swig_type *module_ns, cons } SWIGRUNTIMEINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) { +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::interpreter *interp = octave::interpreter::the_interpreter (); + return interp->global_varval(name); +#else #if SWIG_OCTAVE_PREREQ(4,4,0) octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); return symtab.global_varval(name); #else return get_global_value(name, true); #endif +#endif } SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) { -#if SWIG_OCTAVE_PREREQ(4,4,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::interpreter *interp = octave::interpreter::the_interpreter (); + interp->global_assign(name, value); +#elif SWIG_OCTAVE_PREREQ(4,4,0) octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); symtab.global_assign(name, value); #else @@ -1534,10 +1583,20 @@ SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) { #if SWIG_OCTAVE_PREREQ(4,4,0) - octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); octave::symbol_scope symscope = octave::interpreter::the_interpreter()->get_current_scope(); +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::interpreter *interp = octave::interpreter::the_interpreter (); + interp->assign(name, interp->global_varval(name)); + octave::tree_evaluator& tree_eval = interp->get_evaluator(); + octave::call_stack& callStack = tree_eval.get_call_stack(); + std::shared_ptr stackFrame = callStack.get_current_stack_frame(); + octave::symbol_record sym=symscope.lookup_symbol(name); + stackFrame->mark_global(sym); +#else + octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table(); symscope.assign(name, symtab.global_varval(name)); symscope.mark_global(name); +#endif #else #if !SWIG_OCTAVE_PREREQ(3,2,0) link_to_global_variable(curr_sym_tab->lookup(name, true)); diff --git a/Lib/octave/octruntime.swg b/Lib/octave/octruntime.swg index ca69e44c4..e76151f14 100644 --- a/Lib/octave/octruntime.swg +++ b/Lib/octave/octruntime.swg @@ -19,7 +19,8 @@ static bool SWIG_init_user(octave_swig_type* module_ns); SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { bool retn = false; { -#if SWIG_OCTAVE_PREREQ(4,2,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) +#elif SWIG_OCTAVE_PREREQ(4,2,0) octave::unwind_protect frame; frame.protect_var(discard_error_messages); discard_error_messages = true; frame.protect_var(discard_warning_messages); discard_warning_messages = true; @@ -62,7 +63,8 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) { SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) { bool retn = false; { -#if SWIG_OCTAVE_PREREQ(4,2,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) +#elif SWIG_OCTAVE_PREREQ(4,2,0) octave::unwind_protect frame; frame.protect_var(discard_error_messages); discard_error_messages = true; frame.protect_var(discard_warning_messages); discard_warning_messages = true; @@ -316,7 +318,11 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) { SWIG_InitializeModule(0); SWIG_PropagateClientData(); -#if SWIG_OCTAVE_PREREQ(4,4,0) +#if SWIG_OCTAVE_PREREQ(6,0,0) + octave::tree_evaluator& tree_eval = octave::interpreter::the_interpreter()->get_evaluator(); + octave::call_stack& stack = tree_eval.get_call_stack(); + octave_function *me = stack.current_function(); +#elif SWIG_OCTAVE_PREREQ(4,4,0) octave::call_stack& stack = octave::interpreter::the_interpreter()->get_call_stack(); octave_function *me = stack.current(); #else -- cgit v1.2.1 From 983b91694fc9891e9c01f968cbbcdde96339434d Mon Sep 17 00:00:00 2001 From: Robert Fries Date: Wed, 12 May 2021 20:22:30 -0400 Subject: Additional changes due to name changes in octave-6 * is_map to isstruct, is_object to isobject --- Lib/octave/octrun.swg | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Lib/octave') diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 5100825e7..fda4596d6 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -660,7 +660,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return true; } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isstruct() const { +#else virtual bool is_map() const { +#endif return true; } @@ -808,7 +812,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); return as_value(); } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isobject() const { +#else virtual bool is_object() const { +#endif return true; } @@ -1117,8 +1125,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); bool is_defined() const { return ptr->is_defined(); } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isstruct() const + { return ptr->isstruct(); } +#else virtual bool is_map() const { return ptr->is_map(); } +#endif virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx) { return ptr->subsref(ops, idx); } @@ -1129,8 +1142,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own); octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs) { return ptr->subsasgn(ops, idx, rhs); } +#if SWIG_OCTAVE_PREREQ(6,0,0) + virtual bool isobject() const + { return ptr->isobject(); } +#else virtual bool is_object() const { return ptr->is_object(); } +#endif virtual bool is_string() const { return ptr->is_string(); } -- cgit v1.2.1