@@ -1246,8 +1246,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
12461246 "unicode string expected instead of %s instance" ,
12471247 value -> ob_type -> tp_name );
12481248 return NULL ;
1249- } else
1250- Py_INCREF (value );
1249+ }
12511250
12521251 wstr = PyUnicode_AsUnicodeAndSize (value , & size );
12531252 if (wstr == NULL )
@@ -1256,7 +1255,6 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
12561255 PyErr_Format (PyExc_ValueError ,
12571256 "string too long (%zd, maximum length %zd)" ,
12581257 size , length );
1259- Py_DECREF (value );
12601258 return NULL ;
12611259 } else if (size < length - 1 )
12621260 /* copy terminating NUL character if there is space */
@@ -1266,6 +1264,7 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
12661264 return NULL ;
12671265 }
12681266
1267+ Py_INCREF (value );
12691268 return value ;
12701269}
12711270
@@ -1292,35 +1291,29 @@ s_set(void *ptr, PyObject *value, Py_ssize_t length)
12921291 char * data ;
12931292 Py_ssize_t size ;
12941293
1295- if (PyBytes_Check (value )) {
1296- Py_INCREF (value );
1297- } else {
1294+ if (!PyBytes_Check (value )) {
12981295 PyErr_Format (PyExc_TypeError ,
12991296 "expected bytes, %s found" ,
13001297 value -> ob_type -> tp_name );
13011298 return NULL ;
13021299 }
13031300
13041301 data = PyBytes_AS_STRING (value );
1305- if (!data )
1306- return NULL ;
13071302 size = strlen (data ); /* XXX Why not Py_SIZE(value)? */
13081303 if (size < length ) {
1309- /* This will copy the leading NUL character
1304+ /* This will copy the terminating NUL character
13101305 * if there is space for it.
13111306 */
13121307 ++ size ;
13131308 } else if (size > length ) {
13141309 PyErr_Format (PyExc_ValueError ,
13151310 "bytes too long (%zd, maximum length %zd)" ,
13161311 size , length );
1317- Py_DECREF (value );
13181312 return NULL ;
13191313 }
13201314 /* Also copy the terminating NUL character if there is space */
13211315 memcpy ((char * )ptr , data , size );
13221316
1323- Py_DECREF (value );
13241317 _RET (value );
13251318}
13261319
@@ -1428,9 +1421,7 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
14281421 /* convert value into a PyUnicodeObject or NULL */
14291422 if (Py_None == value ) {
14301423 value = NULL ;
1431- } else if (PyUnicode_Check (value )) {
1432- Py_INCREF (value ); /* for the descref below */
1433- } else {
1424+ } else if (!PyUnicode_Check (value )) {
14341425 PyErr_Format (PyExc_TypeError ,
14351426 "unicode string expected instead of %s instance" ,
14361427 value -> ob_type -> tp_name );
@@ -1449,7 +1440,6 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
14491440 return NULL ;
14501441 }
14511442 bstr = SysAllocStringLen (wvalue , (unsigned )wsize );
1452- Py_DECREF (value );
14531443 } else
14541444 bstr = NULL ;
14551445
0 commit comments