[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mkoctfile: Problems sometimes during linking of text file

From: John W. Eaton
Subject: Re: mkoctfile: Problems sometimes during linking of text file
Date: Tue, 27 Jun 2000 12:25:00 -0500 (CDT)

[Sorry to quote all of this, but it has been a while, so the context
might be useful.  --jwe]

On 27-Apr-2000, Joao Cardoso <address@hidden> wrote:

| "John W. Eaton" wrote:
| > 
| > On 20-Apr-2000, Stef Pillaert <address@hidden> wrote:
| ...
| > | And a second tought: it would even be greater if the need for making the
| > | symbolic links wouldn't be necesarry any more: just having one lib, with 
| > | the functions in it, that can be called from octave. Is this possible, or
| > | unrealistic?
| > 
| > How would Octave know what functions are in the library?  Design a
| > clean and efficient way to do it that works well with the current
| > autoloading scheme (inherited from Matlab, for better or worse),
| Hi,
| I think that the advantages of a one-file/multiple-functions are
| obvious. Humm... simpler to maintain, at least. And more elegant, for
| sure!
| And it would be enough to add to Octave a procedure to register other
| existing functions in the file.
| E.g., a function should contain:
|   DEFUN_DLD (min, args, nargout,
|   ...
|   DEFUN_DLD (max, args, nargout,
|   ...
|   DEFUN_DLD (minmax, args, nargout,
|     // register max() and min() as existing in this file
|     REGFUN("max");
|     REGFUN("min");
|   ...
| and should be named minmax.oct.
| Of course this implies explicit user initialization, that could be left
| in ".octaverc". No free lunch! But compatible.
| > implement it, and submit it.
| Arghh! "touché"
| >  But why bother?  Don't links work well
| > enough?
| Perhaps not. And I think that this has been already addressed in this
| mailing list.
| If my multi-function file has to keep an internal global state variable,
| "static int state", e.g., with file linking the "state" variable will be
| local to each linked file/function, not global to all defined functions.
| For simple variables, one could use "set/get_global_value", but for
| complex structures...

No, because here is what is supposed to happen.  Assume we have one
file with two names (hard links) min.oct and max.oct.  When you ask
for min, Octave finds min.oct and loads it (a call to dlopen or
equivalent, which should also handle initialization of global objects)
and then searches for a pointer to a function called Fmin, and loads
it into the symbol table, then calls it with the args you supplied.
Octave also adds min.oct to a list of currently loaded .oct files.
The next time you try to load a function that is not currently in the
symbol table (for example, max), Octave will look in its list of
loaded .oct files before looking on the disk.  So it will search
min.oct for Fmax.  Since min.oct and max.oct are actually the same
file, Octave will find max in min.oct, and will not reload the file.
So global variables should work fine.

BTW, you can see this behavior if you do the following using a copy of
Octave that has been compiled using --enable-dl --enable-lite-kernel:

  octave:3> which min
  min is the dynamically-linked function from the file
  octave:4> which max
  max is the dynamically-linked function from the file

Note that max is defined from the file min.oct (i.e., max.oct was not
loaded, because max was found in min.oct, which was loaded first).

Now clear them, and do it in the opposite order.

  octave:5> clear min
  octave:6> clear max

  octave:7> which max 
  max is the dynamically-linked function from the file
  octave:8> which min
  min is the dynamically-linked function from the file

This time, min is found in max.oct because max was loaded first.


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]