diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-05-05 13:55:47 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2017-05-05 13:55:47 (GMT) |
commit | fe2b88f2782fc8a4d6a9d7beda9900501f1548fd (patch) | |
tree | 62352d8b850165c0596647d8c111cbe3a2fbfd32 /win/tkWinSend.c | |
parent | ba7ccfc695ea0f53f4afb2165fca6783d7dcfcd7 (diff) | |
download | tk-fe2b88f2782fc8a4d6a9d7beda9900501f1548fd.zip tk-fe2b88f2782fc8a4d6a9d7beda9900501f1548fd.tar.gz tk-fe2b88f2782fc8a4d6a9d7beda9900501f1548fd.tar.bz2 |
On Windows, use Tcl_WinTCharToUtf() in stead of Tcl_NewUnicodeObj(), since Tcl_WinTCharToUtf() works correctly when TCL_UTF_MAX==6 while Tcl_NewUnicodeObj() doesn't.
All changes taken over from androwish. Thanks to Christian Werner!
And ... on the go ... fixed a few memory leaks correctly detected by Christian.
Diffstat (limited to 'win/tkWinSend.c')
-rw-r--r-- | win/tkWinSend.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/win/tkWinSend.c b/win/tkWinSend.c index 6c4731a..c999c0b 100644 --- a/win/tkWinSend.c +++ b/win/tkWinSend.c @@ -252,8 +252,14 @@ TkGetInterpNames( LPOLESTR p = olestr + wcslen(oleszStub); if (*p) { + Tcl_DString ds; + + Tcl_WinTCharToUtf(p + 1, -1, &ds); result = Tcl_ListObjAppendElement(interp, - objList, Tcl_NewUnicodeObj(p + 1, -1)); + objList, + Tcl_NewStringObj(Tcl_DStringValue(&ds), + Tcl_DStringLength(&ds))); + Tcl_DStringFree(&ds); } } @@ -614,7 +620,7 @@ BuildMoniker( Tcl_DString dString; Tcl_DStringInit(&dString); - Tcl_UtfToUniCharDString(name, -1, &dString); + Tcl_WinUtfToTChar(name, -1, &dString); hr = CreateFileMoniker((LPOLESTR)Tcl_DStringValue(&dString), &pmkItem); Tcl_DStringFree(&dString); if (SUCCEEDED(hr)) { @@ -740,6 +746,8 @@ Send( HRESULT hr = S_OK, ehr = S_OK; Tcl_Obj *cmd = NULL; DISPID dispid; + Tcl_DString ds; + const char *src; cmd = Tcl_ConcatObj(objc, objv); @@ -753,7 +761,10 @@ Send( memset(&ei, 0, sizeof(ei)); vCmd.vt = VT_BSTR; - vCmd.bstrVal = SysAllocString(Tcl_GetUnicode(cmd)); + src = Tcl_GetString(cmd); + Tcl_WinUtfToTChar(src, cmd->length, &ds); + vCmd.bstrVal = SysAllocString((WCHAR *) Tcl_DStringValue(&ds)); + Tcl_DStringFree(&ds); dp.cArgs = 1; dp.rgvarg = &vCmd; @@ -774,7 +785,9 @@ Send( ehr = VariantChangeType(&vResult, &vResult, 0, VT_BSTR); if (SUCCEEDED(ehr)) { - Tcl_SetObjResult(interp, Tcl_NewUnicodeObj(vResult.bstrVal, -1)); + Tcl_WinTCharToUtf(vResult.bstrVal, (int) SysStringLen(vResult.bstrVal) * + sizeof (WCHAR), &ds); + Tcl_DStringResult(interp, &ds); } /* @@ -785,8 +798,11 @@ Send( if (hr == DISP_E_EXCEPTION && ei.bstrSource != NULL) { Tcl_Obj *opError, *opErrorCode, *opErrorInfo; - - opError = Tcl_NewUnicodeObj(ei.bstrSource, -1); + Tcl_WinTCharToUtf(ei.bstrSource, (int) SysStringLen(ei.bstrSource) * + sizeof (WCHAR), &ds); + opError = Tcl_NewStringObj(Tcl_DStringValue(&ds), + Tcl_DStringLength(&ds)); + Tcl_DStringFree(&ds); Tcl_ListObjIndex(interp, opError, 0, &opErrorCode); Tcl_SetObjErrorCode(interp, opErrorCode); Tcl_ListObjIndex(interp, opError, 1, &opErrorInfo); @@ -833,6 +849,8 @@ TkWinSend_SetExcepInfo( ICreateErrorInfo *pCEI; IErrorInfo *pEI, **ppEI = &pEI; HRESULT hr; + Tcl_DString ds; + const char *src; if (!pExcepInfo) { return; @@ -851,8 +869,16 @@ TkWinSend_SetExcepInfo( Tcl_ListObjAppendElement(interp, opErrorCode, opErrorInfo); /* TODO: Handle failure to append */ - pExcepInfo->bstrDescription = SysAllocString(Tcl_GetUnicode(opError)); - pExcepInfo->bstrSource = SysAllocString(Tcl_GetUnicode(opErrorCode)); + src = Tcl_GetString(opError); + Tcl_WinUtfToTChar(src, opError->length, &ds); + pExcepInfo->bstrDescription = + SysAllocString((WCHAR *) Tcl_DStringValue(&ds)); + Tcl_DStringFree(&ds); + src = Tcl_GetString(opErrorCode); + Tcl_WinUtfToTChar(src, opErrorCode->length, &ds); + pExcepInfo->bstrSource = + SysAllocString((WCHAR *) Tcl_DStringValue(&ds)); + Tcl_DStringFree(&ds); Tcl_DecrRefCount(opErrorCode); pExcepInfo->scode = E_FAIL; |