2011-05-21 12:02 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/src/rtl/valtoexp.prg
    ! fixed typo in recent modifications causing RTE in HB_VALTOEXP()

  * harbour/contrib/hbwin/win_prn2.c
    ! allocate dynamic memory for print buffer in WIN_PRINTFILERAW()
      32KB variable on process execution stack is potential source of
      random GPFs in programs using deeper recursive calls and killer
      for MT mode when smaller thread stack is allocated.
    ! fixed potential data lost in WIN_PRINTFILERAW() when not all data
      is transfered in single WritePrinter() call
    ! interrupt printing in WIN_PRINTFILERAW() if WritePrinter() returns
      error

  * harbour/include/harbour.hbx
  * harbour/src/rtl/hbrandom.c
    ! restored my old fix - it was correct and the results over RAND_MAX
      range expected
    + added new PRG function:
         HB_RANDOMMAX() -> <nRAND_MAX>
This commit is contained in:
Przemyslaw Czerpak
2011-05-21 10:02:49 +00:00
parent 1ec0e26192
commit 7fbc9044fe
5 changed files with 61 additions and 20 deletions

View File

@@ -16,6 +16,27 @@
The license applies to all entries newer than 2009-04-28.
*/
2011-05-21 12:02 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/src/rtl/valtoexp.prg
! fixed typo in recent modifications causing RTE in HB_VALTOEXP()
* harbour/contrib/hbwin/win_prn2.c
! allocate dynamic memory for print buffer in WIN_PRINTFILERAW()
32KB variable on process execution stack is potential source of
random GPFs in programs using deeper recursive calls and killer
for MT mode when smaller thread stack is allocated.
! fixed potential data lost in WIN_PRINTFILERAW() when not all data
is transfered in single WritePrinter() call
! interrupt printing in WIN_PRINTFILERAW() if WritePrinter() returns
error
* harbour/include/harbour.hbx
* harbour/src/rtl/hbrandom.c
! restored my old fix - it was correct and the results over RAND_MAX
range expected
+ added new PRG function:
HB_RANDOMMAX() -> <nRAND_MAX>
2011-05-20 17:27 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbide/idethemes.prg
+ Added: "NOT" as Harbour keyword.

View File

@@ -370,6 +370,8 @@ HB_FUNC( WIN_PRINTERPORTTONAME )
#endif
}
#define HB_PRINT_BUFFER_SIZE ( 32 * 1024 )
HB_FUNC( WIN_PRINTFILERAW )
{
int iResult = -1;
@@ -399,12 +401,15 @@ HB_FUNC( WIN_PRINTFILERAW )
if( fhnd != FS_ERROR )
{
HB_BYTE pbyBuffer[ 32 * 1024 ];
DWORD dwWritten = 0;
HB_BYTE * pbyBuffer = ( HB_BYTE * ) hb_xgrab( HB_PRINT_BUFFER_SIZE );
HB_SIZE nRead;
while( ( nRead = hb_fsReadLarge( fhnd, pbyBuffer, sizeof( pbyBuffer ) ) ) > 0 )
iResult = 1;
while( ( nRead = hb_fsReadLarge( fhnd, pbyBuffer, HB_PRINT_BUFFER_SIZE ) ) > 0 )
{
DWORD nWritten = 0;
#if 0
/* TOFIX: This check seems wrong for any input files
larger than our read buffer, in such case it
@@ -414,11 +419,29 @@ HB_FUNC( WIN_PRINTFILERAW )
nRead--; /* Skip the EOF() character */
#endif
WritePrinter( hPrinter, pbyBuffer, ( DWORD ) nRead, &dwWritten );
while( nWritten < nRead )
{
DWORD dwWritten = 0;
if( !WritePrinter( hPrinter, &pbyBuffer[ nWritten ],
( DWORD ) ( nRead - nWritten ),
&dwWritten ) )
{
iResult = -7;
break;
}
else if( nWritten == 0 )
{
iResult = -8;
break;
}
nWritten += dwWritten;
}
if( nWritten < nRead )
break;
}
iResult = 1;
hb_fsClose( fhnd );
hb_xfree( pbyBuffer );
}
else
iResult = -6;

View File

@@ -695,6 +695,7 @@ DYNAMIC HB_RAND32
DYNAMIC HB_RANDOM
DYNAMIC HB_RANDOMINT
DYNAMIC HB_RANDOMSEED
DYNAMIC HB_RANDOMMAX
DYNAMIC HB_RASCAN
DYNAMIC HB_RAT
DYNAMIC HB_RDDGETTEMPALIAS

View File

@@ -124,8 +124,17 @@ HB_FUNC( HB_RANDOMSEED )
s_fInit = HB_TRUE;
}
HB_FUNC( HB_RANDOMMAX )
{
#if RAND_MAX > HB_VMLONG_MAX
hb_retnd( RAND_MAX );
#else
hb_retnint( RAND_MAX );
#endif
}
/* Returns a double value between 0 and 1 */
double hb_random_num()
double hb_random_num( void )
{
double d1, d2;
@@ -136,20 +145,7 @@ double hb_random_num()
}
d1 = ( double ) rand();
#ifdef __HB_THIS_FIX_BREAKS_MINGW32_64__
d2 = ( double ) RAND_MAX + 1.0;
#else
d2 = ( double ) RAND_MAX;
#if defined( __BORLANDC__ )
/* It seems that on Windows platform there some weirdness about EPSILON value so
that a float division using an epsilon smaller than 1e-10 may be rounded.
Must dig if it's a borland lib bug or a windows problem.
*/
d2 += 0.001;
#else
d2 += DBL_EPSILON;
#endif
#endif
return d1 / d2;
}

View File

@@ -59,7 +59,7 @@ FUNCTION hb_VALTOEXP( xVal )
SWITCH v
CASE "C"
CASE "M" ; RETURN hb_StrToExp( xVal )
CASE "N" ; hb_ntos( xVal )
CASE "N" ; RETURN hb_ntos( xVal )
CASE "D" ; RETURN iif( Empty( xVal ), "0d00000000", "0d" + DToS( xVal ) )
CASE "T" ; RETURN 't"' + hb_TSToStr( xVal, .T. ) + '"'
CASE "L" ; RETURN iif( xVal, ".T.", ".F." )