From ecb56859df4b3deceab7f721a8bf2a1c3e545e14 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 30 Jul 2009 04:36:35 +0000 Subject: [PATCH] 2009-07-30 06:35 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * source/common/hbdate.c ! Fixed for some systems where tm->tm_gmtoff isn't available. (like sunos). Thanks to Tamas Tevesz for report and pointer. * contrib/rddads/adsfunc.c + ADSCREATESAVEPOINT() ADSROLLBACKSAVEPOINT() Added support for 3rd optional parameter on Harbour level. * include/hbapi.h * source/vm/extend.c + hb_parnidef(), hb_parnldef() to give a faster and shorter alternative to HB_ISNUM( x ) ? hb_parn[i|l]( x ) : construct, which quite often occure in C interface code. We may also add a hb_parl() version which returns TRUE, this covers most real-life usages. * examples/uhttpd2/socket.c * examples/httpsrv/socket.c % Deleted local hb_parnidef() wrapper. --- harbour/ChangeLog | 22 ++++++++++++ harbour/contrib/rddads/adsfunc.c | 4 +-- harbour/examples/httpsrv/socket.c | 5 --- harbour/examples/uhttpd2/socket.c | 5 --- harbour/include/hbapi.h | 2 ++ harbour/source/common/hbdate.c | 13 ++++--- harbour/source/vm/extend.c | 58 +++++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 17 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index fe545a5b18..442568ccb7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,28 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-07-30 06:35 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * source/common/hbdate.c + ! Fixed for some systems where tm->tm_gmtoff isn't available. + (like sunos). Thanks to Tamas Tevesz for report and pointer. + + * contrib/rddads/adsfunc.c + + ADSCREATESAVEPOINT() + ADSROLLBACKSAVEPOINT() + Added support for 3rd optional parameter on Harbour level. + + * include/hbapi.h + * source/vm/extend.c + + hb_parnidef(), hb_parnldef() to give a faster and shorter + alternative to HB_ISNUM( x ) ? hb_parn[i|l]( x ) : + construct, which quite often occure in C interface code. + We may also add a hb_parl() version which returns TRUE, + this covers most real-life usages. + + * examples/uhttpd2/socket.c + * examples/httpsrv/socket.c + % Deleted local hb_parnidef() wrapper. + 2009-07-30 00:43 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * include/hbextern.ch * source/rtl/dateshb.c diff --git a/harbour/contrib/rddads/adsfunc.c b/harbour/contrib/rddads/adsfunc.c index 3a0dc105b7..f6353ebc4d 100644 --- a/harbour/contrib/rddads/adsfunc.c +++ b/harbour/contrib/rddads/adsfunc.c @@ -2196,7 +2196,7 @@ HB_FUNC( ADSCREATESAVEPOINT ) #if ADS_LIB_VERSION >= 800 hb_retnl( AdsCreateSavepoint( HB_ADS_PARCONNECTION( 1 ) /* hConnect */, ( UNSIGNED8 * ) hb_parc( 2 ) /* pucSavepoint */, - ADS_DEFAULT /* ulOptions */ ) ); + ( UNSIGNED32 ) ( HB_ISNUM( 3 ) ? hb_parnl( 3 ) : ADS_DEFAULT ) /* ulOptions */ ) ); #else hb_retnl( 0 ); #endif @@ -2207,7 +2207,7 @@ HB_FUNC( ADSROLLBACKSAVEPOINT ) #if ADS_LIB_VERSION >= 800 hb_retnl( AdsRollbackTransaction80( HB_ADS_PARCONNECTION( 1 ) /* hConnect */, ( UNSIGNED8 * ) hb_parc( 2 ) /* pucSavepoint */, - ADS_DEFAULT /* ulOptions */ ) ); + ( UNSIGNED32 ) ( HB_ISNUM( 3 ) ? hb_parnl( 3 ) : ADS_DEFAULT ) /* ulOptions */ ) ); #else hb_retnl( 0 ); #endif diff --git a/harbour/examples/httpsrv/socket.c b/harbour/examples/httpsrv/socket.c index 59b72f5e52..b83daee8d4 100644 --- a/harbour/examples/httpsrv/socket.c +++ b/harbour/examples/httpsrv/socket.c @@ -45,11 +45,6 @@ #include "hbsocket.h" #include "hbapiitm.h" -static int hb_parnidef( int iParam, int iValue ) -{ - return HB_ISNUM( iParam ) ? hb_parni( iParam ) : iValue; -} - static HB_SOCKET hb_parsocket( int iParam ) { return HB_ISPOINTER( iParam ) ? ( HB_SOCKET ) ( HB_PTRDIFF ) diff --git a/harbour/examples/uhttpd2/socket.c b/harbour/examples/uhttpd2/socket.c index 59b72f5e52..b83daee8d4 100644 --- a/harbour/examples/uhttpd2/socket.c +++ b/harbour/examples/uhttpd2/socket.c @@ -45,11 +45,6 @@ #include "hbsocket.h" #include "hbapiitm.h" -static int hb_parnidef( int iParam, int iValue ) -{ - return HB_ISNUM( iParam ) ? hb_parni( iParam ) : iValue; -} - static HB_SOCKET hb_parsocket( int iParam ) { return HB_ISPOINTER( iParam ) ? ( HB_SOCKET ) ( HB_PTRDIFF ) diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 129590cae4..14a87b5142 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -622,7 +622,9 @@ extern HB_EXPORT BOOL hb_partdt( long * plJulian, long * plMilliSec , in extern HB_EXPORT int hb_parl( int iParam ); /* retrieve a logical parameter as an int */ extern HB_EXPORT double hb_parnd( int iParam ); /* retrieve a numeric parameter as a double */ extern HB_EXPORT int hb_parni( int iParam ); /* retrieve a numeric parameter as a integer */ +extern HB_EXPORT int hb_parnidef( int iParam, int iDefValue ); /* retrieve a numeric parameter as a integer, return default value if parameter isn't numeric */ extern HB_EXPORT long hb_parnl( int iParam ); /* retrieve a numeric parameter as a long */ +extern HB_EXPORT long hb_parnldef( int iParam, long lDefValue ); /* retrieve a numeric parameter as a long, return default value if parameter isn't numeric */ extern HB_EXPORT HB_LONG hb_parnint( int iParam ); /* retrieve a numeric parameter as a HB_LONG */ extern HB_EXPORT void * hb_parptr( int iParam ); /* retrieve a parameter as a pointer */ extern HB_EXPORT void * hb_parptrGC( HB_GARBAGE_FUNC_PTR pFunc, int iParam ); /* retrieve a parameter as a pointer if it's a pointer to GC allocated block */ diff --git a/harbour/source/common/hbdate.c b/harbour/source/common/hbdate.c index 9bb0c70bfd..5528158ed3 100644 --- a/harbour/source/common/hbdate.c +++ b/harbour/source/common/hbdate.c @@ -912,17 +912,20 @@ long hb_timeUTCOffset( void ) /* in seconds */ } #else { - struct tm tmTime; - time_t current; + struct tm * timeinfo; + time_t current, utc, local; time( ¤t ); + timeinfo = gmtime( ¤t ); + utc = mktime( timeinfo ); # if defined( HB_HAS_LOCALTIME_R ) - localtime_r( ¤t, &tmTime ); + localtime_r( ¤t, timeinfo ); # else - tmTime = *localtime( ¤t ); + timeinfo = localtime( ¤t ); # endif + local = mktime( timeinfo ); - return tmTime.tm_gmtoff; + return utc - local - ( timeinfo->tm_isdst ? 1 : 0 ); } #endif } diff --git a/harbour/source/vm/extend.c b/harbour/source/vm/extend.c index 6d81589bc9..38ae131dc0 100644 --- a/harbour/source/vm/extend.c +++ b/harbour/source/vm/extend.c @@ -61,6 +61,8 @@ * hb_retnllen() * hb_retndlen() * hb_retdl() + * hb_parnidef() (based on idea by Mindaugas Kavaliauskas) + * hb_parnldef() * * Copyright 2000 Jose Lalin * hb_retd() @@ -481,6 +483,34 @@ int hb_parni( int iParam ) return 0; } +int hb_parnidef( int iParam, int iDefValue ) +{ + HB_STACK_TLS_PRELOAD + + HB_TRACE(HB_TR_DEBUG, ("hb_parni(%d, %d)", iParam, iDefValue)); + + if( iParam >= -1 && iParam <= hb_pcount() ) + { + PHB_ITEM pItem = ( iParam == -1 ) ? hb_stackReturnItem() : hb_stackItemFromBase( iParam ); + + if( HB_IS_BYREF( pItem ) ) + pItem = hb_itemUnRef( pItem ); + + if( HB_IS_INTEGER( pItem ) ) + return pItem->item.asInteger.value; + else if( HB_IS_LONG( pItem ) ) + return ( int ) pItem->item.asLong.value; + else if( HB_IS_DOUBLE( pItem ) ) +#ifdef __GNUC__ + return ( int ) ( unsigned int ) pItem->item.asDouble.value; +#else + return ( int ) pItem->item.asDouble.value; +#endif + } + + return iDefValue; +} + long hb_parnl( int iParam ) { HB_STACK_TLS_PRELOAD @@ -509,6 +539,34 @@ long hb_parnl( int iParam ) return 0; } +long hb_parnldef( int iParam, long lDefValue ) +{ + HB_STACK_TLS_PRELOAD + + HB_TRACE(HB_TR_DEBUG, ("hb_parnldef(%d, %ld)", iParam, lDefValue)); + + if( iParam >= -1 && iParam <= hb_pcount() ) + { + PHB_ITEM pItem = ( iParam == -1 ) ? hb_stackReturnItem() : hb_stackItemFromBase( iParam ); + + if( HB_IS_BYREF( pItem ) ) + pItem = hb_itemUnRef( pItem ); + + if( HB_IS_LONG( pItem ) ) + return ( long ) pItem->item.asLong.value; + else if( HB_IS_INTEGER( pItem ) ) + return ( long ) pItem->item.asInteger.value; + else if( HB_IS_DOUBLE( pItem ) ) +#ifdef __GNUC__ + return ( long ) ( unsigned long ) pItem->item.asDouble.value; +#else + return ( long ) pItem->item.asDouble.value; +#endif + } + + return lDefValue; +} + #ifndef HB_LONG_LONG_OFF LONGLONG hb_parnll( int iParam ) {