Hi Przemek,

Il 28/01/2009 3.52, Przemyslaw Czerpak ha scritto:

First of all thank you for your detailed explanation,

[snip]

   HB_REINIT_STATIC
   HB_KEEP_LOCAL_REFERENCES

good

   HB_OVERLOAD_FUNCTIONS

interesting, but, as you pointed out, is dangerous in code like HTTP server, so my vote is no

So what should you make now?
I suggest to ignore this problem until I'll not change structures used
to hold static variables. The chance for GPF is rather small. The side
effect of array preallocation added by Mindaugas is noticeable reduced
number of memory reallocation when new statics are added so the risk is
really small that the problem will be exploited. Of course it _MUST_ be
fixed but it should not be critical during uHTTPd developing.
Now concentrate on the above information. I hope it helps to understand
how .hrb modules works.

BTW all of the above is also valid with exactly the same conditions for
compiled .prg code loaded/unloaded from dynamic libraries (.dll, .so,
.sl, .dyn, ...).


Ok, I will go on. Thank you again.

Just 3 other questions:
1 - I would like to limit use of some functions that may be dangerous if used from a user, like zap a database or FErase, but this are only two samples and maybe not pertinent in real developing, or to other functions, like dbUseArea(), that I want that not have to be used because I would like to add an HTTP_dbUseArea() that can open databases and control them. Is there a way to add a HRB_INHIBIT_FUNCTIONS that can inhibit some function calls from hrb at HVM level ?

2 - In uhttpd.prg the piece of code that runs HRB modules is guarded from a mutex:
--------------
.....
              // Lock HRB to avoid MT race conditions
              IF hb_mutexLock( s_hmtxHRB )  <<<<----
                 IF HRB_ACTIVATE_CACHE
                    // caching modules
                    IF !hb_HHasKey( s_hHRBModules, cFileName )
hb_HSet( s_hHRBModules, cFileName, HRB_LoadFromFile( uOSFileName( cFileName ) ) )
                    ENDIF
                    cHRBBody := s_hHRBModules[ cFileName ]
                 ELSE
cHRBBody := HRB_LoadFromFile( uOSFileName( cFileName ) )
                 ENDIF
                 IF !EMPTY( pHRB := HB_HRBLOAD( cHRBBody ) )

                     xResult := HRBMAIN()

                     HB_HRBUNLOAD( pHRB )
                 ELSE
                     uSetStatusCode( 404 )
                     t_cErrorMsg := "File does not exist: " + cFileName
                 ENDIF
                 hb_mutexUnlock( s_hmtxHRB ) <<<<----

              ENDIF

.....

STATIC FUNCTION HRB_LoadFromFile( cFile )
   RETURN hb_memoread( cFile )

--------------
Is it correct or is it unnecessary because this is already done from HVM  ?

3 - In the same piece of code (not already uploaded) I have thought to a memory cache of HRBBody code using an hash (actually HRB_ACTIVATE_CACHE can has value .T. or .F.) but I'm not able to evaluate costs between load from file everytime (where I suppose that OS helps caching file in memory) or scanning an hash and retrieve the string (apart from a side effect: loading an hrb module from file permits to update hrb code on the fly, the other method load hrb only first time than I need to "purge" list to have it loaded again).

TIA

Best regards,

Francesco
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to