diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-06-24 20:55:03 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-06-24 20:55:03 (GMT) |
commit | 946598bb9f345a06cb4ae5de31b6049e2e15baed (patch) | |
tree | 564656618626c2f953a10adc838f3c14b31cc0f8 /win | |
parent | b456ce6d74e9d801a105f103e737b9c4c523e0f7 (diff) | |
parent | 8a3c1f7a687d580fed696e02ed7a5ee71c73fadd (diff) | |
download | tcl-946598bb9f345a06cb4ae5de31b6049e2e15baed.zip tcl-946598bb9f345a06cb4ae5de31b6049e2e15baed.tar.gz tcl-946598bb9f345a06cb4ae5de31b6049e2e15baed.tar.bz2 |
Merge-mark 9.0. Use Tcl_Size (but not in tclWinDde.c/tclWinReg.c)
Diffstat (limited to 'win')
-rw-r--r-- | win/tclWinDde.c | 60 | ||||
-rw-r--r-- | win/tclWinReg.c | 38 |
2 files changed, 73 insertions, 25 deletions
diff --git a/win/tclWinDde.c b/win/tclWinDde.c index 696f273..2570954 100644 --- a/win/tclWinDde.c +++ b/win/tclWinDde.c @@ -125,9 +125,27 @@ static int DdeObjCmd(void *clientData, # define Tcl_WCharToUtfDString Tcl_UniCharToUtfDString # define Tcl_UtfToWCharDString Tcl_UtfToUniCharDString # endif -# define Tcl_Size int #endif +static unsigned char * +getByteArrayFromObj( + Tcl_Obj *objPtr, + size_t *lengthPtr +) { + int length; + + unsigned char *result = Tcl_GetByteArrayFromObj(objPtr, &length); +#if TCL_MAJOR_VERSION > 8 + if (sizeof(TCL_HASH_TYPE) > sizeof(int)) { + /* 64-bit and TIP #494 situation: */ + *lengthPtr = *(TCL_HASH_TYPE *) objPtr->internalRep.twoPtrValue.ptr1; + } else +#endif + /* 32-bit or without TIP #494 */ + *lengthPtr = (size_t) (unsigned) length; + return result; +} + #ifdef __cplusplus extern "C" { #endif @@ -629,7 +647,7 @@ DdeServerProc( /* Transaction-dependent data. */ { Tcl_DString dString; - Tcl_Size len; + size_t len; DWORD dlen; WCHAR *utilString; Tcl_Obj *ddeObjectPtr; @@ -749,7 +767,8 @@ DdeServerProc( CP_WINUNICODE); if (_wcsicmp(utilString, TCL_DDE_EXECUTE_RESULT) == 0) { returnString = - Tcl_GetStringFromObj(convPtr->returnPackagePtr, &len); + Tcl_GetString(convPtr->returnPackagePtr); + len = convPtr->returnPackagePtr->length; if (uFmt != CF_TEXT) { Tcl_DStringInit(&dsBuf); Tcl_UtfToWCharDString(returnString, len, &dsBuf); @@ -771,7 +790,8 @@ DdeServerProc( convPtr->riPtr->interp, Tcl_DStringValue(&ds), NULL, TCL_GLOBAL_ONLY); if (variableObjPtr != NULL) { - returnString = Tcl_GetStringFromObj(variableObjPtr, &len); + returnString = Tcl_GetString(variableObjPtr); + len = variableObjPtr->length; if (uFmt != CF_TEXT) { Tcl_DStringInit(&dsBuf); Tcl_UtfToWCharDString(returnString, len, &dsBuf); @@ -919,7 +939,8 @@ DdeServerProc( */ HSZPAIR *returnPtr; - Tcl_Size i, numItems; + int i; + int numItems; for (i = 0, riPtr = tsdPtr->interpListPtr; riPtr != NULL; i++, riPtr = riPtr->nextPtr) { @@ -1304,7 +1325,7 @@ DdeObjCmd( }; int index, i, argIndex; - Tcl_Size length; + size_t length; int flags = 0, result = TCL_OK, firstArg = 0; HSZ ddeService = NULL, ddeTopic = NULL, ddeItem = NULL, ddeCookie = NULL; HDDEDATA ddeData = NULL, ddeItemData = NULL, ddeReturn; @@ -1467,8 +1488,9 @@ DdeObjCmd( Initialize(); if (firstArg != 1) { - const char *src = Tcl_GetStringFromObj(objv[firstArg], &length); + const char *src = Tcl_GetString(objv[firstArg]); + length = objv[firstArg]->length; Tcl_DStringInit(&serviceBuf); Tcl_UtfToWCharDString(src, length, &serviceBuf); serviceName = (WCHAR *) Tcl_DStringValue(&serviceBuf); @@ -1485,8 +1507,9 @@ DdeObjCmd( } if ((index != DDE_SERVERNAME) && (index != DDE_EVAL)) { - const char *src = Tcl_GetStringFromObj(objv[firstArg + 1], &length); + const char *src = Tcl_GetString(objv[firstArg + 1]); + length = objv[firstArg + 1]->length; Tcl_DStringInit(&topicBuf); topicName = Tcl_UtfToWCharDString(src, length, &topicBuf); length = Tcl_DStringLength(&topicBuf) / sizeof(WCHAR); @@ -1516,18 +1539,19 @@ DdeObjCmd( break; case DDE_EXECUTE: { - Tcl_Size dataLength; + size_t dataLength; const void *dataString; Tcl_DString dsBuf; Tcl_DStringInit(&dsBuf); if (flags & DDE_FLAG_BINARY) { dataString = - Tcl_GetByteArrayFromObj(objv[firstArg + 2], &dataLength); + getByteArrayFromObj(objv[firstArg + 2], &dataLength); } else { const char *src; - src = Tcl_GetStringFromObj(objv[firstArg + 2], &dataLength); + src = Tcl_GetString(objv[firstArg + 2]); + dataLength = objv[firstArg + 2]->length; Tcl_DStringInit(&dsBuf); dataString = Tcl_UtfToWCharDString(src, dataLength, &dsBuf); @@ -1580,7 +1604,8 @@ DdeObjCmd( const WCHAR *itemString; const char *src; - src = Tcl_GetStringFromObj(objv[firstArg + 2], &length); + src = Tcl_GetString(objv[firstArg + 2]); + length = objv[firstArg + 2]->length; Tcl_DStringInit(&itemBuf); itemString = Tcl_UtfToWCharDString(src, length, &itemBuf); length = Tcl_DStringLength(&itemBuf) / sizeof(WCHAR); @@ -1647,7 +1672,8 @@ DdeObjCmd( BYTE *dataString; const char *src; - src = Tcl_GetStringFromObj(objv[firstArg + 2], &length); + src = Tcl_GetString(objv[firstArg + 2]); + length = objv[firstArg + 2]->length; Tcl_DStringInit(&itemBuf); itemString = Tcl_UtfToWCharDString(src, length, &itemBuf); length = Tcl_DStringLength(&itemBuf) / sizeof(WCHAR); @@ -1661,10 +1687,11 @@ DdeObjCmd( Tcl_DStringInit(&dsBuf); if (flags & DDE_FLAG_BINARY) { dataString = (BYTE *) - Tcl_GetByteArrayFromObj(objv[firstArg + 3], &length); + getByteArrayFromObj(objv[firstArg + 3], &length); } else { const char *data = - Tcl_GetStringFromObj(objv[firstArg + 3], &length); + Tcl_GetString(objv[firstArg + 3]); + length = objv[firstArg + 3]->length; Tcl_DStringInit(&dsBuf); dataString = (BYTE *) Tcl_UtfToWCharDString(data, length, &dsBuf); @@ -1828,7 +1855,8 @@ DdeObjCmd( } objPtr = Tcl_ConcatObj(objc, objv); - string = Tcl_GetStringFromObj(objPtr, &length); + string = Tcl_GetString(objPtr); + length = objPtr->length; Tcl_DStringInit(&dsBuf); Tcl_UtfToWCharDString(string, length, &dsBuf); string = Tcl_DStringValue(&dsBuf); diff --git a/win/tclWinReg.c b/win/tclWinReg.c index 57cf0c6..998521c 100644 --- a/win/tclWinReg.c +++ b/win/tclWinReg.c @@ -134,6 +134,25 @@ static int SetValue(Tcl_Interp *interp, Tcl_Obj *keyNameObj, # endif #endif +static unsigned char * +getByteArrayFromObj( + Tcl_Obj *objPtr, + size_t *lengthPtr +) { + int length; + + unsigned char *result = Tcl_GetByteArrayFromObj(objPtr, &length); +#if TCL_MAJOR_VERSION > 8 + if (sizeof(TCL_HASH_TYPE) > sizeof(int)) { + /* 64-bit and TIP #494 situation: */ + *lengthPtr = *(TCL_HASH_TYPE *) objPtr->internalRep.twoPtrValue.ptr1; + } else +#endif + /* 32-bit or without TIP #494 */ + *lengthPtr = (size_t) (unsigned) length; + return result; +} + #ifdef __cplusplus extern "C" { #endif @@ -1270,8 +1289,8 @@ SetValue( if (typeObj == NULL) { type = REG_SZ; } else if (Tcl_GetIndexFromObj(interp, typeObj, typeNames, "type", - 0, &type) != TCL_OK) { - if (Tcl_GetIntFromObj(NULL, typeObj, &type) != TCL_OK) { + 0, (int *) &type) != TCL_OK) { + if (Tcl_GetIntFromObj(NULL, typeObj, (int *) &type) != TCL_OK) { return TCL_ERROR; } Tcl_ResetResult(interp); @@ -1299,7 +1318,7 @@ SetValue( (DWORD) type, (BYTE *) &value, sizeof(DWORD)); } else if (type == REG_MULTI_SZ) { Tcl_DString data, buf; - Tcl_Size objc, i; + int objc, i; Tcl_Obj **objv; if (Tcl_ListObjGetElements(interp, dataObj, &objc, &objv) != TCL_OK) { @@ -1353,13 +1372,13 @@ SetValue( Tcl_DStringFree(&buf); } else { BYTE *data; - Tcl_Size bytelength; + size_t bytelength; /* * Store binary data in the registry. */ - data = (BYTE *) Tcl_GetByteArrayFromObj(dataObj, &bytelength); + data = (BYTE *) getByteArrayFromObj(dataObj, &bytelength); result = RegSetValueExW(key, (WCHAR *) valueName, 0, (DWORD) type, data, (DWORD) bytelength); } @@ -1402,14 +1421,15 @@ BroadcastValue( LRESULT result; DWORD_PTR sendResult; int timeout = 3000; - Tcl_Size len; + size_t len; const char *str; Tcl_Obj *objPtr; WCHAR *wstr; Tcl_DString ds; if (objc == 3) { - str = Tcl_GetStringFromObj(objv[1], &len); + str = Tcl_GetString(objv[1]); + len = objv[1]->length; if ((len < 2) || (*str != '-') || strncmp(str, "-timeout", len)) { return TCL_BREAK; } @@ -1418,9 +1438,9 @@ BroadcastValue( } } - str = Tcl_GetStringFromObj(objv[0], &len); + str = Tcl_GetString(objv[0]); Tcl_DStringInit(&ds); - wstr = Tcl_UtfToWCharDString(str, len, &ds); + wstr = Tcl_UtfToWCharDString(str, objv[0]->length, &ds); if (Tcl_DStringLength(&ds) == 0) { wstr = NULL; } |