diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 3e8e385ce6..f32d3afbb5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,45 @@ +19990824-20:30 GMT+1 Victor Szel + + * include/hbdefs.h + ! ISBYREF() macro changed to call hb_parinfo() instead of hb_param(), + it was not working previously since hb_param() was automatically + dereferencing the parameter. + FOPEN() parameter checking was not working correctly because of this. + + ( WARNING ! THIS SEEMS TO BE A WORKAROUND FOR SOME OTHER PROBLEM + WITH PARAMETERS PASSED BY REFERENCE, PLEASE ALSO NOTE THAT + FRead() IS NOT WORKING RIGHT NOW ) + + * source/rtl/filesys.c + doc/subcodes.txt + * Huge cleanup, reformatted, eliminated usage of internal structures, + fixed types, standardized variable names, explicit constants changed + to manifest constants, fixed a whole bunch of bugs, simplified code + fragments, optimalized variable usage and scope. 65535U -> (USHORT)-1 + % "return;"s removed + * reindented using 3 chars + ! FWRITE() and hb_fsWrite() returns 0 instead of 65535 if the write failed. + ! FOPEN() runtime error code fixed + ! FERASE() return value fixed + ! FREAD() will check is the passed buffer size is smaller than the + required read length. + ! FREAD(): Added warning about the fact, that the buffer returned by + hb_parc() will be directly modified. (this is strictly prohibited by + Clipper doc). + ! hb_fsCreate() didn't reset the last error code on success. + ! hb_fsDelete(), bh_fsRename(), hb_fsLock(), hb_fsCommit() - the not + defined platform branch is now setting the last error code. + ! hb_fsExtOpen() is now setting the last code the FS_ERROR. + % FREADSTR() made much faster + ! FREADSTR() uses hb_fsRead() instead of read() + ! hb_fsClose() didn't set the last error code. + ! I2BIN(), L2BIN() was returning one more character than Clipper + (it worked OK when bad parameters were passed). + ! BIN2L() returned an int instead of long, this is fixed. + + * source/rtl/math.c + * Reformatting finished. + 19990824-19:05 GMT+1 Victor Szel * source/rtl/math.c diff --git a/harbour/doc/subcodes.txt b/harbour/doc/subcodes.txt index 51de39209d..debd2cb3c8 100644 --- a/harbour/doc/subcodes.txt +++ b/harbour/doc/subcodes.txt @@ -1168,16 +1168,11 @@ start from 3000 * $SUBCODE$ * BASE/3006 * $CATEGORY$ - * arguments + * (not used yet) * $ONELINER$ - * Invalid type of argument * $DESCRIPTION$ - * The passed argument is of invalid type. This function expects a string - * with the name of file to open. * $FUNCTION$ - * FOPEN * $STATUS$ - * Harbour specific * $SEEALSO$ * * $END$ diff --git a/harbour/include/hbdefs.h b/harbour/include/hbdefs.h index 3996cb1fb0..ce1d263be6 100644 --- a/harbour/include/hbdefs.h +++ b/harbour/include/hbdefs.h @@ -130,7 +130,7 @@ typedef char SYMBOLSCOPE; /* stores symbol's scope */ #define ISLOG( n ) ( hb_param( n, IT_LOGICAL ) != NULL ) #define ISDATE( n ) ( hb_param( n, IT_DATE ) != NULL ) #define ISMEMO( n ) ( hb_param( n, IT_MEMO ) != NULL ) -#define ISBYREF( n ) ( hb_param( n, IT_BYREF ) != NULL ) +#define ISBYREF( n ) ( hb_parinfo( n ) & IT_BYREF ) /* Intentionally using a different method */ #define ISARRAY( n ) ( hb_param( n, IT_ARRAY ) != NULL ) #define PCOUNT hb_parinfo( 0 ) diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 8739fd1c27..108d175555 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -344,7 +344,7 @@ USHORT hb_fsWrite ( FHANDLE hFileHandle, BYTE * pBuff, USHORT uiCount ) errno = 0; uiWritten = write( hFileHandle, pBuff, uiCount ); s_uiErrorLast = errno; - if( uiWritten == (USHORT)-1 ) + if( uiWritten == ( USHORT )-1 ) uiWritten = 0; #else @@ -354,7 +354,7 @@ USHORT hb_fsWrite ( FHANDLE hFileHandle, BYTE * pBuff, USHORT uiCount ) errno = 0; uiWritten = _write( hFileHandle, pBuff, uiCount ); s_uiErrorLast = errno; - if( uiWritten == (USHORT)-1 ) + if( uiWritten == ( USHORT )-1 ) uiWritten = 0; #else @@ -718,7 +718,7 @@ HARBOUR HB_FREAD( void ) { ULONG ulRead = 0; - if( ISNUM( 1 ) && hb_param( 2, IT_STRING | IT_BYREF ) != NULL && ISNUM( 3 ) ) + if( ISNUM( 1 ) && ISCHAR( 2 ) && ISBYREF( 2 ) && ISNUM( 3 ) ) { ULONG ulToRead = hb_parnl( 3 ); @@ -730,9 +730,7 @@ HARBOUR HB_FREAD( void ) hb_parc( 2 ), ulToRead ); } - else ulRead = (ULONG) -1; } - else ulRead = (ULONG) -1; hb_retnl( ulRead ); } @@ -809,7 +807,7 @@ HARBOUR HB_FILE( void ) if( ISCHAR( 1 ) ) { -/*TODO: Check if F_OK is defined in all compilers */ +/* TODO: Check if F_OK is defined in all compilers */ #ifdef OS_UNIX_COMPATIBLE hb_retl( access( hb_parc( 1 ), F_OK ) == 0 ); @@ -1079,7 +1077,7 @@ char * hb_fsFNameMerge( char *szFileName, PHB_FNAME pFileName ) return szFileName; } -/* +/* TOFIX: If you call pFileName = hb_fsFNameSplit( "C:FILE.EXT" ) the result is: pFileName->szPath => (null) must be 'C:' pFileName->szName => 'C:FILE' must be 'FILE' diff --git a/harbour/source/rtl/math.c b/harbour/source/rtl/math.c index 8f8a9e235e..e102d8f0db 100644 --- a/harbour/source/rtl/math.c +++ b/harbour/source/rtl/math.c @@ -13,13 +13,11 @@ #include "set.h" #include "errorapi.h" -/* The rest of functions is pulled automatically by initsymb.c */ - HARBOUR HB_ABS( void ) { if( hb_pcount() == 1 ) { - PHB_ITEM pNumber = hb_param(1, IT_NUMERIC); + PHB_ITEM pNumber = hb_param( 1, IT_NUMERIC ); if( pNumber ) switch( pNumber->type ) { @@ -45,15 +43,10 @@ HARBOUR HB_ABS( void ) stack.Return.item.asDouble.decimal = pNumber->item.asDouble.decimal; } else - { - hb_errRT_BASE(EG_ARG, 1089, NULL, "ABS"); - } + hb_errRT_BASE( EG_ARG, 1089, NULL, "ABS" ); } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "ABS"); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "ABS" ); /* NOTE: Clipper catches this at compile time! */ } HARBOUR HB_EXP( void ) @@ -67,15 +60,10 @@ HARBOUR HB_EXP( void ) stack.Return.item.asDouble.decimal = hb_set.HB_SET_DECIMALS; } else - { - hb_errRT_BASE(EG_ARG, 1096, NULL, "EXP"); - } + hb_errRT_BASE( EG_ARG, 1096, NULL, "EXP" ); } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "EXP"); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "EXP" ); /* NOTE: Clipper catches this at compile time! */ } HARBOUR HB_INT( void ) @@ -85,15 +73,10 @@ HARBOUR HB_INT( void ) if( ISNUM( 1 ) ) hb_retnl( hb_parnd( 1 ) ); else - { hb_errRT_BASE( EG_ARG, 1090, NULL, "INT" ); - } } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "INT" ); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "INT" ); /* NOTE: Clipper catches this at compile time! */ } HARBOUR HB_LOG( void ) @@ -111,15 +94,10 @@ HARBOUR HB_LOG( void ) stack.Return.item.asDouble.length = 99; } else - { - hb_errRT_BASE(EG_ARG, 1095, NULL, "LOG"); - } + hb_errRT_BASE( EG_ARG, 1095, NULL, "LOG" ); } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "LOG"); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "LOG" ); /* NOTE: Clipper catches this at compile time! */ } /* returns the maximum of two date or numerics */ @@ -173,15 +151,10 @@ HARBOUR HB_MAX( void ) hb_retds( l1 >= l2 ? hb_pards( 1 ) : hb_pards( 2 ) ); } else - { hb_errRT_BASE( EG_ARG, 1093, NULL, "MAX" ); - } } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "MAX" ); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "MAX" ); /* NOTE: Clipper catches this at compile time! */ } /* returns the minimum of two date or numerics */ @@ -235,15 +208,10 @@ HARBOUR HB_MIN( void ) hb_retds( l1 <= l2 ? hb_pards( 1 ) : hb_pards( 2 ) ); } else - { hb_errRT_BASE( EG_ARG, 1092, NULL, "MIN" ); - } } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "MIN" ); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "MIN" ); /* NOTE: Clipper catches this at compile time! */ } /* TOFIX: In Clipper this is written in Clipper, see the source below, */ @@ -262,36 +230,33 @@ FUNCTION MOD(cl_num, cl_base) cl_num,; IF(cl_result * cl_base < 0, cl_result + cl_base, cl_result) ) */ - PHB_ITEM pNumber = hb_param(1, IT_NUMERIC); + PHB_ITEM pNumber = hb_param( 1, IT_NUMERIC ); if( pNumber && ISNUM( 2 ) ) { double dNumber = hb_parnd( 1 ); double dBase = hb_parnd( 2 ); /* dBase! Cool! */ - double dResult; if( dBase ) { - dResult = dNumber - ((long)(dNumber / dBase) * dBase); + double dResult = dNumber - ( ( long )( dNumber / dBase ) * dBase ); if( dResult * dBase < 0 ) - hb_retnd(dResult + dBase); + hb_retnd( dResult + dBase ); else - hb_retnd(dResult); + hb_retnd( dResult ); /* Always set default number of decimals after computing mod */ stack.Return.item.asDouble.decimal = hb_set.HB_SET_DECIMALS; } else { - hb_retnd(dNumber); + hb_retnd( dNumber ); /* Set the correct number of decimals */ stack.Return.item.asDouble.decimal = pNumber->item.asDouble.decimal; } } else - { hb_errRT_BASE( EG_ARG, 1085, NULL, "%" ); - } } double hb_numRound( double dResult, int iDec ) @@ -322,6 +287,7 @@ double hb_numRound( double dResult, int iDec ) } szResult = ( char * ) hb_xgrab( iSize + iDec + 1 ); + if( szResult ) { sprintf( szResult, "%*.*f", iSize, iDec, dResult ); @@ -344,15 +310,10 @@ HARBOUR HB_ROUND( void ) stack.Return.item.asDouble.decimal = iDec; } else - { hb_errRT_BASE( EG_ARG, 1094, NULL, "ROUND" ); - } } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "ROUND" ); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "ROUND" ); /* NOTE: Clipper catches this at compile time! */ } HARBOUR HB_SQRT( void ) @@ -361,27 +322,22 @@ HARBOUR HB_SQRT( void ) { if( ISNUM( 1 ) ) { - double dNumber = hb_parnd(1); + double dNumber = hb_parnd( 1 ); if( dNumber > 0 ) { - hb_retnd( sqrt(dNumber) ); + hb_retnd( sqrt( dNumber ) ); } else /* Clipper doesn't error! */ - hb_retnd(0); + hb_retnd( 0 ); /* Always set default number of decimals after SQRT() */ stack.Return.item.asDouble.decimal = hb_set.HB_SET_DECIMALS; } else - { - hb_errRT_BASE(EG_ARG, 1097, NULL, "SQRT"); - } + hb_errRT_BASE( EG_ARG, 1097, NULL, "SQRT" ); } else - { - /* NOTE: Clipper catches this at compile time! */ - hb_errRT_BASE(EG_ARGCOUNT, 3000, NULL, "SQRT"); - } + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "SQRT" ); /* NOTE: Clipper catches this at compile time! */ }