Mercurial > pytave
changeset 106:896fdc369789
Use latest Octave library API
* pytave.cc, octave_to_python.cc, python_to_octave.cc: Force
octave/config.h to be included before other Octave include files. Update
uses of the Octave API to the latest version. Apply the following
replacements:
* Octave_map -> octave_map.
* symbol_table::varref -> symbol_table::assign
* symbol_table::global_varref -> symbol_table::global_assign
* Array<octave_value> -> octave_value_list
* Array<std::string> -> string_vector
* do_octave_atexit -> clean_up_and_exit
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Tue, 14 Apr 2015 07:44:24 -0400 |
parents | 81432840e1c0 |
children | 691ef5c6b9e2 |
files | octave_to_python.cc pytave.cc python_to_octave.cc |
diffstat | 3 files changed, 21 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/octave_to_python.cc Tue Apr 14 07:32:19 2015 -0400 +++ b/octave_to_python.cc Tue Apr 14 07:44:24 2015 -0400 @@ -28,8 +28,8 @@ #undef HAVE_STAT #undef HAVE_FSTAT +#include <octave/config.h> #include <octave/oct.h> -#include <octave/Matrix.h> #include <octave/ov.h> #include <octave/oct-map.h> @@ -282,7 +282,7 @@ } static void octmap_to_pyobject(boost::python::object &py_object, - const Octave_map& map) { + const octave_map& map) { py_object = boost::python::dict(); string_vector keys = map.keys();
--- a/pytave.cc Tue Apr 14 07:32:19 2015 -0400 +++ b/pytave.cc Tue Apr 14 07:44:24 2015 -0400 @@ -27,6 +27,7 @@ #undef HAVE_STAT #undef HAVE_FSTAT +#include <octave/config.h> #include <octave/oct.h> #include <octave/oct-map.h> @@ -125,10 +126,10 @@ variable_name_exception::excclass))); } - string make_error_message (const Octave_map& map) { + string make_error_message (const octave_map& map) { ostringstream exceptionmsg; - string message = map.stringfield("message", ""); - string identifier = map.stringfield("identifier", ""); + string message = map(0).getfield("message").string_value(); + string identifier = map(0).getfield("identifier").string_value(); Cell stackCell = map.contents("stack"); // Trim trailing new lines @@ -137,11 +138,11 @@ if (!stackCell.is_empty() && stackCell(0).is_map()) { // The struct element is called "stack" but only contain // info about the top frame. - Octave_map stack = stackCell(0).map_value(); - string file = stack.stringfield("file", ""); - string name = stack.stringfield("name", ""); - int line = stack.intfield("line", 1); - int column = stack.intfield("column", 2); + octave_map stack = stackCell(0).map_value(); + string file = stack(0).getfield("file").string_value(); + string name = stack(0).getfield("name").string_value(); + int line = stack(0).getfield("line").int_value(); + int column = stack(0).getfield("column").int_value(); exceptionmsg << file << ":" << line << ":" << column << ": "; if (!name.empty()) @@ -315,9 +316,9 @@ pyobj_to_octvalue(val, pyobject); if (global) - symbol_table::global_varref(name) = val; + symbol_table::global_assign (name, val); else - symbol_table::varref(name) = val; + symbol_table::assign (name, val); } bool isvar(const string& name, bool global) { @@ -374,7 +375,7 @@ #endif Py_BEGIN_ALLOW_THREADS - do_octave_atexit(); + clean_up_and_exit (0); Py_END_ALLOW_THREADS #ifdef HAVE_USELOCALE
--- a/python_to_octave.cc Tue Apr 14 07:32:19 2015 -0400 +++ b/python_to_octave.cc Tue Apr 14 07:44:24 2015 -0400 @@ -29,11 +29,12 @@ #undef HAVE_STAT #undef HAVE_FSTAT +#include <octave/config.h> #include <octave/oct.h> #include <octave/oct-map.h> #include <octave/Cell.h> -#include <octave/Matrix.h> #include <octave/ov.h> +#include <octave/Array.h> #include "pytavedefs.h" #include "arrayobjectdefs.h" @@ -352,15 +353,15 @@ dim_vector dims = dim_vector(1, 1); - Array<octave_value> vals (length); - Array<std::string> keys (length); + octave_value_list vals (length); + string_vector keys (length); // Extract all keys and convert values. Remember whether dimensions // match. for(octave_idx_type i = 0; i < length; i++) { - std::string& key = keys(i); + std::string& key = keys[i]; boost::python::tuple tuple = boost::python::extract<boost::python::tuple>(list[i])(); @@ -396,11 +397,11 @@ } } - Octave_map map = Octave_map(dims); + octave_map map = octave_map(dims); for(octave_idx_type i = 0; i < length; i++) { - std::string& key = keys(i); + std::string& key = keys[i]; octave_value val = vals(i); if(val.is_cell()) {