Adriaan van Os wrote:
That is the case of subtle errors: consider things like signal handlers or file buffers. You do not want handler from library A to clean up only library A when library B caused an error. You do not want to have two file buffers for a single file. While I have _not_ checked that any of the above may happen in gpc runtime, just by Murphy something will get broken.
I see the point, but what is the difference between this situation (two shared libraries, each with a copy of libgpc) and e.g. one library written in Pascal and the other in a language xxx ?
You mean the difference between one and two copies of libgpc? (Whether there are other libraries is irrelevant here.) As Waldek said, two copies means two copies of all the global variables such as Input and Output and several internal RTS variables. This will most likely lead to inconsistent results. E.g., imagine, two `Input's, each with its own buffer, and reading from `Input' will read from different buffers, depending from where it's called.
_p__rts_Init_init(); mylib_init();
Is it better to call _p__rts_Init_init rather than _p_initialize ?
_p__rts_Init_init is an name used internally by the RTS. It should never be called from outside and could be changed anytime. _p_initialize is the function to be called from outside.
Waldek Hebisch wrote:
What is better depends on goals. AFAICS if we only do the above then arguments and environment effectively will be empty. If a a Pascal main program dynamically loads the library, then call to _p_initialize will wipe out main program environment and arguments (IIUC normally dynamic linker loads libraries _before_ the main program, but it is possible to load libraries _after_ the main program has started).
If that's a problem, IMHO we should find a proper solution instead of accessing RTS internals. One way would be to skip setting arguments if NULL (AFAIK, this can never happen in the main program).
For the environment, it's a bit more difficult, as there are two ways to get it -- the 3rd parameter to `main' and the `[__]environ' variable. The latter is POSIX, AFAIK, but not all systems really support it, so GPC supports both ways, to make it more likely to get the environment. But here, AFAICS, for the first way, we can do the same as for the arguments, and for the second one, we could use an internal flag, so the environment variable, if present, is only used once.
This require some changes in the RTS, but not too bad AFAICS. So if we decide that's what we need, I think I could do it quickly ...
An alternative would be a new flag (in the `Options' parameter), but AFAICS we don't actually need it.
Frank