@@ -404,7 +404,7 @@ PyHKEY_strFunc(PyObject *ob)
404404 PyHKEYObject * pyhkey = (PyHKEYObject * )ob ;
405405 char resBuf [160 ];
406406 wsprintf (resBuf , "<PyHKEY:%p>" , pyhkey -> hkey );
407- return PyString_FromString (resBuf );
407+ return PyUnicode_FromString (resBuf );
408408}
409409
410410static int
@@ -444,6 +444,7 @@ static PyNumberMethods PyHKEY_NumberMethods =
444444 PyHKEY_binaryFailureFunc , /* nb_and */
445445 PyHKEY_binaryFailureFunc , /* nb_xor */
446446 PyHKEY_binaryFailureFunc , /* nb_or */
447+ NULL , /* nb_coerce */
447448 PyHKEY_intFunc , /* nb_int */
448449 PyHKEY_unaryFailureFunc , /* nb_long */
449450 PyHKEY_unaryFailureFunc , /* nb_float */
@@ -729,11 +730,10 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
729730 return FALSE;
730731 need_decref = 1 ;
731732 }
732- if (!PyString_Check (value ))
733+ if (!PyBytes_Check (value ))
733734 return FALSE;
734735 * retDataSize = 1 + strlen (
735- PyString_AS_STRING (
736- (PyStringObject * )value ));
736+ PyBytes_AS_STRING (value ));
737737 }
738738 * retDataBuf = (BYTE * )PyMem_NEW (DWORD , * retDataSize );
739739 if (* retDataBuf == NULL ){
@@ -744,8 +744,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
744744 strcpy ((char * )* retDataBuf , "" );
745745 else
746746 strcpy ((char * )* retDataBuf ,
747- PyString_AS_STRING (
748- (PyStringObject * )value ));
747+ PyBytes_AS_STRING (value ));
749748 if (need_decref )
750749 Py_DECREF (value );
751750 break ;
@@ -770,7 +769,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
770769 PyObject * t ;
771770 t = PyList_GET_ITEM (
772771 (PyListObject * )value ,j );
773- if (PyString_Check (t )) {
772+ if (PyBytes_Check (t )) {
774773 obs [j ] = t ;
775774 Py_INCREF (t );
776775 } else if (PyUnicode_Check (t )) {
@@ -783,8 +782,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
783782 } else
784783 goto reg_multi_fail ;
785784 size += 1 + strlen (
786- PyString_AS_STRING (
787- (PyStringObject * )obs [j ]));
785+ PyBytes_AS_STRING (obs [j ]));
788786 }
789787
790788 * retDataSize = size + 1 ;
@@ -800,12 +798,9 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
800798 {
801799 PyObject * t ;
802800 t = obs [j ];
803- strcpy (P ,
804- PyString_AS_STRING (
805- (PyStringObject * )t ));
801+ strcpy (P , PyBytes_AS_STRING (t ));
806802 P += 1 + strlen (
807- PyString_AS_STRING (
808- (PyStringObject * )t ));
803+ PyBytes_AS_STRING (t ));
809804 Py_DECREF (obs [j ]);
810805 }
811806 /* And doubly-terminate the list... */
@@ -922,7 +917,7 @@ Reg2Py(char *retDataBuf, DWORD retDataSize, DWORD typ)
922917 obData = Py_None ;
923918 }
924919 else
925- obData = Py_BuildValue ("s #" ,
920+ obData = Py_BuildValue ("y #" ,
926921 (char * )retDataBuf ,
927922 retDataSize );
928923 break ;
@@ -1047,7 +1042,7 @@ PyEnumKey(PyObject *self, PyObject *args)
10471042 if (rc != ERROR_SUCCESS )
10481043 return PyErr_SetFromWindowsErrWithFunction (rc , "RegEnumKeyEx ");
10491044
1050- retStr = PyString_FromStringAndSize (tmpbuf , len );
1045+ retStr = PyUnicode_FromStringAndSize (tmpbuf , len );
10511046 return retStr ; /* can be NULL */
10521047}
10531048
@@ -1109,7 +1104,7 @@ PyEnumValue(PyObject *self, PyObject *args)
11091104 retVal = NULL ;
11101105 goto fail ;
11111106 }
1112- retVal = Py_BuildValue ("sOi " , retValueBuf , obData , typ );
1107+ retVal = Py_BuildValue ("UOi " , retValueBuf , obData , typ );
11131108 Py_DECREF (obData );
11141109 fail :
11151110 PyMem_Free (retValueBuf );
@@ -1232,17 +1227,19 @@ PyQueryValue(PyObject *self, PyObject *args)
12321227 != ERROR_SUCCESS )
12331228 return PyErr_SetFromWindowsErrWithFunction (rc ,
12341229 "RegQueryValue" );
1235- retStr = PyString_FromStringAndSize ( NULL , bufSize );
1236- if (retStr == NULL )
1237- return NULL ;
1238- retBuf = PyString_AS_STRING ( retStr );
1230+ retBuf = ( char * ) PyMem_Malloc ( bufSize );
1231+ if (retBuf == NULL )
1232+ return PyErr_NoMemory () ;
1233+
12391234 if ((rc = RegQueryValue (hKey , subKey , retBuf , & bufSize ))
12401235 != ERROR_SUCCESS ) {
1241- Py_DECREF ( retStr );
1236+ PyMem_Free ( retBuf );
12421237 return PyErr_SetFromWindowsErrWithFunction (rc ,
12431238 "RegQueryValue" );
12441239 }
1245- _PyString_Resize (& retStr , strlen (retBuf ));
1240+
1241+ retStr = PyUnicode_DecodeMBCS (retBuf , strlen (retBuf ), NULL );
1242+ PyMem_Free (retBuf );
12461243 return retStr ;
12471244}
12481245
0 commit comments