octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

user type segfault


From: Paul Kienzle
Subject: user type segfault
Date: Tue, 11 Feb 2003 14:47:43 -0500
User-agent: Mutt/1.2.5.1i

Hi,

Here's a foolproof method of generating a segfault:

octave> x = make_int(1)
octave> clear functions
octave> x

It fails with any user defined type, since once
the oct-file is unloaded the virtual octave_value
functions are no longer available.  The following
code works around this:

  symbol_record *fn = fbi_sym_tab->lookup("myconstructor")
  fn->unprotect();
  fn->make_eternal();
  fn->make_as_static();
  fn->protect();

Now the constructor is no longer cleared so the oct-file
is no longer unloaded so the virtual functions are
still available.

I've defined lock_function(string) in variables.cc 
which does this.  Call lock_function("myconstructor")
when you call mytype::register_type().

Paul Kienzle
address@hidden

Paul Kienzle <address@hidden>
        * variables.cc,variables.h: define lock_function which
        prevents the named DEFUN_DLD function from being cleared.

Index: variables.h
===================================================================
RCS file: /cvs/octave/src/variables.h,v
retrieving revision 1.69
diff -c -p -r1.69 variables.h
*** variables.h 2002/12/28 04:02:31     1.69
--- variables.h 2003/02/11 19:41:29
*************** extern std::string builtin_string_variab
*** 84,89 ****
--- 84,90 ----
  extern int builtin_real_scalar_variable (const std::string&, double&);
  extern octave_value builtin_any_variable (const std::string&);
  
+ extern void lock_function (const std::string&);
  extern void link_to_global_variable (symbol_record *sr);
  extern void link_to_builtin_or_function (symbol_record *sr);
  
Index: variables.cc
===================================================================
RCS file: /cvs/octave/src/variables.cc,v
retrieving revision 1.242
diff -c -p -r1.242 variables.cc
*** variables.cc        2003/01/04 03:11:42     1.242
--- variables.cc        2003/02/11 19:41:29
*************** name_matches_any_pattern (const std::str
*** 1317,1322 ****
--- 1317,1335 ----
    return retval;
  }
  
+ void 
+ lock_function(const std::string& nm)
+ {
+   symbol_record *sr = fbi_sym_tab->lookup(nm,true);
+   if (sr)
+     {
+       sr->unprotect();
+       sr->make_eternal();
+       sr->mark_as_static();
+       sr->protect();
+     }
+ }
+ 
  static inline bool
  is_local_variable (const std::string& nm)
  {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]