# HG changeset patch # User John W. Eaton # Date 1629054369 14400 # Node ID da1678140f7e676bdb0b5fbf99014103560a311c # Parent 7d9be634ac91d32aac723f563bc7d01bff3b599b make interpreter functions in .oct files static * find-defun-files.sh, mk-pkg-add.sh, mk-doc.pl: Adjust regular expression patterns to also find DEFUN_STATIC_DLD, DEFUNX_STATIC_DLD, DEFMETHOD_STATIC_DLD, and DEFMETHODX_STATIC_DLD. * defun-int.h (FORWARD_DECLARE_STATIC_FUNX, FORWARD_DECLARE_STATIC_METHODX, FORWARD_DECLARE_STATIC_FUN, FORWARD_DECLARE_STATIC_METHOD): New macros. * defun-dld.h (DEFUN_STATIC_DLD, DEFUNX_STATIC_DLD, DEFMETHOD_STATIC_DLD, DEFMETHODX_STATIC_DLD): New macros. If OCTAVE_USE_STATIC_DEFUN is defined, make DEFUN_DLD, DEFUNX_DLD, DEFMTHOD_DLD, and DEFMETHODX_DLD expand to the static versions. * oct-conf-post.in.h: Define OCTAVE_USE_STATIC_DEFUN. diff -r 7d9be634ac91 -r da1678140f7e build-aux/find-defun-files.sh --- a/build-aux/find-defun-files.sh Sun Aug 15 15:00:49 2021 -0400 +++ b/build-aux/find-defun-files.sh Sun Aug 15 15:06:09 2021 -0400 @@ -34,7 +34,7 @@ # so we have to repeat ourselves because some stupid egreps don't like # empty elements in alternation patterns. -DEFUN_PATTERN="^[ \t]*DEF(CONSTFUN|CONSTMETHOD|METHOD|METHOD_DLD|METHODX|METHODX_DLD|UN|UN_DLD|UNX|UNX_DLD)[ \t]*\\(" +DEFUN_PATTERN="^[ \t]*DEF(CONSTFUN|CONSTMETHOD|METHOD|METHOD_(|STATIC_)DLD|METHODX|METHODX_(|STATIC_)DLD|UN|UN_(|STATIC_)DLD|UNX|UNX_(|STATIC_)DLD)[ \t]*\\(" srcdir="$1" if [ "$1" ]; then diff -r 7d9be634ac91 -r da1678140f7e build-aux/mk-pkg-add.sh --- a/build-aux/mk-pkg-add.sh Sun Aug 15 15:00:49 2021 -0400 +++ b/build-aux/mk-pkg-add.sh Sun Aug 15 15:06:09 2021 -0400 @@ -45,11 +45,11 @@ ## Compute and print the autoloads. base=`basename "$src_file" | $SED 's/\.cc$//'` - fcns=`$SED -n -e 's/^ *DEFMETHOD_DLD *( *\([^, ]*\) *,.*$/\1/p' \ - -e 's/^ *DEFMETHODX_DLD *( *"\([^"]*\)".*$/\1/p' \ - -e 's/^ *DEFUN_DLD *( *\([^, ]*\) *,.*$/\1/p' \ - -e 's/^ *DEFUNX_DLD *( *"\([^"]*\)".*$/\1/p' "$src_file" | \ - sort -u` + fcns=`$SED -n \ + -e 's/^ *DEF\(METHOD\|UN\)_\(\|STATIC_\)DLD *( *\([^, ]*\) *,.*$/\3/p' \ + -e 's/^ *DEF\(METHOD\|UN\)X_\(\|STATIC_\)DLD *( *"\([^"]*\)".*$/\3/p' \ + "$src_file" | \ + sort -u` if [ -n "$fcns" ]; then for n in $fcns; do if [ "$n" = "$base" ]; then diff -r 7d9be634ac91 -r da1678140f7e libinterp/corefcn/defun-dld.h --- a/libinterp/corefcn/defun-dld.h Sun Aug 15 15:00:49 2021 -0400 +++ b/libinterp/corefcn/defun-dld.h Sun Aug 15 15:06:09 2021 -0400 @@ -107,4 +107,45 @@ DEFINE_FUNX_INSTALLER_FUN (name, fname, gname, doc) \ DECLARE_METHODX (fname, interp_name, args_name, nargout_name) +// The same as the above, but declare the functions as static. +// NOTE: These macros should not be used directly. + +#define DEFUN_STATIC_DLD(name, args_name, nargout_name, doc) \ + FORWARD_DECLARE_STATIC_FUN (name); \ + DEFINE_FUN_INSTALLER_FUN (name, doc) \ + DECLARE_STATIC_FUN (name, args_name, nargout_name) + +#define DEFUNX_STATIC_DLD(name, fname, gname, args_name, \ + nargout_name, doc) \ + FORWARD_DECLARE_STATIC_FUNX (fname); \ + DEFINE_FUNX_INSTALLER_FUN (name, fname, gname, doc) \ + DECLARE_STATIC_FUNX (fname, args_name, nargout_name) + +#define DEFMETHOD_STATIC_DLD(name, interp_name, args_name, \ + nargout_name, doc) \ + FORWARD_DECLARE_STATIC_METHOD (name); \ + DEFINE_FUN_INSTALLER_FUN (name, doc) \ + DECLARE_STATIC_METHOD (name, interp_name, args_name, nargout_name) + +#define DEFMETHODX_STATIC_DLD(name, fname, gname, interp_name, \ + args_name, nargout_name, doc) \ + FORWARD_DECLARE_STATIC_METHODX (fname); \ + DEFINE_FUNX_INSTALLER_FUN (name, fname, gname, doc) \ + DECLARE_STATIC_METHODX (fname, interp_name, args_name, nargout_name) + +// The oct-conf-post.h file defines OCTAVE_USE_STATIC_DEFUN to force all +// dynamically loaded interpreter functions and methods to be static. + +#if defined (OCTAVE_USE_STATIC_DEFUN) +# undef DEFUN_DLD +# undef DEFUNX_DLD +# undef DEFMETHOD_DLD +# undef DEFMETHODX_DLD + +# define DEFUN_DLD DEFUN_STATIC_DLD +# define DEFUNX_DLD DEFUNX_STATIC_DLD +# define DEFMETHOD_DLD DEFMETHOD_STATIC_DLD +# define DEFMETHODX_DLD DEFMETHODX_STATIC_DLD #endif + +#endif diff -r 7d9be634ac91 -r da1678140f7e libinterp/corefcn/defun-int.h --- a/libinterp/corefcn/defun-int.h Sun Aug 15 15:00:49 2021 -0400 +++ b/libinterp/corefcn/defun-int.h Sun Aug 15 15:06:09 2021 -0400 @@ -160,6 +160,20 @@ #define DECLARE_METHOD(name, interp_name, args_name, nargout_name) \ DECLARE_METHODX (F ## name, interp_name, args_name, nargout_name) +#define FORWARD_DECLARE_STATIC_FUNX(name) \ + static octave_value_list \ + name (const octave_value_list&, int) + +#define FORWARD_DECLARE_STATIC_METHODX(name) \ + static octave_value_list \ + name (octave::interpreter&, const octave_value_list&, int) + +#define FORWARD_DECLARE_STATIC_FUN(name) \ + FORWARD_DECLARE_STATIC_FUNX (F ## name) + +#define FORWARD_DECLARE_STATIC_METHOD(name) \ + FORWARD_DECLARE_STATIC_METHODX (F ## name) + #define DECLARE_STATIC_FUNX(name, args_name, nargout_name) \ static octave_value_list \ name (const octave_value_list& args_name, int nargout_name) diff -r 7d9be634ac91 -r da1678140f7e libinterp/mk-doc.pl --- a/libinterp/mk-doc.pl Sun Aug 15 15:00:49 2021 -0400 +++ b/libinterp/mk-doc.pl Sun Aug 15 15:06:09 2021 -0400 @@ -55,7 +55,7 @@ LINE: while (my $line = ) { - if ($line =~ /^\s*DEF(?:CONSTFUN|CONSTMETHOD|METHOD|METHOD_DLD|METHODX|METHODX_DLD|UN|UN_DLD|UNX|UNX_DLD)\s*\(/) + if ($line =~ /^\s*DEF(?:CONSTFUN|CONSTMETHOD|METHOD|METHOD_(|STATIC_)DLD|METHODX|METHODX_(|STATIC_)DLD|UN|UN_(|STATIC_)DLD|UNX|UNX_(|STATIC_)DLD)\s*\(/) { ($func) = $line =~ /\("?(\w+)"?,/; unless ($func) { die "Unable to parse $src_fname at line $.\n" } diff -r 7d9be634ac91 -r da1678140f7e oct-conf-post.in.h --- a/oct-conf-post.in.h Sun Aug 15 15:00:49 2021 -0400 +++ b/oct-conf-post.in.h Sun Aug 15 15:06:09 2021 -0400 @@ -273,6 +273,9 @@ # define OCTAVE_THREAD_LOCAL #endif +/* Make all .oct file interpreter functions and methods static. */ +#define OCTAVE_USE_STATIC_DEFUN + /* Tag indicating Octave's autoconf-generated config.h has been included. This symbol is provided because autoconf-generated config.h files do not define a multiple-inclusion guard. See also