changeset 29957:64e3ef97384e

move some defun functions inside the octave namespace * defun-int.h, defun.cc (print_usage, check_version, install_dld_function, install_mex_function, get_current_shlib): Move functions inside Octave namespace. Provide inline global wrappers.
author John W. Eaton <jwe@octave.org>
date Sat, 14 Aug 2021 18:35:57 -0400
parents a956ca6698d2
children 32c3a5805893
files libinterp/corefcn/defun-int.h libinterp/corefcn/defun.cc
diffstat 2 files changed, 75 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/defun-int.h	Sat Aug 14 16:27:53 2021 -0400
+++ b/libinterp/corefcn/defun-int.h	Sat Aug 14 18:35:57 2021 -0400
@@ -41,7 +41,10 @@
 
 class octave_value;
 
+OCTAVE_NAMESPACE_BEGIN
+
 extern OCTINTERP_API void print_usage (void);
+
 extern OCTINTERP_API void print_usage (const std::string&);
 
 extern OCTINTERP_API void check_version (const std::string& version,
@@ -49,20 +52,22 @@
 
 extern OCTINTERP_API void
 install_dld_function (octave_dld_function::fcn f, const std::string& name,
-                      const octave::dynamic_library& shl, const std::string& doc,
+                      const dynamic_library& shl, const std::string& doc,
                       bool relative = false);
 
 extern OCTINTERP_API void
 install_dld_function (octave_dld_function::meth m, const std::string& name,
-                      const octave::dynamic_library& shl, const std::string& doc,
+                      const dynamic_library& shl, const std::string& doc,
                       bool relative = false);
 
 extern OCTINTERP_API void
 install_mex_function (void *fptr, bool fmex, const std::string& name,
-                      const octave::dynamic_library& shl, bool relative = false);
+                      const dynamic_library& shl, bool relative = false);
+
 // Gets the shlib of the currently executing DLD function, if any.
-extern OCTINTERP_API octave::dynamic_library
-get_current_shlib (void);
+extern OCTINTERP_API dynamic_library get_current_shlib (void);
+
+OCTAVE_NAMESPACE_END
 
 namespace octave
 {
@@ -81,6 +86,56 @@
 
     auto_shlib (const dynamic_library& shl) : dynamic_library (shl) { }
   };
+
+}
+
+// Some of these functions are widely used, so maybe we should avoid
+// deprecating them for now?
+
+inline void print_usage (void)
+{
+  octave::print_usage ();
+}
+
+inline void print_usage (const std::string& name)
+{
+  octave::print_usage (name);
+}
+
+inline void
+check_version (const std::string& version, const std::string& fcn)
+{
+  octave::check_version (version, fcn);
+}
+
+inline void
+install_dld_function (octave_dld_function::fcn f, const std::string& name,
+                      const octave::dynamic_library& shl,
+                      const std::string& doc, bool relative = false)
+{
+  octave::install_dld_function (f, name, shl, doc, relative);
+}
+
+inline void
+install_dld_function (octave_dld_function::meth m, const std::string& name,
+                      const octave::dynamic_library& shl,
+                      const std::string& doc, bool relative = false)
+{
+  octave::install_dld_function (m, name, shl, doc, relative);
+}
+
+inline void
+install_mex_function (void *fptr, bool fmex, const std::string& name,
+                      const octave::dynamic_library& shl,
+                      bool relative = false)
+{
+  octave::install_mex_function (fptr, fmex, name, shl, relative);
+}
+
+// Gets the shlib of the currently executing DLD function, if any.
+inline octave::dynamic_library get_current_shlib (void)
+{
+  return octave::get_current_shlib ();
 }
 
 #define FORWARD_DECLARE_FUNX(name)              \
--- a/libinterp/corefcn/defun.cc	Sat Aug 14 16:27:53 2021 -0400
+++ b/libinterp/corefcn/defun.cc	Sat Aug 14 18:35:57 2021 -0400
@@ -48,11 +48,13 @@
 #include "variables.h"
 #include "parse.h"
 
+OCTAVE_NAMESPACE_BEGIN
+
 // Print the usage part of the doc string of FCN (user-defined or DEFUN).
 void
 print_usage (void)
 {
-  octave::tree_evaluator& tw = octave::__get_evaluator__ ("print_usage");
+  tree_evaluator& tw = __get_evaluator__ ("print_usage");
 
   const octave_function *cur = tw.current_function ();
 
@@ -65,7 +67,7 @@
 void
 print_usage (const std::string& name)
 {
-  octave::feval ("print_usage", octave_value (name), 0);
+  feval ("print_usage", octave_value (name), 0);
 }
 
 void
@@ -85,7 +87,7 @@
 
 void
 install_dld_function (octave_dld_function::fcn f, const std::string& name,
-                      const octave::dynamic_library& shl, const std::string& doc,
+                      const dynamic_library& shl, const std::string& doc,
                       bool relative)
 {
   octave_dld_function *fcn = new octave_dld_function (f, shl, name, doc);
@@ -95,15 +97,14 @@
 
   octave_value fval (fcn);
 
-  octave::symbol_table& symtab
-    = octave::__get_symbol_table__ ("install_dld_function");
+  symbol_table& symtab = __get_symbol_table__ ("install_dld_function");
 
   symtab.install_built_in_function (name, fval);
 }
 
 void
 install_dld_function (octave_dld_function::meth m, const std::string& name,
-                      const octave::dynamic_library& shl, const std::string& doc,
+                      const dynamic_library& shl, const std::string& doc,
                       bool relative)
 {
   octave_dld_function *fcn = new octave_dld_function (m, shl, name, doc);
@@ -113,15 +114,14 @@
 
   octave_value fval (fcn);
 
-  octave::symbol_table& symtab
-    = octave::__get_symbol_table__ ("install_dld_function");
+  symbol_table& symtab = __get_symbol_table__ ("install_dld_function");
 
   symtab.install_built_in_function (name, fval);
 }
 
 void
 install_mex_function (void *fptr, bool fmex, const std::string& name,
-                      const octave::dynamic_library& shl, bool relative)
+                      const dynamic_library& shl, bool relative)
 {
   octave_mex_function *fcn = new octave_mex_function (fptr, fmex, shl, name);
 
@@ -130,18 +130,17 @@
 
   octave_value fval (fcn);
 
-  octave::symbol_table& symtab
-    = octave::__get_symbol_table__ ("install_mex_function");
+  symbol_table& symtab = __get_symbol_table__ ("install_mex_function");
 
   symtab.install_built_in_function (name, fval);
 }
 
-octave::dynamic_library
+dynamic_library
 get_current_shlib (void)
 {
-  octave::dynamic_library retval;
+  dynamic_library retval;
 
-  octave::tree_evaluator& tw = octave::__get_evaluator__ ("get_current_shlib");
+  tree_evaluator& tw = __get_evaluator__ ("get_current_shlib");
 
   octave_function *curr_fcn = tw.current_function ();
 
@@ -163,3 +162,5 @@
 
   return retval;
 }
+
+OCTAVE_NAMESPACE_END