diff --git a/ChangeLog.txt b/ChangeLog.txt index 75d05c304d..4ba9f861ac 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,39 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2017-07-27 18:57 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * contrib/hbexpat/3rd/expat/_hbconf.h + * contrib/hbexpat/3rd/expat/xmlparse.c + ! fixed WINCE builds + ! fixed OpenWatcom DOS builds + ! fixed OpenWatcom OS2 builds + + * contrib/hbexpat/3rd/expat/expat.dif + * rediffed + + * include/harbour.hbx + * include/hbvm.h + * src/harbour.def + * src/vm/hvm.c + * src/vm/thread.c + + added new C function + HB_BOOL hb_vmThreadIsMain( void * ); + it checks if given or current thread is main HVM thread + + added new PRG function + hb_threadIsMain( [ ] ) -> + it returns true if given or current thread is main HVM thread + + added new PRG function + hb_mutexExists( ) -> + it returns true if passed parameter is pointer item to + fully functional mutex + + * src/rtl/tpersist.prg + ! fixed problem with array item deserialization - many thanks + to Peter Rees for exact information about the problem. + + * src/rtl/val.c + * minor simplification + 2017-07-03 18:36 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbwin/olecore.c ! reverted order of indexes and dimensions in conversions of diff --git a/contrib/hbexpat/3rd/expat/_hbconf.h b/contrib/hbexpat/3rd/expat/_hbconf.h index ed123e7524..b40a331e62 100644 --- a/contrib/hbexpat/3rd/expat/_hbconf.h +++ b/contrib/hbexpat/3rd/expat/_hbconf.h @@ -7,6 +7,10 @@ # define WIN32_LEAN_AND_MEAN # include # undef WIN32_LEAN_AND_MEAN +# include "hbwinuni.h" +#endif +#if defined( HB_OS_WIN_CE ) && ! defined( _WINCE ) +# define _WINCE #endif /* 1234 = LITLE_ENDIAN, 4321 = BIG_ENDIAN */ diff --git a/contrib/hbexpat/3rd/expat/expat.dif b/contrib/hbexpat/3rd/expat/expat.dif index f1af7f551f..c8243d356c 100644 --- a/contrib/hbexpat/3rd/expat/expat.dif +++ b/contrib/hbexpat/3rd/expat/expat.dif @@ -1,7 +1,20 @@ diff -urN expat.orig/xmlparse.c expat/xmlparse.c ---- expat.orig/xmlparse.c 2017-06-26 08:22:50.000000000 +0200 -+++ expat/xmlparse.c 2017-06-26 08:22:50.000000000 +0200 -@@ -23,7 +23,9 @@ +--- expat.orig/xmlparse.c 2017-07-24 16:57:23.412595132 +0200 ++++ expat/xmlparse.c 2017-07-24 16:57:23.412595132 +0200 +@@ -15,6 +15,12 @@ + + #ifdef _WIN32 + #define getpid GetCurrentProcessId ++#elif defined(__WATCOMC__) && defined(__DOS__) ++#include /* getpid() */ ++#include /* ftime() */ ++#elif defined(__WATCOMC__) && defined(__OS2__) ++#include /* getpid() */ ++#include /* gettimeofday() */ + #else + #include /* gettimeofday() */ + #include /* getpid() */ +@@ -23,7 +29,9 @@ #define XML_BUILDING_EXPAT 1 @@ -12,7 +25,7 @@ diff -urN expat.orig/xmlparse.c expat/xmlparse.c #include "winconfi.h" #elif defined(HAVE_EXPAT_CONFIG_H) #include -@@ -749,7 +751,7 @@ +@@ -749,11 +757,11 @@ static int writeRandomBytes_RtlGenRandom(void * target, size_t count) { int success = 0; /* full count bytes written? */ @@ -21,9 +34,49 @@ diff -urN expat.orig/xmlparse.c expat/xmlparse.c if (advapi32) { const RTLGENRANDOM_FUNC RtlGenRandom +- = (RTLGENRANDOM_FUNC)GetProcAddress(advapi32, "SystemFunction036"); ++ = (RTLGENRANDOM_FUNC)HB_WINAPI_GETPROCADDRESS(advapi32, "SystemFunction036"); + if (RtlGenRandom) { + if (RtlGenRandom((PVOID)target, (ULONG)count) == TRUE) { + success = 1; +@@ -771,10 +779,21 @@ + static unsigned long + gather_time_entropy(void) + { +-#ifdef _WIN32 ++#ifdef _WINCE ++ SYSTEMTIME st; ++ GetSystemTime(&st); ++ return ( ( ( ( long ) st.wDay * 24 + ++ st.wHour ) * 60 + ++ st.wMinute ) * 60 + ++ st.wSecond ) * 1000 + st.wMilliseconds; ++#elif defined(_WIN32) + FILETIME ft; + GetSystemTimeAsFileTime(&ft); /* never fails */ + return ft.dwHighDateTime ^ ft.dwLowDateTime; ++#elif defined(__WATCOMC__) && defined(__DOS__) ++ struct timeb tb; ++ ftime( &tb ); ++ return tb.time ^ tb.millitm; + #else + struct timeval tv; + int gettimeofday_res; +@@ -793,7 +812,11 @@ + + static unsigned long + ENTROPY_DEBUG(const char * label, unsigned long entropy) { ++#ifdef _WINCE ++ const char * const EXPAT_ENTROPY_DEBUG = NULL; ++#else + const char * const EXPAT_ENTROPY_DEBUG = getenv("EXPAT_ENTROPY_DEBUG"); ++#endif + if (EXPAT_ENTROPY_DEBUG && ! strcmp(EXPAT_ENTROPY_DEBUG, "1")) { + fprintf(stderr, "Entropy: %s --> 0x%0*lx (%lu bytes)\n", + label, diff -urN expat.orig/xmlrole.c expat/xmlrole.c ---- expat.orig/xmlrole.c 2017-06-26 08:22:50.000000000 +0200 -+++ expat/xmlrole.c 2017-06-26 08:22:50.000000000 +0200 +--- expat.orig/xmlrole.c 2017-07-24 16:57:23.416595132 +0200 ++++ expat/xmlrole.c 2017-07-24 16:57:23.456595133 +0200 @@ -4,7 +4,9 @@ #include @@ -36,8 +89,8 @@ diff -urN expat.orig/xmlrole.c expat/xmlrole.c #else #ifdef HAVE_EXPAT_CONFIG_H diff -urN expat.orig/xmltok.c expat/xmltok.c ---- expat.orig/xmltok.c 2017-06-26 08:22:50.000000000 +0200 -+++ expat/xmltok.c 2017-06-26 08:22:50.000000000 +0200 +--- expat.orig/xmltok.c 2017-07-24 16:57:23.460595133 +0200 ++++ expat/xmltok.c 2017-07-24 16:57:23.476595134 +0200 @@ -4,7 +4,9 @@ #include diff --git a/contrib/hbexpat/3rd/expat/xmlparse.c b/contrib/hbexpat/3rd/expat/xmlparse.c index 2b37e42c7f..f89410254f 100644 --- a/contrib/hbexpat/3rd/expat/xmlparse.c +++ b/contrib/hbexpat/3rd/expat/xmlparse.c @@ -15,6 +15,12 @@ #ifdef _WIN32 #define getpid GetCurrentProcessId +#elif defined(__WATCOMC__) && defined(__DOS__) +#include /* getpid() */ +#include /* ftime() */ +#elif defined(__WATCOMC__) && defined(__OS2__) +#include /* getpid() */ +#include /* gettimeofday() */ #else #include /* gettimeofday() */ #include /* getpid() */ @@ -755,7 +761,7 @@ writeRandomBytes_RtlGenRandom(void * target, size_t count) { if (advapi32) { const RTLGENRANDOM_FUNC RtlGenRandom - = (RTLGENRANDOM_FUNC)GetProcAddress(advapi32, "SystemFunction036"); + = (RTLGENRANDOM_FUNC)HB_WINAPI_GETPROCADDRESS(advapi32, "SystemFunction036"); if (RtlGenRandom) { if (RtlGenRandom((PVOID)target, (ULONG)count) == TRUE) { success = 1; @@ -773,10 +779,21 @@ writeRandomBytes_RtlGenRandom(void * target, size_t count) { static unsigned long gather_time_entropy(void) { -#ifdef _WIN32 +#ifdef _WINCE + SYSTEMTIME st; + GetSystemTime(&st); + return ( ( ( ( long ) st.wDay * 24 + + st.wHour ) * 60 + + st.wMinute ) * 60 + + st.wSecond ) * 1000 + st.wMilliseconds; +#elif defined(_WIN32) FILETIME ft; GetSystemTimeAsFileTime(&ft); /* never fails */ return ft.dwHighDateTime ^ ft.dwLowDateTime; +#elif defined(__WATCOMC__) && defined(__DOS__) + struct timeb tb; + ftime( &tb ); + return tb.time ^ tb.millitm; #else struct timeval tv; int gettimeofday_res; @@ -795,7 +812,11 @@ gather_time_entropy(void) static unsigned long ENTROPY_DEBUG(const char * label, unsigned long entropy) { +#ifdef _WINCE + const char * const EXPAT_ENTROPY_DEBUG = NULL; +#else const char * const EXPAT_ENTROPY_DEBUG = getenv("EXPAT_ENTROPY_DEBUG"); +#endif if (EXPAT_ENTROPY_DEBUG && ! strcmp(EXPAT_ENTROPY_DEBUG, "1")) { fprintf(stderr, "Entropy: %s --> 0x%0*lx (%lu bytes)\n", label, diff --git a/include/harbour.hbx b/include/harbour.hbx index de13da958b..8a888c81d7 100644 --- a/include/harbour.hbx +++ b/include/harbour.hbx @@ -700,6 +700,7 @@ DYNAMIC hb_MSecToT DYNAMIC hb_mtvm DYNAMIC hb_mutexCreate DYNAMIC hb_mutexEval +DYNAMIC hb_mutexExists DYNAMIC hb_mutexLock DYNAMIC hb_mutexNotify DYNAMIC hb_mutexNotifyAll @@ -859,6 +860,7 @@ DYNAMIC hb_StrToUTF8 DYNAMIC hb_StrXor DYNAMIC hb_threadDetach DYNAMIC hb_threadID +DYNAMIC hb_threadIsMain DYNAMIC hb_threadJoin DYNAMIC hb_threadOnce DYNAMIC hb_threadOnceInit diff --git a/include/hbvm.h b/include/hbvm.h index d1ac33e011..09fefea329 100644 --- a/include/hbvm.h +++ b/include/hbvm.h @@ -187,6 +187,7 @@ extern HB_EXPORT void hb_vmThreadQuit( void ); /* destroy local thread HVM s extern HB_EXPORT void hb_vmThreadQuitRequest( void * ); /* send QUIT request to given thread */ extern HB_EXPORT void hb_vmWaitForThreads( void ); /* wait for all threads to terminate can be called only by main HVM thread */ extern HB_EXPORT void hb_vmTerminateThreads( void ); /* send QUIT request to all threads except current one and wait for their termination, should be called only by main HVM thread */ +extern HB_EXPORT HB_BOOL hb_vmThreadIsMain( void * ); /* check if given or current thread is main HVM thread */ extern HB_EXPORT PHB_ITEM hb_vmThreadStart( HB_ULONG ulAttr, PHB_CARGO_FUNC pThreadFunc, void * cargo ); /* create new thread with HVM stack */ extern HB_EXPORT void * hb_vmThreadState( void ); diff --git a/src/harbour.def b/src/harbour.def index c061e27a09..ccf9de7b20 100644 --- a/src/harbour.def +++ b/src/harbour.def @@ -886,6 +886,7 @@ HB_FUN_HB_MT HB_FUN_HB_MTVM HB_FUN_HB_MUTEXCREATE HB_FUN_HB_MUTEXEVAL +HB_FUN_HB_MUTEXEXISTS HB_FUN_HB_MUTEXLOCK HB_FUN_HB_MUTEXNOTIFY HB_FUN_HB_MUTEXNOTIFYALL @@ -1044,6 +1045,7 @@ HB_FUN_HB_STRTOUTF8 HB_FUN_HB_STRXOR HB_FUN_HB_THREADDETACH HB_FUN_HB_THREADID +HB_FUN_HB_THREADISMAIN HB_FUN_HB_THREADJOIN HB_FUN_HB_THREADONCE HB_FUN_HB_THREADONCEINIT @@ -3556,6 +3558,7 @@ hb_vmSuspendThreads hb_vmSymbolInit_RT hb_vmTerminateThreads hb_vmThreadInit +hb_vmThreadIsMain hb_vmThreadQuit hb_vmThreadQuitRequest hb_vmThreadRegister diff --git a/src/rtl/tpersist.prg b/src/rtl/tpersist.prg index 68ad4d3d51..a49d0918ed 100644 --- a/src/rtl/tpersist.prg +++ b/src/rtl/tpersist.prg @@ -65,6 +65,7 @@ METHOD LoadFromText( cObjectText, lIgnoreErrors ) CLASS HBPersistent LOCAL nPos LOCAL cLine LOCAL cProp + LOCAL cInd LOCAL uValue LOCAL aWords LOCAL lStart := .T. @@ -121,7 +122,13 @@ METHOD LoadFromText( cObjectText, lIgnoreErrors ) CLASS HBPersistent ENDIF IF !Empty( cProp ) - ATail( aObjects ):&cProp := uValue + IF ( nPos := At( "[", cProp ) ) > 0 + cInd := SubStr( cProp, nPos + 1, Len( cProp ) - nPos - 1 ) + cProp := Left( cProp, nPos - 1 ) + ATail( aObjects ):&cProp[ &cInd ] := uValue + ELSE + ATail( aObjects ):&cProp := uValue + ENDIF ENDIF END SEQUENCE diff --git a/src/rtl/val.c b/src/rtl/val.c index 29ccdf091b..2196d4eda2 100644 --- a/src/rtl/val.c +++ b/src/rtl/val.c @@ -86,8 +86,7 @@ HB_FUNC( HB_VAL ) fDbl = hb_valStrnToNum( szText, iLen, &lValue, &dValue, &iDec, &iWidth ); - if( HB_ISNUM( 2 ) ) - iLen = hb_parni( 2 ); + iLen = hb_parnidef( 2, iLen ); if( fDbl && iDec > 0 ) iLen -= iDec + 1; diff --git a/src/vm/hvm.c b/src/vm/hvm.c index 2afa57ca7f..a6fa02face 100644 --- a/src/vm/hvm.c +++ b/src/vm/hvm.c @@ -457,6 +457,7 @@ static void hb_vmDoInitHelp( void ) #if ! defined( HB_MT_VM ) HB_BOOL hb_vmIsMt( void ) { return HB_FALSE; } +HB_BOOL hb_vmThreadIsMain( void * Cargo ) { HB_SYMBOL_UNUSED( Cargo ); return s_fHVMActive; } void hb_vmLock( void ) {} void hb_vmUnlock( void ) {} HB_BOOL hb_vmSuspendThreads( HB_BOOL fWait ) { HB_SYMBOL_UNUSED( fWait ); return HB_TRUE; } @@ -720,6 +721,21 @@ void * hb_vmThreadState( void ) return hb_stackId() ? hb_stackList() : NULL; } +HB_BOOL hb_vmThreadIsMain( void * Cargo ) +{ + HB_TRACE( HB_TR_DEBUG, ( "hb_vmThreadIsMain(%p)", Cargo ) ); + + if( ! s_fHVMActive || s_main_thread == NULL ) + return HB_FALSE; + else if( Cargo ) + return s_main_thread == ( ( PHB_THREADSTATE ) Cargo )->pStackId; + else + { + HB_STACK_TLS_PRELOAD + return s_main_thread == hb_stackId(); + } +} + static void hb_vmStackAdd( PHB_THREADSTATE pState ) { HB_TRACE( HB_TR_DEBUG, ( "hb_vmStackAdd(%p)", pState ) ); @@ -9072,7 +9088,7 @@ HB_BOOL hb_vmTryEval( PHB_ITEM * pResult, PHB_ITEM pItem, HB_ULONG ulPCount, ... { HB_BOOL fResult; - HB_TRACE( HB_TR_DEBUG, ( "hb_vmTryEval(%p, %lu)", pItem, ulPCount ) ); + HB_TRACE( HB_TR_DEBUG, ( "hb_vmTryEval(%p, %p, %lu)", pResult, pItem, ulPCount ) ); fResult = HB_FALSE; *pResult = NULL; @@ -12398,6 +12414,8 @@ HB_FUNC( __VMITEMID ) hb_retptr( hb_hashId( pItem ) ); else if( HB_IS_BLOCK( pItem ) ) hb_retptr( hb_codeblockId( pItem ) ); + else if( HB_IS_SYMBOL( pItem ) ) + hb_retptr( pItem->item.asSymbol.value ); } } diff --git a/src/vm/thread.c b/src/vm/thread.c index 98b1e5371b..c005eb036e 100644 --- a/src/vm/thread.c +++ b/src/vm/thread.c @@ -54,11 +54,13 @@ hb_threadDetach( ) -> * hb_threadQuitRequest( ) -> hb_threadTerminateAll() -> NIL + hb_threadIsMain( [ ] ) -> hb_threadWaitForAll() -> NIL hb_threadWait( | , [ ] [, ] ) => | | 0 hb_threadOnce( @ [, | <@sAction()> ] ) -> hb_threadOnceInit( @, ) -> hb_mutexCreate() -> + hb_mutexExists( ) -> hb_mutexLock( [, ] ) -> hb_mutexUnlock( ) -> hb_mutexNotify( [, ] ) -> NIL @@ -1318,6 +1320,24 @@ HB_FUNC( HB_THREADID ) #endif } +HB_FUNC( HB_THREADISMAIN ) +{ +#if defined( HB_MT_VM ) + HB_STACK_TLS_PRELOAD + + if( hb_pcount() > 0 ) + { + PHB_THREADSTATE pThread = hb_thParam( 1, 0 ); + if( pThread ) + hb_retl( hb_vmThreadIsMain( pThread ) ); + } + else + hb_retl( hb_vmThreadIsMain( NULL ) ); +#else + hb_retl( HB_TRUE ); +#endif +} + #if defined( HB_MT_VM ) static int hb_threadWait( PHB_THREADSTATE * pThreads, int iThreads, HB_BOOL fAll, HB_ULONG ulMilliSec ) @@ -2554,6 +2574,12 @@ PHB_ITEM hb_threadMutexTimedSubscribe( PHB_ITEM pItem, HB_ULONG ulMilliSec, HB_B return pResult; } +HB_FUNC( HB_MUTEXEXISTS ) +{ + HB_STACK_TLS_PRELOAD + hb_retl( hb_itemGetPtrGC( hb_param( 1, HB_IT_POINTER ), &s_gcMutexFuncs ) != NULL ); +} + HB_FUNC( HB_MUTEXCREATE ) { hb_itemReturnRelease( hb_threadMutexCreate() );