bugGNU Octave - Bugs: bug #52582, using static method to initialize...

 
 

bug #52582: using static method to initialize property value fails

Submitter:  Damian Gisler <zweistein>
Submitted:  Sun 03 Dec 2017 04:47:55 PM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Damian Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 24 Apr 2019 10:13:41 PM UTC, comment #19: 

I don't get a segfault.  I get the same error as before about the file containing the classdef code not existing.

Rik <rik5>
Group administrator
Wed 24 Apr 2019 08:53:07 PM UTC, comment #18: 

I don't get seg fault, I guess sth related to this has changed between 5.1 and Dev.

Thanks for the workaround, but isn't it a bit strange having to move the function outside the class?

At the moment I use this alternative version that seems to work both in Matlab and Octave (not using Constant properties neither Static methods):


classdef testL2
    properties
      engine
      isMatlab
    end
    methods
        function obj = testL2()

            obj.isMatlab = f_isMatlab(obj);

            if obj.isMatlab
                obj.engine = 'matlab';
            else
                obj.engine = 'octave';
            end
        end

        function bool = f_isMatlab(obj)
            LIC = license('inuse');
            bool = strcmp(LIC.feature,'matlab');
        end
    end
end


avlas <kupiqu>
Wed 24 Apr 2019 08:50:15 PM UTC, comment #17: 

Also changing the title because I don' think this problem is about dependent properties.  Those are ones which have the attribute "Dependent" and for which there is no actual value, they are just computed by get methods.

The failure reported here looks like a problem with calling static functions during class initialization.

John W. Eaton <jwe>
Group administrator
Wed 24 Apr 2019 08:09:48 PM UTC, comment #16: 

With the example posted in comment #2, I see a segfault.  Gdb shows the following stack trace for the Octave interpreter:


octave:1> x = testL ()

Thread 1 "octave-cli" received signal SIGSEGV, Segmentation fault.
0x00007ffff752cccf in std::__deque_buf_size (__size=<error reading variable: Cannot access memory at address 0x7fffff7feff8>) at /usr/include/c++/8/bits/stl_deque.h:93
93          { return (__size < _GLIBCXX_DEQUE_BUF_SIZE
(gdb) where
#0  0x00007ffff752cccf in std::__deque_buf_size (__size=<error reading variable: Cannot access memory at address 0x7fffff7feff8>) at /usr/include/c++/8/bits/stl_deque.h:93
#1  0x00007ffff756479a in std::_Deque_iterator<octave::stack_frame*, octave::stack_frame*&, octave::stack_frame**>::_S_buffer_size () at /usr/include/c++/8/bits/stl_deque.h:130
#2  0x00007ffff7564832 in std::_Deque_iterator<octave::stack_frame*, octave::stack_frame*&, octave::stack_frame**>::operator+= (this=0x7fffff7ff080, __n=0)
    at /usr/include/c++/8/bits/stl_deque.h:212
#3  0x00007ffff7564774 in std::_Deque_iterator<octave::stack_frame*, octave::stack_frame*&, octave::stack_frame**>::operator+ (this=0x5555555d0af0, __n=0)
    at /usr/include/c++/8/bits/stl_deque.h:231
#4  0x00007ffff75646cb in std::_Deque_iterator<octave::stack_frame*, octave::stack_frame*&, octave::stack_frame**>::operator[] (this=0x5555555d0af0, __n=0)
    at /usr/include/c++/8/bits/stl_deque.h:247
#5  0x00007ffff756467f in std::deque<octave::stack_frame*, std::allocator<octave::stack_frame*> >::operator[] (this=0x5555555d0ae0, __n=0)
    at /usr/include/c++/8/bits/stl_deque.h:1404
#6  0x00007ffff771d116 in octave::call_stack::current_scope (this=0x5555555d0ad8) at /home/jwe/src/octave/libinterp/corefcn/call-stack.h:114
#7  0x00007ffff77106c2 in octave::tree_evaluator::get_current_scope (this=0x5555555d08d0) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:1868
#8  0x00007ffff7bd2c3e in octave::symbol_table::current_scope (this=0x5555555d0838) at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:72
#9  0x00007ffff7bd34b7 in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", search_scope_arg=...) at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:208

#10 0x00007ffff77138a1 in octave::tree_evaluator::visit_identifier (this=0x5555555d08d0, expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2659
#11 0x00007ffff77305f0 in octave::tree_identifier::accept (this=0x555559ab4b60, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-id.h:97
#12 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559ab4b60, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337
#13 0x00007ffff77146ac in octave::tree_evaluator::visit_index_expression (this=0x5555555d08d0, idx_expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2947
#14 0x00007ffff77327a6 in octave::tree_index_expression::accept (this=0x555559ab4c70, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-idx.h:106
#15 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559ab4c70, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337

#16 0x00007ffff752c011 in octave::cdef_class::make_meta_class (interp=..., t=0x555559ab9ed0, is_at_folder=false) at /home/jwe/src/octave/libinterp/octave-value/cdef-class.cc:1091
#17 0x00007ffff7708706 in octave::tree_classdef::make_meta_class (this=0x555559ab9ed0, interp=..., is_at_folder=false)
    at /home/jwe/src/octave/libinterp/parse-tree/pt-classdef.cc:173
#18 0x00007ffff7a70827 in octave::interpreter::parse_fcn_file (this=0x5555555cfcb0, full_file="/net/devnull/scratch/jwe/build/octave/testL.m", file="testL", dir_name=".",
    dispatch_type="", package_name="", require_file=true, force_script=false, autoload=false, relative_lookup=true, warn_for="")
    at /home/jwe/src/octave/libinterp/corefcn/interpreter.cc:1475
#19 0x00007ffff76e98ca in octave::load_fcn_from_file (file_name="./testL.m", dir_name=".", dispatch_type="", package_name="", fcn_name="", autoload=false)
    at /home/jwe/src/octave/libinterp/parse-tree/oct-parse.yy:4654
#20 0x00007ffff78585e5 in octave::fcn_info::fcn_info_rep::find_user_function (this=0x555559aac0a0) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:759
#21 0x00007ffff7855adb in octave::fcn_info::fcn_info_rep::load_class_constructor (this=0x555559aac0a0) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:122
#22 0x00007ffff785721d in octave::fcn_info::fcn_info_rep::xfind (this=0x555559aac0a0, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:472
#23 0x00007ffff7856b8f in octave::fcn_info::fcn_info_rep::find (this=0x555559aac0a0, scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:354
#24 0x00007ffff7bd7347 in octave::fcn_info::find (this=0x7fffff8012f0, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.h:247
#25 0x00007ffff7bd327e in octave::symbol_table::fcn_table_find (this=0x5555555d0838, name="testL", args=..., search_scope_arg=...)
--Type <RET> for more, q to quit, c to continue without paging--
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:175
#26 0x00007ffff7bd35cd in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", args=..., search_scope=...)
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:222
#27 0x00007ffff7bd34eb in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", search_scope_arg=...) at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:210
#28 0x00007ffff77138a1 in octave::tree_evaluator::visit_identifier (this=0x5555555d08d0, expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2659
#29 0x00007ffff77305f0 in octave::tree_identifier::accept (this=0x555559aa3740, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-id.h:97
#30 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559aa3740, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337
#31 0x00007ffff77146ac in octave::tree_evaluator::visit_index_expression (this=0x5555555d08d0, idx_expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2947
#32 0x00007ffff77327a6 in octave::tree_index_expression::accept (this=0x555559aa3850, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-idx.h:106
#33 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559aa3850, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337
#34 0x00007ffff752c011 in octave::cdef_class::make_meta_class (interp=..., t=0x555559aa8ab0, is_at_folder=false) at /home/jwe/src/octave/libinterp/octave-value/cdef-class.cc:1091
#35 0x00007ffff7708706 in octave::tree_classdef::make_meta_class (this=0x555559aa8ab0, interp=..., is_at_folder=false)
    at /home/jwe/src/octave/libinterp/parse-tree/pt-classdef.cc:173
#36 0x00007ffff7a70827 in octave::interpreter::parse_fcn_file (this=0x5555555cfcb0, full_file="/net/devnull/scratch/jwe/build/octave/testL.m", file="testL", dir_name=".",
    dispatch_type="", package_name="", require_file=true, force_script=false, autoload=false, relative_lookup=true, warn_for="")
    at /home/jwe/src/octave/libinterp/corefcn/interpreter.cc:1475
#37 0x00007ffff76e98ca in octave::load_fcn_from_file (file_name="./testL.m", dir_name=".", dispatch_type="", package_name="", fcn_name="", autoload=false)
    at /home/jwe/src/octave/libinterp/parse-tree/oct-parse.yy:4654
#38 0x00007ffff78585e5 in octave::fcn_info::fcn_info_rep::find_user_function (this=0x555559a9ac80) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:759
#39 0x00007ffff7855adb in octave::fcn_info::fcn_info_rep::load_class_constructor (this=0x555559a9ac80) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:122
#40 0x00007ffff785721d in octave::fcn_info::fcn_info_rep::xfind (this=0x555559a9ac80, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:472
#41 0x00007ffff7856b8f in octave::fcn_info::fcn_info_rep::find (this=0x555559a9ac80, scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:354
#42 0x00007ffff7bd7347 in octave::fcn_info::find (this=0x7fffff8034d0, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.h:247
#43 0x00007ffff7bd327e in octave::symbol_table::fcn_table_find (this=0x5555555d0838, name="testL", args=..., search_scope_arg=...)
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:175
#44 0x00007ffff7bd35cd in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", args=..., search_scope=...)
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:222
#45 0x00007ffff7bd34eb in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", search_scope_arg=...) at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:210
#46 0x00007ffff77138a1 in octave::tree_evaluator::visit_identifier (this=0x5555555d08d0, expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2659
#47 0x00007ffff77305f0 in octave::tree_identifier::accept (this=0x555559a92320, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-id.h:97
#48 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559a92320, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337
#49 0x00007ffff77146ac in octave::tree_evaluator::visit_index_expression (this=0x5555555d08d0, idx_expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2947
#50 0x00007ffff77327a6 in octave::tree_index_expression::accept (this=0x555559a92430, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-idx.h:106
#51 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559a92430, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337
--Type <RET> for more, q to quit, c to continue without paging--
#52 0x00007ffff752c011 in octave::cdef_class::make_meta_class (interp=..., t=0x555559a97690, is_at_folder=false) at /home/jwe/src/octave/libinterp/octave-value/cdef-class.cc:1091
#53 0x00007ffff7708706 in octave::tree_classdef::make_meta_class (this=0x555559a97690, interp=..., is_at_folder=false)
    at /home/jwe/src/octave/libinterp/parse-tree/pt-classdef.cc:173
#54 0x00007ffff7a70827 in octave::interpreter::parse_fcn_file (this=0x5555555cfcb0, full_file="/net/devnull/scratch/jwe/build/octave/testL.m", file="testL", dir_name=".",
    dispatch_type="", package_name="", require_file=true, force_script=false, autoload=false, relative_lookup=true, warn_for="")
    at /home/jwe/src/octave/libinterp/corefcn/interpreter.cc:1475
#55 0x00007ffff76e98ca in octave::load_fcn_from_file (file_name="./testL.m", dir_name=".", dispatch_type="", package_name="", fcn_name="", autoload=false)
    at /home/jwe/src/octave/libinterp/parse-tree/oct-parse.yy:4654
#56 0x00007ffff78585e5 in octave::fcn_info::fcn_info_rep::find_user_function (this=0x555559a89860) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:759
#57 0x00007ffff7855adb in octave::fcn_info::fcn_info_rep::load_class_constructor (this=0x555559a89860) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:122
#58 0x00007ffff785721d in octave::fcn_info::fcn_info_rep::xfind (this=0x555559a89860, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:472
#59 0x00007ffff7856b8f in octave::fcn_info::fcn_info_rep::find (this=0x555559a89860, scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:354
#60 0x00007ffff7bd7347 in octave::fcn_info::find (this=0x7fffff8056b0, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.h:247
#61 0x00007ffff7bd327e in octave::symbol_table::fcn_table_find (this=0x5555555d0838, name="testL", args=..., search_scope_arg=...)
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:175
#62 0x00007ffff7bd35cd in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", args=..., search_scope=...)
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:222
#63 0x00007ffff7bd34eb in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", search_scope_arg=...) at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:210
#64 0x00007ffff77138a1 in octave::tree_evaluator::visit_identifier (this=0x5555555d08d0, expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2659
#65 0x00007ffff77305f0 in octave::tree_identifier::accept (this=0x555559a80f00, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-id.h:97
#66 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559a80f00, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337
#67 0x00007ffff77146ac in octave::tree_evaluator::visit_index_expression (this=0x5555555d08d0, idx_expr=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.cc:2947
#68 0x00007ffff77327a6 in octave::tree_index_expression::accept (this=0x555559a81010, tw=...) at /home/jwe/src/octave/libinterp/parse-tree/pt-idx.h:106
#69 0x00007ffff752fb34 in octave::tree_evaluator::evaluate (this=0x5555555d08d0, expr=0x555559a81010, nargout=1) at /home/jwe/src/octave/libinterp/parse-tree/pt-eval.h:337
#70 0x00007ffff752c011 in octave::cdef_class::make_meta_class (interp=..., t=0x555559a86270, is_at_folder=false) at /home/jwe/src/octave/libinterp/octave-value/cdef-class.cc:1091
#71 0x00007ffff7708706 in octave::tree_classdef::make_meta_class (this=0x555559a86270, interp=..., is_at_folder=false)
    at /home/jwe/src/octave/libinterp/parse-tree/pt-classdef.cc:173
#72 0x00007ffff7a70827 in octave::interpreter::parse_fcn_file (this=0x5555555cfcb0, full_file="/net/devnull/scratch/jwe/build/octave/testL.m", file="testL", dir_name=".",
    dispatch_type="", package_name="", require_file=true, force_script=false, autoload=false, relative_lookup=true, warn_for="")
    at /home/jwe/src/octave/libinterp/corefcn/interpreter.cc:1475
#73 0x00007ffff76e98ca in octave::load_fcn_from_file (file_name="./testL.m", dir_name=".", dispatch_type="", package_name="", fcn_name="", autoload=false)
    at /home/jwe/src/octave/libinterp/parse-tree/oct-parse.yy:4654
#74 0x00007ffff78585e5 in octave::fcn_info::fcn_info_rep::find_user_function (this=0x555559a78440) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:759
#75 0x00007ffff7855adb in octave::fcn_info::fcn_info_rep::load_class_constructor (this=0x555559a78440) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:122
--Type <RET> for more, q to quit, c to continue without paging--
#76 0x00007ffff785721d in octave::fcn_info::fcn_info_rep::xfind (this=0x555559a78440, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:472
#77 0x00007ffff7856b8f in octave::fcn_info::fcn_info_rep::find (this=0x555559a78440, scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.cc:354
#78 0x00007ffff7bd7347 in octave::fcn_info::find (this=0x7fffff807890, search_scope=..., args=...) at /home/jwe/src/octave/libinterp/corefcn/fcn-info.h:247
#79 0x00007ffff7bd327e in octave::symbol_table::fcn_table_find (this=0x5555555d0838, name="testL", args=..., search_scope_arg=...)
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:175
#80 0x00007ffff7bd35cd in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", args=..., search_scope=...)
    at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:222
#81 0x00007ffff7bd34eb in octave::symbol_table::find_function (this=0x5555555d0838, name="testL", search_scope_arg=...) at /home/jwe/src/octave/libinterp/corefcn/symtab.cc:210


It looks like an infinite recursion problem to me.

If I move the f_isMatlab function outside of the class and change the rest of the class to be


classdef testL
    properties
      engine
    end
    properties(Constant=true, Hidden=true, Access=private)
        isMatlab = f_isMatlab()
    end
    methods
        function obj = testL()
            if testL.isMatlab
                obj.engine = 'matlab';
            else
                obj.engine = 'octave';
            end
        end
    end
end


then it appears to work.  So the infinite recursion problem might be due to calling the static method while constructing the class?

John W. Eaton <jwe>
Group administrator
Wed 24 Apr 2019 06:59:59 PM UTC, comment #15: 

Sorry, I was not familiar with rich markup:


classdef testL
    properties
      engine
    end
    properties(Constant=true, Hidden=true, Access=private)
        isMatlab = testL.f_isMatlab()
    end
    methods
        function obj = testL()
            if testL.isMatlab
                obj.engine = 'matlab';
            else
                obj.engine = 'octave';
            end
        end
    end
    methods(Static=true, Hidden=true)
        function bool = f_isMatlab()
            LIC = license('inuse');
            bool = strcmp(LIC.feature,'matlab');
        end
    end
end


avlas <kupiqu>
Wed 24 Apr 2019 06:55:18 PM UTC, comment #14: 

I'm having a similar (if not the same) issue in Octave 5.1, with the following example that uses the license to check the backend engine, whether Matlab or Octave:

classdef testL
    properties
      engine
    end
    properties(Constant=true, Hidden=true, Access=private)
        isMatlab = testL.f_isMatlab()
    end
    methods
        function obj = testL()
            if testL.isMatlab
                obj.engine = 'matlab';
            else
                obj.engine = 'octave';
            end
        end
    end
    methods(Static=true, Hidden=true)
        function bool = f_isMatlab()
            LIC = license('inuse');
            bool = strcmp(LIC.feature,'matlab');
        end
    end
end

This works in Matlab, but in Octave I get an analogous error to the one reported in this thread:

x = testL()
error: no such file, 'testL.m'

[ I apologize if adding another example is not useful and just adds noise ]

avlas <kupiqu>
Sun 03 Mar 2019 09:24:00 PM UTC, comment #13: 

With the code from comment #8 I can get a segfault simply by trying to create an instance of the class.  Looking at a stack trace, the parser is being called recursively while trying to create the meta class object, while evaluating the properties block.  There is a comment in the cdef-class.cc file that that is not exactly about this issue, but it seems relevant:


// Property blocks

// FIXME: default property expression should be able to call static
//        methods of the class being constructed.  A restricted CLASSNAME
//        symbol should be added to the scope before evaluating default
//        value expressions.


I'm not sure of the details, but it seems we need to do what that comment suggests and register the partially constructed object so that we can use it (at least as much as has been constructed so far) to complete the initialization and fully construct the meta object.

John W. Eaton <jwe>
Group administrator
Sun 03 Mar 2019 08:15:01 PM UTC, comment #12: 

Okay, I an reproduce the "no such file" message if I start with


run-octave -f



Rik <rik5>
Group administrator
Sun 03 Mar 2019 05:09:03 PM UTC, comment #11: 

I still get the error message reported in comment #8


>> x = Crash ()
error: no such file, '/home/mike/Crash.m'


Mike Miller <mtmiller>
Group Member
Sun 03 Mar 2019 07:03:42 AM UTC, comment #10: 

I just tested with changeset 26816:92ecc4a97b5c.  I see no crash or error message.

@Rik, that's a strange error to have for this code, since the script has no indexing.  I see that "sq_string" using a lot in the ov.cc and "cannot be indexed with" shows up all over the Octave source.  My guess at starting point would be that the parser in your case is having trouble trying to look up the structure element name.  Perhaps using the '.' of ".c1" to search a variable table?

Dan Sebald <sebald>
Sun 03 Mar 2019 05:29:14 AM UTC, comment #9: 

Running on the latest development tip, this still doesn't work, but the error message has change once again.


octave:1> Crash.c1
error: sq_string cannot be indexed with .


Adding jwe to the CC list simply because he has been looking at classdef issues lately.

Rik <rik5>
Group administrator
Tue 27 Nov 2018 03:19:10 AM UTC, comment #8: 

An update on this issue (I'm running Octave 4.4.1 on Xubuntu):

Using the given Crash classdef example from this thread:


classdef Crash < handle
properties (Constant)
c1 = 1;
c2 = Crash.c1 + 1;
end
end


When I run


Crash.c1


or


Crash.c2


from the Octave interpreter, for me Octave does not crash (as Daiman said he observed). Instead I get the following error message:


error: no such file, '/home/teerav42/Documents/junk/Crash.m'


I guess it's good that it doesn't crash any more, but a fix would be nice. As Philip mentioned, the above works just fine in Matlab.

Travis Arnold <teerav42>
Tue 05 Dec 2017 05:21:07 PM UTC, comment #7: 

OK, "which".  Yes, I'm seeing that:


octave:2> which('Crash')
'Crash' is a built-in function


It appears someone has filed a bug report related to "type" and classdef (https://savannah.gnu.org/bugs/?52585), so I think that covers most issues at the moment.

Dan Sebald <sebald>
Tue 05 Dec 2017 04:16:22 PM UTC, comment #6: 

@Dan: That is what I was trying to say.  Whenever a function is used for the first time, regardless of whether it is invoked, queried for help, or the target of the type() function, it is first parsed.  If it fails parsing then the overall command fails.

Bug report #50541 explains a bit why which() returns "built-in function" for a classdef file.  That doesn't seem right in this case where the function is a user-specified classdef file.

I filed a report about not being ablet to use the help system with classdef keywords here https://savannah.gnu.org/bugs/index.php?52591


Rik <rik5>
Group administrator
Tue 05 Dec 2017 09:36:05 AM UTC, comment #5: 

Octave must be trying to evaluate the expressing before typing out its contents, i.e., Crash() as opposed to Crash.m which must be a file...well, I suppose Crash.m could be a classdef element, ha.

Here, I'm seeing a 2 rather than a 5:


octave:2> exist('Crash')
ans =  2
octave:3> help exist
[snip]
     2
          NAME is an absolute filename, an ordinary file in Octave's
          'path', or (after appending '.m') a function file in Octave's
          'path'.


Dan Sebald <sebald>
Mon 04 Dec 2017 11:55:52 PM UTC, comment #4: 

The segmentation fault is the same from type () as it is for invoking the file to create an instance of an object.  The issue is that the first time Octave needs an m-file, for whatever reason, it parses it.  And since this file doesn't parse correctly it causes some sort of error.

I think the other two issues should be opened as independent bug reports.  One should be able to say 'type classfile' and have it work.  Indeed, this works if you specifically give it the name of the file


type Crash.m


The file type.m can be inspected to see what is going on.  The problem is that


exist ("Crash")


returns "Built-in Function".  All classdef files do this, which is incorrect.  There is a bug report about that already.

The second issue, at least minimal help for the "classdef" keyword, is a new issue report.  There is a file libinterp/op-kw-docs which contains help text for keywords and operators.  It probably needs the addition of "classdef", "properties", "enumeration", etc.

Rik <rik5>
Group administrator
Mon 04 Dec 2017 10:45:43 PM UTC, comment #3: 

This classdef needs some work.  Just typing the file causes a crash:


octave:1> type Crash
Segmentation fault


The use of Crash.c1 immediately after its definition is what's causing the segfault.  The following:


classdef Crash < handle
    properties (Constant)
        c1 = 1;
        c2 = 1;
    end
 end


does not cause a crash, but it still doesn't handle typing correctly:


octave:1> x = Crash ()
x =

<object Crash>

octave:2> x.c1
ans =  1
octave:3> x.c2
ans =  1
octave:4> type Crash
error: type: couldn't open '' for reading
error: called from
    type at line 85 column 9


Note that there is no "help" for classdef:


octave:4> help classdef
error: help: 'classdef' not found
octave:4> type classdef
classdef is a keyword


Definitely some interpreter issues, and probably not a minor fix.

Dan Sebald <sebald>
Mon 04 Dec 2017 12:00:43 PM UTC, comment #2: 

FWIW, in Matlab r2017b:

>> format compact
>> Crash
ans =
  Crash with properties:

    c1: 1
    c2: 2
>> Crash.c2
ans =
     2
>>


Octave 4.3.0+ (a tip from 26 nov) segfaults already at just a:

which Crash

Status -> confirmed
Release -> dev

Philip Nienhuis <philipnienhuis>
Group Member
Mon 04 Dec 2017 02:38:38 AM UTC, comment #1: 

I can confirm that there is some strangeness.  With 4.2.1, I get


octave:1> x = Crash
error: no such file, '/home/rik/downloads/Crash.m'


That alone is weird.  With the development branch I get a true segfault.


octave:1> x  = Crash ()
Segmentation fault


On the other hand, is this even valid code?  Does it run under Matlab?

It appears to me that this line


c2 = Crash.c1 + 1;


will cause an infinite loop.  The first time an object of the class is created the class will try to be initialized.  The line 'c1 = 1' is straightforward.  The next line will allocate space for the variable c2, but then will call the class constructor Crash because 'Crash.c1' does not yet exist as a class constant variable since the first initialization has not finished.


Rik <rik5>
Group administrator
Sun 03 Dec 2017 04:47:55 PM UTC, original submission:  

If an instance of the following class is created with
ans = Crash;
or if c2 is accessed with
ans = Crash.c2;
Octave will crash.


classdef Crash < handle
    properties (Constant)
        c1 = 1;
        c2 = Crash.c1 + 1;
    end
end

Damian Gisler <zweistein>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #42561:  Crash.m added by zweistein (110B - application/octet-stream)

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by seijikun
  • -email is unavailable- added by kupiqu (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5
  • -email is unavailable- added by teerav42 (Posted a comment)
  • -email is unavailable- added by sebald (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by zweistein (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-26 rik5 Dependencies- bugs #65214 is dependent
    2024-01-23 mmuetzel CategoryInterpreter Classdef
    2019-08-16 seijikun Carbon-Copy- Added seijikun
    2019-04-24 jwe SummaryDependent constant properties in classdef errors: no such file using static method to initialize property value fails
    2019-03-11 mtmiller Dependencies- bugs #45457 is dependent
    2019-03-03 rik5 Carbon-Copy- Added jwe
    2018-12-21 mtmiller Item GroupOther Incorrect Result
        Summary Dependent constant properties cause a crash Dependent constant properties in classdef errors: no such file
    2017-12-05 rik5 Operating SystemMicrosoft Windows Any
    2017-12-04 philipnienhuis StatusNone Confirmed
        Release4.2.1 dev
    2017-12-03 zweistein Attached File- Added Crash.m, #42561

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code