Mercurial > octave
changeset 29967:da1678140f7e
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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 15 Aug 2021 15:06:09 -0400 |
parents | 7d9be634ac91 |
children | 7aa4d8c049e5 |
files | build-aux/find-defun-files.sh build-aux/mk-pkg-add.sh libinterp/corefcn/defun-dld.h libinterp/corefcn/defun-int.h libinterp/mk-doc.pl oct-conf-post.in.h |
diffstat | 6 files changed, 65 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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
--- 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
--- 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)
--- 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 = <SRC_FH>) { - 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" }
--- 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