Please can you do it necessary changes to ziparch

Best regards,
Miguel Angel Marchuet

Przemyslaw Czerpak escribió:
On Wed, 02 Jul 2008, Miguel Angel Marchuet wrote:
Yes. Neither Harbour not xHarbour execute HB_EXIT_FUNC() and/or
HB_INIT_FUNC() automatically. HB_EXIT_FUNC/HB_INIT_FUNC are only
macros to define special unique names for compiler but they not
cause that anything will be executed.
The HB_EXIT_FUNC removed from hbziparch library from the beginning
was dummy code never executed in both project.
False i test it at xharbour with OutputDebugString and is executed at end of application

Miguel you used to check only part of problem and then create
very wide conclusions.
You are wrong. HB_EXIT_FUNC/HB_INIT_FUNC macros _does_not_ cause
any function execution and never did.

I this is because has the next lines:
#define __PRG_SOURCE__ (char*) "zip.c"
#ifdef HB_PCODE_VER
#  undef HB_PRG_PCODE_VER
#  define HB_PRG_PCODE_VER HB_PCODE_VER
#endif
HB_INIT_SYMBOLS_BEGIN( hbzip_CLEANUP )
{ (char*) "HBZIPCLEANUP$", {HB_FS_EXIT | HB_FS_LOCAL}, {HB_EXIT_FUNCNAME( HBZIPCLEANUP )}, &ModuleFakeDyn }
HB_INIT_SYMBOLS_END( hbzip_CLEANUP )

#if defined(HB_PRAGMA_STARTUP)
   #pragma startup hbzip_CLEANUP
#elif defined(HB_MSC_STARTUP)
   #if _MSC_VER >= 1010
      #pragma data_seg( ".CRT$XIY" )
      #pragma comment( linker, "/Merge:.CRT=.data" )
   #else
      #pragma data_seg( "XIY" )
   #endif
   static HB_$INITSYM hb_vm_auto_SymbolInit_INIT = hbzip_CLEANUP;
   #pragma data_seg()
#endif

This code causes that function HB_EXIT_FUNCNAME( HBZIPCLEANUP )
will be executed by HVM because it registers new symbol table
in HVM internal structure. But it's done by this additional code
not the HB_EXIT_FUNC() macro. You can change the function name
to any other one, f.e.:

   void my_func( void ) { doSomeThing(); }
   HB_INIT_SYMBOLS_BEGIN( hbzip_CLEANUP )
      { "$", {HB_FS_EXIT | HB_FS_LOCAL}, { doSomeThing }, &ModuleFakeDyn }
   HB_INIT_SYMBOLS_END( hbzip_CLEANUP )
   [...] // pragmas

and it will be executed too. HB_INIT_FUNC/HB_EXIT_FUNC macros are used
_ONLY_ for giving unique function name for .prg INIT/EXIT procedures
which will not cause conflict with other function/procedure names used
in the same module.
So far ZIPARCH cleanup function was dummy function from the beginning in
both projects because this additional code was missing.

Anyhow with additional code it will work but it's not efficient method for
C code. HB_INIT_SYMBOLS_BEGIN/HB_INIT_SYMBOLS_END should be used only for
.prg code or if you want to register some public symbols inside HVM.
It also has bad side effect because we are not able to control the order
of execution INIT/EXIT procedures so it can be executed before some other
.prg EXIT procedure which will try to access some ZIPARCH functions.
If you want to make it well and execute C function at HVM startup/cleanup
phase then use:
   void hb_vmAtInit( HB_INIT_FUNC pFunc, void * cargo );
   void hb_vmAtExit( HB_INIT_FUNC pFunc, void * cargo );
See in harbour/source/rtl/inkey.c how C exit function can
be registered and executed. If you need automatic registration of
init/exit functions at application startup then see end of file
harbour/source/rtl/gtwvt/gtwvt.c:
   HB_CALL_ON_STARTUP_BEGIN( file_unique_name )
      [...code_using hb_vmAtInit/hb_vmAtExit...]
   HB_CALL_ON_STARTUP_END( file_unique_name )
   [...pragmas...]

Functions registered in such way does not allocate unnecessary symbol
table in HVM and it's guarantied that INIT functions will be executed
just before .prg INIT procedures and exit functions just after all .prg
EXIT procedures.

best regards,
Przemek
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour


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

Reply via email to