Skip to content

Commit

Permalink
2017-07-27 18:57 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
Browse files Browse the repository at this point in the history
  * 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( [ <pThID> ] ) -> <lMainHvmThread>
      it returns true if given or current thread is main HVM thread
    + added new PRG function
         hb_mutexExists( <pMtx> ) -> <lExists>
      it returns true if passed <pMtx> 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
  • Loading branch information
druzus committed Jul 27, 2017
1 parent b075fcc commit 9eccf94
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 14 deletions.
33 changes: 33 additions & 0 deletions ChangeLog.txt
Expand Up @@ -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( [ <pThID> ] ) -> <lMainHvmThread>
it returns true if given or current thread is main HVM thread
+ added new PRG function
hb_mutexExists( <pMtx> ) -> <lExists>
it returns true if passed <pMtx> 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
Expand Down
4 changes: 4 additions & 0 deletions contrib/hbexpat/3rd/expat/_hbconf.h
Expand Up @@ -7,6 +7,10 @@
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# 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 */
Expand Down
69 changes: 61 additions & 8 deletions 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 <process.h> /* getpid() */
+#include <sys/timeb.h> /* ftime() */
+#elif defined(__WATCOMC__) && defined(__OS2__)
+#include <process.h> /* getpid() */
+#include <sys/time.h> /* gettimeofday() */
#else
#include <sys/time.h> /* gettimeofday() */
#include <sys/types.h> /* getpid() */
@@ -23,7 +29,9 @@

#define XML_BUILDING_EXPAT 1

Expand All @@ -12,7 +25,7 @@ diff -urN expat.orig/xmlparse.c expat/xmlparse.c
#include "winconfi.h"
#elif defined(HAVE_EXPAT_CONFIG_H)
#include <expat_config.h>
@@ -749,7 +751,7 @@
@@ -749,11 +757,11 @@
static int
writeRandomBytes_RtlGenRandom(void * target, size_t count) {
int success = 0; /* full count bytes written? */
Expand All @@ -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 <stddef.h>
Expand All @@ -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 <stddef.h>
Expand Down
25 changes: 23 additions & 2 deletions contrib/hbexpat/3rd/expat/xmlparse.c
Expand Up @@ -15,6 +15,12 @@

#ifdef _WIN32
#define getpid GetCurrentProcessId
#elif defined(__WATCOMC__) && defined(__DOS__)
#include <process.h> /* getpid() */
#include <sys/timeb.h> /* ftime() */
#elif defined(__WATCOMC__) && defined(__OS2__)
#include <process.h> /* getpid() */
#include <sys/time.h> /* gettimeofday() */
#else
#include <sys/time.h> /* gettimeofday() */
#include <sys/types.h> /* getpid() */
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions include/harbour.hbx
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/hbvm.h
Expand Up @@ -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 );

Expand Down
3 changes: 3 additions & 0 deletions src/harbour.def
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -3556,6 +3558,7 @@ hb_vmSuspendThreads
hb_vmSymbolInit_RT
hb_vmTerminateThreads
hb_vmThreadInit
hb_vmThreadIsMain
hb_vmThreadQuit
hb_vmThreadQuitRequest
hb_vmThreadRegister
Expand Down
9 changes: 8 additions & 1 deletion src/rtl/tpersist.prg
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/rtl/val.c
Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion src/vm/hvm.c
Expand Up @@ -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; }
Expand Down Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/vm/thread.c
Expand Up @@ -54,11 +54,13 @@
hb_threadDetach( <pThID> ) -> <lOK>
* hb_threadQuitRequest( <pThID> ) -> <lOK>
hb_threadTerminateAll() -> NIL
hb_threadIsMain( [ <pThID> ] ) -> <lMainHvmThread>
hb_threadWaitForAll() -> NIL
hb_threadWait( <pThID> | <apThID>, [ <nTimeOut> ] [, <lAll> ] ) => <nThInd> | <nThCount> | 0
hb_threadOnce( @<onceControl> [, <bAction> | <@sAction()> ] ) -> <lFirstCall>
hb_threadOnceInit( @<item>, <value> ) -> <lInitialized>
hb_mutexCreate() -> <pMtx>
hb_mutexExists( <pMtx> ) -> <lExists>
hb_mutexLock( <pMtx> [, <nTimeOut> ] ) -> <lLocked>
hb_mutexUnlock( <pMtx> ) -> <lOK>
hb_mutexNotify( <pMtx> [, <xVal>] ) -> NIL
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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() );
Expand Down

0 comments on commit 9eccf94

Please sign in to comment.