Author Topic: REXX - RXLVM library - issue?  (Read 4552 times)

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1317
  • Karma: +26/-0
    • View Profile
REXX - RXLVM library - issue?
« on: November 16, 2020, 10:29:32 pm »
Hi Everyone,

I'm encountering an issue that suggests re-loading the RXLVM library is not successful, while several other REXX library are going through exactly the same process and are NOT showing this issue.

Please take a look at the below samples of my code and tell me where things may be going wrong?

1) load the REXX library
Code: [Select]
...
/* check if the RxLvm - RXLVM.DLL - is already loaded */
   rxlvm_api = RxFuncQuery('RxLvmLoadFuncs')
   msg_text = "RXLVM: API LOAD RC="||rxlvm_api
   CALL debug debug_flag calling_code msg_level msg_text
   If rxlvm_api <> 0 Then do
      Call RxFuncAdd 'RxLvmLoadFuncs', 'RXLVM', 'RxLvmLoadFuncs'
      Call RxLvmLoadFuncs
      end
   msg_text = "RXLVM: Using version "||RxLvmVersion()
   CALL debug debug_flag calling_code msg_level msg_text
...

2) unload the REXX library
Code: [Select]
...
   /* check the RXLVM library */
   If rxlvm_api <> 0 Then
      Call RxLvmDropFuncs
...

I use the rxlvm_api variable to tell me whether I need to un-load the library when my code is done. The purpose is to avoid doing so if the library was already loaded prior to my code starting, presumably something else out there loaded it first and perhaps requires it to remain loaded.

Now, 1st time through running my script I'm getting rxlvm_api=1, which means I did not have the RXLVM library loaded already and therefore need to load it. OK, good stuff, it works and the version info call (RxLvmVersion) works fine. The program then ends and the RXLVM is completely un-loaded.

However, re-running this script in the very same CLI session the 2nd time around produces the following error:

Code: [Select]
[G:\code\source\rexx\os2utils]nas_check v:
DEBUG : MAIN => Initializing...
DEBUG :    ==> library_load => Initializing...
DEBUG :    ==> library_load => RXU: Using version v1.a
DEBUG :    ==> library_load => REXXUTIL: Using version 2.00
DEBUG :    ==> library_load => RXUTILEX: Using version 0.1.6
DEBUG :    ==> library_load => RXEXTRAS: API LOAD RC=0
DEBUG :    ==> library_load => RXEXTRAS: Using version 1.G
DEBUG :    ==> library_load => RXLVM: API LOAD RC=0
   242 +++     msg_text = 'RXLVM: Using version ' || RxLvmVersion();
REX0043: Error 43 running G:\code\source\rexx\os2utils\nas_check.cmd, line
242: Routine not found
    67 +++   Call library_load;

What's weird about this is that rxlvm_api is clearly set to 0, which implies that it's already loaded and perhaps the un-load call actually failed?

Either way, if it was already loaded, why does the call to RxLvmVersion fail?

BTW: the same process is repeated for several other libraries, they work fine.

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Re: REXX - RXLVM library - issue?
« Reply #1 on: November 17, 2020, 12:30:19 am »
It's hard to say without a complete and minimal example. BTW: Registering RXLVM works for me. I guess the error is somewhere else.

Lars

  • Hero Member
  • *****
  • Posts: 1271
  • Karma: +65/-0
    • View Profile
Re: REXX - RXLVM library - issue?
« Reply #2 on: November 17, 2020, 01:25:58 am »
Don't go through the hassle of unloading a REXX DLL. It's not worth the effort: if another process is currently using that DLL, it will fail with a runtime error and this failure is not obvious at all (the DLL loading couples these 2 processes even though they seemingly have nothing to do with each other).

If the last process that uses that DLL ends, that DLL will be unloaded by the REXX exit handler (I seem to remember).
For this reason, I never bother to unload a REXX DLL.
« Last Edit: November 17, 2020, 01:28:03 am by Lars »

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1317
  • Karma: +26/-0
    • View Profile
Re: REXX - RXLVM library - issue?
« Reply #3 on: November 17, 2020, 02:13:21 am »
Andreas,

It's hard to say without a complete and minimal example. BTW: Registering RXLVM works for me. I guess the error is somewhere else.

Can your code register the RXLVM multiple times during the same session?

My problem appears to be due to the fact that I:
1) register
2) un-register
3) attempt to register again <= FAILURE

Dariusz Piatkowski

  • Hero Member
  • *****
  • Posts: 1317
  • Karma: +26/-0
    • View Profile
Re: REXX - RXLVM library - issue?
« Reply #4 on: November 17, 2020, 02:19:09 am »
Hi Lars,
Don't go through the hassle of unloading a REXX DLL. It's not worth the effort: if another process is currently using that DLL, it will fail with a runtime error and this failure is not obvious at all (the DLL loading couples these 2 processes even though they seemingly have nothing to do with each other)...

Yes, you are absolutely right about that, which is why during the inital DLL load I rely on the following code to check whether that DLL has already been loaded by another process and is currently registered with the REXX runtime:

Code: [Select]
...
rxlvm_api = RxFuncQuery('RxLvmLoadFuncs')
...

If that call returns 0 (zero), that means the DLL has already been loaded, and if that is the case I completely skip the built-in DLL load process.

The opposite of that happens in the DLL un-load process: if the flag was set to 0 originally (DLL was already in-memory) I skip the un-load.

All in all this is a fairly elegant technique and is something that's mentioned in one of the REXX library INF files. The overall idea being to toss all the REXX DLLs into startup.cmd and basically prevent any other REXX script on my machine from ever having to load that DLL again. In theory at least, because while I have the control over my code, I certainly do NOT have that control over all the other REXX code that's out there.

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Re: REXX - RXLVM library - issue?
« Reply #5 on: November 17, 2020, 02:32:43 am »
Can your code register the RXLVM multiple times during the same session?
Yes. What I remember from some time ago is that the return values don't stand for that what I initially thought. Therefore I usually ignore them and additionally, as Lars wrote, never deregister functions.

Lars

  • Hero Member
  • *****
  • Posts: 1271
  • Karma: +65/-0
    • View Profile
Re: REXX - RXLVM library - issue?
« Reply #6 on: November 17, 2020, 11:09:36 am »
I rely on the following code to check whether that DLL has already been loaded by another process and is currently registered with the REXX runtime:

Code: [Select]
...
rxlvm_api = RxFuncQuery('RxLvmLoadFuncs')
...

If that call returns 0 (zero), that means the DLL has already been loaded, and if that is the case I completely skip the built-in DLL load process.
I have never bothered to query if any function is already registered. You just register again and that's it. I would think that REXX just relies on the OS's module loader to remember how many times a DLL has been loaded. I don't know if REXX adds some additional intelligence to remember what script has loaded what DLL. Presumably not, given the problem that one REXX script can pull the carpet from beneath another REXX script that happens to use that same DLL.

As you have already experienced, that "preloading" approach is adding a whole lot of unnecessary complexity. I consider it completely superfluous. Plus, you never know what some other REXX script writer will do. Take me as a bad example :-)

« Last Edit: November 17, 2020, 11:58:59 am by Lars »