2008-10-13 18:01 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/source/vm/thread.c
    + added small description for hb_threadOnce() .prg function

  * harbour/include/hbthread.h
    ! do not set TLS in POCC and XCC builds when _MSC_VER macro is set
      This compilers also have this macro but dllspec( thread) does
      not work for them (at least in version 4.50.15)

  * harbour/utils/hbtest/rt_hvm.prg
    + added few tests which exploit by DMC bug. Be careful with
      this compiler. In some cases it gives buggy final code, f.e.
      try this:

            #include <stdio.h>
            typedef struct
            {
               double         dd;
               long long int  ll;
            } UN;
            const char * cmp( UN * pU )
            {
               return pU->dd >= pU->ll ? "OK" : "ERRROR";
            }
            int main( void )
            {
               UN u = { 10.50, 10 };
               printf( "%s\n", cmp( &u ) );
               return 0;
            }

      The same bug can be exploited also by final Harbour binaries
      compiled by DMC in code like:

         ? iif( 10.50 >= 10, "OK", "ERROR" )

      I used DMC 8.42n. As long as such things will not be fixed by
      DMC developers this compiler is not supported by Harbour and
      reported problems with DMC Harbour builds will have to be
      ignored by us.
This commit is contained in:
Przemyslaw Czerpak
2008-10-13 16:01:44 +00:00
parent b3ee472fee
commit 7d8c51e71a
4 changed files with 60 additions and 1 deletions

View File

@@ -8,6 +8,47 @@
2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org)
*/
2008-10-13 18:01 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/source/vm/thread.c
+ added small description for hb_threadOnce() .prg function
* harbour/include/hbthread.h
! do not set TLS in POCC and XCC builds when _MSC_VER macro is set
This compilers also have this macro but dllspec( thread) does
not work for them (at least in version 4.50.15)
* harbour/utils/hbtest/rt_hvm.prg
+ added few tests which exploit by DMC bug. Be careful with
this compiler. In some cases it gives buggy final code, f.e.
try this:
#include <stdio.h>
typedef struct
{
double dd;
long long int ll;
} UN;
const char * cmp( UN * pU )
{
return pU->dd >= pU->ll ? "OK" : "ERRROR";
}
int main( void )
{
UN u = { 10.50, 10 };
printf( "%s\n", cmp( &u ) );
return 0;
}
The same bug can be exploited also by final Harbour binaries
compiled by DMC in code like:
? iif( 10.50 >= 10, "OK", "ERROR" )
I used DMC 8.42n. As long as such things will not be fixed by
DMC developers this compiler is not supported by Harbour and
reported problems with DMC Harbour builds will have to be
ignored by us.
2008-10-13 16:34 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbclass.ch
* harbour/source/vm/classes.c

View File

@@ -316,7 +316,7 @@ extern void hb_threadMutexUnlockAll( void );
/* enable native compiler TLS support be default for this compilers
* which are known that it will work correctly
*/
# if defined( _MSC_VER )
# if defined( _MSC_VER ) && !defined( __POCC__ ) && !defined( __XCC__ )
# define HB_USE_TLS
# elif defined( __GNUC__ ) && __GNUC__ >= 3 && \
defined( __GLIBC__ ) && defined( __GLIBC_MINOR__ ) && \

View File

@@ -959,6 +959,20 @@ HB_FUNC( HB_THREADTERMINATEALL )
#endif
}
/* hb_threadOnce( @<onceControl> [, <bAction> ] ) -> <lFirstCall>
* Execute <bAction> only once. <onceControl> is variable which holds
* the execution status and have to be initialized to NIL. In most of
* cases it will be simple staticvariable in user code.
* When <bAction> is executed by a thread all other threads which call
* hb_threadOnce() are stopped even if they use different <onceControl>.
* Because hb_threadOnce() uses single recursive mutex then deadlock caused
* by cross call to hb_threadOnce() from different threads is not possible.
* If thread calls hb_threadOnce() with the same <onceControl> variable
* recursively from <bAction> then hb_threadOnce() returns immediately
* returning FALSE without executing <bAction>.
* This function returns logical value indicating if it was 1-st call to
* hb_threadOnce() for given <onceControl> variable
*/
HB_FUNC( HB_THREADONCE )
{
PHB_ITEM pItem = hb_param( 1, HB_IT_ANY );

View File

@@ -265,6 +265,7 @@ PROCEDURE Main_HVM()
TEST_LINE( 2 <= 2.0 , .T. )
TEST_LINE( 2.5 <= 3.7 , .T. )
TEST_LINE( 3.7 <= 2.5 , .F. )
TEST_LINE( 10 <= 10.50 , .T. )
TEST_LINE( .F. <= .F. , .T. )
TEST_LINE( .T. <= .F. , .F. )
TEST_LINE( .F. <= .T. , .T. )
@@ -297,6 +298,7 @@ PROCEDURE Main_HVM()
TEST_LINE( 2 < 2.0 , .F. )
TEST_LINE( 2.5 < 3.7 , .T. )
TEST_LINE( 3.7 < 2.5 , .F. )
TEST_LINE( 10.50 < 10 , .F. )
TEST_LINE( .F. < .F. , .F. )
TEST_LINE( .T. < .F. , .F. )
TEST_LINE( .F. < .T. , .T. )
@@ -329,6 +331,7 @@ PROCEDURE Main_HVM()
TEST_LINE( 2 >= 2.0 , .T. )
TEST_LINE( 2.5 >= 3.7 , .F. )
TEST_LINE( 3.7 >= 2.5 , .T. )
TEST_LINE( 10.50 >= 10 , .T. )
TEST_LINE( .F. >= .F. , .T. )
TEST_LINE( .T. >= .F. , .T. )
TEST_LINE( .F. >= .T. , .F. )
@@ -361,6 +364,7 @@ PROCEDURE Main_HVM()
TEST_LINE( 2 > 2.0 , .F. )
TEST_LINE( 2.5 > 3.7 , .F. )
TEST_LINE( 3.7 > 2.5 , .T. )
TEST_LINE( 10.50 > 10 , .T. )
TEST_LINE( .F. > .F. , .F. )
TEST_LINE( .T. > .F. , .T. )
TEST_LINE( .F. > .T. , .F. )