On Thu, 07 Jan 2010, Mindaugas Kavaliauskas wrote:

Hi,

> Mindaugas Kavaliauskas wrote:
> >homework.prg (test module):
> >PROC main()
> >  ? netio_connect()
> >  ? NETIO_PROCEXISTS("HB_HRBLOAD")
> >  ? NETIO_PROCEXISTS("HELLO")
> >  ? NETIO_PROCEXECW("HB_HRBLOAD", HB_MEMOREAD("homework2.prg"))
> >  ? NETIO_PROCEXISTS("HELLO")
> >  ? NETIO_FUNCEXEC("HELLO")
> >RETURN
> >Unfortunately test code prints:
> >.T.
> >.T.
> >.F.
> >and application hangs up.
> Sorry. It was a simple typo, should be:
>    ? NETIO_PROCEXECW("HB_HRBLOAD", HB_MEMOREAD("homework1.hrb"))
> This method works!

Yes and it's _exactly_ what I have in mind though I haven't thought
about using #pragma __streaminclude. Very nice solution.
Thank you very much.
It also shows what clever programmer can do if he knows well HVM
internals. It's enough to leave even small peace code and he can
make what he only wants and it's the reason why protection by
available function list can work only if this is rather short list
of small and simple functions well known that work without any side
effects.

> BTW, results for this test are:
[...]
> I.e. every second time existing function is destroyed by
> unsuccessful overload. I'm not sure (not tested the details) if it
> is a bug in runner.c or some strange side effect, like: the second
> time code s_hHrb := HB_HRBLOAD("...") is called, HB_HRBLOAD() fails
> because Hello() already exists.

It's not a bug. See include/hbhrb.ch.
HRB module was loaded with HB_HRB_BIND_DEFAULT what means:
   /* do not overwrite any functions, ignore
      public HRB functions if functions with
      the same names already exist in HVM */
So when it's loaded second time public HELLO() function still exists
in HVM as part of previously loaded module and the new one is ignored.
Just after loading the new module you cleared s_hHrb so the old module
with HELLO() function was unloaded so all is correct.

> So, HB_HRBLOAD() returns empty value
> and destroys the last pointer to loaded hrb module in static
> variable. The next time module does not clashes with existing
> functions, so, it's loaded again.
> Modification of homework1.prg solves the problem:
> STATIC s_hHrb
> INIT PROC LoadHello()
> IF EMPTY(s_hHrb)
> #pragma __streaminclude "homework2.hrb"|s_hHrb := HB_HRBLOAD(%s)
> ENDIF
> RETURN

Yes it's enough. Other solution is clearing the old module before
registering the new one so its public functions will not be used,
i.e.:

   STATIC s_hHrb
   INIT PROC LoadHello()
   s_hHrb := NIL // clear the old module
   #pragma __streaminclude "homework2.hrb"|s_hHrb := HB_HRBLOAD(%s)
   RETURN

best regards,
Przemek
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to