# HG changeset patch # User Mike Miller # Date 1493772242 25200 # Node ID b9b8790d10826ca361cb8a95f3ff49c72459a6e6 # Parent f833e29b2c12be04249553ca2e53dccdc6da10a0 Add overload of py_isinstance taking a string decribing a type * oct-py-util.h (pytave::py_isinstance): New function overload. * __py_struct_from_dict__.cc (F__py_isinstance__): Use it. * python_to_octave.cc (pytave::pyobj_to_octvalue): Use it. diff -r f833e29b2c12 -r b9b8790d1082 __py_struct_from_dict__.cc --- a/__py_struct_from_dict__.cc Tue May 02 10:06:14 2017 -0700 +++ b/__py_struct_from_dict__.cc Tue May 02 17:44:02 2017 -0700 @@ -238,8 +238,7 @@ pytave::py_init (); pytave::python_object obj = pytave::pyobject_unwrap_object (args(0)); - pytave::python_object type = pytave::py_find_type (typestr); - retval(0) = pytave::py_isinstance (obj, type); + retval(0) = pytave::py_isinstance (obj, typestr); return retval; } diff -r f833e29b2c12 -r b9b8790d1082 oct-py-util.h --- a/oct-py-util.h Tue May 02 10:06:14 2017 -0700 +++ b/oct-py-util.h Tue May 02 17:44:02 2017 -0700 @@ -83,6 +83,18 @@ bool py_isinstance (PyObject *obj, PyObject *type); + //! Check whether an object is an instance of a type. + //! + //! @param obj Python object + //! @param typestr name of a Python type + //! @return @c true if @a obj is an instance of the type named by @a typestr, + //! @c false otherwise + inline bool + py_isinstance (PyObject *obj, const std::string& typestr) + { + return py_isinstance (obj, py_find_type (typestr)); + } + std::string py_object_class_name (PyObject *obj); diff -r f833e29b2c12 -r b9b8790d1082 python_to_octave.cc --- a/python_to_octave.cc Tue May 02 10:06:14 2017 -0700 +++ b/python_to_octave.cc Tue May 02 17:44:02 2017 -0700 @@ -311,7 +311,6 @@ void pyobj_to_octvalue (octave_value& oct_value, const boost::python::object& py_object) { - boost::python::extract arrayx (py_object); if (PyBool_Check (py_object.ptr ())) oct_value = extract_py_bool (py_object.ptr ()); @@ -323,7 +322,7 @@ oct_value = extract_py_float (py_object.ptr ()); else if (PyComplex_Check (py_object.ptr ())) oct_value = extract_py_complex (py_object.ptr ()); - else if (arrayx.check ()) + else if (py_isinstance (py_object.ptr (), "numpy.ndarray")) pyarr_to_octvalue (oct_value, (PyArrayObject*)py_object.ptr ()); else oct_value = pyobject_wrap_object (py_object.ptr ());