Mercurial > hg > octave-jordi
changeset 3239:d54ef0aa6e82
[project @ 1999-03-27 17:40:45 by jwe]
author | jwe |
---|---|
date | Sat, 27 Mar 1999 17:40:46 +0000 |
parents | 041ea33fbbf4 |
children | 2e74d8aa1a20 |
files | src/ChangeLog src/ov-usr-fcn.cc src/ov-usr-fcn.h src/ov.h src/pt-misc.cc src/pt-misc.h src/symtab.cc src/symtab.h src/variables.cc |
diffstat | 9 files changed, 127 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +Sat Mar 27 11:07:51 1999 John W. Eaton <jwe@bevo.che.wisc.edu> + + * ov.h (octave_value::count): New function. + * symtab.cc (symbol_record::dump_symbol_info): New function. + * symtab.cc (symbol_record::symbol_def::dump_symbol_info): Ditto. + * variables.cc (F__dump_symbol_info__): Ditto. + + * pt-misc.cc (tree_parameter_list::clear): New function. + * ov-usr-fcn.h (octave_user_function::clear_args_passed): Ditto. + * ov-usr-fcn.cc (clear_param_list): New function. + (clear_args_passed): New function. + (octave_user_function::do_index_op): Use them to decrement + reference counts on local variables. + Fri Mar 26 00:51:53 1999 John W. Eaton <jwe@bevo.che.wisc.edu> * Makefile.in (libraries): Use the libfoo.a(objects) method of
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -226,6 +226,24 @@ } static void +clear_param_list (void *lst) +{ + tree_parameter_list *tmp = static_cast<tree_parameter_list *> (lst); + + if (tmp) + tmp->clear (); +} + +static void +clear_args_passed (void *fcn) +{ + octave_user_function *tmp = static_cast<octave_user_function *> (fcn); + + if (tmp) + tmp->clear_args_passed (); +} + +static void unprotect_function (void *sr_arg) { symbol_record *sr = static_cast<symbol_record *> (sr_arg); @@ -302,6 +320,12 @@ args_passed = args; + // Force cache of arguments to be undefined when this function exits. + // Doing so decrements the reference counts on the values of local + // variables that are also named function parameters. + + unwind_protect::add (::clear_args_passed, this); + string_vector arg_names = args.name_tags (); unwind_protect_int (num_args_passed); @@ -317,6 +341,12 @@ goto abort; } + // Force parameter list to be undefined when this function exits. + // Doing so decrements the reference counts on the values of local + // variables that are also named function parameters. + + unwind_protect::add (clear_param_list, param_list); + if (ret_list && Vdefine_all_return_values) { octave_value tmp = builtin_any_variable ("default_return_value"); @@ -325,6 +355,12 @@ ret_list->initialize_undefined_elements (tmp); } + // Force return list to be undefined when this function exits. + // Doing so decrements the reference counts on the values of local + // variables that are also named values returned by this function. + + unwind_protect::add (clear_param_list, ret_list); + // The following code is in a separate scope to avoid warnings from // G++ about `goto abort' crossing the initialization of some // variables.
--- a/src/ov-usr-fcn.h +++ b/src/ov-usr-fcn.h @@ -111,6 +111,9 @@ string function_name (void) { return fcn_name; } + void clear_args_passed (void) + { args_passed = octave_value_list (); } + octave_value_list do_index_op (int nargout, const octave_value_list& args); void traceback_error (void);
--- a/src/ov.h +++ b/src/ov.h @@ -222,6 +222,8 @@ return *this; } + int count (void) { return rep->count; } + virtual type_conv_fcn numeric_conversion_function (void) const { return rep->numeric_conversion_function (); }
--- a/src/pt-misc.cc +++ b/src/pt-misc.cc @@ -110,6 +110,25 @@ } } +void +tree_parameter_list::clear (void) +{ + int len = length (); + + Pix p = first (); + + for (int i = 0; i < len; i++) + { + tree_identifier *elt = this->operator () (p); + + octave_lvalue ref = elt->lvalue (); + + ref.assign (octave_value::asn_eq, octave_value ()); + + next (p); + } +} + octave_value_list tree_parameter_list::convert_to_const_vector (tree_va_return_list *vr_list) {
--- a/src/pt-misc.h +++ b/src/pt-misc.h @@ -73,6 +73,8 @@ void define_from_arg_vector (const octave_value_list& args); + void clear (void); + bool is_defined (void); octave_value_list convert_to_const_vector (tree_va_return_list *vr_list);
--- a/src/symtab.cc +++ b/src/symtab.cc @@ -48,6 +48,14 @@ octave_allocator symbol_record::symbol_def::allocator (sizeof (symbol_record::symbol_def)); +void +symbol_record::symbol_def::dump_symbol_info (void) +{ + octave_stdout << "symbol_def::count: " << count << "\n"; + octave_stdout << "def.type_name(): " << definition.type_name () << "\n"; + octave_stdout << "def.count(): " << definition.count () << "\n"; +} + // Individual records in a symbol table. // XXX FIXME XXX -- there are lots of places below where we should @@ -304,6 +312,15 @@ os << " " << name () << "\n"; } +void +symbol_record::dump_symbol_info (void) +{ + if (definition) + definition->dump_symbol_info (); + else + octave_stdout << "symbol " << name () << " is undefined\n"; +} + bool symbol_record::read_only_error (const char *action) {
--- a/src/symtab.h +++ b/src/symtab.h @@ -177,6 +177,8 @@ // Reference count. int count; + void dump_symbol_info (void); + // No copying! symbol_def (const symbol_def& sd); @@ -295,6 +297,8 @@ void print_symbol_info_line (ostream& os); + void dump_symbol_info (void); + private: unsigned int formal_param : 1;
--- a/src/variables.cc +++ b/src/variables.cc @@ -1148,6 +1148,36 @@ return retval; } +DEFUN (__dump_symbol_info__, args, , + "__dump_symbol_info__ (NAME)") +{ + octave_value_list retval; + + int nargin = args.length (); + + if (nargin == 1) + { + string symbol_name = args(0).string_value (); + + if (! error_state) + { + symbol_record *sr = curr_sym_tab->lookup (symbol_name); + + if (sr) + sr->dump_symbol_info (); + else + error ("__dymp_symbol_info__: symbol %s not found", + symbol_name.c_str ()); + } + else + print_usage ("__dump_symbol_info__"); + } + else + print_usage ("__dump_symbol_info__"); + + return retval; +} + // XXX FIXME XXX -- some of these should do their own checking to be // able to provide more meaningful warning or error messages.