@@ -947,7 +947,7 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
947947#ifdef linux
948948 if (a -> sun_path [0 ] == 0 ) { /* Linux abstract namespace */
949949 addrlen -= (sizeof (* a ) - sizeof (a -> sun_path ));
950- return PyBytes_FromStringAndSize (a -> sun_path , addrlen );
950+ return PyString_FromStringAndSize (a -> sun_path , addrlen );
951951 }
952952 else
953953#endif /* linux */
@@ -1273,12 +1273,12 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
12731273
12741274 addr = (struct sockaddr_sco * )addr_ret ;
12751275 _BT_SCO_MEMB (addr , family ) = AF_BLUETOOTH ;
1276- if (!PyBytes_Check (args )) {
1276+ if (!PyString_Check (args )) {
12771277 PyErr_SetString (socket_error , "getsockaddrarg: "
12781278 "wrong format" );
12791279 return 0 ;
12801280 }
1281- straddr = PyBytes_AS_STRING (args );
1281+ straddr = PyString_AS_STRING (args );
12821282 if (setbdaddr (straddr , & _BT_SCO_MEMB (addr , bdaddr )) < 0 )
12831283 return 0 ;
12841284
@@ -1313,7 +1313,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
13131313 Py_Type (args )-> tp_name );
13141314 return 0 ;
13151315 }
1316- if (!PyArg_ParseTuple (args , "si|iis #" , & interfaceName ,
1316+ if (!PyArg_ParseTuple (args , "si|iiy #" , & interfaceName ,
13171317 & protoNumber , & pkttype , & hatype ,
13181318 & haddr , & halen ))
13191319 return 0 ;
@@ -1606,7 +1606,7 @@ sock_setsockopt(PySocketSockObject *s, PyObject *args)
16061606 }
16071607 else {
16081608 PyErr_Clear ();
1609- if (!PyArg_ParseTuple (args , "iis #:setsockopt" ,
1609+ if (!PyArg_ParseTuple (args , "iiy #:setsockopt" ,
16101610 & level , & optname , & buf , & buflen ))
16111611 return NULL ;
16121612 }
@@ -1662,19 +1662,16 @@ sock_getsockopt(PySocketSockObject *s, PyObject *args)
16621662 "getsockopt buflen out of range" );
16631663 return NULL ;
16641664 }
1665- buf = PyBytes_FromStringAndSize ((char * )NULL , buflen );
1665+ buf = PyString_FromStringAndSize ((char * )NULL , buflen );
16661666 if (buf == NULL )
16671667 return NULL ;
16681668 res = getsockopt (s -> sock_fd , level , optname ,
1669- (void * )PyBytes_AS_STRING (buf ), & buflen );
1669+ (void * )PyString_AS_STRING (buf ), & buflen );
16701670 if (res < 0 ) {
16711671 Py_DECREF (buf );
16721672 return s -> errorhandler ();
16731673 }
1674- if (PyBytes_Resize (buf , buflen ) < 0 ) {
1675- Py_DECREF (buf );
1676- return NULL ;
1677- }
1674+ _PyString_Resize (& buf , buflen );
16781675 return buf ;
16791676}
16801677
@@ -2097,12 +2094,12 @@ sock_recv(PySocketSockObject *s, PyObject *args)
20972094 }
20982095
20992096 /* Allocate a new string. */
2100- buf = PyBytes_FromStringAndSize ((char * ) 0 , recvlen );
2097+ buf = PyString_FromStringAndSize ((char * ) 0 , recvlen );
21012098 if (buf == NULL )
21022099 return NULL ;
21032100
21042101 /* Call the guts */
2105- outlen = sock_recv_guts (s , PyBytes_AS_STRING (buf ), recvlen , flags );
2102+ outlen = sock_recv_guts (s , PyString_AS_STRING (buf ), recvlen , flags );
21062103 if (outlen < 0 ) {
21072104 /* An error occurred, release the string and return an
21082105 error. */
@@ -2112,9 +2109,7 @@ sock_recv(PySocketSockObject *s, PyObject *args)
21122109 if (outlen != recvlen ) {
21132110 /* We did not read as many bytes as we anticipated, resize the
21142111 string if possible and be successful. */
2115- if (PyBytes_Resize (buf , outlen ) < 0 )
2116- /* Oopsy, not so successful after all. */
2117- return NULL ;
2112+ _PyString_Resize (& buf , outlen );
21182113 }
21192114
21202115 return buf ;
@@ -2270,11 +2265,11 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
22702265 return NULL ;
22712266 }
22722267
2273- buf = PyBytes_FromStringAndSize ((char * ) 0 , recvlen );
2268+ buf = PyString_FromStringAndSize ((char * ) 0 , recvlen );
22742269 if (buf == NULL )
22752270 return NULL ;
22762271
2277- outlen = sock_recvfrom_guts (s , PyBytes_AS_STRING (buf ),
2272+ outlen = sock_recvfrom_guts (s , PyString_AS_STRING (buf ),
22782273 recvlen , flags , & addr );
22792274 if (outlen < 0 ) {
22802275 goto finally ;
@@ -2283,7 +2278,7 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
22832278 if (outlen != recvlen ) {
22842279 /* We did not read as many bytes as we anticipated, resize the
22852280 string if possible and be succesful. */
2286- if (PyBytes_Resize ( buf , outlen ) < 0 )
2281+ if (_PyString_Resize ( & buf , outlen ) < 0 )
22872282 /* Oopsy, not so succesful after all. */
22882283 goto finally ;
22892284 }
@@ -2358,7 +2353,7 @@ sock_send(PySocketSockObject *s, PyObject *args)
23582353 char * buf ;
23592354 int len , n = -1 , flags = 0 , timeout ;
23602355
2361- if (!PyArg_ParseTuple (args , "s #|i:send" , & buf , & len , & flags ))
2356+ if (!PyArg_ParseTuple (args , "y #|i:send" , & buf , & len , & flags ))
23622357 return NULL ;
23632358
23642359 if (!IS_SELECTABLE (s ))
@@ -2399,7 +2394,7 @@ sock_sendall(PySocketSockObject *s, PyObject *args)
23992394 char * buf ;
24002395 int len , n = -1 , flags = 0 , timeout ;
24012396
2402- if (!PyArg_ParseTuple (args , "s #|i:sendall" , & buf , & len , & flags ))
2397+ if (!PyArg_ParseTuple (args , "y #|i:sendall" , & buf , & len , & flags ))
24032398 return NULL ;
24042399
24052400 if (!IS_SELECTABLE (s ))
@@ -2454,9 +2449,9 @@ sock_sendto(PySocketSockObject *s, PyObject *args)
24542449 int addrlen , len , n = -1 , flags , timeout ;
24552450
24562451 flags = 0 ;
2457- if (!PyArg_ParseTuple (args , "s #O:sendto" , & buf , & len , & addro )) {
2452+ if (!PyArg_ParseTuple (args , "y #O:sendto" , & buf , & len , & addro )) {
24582453 PyErr_Clear ();
2459- if (!PyArg_ParseTuple (args , "s #iO:sendto" ,
2454+ if (!PyArg_ParseTuple (args , "y #iO:sendto" ,
24602455 & buf , & len , & flags , & addro ))
24612456 return NULL ;
24622457 }
@@ -3382,7 +3377,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
33823377 if (inet_aton != NULL ) {
33833378#endif
33843379 if (inet_aton (ip_addr , & buf ))
3385- return PyBytes_FromStringAndSize ((char * )(& buf ),
3380+ return PyString_FromStringAndSize ((char * )(& buf ),
33863381 sizeof (buf ));
33873382
33883383 PyErr_SetString (socket_error ,
@@ -3411,8 +3406,8 @@ socket_inet_aton(PyObject *self, PyObject *args)
34113406 return NULL ;
34123407 }
34133408 }
3414- return PyBytes_FromStringAndSize ((char * ) & packed_addr ,
3415- sizeof (packed_addr ));
3409+ return PyString_FromStringAndSize ((char * ) & packed_addr ,
3410+ sizeof (packed_addr ));
34163411
34173412#ifdef USE_INET_ATON_WEAKLINK
34183413 }
@@ -3488,12 +3483,12 @@ socket_inet_pton(PyObject *self, PyObject *args)
34883483 "illegal IP address string passed to inet_pton" );
34893484 return NULL ;
34903485 } else if (af == AF_INET ) {
3491- return PyBytes_FromStringAndSize (packed ,
3492- sizeof (struct in_addr ));
3486+ return PyString_FromStringAndSize (packed ,
3487+ sizeof (struct in_addr ));
34933488#ifdef ENABLE_IPV6
34943489 } else if (af == AF_INET6 ) {
3495- return PyBytes_FromStringAndSize (packed ,
3496- sizeof (struct in6_addr ));
3490+ return PyString_FromStringAndSize (packed ,
3491+ sizeof (struct in6_addr ));
34973492#endif
34983493 } else {
34993494 PyErr_SetString (socket_error , "unknown address family" );
0 commit comments