From dd570d683cb57f1ed833275a7da78e0568f762cd Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 7 Jan 2010 20:59:38 +0000 Subject: [PATCH] 2010-01-07 21:10 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * INSTALL + Added free SVN book link. * src/vm/extrap.c % Marked exception filter callback as 'static' ; TOCHECK: Please verify that OS/2 still works this way. * src/rtl/oemansi.c ! Fixed two tabs. * src/rtl/gtwvt/gtwvt.c * contrib/gtwvg/gtwvg.c * contrib/rddads/adsfunc.c ! Fixed to not use unsafe/ANSI CharToOemBuffA() API. ; Please review me. * config/win/mingw.mk + Added information about MinGW alternatives for MSVC security features. Unfortunately they need Cygwin binary plus some depend on MinGW host platform and/or version. * include/hbwince.h * src/common/hbwince.c - Deleted CharToOemBuffA(), OemToCharBuffA(). No longer needed by Harbour. ; TODO: Delete rest of not anymore used ANSI WinAPI functions. Now Harbour never uses ANSI WinAPI functions in UNICODE mode. * config/win/global.mk - Deleted reference to CharToOemBuffA(), OemToCharBuffA(). --- harbour/ChangeLog | 34 ++++++++++++++++++++++ harbour/INSTALL | 2 ++ harbour/config/win/global.mk | 2 +- harbour/config/win/mingw.mk | 9 ++++++ harbour/contrib/gtwvg/gtwvg.c | 17 +++++++---- harbour/contrib/rddads/adsfunc.c | 48 ++++++++++++++++++++++++-------- harbour/include/hbwince.h | 2 -- harbour/src/common/hbwince.c | 14 ---------- harbour/src/rtl/gtwvt/gtwvt.c | 17 +++++++---- harbour/src/rtl/oemansi.c | 4 +-- harbour/src/vm/extrap.c | 10 +++---- 11 files changed, 111 insertions(+), 48 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2556e63938..78c16dce5d 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,40 @@ past entries belonging to author(s): Viktor Szakats. */ +2010-01-07 21:10 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * INSTALL + + Added free SVN book link. + + * src/vm/extrap.c + % Marked exception filter callback as 'static' + ; TOCHECK: Please verify that OS/2 still works this way. + + * src/rtl/oemansi.c + ! Fixed two tabs. + + * src/rtl/gtwvt/gtwvt.c + * contrib/gtwvg/gtwvg.c + * contrib/rddads/adsfunc.c + ! Fixed to not use unsafe/ANSI CharToOemBuffA() API. + ; Please review me. + + * config/win/mingw.mk + + Added information about MinGW alternatives for MSVC + security features. Unfortunately they need Cygwin + binary plus some depend on MinGW host platform + and/or version. + + * include/hbwince.h + * src/common/hbwince.c + - Deleted CharToOemBuffA(), OemToCharBuffA(). No longer + needed by Harbour. + ; TODO: Delete rest of not anymore used ANSI WinAPI + functions. Now Harbour never uses ANSI + WinAPI functions in UNICODE mode. + + * config/win/global.mk + - Deleted reference to CharToOemBuffA(), OemToCharBuffA(). + 2010-01-07 10:34 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbide/idethemes.prg * contrib/hbide/resources/selectionlist.ui diff --git a/harbour/INSTALL b/harbour/INSTALL index 11bc3353a4..8d0cb17aee 100644 --- a/harbour/INSTALL +++ b/harbour/INSTALL @@ -1399,6 +1399,8 @@ HARBOUR Netiquette Guidelines http://tools.ietf.org/html/rfc1855 + Subversion book (free) + http://svnbook.red-bean.com/ 14. HOW TO PARTICIPATE diff --git a/harbour/config/win/global.mk b/harbour/config/win/global.mk index 4b6636d68a..791a18bf75 100644 --- a/harbour/config/win/global.mk +++ b/harbour/config/win/global.mk @@ -15,7 +15,7 @@ ifneq ($(HB_CPU),x86) endif # kernel32: needed by some compilers (pocc/watcom) -# user32: *Clipboard*(), MessageBox(), CharToOemBuff(), OemToCharBuff(), GetKeyState(), GetKeyboardState(), SetKeyboardState() +# user32: *Clipboard*(), MessageBox(), GetKeyState(), GetKeyboardState(), SetKeyboardState() # ws2_32: hbsocket # advapi32: GetUserName() # gdi32: gtwvt diff --git a/harbour/config/win/mingw.mk b/harbour/config/win/mingw.mk index f8d5e176c4..c6e0832cd0 100644 --- a/harbour/config/win/mingw.mk +++ b/harbour/config/win/mingw.mk @@ -18,6 +18,15 @@ CC_OUT := -o CFLAGS += -I. -I$(HB_INC_COMPILE) +# Equivalent to MSVC -GS (default) option, available in GCC 4.1 and upper: +# -fstack-protector +# Equivalent to -dynamicbase MSVC linker option: +# peflags --dynamicbase=true +# Equivalent to -nxcompat MSVC linker option: +# peflags --nxcompat=true +# Equivalent to -tsaware MSVC linker option: +# peflags --tsaware=true + ifneq ($(HB_BUILD_WARN),no) CFLAGS += -Wall -W endif diff --git a/harbour/contrib/gtwvg/gtwvg.c b/harbour/contrib/gtwvg/gtwvg.c index 9af2119304..33dffec582 100644 --- a/harbour/contrib/gtwvg/gtwvg.c +++ b/harbour/contrib/gtwvg/gtwvg.c @@ -689,14 +689,19 @@ static void hb_gt_wvt_TranslateKey( PHB_GTWVT pWVT, int key, int shiftkey, int a static int hb_gt_wvt_key_ansi_to_oem( int c ) { - BYTE pszAnsi[ 2 ]; - BYTE pszOem[ 2 ]; + BYTE pszSrc[ 2 ]; + wchar_t pszWide[ 1 ]; + BYTE pszDst[ 2 ]; - pszAnsi[ 0 ] = ( CHAR ) c; - pszAnsi[ 1 ] = 0; - CharToOemBuffA( ( LPCSTR ) pszAnsi, ( LPSTR ) pszOem, 1 ); + pszSrc[ 0 ] = ( CHAR ) c; + pszSrc[ 1 ] = + pszDst[ 0 ] = + pszDst[ 1 ] = 0; - return * pszOem; + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, ( LPCSTR ) pszSrc, 1, ( LPWSTR ) pszWide, 1 ); + WideCharToMultiByte( CP_OEMCP, 0, ( LPCWSTR ) pszWide, 1, ( LPSTR ) pszDst, 1, NULL, NULL ); + + return pszDst[ 0 ]; } static BOOL hb_gt_wvt_FitRows( PHB_GTWVT pWVT ) diff --git a/harbour/contrib/rddads/adsfunc.c b/harbour/contrib/rddads/adsfunc.c index 6b00107287..f9cb151023 100644 --- a/harbour/contrib/rddads/adsfunc.c +++ b/harbour/contrib/rddads/adsfunc.c @@ -82,34 +82,58 @@ ADSHANDLE hb_ads_hConnect = 0; BOOL hb_ads_bOEM = FALSE; -char * hb_adsOemToAnsi( const char * pcString, ULONG ulLen ) +char * hb_adsOemToAnsi( const char * pszSrc, ULONG nLen ) { if( hb_ads_bOEM ) { - char * pszDst = ( char * ) hb_xgrab( ulLen + 1 ); - OemToCharBuffA( ( LPCSTR ) pcString, ( LPSTR ) pszDst, ( DWORD ) ulLen ); - pszDst[ ulLen ] = '\0'; + int nWideLen = MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, pszSrc, nLen, NULL, 0 ); + LPWSTR pszWide = ( LPWSTR ) hb_xgrab( ( nWideLen + 1 ) * sizeof( wchar_t ) ); + + char * pszDst; + + MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED, pszSrc, nLen, pszWide, nWideLen ); + + nLen = WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); + pszDst = ( char * ) hb_xgrab( nLen + 1 ); + + WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + + hb_xfree( pszWide ); + + pszDst[ nLen ] = '\0'; return pszDst; } - return ( char * ) pcString; + return ( char * ) pszSrc; } -char * hb_adsAnsiToOem( const char * pcString, ULONG ulLen ) +char * hb_adsAnsiToOem( const char * pszSrc, ULONG nLen ) { if( hb_ads_bOEM ) { - char * pszDst = ( char * ) hb_xgrab( ulLen + 1 ); - CharToOemBuffA( ( LPCSTR ) pcString, ( LPSTR ) pszDst, ( DWORD ) ulLen ); - pszDst[ ulLen ] = '\0'; + int nWideLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszSrc, nLen, NULL, 0 ); + LPWSTR pszWide = ( LPWSTR ) hb_xgrab( ( nWideLen + 1 ) * sizeof( wchar_t ) ); + + char * pszDst; + + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pszSrc, nLen, pszWide, nWideLen ); + + nLen = WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); + pszDst = ( char * ) hb_xgrab( nLen + 1 ); + + WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + + hb_xfree( pszWide ); + + pszDst[ nLen ] = '\0'; return pszDst; } - return ( char * ) pcString; + return ( char * ) pszSrc; } -void hb_adsOemAnsiFree( char * pcString ) +void hb_adsOemAnsiFree( char * pszSrc ) { if( hb_ads_bOEM ) - hb_xfree( pcString ); + hb_xfree( pszSrc ); } #endif diff --git a/harbour/include/hbwince.h b/harbour/include/hbwince.h index bc4aeba7a5..fd2de148a9 100644 --- a/harbour/include/hbwince.h +++ b/harbour/include/hbwince.h @@ -133,8 +133,6 @@ extern char * strerror( int errnum ); BOOL WINAPI RemoveDirectoryA( LPCSTR path ); BOOL WINAPI CreateDirectoryA( LPCSTR path, LPSECURITY_ATTRIBUTES attr ); BOOL WINAPI SetFileAttributesA( LPCSTR filename, DWORD attr ); - BOOL WINAPI CharToOemBuffA( LPCSTR src, LPSTR dst, DWORD len ); - BOOL WINAPI OemToCharBuffA( LPCSTR src, LPSTR dst, DWORD len ); HANDLE WINAPI FindFirstFileA( LPCSTR path, WIN32_FIND_DATAA * data ); BOOL WINAPI FindNextFileA( HANDLE handle, WIN32_FIND_DATAA * data ); BOOL WINAPI GetVersionExA( OSVERSIONINFOA * v ); diff --git a/harbour/src/common/hbwince.c b/harbour/src/common/hbwince.c index db564f89f7..c5cfaa29a3 100644 --- a/harbour/src/common/hbwince.c +++ b/harbour/src/common/hbwince.c @@ -510,20 +510,6 @@ BOOL WINAPI SetFileAttributesA( LPCSTR filename, DWORD attr ) return b; } -BOOL WINAPI CharToOemBuffA( LPCSTR src, LPSTR dst, DWORD len ) -{ - if( len ) - hb_strncpy( dst, src, len - 1 ); - return TRUE; -} - -BOOL WINAPI OemToCharBuffA( LPCSTR src, LPSTR dst, DWORD len ) -{ - if( len ) - hb_strncpy( dst, src, len - 1 ); - return TRUE; -} - HANDLE WINAPI FindFirstFileA( LPCSTR path, WIN32_FIND_DATAA * data ) { DWORD dwError; diff --git a/harbour/src/rtl/gtwvt/gtwvt.c b/harbour/src/rtl/gtwvt/gtwvt.c index 81b8f3d046..8d70341bb1 100644 --- a/harbour/src/rtl/gtwvt/gtwvt.c +++ b/harbour/src/rtl/gtwvt/gtwvt.c @@ -557,14 +557,19 @@ static void hb_gt_wvt_TranslateKey( PHB_GTWVT pWVT, int key, int shiftkey, int a static int hb_gt_wvt_key_ansi_to_oem( int c ) { - BYTE pszAnsi[ 2 ]; - BYTE pszOem[ 2 ]; + BYTE pszSrc[ 2 ]; + wchar_t pszWide[ 1 ]; + BYTE pszDst[ 2 ]; - pszAnsi[ 0 ] = ( CHAR ) c; - pszAnsi[ 1 ] = 0; - CharToOemBuffA( ( LPCSTR ) pszAnsi, ( LPSTR ) pszOem, 1 ); + pszSrc[ 0 ] = ( CHAR ) c; + pszSrc[ 1 ] = + pszDst[ 0 ] = + pszDst[ 1 ] = 0; - return * pszOem; + MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, ( LPCSTR ) pszSrc, 1, ( LPWSTR ) pszWide, 1 ); + WideCharToMultiByte( CP_OEMCP, 0, ( LPCWSTR ) pszWide, 1, ( LPSTR ) pszDst, 1, NULL, NULL ); + + return pszDst[ 0 ]; } static void hb_gt_wvt_FitRows( PHB_GTWVT pWVT ) diff --git a/harbour/src/rtl/oemansi.c b/harbour/src/rtl/oemansi.c index 82fc26ae15..0f2e18ee3c 100644 --- a/harbour/src/rtl/oemansi.c +++ b/harbour/src/rtl/oemansi.c @@ -78,7 +78,7 @@ HB_FUNC( HB_ANSITOOEM ) nLen = WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); pszDst = ( char * ) hb_xgrab( nLen + 1 ); - WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + WideCharToMultiByte( CP_OEMCP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); hb_xfree( pszWide ); hb_retclen_buffer( pszDst, nLen ); @@ -110,7 +110,7 @@ HB_FUNC( HB_OEMTOANSI ) nLen = WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, NULL, 0, NULL, NULL ); pszDst = ( char * ) hb_xgrab( nLen + 1 ); - WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); + WideCharToMultiByte( CP_ACP, 0, pszWide, nWideLen, pszDst, nLen, NULL, NULL ); hb_xfree( pszWide ); hb_retclen_buffer( pszDst, nLen ); diff --git a/harbour/src/vm/extrap.c b/harbour/src/vm/extrap.c index 9ee51f5fe5..a569ec7b7b 100644 --- a/harbour/src/vm/extrap.c +++ b/harbour/src/vm/extrap.c @@ -98,7 +98,7 @@ #if defined( HB_OS_WIN ) && !defined( HB_OS_WIN_CE ) -LONG WINAPI hb_winExceptionHandler( struct _EXCEPTION_POINTERS * pExceptionInfo ) +static LONG WINAPI hb_winExceptionHandler( struct _EXCEPTION_POINTERS * pExceptionInfo ) { char errmsg[ 8192 ]; int errmsglen = sizeof( errmsg ) - 1; @@ -288,10 +288,10 @@ LONG WINAPI hb_winExceptionHandler( struct _EXCEPTION_POINTERS * pExceptionInfo static EXCEPTIONREGISTRATIONRECORD s_regRec; /* Exception Registration Record */ -ULONG _System hb_os2ExceptionHandler( PEXCEPTIONREPORTRECORD p1, - PEXCEPTIONREGISTRATIONRECORD p2, - PCONTEXTRECORD p3, - PVOID pv ) +static ULONG _System hb_os2ExceptionHandler( PEXCEPTIONREPORTRECORD p1, + PEXCEPTIONREGISTRATIONRECORD p2, + PCONTEXTRECORD p3, + PVOID pv ) { HB_SYMBOL_UNUSED( p1 ); HB_SYMBOL_UNUSED( p2 );