# HG changeset patch # User John W. Eaton # Date 1343062784 14400 # Node ID ea69976576142602e3314aba2987db2188948906 # Parent 1f5dbfc23fc2c61b29d1594ba0cb8399c77b699d which: provide source file name for built-in functions * defun-int.h, defun.cc (install_builtin_function): New arg, FILE. Pass file to octave_builtin constructor. * mkbuiltins: Redefine XDEFUN_FILE_NAME to create a local FILE variable. Pass FILE to install_builtin_function. * ov-builtin.h (octave_builtin::file): New member variable. (octave_builtin::octave_builtin): Handle file name. (octave_builtin::fcn_file_name): New function. * ov-fcn-handle.cc (octave_fcn_handle::set_fcn): Only attempt to load functions from .oct, .mex, or .m files. diff -r 1f5dbfc23fc2 -r ea6997657614 src/defun-int.h --- a/src/defun-int.h Mon Jul 23 06:53:09 2012 -0500 +++ b/src/defun-int.h Mon Jul 23 12:59:44 2012 -0400 @@ -39,7 +39,7 @@ extern OCTINTERP_API void install_builtin_function (octave_builtin::fcn f, const std::string& name, - const std::string& doc, + const std::string& file, const std::string& doc, bool can_hide_function = true); extern OCTINTERP_API void diff -r 1f5dbfc23fc2 -r ea6997657614 src/defun.cc --- a/src/defun.cc Mon Jul 23 06:53:09 2012 -0500 +++ b/src/defun.cc Mon Jul 23 12:59:44 2012 -0400 @@ -80,10 +80,10 @@ void install_builtin_function (octave_builtin::fcn f, const std::string& name, - const std::string& doc, + const std::string& file, const std::string& doc, bool /* can_hide_function -- not yet implemented */) { - octave_value fcn (new octave_builtin (f, name, doc)); + octave_value fcn (new octave_builtin (f, name, file, doc)); symbol_table::install_built_in_function (name, fcn); } diff -r 1f5dbfc23fc2 -r ea6997657614 src/mkbuiltins --- a/src/mkbuiltins Mon Jul 23 06:53:09 2012 -0500 +++ b/src/mkbuiltins Mon Jul 23 12:59:44 2012 -0400 @@ -57,19 +57,20 @@ #endif -#define XDEFUN_FILE_NAME(name) +#define XDEFUN_FILE_NAME(name) \ + std::string file = name; #define XDEFUN_INTERNAL(name, args_name, nargout_name, doc) \ extern DECLARE_FUN (name, args_name, nargout_name); \ - install_builtin_function (F ## name, #name, doc); \ + install_builtin_function (F ## name, #name, file, doc); \ #define XDEFCONSTFUN_INTERNAL(name, args_name, nargout_name, doc) \ extern DECLARE_FUN (name, args_name, nargout_name); \ - install_builtin_function (F ## name, #name, doc, false); \ + install_builtin_function (F ## name, #name, file, doc, false); \ #define XDEFUNX_INTERNAL(name, fname, args_name, nargout_name, doc) \ extern DECLARE_FUNX (fname, args_name, nargout_name); \ - install_builtin_function (fname, name, doc); \ + install_builtin_function (fname, name, file, doc); \ #define XDEFALIAS_INTERNAL(alias, name) \ alias_builtin (#alias, #name); diff -r 1f5dbfc23fc2 -r ea6997657614 src/ov-builtin.h --- a/src/ov-builtin.h Mon Jul 23 06:53:09 2012 -0500 +++ b/src/ov-builtin.h Mon Jul 23 12:59:44 2012 -0400 @@ -40,16 +40,22 @@ { public: - octave_builtin (void) : octave_function (), f (0), jtype (0) { } + octave_builtin (void) : octave_function (), f (0), file (), jtype (0) { } typedef octave_value_list (*fcn) (const octave_value_list&, int); octave_builtin (fcn ff, const std::string& nm = std::string (), const std::string& ds = std::string ()) - : octave_function (nm, ds), f (ff), jtype (0) { } + : octave_function (nm, ds), f (ff), file (), jtype (0) { } + + octave_builtin (fcn ff, const std::string& nm, const std::string& fnm, + const std::string& ds) + : octave_function (nm, ds), f (ff), file (fnm), jtype (0) { } ~octave_builtin (void) { } + std::string fcn_file_name (void) const { return file; } + octave_value subsref (const std::string& type, const std::list& idx) { @@ -89,6 +95,9 @@ // A pointer to the actual function. fcn f; + // The name of the file where this function was defined. + std::string file; + // A pointer to the jit type that represents the function. jit_type *jtype; diff -r 1f5dbfc23fc2 -r ea6997657614 src/ov-fcn-handle.cc --- a/src/ov-fcn-handle.cc Mon Jul 23 06:53:09 2012 -0500 +++ b/src/ov-fcn-handle.cc Mon Jul 23 12:59:44 2012 -0400 @@ -313,7 +313,11 @@ } else { - if (fpath.length () > 0) + size_t fpath_len = fpath.length (); + + if ((fpath_len > 4 && fpath.substr (fpath_len-4) == ".oct") + || (fpath_len > 4 && fpath.substr (fpath_len-4) == ".mex") + || (fpath_len > 2 && fpath.substr (fpath_len-4) == ".m")) { size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); @@ -327,11 +331,6 @@ fcn = octave_value (new octave_fcn_handle (tmp, nm)); } - else - { - error ("function handle points to non-existent function"); - success = false; - } } else { @@ -384,9 +383,10 @@ { octave_function *f = function_value (); std::string fnm = f ? f->fcn_file_name () : std::string (); + bool is_builtin = f && f->is_builtin_function (); os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n"; - if (! fnm.empty ()) + if (! (is_builtin || fnm.empty ())) os << "# path: " << fnm << "\n"; os << nm << "\n"; }